tinyqc/app/Models/ResultCommentModel.php

39 lines
1.2 KiB
PHP
Raw Normal View History

<?php
namespace App\Models;
use App\Models\BaseModel;
class ResultCommentModel extends BaseModel
{
protected $table = 'result_comments';
protected $primaryKey = 'result_comment_id';
protected $useAutoIncrement = true;
protected $returnType = 'array';
protected $useSoftDeletes = true;
protected $useTimestamps = true;
protected $allowedFields = ['control_ref_id', 'test_ref_id', 'commonth', 'comtext'];
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);
}
}
}