6
6
use App \Http \Controllers \Controller ;
7
7
use App \Models \ApplicationForm ;
8
8
use App \Models \Faculty ;
9
- use App \Models \User ;
10
- use App \Models \Workshop ;
11
- use App \Models \RoleUser ;
12
9
use App \Models \File ;
13
10
use App \Models \Role ;
11
+ use App \Models \RoleUser ;
12
+ use App \Models \Semester ;
13
+ use App \Models \User ;
14
+ use App \Models \Workshop ;
15
+ use App \Utils \HasPeriodicEvent ;
14
16
use Carbon \Carbon ;
15
17
use Illuminate \Auth \Access \AuthorizationException ;
16
18
use Illuminate \Http \RedirectResponse ;
17
19
use Illuminate \Http \Request ;
18
- use Illuminate \View \View ;
19
- use Illuminate \Support \Facades \Storage ;
20
20
use Illuminate \Support \Facades \Cache ;
21
21
use Illuminate \Support \Facades \DB ;
22
+ use Illuminate \Support \Facades \Storage ;
23
+ use Illuminate \View \View ;
22
24
use Maatwebsite \Excel \Facades \Excel ;
23
25
24
26
class ApplicationController extends Controller
25
27
{
28
+ use HasPeriodicEvent;
29
+
26
30
private const EDUCATIONAL_ROUTE = 'educational ' ;
27
31
private const QUESTIONS_ROUTE = 'questions ' ;
28
32
private const FILES_ROUTE = 'files ' ;
29
33
private const DELETE_FILE_ROUTE = 'files.delete ' ;
30
34
private const ADD_PROFILE_PIC_ROUTE = 'files.profile ' ;
31
35
private const SUBMIT_ROUTE = 'submit ' ;
32
36
37
+ /**
38
+ * Update the PeriodicEvent connected to the applications.
39
+ * @throws AuthorizationException
40
+ */
41
+ public function updateApplicationPeriod (Request $ request ): RedirectResponse
42
+ {
43
+ $ this ->authorize ('finalize ' , ApplicationForm::class);
44
+
45
+ $ request ->validate ([
46
+ 'semester_id ' => 'required|exists:semesters,id ' ,
47
+ 'start_date ' => 'required|date ' ,
48
+ 'end_date ' => 'required|date|after:now|after:start_date ' ,
49
+ 'extended_end_date ' => 'nullable|date|after:end_date ' ,
50
+ ]);
51
+
52
+ $ this ->updatePeriodicEvent (
53
+ Semester::find ($ request ->semester_id ),
54
+ Carbon::parse ($ request ->start_date ),
55
+ Carbon::parse ($ request ->end_date ),
56
+ $ request ->extended_end_date ? Carbon::parse ($ request ->extended_end_date ) : null
57
+ );
58
+
59
+ return back ()->with ('message ' , __ ('general.successful_modification ' ));
60
+ }
61
+
33
62
/**
34
63
* Return the view based on the request's page parameter.
35
64
* @param Request $request
@@ -48,8 +77,8 @@ public function showApplicationForm(Request $request): View|RedirectResponse
48
77
$ data = [
49
78
'workshops ' => Workshop::all (),
50
79
'faculties ' => Faculty::all (),
51
- 'deadline ' => self :: getApplicationDeadline (),
52
- 'deadline_extended ' => self :: isDeadlineExtended (),
80
+ 'deadline ' => $ this -> getDeadline (),
81
+ 'deadline_extended ' => $ this -> isExtended (),
53
82
'user ' => user (),
54
83
];
55
84
switch ($ request ->input ('page ' )) {
@@ -74,7 +103,7 @@ public function storeApplicationForm(Request $request)
74
103
{
75
104
$ user = $ request ->user ();
76
105
77
- if (now () > self :: getApplicationDeadline ()) {
106
+ if (now () > $ this -> getDeadline ()) {
78
107
return redirect ()->route ('application ' )->with ('error ' , 'A jelentkezési határidő lejárt ' );
79
108
}
80
109
@@ -113,13 +142,13 @@ public function showApplications(Request $request): View
113
142
if ($ request ->has ('id ' )) { // return one application in detail
114
143
$ user = User::withoutGlobalScope ('verified ' )
115
144
->with ('application ' )->findOrFail ($ request ->input ('id ' ));
116
- $ this ->authorize ('viewApplication ' , $ user );
145
+ $ this ->authorize ('view ' , $ user-> application );
117
146
return view ('auth.application.applications_details ' , [
118
147
'user ' => $ user ,
119
148
]);
120
149
} else { //return all applications that can be visible
121
- $ this ->authorize ('viewSomeApplication ' , User ::class);
122
- if ($ authUser ->can ('viewAllApplications ' , User ::class)) {
150
+ $ this ->authorize ('viewSome ' , ApplicationForm ::class);
151
+ if ($ authUser ->can ('viewAll ' , ApplicationForm ::class)) {
123
152
$ workshops = Workshop::all ();
124
153
} else {
125
154
$ workshops = $ authUser ->roleWorkshops ->concat ($ authUser ->applicationCommitteWorkshops );
@@ -150,7 +179,8 @@ public function showApplications(Request $request): View
150
179
'workshop ' => $ request ->input ('workshop ' ), //filtered workshop
151
180
'workshops ' => $ workshops , //workshops that can be chosen to filter
152
181
'status ' => $ request ->input ('status ' ), //filtered status
153
- 'applicationDeadline ' => self ::getApplicationDeadline (),
182
+ 'applicationDeadline ' => $ this ->getDeadline (),
183
+ 'periodicEvent ' => $ this ->periodicEvent ()
154
184
]);
155
185
}
156
186
}
@@ -163,7 +193,7 @@ public function showApplications(Request $request): View
163
193
*/
164
194
public function editApplication (Request $ request ): RedirectResponse
165
195
{
166
- $ this ->authorize ('viewSomeApplication ' , User ::class);
196
+ $ this ->authorize ('viewSome ' , ApplicationForm ::class);
167
197
$ application = ApplicationForm::findOrFail ($ request ->input ('application ' ));
168
198
$ newStatus = $ request ->input ('status_ ' .$ application ->user ->id );
169
199
if ($ request ->has ('note ' )) {
@@ -181,7 +211,7 @@ public function editApplication(Request $request): RedirectResponse
181
211
*/
182
212
public function finalizeApplicationProcess ()
183
213
{
184
- $ this ->authorize ('finalizeApplicationProcess ' , User ::class);
214
+ $ this ->authorize ('finalize ' , ApplicationForm ::class);
185
215
Cache::forget ('collegists ' );
186
216
$ not_handled_applicants = User::query ()->withoutGlobalScope ('verified ' )
187
217
->where ('verified ' , 0 )
@@ -223,22 +253,6 @@ public function finalizeApplicationProcess()
223
253
return back ()->with ('message ' , 'Sikeresen jóváhagyta az elfogadott jelentkezőket ' );
224
254
}
225
255
226
- /**
227
- * @return Carbon the application deadline set in .env
228
- */
229
- public static function getApplicationDeadline (): Carbon
230
- {
231
- return Carbon::parse (config ('custom.application_deadline ' ));
232
- }
233
-
234
- /**
235
- * @return bool if the deadline has been extended or not
236
- */
237
- public static function isDeadlineExtended (): bool
238
- {
239
- return config ('custom.application_extended ' );
240
- }
241
-
242
256
243
257
/**
244
258
* @param Request $request
@@ -314,7 +328,7 @@ public function submitApplication(User $user)
314
328
if ($ user ->application ->missingData () == []) {
315
329
$ user ->application ->update (['status ' => ApplicationForm::STATUS_SUBMITTED ]);
316
330
$ user ->internetAccess ->setWifiCredentials ($ user ->educationalInformation ->neptun );
317
- $ user ->internetAccess ()->update (['has_internet_until ' => $ this :: getApplicationDeadline () ->addMonth (1 )]);
331
+ $ user ->internetAccess ()->update (['has_internet_until ' => $ this -> getDeadline ()? ->addMonth()]);
318
332
return back ()->with ('message ' , 'Sikeresen véglegesítette a jelentkezését! ' );
319
333
} else {
320
334
return back ()->with ('error ' , 'Hiányzó adatok! ' );
@@ -326,7 +340,7 @@ public function submitApplication(User $user)
326
340
*/
327
341
public function exportApplications ()
328
342
{
329
- $ this ->authorize ('viewAllApplications ' , User ::class);
343
+ $ this ->authorize ('viewAll ' , ApplicationForm ::class);
330
344
331
345
$ applications = ApplicationForm::with ('user ' )
332
346
->where ('status ' , ApplicationForm::STATUS_SUBMITTED )
0 commit comments