- 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
39 lines
1.2 KiB
PHP
39 lines
1.2 KiB
PHP
<?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);
|
|
}
|
|
}
|
|
}
|