public function get_quiz_actions($quiz) { if (!is_object($quiz)) { return false; } // set blank array $quiz_actions = array(); $quiz_status = $quiz->get_quiz_status(); $quiz_id = $quiz->get_quiz_id(); if ($quiz_status === 'published') { $quiz_actions[] = array('title' => 'Results', 'url' => ENP_QUIZ_RESULTS_URL . $quiz_id); $quiz_actions[] = array('title' => 'Edit', 'url' => ENP_QUIZ_CREATE_URL . $quiz_id); $quiz_actions[] = array('title' => 'Settings', 'url' => ENP_QUIZ_PREVIEW_URL . $quiz_id); $quiz_actions[] = array('title' => 'Embed', 'url' => ENP_QUIZ_PUBLISH_URL . $quiz_id); } elseif ($quiz_status === 'draft') { $quiz_actions[] = array('title' => 'Edit', 'url' => ENP_QUIZ_CREATE_URL . $quiz_id); // see if the quiz is valid. If it is, allow a preview for it $response = new Enp_quiz_Save_quiz_Response(); $validate = $response->validate_quiz_and_questions($quiz); if ($validate === 'valid') { $quiz_actions[] = array('title' => 'Preview', 'url' => ENP_QUIZ_PREVIEW_URL . $quiz_id); } } return $quiz_actions; }
public function validate_quiz_redirect($quiz, $publish = false) { $response = new Enp_quiz_Save_quiz_Response(); $validate = $response->validate_quiz_and_questions($quiz); if ($validate === 'invalid') { // combine the arrays if (is_array(self::$message['error'])) { self::$message['error'] = array_merge(self::$message['error'], $response->get_error_messages()); } else { self::$message['error'] = $response->get_error_messages(); } // check to make sure there's actually a quiz... if ($quiz->get_quiz_id() === null) { // nope... redirect to quiz create $this->redirect_to_quiz_create('new'); } else { // There's a quiz, it's just an invalid quiz. // Send them back to the create page to fix it. $this->redirect_to_quiz_create($quiz->get_quiz_id()); } } elseif ($validate === 'valid' && $publish === 'publish') { // let's just send them to the preview page if they're trying to // access the publish URL on a NON-published quiz if ($quiz->get_quiz_status() !== 'published') { // add error message // add error message self::$message['error'][] = "Please use the Publish Button to publish a quiz instead of the Breadcrumb Publish link."; // redirect to preview page $this->redirect_to_quiz_preview($quiz->get_quiz_id()); } } }