41 lines
1.4 KiB
PHP
41 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Services\ClassPreparation;
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class ClassPreparationRosterService
|
|
{
|
|
public function getClassSectionStudentCounts(string $schoolYear, string $semester, bool $limitToSemester): array
|
|
{
|
|
$query = DB::table('student_class as sc')
|
|
->select('sc.class_section_id, COUNT(DISTINCT sc.student_id) AS student_count', false)
|
|
->join('students as s', 's.id', '=', 'sc.student_id')
|
|
->where('s.is_active', 1)
|
|
->where('sc.school_year', $schoolYear);
|
|
|
|
if ($limitToSemester && $semester !== '') {
|
|
$query->where('sc.semester', $semester);
|
|
}
|
|
|
|
return $query->groupBy('sc.class_section_id')->get()->toArray();
|
|
}
|
|
|
|
public function getStudentCountForSection(string $schoolYear, string $semester, bool $limitToSemester, string $classSectionId): int
|
|
{
|
|
$query = DB::table('student_class as sc')
|
|
->select('COUNT(DISTINCT sc.student_id) AS cnt', false)
|
|
->join('students as s', 's.id', '=', 'sc.student_id')
|
|
->where('s.is_active', 1)
|
|
->where('sc.class_section_id', $classSectionId)
|
|
->where('sc.school_year', $schoolYear);
|
|
|
|
if ($limitToSemester && $semester !== '') {
|
|
$query->where('sc.semester', $semester);
|
|
}
|
|
|
|
$row = $query->first();
|
|
return (int) ($row->cnt ?? 0);
|
|
}
|
|
}
|