| Total Complexity | 10 |
| Total Lines | 116 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 13 | class FirstVisitController extends AuthController |
||
| 14 | { |
||
| 15 | /** |
||
| 16 | * Show the form for completing Manager registration on first visit. |
||
| 17 | * |
||
| 18 | * @param Request $request |
||
|
2 ignored issues
–
show
|
|||
| 19 | * @return \Illuminate\Http\Response |
||
| 20 | */ |
||
| 21 | public function showFirstVisitManagerForm() |
||
| 22 | { |
||
| 23 | $routes = [ |
||
| 24 | 'return' => route('home'), |
||
| 25 | 'continue' => route('manager.finish_registration'), |
||
| 26 | ]; |
||
| 27 | |||
| 28 | return view('auth.first_visit_manager', [ |
||
| 29 | 'routes' => $routes, |
||
| 30 | 'first_visit' => Lang::get('common/auth/first_manager_visit'), |
||
| 31 | 'departments' => Department::all(), |
||
| 32 | 'not_in_gov_option' => ['value' => 0, 'name' => Lang::get('common/auth/register.not_in_gov')], |
||
| 33 | ]); |
||
| 34 | } |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Process the final data required for Managers. |
||
| 38 | * |
||
| 39 | * @param Request $request |
||
|
1 ignored issue
–
show
|
|||
| 40 | * @return void |
||
|
1 ignored issue
–
show
|
|||
| 41 | */ |
||
| 42 | public function finishManagerRegistration(Request $request) |
||
| 43 | { |
||
| 44 | $data = $request->all(); |
||
| 45 | $validator = RegistrationValidator::finalizeManagerValidator($data); |
||
| 46 | $validator->validate(); |
||
| 47 | |||
| 48 | $user = $request->user(); |
||
| 49 | |||
| 50 | // Save manager specific fields to user |
||
| 51 | $managerDepartment = Department::find($data['department']); |
||
| 52 | $inGovernment = ($managerDepartment !== null); |
||
| 53 | $user->not_in_gov = !$inGovernment; |
||
| 54 | $user->gov_email = $inGovernment ? $data['gov_email'] : null; |
||
| 55 | $user->save(); |
||
| 56 | $user->refresh(); |
||
| 57 | |||
| 58 | // Add (or update) manager profile |
||
| 59 | // NOTE: modifying a field in $user, and saving it, appears to create Manager object. I don't know how. -- Tristan |
||
| 60 | // That means that after setting not_in_gov or gov_email, a manager already exists here. Adding a new one will throw an exception. |
||
| 61 | $department_id = $inGovernment ? $managerDepartment->id : null; |
||
| 62 | if ($user->manager === null) { |
||
| 63 | $user->applicant()->save(new Manager()); |
||
| 64 | $user->refresh(); |
||
| 65 | } |
||
| 66 | $user->manager->department_id = $department_id; |
||
| 67 | $user->manager->save(); |
||
| 68 | |||
| 69 | $user->refresh(); |
||
| 70 | $expectedUrl = session()->remove('url.expected'); |
||
| 71 | session()->remove('url.expected'); |
||
| 72 | return redirect($expectedUrl); |
||
| 73 | } |
||
| 74 | |||
| 75 | /** |
||
| 76 | * Show the form for completing HR Advisor registration on first visit. |
||
| 77 | * |
||
| 78 | * @return \Illuminate\Http\Response |
||
| 79 | */ |
||
| 80 | public function showFirstVisitHrForm() |
||
| 81 | { |
||
| 82 | $routes = [ |
||
| 83 | 'return' => route('hr_advisor.home'), |
||
| 84 | 'continue' => route('hr_advisor.finish_registration'), |
||
| 85 | ]; |
||
| 86 | |||
| 87 | return view('auth.first_visit_manager', [ |
||
| 88 | 'routes' => $routes, |
||
| 89 | 'first_visit' => Lang::get('common/auth/first_hr_visit'), |
||
| 90 | 'departments' => Department::all(), |
||
| 91 | 'not_in_gov_option' => ['value' => 0, 'name' => Lang::get('common/auth/register.not_in_gov')], |
||
| 92 | ]); |
||
| 93 | } |
||
| 94 | |||
| 95 | /** |
||
| 96 | * Process the final data required for Managers. |
||
| 97 | * |
||
| 98 | * @param Request $request |
||
|
1 ignored issue
–
show
|
|||
| 99 | * @return void |
||
|
1 ignored issue
–
show
|
|||
| 100 | */ |
||
| 101 | public function finishHrRegistration(Request $request) |
||
| 129 | } |
||
| 130 | } |
||
| 131 |