-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathMatchMakingToolController.php
More file actions
97 lines (81 loc) · 3.09 KB
/
Copy pathMatchMakingToolController.php
File metadata and controls
97 lines (81 loc) · 3.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
namespace App\Http\Controllers;
use App\Country;
use App\ResourceLanguage;
use App\MatchmakingProfile;
use Illuminate\Http\Request;
use Illuminate\View\View;
use App\Filters\MatchmakingProfileFilters;
class MatchMakingToolController extends Controller
{
public function index(Request $request): View
{
$selected_languages = $request->input('languages', []);
$selected_locations = $request->input('locations', []);
$selected_types = $request->input('types', []);
$selected_topics = $request->input('topics', []);
$selected_languages = is_array($selected_languages) ? array_filter($selected_languages) : [];
$selected_locations = is_array($selected_locations) ? array_filter($selected_locations) : [];
$selected_types = is_array($selected_types) ? array_filter($selected_types) : [];
$selected_topics = is_array($selected_topics) ? array_filter($selected_topics) : [];
$used_languages = MatchmakingProfile::query()
->whereNotNull('languages')
->pluck('languages')
->filter()
->flatMap(function ($langs) {
return is_array($langs) ? $langs : (json_decode($langs, true) ?: []);
})
->unique()
->values()
->all();
$languages = ResourceLanguage::whereIn('name', $used_languages)
->orderBy('position')
->get(['id', 'name'])
->toArray();
$used_countries = MatchmakingProfile::query()
->whereNotNull('country')
->pluck('country')
->unique()
->values()
->all();
$locations = Country::whereIn('iso', $used_countries)
->orderBy('name')
->get(['iso', 'name'])
->toArray();
$types = MatchmakingProfile::getValidOrganizationTypeOptions();
$topics = MatchmakingProfile::getUniqueDigitalExpertiseAreas();
$support_types = MatchmakingProfile::getValidTypes();
$valid_formats = MatchmakingProfile::getValidFormats();
return view('matchmaking-tool.index', compact([
'selected_languages',
'selected_locations',
'selected_types',
'selected_topics',
'languages',
'locations',
'types',
'topics',
'support_types',
'valid_formats',
]));
}
public function show(Request $request, string $slug): View
{
$profile = MatchmakingProfile::where('slug', $slug)->first();
if (! $profile) {
abort(404);
}
$locations = Country::orderBy('name')->select(['iso', 'name'])->get()->toArray();
return view('matchmaking-tool.show', [
'profile' => $profile,
'locations' => $locations,
]);
}
public function searchPOST(MatchmakingProfileFilters $filters, Request $request)
{
return MatchmakingProfile::query()
->filter($filters)
->orderByDesc('start_time')
->paginate(12);
}
}