public static function delete(array $restOfRoute) { RecruiterController::requireLogin(); $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; } // Delete all applications with jobid. ApplicationModel::deleteByJob($jobId); // Delete from questions' uses this jobid. $application = ApplicationJob::get($jobId); $questions = []; if (!is_null($application)) { $questions = $application->getQuestions(); } foreach ($questions as $questionId) { QuestionModel::removeFromUses($questionId, $jobId); } // Delete this job. JobModel::deleteById($jobId); // Redirect back to home. self::redirect('../home'); }