- 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
42 lines
1.2 KiB
PHP
42 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Models\BaseModel;
|
|
|
|
class ControlModel extends BaseModel
|
|
{
|
|
protected $table = 'dict_controls';
|
|
protected $primaryKey = 'control_id';
|
|
protected $useAutoIncrement = true;
|
|
protected $returnType = 'array';
|
|
protected $useSoftDeletes = true;
|
|
protected $useTimestamps = true;
|
|
protected $allowedFields = ['dept_ref_id', 'name', 'lot', 'producer', 'expdate'];
|
|
|
|
public function getByDept($deptId)
|
|
{
|
|
return $this->where('dept_ref_id', $deptId)->findAll();
|
|
}
|
|
|
|
public function getWithDept()
|
|
{
|
|
$builder = $this->db->table('dict_controls c');
|
|
$builder->select('c.*, d.name as dept_name');
|
|
$builder->join('dict_depts d', 'd.dept_id = c.dept_ref_id', 'left');
|
|
return $builder->get()->getResultArray();
|
|
}
|
|
|
|
public function getActiveByDate($date, $deptId = null)
|
|
{
|
|
$builder = $this->db->table('dict_controls c');
|
|
$builder->select('c.*');
|
|
$builder->where('c.expdate >=', $date);
|
|
if ($deptId) {
|
|
$builder->where('c.dept_ref_id', $deptId);
|
|
}
|
|
$builder->orderBy('c.name', 'ASC');
|
|
return $builder->get()->getResultArray();
|
|
}
|
|
}
|