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