add projet

This commit is contained in:
root
2026-03-05 12:29:37 -05:00
parent 8d1eef8ba8
commit 23b7db1107
9109 changed files with 1106501 additions and 73 deletions
+130
View File
@@ -0,0 +1,130 @@
<?php
namespace App\Models;
use App\Models\BaseModel;
class ClassSection extends BaseModel
{
protected $table = 'classSection'; // Correct table name
protected $primaryKey = 'id'; // Specify the primary key field
protected $fillable = [
'class_id',
'class_section_id',
'class_section_name',
'created_at',
'updated_at',
'semester',
'school_year',
];
public $timestamps = true;
const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at';
// Set default return type
// Method to get class sections with class and section names
public function getClassSections(?string $schoolYear = null, ?string $semester = null)
{
$builder = $this->select('ClassSection.*', 'classes.class_name', 'sections.section_name')
->join('classes', 'ClassSection.class_id', '=', 'classes.id')
->leftJoin('sections', 'ClassSection.class_section_id', '=', 'sections.id');
if ($schoolYear !== null) {
$builder->where('ClassSection.school_year', $schoolYear);
}
if ($semester !== null) {
$builder->where('ClassSection.semester', $semester);
}
return $builder->findAll();
}
public function getCurrentAcademicSection(int $classId, string $schoolYear, string $semester): ?array
{
return $this->newQuery()
->where('class_id', $classId)
->where('school_year', $schoolYear)
->where('semester', $semester)
->orderBy('class_section_name', 'ASC')
->first();
}
/**
* Get the parent class_id for a given class_section_id.
*
* @param int|string $classSectionId
* @return int|null class_id if found, otherwise null
*/
public function getClassId($classSectionId): ?int
{
if ($classSectionId === null || $classSectionId === '') {
return null;
}
$row = $this->select('class_id')
->where('class_section_id', $classSectionId)
->orderBy($this->primaryKey, 'DESC') // in case of duplicates, take latest
->first();
return $row ? (int) $row['class_id'] : null;
}
/**
* Get the class_section_name for a given section_id.
*
* @param int|string $sectionId
* @return string|null
*/
public function getClassSectionNameBySectionId($sectionId)
{
$result = $this->where('class_section_id', $sectionId)->first();
return $result['class_section_name'] ?? null;
}
public function getClassSectionNameByClassId($classId)
{
$result = $this->where('class_id', $classId)->first();
return $result['class_section_name'] ?? null;
}
/**
* Get section ID from class section name.
*
* @param string $classSectionName The name of the class section.
* @return mixed The section ID or null if no match is found.
*/
public function getSectionIDFromClassSectionName($classSectionName)
{
// Query the table to find the class section by its name
$result = $this->where('class_section_name', $classSectionName)
->first(); // Get the first result (assuming class section name is unique)
// Return the class section_id if the result is found, otherwise return null
return $result ? $result['class_section_id'] : null;
}
/**
* Return the base (non-letter) section row for a given class_id. E.g., '3' vs '3-A'.
*/
public function getBaseSectionByClassId(int $classId): ?array
{
// Heuristic: names without a dash are base sections (e.g., '3', 'KG', 'youth')
return $this->where('class_id', $classId)
->where("class_section_name NOT LIKE '%-%'", null, false)
->orderBy('id', 'ASC')
->first();
}
/**
* Return lettered sections for a class (e.g., '3-A','3-B',...). Ordered by name asc.
*/
public function getLetterSectionsByClassId(int $classId): array
{
return $this->where('class_id', $classId)
->like('class_section_name', '-', 'both')
->orderBy('class_section_name', 'ASC')
->findAll();
}
}