mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
message refactor
This commit is contained in:
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Models\Chat;
|
||||
|
||||
use App\Entities\Chat\ChatDepartmentEntity;
|
||||
use App\Models\Usuarios\UserModel;
|
||||
use CodeIgniter\Model;
|
||||
|
||||
@ -10,7 +11,7 @@ class ChatDeparmentModel extends Model
|
||||
protected $table = 'chat_departments';
|
||||
protected $primaryKey = 'id';
|
||||
protected $useAutoIncrement = true;
|
||||
protected $returnType = 'object';
|
||||
protected $returnType = ChatDepartmentEntity::class;
|
||||
protected $useSoftDeletes = true;
|
||||
protected $protectFields = true;
|
||||
protected $allowedFields = [
|
||||
@ -181,4 +182,20 @@ class ChatDeparmentModel extends Model
|
||||
{
|
||||
return $this->select(['id','display','description'])->where('deleted_at',null);
|
||||
}
|
||||
|
||||
public function getModelChatDepartments(string $modelFk,int $modelId) : array
|
||||
{
|
||||
$query = $this->builder()->select([
|
||||
'chat_departments.id',
|
||||
'chat_departments.name',
|
||||
'chat_departments.display',
|
||||
'COUNT(chat_messages.id) as countMessages'
|
||||
])
|
||||
->join('chats','chats.chat_department_id = chat_departments.id','left')
|
||||
->join('chat_messages','chat_messages.chat_id = chats.id','left')
|
||||
->where($modelFk,$modelId)
|
||||
->groupBy('chat_departments.name');
|
||||
return $query->get()->getResultArray() ?? [];
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user