implementado pestaña clientes en usuarios

This commit is contained in:
2024-12-15 12:24:49 +01:00
parent 7c5fdc0c88
commit 9a0581319c
7 changed files with 228 additions and 80 deletions

View File

@ -16,9 +16,10 @@ class ClienteUsuariosModel extends ShieldUserModel
protected $useAutoIncrement = true;
const SORTABLE = [
0 => "t1.first_name",
1 => "t1.last_name",
2 => "t2.secret",
0 => "t1.id",
1 => "t1.first_name",
2 => "t1.last_name",
3 => "t2.secret",
];
protected $allowedFields = ["id", "first_name", "last_name", "email"];
@ -83,6 +84,19 @@ class ClienteUsuariosModel extends ShieldUserModel
return $result;
}
public function removeClienteFromUser($user_id = -1){
$this->db->table($this->table)->where('id', $user_id)->update(['cliente_id' => null]);
}
public function addUserToClient($user_id = -1, $cliente_id = -1){
if($user_id < 1 || $cliente_id < 1){
return;
}
$this->db->table($this->table)->where('id', $user_id)->update(['cliente_id' => $cliente_id]);
}
/**
* Get resource data.
*
@ -100,15 +114,8 @@ class ClienteUsuariosModel extends ShieldUserModel
);
$builder->join("auth_identities t2", "t1.id = t2.user_id", "left");
$builder->where('t1.id', $cliente_id);
$builder->where('t1.cliente_id', $cliente_id);
return empty($search)
? $builder
: $builder
->groupStart()
->like("t1.first_name", $search)
->orLike("t1.last_name", $search)
->orLike("t2.secret", $search)
->groupEnd();
return $builder;
}
}