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
5 changes: 2 additions & 3 deletions app/Helpers/EventHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
49 changes: 34 additions & 15 deletions app/Livewire/OnlineCalendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -34,17 +33,16 @@ class OnlineCalendar extends Component
private $whereClause = [
'activity_type' => 'open-online',
'status' => 'APPROVED',
'highlighted_status' => 'FEATURED',
];

public function mount()
{
$this->selectedLanguage = strtolower(App::getLocale());
$this->selectedYear = Carbon::now()->year;
$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) {
Expand Down Expand Up @@ -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();

Expand All @@ -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()) {
Expand All @@ -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();

Expand All @@ -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
*/
Expand All @@ -148,4 +167,4 @@ private function getCountryNamesFromEvents($events)

return $countryNames;
}
}
}
4 changes: 2 additions & 2 deletions resources/lang/en/snippets.php
Original file line number Diff line number Diff line change
Expand Up @@ -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?',
Expand Down
41 changes: 35 additions & 6 deletions tests/Feature/EventsHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
31 changes: 27 additions & 4 deletions tests/Feature/OnlineEventsWorkflowTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Loading