mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
77 lines
2.0 KiB
PHP
77 lines
2.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Entities\Usuarios\UsersEntity;
|
|
use CodeIgniter\Shield\Models\UserModel as ShieldUserModel;
|
|
|
|
class UserModel extends ShieldUserModel
|
|
{
|
|
protected function initialize(): void
|
|
{
|
|
parent::initialize();
|
|
|
|
$this->allowedFields = [
|
|
...$this->allowedFields,
|
|
'first_name', // Añadido
|
|
'last_name', // Añadido
|
|
'cliente_id', // Añadido
|
|
];
|
|
}
|
|
|
|
protected $returnType = UsersEntity::class;
|
|
|
|
protected $useSoftDeletes = true;
|
|
protected $useTimestamps = true;
|
|
protected $createdField = 'created_at';
|
|
protected $updatedField = 'updated_at';
|
|
protected $deletedField = 'deleted_at';
|
|
|
|
|
|
protected $validationRules = [
|
|
"username" => [
|
|
"label" => "correo duplicado",
|
|
"rules" => "is_unique[users.username]",
|
|
]
|
|
|
|
];
|
|
|
|
public function getComerciales(){
|
|
|
|
$builder = $this->db
|
|
->table("users" . " t1")
|
|
->select(
|
|
"t1.id AS id, CONCAT(t1.first_name, ' ', t1.last_name) AS text"
|
|
);
|
|
|
|
$builder->where('t1.deleted_at', null);
|
|
$builder->where("t2.group", "comercial");
|
|
$builder->join("auth_groups_users t2", "t1.id = t2.user_id", "left");
|
|
|
|
return $builder->get()->getResult();
|
|
|
|
}
|
|
|
|
public function getUsersList()
|
|
{
|
|
$builder = $this->db
|
|
->table('users t1')
|
|
->select('
|
|
t1.id AS id,
|
|
t1.first_name AS first_name,
|
|
t1.last_name AS last_name,
|
|
t1.email AS email,
|
|
t1.last_active AS last_active,
|
|
GROUP_CONCAT(DISTINCT t2.`group` SEPARATOR ", ") AS `group`
|
|
')
|
|
->join('auth_groups_users t2', 't1.id = t2.user_id', 'left')
|
|
->where('t1.deleted_at', null)
|
|
->groupBy('t1.id, t1.first_name, t1.last_name, t1.email, t1.last_active');
|
|
|
|
return $builder->get()->getResult();
|
|
}
|
|
|
|
}
|