// for the session asked for if (!($activequiz = $DB->get_record('activequiz', array('id' => $session->activequizid)))) { $jsonlib->send_error('invalid request'); } else { // place within try/catch in order to catch errors/redirects and just display invalid request. try { $course = $DB->get_record('course', array('id' => $activequiz->course), '*', MUST_EXIST); $cm = get_coursemodule_from_instance('activequiz', $activequiz->id, $course->id, false, MUST_EXIST); require_login($course->id, false, $cm, false, true); } catch (Exception $e) { $jsonlib->send_error('invalid request'); } } // if we have a session determine the response if ($session->sessionopen == 0) { $jsonlib->set('status', 'sessionclosed'); $jsonlib->send_response(); } else { if (empty($session->currentquestion)) { // send a status of quiz not running $jsonlib->set('status', 'notrunning'); $jsonlib->send_response(); } else { if ($session->status == 'reviewing') { $jsonlib->set('status', 'reviewing'); $jsonlib->send_response(); } else { if ($session->status == 'endquestion') { $jsonlib->set('status', 'endquestion'); $jsonlib->send_response(); } else {
/** * Handles the action specified * */ public function handle_action() { global $PAGE, $DB; // check if a session is open. If so display error. if ($sessions = $DB->get_records('activequiz_sessions', array('activequizid' => $this->RTQ->getRTQ()->id, 'sessionopen' => '1'))) { $this->RTQ->get_renderer()->print_editpage_header(); $this->RTQ->get_renderer()->editpage_opensession(); $this->RTQ->get_renderer()->end_editpage(); return; // return early to stop continuation. } switch ($this->action) { case 'dragdrop': // this is a javascript callack case for the drag and drop of questions using ajax $jsonlib = new \mod_activequiz\utils\jsonlib(); $questionorder = optional_param('questionorder', '', PARAM_RAW); if ($questionorder === '') { $jsonlib->send_error('invalid request'); } $questionorder = explode(',', $questionorder); if ($this->RTQ->get_questionmanager()->set_full_order($questionorder) === true) { $jsonlib->set('success', 'true'); $jsonlib->send_response(); } else { $jsonlib->send_error('unable to re-sort questions'); } break; case 'moveup': $questionid = required_param('questionid', PARAM_INT); if ($this->RTQ->get_questionmanager()->move_question('up', $questionid)) { $type = 'success'; $message = get_string('qmovesuccess', 'activequiz'); } else { $type = 'error'; $message = get_string('qmoveerror', 'activequiz'); } $this->RTQ->get_renderer()->setMessage($type, $message); $this->RTQ->get_renderer()->print_editpage_header($this->RTQ); $this->list_questions(); $this->RTQ->get_renderer()->end_editpage(); break; case 'movedown': $questionid = required_param('questionid', PARAM_INT); if ($this->RTQ->get_questionmanager()->move_question('down', $questionid)) { $type = 'success'; $message = get_string('qmovesuccess', 'activequiz'); } else { $type = 'error'; $message = get_string('qmoveerror', 'activequiz'); } $this->RTQ->get_renderer()->setMessage($type, $message); $this->RTQ->get_renderer()->print_editpage_header($this->RTQ); $this->list_questions(); $this->RTQ->get_renderer()->end_editpage(); break; case 'addquestion': $questionid = required_param('questionid', PARAM_INT); $this->RTQ->get_questionmanager()->add_question($questionid); break; case 'editquestion': $questionid = required_param('rtqquestionid', PARAM_INT); $this->RTQ->get_questionmanager()->edit_question($questionid); break; case 'deletequestion': $questionid = required_param('questionid', PARAM_INT); if ($this->RTQ->get_questionmanager()->delete_question($questionid)) { $type = 'success'; $message = get_string('qdeletesucess', 'activequiz'); } else { $type = 'error'; $message = get_string('qdeleteerror', 'activequiz'); } $this->RTQ->get_renderer()->setMessage($type, $message); $this->RTQ->get_renderer()->print_editpage_header($this->RTQ); $this->list_questions(); $this->RTQ->get_renderer()->end_editpage(); break; case 'listquestions': // default is to list the questions $this->RTQ->get_renderer()->print_editpage_header($this->RTQ); $this->list_questions(); $this->RTQ->get_renderer()->end_editpage(); break; } }