Skip to content

Commit 1c30ae9

Browse files
committed
Merge branch 'dev' of https://github.com/codeeu/codeweek into dev
2 parents 5616fd6 + 4573964 commit 1c30ae9

36 files changed

+1352
-149
lines changed
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
<?php
2+
3+
namespace App\Enums;
4+
5+
use App\Event;
6+
use App\StaticPage;
7+
use App\Podcast;
8+
9+
enum GlobalSearchFiltersEnum: string
10+
{
11+
case ALL = 'All';
12+
case PODCASTS = 'Podcasts';
13+
case HACKATHONS = 'Hackathons';
14+
case ONLINE_COURSES = 'Online Courses';
15+
case TRAINING = 'Training';
16+
case CHALLENGES = 'Challenges';
17+
case LEARN = 'Learn';
18+
case TEACH = 'Teach';
19+
case PRESENTATIONS_AND_TOOLKITS = 'Presentations and Toolkits';
20+
case ACTIVITIES = 'Activities';
21+
case BLOGS = 'Blogs';
22+
case OTHERS = 'Others';
23+
24+
/**
25+
* Get additional information for each filter.
26+
*/
27+
public function meta(): array
28+
{
29+
return match ($this) {
30+
self::ALL => [
31+
'type_search' => 'all',
32+
'model' => null,
33+
'search_fields' => [],
34+
],
35+
self::PODCASTS => [
36+
'type_search' => 'model',
37+
'model' => Podcast::class,
38+
'search_fields' => ['title'],
39+
'map_fields' => [
40+
'name' => '{title}',
41+
'category' => 'Podcast',
42+
'description' => '{description}',
43+
'thumbnail' => '{image}',
44+
'path' => '{url}',
45+
'link_type' => 'internal',
46+
'language' => 'en',
47+
]
48+
],
49+
self::HACKATHONS,
50+
self::ONLINE_COURSES,
51+
self::TRAINING,
52+
self::CHALLENGES,
53+
self::PRESENTATIONS_AND_TOOLKITS,
54+
self::OTHERS => [
55+
'type_search' => 'model',
56+
'model' => StaticPage::class,
57+
'search_fields' => [
58+
'description',
59+
'keywords'
60+
],
61+
'map_fields' => [
62+
'name' => '{name}',
63+
'category' => '{category}',
64+
'description' => '{description}',
65+
'thumbnail' => '{thumbnail}',
66+
'path' => '{path}',
67+
'link_type' => '{link_type}',
68+
'language' => '{language}',
69+
]
70+
],
71+
self::LEARN => [
72+
'type_search' => 'function',
73+
'function' => 'searchResources',
74+
'params' => ['section' => 'learn'],
75+
'map_fields' => [
76+
'name' => '{name}',
77+
'category' => 'Learn',
78+
'description' => '',
79+
'thumbnail' => '/img/event_default_picture.png',
80+
'path' => '#',
81+
'link_type' => 'internal',
82+
'language' => 'en',
83+
]
84+
],
85+
self::TEACH => [
86+
'type_search' => 'function',
87+
'function' => 'searchResources',
88+
'params' => ['section' => 'teach'],
89+
'map_fields' => [
90+
'name' => '{name}',
91+
'category' => 'Teach',
92+
'description' => '',
93+
'thumbnail' => '/img/event_default_picture.png',
94+
'path' => '#',
95+
'link_type' => 'internal',
96+
'language' => 'en',
97+
]
98+
],
99+
self::BLOGS => [
100+
'type_search' => 'blog'
101+
],
102+
self::ACTIVITIES => [
103+
'type_search' => 'model',
104+
'model' => Event::class,
105+
'search_fields' => ['title'],
106+
'map_fields' => [
107+
'name' => '{title}',
108+
'category' => 'Activities',
109+
'description' => '{description}',
110+
'thumbnail' => '{picture}',
111+
'path' => '{url}',
112+
'link_type' => 'internal',
113+
'language' => 'en',
114+
]
115+
],
116+
};
117+
}
118+
119+
/**
120+
* Get a list of all enum values.
121+
*/
122+
public static function values(): array
123+
{
124+
return array_column(self::cases(), 'value');
125+
}
126+
127+
/**
128+
* Get a list of all filter keys.
129+
*/
130+
public static function keys(): array
131+
{
132+
return array_map(fn ($case) => $case->name, self::cases());
133+
}
134+
}

app/Event.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,13 @@ class Event extends Model
7676

7777
//protected $appends = ['LatestModeration'];
7878

