tinyqc/app/Models/ResultCommentModel.php
mahdahar ff90e0eb29 Initial commit: Add CodeIgniter 4 QC application with full MVC structure
- CodeIgniter 4 framework setup with SQL Server database config
- Models: Control, Test, Dept, Result, Daily/ Monthly entry models
- Controllers: Dashboard, Control, Test, Dept, Entry, Report, API endpoints
- Views: CRUD pages with modal dialogs, dashboard, reports
- Database: Migrations for control test and daily/monthly result tables
- Legacy v1 PHP application preserved in /v1 directory
- Documentation: AGENTS.md, VIEWS_RULES.md for development guidelines
2026-01-14 16:49:27 +07:00

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);
}
}
}