update the new school year model

This commit is contained in:
root
2026-06-07 20:01:58 -04:00
parent 6866aedf42
commit 68a5c9edca
19 changed files with 472 additions and 32 deletions
+14 -1
View File
@@ -5,6 +5,7 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Builder;
use App\Models\BaseModel;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Support\Facades\Schema;
class SubjectCurriculum extends BaseModel
{
@@ -12,6 +13,7 @@ class SubjectCurriculum extends BaseModel
protected $fillable = [
'class_id',
'school_year',
'subject',
'unit_number',
'unit_title',
@@ -54,6 +56,16 @@ class SubjectCurriculum extends BaseModel
return $q->where('subject', $subject);
}
public function scopeForSchoolYear(Builder $q, ?string $schoolYear): Builder
{
$schoolYear = trim((string) $schoolYear);
if ($schoolYear === '' || !Schema::hasColumn($this->getTable(), 'school_year')) {
return $q;
}
return $q->where('school_year', $schoolYear);
}
public function scopeOrdered(Builder $q): Builder
{
return $q->orderBy('unit_number', 'asc')
@@ -68,11 +80,12 @@ class SubjectCurriculum extends BaseModel
/**
* legacy: getOptionsForClass($classId, $subject)
*/
public static function getOptionsForClass(int $classId, string $subject): array
public static function getOptionsForClass(int $classId, string $subject, ?string $schoolYear = null): array
{
return static::query()
->forClass($classId)
->forSubject($subject)
->forSchoolYear($schoolYear)
->ordered()
->get()
->all();