| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace App\Http\Controllers; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Illuminate\Http\Request; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Illuminate\Support\Facades\Lang; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Illuminate\Support\Facades\Auth; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use App\Models\JobApplication; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use App\Models\JobPoster; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use App\Models\Skill; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use App\Models\Lookup\ReviewStatus; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use Facades\App\Services\WhichPortal; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | class ApplicationController extends Controller | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |      * Display a listing of the resource. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |      * @return \Illuminate\Http\Response | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |     public function index() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |         $applications = Auth::user()->applicant->job_applications; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |         return view( | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |             'applicant/application_index', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |             [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |                 'application_index' => Lang::get('applicant/application_index'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |                 'applications' => $applications, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |                 'manager_profile_photo' => '/images/user.png', // TODO: get real photo. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |             ] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |      * Determine whether the user can view the jobApplication. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |      * @param  \App\Models\JobPoster    $jobPoster Incoming JobPoster object. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |      * @param  \App\Models\JobApplication $application Incoming Application object. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |      * @return \Illuminate\Http\Response | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 40 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  |     public function showWithJob(JobPoster $jobPoster, JobApplication $application) | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  |         if ($jobPoster->job_applications->contains($application)) { | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  |             return $this->show($application); | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  |         } else { | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  |             return abort(404); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |      * Display specified application | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |      * @param  \App\Models\JobApplication $application Incoming Application object. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |      * @return \Illuminate\Http\Response | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |     public function show(JobApplication $application) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |         $response_poster = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |         $show_review = true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |         $jobPoster = $application->job_poster; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |         if ($jobPoster->isInStrategicResponseDepartment()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |             $response_poster = true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |             $show_review = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |         $essential_criteria = $jobPoster->criteria->filter(function ($value, $key) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |             return $value->criteria_type->name == 'essential' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |                 && $value->skill->skill_type->name == 'hard'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |         }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |         $asset_criteria = $jobPoster->criteria->filter(function ($value, $key) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |             return $value->criteria_type->name == 'asset' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |                 && $value->skill->skill_type->name == 'hard'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |         }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |         // Display slightly different views on different portals. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |         $view = WhichPortal::isManagerPortal() || WhichPortal::isHrPortal() ? | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |             'manager/application_post' : 'applicant/application_preview'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |         $application_view = $response_poster | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |             ? 'applicant/strategic_response_application/application_view/application_layout' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |             : 'common/application/view/view_layout'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |         if (WhichPortal::isManagerPortal() || WhichPortal::isHrPortal()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |             // Load things required for review component. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |             $application->load(['veteran_status', 'citizenship_declaration', 'application_review', 'applicant.user']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |         // If the application status is draft then get data through the applicant model. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |         // Else, grab the data from the application itself. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |         if ($application->isDraft()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |             $source = $application->applicant; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |             $show_review = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |             $source = $application; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |         $degrees = $source->degrees; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |         $courses = $source->courses; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |         $work_experiences = $source->work_experiences; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |         $skill_declarations = $source->skill_declarations; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |         $references = $source->references; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |         $work_samples = $source->work_samples; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |         $custom_breadcrumbs = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |             'home' => route('home'), | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |             'applications' =>  route('applications.index'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |             'application' => '', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |         if (WhichPortal::isManagerPortal() || WhichPortal::isHrPortal()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |             $custom_breadcrumbs = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |                 'home' => route('home'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |                 'jobs' => route(WhichPortal::prefixRoute('jobs.index')), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |                 $jobPoster->title => route(WhichPortal::prefixRoute('jobs.summary'), $jobPoster), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |                 'applications' =>  route(WhichPortal::prefixRoute('jobs.applications'), $jobPoster), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |                 'application' => '', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |             ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |         return view( | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |             $view, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |             [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |                 'application_view_template' => $application_view, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |                 // Localized strings. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |                 'post' => Lang::get('manager/application_post'), // Change text | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |                 'is_manager_view' => WhichPortal::isManagerPortal(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |                 'is_hr_portal' => WhichPortal::isHrPortal(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |                 // Application Template Data. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |                 'application_template' => Lang::get('applicant/application_template'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |                 'citizenship_declaration_template' => Lang::get('common/citizenship_declaration'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |                 'veteran_status_template' => Lang::get('common/veteran_status'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |                 // Job Data. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |                 'job' => $jobPoster, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |                 // Skills Data. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |                 'skills' => Skill::all(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |                 'skill_template' => Lang::get('common/skills'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |                 'reference_template' => Lang::get('common/references'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |                 'sample_template' => Lang::get('common/work_samples'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |                 'essential_criteria' => $essential_criteria, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |                 'asset_criteria' => $asset_criteria, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |                 // Applicant Data. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |                 'applicant' => $application->applicant, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |                 'job_application' => $application, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |                 'degrees' => $degrees, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |                 'courses' => $courses, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |                 'work_experiences' => $work_experiences, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |                 'skill_declarations' => $skill_declarations, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |                 'references' => $references, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |                 'work_samples' => $work_samples, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |                 'review_statuses' => ReviewStatus::all(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |                 'custom_breadcrumbs' => $custom_breadcrumbs, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |                 'response_poster' => $response_poster, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |                 'show_review' => $show_review, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |             ] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |      * Delete the particular resource from storage. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  |      * @param  \Illuminate\Http\Request   $request     Incoming Request object. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |      * @param  \App\Models\JobApplication $application Incoming Application object. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  |      * @return \Illuminate\Http\Response | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  |     public function destroy(Request $request, JobApplication $application) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  |         $this->authorize('delete', $application); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  |         $application->delete(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  |         if ($request->ajax()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  |             return [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  |                 'message' => 'Application deleted' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  |             ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 |  |  |         return redirect()->back(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 181 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 182 |  |  |  |