77 lines
2.1 KiB
PHP
77 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use CodeIgniter\Model;
|
|
|
|
class ClaimFilesModel extends Model
|
|
{
|
|
protected $table = 'claim_files';
|
|
protected $primaryKey = 'id';
|
|
protected $allowedFields = [
|
|
'id',
|
|
'ticket_id',
|
|
'ticket_type',
|
|
'ticket_message_id',
|
|
'file_type',
|
|
'doc_name',
|
|
'url',
|
|
'created_by',
|
|
'updated_by',
|
|
'created_at',
|
|
'updated_at',
|
|
'is_active',
|
|
'file_name',
|
|
'mime_type',
|
|
'docs_for_ir',
|
|
'is_file_sent_to_tpa',
|
|
];
|
|
|
|
// Callbacks
|
|
protected $allowCallbacks = true;
|
|
protected $beforeInsert = ["checkAndADDCreatedByValue"];
|
|
protected $afterInsert = [];
|
|
protected $beforeUpdate = ["checkAndUpdateUpdatedByValue"];
|
|
protected $afterUpdate = [];
|
|
protected $beforeFind = [];
|
|
protected $afterFind = [];
|
|
protected $beforeDelete = [];
|
|
protected $afterDelete = [];
|
|
|
|
protected function checkAndADDCreatedByValue(array $data)
|
|
{
|
|
// Check if 'updated_by' value is null or empty
|
|
if (empty($data['data']['created_by'])) {
|
|
// Set 'updated_by' value to the current session user ID
|
|
$data['data']['created_by'] = get_session_userid();
|
|
}
|
|
|
|
return $data;
|
|
}
|
|
|
|
protected function checkAndUpdateUpdatedByValue(array $data)
|
|
{
|
|
// Check if 'updated_by' value is null or empty
|
|
if (empty($data['data']['updated_by'])) {
|
|
// Set 'updated_by' value to the current session user ID
|
|
$data['data']['updated_by'] = get_session_userid();
|
|
}
|
|
|
|
return $data;
|
|
}
|
|
|
|
/**
|
|
* Whether the claim (ticket) has at least one active PDF in claim_files.
|
|
*/
|
|
public function hasPdfFileForTicket($ticketId): bool
|
|
{
|
|
return $this->where('ticket_id', $ticketId)
|
|
->where('is_active', 1)
|
|
->groupStart()
|
|
->where('mime_type', 'pdf')
|
|
->orWhere('mime_type', 'application/pdf')
|
|
->groupEnd()
|
|
->countAllResults(false) > 0;
|
|
}
|
|
}
|