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
39 changes: 27 additions & 12 deletions app/Imports/CoderDojoEventsImport.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public function parseDate($date)

public function model(array $row): ?Model
{
// Validate required fields
if (
empty($row['activity_title']) ||
empty($row['name_of_organisation']) ||
Expand All @@ -38,7 +37,16 @@ public function model(array $row): ?Model
}

try {
$event = new Event([
$latitude = !empty($row['latitude']) ? trim($row['latitude']) : '';
$longitude = !empty($row['longitude']) ? trim($row['longitude']) : '';
$start_date = \PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($row['start_date']);

// Check for existing event
$existingEvent = Event::where('title', trim($row['activity_title']))
->where('start_date', $start_date)
->first();

$eventData = [
'status' => 'APPROVED',
'title' => trim($row['activity_title']),
'slug' => str_slug(trim($row['activity_title'])),
Expand All @@ -54,28 +62,35 @@ public function model(array $row): ?Model
'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']),
'start_date' => $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']) : '',
'geoposition' => ($latitude && $longitude) ? "$longitude,$latitude" : '',
'longitude' => $longitude,
'latitude' => $latitude,
'language' => !empty($row['language']) ? trim($row['language']) : 'nl',
'approved_by' => 19588,
'mass_added_for' => 'Excel',
]);
];

$event->save();
if ($existingEvent) {
Log::info('Updating existing event: ' . $existingEvent->id);
$existingEvent->update($eventData);
$event = $existingEvent;
} else {
$eventData['created'] = now();
$event = new Event($eventData);
$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);
$event->audiences()->sync($audiences);
}
}

Expand All @@ -85,7 +100,7 @@ public function model(array $row): ?Model
return is_numeric($id) && $id > 0 && $id <= 100;
});
if (!empty($themes)) {
$event->themes()->attach($themes);
$event->themes()->sync($themes);
}
}

Expand All @@ -95,4 +110,4 @@ public function model(array $row): ?Model
return null;
}
}
}
}
37 changes: 23 additions & 14 deletions resources/views/event/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<div class="text">
<div class="edit-button">
@can('edit', $event)
<a class="codeweek-action-link-button mr-2"
<a class="mr-2 codeweek-action-link-button"
href="{{route('edit_event',$event->id)}}">@lang('eventdetails.edit')</a>
@endcan

Expand Down Expand Up @@ -77,7 +77,7 @@

<div class="codeweek-display-field">

<label class="block text-orange-500 font-bold mb-1 md:mb-0 pr-4" for="inline-full-name">
<label class="block pr-4 mb-1 font-bold text-orange-500 md:mb-0" for="inline-full-name">
@lang('eventdetails.organised_by')
</label>
<p>
Expand All @@ -91,7 +91,7 @@


<div class="codeweek-display-field">
<label class="block text-orange-500 font-bold mb-1 md:mb-0 pr-4"
<label class="block pr-4 mb-1 font-bold text-orange-500 md:mb-0"
for="activity_type">@lang('event.activitytype.label')</label>
<p>
@if($event->activity_type && $event->activity_type !== 'other')
Expand All @@ -105,35 +105,35 @@

@if($event->contact_person)
<div class="codeweek-display-field">
<label class="block text-orange-500 font-bold mb-1 md:mb-0 pr-4"
<label class="block pr-4 mb-1 font-bold text-orange-500 md:mb-0"
for="inline-full-name">@lang('eventdetails.contact_email')</label>
<p><a href="mailto:{{ $event->contact_person }}">{{ $event->contact_person }}</a></p>
</div>
@endif

@if($event->language)
<div class="codeweek-display-field">
<label class="block text-orange-500 font-bold mb-1 md:mb-0 pr-4"
<label class="block pr-4 mb-1 font-bold text-orange-500 md:mb-0"
for="inline-full-name">@lang('resources.Languages')</label>
<p>@lang("base.languages.{$event->language}")</p>
</div>
@endif

<div class="codeweek-display-field">
<label class="block text-orange-500 font-bold mb-1 md:mb-0 pr-4"
<label class="block pr-4 mb-1 font-bold text-orange-500 md:mb-0"
for="inline-full-name">@lang('eventdetails.happening_at')</label>
<p>{!! $event->location !!}</p>
</div>

