diff --git a/.phpstorm.meta.php b/.phpstorm.meta.php new file mode 100644 index 0000000..fe6c213 --- /dev/null +++ b/.phpstorm.meta.php @@ -0,0 +1,15 @@ +gradeColumns()->create($request->getData()); @@ -48,7 +48,7 @@ public function store(UpdateGradeColumn $request, CourseSemester $course, Group ->with("success", "Dodano kolumnę"); } - public function update(UpdateGradeColumn $request, CourseSemester $course, Group $group, GradeColumn $gradeColumn): RedirectResponse + public function update(UpdateGradeColumnRequest $request, CourseSemester $course, Group $group, GradeColumn $gradeColumn): RedirectResponse { $gradeColumn->update($request->getData()); @@ -56,7 +56,7 @@ public function update(UpdateGradeColumn $request, CourseSemester $course, Group ->with("success", "Zaktualizowano kolumnę"); } - public function storeGrade(UpdateGrade $request, CourseSemester $course, Group $group, GradeColumn $gradeColumn): RedirectResponse + public function storeGrade(UpdateGradeRequest $request, CourseSemester $course, Group $group, GradeColumn $gradeColumn): RedirectResponse { $gradeColumn->grades() ->create($request->getData()); @@ -64,7 +64,7 @@ public function storeGrade(UpdateGrade $request, CourseSemester $course, Group $ return redirect()->back(); } - public function updateGrade(UpdateGrade $request, CourseSemester $course, Group $group, GradeColumn $gradeColumn): RedirectResponse + public function updateGrade(UpdateGradeRequest $request, CourseSemester $course, Group $group, GradeColumn $gradeColumn): RedirectResponse { $grade = $gradeColumn->grades() ->where("student_id", $request->get("student_id")) diff --git a/app/Http/Controllers/Dashboard/GradeImportController.php b/app/Http/Controllers/Dashboard/GradeImportController.php new file mode 100644 index 0000000..7e022ef --- /dev/null +++ b/app/Http/Controllers/Dashboard/GradeImportController.php @@ -0,0 +1,50 @@ + CourseSemesterData::fromModel($course), + "group" => $group, + "column" => $column, + "csrfToken" => csrf_token(), + ]); + } + + public function prepare(Request $request, CourseSemester $course, Group $group, GradeColumn $column, ResponseFactory $response): JsonResponse + { + $students = $request; + + return $response->json([ + "students" => $column->refresh()->grades->map(fn(Grade $grade): array => [ + "id" => $grade->id, + "column" => [ + "id" => $column->id, + ], + "student" => [ + "id" => $grade->student->id, + "name" => $grade->student->fullName, + "indexNumber" => $grade->student->index_number, + ], + "status" => $grade->status, + "value" => $grade->value, + "imported" => rand(0, 1) > .5, + ]), + ]); + } +} diff --git a/app/Http/Requests/UpdateGradeColumn.php b/app/Http/Requests/UpdateGradeColumnRequest.php similarity index 88% rename from app/Http/Requests/UpdateGradeColumn.php rename to app/Http/Requests/UpdateGradeColumnRequest.php index 8cba059..12262f5 100644 --- a/app/Http/Requests/UpdateGradeColumn.php +++ b/app/Http/Requests/UpdateGradeColumnRequest.php @@ -6,7 +6,7 @@ use Illuminate\Foundation\Http\FormRequest; -class UpdateGradeColumn extends FormRequest +class UpdateGradeColumnRequest extends FormRequest { public function rules(): array { diff --git a/app/Http/Requests/UpdateGrade.php b/app/Http/Requests/UpdateGradeRequest.php similarity index 92% rename from app/Http/Requests/UpdateGrade.php rename to app/Http/Requests/UpdateGradeRequest.php index 72a02e9..8537748 100644 --- a/app/Http/Requests/UpdateGrade.php +++ b/app/Http/Requests/UpdateGradeRequest.php @@ -6,7 +6,7 @@ use Illuminate\Foundation\Http\FormRequest; -class UpdateGrade extends FormRequest +class UpdateGradeRequest extends FormRequest { public function rules(): array { diff --git a/app/Models/Grade.php b/app/Models/Grade.php index 8f2da74..8bbb72e 100644 --- a/app/Models/Grade.php +++ b/app/Models/Grade.php @@ -15,6 +15,10 @@ * @property string $id * @property ?boolean $status * @property ?string $value + * @property string $student_id + * @property Student $student + * @property string $grade_column_id + * @property GradeColumn $gradeColumn * @property Carbon $created_at * @property Carbon $updated_at */ @@ -27,6 +31,7 @@ class Grade extends Model "status", "value", "student_id", + "grade_column_id", ]; protected $casts = [ "status" => "boolean", diff --git a/app/Models/Group.php b/app/Models/Group.php index 5d7e747..30b5995 100644 --- a/app/Models/Group.php +++ b/app/Models/Group.php @@ -5,6 +5,7 @@ namespace Keating\Models; use Carbon\Carbon; +use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Concerns\HasUlids; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; @@ -18,6 +19,9 @@ * @property string $name * @property string $course_semester_id * @property StudyForm $form + * @property CourseSemester course + * @property Collection students + * @property Collection gradeColumns * @property Carbon $created_at * @property Carbon $updated_at */ diff --git a/app/Models/Student.php b/app/Models/Student.php index a9a5a69..20ca690 100644 --- a/app/Models/Student.php +++ b/app/Models/Student.php @@ -5,6 +5,7 @@ namespace Keating\Models; use Carbon\Carbon; +use Illuminate\Database\Eloquent\Casts\Attribute; use Illuminate\Database\Eloquent\Concerns\HasUlids; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; @@ -16,6 +17,7 @@ * @property string $first_name * @property string $surname * @property string $index_number + * @property-read string $fullName * @property Carbon $created_at * @property Carbon $updated_at */ @@ -30,6 +32,13 @@ class Student extends Model "index_number", ]; + public function fullName(): Attribute + { + return new Attribute( + get: fn(): string => $this->first_name . " " . $this->surname, + ); + } + public function groups(): BelongsToMany { return $this->belongsToMany(Group::class, "student_group"); diff --git a/app/Providers/BuilderServiceProvider.php b/app/Providers/BuilderServiceProvider.php index 8c1eb27..d9f9e16 100644 --- a/app/Providers/BuilderServiceProvider.php +++ b/app/Providers/BuilderServiceProvider.php @@ -9,9 +9,19 @@ class BuilderServiceProvider extends ServiceProvider { + /** + * all macros are also registered in .phpstorm.meta.php file + */ public function boot(): void { - Builder::macro("whereLikeUnaccentInsensitive", fn($column, $search): Builder => $this->whereRaw("unaccent($column) ILIKE unaccent(?)", ["%{$search}%"])); - Builder::macro("orWhereLikeUnaccentInsensitive", fn($column, $search): Builder => $this->orWhereRaw("unaccent($column) ILIKE unaccent(?)", ["%{$search}%"])); + Builder::macro( + "whereLikeUnaccentInsensitive", + fn($column, $search): Builder => $this->whereRaw("unaccent($column) ILIKE unaccent(?)", ["%{$search}%"]), + ); + + Builder::macro( + "orWhereLikeUnaccentInsensitive", + fn($column, $search): Builder => $this->orWhereRaw("unaccent($column) ILIKE unaccent(?)", ["%{$search}%"]), + ); } } diff --git a/codestyle.php b/codestyle.php index 3b73200..e22e93d 100644 --- a/codestyle.php +++ b/codestyle.php @@ -5,14 +5,12 @@ use Blumilk\Codestyle\Config; use Blumilk\Codestyle\Configuration\Defaults\CommonRules; use Blumilk\Codestyle\Configuration\Defaults\LaravelPaths; -use PhpCsFixer\Fixer\LanguageConstruct\ClassKeywordFixer; $paths = new LaravelPaths(); $rules = new CommonRules(); $config = new Config( paths: $paths->add("codestyle.php"), - rules: $rules->filter(ClassKeywordFixer::class), ); return $config->config(); diff --git a/database/factories/GradeColumnFactory.php b/database/factories/GradeColumnFactory.php index a37d4a5..b85a4ed 100644 --- a/database/factories/GradeColumnFactory.php +++ b/database/factories/GradeColumnFactory.php @@ -12,7 +12,7 @@ class GradeColumnFactory extends Factory public function definition(): array { return [ - "name" => fake()->asciify("***"), + "name" => fake()->numerify("W#"), "active" => fake()->boolean, "priority" => fake()->numberBetween(1, 100), "group_id" => Group::factory(), diff --git a/resources/js/Pages/Dashboard/CourseSemester/Grade/Import.vue b/resources/js/Pages/Dashboard/CourseSemester/Grade/Import.vue new file mode 100644 index 0000000..33c88da --- /dev/null +++ b/resources/js/Pages/Dashboard/CourseSemester/Grade/Import.vue @@ -0,0 +1,96 @@ + + +