Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Laravel 10.x Shift #342

Merged
merged 18 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion app/Console/Commands/genderizeStudents.php
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ private function remove_accents($string)
return strtr($string, $chars);
}

public function handle()
public function handle(): void
{
Student::whereNull('gender_id')->chunkById(10, function ($students) {
$query = $students->map(fn ($student) => ['id' => $student->id,
Expand Down
4 changes: 1 addition & 3 deletions app/Console/Commands/resyncCourseTimes.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@ class resyncCourseTimes extends Command

/**
* Execute the console command.
*
* @return int
*/
public function handle()
public function handle(): int
{
foreach ($this->argument('course_ids') as $courseId) {
$course = Course::find($courseId);
Expand Down
2 changes: 1 addition & 1 deletion app/Console/Commands/syncLeadStatuses.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function __construct()
parent::__construct();
}

public function handle()
public function handle(): int
{
foreach (Student::where('lead_type_id', 1)->get() as $student) {
$student->update(['lead_type_id' => null]);
Expand Down
8 changes: 2 additions & 6 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@ class Kernel extends ConsoleKernel

/**
* Define the application's command schedule.
*
* @return void
*/
protected function schedule(Schedule $schedule)
protected function schedule(Schedule $schedule): void
{
$schedule->call(function () {
Log::info('Sending attendance reminders');
Expand Down Expand Up @@ -88,10 +86,8 @@ protected function schedule(Schedule $schedule)

/**
* Register the commands for the application.
*
* @return void
*/
protected function commands()
protected function commands(): void
{
$this->load(__DIR__.'/Commands');

Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Admin/EnrollmentCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ public function setupListOperation()
'type' => 'select2_multiple',
'label' => __('Status'),
],
fn () => EnrollmentStatusType::all()->pluck('name', 'id')->toArray(),
fn () => EnrollmentStatusType::all()->pluck('name', 'id')->toArray(),
function ($values) {
foreach (json_decode($values, null, 512, JSON_THROW_ON_ERROR) as $value) {
CRUD::addClause('orWhere', 'status_id', $value);
Expand Down
3 changes: 2 additions & 1 deletion app/Http/Controllers/Admin/InstitutionCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Backpack\CRUD\app\Http\Controllers\Operations\ListOperation;
use Backpack\CRUD\app\Http\Controllers\Operations\ShowOperation;
use Backpack\CRUD\app\Http\Controllers\Operations\UpdateOperation;
use Illuminate\Http\RedirectResponse;

class InstitutionCrudController extends CrudController
{
Expand Down Expand Up @@ -52,7 +53,7 @@ protected function setupUpdateOperation()
$this->setupCreateOperation();
}

public function show($id)
public function show($id): RedirectResponse
{
return redirect()->route('student.index', ['institution_id' => $id]);
}
Expand Down
3 changes: 2 additions & 1 deletion app/Http/Controllers/Admin/InvoiceCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Request;
use Illuminate\Support\Facades\Route;
use Illuminate\View\View;
use Ramsey\Uuid\Uuid;
use ZipArchive;

Expand Down Expand Up @@ -229,7 +230,7 @@ protected function setupUpdateOperation()
]);
}

public function show($id)
public function show($id): View
{
$invoice = Invoice::findOrFail($id)->load('payments');

Expand Down
3 changes: 2 additions & 1 deletion app/Http/Controllers/Admin/LeaveCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Backpack\CRUD\app\Http\Controllers\Operations\UpdateOperation;
use Backpack\CRUD\app\Library\CrudPanel\CrudPanelFacade as CRUD;
use Carbon\Carbon;
use Illuminate\Http\RedirectResponse;

class LeaveCrudController extends CrudController
{
Expand Down Expand Up @@ -117,7 +118,7 @@ protected function setupCreateOperation()
]);
}

public function store()
public function store(): RedirectResponse
{
$request = $this->crud->getRequest();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Models\Course;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\Facades\Route;
use Illuminate\View\View;

trait ShowStudentListOperation
{
Expand All @@ -15,7 +16,7 @@ trait ShowStudentListOperation
* @param string $routeName Prefix of the route name.
* @param string $controller Name of the current CrudController.
*/
protected function setupShowStudentListRoutes($segment, $routeName, $controller)
protected function setupShowStudentListRoutes(string $segment, string $routeName, string $controller)
{
Route::get($segment.'/{id}/show', [
'as' => $routeName.'.showstudentlist',
Expand Down Expand Up @@ -44,7 +45,7 @@ protected function setupShowStudentListDefaults()
/**
* Show the view for performing the operation.
*/
public function showstudentlist($id)
public function showstudentlist($id): View
{
$course = Course::findOrFail($id);
// The current is not allowed to view the page
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Models\Course;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\Facades\Route;
use Illuminate\View\View;

trait ShowStudentPhotoRosterOperation
{
Expand All @@ -15,7 +16,7 @@ trait ShowStudentPhotoRosterOperation
* @param string $routeName Prefix of the route name.
* @param string $controller Name of the current CrudController.
*/
protected function setupShowStudentPhotoRosterRoutes($segment, $routeName, $controller)
protected function setupShowStudentPhotoRosterRoutes(string $segment, string $routeName, string $controller)
{
Route::get($segment.'/{id}/show/roster', [
'as' => $routeName.'.showstudentphotoroster',
Expand Down Expand Up @@ -44,7 +45,7 @@ protected function setupShowStudentPhotoRosterDefaults()
/**
* Show the view for performing the operation.
*/
public function showstudentphotoroster($course)
public function showstudentphotoroster($course): View
{
$course = Course::findOrFail($course);

Expand Down
3 changes: 2 additions & 1 deletion app/Http/Controllers/Admin/PaymentCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Backpack\CRUD\app\Http\Controllers\Operations\ListOperation;
use Backpack\CRUD\app\Http\Controllers\Operations\ShowOperation;
use Backpack\CRUD\app\Library\CrudPanel\CrudPanelFacade as CRUD;
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Redirect;

Expand Down Expand Up @@ -89,7 +90,7 @@ function ($value) { // if the filter is active, apply these constraints
]);
}

public function show($id)
public function show($id): RedirectResponse
{
$payment = Payment::findOrFail($id);

Expand Down
3 changes: 2 additions & 1 deletion app/Http/Controllers/Admin/ResultCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Backpack\CRUD\app\Http\Controllers\Operations\ShowOperation;
use Backpack\CRUD\app\Library\CrudPanel\CrudPanelFacade as CRUD;
use Illuminate\Support\Facades\Gate;
use Illuminate\View\View;

/**
* Class ResultCrudController
Expand Down Expand Up @@ -130,7 +131,7 @@ function () {
/**
* Display the specified resource (result for a specific enrollment).
*/
public function show($enrollment)
public function show($enrollment): View
{
// the user is allowed to view the result if they are the student,
// if they are the teacher of the course for this result
Expand Down
18 changes: 12 additions & 6 deletions app/Http/Controllers/Admin/SkillCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use Illuminate\Validation\Rule;
use Illuminate\View\View;
use League\Csv\Reader;

class SkillCrudController extends CrudController
Expand Down Expand Up @@ -116,7 +117,7 @@ protected function setupCreateOperation()
'entity' => 'level',
'attribute' => 'name',
'model' => Level::class,
]
],
]);
}

Expand Down Expand Up @@ -144,7 +145,7 @@ protected function setupImportRoutes($segment, $routeName, $controller)
]);
}

public function getImportForm()
public function getImportForm(): View
{
$this->crud->hasAccessOrFail('update');
$this->crud->setOperation('Import');
Expand All @@ -160,15 +161,17 @@ public function postImportForm(Request $request)
{
$this->crud->hasAccessOrFail('update');

if (!$request->file('file')) {
if (! $request->file('file')) {
\Alert::error('Le fichier est invalide.')->flash();

return \Redirect::to($this->crud->route);
}

try {
$csv = Reader::createFromString(content: $request->file('file')->getContent());
} catch (\Exception $e) {
\Alert::error('Le fichier est invalide.')->flash();

return \Redirect::to($this->crud->route);
}

Expand All @@ -178,25 +181,29 @@ public function postImportForm(Request $request)
// check data before doing anything
foreach ($csv as $record) {
$data = array_values($record);
if (! $data[2] || !$level = Level::firstWhere(['name' => $data[2]])) {
if (! $data[2] || ! $level = Level::firstWhere(['name' => $data[2]])) {
\Alert::error('Le fichier contient des niveaux invalides.')->flash();

return \Redirect::to($this->crud->route);
}

if (! $data[1]) {
\Alert::error('Le fichier contient des compétences invalides.')->flash();

return \Redirect::to($this->crud->route);
}

if (! $data[0] || !$skillType = SkillType::firstWhere(['shortname' => $data[0]]) ?? SkillType::firstWhere(['name' => $data[0]])) {
if (! $data[0] || ! $skillType = SkillType::firstWhere(['shortname' => $data[0]]) ?? SkillType::firstWhere(['name' => $data[0]])) {
\Alert::error('Le fichier contient des catégories de compétences invalides.')->flash();

return \Redirect::to($this->crud->route);
}
}

if ($groupName = $request->group) {
if (EvaluationType::firstWhere(['name' => $request->group])) {
\Alert::error("Ce nom est déjà utilisé pour un autre type d'évaluation.")->flash();

return \Redirect::to($this->crud->route);
}

Expand All @@ -221,5 +228,4 @@ public function postImportForm(Request $request)

return \Redirect::to($this->crud->route);
}

}
6 changes: 4 additions & 2 deletions app/Http/Controllers/Admin/StudentCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
use Backpack\CRUD\app\Library\CrudPanel\CrudPanelFacade as CRUD;
use Carbon\Carbon;
use Exception;
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;
use Illuminate\View\View;

class StudentCrudController extends CrudController
{
Expand Down Expand Up @@ -360,7 +362,7 @@ public function setupUpdateOperation()
$this->setupCreateOperation();
}

public function store()
public function store(): RedirectResponse
{
$request = $this->crud->getRequest();

Expand Down Expand Up @@ -460,7 +462,7 @@ public function update()
return $this->crud->performSaveAction($item->getKey());
}

public function show($student)
public function show($student): View
{
$student = Student::findOrFail($student);

Expand Down
3 changes: 2 additions & 1 deletion app/Http/Controllers/Admin/TeacherCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Backpack\CRUD\app\Http\Controllers\Operations\ListOperation;
use Backpack\CRUD\app\Http\Controllers\Operations\UpdateOperation;
use Backpack\CRUD\app\Library\CrudPanel\CrudPanelFacade as CRUD;
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;
use Illuminate\Validation\Rule;
Expand Down Expand Up @@ -165,7 +166,7 @@ protected function setupUpdateOperation()
$this->setupCreateOperation();
}

public function store()
public function store(): RedirectResponse
{
$request = $this->crud->validateRequest();

Expand Down
11 changes: 5 additions & 6 deletions app/Http/Controllers/AttendanceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\Facades\Log;
use Illuminate\View\View;
use Prologue\Alerts\Facades\Alert;

class AttendanceController extends Controller
Expand Down Expand Up @@ -125,8 +126,7 @@ public function store(Request $request)
*/
public function showCourse(Course $course)
{

// The current is not allowed to view the page
// The current is not allowed to view the page
if (Gate::forUser(backpack_user())->denies('view-course-attendance', $course)) {
abort(403);
}
Expand Down Expand Up @@ -161,10 +161,9 @@ public function showCourse(Course $course)
return view('attendance/course', compact('attendances', 'isadmin', 'course', 'events'));
}

public function showEvent(Event $event)
public function showEvent(Event $event): View
{

// The current is not allowed to view the page
// The current is not allowed to view the page
if (Gate::forUser(backpack_user())->denies('view-event-attendance', $event)) {
abort(403);
}
Expand All @@ -191,7 +190,7 @@ public function showEvent(Event $event)
return view('attendance/event', compact('attendances', 'event', 'attendance_types'));
}

public function showStudentAttendanceForCourse(Student $student, Request $request)
public function showStudentAttendanceForCourse(Student $student, Request $request): View
{
if ($request->query('course_id') == null) {
$selectedCourse = $student->enrollments->last()->course;
Expand Down
Loading
Loading