-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathProgrammeController.php
139 lines (121 loc) · 4.47 KB
/
ProgrammeController.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
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<?php
namespace App\Http\Controllers;
use App\Models\Edition;
use App\Models\Presentation;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\View\View;
class ProgrammeController extends Controller
{
/**
* Displays an index page of the general programme
*
* @return View
*/
public function index(): View
{
if (!optional(Edition::current())->is_final_programme_released) {
abort(404);
}
$lectures = Presentation::where('type', 'lecture')
->whereNotNull('room_id')
->whereNotNull('timeslot_id')
->orderBy('start')
->get();
$workshops = Presentation::where('type', 'workshop')
->whereNotNull('room_id')
->whereNotNull('timeslot_id')
->orderBy('start')
->get();
$lectureTimeslots = $lectures->map->only('start')->unique();
$workshopTimeslots = $workshops->map->only('start')->unique();
return view('programme.index', compact(
'lectures',
'workshops',
'lectureTimeslots',
'workshopTimeslots'
));
}
/**
* Displays details of the specific presentation
*
* @param Presentation $presentation
* @return View
*/
public function show(Presentation $presentation): View
{
if (!$presentation->is_approved) {
abort(404);
}
$styles = [
1 => [
'borderColor' => 'bg-gradient-to-r from-yellow-300 to-yellow-600', // Gold
'linkColor' => 'text-yellow-400 hover:text-yellow-500',
'textColor' => 'text-yellow-400',
'iconColor' => 'stroke-yellow-400 hover:stroke-yellow-500',
],
2 => [
'borderColor' => 'bg-gradient-to-r from-gray-300 to-gray-600', // Silver
'linkColor' => 'text-gray-600 hover:text-gray-700',
'textColor' => 'text-gray-600',
'iconColor' => 'stroke-gray-600 hover:stroke-gray-700',
],
3 => [
'borderColor' => 'bg-gradient-to-r from-orange-300 to-orange-600', // Bronze
'linkColor' => 'text-orange-400 hover:text-orange-500',
'textColor' => 'text-orange-400',
'iconColor' => 'stroke-orange-400 hover:stroke-orange-500',
],
];
$company = $presentation->company;
if ($company && $company->is_sponsorship_approved && isset($styles[$company->sponsorship_id])) {
$borderColor = $styles[$company->sponsorship_id]['borderColor'];
$linkColor = $styles[$company->sponsorship_id]['linkColor'];
$iconColor = $styles[$company->sponsorship_id]['iconColor'];
$textColor = $styles[$company->sponsorship_id]['textColor'];
} else {
$borderColor = 'bg-gradient-to-r from-blue-300 via-blue-400 to-blue-500'; // Default
$linkColor = 'text-blue-400 hover:text-blue-600';
$textColor = 'text-blue-400';
$iconColor = 'stroke-blue-400 dark:stroke-blue-400';
}
return view(
'programme.show',
compact('presentation', 'borderColor', 'linkColor', 'textColor', 'iconColor')
);
}
/**
* Handles enrollment for the presentation
*
* @param Presentation $presentation
* @return int
*/
public function enroll(Presentation $presentation)
{
if (Auth::user()->cannot('enroll', $presentation)) {
return 403;
}
$enrollmentResult = Auth::user()->joinPresentation($presentation);
if (!$enrollmentResult) {
return redirect(route('programme.presentation.show', compact('presentation')))
->banner("Something went wrong with enrolling for {$presentation->name}");
}
return redirect(route('programme'))
->banner("You have successfully enrolled for {$presentation->name}");
}
/**
* Handles disenrollment from the presentation
*
* @param Presentation $presentation
* @return int
*/
public function disenroll(Presentation $presentation)
{
if (Auth::user()->cannot('disenroll', $presentation)) {
return 403;
}
Auth::user()->leavePresentation($presentation);
return redirect(route('programme'))
->banner("You have successfully deregistered from the {$presentation->name}");
}
}