mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
Avance en usuarios de clientes
This commit is contained in:
110
ci4/app/Models/Clientes/ClienteUsuariosModel.php
Normal file
110
ci4/app/Models/Clientes/ClienteUsuariosModel.php
Normal file
@ -0,0 +1,110 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Clientes;
|
||||
|
||||
class ClienteUsuariosModel extends \App\Models\GoBaseModel
|
||||
{
|
||||
protected $table = "auth_user";
|
||||
|
||||
/**
|
||||
* Whether primary key uses auto increment.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $useAutoIncrement = true;
|
||||
|
||||
const SORTABLE = [
|
||||
0 => "t1.first_name",
|
||||
1 => "t1.last_name",
|
||||
2 => "t1.email",
|
||||
];
|
||||
|
||||
protected $allowedFields = ["id", "first_name", "last_name", "email"];
|
||||
protected $returnType = "App\Entities\Usuarios\UserEntity";
|
||||
|
||||
protected $useTimestamps = true;
|
||||
protected $useSoftDeletes = false;
|
||||
|
||||
protected $createdField = "created_at";
|
||||
|
||||
protected $updatedField = "updated_at";
|
||||
|
||||
public static $labelField = "nombre";
|
||||
|
||||
protected $validationRules = [
|
||||
"last_name" => [
|
||||
"label" => "ClienteContactos.apellidos",
|
||||
"rules" => "trim|max_length[500]",
|
||||
],
|
||||
"email" => [
|
||||
"label" => "ClienteContactos.email",
|
||||
"rules" => "trim|max_length[150]|valid_email|permit_empty",
|
||||
],
|
||||
"first_name" => [
|
||||
"label" => "ClienteContactos.nombre",
|
||||
"rules" => "trim|max_length[100]",
|
||||
],
|
||||
];
|
||||
|
||||
protected $validationMessages = [
|
||||
"last_name" => [
|
||||
"max_length" => "ClienteContactos.validation.apellidos.max_length",
|
||||
],
|
||||
|
||||
"email" => [
|
||||
"max_length" => "ClienteContactos.validation.email.max_length",
|
||||
"valid_email" => "ClienteContactos.validation.email.valid_email",
|
||||
],
|
||||
"first_name" => [
|
||||
"max_length" => "ClienteContactos.validation.nombre.max_length",
|
||||
],
|
||||
];
|
||||
|
||||
public function findAllWithClientes(string $selcols = "*", int $limit = null, int $offset = 0)
|
||||
{
|
||||
$sql =
|
||||
"SELECT t1." .
|
||||
$selcols .
|
||||
", t2.nombre AS cliente_id FROM " .
|
||||
$this->table .
|
||||
" t1 LEFT JOIN clientes t2 ON t1.cliente_id = t2.id";
|
||||
if (!is_null($limit) && intval($limit) > 0) {
|
||||
$sql .= " LIMIT " . $limit;
|
||||
}
|
||||
|
||||
if (!is_null($offset) && intval($offset) > 0) {
|
||||
$sql .= " OFFSET " . $offset;
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
$result = $query->getResultObject();
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get resource data.
|
||||
*
|
||||
* @param string $search
|
||||
*
|
||||
* @return \CodeIgniter\Database\BaseBuilder
|
||||
*/
|
||||
public function getResource(string $search = "", $cliente_id = -1)
|
||||
{
|
||||
$builder = $this->db
|
||||
->table($this->table . " t1")
|
||||
->select(
|
||||
"t1.id_user AS id, t1.first_name AS nombre, t1.last_name AS apellidos, t1.email AS email"
|
||||
);
|
||||
|
||||
$builder->where('t1.id_user', $cliente_id);
|
||||
|
||||
return empty($search)
|
||||
? $builder
|
||||
: $builder
|
||||
->groupStart()
|
||||
->like("t1.first_name", $search)
|
||||
->orLike("t1.last_name", $search)
|
||||
->orLike("t1.email", $search)
|
||||
->groupEnd();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user