79+
public function getUrlAttribute() {
80+
return route('view_event', [
81+
'event' => $this->id,
82+
'slug' => $this->slug
83+
]);
84+
}
85+
7986
public function getJavascriptData()
8087
{
8188
return $this->only(['geoposition', 'title', 'description']);

app/Http/Controllers/PodcastsController.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ public function index(Request $request): View
1919

2020
public function show(Podcast $podcast): View
2121
{
22-
2322
return view('podcast', compact('podcast'));
2423
}
2524

Lines changed: 4 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -1,127 +1,13 @@
1-
<?php
1+
<?php
22

33
namespace App\Http\Controllers;
44

5-
use App\Country;
6-
use App\Event;
7-
use App\Filters\EventFilters;
8-
use App\Http\Transformers\EventTransformer;
9-
use Carbon\Carbon;
105
use Illuminate\Http\Request;
11-
use Illuminate\Support\Arr;
12-
use Illuminate\Support\Facades\Cache;
13-
use Illuminate\Support\Facades\Log;
14-
use Illuminate\View\View;
156

167
class SearchController extends Controller
178
{
18-
protected $eventTransformer;
19-
20-
/**
21-
* EventController constructor.
22-
*/
23-
public function __construct(EventTransformer $eventTransformer)
24-
{
25-
$this->eventTransformer = $eventTransformer;
26-
}
27-
28-
public function search(Request $request): View
29-
{
30-
31-
$query = $request->input('q', '');
32-
$selected_year = $request->input('year', Carbon::now()->year);
33-
34-
$country_iso = $request->input('country_iso', null);
35-
$tag = $request->input('tag', '');
36-
37-
$selected_country = [];
38-
39-
if (! is_null($country_iso)) {
40-
$country = Country::where('iso', $country_iso)->first();
41-
if ($country) {
42-
$country->translation = __('countries.'.$country->name);
43-
$selected_country[] = $country;
44-
}
45-
46-
}
47-
48-
$current_year = Carbon::now()->year;
49-
$years = [];
50-
for ($year = $current_year; $year >= 2014; $year--) {
51-
$years[] = $year;
52-
}
53-
54-
return view('event.search', compact(['query', 'years', 'selected_country', 'selected_year', 'tag']));
55-
}
56-
57-
public function searchPOST(EventFilters $filters, Request $request)
58-
{
59-
$events = $this->getEvents($filters);
60-
61-
//Log::info($request->input('page'));
62-
if ($request->input('page')) {
63-
$result = [$events];
64-
} else {
65-
Log::info('no page');
66-
$eventsMap = $this->getAllEventsToMap($filters);
67-
$result = [$events, $eventsMap];
68-
}
69-
70-
return $result;
71-
}
72-
73-
protected function getEvents(EventFilters $filters)
9+
public function index()
7410
{
75-
76-
$events = Event::where('status', 'like', 'APPROVED')
77-
->filter($filters)
78-
->orderBy('start_date')
79-
->get()
80-
->groupBy(function ($event) {
81-
if ($event->start_date <= Carbon::today()) {
82-
return 'past';
83-
}
84-
85-
return 'future';
86-
});
87-
88-
if (is_null($events->get('future')) || is_null($events->get('past'))) {
89-
return $events->flatten()->paginate(12);
90-
}
91-
92-
return $events->get('future')->merge($events->get('past'))->paginate(12);
93-
94-
}
95-
96-
protected function getAllEventsToMap(EventFilters $filters)
97-
{
98-
99-
$flattened = Arr::flatten($filters->getFilters());
100-
101-
$composed_key = '';
102-
103-
foreach ($flattened as $value) {
104-
$composed_key .= $value.',';
105-
}
106-
107-
$value = Cache::get($composed_key, function () use ($composed_key, $filters) {
108-
Log::info("Building cache [{$composed_key}]");
109-
$events = Event::where('status', 'like', 'APPROVED')
110-
->filter($filters)
111-
->get();
112-
113-
$events = $this->eventTransformer->transformCollection($events);
114-
115-
$events = $events->groupBy('country');
116-
117-
Cache::put($composed_key, $events, 5 * 60);
118-
119-
return $events;
120-
});
121-
122-
Log::info("Serving from cache [{$composed_key}]");
123-
124-
return $value;
125-
11+
return view('static.search');
12612
}
127-
}
13+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
namespace App\Livewire;
4+
5+
use Livewire\Component;
6+
use App\Enums\GlobalSearchFiltersEnum;
7+
use App\Services\GlobalSearchService;
8+
9+
class GlobalSearchFilterComponent extends Component
10+
{
11+
public $selectedFilter = GlobalSearchFiltersEnum::ALL->value;
12+
13+
protected $globalSearchService;
14+
15+
protected $queryString = [
16+
'selectedFilter' => ['except' => GlobalSearchFiltersEnum::ALL->value],
17+
];
18+
19+
public function __construct()
20+
{
21+
$this->globalSearchService = new GlobalSearchService();
22+
}
23+
24+
public function selectFilter($filter)
25+
{
26+
if (!GlobalSearchFiltersEnum::tryFrom($filter)) {
27+
return;
28+
}
29+
30+
$this->selectedFilter = $filter;
31+
$this->dispatch('filterChanged', filter: $filter);
32+
}
33+
34+
public function render()
35+
{
36+
return view('livewire.filter-component', [
37+
'filters' => GlobalSearchFiltersEnum::values(),
38+
]);
39+
}
40+
}

app/Livewire/PartnerFilterComponent.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public function selectFilter($filter)
1818

1919
public function render()
2020
{
21-
return view('livewire.partner-filter-component', [
21+
return view('livewire.filter-component', [
2222
'filters' => ['Partners', 'Council Presidency', 'EU Code Week Supporters'] // Available filters
2323
]);
2424
}

0 commit comments

Comments
 (0)