| Server IP : 162.214.74.102 / Your IP : 216.73.217.114 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/imobles/application/plugins/module_helpdesk/factories/ |
Upload File : |
<?php
include_once "Factory.php";
class TicketFactory extends Factory {
public static function create($data, $ticket, $create = false) {
static::populate($data, $ticket, 'client_id');
static::populate($data, $ticket, 'form_id');
static::populate($data, $ticket, 'requester_id');
static::populate($data, $ticket, 'module_helpdesk_tickets_priority_id');
static::populate($data, $ticket, 'module_helpdesk_tickets_cat_id');
static::populate($data, $ticket, 'module_helpdesk_tickets_treatment_type_id');
$ticket->treatment_type_local = $data['module_helpdesk_tickets_treatment_type_id'] == 2 ? $data['treatment_type_local'] : '';
// static::populate($data, $ticket, 'product_cat_id');
static::populate($data, $ticket, 'description');
$ticket->responsible_id = empty($data['responsible_id']) ? 0 : $data['responsible_id'];
$ticket->status = empty($data['status']) ? 'Open' : $data['status'];
if ($create) {
$ticket->created_at = date('Y-m-d H:i:s');
// Verifico se é ADMIN ou CLIENTE
$user_id = 0;
if (isset($_SESSION['uid'])) {
$user = User::_info();
$user_id = $user->id;
}
$ticket->requester_id = $user_id;
} else {
$ticket->closed_at = $data['status'] == "Closed" ? date('Y-m-d H:i:s') : null;
}
if (!empty($data['id_offline'])) {
if (!empty($data['dt_create'])) {
$ticket->created_at = _postDate($data['dt_create']);
}
$ticket->id_offline = $data['id_offline'];
}
//sem responsável, o sistema localiza o com menos tickets
if ($ticket->responsible_id == 0) {
$client = ORM::for_table('crm_accounts')->where('id', $data['client_id'])->find_one();
if (!empty($data['product_cat_id'])) {
$catsArvoreAcima = static::recuperaIdPaiCategory($data['product_cat_id']);
} else {
$catsArvoreAcima = array();
}
$d = ORM::for_table('crm_accounts')
->table_alias('c')
->select('c.id')
->select_expr("(select count(sub_t.id) from module_helpdesk_tickets sub_t where sub_t.responsible_id= c.id and status in ('Open','Atendence') " . ($ticket->id > 0 ? " and sub_t.id<>" . $ticket->id : "") . ") as number_tickets");
$d->join('crm_accounts_groups', array('c.id', '=', 'ag.crm_accounts_id'), 'ag')
->join('crm_groups', array('g.id', '=', 'ag.crm_group_id'), 'g')
->join('module_hr_compl_data', array('f.func', '=', 'c.id'), 'f')
->where('g.id', 5) //employee;
->order_by_expr('number_tickets ASC')
->limit(1);
//TRATAMENTO PARA CATEGORIA CHUMBADO NO FONTE, REGRA DE CENTRO DE CUSTO
//CUSTOMIZAÇÃO PARA HEXAGON - DADOS CHUMBADOS
if ($data['product_cat_id'] == 1) {
$d->where('c.cost_center_id', $client->cost_center_id);
}
$sql = "";
if (is_array($catsArvoreAcima)) {
foreach ($catsArvoreAcima as $ca) {
$sql .= " OR f.product_category LIKE '%" . $ca . "%'";
}
$d->where_raw("(" . substr($sql, 3) . ")");
}
$resp = $d->find_array();
if (count($resp) > 0) {
$ticket->responsible_id = $resp[0]['id'];
}
}
return $ticket;
}
//função, que busca todas as categorias acima da categoria selecionada
//necessári exemplo. Sistema >> PHP >> suporte. digamos que o chamado é suporte
// qualquer usuário com o nivel sistema de categoria, tem permissão no suporte para atribuiçao
public static function recuperaIdPaiCategory($category) {
$requester = ORM::for_table('sys_items_category')->find_one($category);
if ($requester->parent > 0) {
return array_merge(array($requester->id), static::recuperaIdPaiCategory($requester->parent));
} else {
return array($requester->id);
}
}
}