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
136 changes: 136 additions & 0 deletions app/Livewire/OnlineCalendar.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
<?php

namespace App\Livewire;

use App\Country;
use App\Event;
use App\Queries\CountriesQuery;
use Carbon\Carbon;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Log;
use Livewire\Component;
use Livewire\WithPagination;

class OnlineCalendar extends Component
{
use WithPagination;

public $events;

private $filteredEvents;

public $selectedLanguage;

public $selectedYear;

public $selectedMonth;

public $selectedDate;

public $months;

public $listeners = ['eventsUpdated' => 'render'];

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;

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

$this->months = [];

foreach ($byMonths as $result) {
$this->months[$result->month.'/'.$result->year] =
$result->monthname.' '.$result->year;
}

//Go back to start of array to get the first item
reset($this->months);
$parts = explode('/', key($this->months));
if ($parts[0] !== $this->selectedMonth) {
$this->selectedMonth = $parts[0];
}

$this->selectedDate = $this->selectedMonth.'/'.$this->selectedYear;
}

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

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

$this->events->map(function ($event) {
$event->title = str_limit($event->title, 50);
$event->start_date = Carbon::parse($event->start_date);
});

if ($this->selectedLanguage !== '') {
$this->filteredEvents = $this->events->filter(function ($event) {
return $event->language == $this->selectedLanguage;
});

if ($this->filteredEvents->isEmpty()) {
$this->filteredEvents = $this->events;
}
} else {
$this->filteredEvents = $this->events;
}

$countries = CountriesQuery::withOnlineEvents('FEATURED');

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

$languages = $this->events
->groupBy('language')
->keys()
->all();

return view('livewire.online-calendar', [
'countries' => $countries,
'countryNames' => $countryNames,
'languages' => $languages,
'filteredEvents' => $this->filteredEvents->paginate(50),
]);
}
/**
* @return mixed
*/
private function getCountryNamesFromEvents($events)
{
$country_codes = $events
->groupBy('country_iso')
->keys()
->all();

$countriesObjects = Country::whereIn('iso', $country_codes)->get();
$countryNames = $countriesObjects->mapWithKeys(function ($item) {
return [$item['iso'] => __('countries.'.$item['name'])];
});

return $countryNames;
}
}
2 changes: 1 addition & 1 deletion database/seeders/StaticPagesSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public function run(): void

StaticPage::create([
'name' => 'Presentations and Toolkits',
'description' => 'In this section you will find material which will help you organise your EU Code Week activity, and promote the initiative with your community. Communication toolkit: find here the official EU Code Week logos, badge, flyer, poster, PowerPoint and Word templates, examples of social media posts, and illustrations. ( English ). Teachers toolkit: find here the official EU Code Week logos, badge, template of certificate of participation for your students, an introductory presentation about EU Code Week, and social media material. ( English ).',
'description' => 'In this section you will find material which will help you organise your EU Code Week activity, and promote the initiative with your community. Communication toolkit: find here the official EU Code Week logos, badge, flyer, poster, PowerPoint and Word templates, examples of social media posts, and illustrations. ( English ). Teachers toolkit: find here the official EU Code Week logos, badge, template of certificate of participation for your students, an introductory presentation about EU Code Week, and social media material. English .',
'unique_identifier' => 'presentations-and-toolkits',
'path' => '/toolkits',
'thumbnail' => '/images/banner_learn_teach.svg',
Expand Down
1 change: 1 addition & 0 deletions public/build/assets/app-0yoGi-Tf.css

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion public/build/assets/app-DDfiJZ_P.css

This file was deleted.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Loading