Skip to content
Open
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
58 changes: 29 additions & 29 deletions app/Livewire/OnlineCalendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,46 +41,46 @@ public function mount()
$this->selectedLanguage = strtolower(App::getLocale());
$this->selectedYear = Carbon::now()->year;
$this->selectedMonth = Carbon::now()->month;
$this->selectedDate = $this->selectedMonth.'/'.$this->selectedYear;

$byMonths = Event::selectRaw(
'year(start_date) year, month(start_date) month, monthname(start_date) monthname, count(*) data'
)
->where($this->whereClause)
->where('start_date', '>=', \Carbon\Carbon::now()->firstOfMonth())
->groupBy('year', 'month','monthname')
->orderBy('year', 'asc')
->orderBy('month', 'asc')
->get();

// Format months as objects
$this->months = $byMonths->map(function ($result) {
return [
'id' => $result->month.'/'.$result->year,
'name' => $result->monthname.' '.$result->year
];
})->toArray();

// Update logic for accessing first item
if (!empty($this->months)) {
$firstMonthId = $this->months[0]['id'];
$parts = explode('/', $firstMonthId);
if ($parts[0] !== $this->selectedMonth) {
$this->selectedMonth = $parts[0];
}
$this->months = Event::where($this->whereClause)
->where('start_date', '>=', Carbon::now()->firstOfMonth())
->orderBy('start_date')
->get(['start_date'])
->groupBy(function ($event) {
$date = Carbon::parse($event->start_date);

return $date->month.'/'.$date->year;
})
->map(function ($group, $id) {
$date = Carbon::parse($group->first()->start_date);

return [
'id' => $id,
'name' => $date->format('F').' '.$date->year,
];
})
->values()
->toArray();

if (! empty($this->months)) {
$parts = explode('/', $this->months[0]['id']);
$this->selectedMonth = (int) $parts[0];
$this->selectedYear = (int) ($parts[1] ?? $this->selectedYear);
$this->selectedDate = $this->selectedMonth.'/'.$this->selectedYear;
}
}

public function render()
{
$parts = explode('/', $this->selectedDate);
$this->selectedMonth = $parts[0];
$this->selectedYear = $parts[1] ?? null;
$parts = explode('/', (string) $this->selectedDate);
$this->selectedMonth = (int) ($parts[0] ?: $this->selectedMonth);
$this->selectedYear = (int) ($parts[1] ?? $this->selectedYear);

$this->events = Event::where($this->whereClause)
->whereMonth('start_date', $this->selectedMonth)
->whereYear('start_date', $this->selectedYear)
->where('start_date', '>=', \Carbon\Carbon::now()->firstOfMonth())
->where('start_date', '>=', Carbon::now()->firstOfMonth())
->orderBy('start_date')
->get();

Expand Down
6 changes: 4 additions & 2 deletions app/Livewire/OnlineEventCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,17 @@ public function promote()
$this->authorize('promote', $this->event);
Log::info('going to promote');

return $this->event->promote();
$this->event->promote();
$this->event->refresh();
}

public function feature()
{
$this->authorize('feature', $this->event);
Log::info('going to feature');

return $this->event->feature();
$this->event->feature();
$this->event->refresh();
}

