public static function view(array $restOfRoute) { JobController::requireLogin(); $applicationId = self::getIdFromRoute($restOfRoute); if (is_null($applicationId)) { return; } $application = ApplicationStudent::getById($applicationId); if (is_null($application)) { self::error("nonexistent application"); self::render('notice'); return; } // Only the student who submitted the application and the recruiter // associated with the job can view the application. $myId = $_SESSION['_id']; $jobId = $application->getJobId(); $studentId = $application->getStudentId(); $recruiterId = JobModel::getRecruiterId($jobId); $isRecruiter = $recruiterId == $myId; $isStudent = $studentId == $myId; if (!$isStudent && !$isRecruiter) { self::error("permission denied"); self::render('notice'); return; } // Retrieve data for student. $student = StudentModel::getById($studentId, ['name' => 1]); $studentName = $student['name']; // Retrieve data on the job. $job = JobModel::getById($jobId); $title = $job['title']; $companyId = $job['company']; $company = CompanyModel::getById($companyId); // Set data from application. $profile = $application->getProfile(); $questions = $application->getQuestions(); // Add 'text' to questions to show. $responses = []; foreach ($questions as $question) { $_id = $question['_id']; $responses[] = ['_id' => $_id, 'text' => Question::getTextById($_id), 'answer' => $question['answer']]; } self::render('jobs/applications/view', ['responses' => toJSON($responses), 'studentname' => $studentName, 'jobtitle' => $title, 'companytitle' => $company['name'], 'isStudent' => $isStudent, 'isRecruiter' => $isRecruiter, 'studentId' => $studentId, 'recruiterId' => $recruiterId]); self::render('jobs/student/studentprofile', ['profile' => toJSON($profile)]); self::render('jobs/applications/report', ['applicationId' => $applicationId, 'isStudent' => $isStudent, 'isRecruiter' => $isRecruiter]); }