Skip to content

Commit

Permalink
Modified how we create events for development
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamKyle committed Oct 26, 2024
1 parent bcab8a2 commit a20456b
Showing 1 changed file with 53 additions and 13 deletions.
66 changes: 53 additions & 13 deletions app/Console/DevelopmentCommands/CreateEventsForDevelopment.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,46 @@ class CreateEventsForDevelopment extends Command
*/
public function handle()
{
$options = EventType::getOptionsForSelect();
$options['all'] = 'All Events';

foreach (EventType::getOptionsForSelect() as $eventType => $eventName) {
$selectedEvent = $this->choice(
'Which event do you want to create?',
array_values($options)
);

if ($eventType === EventType::RAID_EVENT) {
$raid = Raid::first();
if ($selectedEvent === 'All Events') {
$this->createAllEvents($options);
} else {
$eventType = array_search($selectedEvent, $options);

ScheduledEvent::create([
'event_type' => $eventType,
'raid_id' => $raid->id,
'start_date' => now()->addMinutes(5),
'end_date' => now()->addMinutes(10),
'description' => $eventName,
'currently_running' => false,
]);

continue;
if ($eventType !== false) {
$this->createEvent($eventType, $selectedEvent);
} else {
$this->error('Invalid event type selected.');
}
}
}

/**
* Create a specific event.
*/
private function createEvent(string $eventType, string $eventName): void
{
if ($eventType === EventType::RAID_EVENT) {
$raid = Raid::first();

ScheduledEvent::create([
'event_type' => $eventType,
'raid_id' => $raid->id,
'start_date' => now()->addMinutes(5),
'end_date' => now()->addMinutes(10),
'description' => $eventName,
'currently_running' => false,
]);

$this->info("Created RAID event: {$eventName}");
} else {
ScheduledEvent::create([
'event_type' => $eventType,
'raid_id' => null,
Expand All @@ -54,6 +76,24 @@ public function handle()
'description' => $eventName,
'currently_running' => false,
]);

$this->info("Created event: {$eventName}");
}
}

/**
* Create all available events.
*/
private function createAllEvents(array $options): void
{
foreach ($options as $eventType => $eventName) {
if ($eventName === 'All Events') {
continue;
}

$this->createEvent($eventType, $eventName);
}

$this->info('All events have been created successfully.');
}
}

0 comments on commit a20456b

Please sign in to comment.