public static function edit(array $restOfRoute) { RecruiterController::requireLogin(); global $params; $jobId = self::getIdFromRoute($restOfRoute); if (is_null($jobId)) { return; } // Make sure job exists. // Make sure recruiter has permission to edit the job. if (!self::checkJobExists($jobId)) { return; } if (!self::ownsJob($jobId)) { return; } // Process saving of questions. if (self::save($jobId)) { return; } $vanillaQuestions = Question::getAllVanilla(); $vanillaQuestionsData = []; $chosenData = []; // Get existing questions. $chosenIds = ApplicationModel::getJobApplication($jobId); // Remove any existing from $vanillaQuestions. if ($chosenIds !== null) { $chosenIdHash = arrayToSet($chosenIds); } foreach ($vanillaQuestions as $question) { $id = (string) $question->getId(); $data = $question->getData(); $data['hide'] = $chosenIds !== null && isset($chosenIdHash[$id]); $vanillaQuestionsData[] = $data; } // If no application, we show form to create application. // Else, we show form to edit existing application. if ($chosenIds === null) { $createEdit = 'create'; } else { $createEdit = 'edit'; // Get the text for each $chosenIds. foreach ($chosenIds as $_id) { $data = QuestionModel::getById($_id, ['text' => 1, 'vanilla' => 1]); if ($data === null) { continue; } $text = $data['text']; $vanilla = $data['vanilla']; $chosenData[] = ['_id' => $_id, 'text' => $text, 'vanilla' => $vanilla]; } } $job = JobModel::getByIdMinimal($jobId); self::render('jobs/applications/edit', ['createEdit' => $createEdit, 'vanillaQuestions' => $vanillaQuestionsData, 'chosen' => $chosenData, 'jobId' => $jobId, 'jobTitle' => $job['title'], 'jobLocation' => $job['location']]); }
public static function exists(MongoId $jobId) { $applicationData = ApplicationModel::getJobApplication($jobId); return !is_null($applicationData); }