public function setLanguage($language)
Expand Down
2 changes: 1 addition & 1 deletion app/Queries/CountriesQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static function withOnlineEvents($highlighted_status){
->select('events.country_iso as iso', 'countries.name', DB::raw('count(events.id) as total'), DB::raw('MIN(events.start_date) as start_date'))
->join('countries', 'events.country_iso', '=', 'countries.iso')
->where('events.status', '=', 'APPROVED')
->where('events.highlighted_status', '=', $highlighted_status)
->where('events.highlighted_status', '=', strtoupper($highlighted_status))
->whereNull('events.deleted_at')
->where('events.activity_type', 'open-online')
->where('events.start_date', '>=', Carbon::now()->subDays(15))
Expand Down
1 change: 1 addition & 0 deletions resources/lang/en/snippets.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
return [

'featured-activities' => 'Here are upcoming EU Code Week featured activities that welcome online participants. You can filter by language and month and, by clicking on “view” you’ll access all details on the activity and the contacts of the organisers. Enjoy!',
'no-featured-activities' => 'No upcoming featured online activities at the moment.',
'learn_and_teach_1' => 'A repository of resources to start or continue your coding journey and develop digital and technical skills – all available at no cost.',
'learn_and_teach_2' => 'Coding and programming are key competences that are increasingly in demand in every field, and EU Code Week wants to support you in your teaching & learning! Browse our repository and find the perfect resource to start or to continue your coding journey. All these resources are free of charge. Don’t forget that you can filter your search by title, resource type, skill level, programming language, subject, category and language.',
'teach_1' => 'Coding and programming are key competences which will open new possibilities to your students and children. Do you want to teach coding at home,in the classroom or code club?',
Expand Down
2 changes: 1 addition & 1 deletion resources/views/layout/menu-profile-dropdown.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
@role('super admin')
<li>
<img src="/images/user_menu_volunteers.svg" class="icon">
<a class="cookweek-link hover-underline" href="{{route('promoted_events')}}">
<a class="cookweek-link hover-underline" href="{{route('admin.online-events')}}">
@lang('menu.online_events')
</a>
</li>
Expand Down
4 changes: 4 additions & 0 deletions resources/views/livewire/online-calendar.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@
<div>
{{ $filteredEvents->links('vendor.pagination') }}
</div>
@else
<p class="text-center text-slate-500 text-xl py-16">
@lang('snippets.no-featured-activities')
</p>
@endif
</div>
</div>
Expand Down
2 changes: 0 additions & 2 deletions resources/views/online-calendar/admin/list.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,11 @@
<div class="mb-4">
<div class="border-b border-gray-200">
<nav class="-mb-px flex">
@role('activities admin')
@include('online-calendar.admin._tab', [
'targetParam'=>'online/list',
'route'=>'admin.online-events',
'title'=>'All Online Activities'
])
@endrole
@include('online-calendar.admin._tab', [
'targetParam'=>'online/promoted',
'route'=>'promoted_events',
Expand Down
69 changes: 69 additions & 0 deletions tests/Feature/OnlineEventsWorkflowTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,75 @@ public function ambassadors_cannot_feature_events(): void

}

#[Test]
public function super_admins_can_feature_events_from_the_online_list(): void
{
$this->seed('RolesAndPermissionsSeeder');

$superadmin = \App\User::factory()->create();
$superadmin->assignRole('super admin');

$this->signIn($superadmin);

$onlineEvent = \App\Event::factory()->create([
'start_date' => Carbon::now()->addDay(),
'end_date' => Carbon::now()->addDays(2),
'country_iso' => $superadmin->country->iso,
'status' => 'APPROVED',
'activity_type' => 'open-online',
'highlighted_status' => 'NONE',
]);

$response = $this->get('/online/list')
->assertSee($onlineEvent->title)
->assertSee('All Online Activities')
->assertSee('Accept as Featured Activity');

$response->assertStatus(200);

$onlineEvent->feature();

$this->assertEquals('FEATURED', $onlineEvent->fresh()->highlighted_status);

$this->get('/online/featured')
->assertSee($onlineEvent->title);
}

#[Test]
public function super_admin_menu_links_to_all_online_activities(): void
{
$this->seed('RolesAndPermissionsSeeder');

$superadmin = \App\User::factory()->create();
$superadmin->assignRole('super admin');

$this->signIn($superadmin);

$this->get('/')
->assertSee(route('admin.online-events'), false);
}

#[Test]
public function featured_activities_page_shows_featured_online_events_in_future_years(): void
{
$this->seed('RolesAndPermissionsSeeder');

$nextYear = Carbon::now()->addYear();

$featuredEvent = \App\Event::factory()->create([
'start_date' => $nextYear->copy()->startOfMonth()->addDays(5),
'end_date' => $nextYear->copy()->startOfMonth()->addDays(6),
'status' => 'APPROVED',
'activity_type' => 'open-online',
'highlighted_status' => 'FEATURED',
'language' => ['en'],
]);

$this->get('/featured-activities')
->assertStatus(200)
->assertSee($featuredEvent->title);
}

#[Test]
public function promoted_event_creates_notification_for_administrators(): void
{
Expand Down
Loading