clqms-be/app/Models/Organization/DepartmentModel.php
root 2bcdf09b55 chore: repo-wide normalization + rules test coverage
Normalize formatting/line endings across configs, controllers, models, tests, and OpenAPI specs.

Update rule expression/rule engine implementation and remove obsolete RuleAction controller/model.

Add unit tests for rule expression syntax and multi-action behavior, and include docs updates.
2026-03-16 07:24:50 +07:00

41 lines
1.6 KiB
PHP

<?php
namespace App\Models\Organization;
use App\Models\BaseModel;
class DepartmentModel extends BaseModel {
protected $table = 'department';
protected $primaryKey = 'DepartmentID';
protected $allowedFields = ['DisciplineID', 'SiteID', 'DepartmentCode', 'DepartmentName', 'CreateDate', 'EndDate'];
protected $useTimestamps = true;
protected $createdField = 'CreateDate';
protected $updatedField = '';
protected $useSoftDeletes = true;
protected $deletedField = 'EndDate';
public function getDepartments($filter = []) {
$this->select('department.*, discipline.DisciplineCode, discipline.DisciplineName, site.SiteCode, site.SiteName')
->join('discipline', 'discipline.DisciplineID=department.DisciplineID', 'left')
->join('site', 'department.SiteID=site.SiteID', 'left');
if (!empty($filter['DepartmentCode'])) {
$this->like('department.DepartmentCode', $filter['DepartmentCode'], 'both');
}
if (!empty($filter['DepartmentName'])) {
$this->like('department.DepartmentName', $filter['DepartmentName'], 'both');
}
$rows = $this->findAll();
return $rows;
}
public function getDepartment($DepartmentID) {
$row = $this->select('department.*, discipline.DisciplineCode, discipline.DisciplineName, site.SiteCode, site.SiteName')
->join('discipline', 'discipline.DisciplineID=department.DisciplineID', 'left')
->join('site', 'site.SiteID=department.SiteID', 'left')
->where('department.DepartmentID', $DepartmentID)
->first();
return $row;
}
}