<div class="codeweek-display-field">
<label class="block text-orange-500 font-bold mb-1 md:mb-0 pr-4"
<label class="block pr-4 mb-1 font-bold text-orange-500 md:mb-0"
for="inline-full-name">@lang('eventdetails.description')</label>
<p>{!! $event->description !!}</p>
</div>

@if($event->event_url)
<div class="codeweek-display-field">
<label class="block text-orange-500 font-bold mb-1 md:mb-0 pr-4"
<label class="block pr-4 mb-1 font-bold text-orange-500 md:mb-0"
for="inline-full-name">@lang('eventdetails.more_info')</label>
<p><a href="{{ $event->event_url }}" target="_blank">{{ $event->event_url }}</a></p>
</div>
Expand All @@ -142,7 +142,7 @@

@if($event->audiences->count())
<div class="codeweek-display-field" style="margin-bottom: 0;">
<label class="block text-orange-500 font-bold mb-1 md:mb-0 pr-4"
<label class="block pr-4 mb-1 font-bold text-orange-500 md:mb-0"
for="inline-full-name">@lang('eventdetails.audience')</label>
<div class="itens">
<ul class="event-list">
Expand All @@ -158,7 +158,7 @@

@if($event->themes->count())
<div class="codeweek-display-field" style="margin-bottom: 0;">
<label class="block text-orange-500 font-bold mb-1 md:mb-0 pr-4"
<label class="block pr-4 mb-1 font-bold text-orange-500 md:mb-0"
for="inline-full-name">@lang('eventdetails.themes')</label>
<div class="itens">
<ul class="event-list">
Expand All @@ -174,7 +174,7 @@

@if($event->tags->count())
<div class="codeweek-display-field" style="margin-bottom: 0;">
<label class="block text-orange-500 font-bold mb-1 md:mb-0 pr-4"
<label class="block pr-4 mb-1 font-bold text-orange-500 md:mb-0"
for="inline-full-name">@lang('eventdetails.tags')</label>
<div class="itens">
<ul class="event-list">
Expand All @@ -194,14 +194,14 @@
@can('edit', $event)
@if($event->codeweek_for_all_participation_code)
<div class="codeweek-display-field">
<label class="block text-orange-500 font-bold mb-1 md:mb-0 pr-4"
<label class="block pr-4 mb-1 font-bold text-orange-500 md:mb-0"
for="inline-full-name">@lang('event.codeweek_for_all_participation_code.title')</label>
<p>{{ $event->codeweek_for_all_participation_code }}</p>
</div>
@endif

<div class="codeweek-display-field">
<label class="block text-orange-500 font-bold mb-1 md:mb-0 pr-4"
<label class="block pr-4 mb-1 font-bold text-orange-500 md:mb-0"
for="inline-full-name">@lang('event.last_update')</label>
<p>
{{Carbon\Carbon::parse($event->updated_at)->isoFormat('LLLL')}}
Expand All @@ -211,7 +211,7 @@


<div class="codeweek-display-field">
<label class="block text-orange-500 font-bold mb-1 md:mb-0 pr-4"
<label class="block pr-4 mb-1 font-bold text-orange-500 md:mb-0"
for="inline-full-name">@lang('eventdetails.share')</label>
<div class="share-event-wrapper">
<div class="fb-like"
Expand Down Expand Up @@ -241,6 +241,15 @@

<div id="events-show-map" style="margin-bottom: 20px;"></div>

<div class="codeweek-display-field">
<label class="block pr-4 mb-1 font-bold text-orange-500 md:mb-0">Location Coordinates</label>
<p>
Longitude: {{ $event->longitude }}<br>
Latitude: {{ $event->latitude }}<br>
Geoposition: {{ $event->geoposition }}
</p>
</div>

<h2 style="margin-top: 40px; margin-bottom: 30px;">@lang('eventdetails.nearby_upcoming_events')</h2>
<div class="codeweek-grid-layout">
@foreach($event->getClosest() as $evt)
Expand Down
Loading