/** * Render an icon, optionally with the word 'Preview' beside it, to preview * a given question. * @param int $questionid the id of the question to be previewed. * @param context $context the context in which the preview is happening. * Must be a course or category context. * @param bool $showlabel if true, show the word 'Preview' after the icon. * If false, just show the icon. */ public function question_preview_link($questionid, context $context, $showlabel) { if ($showlabel) { $alt = ''; $label = ' ' . get_string('preview'); $attributes = array(); } else { $alt = get_string('preview'); $label = ''; $attributes = array('title' => $alt); } $image = $this->pix_icon('t/preview', $alt, '', array('class' => 'iconsmall')); $link = question_preview_url($questionid, null, null, null, null, $context); $action = new popup_action('click', $link, 'questionpreview', question_preview_popup_params()); return $this->action_link($link, $image . $label, $action, $attributes); }
/** * Delete the current preview, if any, and redirect to start a new preview. * @param int $previewid * @param int $questionid * @param object $displayoptions * @param object $context */ function restart_preview($previewid, $questionid, $displayoptions, $context) { global $DB; if ($previewid) { $transaction = $DB->start_delegated_transaction(); question_engine::delete_questions_usage_by_activity($previewid); $transaction->allow_commit(); } redirect(question_preview_url($questionid, $displayoptions->behaviour, $displayoptions->maxmark, $displayoptions, $displayoptions->variant, $context)); }
$options->load_user_defaults(); $options->set_from_request(); $PAGE->set_url(question_preview_url($id, $options->behaviour, $options->maxmark, $options)); // Get and validate exitsing preview, or start a new one. $previewid = optional_param('previewid', 0, PARAM_INT); if ($previewid) { if (!isset($SESSION->question_previews[$previewid])) { print_error('notyourpreview', 'question'); } try { $quba = question_engine::load_questions_usage_by_activity($previewid); } catch (Exception $e) { print_error('submissionoutofsequencefriendlymessage', 'question', question_preview_url($question->id, $options->behaviour, $options->maxmark, $options), null, $e); } $slot = $quba->get_first_question_number(); $usedquestion = $quba->get_question($slot); if ($usedquestion->id != $question->id) { print_error('questionidmismatch', 'question'); } $question = $usedquestion; $options->variant = $quba->get_variant($slot); } else { $quba = question_engine::make_questions_usage_by_activity('core_question_preview', get_context_instance_by_id($category->contextid)); $quba->set_preferred_behaviour($options->behaviour); $slot = $quba->add_question($question, $options->maxmark);
public function preview_question_url($question) { return question_preview_url($question->id, null, null, null, null, $this->contexts->lowest()); }
/** * @param object $quiz the quiz settings * @param object $question the question * @return moodle_url to preview this question with the options from this quiz. */ function quiz_question_preview_url($quiz, $question) { // Get the appropriate display options. $displayoptions = mod_quiz_display_options::make_from_quiz($quiz, mod_quiz_display_options::DURING); $maxmark = null; if (isset($question->maxmark)) { $maxmark = $question->maxmark; } // Work out the correcte preview URL. return question_preview_url($question->id, $quiz->preferredbehaviour, $maxmark, $displayoptions); }
/** * Get the URL to preview a question. * @param stdClass $questiondata the data defining the question. * @return moodle_url the URL. */ public function preview_question_url($questiondata) { return question_preview_url($questiondata->id, null, null, null, null, $this->get_most_specific_context()); }
$PAGE->set_pagelayout('popup'); // Get and validate display options. $maxvariant = min($question->get_num_variants(), QUESTION_PREVIEW_MAX_VARIANTS); $options = new question_preview_options($question); $options->load_user_defaults(); $options->set_from_request(); $PAGE->set_url(question_preview_url($id, $options->behaviour, $options->maxmark, $options, $options->variant, $context)); // Get and validate existing preview, or start a new one. $previewid = optional_param('previewid', 0, PARAM_INT); if ($previewid) { try { $quba = question_engine::load_questions_usage_by_activity($previewid); } catch (Exception $e) { // This may not seem like the right error message to display, but // actually from the user point of view, it makes sense. print_error('submissionoutofsequencefriendlymessage', 'question', question_preview_url($question->id, $options->behaviour, $options->maxmark, $options, $options->variant, $context), null, $e); } if ($quba->get_owning_context()->instanceid != $USER->id) { print_error('notyourpreview', 'question'); } $slot = $quba->get_first_question_number(); $usedquestion = $quba->get_question($slot); if ($usedquestion->id != $question->id) { print_error('questionidmismatch', 'question'); } $question = $usedquestion; $options->variant = $quba->get_variant($slot); } else { $quba = question_engine::make_questions_usage_by_activity('core_question_preview', context_user::instance($USER->id)); $quba->set_preferred_behaviour($options->behaviour); $slot = $quba->add_question($question, $options->maxmark);
$options->set_from_request(); $PAGE->set_url(question_preview_url($id, $options->behaviour, $options->maxmark, $options, $options->variant, $context)); // Get and validate existing preview, or start a new one. $previewid = optional_param('previewid', 0, PARAM_INT); if ($previewid) { try { $quba = question_engine::load_questions_usage_by_activity($previewid); } catch (Exception $e) { // This may not seem like the right error message to display, but // actually from the user point of view, it makes sense. print_error('submissionoutofsequencefriendlymessage', 'question', question_preview_url($question->id, $options->behaviour, $options->maxmark, $options, $options->variant, $context), null, $e); } if ($quba->get_owning_context()->instanceid != $USER->id) { print_error('notyourpreview', 'question'); } $slot = $quba->get_first_question_number(); $usedquestion = $quba->get_question($slot); if ($usedquestion->id != $question->id) { print_error('questionidmismatch', 'question'); } $question = $usedquestion; $options->variant = $quba->get_variant($slot); } else {
/** * @param object $offlinequiz the offlinequiz settings * @param object $question the question * @return moodle_url to preview this question with the options from this offlinequiz. */ function offlinequiz_question_preview_url($offlinequiz, $question) { // Get the appropriate display options. $displayoptions = mod_offlinequiz_display_options::make_from_offlinequiz($offlinequiz); $maxmark = null; if (isset($question->maxmark)) { $maxmark = $question->maxmark; } // Work out the correct preview URL. return question_preview_url($question->id, null, $maxmark, $displayoptions); }
$variantmatched = true; } else { if (empty($question->deployedseeds)) { echo html_writer::tag('p', stack_string('questionnotdeployedyet') . ' ' . $OUTPUT->action_icon(question_preview_url($questionid, null, null, null, null, $context), new pix_icon('t/preview', get_string('preview')))); } else { $notestable = new html_table(); $notestable->head = array(stack_string('variant'), stack_string('questionnote')); $prtstable->attributes['class'] = 'generaltable stacktestsuite'; foreach ($question->deployedseeds as $key => $deployedseed) { if (!is_null($question->seed) && $question->seed == $deployedseed) { $choice = html_writer::tag('b', $deployedseed, array('title' => stack_string('currentlyselectedvariant'))); $variantmatched = true; } else { $choice = html_writer::link(new moodle_url($PAGE->url, array('seed' => $deployedseed)), $deployedseed, array('title' => stack_string('testthisvariant'))); } $choice .= ' ' . $OUTPUT->action_icon(question_preview_url($questionid, null, null, null, $key + 1, $context), new pix_icon('t/preview', get_string('preview'))); if ($canedit) { $choice .= ' ' . $OUTPUT->action_icon(new moodle_url('/question/type/stack/deploy.php', $urlparams + array('undeploy' => $deployedseed, 'sesskey' => sesskey())), new pix_icon('t/delete', stack_string('undeploy'))); } // Print out question notes of all deployed versions. $qn = question_bank::load_question($questionid); $qn->seed = (int) $deployedseed; $cn = $qn->get_context(); $qunote = question_engine::make_questions_usage_by_activity('qtype_stack', $cn); $qunote->set_preferred_behaviour('adaptive'); $slotnote = $qunote->add_question($qn, $qn->defaultmark); $qunote->start_question($slotnote); // Check if the question note has already been deployed. if ($qn->get_question_summary() == $question->get_question_summary()) { $variantdeployed = true; }
public function preview_question_url($question) { return question_preview_url($question->id); }
$questionid = required_param('questionid', PARAM_INT); // Load the necessary data. $questiondata = $DB->get_record('question', array('id' => $questionid), '*', MUST_EXIST); $question = question_bank::load_question($questionid); // Process any other URL parameters, and do require_login. list($context, $notused, $urlparams) = qtype_stack_setup_question_test_page($question); // Check permissions. question_require_capability_on($questiondata, 'edit'); // Initialise $PAGE. $PAGE->set_url('/question/type/stack/tidyquestion.php', $urlparams); $title = stack_string('tidyquestionx', format_string($question->name)); $PAGE->set_title($title); $PAGE->set_heading($COURSE->fullname); $PAGE->set_pagelayout('admin'); // The URL back to the preview page. $returnurl = question_preview_url($questionid, null, null, null, null, $context); // Create the question usage we will use. $quba = question_engine::make_questions_usage_by_activity('qtype_stack', $context); $quba->set_preferred_behaviour('adaptive'); $slot = $quba->add_question($question, $question->defaultmark); $quba->start_question($slot); // Now we are going to display the question with each input box containing the // name of that input, and each feedback area displaying something like // "Feedback from PRT {name}". To do this, first we submit the right answer to // get the question into a state where all feedback will be displayed. $response = $question->get_correct_response(); $response['-submit'] = 1; $quba->process_action($slot, $response); // Now we want to be able to display the question with the wrong input values // and PRT feedback. We do that by polluting the question's input state and // PRT result caches with the data we want to display, then the renderer will