diff --git a/app/Exceptions/InvalidClassException.php b/app/Exceptions/InvalidClassException.php new file mode 100644 index 00000000..8a67380c --- /dev/null +++ b/app/Exceptions/InvalidClassException.php @@ -0,0 +1,10 @@ +search%"]); } else { //filter column - $query = call_user_func_array([$query, 'orWhere'], [$table.'.'.($column['columnName'] ?? $column['property']) ?? 'id', 'LIKE', "%$this->search%"]); + $query = call_user_func_array([$query, 'orWhere'], [$table.'.'.($column['columnName'] ?? $column['property']), 'LIKE', "%$this->search%"]); } } diff --git a/app/Models/AcademicYear.php b/app/Models/AcademicYear.php index 03437f6c..60ffe662 100755 --- a/app/Models/AcademicYear.php +++ b/app/Models/AcademicYear.php @@ -2,37 +2,39 @@ namespace App\Models; -use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Casts\Attribute; +use Illuminate\Database\Eloquent\Factories\HasFactory; +use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\BelongsToMany; +use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\HasManyThrough; class AcademicYear extends Model { use HasFactory; + public $name; + protected $fillable = [ 'start_year', 'stop_year', 'school_id', ]; - public function name() - { - return "$this->start_year - $this->stop_year"; - } - - public function getNameAttribute() + protected function name() : Attribute { - return "$this->start_year - $this->stop_year"; + return Attribute::make( + get: fn() => "$this->start_year - $this->stop_year", + ); } - public function school() + public function school() : BelongsTo { return $this->belongsTo(School::class); } - public function semesters() + public function semesters() : HasMany { return $this->hasMany(Semester::class); } diff --git a/app/Models/Exam.php b/app/Models/Exam.php index a135553a..f3d708ee 100755 --- a/app/Models/Exam.php +++ b/app/Models/Exam.php @@ -5,6 +5,8 @@ use Carbon\Carbon; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\BelongsTo; +use Illuminate\Database\Eloquent\Relations\HasMany; class Exam extends Model { @@ -33,25 +35,13 @@ class Exam extends Model 'publish_result' => 'boolean', ]; - public function semester() + public function semester() : BelongsTo { return $this->belongsTo(Semester::class); } - public function examSlots() + public function examSlots() : HasMany { return $this->hasMany(ExamSlot::class); } - - //accessor for start date - public function getStartDateAttribute($value) - { - return Carbon::parse($value)->format('Y-m-d'); - } - - //accessor for stop date - public function getStopDateAttribute($value) - { - return Carbon::parse($value)->format('Y-m-d'); - } } diff --git a/app/Models/School.php b/app/Models/School.php index d95c81eb..a8e611f6 100755 --- a/app/Models/School.php +++ b/app/Models/School.php @@ -2,8 +2,11 @@ namespace App\Models; -use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\HasOne; +use Illuminate\Database\Eloquent\Relations\HasMany; +use Illuminate\Database\Eloquent\Factories\HasFactory; +use Illuminate\Database\Eloquent\Relations\HasManyThrough; class School extends Model { @@ -13,57 +16,50 @@ class School extends Model 'name', 'address', 'code', 'initials', 'phone', 'email', ]; - public function classGroups() + /** + * Get all the class groups in the school + */ + public function classGroups() : HasMany { return $this->hasMany(ClassGroup::class); } /** * Get all of the users for the School. - * - * @return \Illuminate\Database\Eloquent\Relations\HasMany */ - public function users() + public function users() : HasMany { return $this->hasMany(User::class); } /** * Get all of the MyClasses for the School. - * - * @return \Illuminate\Database\Eloquent\Relations\HasManyThrough */ - public function myClasses() + public function myClasses() : HasManyThrough { return $this->hasManyThrough(MyClass::class, ClassGroup::class); } /** * Get the AcademicYears for the School. - * - * @return \Illuminate\Database\Eloquent\Relations\HasOne */ - public function academicYears() + public function academicYears() : HasMany { return $this->hasMany(AcademicYear::class); } /** * Get the academicYear associated with the School. - * - * @return \Illuminate\Database\Eloquent\Relations\HasOne */ - public function academicYear() + public function academicYear() : HasOne { return $this->hasOne(AcademicYear::class, 'id', 'academic_year_id'); } /** * Get the semester associated with the School. - * - * @return \Illuminate\Database\Eloquent\Relations\HasOne */ - public function semester() + public function semester() : HasOne { return $this->hasOne(Semester::class, 'id', 'semester_id'); } diff --git a/app/Models/Timetable.php b/app/Models/Timetable.php index 234818c0..c028379e 100755 --- a/app/Models/Timetable.php +++ b/app/Models/Timetable.php @@ -3,6 +3,8 @@ namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; +use Illuminate\Database\Eloquent\Relations\BelongsTo; +use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\Pivot; class Timetable extends Pivot @@ -18,22 +20,17 @@ class Timetable extends Pivot 'my_class_id', ]; - public function semester() + public function semester() : BelongsTo { return $this->belongsTo(Semester::class); } - public function MyClass() + public function myClass() : BelongsTo { return $this->belongsTo(MyClass::class); } - /** - * Get all of the timeSlots for the Timetable. - * - * @return \Illuminate\Database\Eloquent\Relations\HasMany - */ - public function timeSlots() + public function timeSlots() : HasMany { return $this->hasMany(TimetableTimeSlot::class, 'timetable_id'); } diff --git a/app/Services/AcademicYear/AcademicYearService.php b/app/Services/AcademicYear/AcademicYearService.php index b811502e..42ef0484 100755 --- a/app/Services/AcademicYear/AcademicYearService.php +++ b/app/Services/AcademicYear/AcademicYearService.php @@ -4,6 +4,7 @@ use App\Models\AcademicYear; use App\Services\School\SchoolService; +use Illuminate\Database\Eloquent\Collection; class AcademicYearService { @@ -19,10 +20,8 @@ public function __construct(SchoolService $schoolService) /** * Get all academic years. - * - * @return \Illuminate\Database\Eloquent\Collection|static[] */ - public function getAllAcademicYears() + public function getAllAcademicYears() : Collection|static { return AcademicYear::where('school_id', auth()->user()->school_id)->get(); } @@ -31,50 +30,45 @@ public function getAllAcademicYears() * Get academic year by Id. * *@param int $id - * - * @return App\Models\AcademicYear */ - public function getAcademicYearById($id) + public function getAcademicYearById($id) : AcademicYear { - return AcademicYear::where('id', $id)->first(); + return AcademicYear::find($id); } /** * Create academic year. * * @param array|Collection $records - * - * @return AcademicYear */ - public function createAcademicYear($records) + public function createAcademicYear($records) : AcademicYear { $records['school_id'] = auth()->user()->school_id; $academicYear = AcademicYear::create($records); + + return $academicYear; } /** * Update Academic Year. * * @param array|Collection $records - * - * @return void */ - public function updateAcademicYear(AcademicYear $academicYear, $records) + public function updateAcademicYear(AcademicYear $academicYear, $records) : AcademicYear { $academicYear->start_year = $records['start_year']; $academicYear->stop_year = $records['stop_year']; $academicYear->save(); + + return $academicYear; } /** * Delete an academic year. - * - * - * @return void */ - public function deleteAcademicYear(AcademicYear $academicYear) + public function deleteAcademicYear(AcademicYear $academicYear) : bool|null { - $academicYear->delete(); + return $academicYear->delete(); } /** @@ -82,10 +76,8 @@ public function deleteAcademicYear(AcademicYear $academicYear) * * @param int $academicYearId * @param int $schoolId - * - * @return void */ - public function setAcademicYear($academicYearId, $schoolId = null) + public function setAcademicYear($academicYearId, $schoolId = null) : bool { if (!isset($schoolId)) { $schoolId = auth()->user()->school_id; @@ -94,6 +86,6 @@ public function setAcademicYear($academicYearId, $schoolId = null) $school->academic_year_id = $academicYearId; //set semester id to null $school->semester_id = null; - $school->save(); + return $school->save(); } } diff --git a/app/Services/Exam/ExamService.php b/app/Services/Exam/ExamService.php index f8872212..6055c234 100755 --- a/app/Services/Exam/ExamService.php +++ b/app/Services/Exam/ExamService.php @@ -2,11 +2,12 @@ namespace App\Services\Exam; -use App\Exceptions\EmptyRecordsException; use App\Models\Exam; -use App\Models\Semester; -use App\Models\Subject; use App\Models\User; +use App\Models\Subject; +use App\Models\Semester; +use App\Exceptions\EmptyRecordsException; +use Illuminate\Database\Eloquent\Collection; class ExamService { diff --git a/app/Traits/MarkTabulationTrait.php b/app/Traits/MarkTabulationTrait.php index c5ca8e6e..d447b6db 100644 --- a/app/Traits/MarkTabulationTrait.php +++ b/app/Traits/MarkTabulationTrait.php @@ -28,9 +28,9 @@ trait MarkTabulationTrait public Collection $students; /** - * @param Collection $subjects - * @param Collection $students - * @param Collection $examSlots + * @param Collection $subjects + * @param Collection $students + * @param Collection $examSlots * * @return Collection */ diff --git a/resources/views/livewire/create-semester-form.blade.php b/resources/views/livewire/create-semester-form.blade.php index b867d11e..f7f353ff 100644 --- a/resources/views/livewire/create-semester-form.blade.php +++ b/resources/views/livewire/create-semester-form.blade.php @@ -1,6 +1,6 @@
-

