Files
vkv/database/seeders/ContestSeeder.php
Zdeněk Burda 41e3ce6f25 Initial commit
2026-01-09 21:26:40 +01:00

98 lines
3.5 KiB
PHP

<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use App\Models\Contest;
use App\Models\ContestParameter;
use App\Models\Band;
use App\Models\Category;
use App\Models\PowerCategory;
use App\Models\EvaluationRuleSet;
class ContestSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
Schema::disableForeignKeyConstraints();
DB::table('contests')->truncate();
DB::table('contests_bands')->truncate();
DB::table('contests_categories')->truncate();
DB::table('contests_power_categories')->truncate();
DB::table('contests_parameters')->truncate();
Schema::enableForeignKeyConstraints();
$bands = Band::all()->pluck('id')->toArray();
$categories = Category::all()->pluck('id')->toArray();
$powerCategories = PowerCategory::all()->pluck('id')->toArray();
$defaultRuleSetId = EvaluationRuleSet::where('code', 'default_vhf_compat')->value('id');
// základní parametry dle vzoru (Y/N -> bool)
$baseParams = [
'ignore_slash_part' => true,
'ignore_third_part' => true,
'letters_in_rst' => true,
'discard_qso_rec_diff_call' => true,
'discard_qso_sent_diff_call' => false,
'discard_qso_rec_diff_rst' => true,
'discard_qso_sent_diff_rst' => false,
'discard_qso_rec_diff_code' => true,
'discard_qso_sent_diff_code' => false,
'unique_qso' => false,
'time_tolerance' => 600,
];
for ($i = 1; $i <= 2; $i++) {
$contest = new Contest();
// lokalizované položky přes Spatie HasTranslations
$contest->setTranslations('name', [
'cs' => "VKV závod {$i}",
'en' => "VHF Contest {$i}",
]);
$contest->setTranslations('description', [
'cs' => "Oficiální VKV závod číslo {$i}.",
'en' => "The official VHF Contest number {$i}.",
]);
// nelokalizovaná data
$contest->evaluator = 'Český radioklub';
$contest->email = 'crk@crk.cz';
$contest->email2 = null;
$contest->is_mcr = true;
$contest->is_sixhr = $i % 2 === 0;
$contest->is_active = $i !== 5; // poslední neaktivní
$contest->start_time = '14:00:00';
$contest->duration = 24;
$contest->logs_deadline_days = 3;
$contest->rule_set_id = $defaultRuleSetId;
$contest->save();
// navázání všech pásem
$contest->bands()->attach($bands);
// navázání všech kategorií
$contest->categories()->attach($categories);
// navázání všech výkonových kategorií
$contest->powerCategories()->attach($powerCategories);
// contest parameters pro oba log typy
foreach (['STANDARD', 'CHECK'] as $logType) {
ContestParameter::create(array_merge(
$baseParams,
[
'contest_id' => $contest->id,
'log_type' => $logType,
]
));
}
}
}
}