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