/** * set up the class for the view page * * @param string $baseurl the base url of the page */ public function setup_page($baseurl) { global $PAGE, $CFG, $DB; $this->pagevars = array(); $this->pageurl = new \moodle_url($baseurl); $this->pageurl->remove_all_params(); $id = optional_param('id', false, PARAM_INT); $quizid = optional_param('quizid', false, PARAM_INT); // get necessary records from the DB if ($id) { $cm = get_coursemodule_from_id('activequiz', $id, 0, false, MUST_EXIST); $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); $quiz = $DB->get_record('activequiz', array('id' => $cm->instance), '*', MUST_EXIST); } else { $quiz = $DB->get_record('activequiz', array('id' => $quizid), '*', MUST_EXIST); $course = $DB->get_record('course', array('id' => $quiz->course), '*', MUST_EXIST); $cm = get_coursemodule_from_instance('activequiz', $quiz->id, $course->id, false, MUST_EXIST); } $this->get_parameters(); // get the rest of the parameters and set them in the class require_login($course->id, false, $cm); $this->pageurl->param('id', $cm->id); $this->pageurl->param('quizid', $quiz->id); $this->pageurl->param('action', $this->pagevars['action']); $this->pagevars['pageurl'] = $this->pageurl; $this->RTQ = new \mod_activequiz\activequiz($cm, $course, $quiz, $this->pagevars); $this->RTQ->require_capability('mod/activequiz:seeresponses'); // set up renderer $this->RTQ->get_renderer()->init($this->RTQ, $this->pageurl, $this->pagevars); $PAGE->set_pagelayout('incourse'); $PAGE->set_context($this->RTQ->getContext()); $PAGE->set_title(strip_tags($course->shortname . ': ' . get_string("modulename", "activequiz") . ': ' . format_string($quiz->name, true))); $PAGE->set_heading($course->fullname); $PAGE->set_url($this->pageurl); }
/** * Sets up the edit page * * @param string $baseurl the base url of the * * @return array Array of variables that the page is set up with */ public function setup_page($baseurl) { global $PAGE, $CFG, $DB; $this->pagevars = array(); $pageurl = new \moodle_url($baseurl); $pageurl->remove_all_params(); $id = optional_param('cmid', false, PARAM_INT); $quizid = optional_param('quizid', false, PARAM_INT); // get necessary records from the DB if ($id) { $cm = get_coursemodule_from_id('activequiz', $id, 0, false, MUST_EXIST); $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); $quiz = $DB->get_record('activequiz', array('id' => $cm->instance), '*', MUST_EXIST); } else { $quiz = $DB->get_record('activequiz', array('id' => $quizid), '*', MUST_EXIST); $course = $DB->get_record('course', array('id' => $quiz->course), '*', MUST_EXIST); $cm = get_coursemodule_from_instance('activequiz', $quiz->id, $course->id, false, MUST_EXIST); } $this->get_parameters(); // get the rest of the parameters and set them in the class if ($CFG->version < 2011120100) { $this->context = get_context_instance(CONTEXT_MODULE, $cm->id); } else { $this->context = \context_module::instance($cm->id); } // set up question lib list($this->pageurl, $this->contexts, $cmid, $cm, $quiz, $this->pagevars) = question_edit_setup('editq', '/mod/activequiz/edit.php', true); $PAGE->set_url($this->pageurl); $this->pagevars['pageurl'] = $this->pageurl; $PAGE->set_title(strip_tags($course->shortname . ': ' . get_string("modulename", "activequiz") . ': ' . format_string($quiz->name, true))); $PAGE->set_heading($course->fullname); // setup classes needed for the edit page $this->RTQ = new \mod_activequiz\activequiz($cm, $course, $quiz, $this->pagevars); $this->RTQ->get_renderer()->init($this->RTQ, $this->pageurl, $this->pagevars); }
/** * Common setup for all pages for editing questions. * @param string $baseurl the name of the script calling this funciton. For examle 'qusetion/edit.php'. * @param string $edittab code for this edit tab * @param bool $requirecmid require cmid? default false * @param bool $requirecourseid require courseid, if cmid is not given? default true * @return array $thispageurl, $contexts, $cmid, $cm, $module, $pagevars */ function question_edit_setup($edittab, $baseurl, $requirecmid = false, $requirecourseid = true) { global $DB, $PAGE; $thispageurl = new moodle_url($baseurl); $thispageurl->remove_all_params(); // We are going to explicity add back everything important - this avoids unwanted params from being retained. if ($requirecmid) { $cmid = required_param('cmid', PARAM_INT); } else { $cmid = optional_param('cmid', 0, PARAM_INT); } if ($cmid) { list($module, $cm) = get_module_from_cmid($cmid); $courseid = $cm->course; $thispageurl->params(compact('cmid')); require_login($courseid, false, $cm); $thiscontext = context_module::instance($cmid); } else { $module = null; $cm = null; if ($requirecourseid) { $courseid = required_param('courseid', PARAM_INT); } else { $courseid = optional_param('courseid', 0, PARAM_INT); } if ($courseid) { $thispageurl->params(compact('courseid')); require_login($courseid, false); $thiscontext = context_course::instance($courseid); } else { $thiscontext = null; } } if ($thiscontext) { $contexts = new question_edit_contexts($thiscontext); $contexts->require_one_edit_tab_cap($edittab); } else { $contexts = null; } $PAGE->set_pagelayout('admin'); $pagevars['qpage'] = optional_param('qpage', -1, PARAM_INT); //pass 'cat' from page to page and when 'category' comes from a drop down menu //then we also reset the qpage so we go to page 1 of //a new cat. $pagevars['cat'] = optional_param('cat', 0, PARAM_SEQUENCE); // if empty will be set up later if ($category = optional_param('category', 0, PARAM_SEQUENCE)) { if ($pagevars['cat'] != $category) { // is this a move to a new category? $pagevars['cat'] = $category; $pagevars['qpage'] = 0; } } if ($pagevars['cat']) { $thispageurl->param('cat', $pagevars['cat']); } if (strpos($baseurl, '/question/') === 0) { navigation_node::override_active_url($thispageurl); } if ($pagevars['qpage'] > -1) { $thispageurl->param('qpage', $pagevars['qpage']); } else { $pagevars['qpage'] = 0; } $pagevars['qperpage'] = question_get_display_preference('qperpage', DEFAULT_QUESTIONS_PER_PAGE, PARAM_INT, $thispageurl); for ($i = 1; $i <= question_bank_view::MAX_SORTS; $i++) { $param = 'qbs' . $i; if (!($sort = optional_param($param, '', PARAM_TEXT))) { break; } $thispageurl->param($param, $sort); } $defaultcategory = question_make_default_categories($contexts->all()); $contextlistarr = array(); foreach ($contexts->having_one_edit_tab_cap($edittab) as $context) { $contextlistarr[] = "'{$context->id}'"; } $contextlist = join($contextlistarr, ' ,'); if (!empty($pagevars['cat'])) { $catparts = explode(',', $pagevars['cat']); if (!$catparts[0] || false !== array_search($catparts[1], $contextlistarr) || !$DB->count_records_select("question_categories", "id = ? AND contextid = ?", array($catparts[0], $catparts[1]))) { print_error('invalidcategory', 'question'); } } else { $category = $defaultcategory; $pagevars['cat'] = "{$category->id},{$category->contextid}"; } // Display options. $pagevars['recurse'] = question_get_display_preference('recurse', 1, PARAM_BOOL, $thispageurl); $pagevars['showhidden'] = question_get_display_preference('showhidden', 0, PARAM_BOOL, $thispageurl); $pagevars['qbshowtext'] = question_get_display_preference('qbshowtext', 0, PARAM_BOOL, $thispageurl); // Category list page. $pagevars['cpage'] = optional_param('cpage', 1, PARAM_INT); if ($pagevars['cpage'] != 1) { $thispageurl->param('cpage', $pagevars['cpage']); } return array($thispageurl, $contexts, $cmid, $cm, $module, $pagevars); }
/** * Common setup for all pages for editing questions. * @param string $baseurl the name of the script calling this funciton. For examle 'qusetion/edit.php'. * @param string $edittab code for this edit tab * @param bool $requirecmid require cmid? default false * @param bool $requirecourseid require courseid, if cmid is not given? default true * @return array $thispageurl, $contexts, $cmid, $cm, $module, $pagevars */ function question_edit_setup($edittab, $baseurl, $requirecmid = false, $requirecourseid = true) { global $DB, $PAGE; $thispageurl = new moodle_url($baseurl); $thispageurl->remove_all_params(); // We are going to explicity add back everything important - this avoids unwanted params from being retained. if ($requirecmid) { $cmid = required_param('cmid', PARAM_INT); } else { $cmid = optional_param('cmid', 0, PARAM_INT); } if ($cmid) { list($module, $cm) = get_module_from_cmid($cmid); $courseid = $cm->course; $thispageurl->params(compact('cmid')); require_login($courseid, false, $cm); $thiscontext = get_context_instance(CONTEXT_MODULE, $cmid); } else { $module = null; $cm = null; if ($requirecourseid) { $courseid = required_param('courseid', PARAM_INT); } else { $courseid = optional_param('courseid', 0, PARAM_INT); } if ($courseid) { $thispageurl->params(compact('courseid')); require_login($courseid, false); $thiscontext = get_context_instance(CONTEXT_COURSE, $courseid); } else { $thiscontext = null; } } if ($thiscontext) { $contexts = new question_edit_contexts($thiscontext); $contexts->require_one_edit_tab_cap($edittab); } else { $contexts = null; } $PAGE->set_pagelayout('admin'); $pagevars['qpage'] = optional_param('qpage', -1, PARAM_INT); //pass 'cat' from page to page and when 'category' comes from a drop down menu //then we also reset the qpage so we go to page 1 of //a new cat. $pagevars['cat'] = optional_param('cat', 0, PARAM_SEQUENCE); // if empty will be set up later if ($category = optional_param('category', 0, PARAM_SEQUENCE)) { if ($pagevars['cat'] != $category) { // is this a move to a new category? $pagevars['cat'] = $category; $pagevars['qpage'] = 0; } } if ($pagevars['cat']) { $thispageurl->param('cat', $pagevars['cat']); } if (strpos($baseurl, '/question/') === 0) { navigation_node::override_active_url($thispageurl); } if ($pagevars['qpage'] > -1) { $thispageurl->param('qpage', $pagevars['qpage']); } else { $pagevars['qpage'] = 0; } $pagevars['qperpage'] = optional_param('qperpage', -1, PARAM_INT); if ($pagevars['qperpage'] > -1) { $thispageurl->param('qperpage', $pagevars['qperpage']); } else { $pagevars['qperpage'] = DEFAULT_QUESTIONS_PER_PAGE; } $sortoptions = array('alpha' => 'name, qtype ASC', 'typealpha' => 'qtype, name ASC', 'age' => 'id ASC'); if ($sortorder = optional_param('qsortorder', '', PARAM_ALPHA)) { $pagevars['qsortorderdecoded'] = $sortoptions[$sortorder]; $pagevars['qsortorder'] = $sortorder; $thispageurl->param('qsortorder', $sortorder); } else { $pagevars['qsortorderdecoded'] = $sortoptions['typealpha']; $pagevars['qsortorder'] = 'typealpha'; } $defaultcategory = question_make_default_categories($contexts->all()); $contextlistarr = array(); foreach ($contexts->having_one_edit_tab_cap($edittab) as $context) { $contextlistarr[] = "'{$context->id}'"; } $contextlist = join($contextlistarr, ' ,'); if (!empty($pagevars['cat'])) { $catparts = explode(',', $pagevars['cat']); if (!$catparts[0] || false !== array_search($catparts[1], $contextlistarr) || !$DB->count_records_select("question_categories", "id = ? AND contextid = ?", array($catparts[0], $catparts[1]))) { print_error('invalidcategory', 'question'); } } else { $category = $defaultcategory; $pagevars['cat'] = "{$category->id},{$category->contextid}"; } if (($recurse = optional_param('recurse', -1, PARAM_BOOL)) != -1) { $pagevars['recurse'] = $recurse; $thispageurl->param('recurse', $recurse); } else { $pagevars['recurse'] = 1; } if (($showhidden = optional_param('showhidden', -1, PARAM_BOOL)) != -1) { $pagevars['showhidden'] = $showhidden; $thispageurl->param('showhidden', $showhidden); } else { $pagevars['showhidden'] = 0; } if (($showquestiontext = optional_param('showquestiontext', -1, PARAM_BOOL)) != -1) { $pagevars['showquestiontext'] = $showquestiontext; $thispageurl->param('showquestiontext', $showquestiontext); } else { $pagevars['showquestiontext'] = 0; } //category list page $pagevars['cpage'] = optional_param('cpage', 1, PARAM_INT); if ($pagevars['cpage'] != 1) { $thispageurl->param('cpage', $pagevars['cpage']); } return array($thispageurl, $contexts, $cmid, $cm, $module, $pagevars); }