diff --git a/app/Helpers/EventHelper.php b/app/Helpers/EventHelper.php index 59639afa5..88392feda 100644 --- a/app/Helpers/EventHelper.php +++ b/app/Helpers/EventHelper.php @@ -154,10 +154,9 @@ public static function getOnlineEvents() $events = Event::where([ 'activity_type' => 'open-online', 'status' => 'APPROVED', - 'highlighted_status' => 'FEATURED', ]) - ->where('start_date', '>=', \Carbon\Carbon::now()->subDays(15))->where('end_date', '>=', \Illuminate\Support\Carbon::now()) -// ->where('start_date', '>=', Carbon::now()->subDays(30)) + ->where('start_date', '>=', Carbon::now()->subDays(15)) + ->where('end_date', '>=', Carbon::now()) ->orderBy('start_date') ->get(); diff --git a/app/Livewire/OnlineCalendar.php b/app/Livewire/OnlineCalendar.php index 90af0cd58..8b67df5d9 100644 --- a/app/Livewire/OnlineCalendar.php +++ b/app/Livewire/OnlineCalendar.php @@ -7,7 +7,6 @@ use App\Queries\CountriesQuery; use Carbon\Carbon; use Illuminate\Support\Facades\App; -use Illuminate\Support\Facades\Log; use Livewire\Component; use Livewire\WithPagination; @@ -34,8 +33,8 @@ class OnlineCalendar extends Component private $whereClause = [ 'activity_type' => 'open-online', 'status' => 'APPROVED', - 'highlighted_status' => 'FEATURED', ]; + public function mount() { $this->selectedLanguage = strtolower(App::getLocale()); @@ -43,8 +42,7 @@ public function mount() $this->selectedMonth = Carbon::now()->month; $this->selectedDate = $this->selectedMonth.'/'.$this->selectedYear; - $this->months = Event::where($this->whereClause) - ->where('start_date', '>=', Carbon::now()->firstOfMonth()) + $this->months = $this->baseQuery() ->orderBy('start_date') ->get(['start_date']) ->groupBy(function ($event) { @@ -77,10 +75,9 @@ public function render() $this->selectedMonth = (int) ($parts[0] ?: $this->selectedMonth); $this->selectedYear = (int) ($parts[1] ?? $this->selectedYear); - $this->events = Event::where($this->whereClause) + $this->events = $this->baseQuery() ->whereMonth('start_date', $this->selectedMonth) ->whereYear('start_date', $this->selectedYear) - ->where('start_date', '>=', Carbon::now()->firstOfMonth()) ->orderBy('start_date') ->get(); @@ -91,7 +88,7 @@ public function render() if ($this->selectedLanguage !== '') { $this->filteredEvents = $this->events->filter(function ($event) { - return $event->language == $this->selectedLanguage; + return $this->eventMatchesLanguage($event, $this->selectedLanguage); }); if ($this->filteredEvents->isEmpty()) { @@ -101,26 +98,28 @@ public function render() $this->filteredEvents = $this->events; } - $countries = CountriesQuery::withOnlineEvents('FEATURED'); + $countries = CountriesQuery::withOnlineEvents('NONE'); $countryNames = $this->getCountryNamesFromEvents($this->events); $languages = $this->events - ->groupBy('language') - ->keys() + ->flatMap(function ($event) { + return $event->languages ?? []; + }) ->filter(function ($language) { - return !empty($language); + return ! empty($language); }) + ->unique() + ->values() ->map(function ($language) { return [ 'id' => $language, - 'name' => __("base.languages.{$language}") + 'name' => __("base.languages.{$language}"), ]; }) - ->values() ->prepend([ 'id' => '', - 'name' => 'All Languages' + 'name' => 'All Languages', ]) ->toArray(); @@ -131,6 +130,26 @@ public function render() 'filteredEvents' => $this->filteredEvents->paginate(50), ]); } + + private function baseQuery() + { + return Event::where($this->whereClause) + ->where('start_date', '>=', Carbon::now()->firstOfMonth()) + ->where('end_date', '>=', Carbon::now()); + } + + private function eventMatchesLanguage($event, string $selectedLanguage): bool + { + $languages = $event->languages ?? []; + + if (! is_array($languages)) { + return $languages == $selectedLanguage; + } + + return in_array($selectedLanguage, $languages, true) + || in_array(strtolower($selectedLanguage), array_map('strtolower', $languages), true); + } + /** * @return mixed */ @@ -148,4 +167,4 @@ private function getCountryNamesFromEvents($events) return $countryNames; } -} \ No newline at end of file +} diff --git a/resources/lang/en/snippets.php b/resources/lang/en/snippets.php index 87da6c6e8..0763d8e5b 100644 --- a/resources/lang/en/snippets.php +++ b/resources/lang/en/snippets.php @@ -2,8 +2,8 @@ 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.', + 'featured-activities' => 'Here are upcoming EU Code Week open online activities that welcome 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 open 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?', diff --git a/tests/Feature/EventsHelperTest.php b/tests/Feature/EventsHelperTest.php index 617c4f949..be2baefe8 100644 --- a/tests/Feature/EventsHelperTest.php +++ b/tests/Feature/EventsHelperTest.php @@ -19,16 +19,45 @@ final class EventsHelperTest extends TestCase #[Test] public function it_should_get_upcoming_online_events(): void { - //Good ones - \App\Event::factory()->create(['activity_type' => 'open-online', 'status' => 'APPROVED', 'start_date' => Carbon::now()->addDay(), 'highlighted_status' => 'FEATURED']); - \App\Event::factory()->create(['activity_type' => 'open-online', 'status' => 'APPROVED', 'start_date' => Carbon::now()->addDays(10), 'highlighted_status' => 'FEATURED']); + // Good ones: approved open-online and still upcoming (featured flag not required) + \App\Event::factory()->create([ + 'activity_type' => 'open-online', + 'status' => 'APPROVED', + 'start_date' => Carbon::now()->addDay(), + 'end_date' => Carbon::now()->addDays(2), + 'highlighted_status' => 'NONE', + ]); + \App\Event::factory()->create([ + 'activity_type' => 'open-online', + 'status' => 'APPROVED', + 'start_date' => Carbon::now()->addDays(10), + 'end_date' => Carbon::now()->addDays(11), + 'highlighted_status' => 'FEATURED', + ]); - //Bad ones - \App\Event::factory()->create(['activity_type' => 'open-online', 'status' => 'APPROVED', 'start_date' => Carbon::now()->subDays(10)]); + // Bad ones + \App\Event::factory()->create([ + 'activity_type' => 'open-online', + 'status' => 'APPROVED', + 'start_date' => Carbon::now()->subDays(20), + 'end_date' => Carbon::now()->addDays(10), + ]); + \App\Event::factory()->create([ + 'activity_type' => 'open-online', + 'status' => 'APPROVED', + 'start_date' => Carbon::now()->subDays(5), + 'end_date' => Carbon::now()->subDay(), + ]); \App\Event::factory()->create(['activity_type' => 'open-closed', 'status' => 'APPROVED']); \App\Event::factory()->create(['activity_type' => 'open-online', 'status' => 'PENDING']); \App\Event::factory()->create(['activity_type' => 'open-offline', 'status' => 'APPROVED']); - \App\Event::factory()->create(['activity_type' => 'invite -online', 'status' => 'APPROVED', 'start_date' => Carbon::now()->addDays(10), 'highlighted_status' => 'FEATURED']); + \App\Event::factory()->create([ + 'activity_type' => 'invite-online', + 'status' => 'APPROVED', + 'start_date' => Carbon::now()->addDays(10), + 'end_date' => Carbon::now()->addDays(11), + 'highlighted_status' => 'FEATURED', + ]); $events = EventHelper::getOnlineEvents(); $this->assertCount(2, $events); diff --git a/tests/Feature/OnlineEventsWorkflowTest.php b/tests/Feature/OnlineEventsWorkflowTest.php index 6808892d1..26dbc7851 100644 --- a/tests/Feature/OnlineEventsWorkflowTest.php +++ b/tests/Feature/OnlineEventsWorkflowTest.php @@ -213,24 +213,47 @@ public function super_admin_menu_links_to_all_online_activities(): void } #[Test] - public function featured_activities_page_shows_featured_online_events_in_future_years(): void + public function featured_activities_page_shows_all_upcoming_open_online_events(): void { $this->seed('RolesAndPermissionsSeeder'); $nextYear = Carbon::now()->addYear(); - $featuredEvent = \App\Event::factory()->create([ + $openOnlineEvent = \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', + 'highlighted_status' => 'NONE', + 'language' => ['en'], + 'title' => 'Open Online Test Activity XYZ', + ]); + + $inviteOnlyEvent = \App\Event::factory()->create([ + 'start_date' => $nextYear->copy()->startOfMonth()->addDays(5), + 'end_date' => $nextYear->copy()->startOfMonth()->addDays(6), + 'status' => 'APPROVED', + 'activity_type' => 'invite-online', + 'highlighted_status' => 'NONE', + 'language' => ['en'], + 'title' => 'Invite Only Should Stay Hidden', + ]); + + $pendingEvent = \App\Event::factory()->create([ + 'start_date' => $nextYear->copy()->startOfMonth()->addDays(5), + 'end_date' => $nextYear->copy()->startOfMonth()->addDays(6), + 'status' => 'PENDING', + 'activity_type' => 'open-online', + 'highlighted_status' => 'NONE', 'language' => ['en'], + 'title' => 'Pending Open Online Hidden', ]); $this->get('/featured-activities') ->assertStatus(200) - ->assertSee($featuredEvent->title); + ->assertSee($openOnlineEvent->title) + ->assertDontSee($inviteOnlyEvent->title) + ->assertDontSee($pendingEvent->title); } #[Test]