message refactor

This commit is contained in:
amazuecos
2025-03-24 08:12:06 +01:00
parent 61af547135
commit c0d54e28b7
26 changed files with 994 additions and 677 deletions

View File

@ -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() ?? [];
}
}