update the new school year model
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user