-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into #24-news
# Conflicts: # composer.lock # routes/web.php
- Loading branch information
Showing
27 changed files
with
867 additions
and
309 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\DTOs; | ||
|
||
use App\Models\Grade; | ||
use App\Models\GradeColumn; | ||
use App\Models\Student; | ||
use Illuminate\Support\Collection; | ||
|
||
readonly class StudentData | ||
{ | ||
public function __construct( | ||
public string $student, | ||
public Collection $grades, | ||
) {} | ||
|
||
public static function fromModels(Student $student, Student $studentByIndex, Collection $gradeColumns): self | ||
{ | ||
return new self( | ||
student: $student->id === $studentByIndex->id ? $student->index_number : "", | ||
grades: self::prepareGrades($student, $gradeColumns), | ||
); | ||
} | ||
|
||
public static function prepareGrades(Student $student, Collection $gradeColumns): Collection | ||
{ | ||
return $gradeColumns->map(function (GradeColumn $column) use ($student): array { | ||
/** @var Grade $grade */ | ||
$grade = Grade::query() | ||
->where("grade_column_id", $column->id) | ||
->where("student_id", $student->id) | ||
->first(); | ||
|
||
return $grade | ||
? [ | ||
"present" => $grade->status, | ||
"value" => $grade->value, | ||
] | ||
: [ | ||
"present" => null, | ||
"value" => null, | ||
]; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Http\Controllers\Public; | ||
|
||
use App\DTOs\StudentData; | ||
use App\Http\Controllers\Controller; | ||
use App\Models\CourseSemester; | ||
use App\Models\Group; | ||
use App\Models\Semester; | ||
use App\Models\Student; | ||
use Illuminate\Database\Eloquent\Relations\BelongsTo; | ||
use Illuminate\Http\Request; | ||
use Inertia\Response; | ||
|
||
class GradeController extends Controller | ||
{ | ||
public function __invoke(Request $request, ?Semester $semester = null, ?CourseSemester $course = null, ?Group $group = null, ?string $index = null): Response | ||
{ | ||
$courses = []; | ||
$groups = []; | ||
$gradeColumns = []; | ||
$students = []; | ||
$studentByIndex = null; | ||
|
||
if ($semester) { | ||
$courses = $semester | ||
->courses() | ||
->with("course", fn(BelongsTo $query): BelongsTo => $query->select(["name", "id"])) | ||
->get(); | ||
} | ||
|
||
if ($course) { | ||
$groups = $course | ||
->groups() | ||
->get(["name", "id"]); | ||
} | ||
|
||
if ($group && $index) { | ||
$studentByIndex = $group->students() | ||
->where("index_number", $index) | ||
->first(); | ||
|
||
if ($studentByIndex?->exists()) { | ||
$gradeColumns = $group | ||
->gradeColumns() | ||
->where("active", true) | ||
->orderBy("priority") | ||
->get(); | ||
$students = $group->students() | ||
->whereNot("index_number", $index) | ||
->inRandomOrder() | ||
->take(8) | ||
->get() | ||
->push($studentByIndex) | ||
->sortBy("index_number") | ||
->map(fn(Student $student): StudentData => StudentData::fromModels($student, $studentByIndex, $gradeColumns)); | ||
} | ||
} | ||
|
||
return inertia("Public/Grade", [ | ||
"semesters" => Semester::query()->get(["name", "id"]), | ||
"semester" => $semester, | ||
"courses" => $courses, | ||
"course" => $course, | ||
"groups" => $groups, | ||
"group" => $group, | ||
"index" => $index ?? "", | ||
"gradeColumns" => $gradeColumns, | ||
"students" => $students, | ||
"indexExists" => $studentByIndex?->exists(), | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Observers; | ||
|
||
use App\Models\Grade; | ||
|
||
class GradeObserver | ||
{ | ||
public function updating(Grade $grade): void | ||
{ | ||
if ($grade->status === true && $grade->getOriginal("status") === false) { | ||
$grade->status = null; | ||
} | ||
} | ||
} |
Oops, something went wrong.