mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
105 lines
3.5 KiB
PHP
105 lines
3.5 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Soporte;
|
|
|
|
|
|
class TicketModel extends \App\Models\BaseModel
|
|
{
|
|
|
|
protected $table = 'tickets';
|
|
protected $primaryKey = 'id';
|
|
protected $allowedFields = ['usuario_id', 'user_soporte_id', 'seccion_id' ,'categoria_id', 'estado_id', 'prioridad', 'titulo', 'descripcion', 'created_at', 'updated_at'];
|
|
|
|
protected $useTimestamps = true;
|
|
|
|
const SORTABLE = [
|
|
0 => "t1.categoria_id",
|
|
1 => "t1.seccion_id",
|
|
2 => "t1.estado_id",
|
|
3 => "t1.prioridad",
|
|
4 => "t1.titulo",
|
|
5 => "t1.usuario_id",
|
|
6 => "t1.usuario_soporte_id",
|
|
7 => "t1.created_at",
|
|
];
|
|
|
|
public function getEstados()
|
|
{
|
|
$values = $this->db->table('tickets_estados')->get()->getResultArray();
|
|
|
|
for($i = 0; $i < count($values); $i++){
|
|
$values[$i]['text'] = lang("Tickets." . $values[$i]['keyword']);
|
|
}
|
|
|
|
return $values;
|
|
}
|
|
|
|
public function getCategorias()
|
|
{
|
|
$values = $this->db->table('tickets_categorias')->get()->getResultArray();
|
|
|
|
for($i = 0; $i < count($values); $i++){
|
|
$values[$i]['text'] = lang("Tickets." . $values[$i]['keyword']);
|
|
}
|
|
|
|
return $values;
|
|
}
|
|
|
|
public function getSecciones()
|
|
{
|
|
$values = $this->db->table('tickets_secciones')->get()->getResultArray();
|
|
|
|
for($i = 0; $i < count($values); $i++){
|
|
$values[$i]['text'] = lang("Tickets." . $values[$i]['keyword']);
|
|
}
|
|
|
|
return $values;
|
|
}
|
|
|
|
public function getTickets($id = null)
|
|
{
|
|
if ($id === null) {
|
|
return $this->select('tickets.*, users.nombre as usuario, categorias.nombre as categoria, estados.nombre as estado')
|
|
->join('users', 'users.id = tickets.usuario_id')
|
|
->join('categorias', 'categorias.id = tickets.categoria_id')
|
|
->join('estados', 'estados.id = tickets.estado_id')
|
|
->findAll();
|
|
}
|
|
|
|
return $this->find($id);
|
|
}
|
|
|
|
public function getResource($search = [], )
|
|
{
|
|
$builder = $this->db
|
|
->table($this->table . " t1")
|
|
->select(
|
|
"t1.id as id, t1.usuario_id AS usuario_id, CONCAT(t2.first_name, ' ', t2.last_name) AS usuario,
|
|
t1.user_soporte_id AS user_soporte_id, CONCAT(t2.first_name, ' ', t2.last_name) AS user_soporte,
|
|
t1.categoria_id AS categoria_id, t3.keyword AS categoria, t1.seccion_id AS seccion_id, t1.estado_id AS estado_id,
|
|
t1.prioridad AS prioridad, t1.titulo AS titulo, t1.created_at AS created_at
|
|
"
|
|
);
|
|
|
|
$builder->join("users t2", "t1.usuario_id = t2.id", "left");
|
|
$builder->join("users t2", "t1.user_soporte_id = t2.id", "left");
|
|
$builder->join("tickets_categorias t3", "t1.categoria_id = t3.id", "left");
|
|
$builder->join("tickets_estados t4", "t1.estado_id = t4.id", "left");
|
|
$builder->join("tickets_secciones t5", "t1.seccion_id = t5.id", "left");
|
|
|
|
if (empty($search))
|
|
return $builder;
|
|
else {
|
|
$builder->groupStart();
|
|
foreach ($search as $col_search) {
|
|
if ($col_search[0] > 0 && $col_search[0] < 4)
|
|
$builder->where(self::SORTABLE[$col_search[0]], $col_search[2]);
|
|
else
|
|
$builder->like(self::SORTABLE[$col_search[0]], $col_search[2]);
|
|
}
|
|
$builder->groupEnd();
|
|
return $builder;
|
|
}
|
|
}
|
|
}
|