| Server IP : 162.214.74.102 / Your IP : 216.73.216.192 Web Server : Apache System : Linux dedi-4363141.lrsys.com.br 3.10.0-1160.119.1.el7.tuxcare.els25.x86_64 #1 SMP Wed Oct 1 17:37:27 UTC 2025 x86_64 User : lrsys ( 1015) PHP Version : 5.6.40 Disable Function : exec,passthru,shell_exec,system MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /home/lrsys/www/lrsys_apps/leo/application/plugins/module_imobles/helpers/api/ |
Upload File : |
<?php
include_once "APIUtils.php";
include_once __DIR__ . "/../../models/CrmgoalsModel.php";
include_once __DIR__ . "/../../models/CrmcommentsModel.php";
include_once __DIR__ . "/../../models/DealsModel.php";
class CRMGoalsHelper {
private $apiUtils;
private $crmGoalsModel;
private $crmCommentsModel;
private $dealsModel;
public function __construct() {
$this->apiUtils = new APIUtils();
$this->crmGoalsModel = new CrmgoalsModel();
$this->crmCommentsModel = new CrmcommentsModel();
$this->dealsModel = new DealsModel();
}
public function listGoals($clientID = null){
$filter = $this->apiUtils->getInputFilter();
if($clientID === null){
try {
$client = $this->apiUtils->crmAccount($filter);
$clientID = $client->id;
} catch (Exception $e) {
return $this->apiUtils->apiError(401, $e->getMessage());
}
}
$categories = array();
$goalsCategories = $this->crmGoalsModel->getClientGoalsByCategory($clientID);
foreach($goalsCategories as $gc){
if (count($gc->goals) == 0){
continue;
}
$goals = array();
foreach($gc->goals as $g){
$goals[] = [
"goal_id" => $g->id,
"goal_title" => $g->title,
"created_at" => $g->created_at,
"updated_at" => $g->updated_at
];
}
$categories[] = [
"category_id" => $gc->id,
"category_name" => $gc->name,
"category_order" => $gc->sorder,
"goals" => $goals
];
}
$comments = array();
$goalsComments = $this->crmCommentsModel->getClientComments($clientID);
foreach($goalsComments as $gc){
$comments[] = [
"comment_id" => $gc->id,
"comment" => $gc->comment,
"created_at" => $gc->created_at,
"updated_at" => $gc->updated_at,
"from_client" => $gc->from_client == 1? true:false
];
}
$dataResult['goals'] = [
'goals_categories' => $categories,
'goals_comments' => $comments
];
if(!empty($client)){
$clientDetails = $this->apiUtils->clientDetails($client);
$dataResult = array_merge($clientDetails, $dataResult);
}
$output = array(
"results" => $dataResult,
);
return $output;
}
public function createComment(){
$filter = $this->apiUtils->getInputFilter();
try {
$client = $this->apiUtils->crmAccount($filter);
$clientID = $client->id;
} catch (Exception $e) {
return $this->apiUtils->apiError(401, $e->getMessage());
}
if(empty($filter['deal_id'])){
return $this->apiUtils->apiError(400, 'deal_id é obrigatório');
}
if(empty($filter['comment'])){
return $this->apiUtils->apiError(400, 'comment é obrigatório');
}
if(!isset($filter['from_client'])){
return $this->apiUtils->apiError(400, 'from_client é obrigatório');
}
$deal = $this->dealsModel->getOne($filter['deal_id']);
if(!$deal){
return $this->apiUtils->apiError(400, 'deal_id inválido');
}
if ($client->id != $deal->crm_account_id){
return $this->apiUtils->apiError(400, 'crm_account_id inválido para este deal_id');
}
try{
$dealComment = $this->crmCommentsModel->addDealComment($client->id, $filter['deal_id'], $filter['from_client'], $filter['comment']);
$comment = array(
"comment_id" => $dealComment->id,
"created_at" => $dealComment->created_at,
);
$output = array(
"results" => $comment
);
return $output;
} catch (Exception $e){
return $this->apiUtils->apiError(400, $e->getMessage());
}
}
public function editComment(){
$filter = $this->apiUtils->getInputFilter();
try {
$client = $this->apiUtils->crmAccount($filter);
$clientID = $client->id;
} catch (Exception $e) {
return $this->apiUtils->apiError(401, $e->getMessage());
}
if(empty($filter['comment_id'])){
return $this->apiUtils->apiError(400, 'comment_id é obrigatório');
}
if(empty($filter['comment'])){
return $this->apiUtils->apiError(400, 'comment é obrigatório');
}
$dealComment = $this->crmCommentsModel->getOne($filter['comment_id']);
if(!$dealComment){
return $this->apiUtils->apiError(400, 'comment_id inválido');
}
if ($client->id != $dealComment->crm_accounts_id){
return $this->apiUtils->apiError(400, 'crm_account_id inválido para este comment_id ' . $client->id . " - " . $dealComment->crm_accounts_id);
}
try{
$dealComment = $this->crmCommentsModel->editDealComment($dealComment, $filter['comment']);
$comment = array(
"comment_id" => $dealComment->id,
"updated_at" => $dealComment->updated_at,
);
$output = array(
"results" => $comment
);
return $output;
} catch (Exception $e){
return $this->apiUtils->apiError(400, $e->getMessage());
}
}
public function deleteComment(){
$filter = $this->apiUtils->getInputFilter();
try {
$client = $this->apiUtils->crmAccount($filter);
$clientID = $client->id;
} catch (Exception $e) {
return $this->apiUtils->apiError(401, $e->getMessage());
}
if(empty($filter['comment_id'])){
return $this->apiUtils->apiError(400, 'comment_id é obrigatório');
}
$dealComment = $this->crmCommentsModel->getOne($filter['comment_id']);
if(!$dealComment){
return $this->apiUtils->apiError(400, 'comment_id inválido');
}
if ($client->id != $dealComment->crm_accounts_id){
return $this->apiUtils->apiError(400, 'crm_account_id inválido para este comment_id ' . $client->id . " - " . $dealComment->crm_accounts_id);
}
try{
$dealComment = $this->crmCommentsModel->deleteDealComment($dealComment);
$comment = array(
"comment_id" => $dealComment->id,
"deleted_at" => $dealComment->deleted_at,
);
$output = array(
"results" => $comment
);
return $output;
} catch (Exception $e){
return $this->apiUtils->apiError(400, $e->getMessage());
}
}
}