46 lines
1.1 KiB
PHP
46 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Actions\YearEndProcedures;
|
|
|
|
use App\Exceptions\AuditionAdminException;
|
|
use App\Models\HistoricalSeat;
|
|
use App\Models\Seat;
|
|
use Carbon\Carbon;
|
|
|
|
class RecordHistoricalSeats
|
|
{
|
|
public function __construct()
|
|
{
|
|
}
|
|
|
|
public function __invoke(): void
|
|
{
|
|
$this->saveSeats();
|
|
}
|
|
|
|
/**
|
|
* @throws AuditionAdminException
|
|
*/
|
|
public function saveSeats()
|
|
{
|
|
if (! auth()->user() or ! auth()->user()->is_admin) {
|
|
throw new AuditionAdminException('Only administrators may perform this action');
|
|
}
|
|
$seats = Seat::all();
|
|
if ($seats->count() > 0) {
|
|
foreach ($seats as $seat) {
|
|
$student_id = $seat->student->id;
|
|
$year = Carbon::now()->year;
|
|
$seat_description = $seat->ensemble->name.' - '.$seat->audition->name.' - '.$seat->seat;
|
|
HistoricalSeat::create([
|
|
'student_id' => $student_id,
|
|
'year' => $year,
|
|
'seat_description' => $seat_description,
|
|
]);
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|