Skip to content
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions app/Console/Commands/api/GermanTraits.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ private function loadJson($url)
{
$client = new \GuzzleHttp\Client();
$guzzle = $client->request('get', $url);

return json_decode($guzzle->getBody(), true);
}

Expand Down Expand Up @@ -52,7 +51,7 @@ private function createRSSItem($json, $city): void
$RSSitem->user_email = $item['user']['email'] ?? '';
$RSSitem->user_publicEmail = $item['user']['publicEmail'] ?? '';
$RSSitem->user_type = $item['user']['type']['identifier'] ??
($item['user']['type'] ?? 'invite-in-person');
($item['user']['type'] ?? 'invite-in-person');
$RSSitem->user_website = $item['user']['www'] ?? '';

// Safely get type data
Expand Down Expand Up @@ -96,8 +95,8 @@ private function createGermanEvent($city): void
'lastname' => '',
'username' => $this->organizer,
'password' => bcrypt(Str::random()),
]);

]
);
}

$event = new Event([
Expand All @@ -124,7 +123,7 @@ private function createGermanEvent($city): void
'end_date' => $this->eventEndDate,
'longitude' => $this->longitude,
'latitude' => $this->latitude,
'geoposition' => $this->latitude.','.$this->longitude,
'geoposition' => $this->latitude . ',' . $this->longitude,
'language' => 'de',
]);

Expand All @@ -151,6 +150,5 @@ private function createGermanEvent($city): void

$event->tags()->sync($tagsArray);
}

}
}
3 changes: 1 addition & 2 deletions app/Console/Commands/excel/CoderDojoEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ public function handle(): void

Excel::import(
new CoderDojoEventsImport(),
'events.xlsx',
'excel'
resource_path('excel/20250113 Events CoderDojo Belgium January - February 2025.xlsx')
);
}
}
107 changes: 71 additions & 36 deletions app/Imports/CoderDojoEventsImport.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,47 +17,82 @@ public function parseDate($date)
{
$arr = explode(',', $date);
array_shift($arr);

return implode($arr);
}

public function model(array $row): ?Model
{
$event = new Event([
'status' => 'APPROVED',
'title' => $row['activity_title'],
'slug' => str_slug($row['activity_title']),
'organizer' => $row['name_of_organisation'],
'description' => $row['description'],
'organizer_type' => $row['type_of_organisation'],
'activity_type' => $row['activity_type'],
'location' => isset($row['address']) ? $row['address'] : 'online',
'event_url' => $row['organiser_website'],
'contact_person' => !empty($row['contact_email']) ? $row['contact_email'] : '',
'user_email' => '',
'creator_id' => 132942,
'country_iso' => $row['country'],
'picture' => isset($row['image_path']) ? $row['image_path'] : '',
'pub_date' => now(),
'created' => now(),
'updated' => now(),
'codeweek_for_all_participation_code' => 'cw20-coderdojo-eu',
'start_date' => \PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($row['start_date']),
'end_date' => \PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($row['end_date']),
'geoposition' => $row['latitude'].','.$row['longitude'],
'longitude' => $row['longitude'],
'latitude' => $row['latitude'],
'language' => isset($row['language']) ? $row['language'] : 'nl',
'approved_by' => 19588,
'mass_added_for' => 'Excel',
]);

$event->save();

$event->audiences()->attach(explode(',', $row['audience_comma_separated_ids']));
$event->themes()->attach(explode(',', $row['theme_comma_separated_ids']));

return $event;
// Validate required fields
if (
empty($row['activity_title']) ||
empty($row['name_of_organisation']) ||
empty($row['description']) ||
empty($row['type_of_organisation']) ||
empty($row['activity_type']) ||
empty($row['country']) ||
empty($row['start_date']) ||
empty($row['end_date'])
) {
Log::error('Missing required fields in row');
return null;
}

try {
$event = new Event([
'status' => 'APPROVED',
'title' => trim($row['activity_title']),
'slug' => str_slug(trim($row['activity_title'])),
'organizer' => trim($row['name_of_organisation']),
'description' => trim($row['description']),
'organizer_type' => trim($row['type_of_organisation']),
'activity_type' => trim($row['activity_type']),
'location' => !empty($row['address']) ? trim($row['address']) : 'online',
'event_url' => !empty($row['organiser_website']) ? trim($row['organiser_website']) : '',
'contact_person' => !empty($row['contact_email']) ? trim($row['contact_email']) : '',
'user_email' => '',
'creator_id' => 132942,
'country_iso' => trim($row['country']),
'picture' => !empty($row['image_path']) ? trim($row['image_path']) : '',
'pub_date' => now(),
'created' => now(),
'updated' => now(),
'codeweek_for_all_participation_code' => 'cw20-coderdojo-eu',
'start_date' => \PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($row['start_date']),
'end_date' => \PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($row['end_date']),
'geoposition' => (!empty($row['latitude']) && !empty($row['longitude'])) ? $row['latitude'] . ',' . $row['longitude'] : '',
'longitude' => !empty($row['longitude']) ? trim($row['longitude']) : '',
'latitude' => !empty($row['latitude']) ? trim($row['latitude']) : '',
'language' => !empty($row['language']) ? trim($row['language']) : 'nl',
'approved_by' => 19588,
'mass_added_for' => 'Excel',
]);

$event->save();

if (!empty($row['audience_comma_separated_ids'])) {
$audiences = array_unique(array_map('trim', explode(',', $row['audience_comma_separated_ids'])));
$audiences = array_filter($audiences, function ($id) {
return is_numeric($id) && $id > 0 && $id <= 100;
});
if (!empty($audiences)) {
$event->audiences()->attach($audiences);
}
}

if (!empty($row['theme_comma_separated_ids'])) {
$themes = array_unique(array_map('trim', explode(',', $row['theme_comma_separated_ids'])));
$themes = array_filter($themes, function ($id) {
return is_numeric($id) && $id > 0 && $id <= 100;
});
if (!empty($themes)) {
$event->themes()->attach($themes);
}
}

return $event;
} catch (\Exception $e) {
Log::error('Event import failed: ' . $e->getMessage());
return null;
}
}
}
Binary file not shown.
Loading