50 lines
1.3 KiB
PHP
50 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use CodeIgniter\Model;
|
|
use App\Models\Concerns\SchoolYearAutoFillTrait;
|
|
use App\Support\Enrollment\DeliberationDecision;
|
|
|
|
class StudentDecisionModel extends Model
|
|
{
|
|
use SchoolYearAutoFillTrait;
|
|
|
|
protected $table = 'student_decisions';
|
|
protected $primaryKey = 'id';
|
|
|
|
protected $allowedFields = [
|
|
'student_id',
|
|
'school_year',
|
|
'class_section_name',
|
|
'year_score',
|
|
'decision',
|
|
'deliberation_decision_standard',
|
|
'source',
|
|
'notes',
|
|
'generated_by',
|
|
];
|
|
protected $validationRules = [
|
|
'school_year' => 'required|string|max_length[9]',
|
|
];
|
|
|
|
|
|
protected $useTimestamps = true;
|
|
protected $createdField = 'created_at';
|
|
protected $updatedField = 'updated_at';
|
|
protected $beforeInsert = ['standardizeDeliberationDecision'];
|
|
protected $beforeUpdate = ['standardizeDeliberationDecision'];
|
|
|
|
protected function standardizeDeliberationDecision(array $data): array
|
|
{
|
|
if (
|
|
array_key_exists('decision', $data['data'] ?? [])
|
|
&& $this->db->fieldExists('deliberation_decision_standard', $this->table)
|
|
) {
|
|
$data['data']['deliberation_decision_standard'] = DeliberationDecision::normalize($data['data']['decision'] ?? null);
|
|
}
|
|
|
|
return $data;
|
|
}
|
|
}
|