-
Notifications
You must be signed in to change notification settings - Fork 2
/
SpeakerController.php
45 lines (38 loc) · 1.41 KB
/
SpeakerController.php
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
<?php
namespace App\Http\Controllers;
use App\Models\Edition;
use App\Models\UserPresentation;
class SpeakerController extends Controller
{
/**
* Returns the public facing speakers index page
*/
public function index()
{
$edition = Edition::current();
$query = UserPresentation::where('role', 'speaker');
if (!$edition) {
return redirect(route('welcome'))
->dangerBanner("Speakers are not available yet.");
}
// If the final program is released, filter by room_id and timeslot_id
if (optional(Edition::current())->is_final_programme_released) {
$query->whereHas('presentation', function ($query) {
$query->whereNotNull('room_id')
->whereNotNull('timeslot_id');
});
} else {
// Otherwise, filter by is_approved
$query->whereHas('presentation', function ($query) {
$query->where('is_approved', true);
});
}
$speakers = $query->get()->sortBy(function ($speaker) {
if ($speaker->user->company && $speaker->user->company->is_sponsorship_approved) {
return $speaker->user->company->sponsorship_id;
}
return 999; // Assign a high value to non-sponsored speakers
});
return view('speakers.index', compact('speakers', 'edition'));
}
}