Skip to content

Commit a8ea809

Browse files
authored
Merge pull request #3653 from codeeu/fix/show-all-open-online-featured
Show all upcoming open-online activities on /featured-activities
2 parents 791f245 + 6728bd3 commit a8ea809

5 files changed

Lines changed: 100 additions & 30 deletions

File tree

‎app/Helpers/EventHelper.php‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,9 @@ public static function getOnlineEvents()
154154
$events = Event::where([
155155
'activity_type' => 'open-online',
156156
'status' => 'APPROVED',
157-
'highlighted_status' => 'FEATURED',
158157
])
159-
->where('start_date', '>=', \Carbon\Carbon::now()->subDays(15))->where('end_date', '>=', \Illuminate\Support\Carbon::now())
160-
// ->where('start_date', '>=', Carbon::now()->subDays(30))
158+
->where('start_date', '>=', Carbon::now()->subDays(15))
159+
->where('end_date', '>=', Carbon::now())
161160
->orderBy('start_date')
162161
->get();
163162

‎app/Livewire/OnlineCalendar.php‎

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use App\Queries\CountriesQuery;
88
use Carbon\Carbon;
99
use Illuminate\Support\Facades\App;
10-
use Illuminate\Support\Facades\Log;
1110
use Livewire\Component;
1211
use Livewire\WithPagination;
1312

@@ -34,17 +33,16 @@ class OnlineCalendar extends Component
3433
private $whereClause = [
3534
'activity_type' => 'open-online',
3635
'status' => 'APPROVED',
37-
'highlighted_status' => 'FEATURED',
3836
];
37+
3938
public function mount()
4039
{
4140
$this->selectedLanguage = strtolower(App::getLocale());
4241
$this->selectedYear = Carbon::now()->year;
4342
$this->selectedMonth = Carbon::now()->month;
4443
$this->selectedDate = $this->selectedMonth.'/'.$this->selectedYear;
4544

46-
$this->months = Event::where($this->whereClause)
47-
->where('start_date', '>=', Carbon::now()->firstOfMonth())
45+
$this->months = $this->baseQuery()
4846
->orderBy('start_date')
4947
->get(['start_date'])
5048
->groupBy(function ($event) {
@@ -77,10 +75,9 @@ public function render()
7775
$this->selectedMonth = (int) ($parts[0] ?: $this->selectedMonth);
7876
$this->selectedYear = (int) ($parts[1] ?? $this->selectedYear);
7977

80-
$this->events = Event::where($this->whereClause)
78+
$this->events = $this->baseQuery()
8179
->whereMonth('start_date', $this->selectedMonth)
8280
->whereYear('start_date', $this->selectedYear)
83-
->where('start_date', '>=', Carbon::now()->firstOfMonth())
8481
->orderBy('start_date')
8582
->get();
8683

@@ -91,7 +88,7 @@ public function render()
9188

9289
if ($this->selectedLanguage !== '') {
9390
$this->filteredEvents = $this->events->filter(function ($event) {
94-
return $event->language == $this->selectedLanguage;
91+
return $this->eventMatchesLanguage($event, $this->selectedLanguage);
9592
});
9693

9794
if ($this->filteredEvents->isEmpty()) {
@@ -101,26 +98,28 @@ public function render()
10198
$this->filteredEvents = $this->events;
10299
}
103100

104-
$countries = CountriesQuery::withOnlineEvents('FEATURED');
101+
$countries = CountriesQuery::withOnlineEvents('NONE');
105102

106103
$countryNames = $this->getCountryNamesFromEvents($this->events);
107104

108105
$languages = $this->events
109-
->groupBy('language')
110-
->keys()
106+
->flatMap(function ($event) {
107+
return $event->languages ?? [];
108+
})
111109
->filter(function ($language) {
112-
return !empty($language);
110+
return ! empty($language);
113111
})
112+
->unique()
113+
->values()
114114
->map(function ($language) {
115115
return [
116116
'id' => $language,
117-
'name' => __("base.languages.{$language}")
117+
'name' => __("base.languages.{$language}"),
118118
];
119119
})
120-
->values()
121120
->prepend([
122121
'id' => '',
123-
'name' => 'All Languages'
122+
'name' => 'All Languages',
124123
])
125124
->toArray();
126125

@@ -131,6 +130,26 @@ public function render()
131130
'filteredEvents' => $this->filteredEvents->paginate(50),
132131
]);
133132
}
133+
134+
private function baseQuery()
135+
{
136+
return Event::where($this->whereClause)
137+
->where('start_date', '>=', Carbon::now()->firstOfMonth())
138+
->where('end_date', '>=', Carbon::now());
139+
}
140+
141+
private function eventMatchesLanguage($event, string $selectedLanguage): bool
142+
{
143+
$languages = $event->languages ?? [];
144+
145+
if (! is_array($languages)) {
146+
return $languages == $selectedLanguage;
147+
}
148+
149+
return in_array($selectedLanguage, $languages, true)
150+
|| in_array(strtolower($selectedLanguage), array_map('strtolower', $languages), true);
151+
}
152+
134153
/**
135154
* @return mixed
136155
*/
@@ -148,4 +167,4 @@ private function getCountryNamesFromEvents($events)
148167

149168
return $countryNames;
150169
}
151-
}
170+
}

