104 lines
3.8 KiB
PHP
104 lines
3.8 KiB
PHP
<?php
|
|
|
|
namespace Database\Seeders;
|
|
|
|
use App\Models\Audition;
|
|
use App\Models\Entry;
|
|
use App\Models\Student;
|
|
use Illuminate\Database\Seeder;
|
|
|
|
use function mt_rand;
|
|
|
|
class EntrySeeder extends Seeder
|
|
{
|
|
/**
|
|
* Run the database seeds.
|
|
*/
|
|
public function run(): void
|
|
{
|
|
$students = Student::all();
|
|
|
|
foreach ($students as $student) {
|
|
if ($student->grade > 9) {
|
|
$audition = Audition::where('maximum_grade', '=', '12')
|
|
->inRandomOrder()->first();
|
|
}
|
|
if ($student->grade == 9) {
|
|
$audition = Audition::where('maximum_grade', '>', '8')
|
|
->inRandomOrder()->first();
|
|
}
|
|
if ($student->grade == 8) {
|
|
$audition = Audition::where('maximum_grade', '=', '9')
|
|
->inRandomOrder()->first();
|
|
}
|
|
if ($student->grade == 7) {
|
|
$audition = Audition::where('maximum_grade', '=', '7')
|
|
->inRandomOrder()->first();
|
|
}
|
|
|
|
Entry::create([
|
|
'student_id' => $student->id,
|
|
'audition_id' => $audition->id,
|
|
'for_seating' => 1,
|
|
'for_advancement' => 1,
|
|
]);
|
|
|
|
if (mt_rand(1, 100) > 90) {
|
|
if ($student->grade > 9) {
|
|
$audition2 = Audition::where('maximum_grade', '=', '12')
|
|
->where('id', '!=', $audition->id)
|
|
->inRandomOrder()->first();
|
|
}
|
|
if ($student->grade == 9) {
|
|
$audition2 = Audition::where('maximum_grade', '>', '8')
|
|
->where('id', '!=', $audition->id)
|
|
->inRandomOrder()->first();
|
|
}
|
|
if ($student->grade == 8) {
|
|
$audition2 = Audition::where('maximum_grade', '=', '9')
|
|
->where('id', '!=', $audition->id)
|
|
->inRandomOrder()->first();
|
|
}
|
|
if ($student->grade == 7) {
|
|
$audition2 = Audition::where('maximum_grade', '=', '7')
|
|
->where('id', '!=', $audition->id)
|
|
->inRandomOrder()->first();
|
|
}
|
|
|
|
Entry::create([
|
|
'student_id' => $student->id,
|
|
'audition_id' => $audition2->id,
|
|
'for_seating' => 1,
|
|
'for_advancement' => 1,
|
|
]);
|
|
}
|
|
|
|
if (mt_rand(1, 100) > 90) {
|
|
if ($student->grade > 9) {
|
|
$audition3 = Audition::where('maximum_grade', '=', '12')->where('id', '!=',
|
|
$audition->id)->where('id', '!=', $audition2->id)->inRandomOrder()->first();
|
|
}
|
|
if ($student->grade == 9) {
|
|
$audition3 = Audition::where('maximum_grade', '>', '8')->where('id', '!=',
|
|
$audition->id)->where('id', '!=', $audition2->id)->inRandomOrder()->first();
|
|
}
|
|
if ($student->grade == 8) {
|
|
$audition3 = Audition::where('maximum_grade', '=', '9')->where('id', '!=',
|
|
$audition->id)->where('id', '!=', $audition2->id)->inRandomOrder()->first();
|
|
}
|
|
if ($student->grade == 7) {
|
|
$audition3 = Audition::where('maximum_grade', '=', '7')->where('id', '!=',
|
|
$audition->id)->where('id', '!=', $audition2->id)->inRandomOrder()->first();
|
|
}
|
|
|
|
Entry::create([
|
|
'student_id' => $student->id,
|
|
'audition_id' => $audition3->id,
|
|
'for_seating' => 1,
|
|
'for_advancement' => 1,
|
|
]);
|
|
}
|
|
}
|
|
}
|
|
}
|