39 lines
1.2 KiB
PHP
39 lines
1.2 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Models;
|
||
|
|
|
||
|
|
use CodeIgniter\Model;
|
||
|
|
|
||
|
|
class ResultCommentModel extends Model
|
||
|
|
{
|
||
|
|
protected $table = 'result_comments';
|
||
|
|
protected $primaryKey = 'result_comment_id';
|
||
|
|
protected $useAutoIncrement = true;
|
||
|
|
protected $returnType = 'array';
|
||
|
|
protected $useSoftDeletes = false;
|
||
|
|
protected $allowedFields = ['result_comment_id', 'control_ref_id', 'test_ref_id', 'commonth', 'comtext'];
|
||
|
|
protected $useTimestamps = false;
|
||
|
|
|
||
|
|
public function getByControlTestMonth($controlId, $testId, $yearMonth)
|
||
|
|
{
|
||
|
|
return $this->where('control_ref_id', $controlId)
|
||
|
|
->where('test_ref_id', $testId)
|
||
|
|
->where('commonth', $yearMonth)
|
||
|
|
->first();
|
||
|
|
}
|
||
|
|
|
||
|
|
public function saveComment($data)
|
||
|
|
{
|
||
|
|
$existing = $this->where('control_ref_id', $data['control_ref_id'])
|
||
|
|
->where('test_ref_id', $data['test_ref_id'])
|
||
|
|
->where('commonth', $data['commonth'])
|
||
|
|
->first();
|
||
|
|
|
||
|
|
if ($existing) {
|
||
|
|
return $this->update($existing['result_comment_id'], $data);
|
||
|
|
} else {
|
||
|
|
return $this->insert($data);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|