‎resources/lang/en/snippets.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
return [
44

5-
'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!',
6-
'no-featured-activities' => 'No upcoming featured online activities at the moment.',
5+
'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!',
6+
'no-featured-activities' => 'No upcoming open online activities at the moment.',
77
'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.',
88
'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.',
99
'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?',

‎tests/Feature/EventsHelperTest.php‎

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,45 @@ final class EventsHelperTest extends TestCase
1919
#[Test]
2020
public function it_should_get_upcoming_online_events(): void
2121
{
22-
//Good ones
23-
\App\Event::factory()->create(['activity_type' => 'open-online', 'status' => 'APPROVED', 'start_date' => Carbon::now()->addDay(), 'highlighted_status' => 'FEATURED']);
24-
\App\Event::factory()->create(['activity_type' => 'open-online', 'status' => 'APPROVED', 'start_date' => Carbon::now()->addDays(10), 'highlighted_status' => 'FEATURED']);
22+
// Good ones: approved open-online and still upcoming (featured flag not required)
23+
\App\Event::factory()->create([
24+
'activity_type' => 'open-online',
25+
'status' => 'APPROVED',
26+
'start_date' => Carbon::now()->addDay(),
27+
'end_date' => Carbon::now()->addDays(2),
28+
'highlighted_status' => 'NONE',
29+
]);
30+
\App\Event::factory()->create([
31+
'activity_type' => 'open-online',
32+
'status' => 'APPROVED',
33+
'start_date' => Carbon::now()->addDays(10),
34+
'end_date' => Carbon::now()->addDays(11),
35+
'highlighted_status' => 'FEATURED',
36+
]);
2537

26-
//Bad ones
27-
\App\Event::factory()->create(['activity_type' => 'open-online', 'status' => 'APPROVED', 'start_date' => Carbon::now()->subDays(10)]);
38+
// Bad ones
39+
\App\Event::factory()->create([
40+
'activity_type' => 'open-online',
41+
'status' => 'APPROVED',
42+
'start_date' => Carbon::now()->subDays(20),
43+
'end_date' => Carbon::now()->addDays(10),
44+
]);
45+
\App\Event::factory()->create([
46+
'activity_type' => 'open-online',
47+
'status' => 'APPROVED',
48+
'start_date' => Carbon::now()->subDays(5),
49+
'end_date' => Carbon::now()->subDay(),
50+
]);
2851
\App\Event::factory()->create(['activity_type' => 'open-closed', 'status' => 'APPROVED']);
2952
\App\Event::factory()->create(['activity_type' => 'open-online', 'status' => 'PENDING']);
3053
\App\Event::factory()->create(['activity_type' => 'open-offline', 'status' => 'APPROVED']);
31-
\App\Event::factory()->create(['activity_type' => 'invite -online', 'status' => 'APPROVED', 'start_date' => Carbon::now()->addDays(10), 'highlighted_status' => 'FEATURED']);
54+
\App\Event::factory()->create([
55+
'activity_type' => 'invite-online',
56+
'status' => 'APPROVED',
57+
'start_date' => Carbon::now()->addDays(10),
58+
'end_date' => Carbon::now()->addDays(11),
59+
'highlighted_status' => 'FEATURED',
60+
]);
3261

3362
$events = EventHelper::getOnlineEvents();
3463
$this->assertCount(2, $events);

‎tests/Feature/OnlineEventsWorkflowTest.php‎

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,24 +213,47 @@ public function super_admin_menu_links_to_all_online_activities(): void
213213
}
214214

215215
#[Test]
216-
public function featured_activities_page_shows_featured_online_events_in_future_years(): void
216+
public function featured_activities_page_shows_all_upcoming_open_online_events(): void
217217
{
218218
$this->seed('RolesAndPermissionsSeeder');
219219

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

222-
$featuredEvent = \App\Event::factory()->create([
222+
$openOnlineEvent = \App\Event::factory()->create([
223223
'start_date' => $nextYear->copy()->startOfMonth()->addDays(5),
224224
'end_date' => $nextYear->copy()->startOfMonth()->addDays(6),
225225
'status' => 'APPROVED',
226226
'activity_type' => 'open-online',
227-
'highlighted_status' => 'FEATURED',
227+
'highlighted_status' => 'NONE',
228+
'language' => ['en'],
229+
'title' => 'Open Online Test Activity XYZ',
230+
]);
231+
232+
$inviteOnlyEvent = \App\Event::factory()->create([
233+
'start_date' => $nextYear->copy()->startOfMonth()->addDays(5),
234+
'end_date' => $nextYear->copy()->startOfMonth()->addDays(6),
235+
'status' => 'APPROVED',
236+
'activity_type' => 'invite-online',
237+
'highlighted_status' => 'NONE',
238+
'language' => ['en'],
239+
'title' => 'Invite Only Should Stay Hidden',
240+
]);
241+
242+
$pendingEvent = \App\Event::factory()->create([
243+
'start_date' => $nextYear->copy()->startOfMonth()->addDays(5),
244+
'end_date' => $nextYear->copy()->startOfMonth()->addDays(6),
245+
'status' => 'PENDING',
246+
'activity_type' => 'open-online',
247+
'highlighted_status' => 'NONE',
228248
'language' => ['en'],
249+
'title' => 'Pending Open Online Hidden',
229250
]);
230251

231252
$this->get('/featured-activities')
232253
->assertStatus(200)
233-
->assertSee($featuredEvent->title);
254+
->assertSee($openOnlineEvent->title)
255+
->assertDontSee($inviteOnlyEvent->title)
256+
->assertDontSee($pendingEvent->title);
234257
}
235258

236259
#[Test]

0 commit comments

Comments
 (0)