add projet
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\BaseModel;
|
||||
|
||||
class ParentAttendanceReport extends BaseModel
|
||||
{
|
||||
protected $table = 'parent_attendance_reports';
|
||||
protected $primaryKey = 'id';
|
||||
protected $useAutoIncrement = true;
|
||||
public $timestamps = true;
|
||||
const CREATED_AT = 'created_at';
|
||||
const UPDATED_AT = 'updated_at';
|
||||
protected $fillable = [
|
||||
'parent_id',
|
||||
'student_id',
|
||||
'class_section_id',
|
||||
'report_date',
|
||||
'type',
|
||||
'arrival_time',
|
||||
'dismiss_time',
|
||||
'reason',
|
||||
'semester',
|
||||
'school_year',
|
||||
'status',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
];
|
||||
|
||||
protected $validationRules = [
|
||||
'parent_id' => 'required|is_natural_no_zero',
|
||||
'student_id' => 'required|is_natural_no_zero',
|
||||
'report_date' => 'required|valid_date[Y-m-d]',
|
||||
'type' => 'required|in_list[absent,late,early_dismissal]',
|
||||
'arrival_time' => 'permit_empty|regex_match[/^\d{2}:\d{2}(:\d{2})?$/]',
|
||||
'dismiss_time' => 'permit_empty|regex_match[/^\d{2}:\d{2}(:\d{2})?$/]',
|
||||
'semester' => 'permit_empty|string',
|
||||
'school_year' => 'permit_empty|string',
|
||||
'status' => 'permit_empty|in_list[new,seen,processed]',
|
||||
];
|
||||
|
||||
public function listForDateRange(?string $startDate = null, ?string $endDate = null, ?string $schoolYear = null, ?string $semester = null): array
|
||||
{
|
||||
$b = $this->builder();
|
||||
if ($startDate) {
|
||||
$b->where('report_date >=', $startDate);
|
||||
}
|
||||
if ($endDate) {
|
||||
$b->where('report_date <=', $endDate);
|
||||
}
|
||||
if (is_string($schoolYear) && $schoolYear !== '') {
|
||||
$b->where('school_year', $schoolYear);
|
||||
}
|
||||
if (is_string($semester) && $semester !== '') {
|
||||
$b->where('semester', $semester);
|
||||
}
|
||||
|
||||
// Join student + class section labels
|
||||
$b->select('parent_attendance_reports.*, s.firstname, s.lastname, cs.class_section_name')
|
||||
->join('students s', 's.id = parent_attendance_reports.student_id', 'left')
|
||||
->join('classSection cs', 'cs.class_section_id = parent_attendance_reports.class_section_id', 'left')
|
||||
->orderBy('report_date', 'ASC')
|
||||
->orderBy('class_section_id', 'ASC')
|
||||
->orderBy('student_id', 'ASC');
|
||||
|
||||
return $b->get()->getResultArray();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user