Create semester in session {{auth()->user()->school->academicYear->name()}}

+

Create semester in session {{auth()->user()->school->academicYear->name}}

diff --git a/resources/views/livewire/layouts/header.blade.php b/resources/views/livewire/layouts/header.blade.php index b872486e..6230ab34 100644 --- a/resources/views/livewire/layouts/header.blade.php +++ b/resources/views/livewire/layouts/header.blade.php @@ -35,7 +35,7 @@

{{auth()->user()->name}}

@isset(auth()->user()->school) - Academic year: {{auth()->user()->school->academicYear?->name()}}
+ Academic year: {{auth()->user()->school->academicYear?->name}}
Semester: {{auth()->user()->school->semester?->name}} @endif

diff --git a/resources/views/livewire/show-school.blade.php b/resources/views/livewire/show-school.blade.php index d291fa12..0b1eaf8f 100644 --- a/resources/views/livewire/show-school.blade.php +++ b/resources/views/livewire/show-school.blade.php @@ -17,7 +17,7 @@ 'Phone', $school->phone ], [ - 'Current Academic Year', $school?->academicYear?->name() + 'Current Academic Year', $school?->academicYear?->name ], [ 'Current Semester', $school?->semester?->name diff --git a/resources/views/pages/academic-year/edit.blade.php b/resources/views/pages/academic-year/edit.blade.php index 02dba43e..17ce89c4 100644 --- a/resources/views/pages/academic-year/edit.blade.php +++ b/resources/views/pages/academic-year/edit.blade.php @@ -1,11 +1,11 @@ @extends('layouts.app', ['breadcrumbs' => [ ['href'=> route('dashboard'), 'text'=> 'Dashboard'], ['href'=> route('academic-years.index'), 'text' => 'academic-years' , ], - ['href'=> route('academic-years.edit', $academicYear->id), 'text'=> "Edit {$academicYear->name()}" , 'active'] + ['href'=> route('academic-years.edit', $academicYear->id), 'text'=> "Edit {$academicYear->name}" , 'active'] ]]) -@section('title', __("Edit {$academicYear->name()}")) +@section('title', __("Edit {$academicYear->name}")) -@section('page_heading', __("Edit {$academicYear->name()}")) +@section('page_heading', __("Edit {$academicYear->name}")) @section('content') @livewire('edit-academic-year-form', ['academicYear' => $academicYear]) diff --git a/resources/views/pages/academic-year/show.blade.php b/resources/views/pages/academic-year/show.blade.php index 9e154fc8..161170f2 100644 --- a/resources/views/pages/academic-year/show.blade.php +++ b/resources/views/pages/academic-year/show.blade.php @@ -1,7 +1,7 @@ @extends('layouts.app', ['breadcrumbs' => [ ['href'=> route('dashboard'), 'text'=> 'Dashboard'], ['href'=> route('academic-years.index'), 'text'=> 'academic years'], - ['href'=> route('academic-years.show', $academicYear->id), 'text'=> "View {$academicYear->name()}", 'active'], + ['href'=> route('academic-years.show', $academicYear->id), 'text'=> "View {$academicYear->name}", 'active'], ]]) @section('title', __("View {$academicYear->name}"))