tinyqc/app/Models/MonthlyCommentModel.php
mahdahar 18b85815ce refactor: standardize codebase with BaseModel and new conventions
- Add BaseModel with automatic camel/snake case conversion
- Add stringcase_helper with camel_to_snake(), snake_to_camel() functions
- Update all models to extend BaseModel for consistent data handling
- Update API controllers with standardized JSON response format
- Remove legacy v1 PHP application directory
- Consolidate documentation into AGENTS.md, delete VIEWS_RULES.md
2026-01-15 10:44:09 +07:00

39 lines
1.2 KiB
PHP

<?php
namespace App\Models;
use App\Models\BaseModel;
class MonthlyCommentModel extends BaseModel
{
protected $table = 'monthly_comment';
protected $primaryKey = 'monthly_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['monthly_comment_id'], $data);
} else {
return $this->insert($data);
}
}
}