2009-11-04 11:58:30 +00:00
|
|
|
<?php
|
2011-02-10 20:44:47 +00:00
|
|
|
// This file is part of Moodle - http://moodle.org/
|
|
|
|
//
|
|
|
|
// Moodle is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// Moodle is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2009-01-19 05:30:01 +00:00
|
|
|
|
2005-05-06 06:24:04 +00:00
|
|
|
/**
|
2011-02-10 20:44:47 +00:00
|
|
|
* This contains functions that are called from within the quiz module only
|
|
|
|
* Functions that are also called by core Moodle are in {@link lib.php}
|
|
|
|
* This script also loads the code in {@link questionlib.php} which holds
|
|
|
|
* the module-indpendent code for handling questions and which in turn
|
|
|
|
* initialises all the questiontype classes.
|
2007-11-07 15:26:37 +00:00
|
|
|
*
|
2011-02-21 16:13:25 +00:00
|
|
|
* @package mod
|
2011-02-10 20:44:47 +00:00
|
|
|
* @subpackage quiz
|
2011-02-21 16:13:25 +00:00
|
|
|
* @copyright 1999 onwards Martin Dougiamas and others {@link http://moodle.com}
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
2011-02-10 20:44:47 +00:00
|
|
|
*/
|
|
|
|
|
2005-05-06 06:24:04 +00:00
|
|
|
|
2011-02-23 15:03:35 +00:00
|
|
|
defined('MOODLE_INTERNAL') || die();
|
2005-05-06 06:24:04 +00:00
|
|
|
|
2011-02-23 15:03:35 +00:00
|
|
|
require_once($CFG->dirroot . '/mod/quiz/locallib.php');
|
2011-02-10 20:44:47 +00:00
|
|
|
|
2009-02-11 10:08:07 +00:00
|
|
|
define('NUM_QS_TO_SHOW_IN_RANDOM', 3);
|
|
|
|
|
2012-03-28 13:55:17 +01:00
|
|
|
/**
|
|
|
|
* Verify that the question exists, and the user has permission to use it.
|
|
|
|
* Does not return. Throws an exception if the question cannot be used.
|
|
|
|
* @param int $questionid The id of the question.
|
|
|
|
*/
|
|
|
|
function quiz_require_question_use($questionid) {
|
|
|
|
global $DB;
|
|
|
|
$question = $DB->get_record('question', array('id' => $questionid), '*', MUST_EXIST);
|
|
|
|
question_require_capability_on($question, 'use');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Verify that the question exists, and the user has permission to use it.
|
|
|
|
* @param int $questionid The id of the question.
|
|
|
|
* @return bool whether the user can use this question.
|
|
|
|
*/
|
|
|
|
function quiz_has_question_use($questionid) {
|
|
|
|
global $DB;
|
|
|
|
$question = $DB->get_record('question', array('id' => $questionid), '*', MUST_EXIST);
|
|
|
|
return question_has_capability_on($question, 'use');
|
|
|
|
}
|
|
|
|
|
2005-05-06 06:24:04 +00:00
|
|
|
/**
|
2009-02-27 08:45:05 +00:00
|
|
|
* Remove a question from a quiz
|
|
|
|
* @param object $quiz the quiz object.
|
|
|
|
* @param int $questionid The id of the question to be deleted.
|
|
|
|
*/
|
|
|
|
function quiz_remove_question($quiz, $questionid) {
|
2008-06-09 10:00:35 +00:00
|
|
|
global $DB;
|
2005-05-06 06:24:04 +00:00
|
|
|
|
2009-02-27 08:45:05 +00:00
|
|
|
$questionids = explode(',', $quiz->questions);
|
|
|
|
$key = array_search($questionid, $questionids);
|
|
|
|
if ($key === false) {
|
|
|
|
return;
|
2005-05-06 06:24:04 +00:00
|
|
|
}
|
|
|
|
|
2009-02-27 08:45:05 +00:00
|
|
|
unset($questionids[$key]);
|
|
|
|
$quiz->questions = implode(',', $questionids);
|
|
|
|
$DB->set_field('quiz', 'questions', $quiz->questions, array('id' => $quiz->id));
|
2011-05-13 00:33:44 +01:00
|
|
|
$DB->delete_records('quiz_question_instances',
|
|
|
|
array('quiz' => $quiz->instance, 'question' => $questionid));
|
2009-02-27 08:45:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove an empty page from the quiz layout. If that is not possible, do nothing.
|
|
|
|
* @param string $layout the existinng layout, $quiz->questions.
|
2011-02-23 16:25:25 +00:00
|
|
|
* @param int $index the position into $layout where the empty page should be removed.
|
2009-02-27 08:45:05 +00:00
|
|
|
* @return the updated layout
|
|
|
|
*/
|
|
|
|
function quiz_delete_empty_page($layout, $index) {
|
|
|
|
$questionids = explode(',', $layout);
|
|
|
|
|
|
|
|
if ($index < -1 || $index >= count($questionids) - 1) {
|
|
|
|
return $layout;
|
2005-05-06 06:24:04 +00:00
|
|
|
}
|
2009-02-27 08:45:05 +00:00
|
|
|
|
|
|
|
if (($index >= 0 && $questionids[$index] != 0) || $questionids[$index + 1] != 0) {
|
|
|
|
return $layout; // This was not an empty page.
|
|
|
|
}
|
|
|
|
|
|
|
|
unset($questionids[$index + 1]);
|
|
|
|
|
|
|
|
return implode(',', $questionids);
|
2005-05-06 06:24:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-03-06 04:06:48 +00:00
|
|
|
* Add a question to a quiz
|
|
|
|
*
|
|
|
|
* Adds a question to a quiz by updating $quiz as well as the
|
|
|
|
* quiz and quiz_question_instances tables. It also adds a page break
|
|
|
|
* if required.
|
2010-11-22 09:52:42 +00:00
|
|
|
* @param int $id The id of the question to be added
|
|
|
|
* @param object $quiz The extended quiz object as used by edit.php
|
|
|
|
* This is updated by this function
|
2011-05-13 00:33:44 +01:00
|
|
|
* @param int $page Which page in quiz to add the question on. If 0 (default),
|
|
|
|
* add at the end
|
2011-02-23 16:25:25 +00:00
|
|
|
* @return bool false if the question was already in the quiz
|
2009-03-06 04:06:48 +00:00
|
|
|
*/
|
2010-11-22 09:52:42 +00:00
|
|
|
function quiz_add_quiz_question($id, $quiz, $page = 0) {
|
2008-06-09 10:00:35 +00:00
|
|
|
global $DB;
|
2010-05-01 08:11:25 +00:00
|
|
|
$questions = explode(',', quiz_clean_layout($quiz->questions));
|
2005-05-06 06:24:04 +00:00
|
|
|
if (in_array($id, $questions)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// remove ending page break if it is not needed
|
|
|
|
if ($breaks = array_keys($questions, 0)) {
|
|
|
|
// determine location of the last two page breaks
|
|
|
|
$end = end($breaks);
|
|
|
|
$last = prev($breaks);
|
|
|
|
$last = $last ? $last : -1;
|
2010-05-01 08:11:25 +00:00
|
|
|
if (!$quiz->questionsperpage || (($end - $last - 1) < $quiz->questionsperpage)) {
|
2005-05-06 06:24:04 +00:00
|
|
|
array_pop($questions);
|
|
|
|
}
|
|
|
|
}
|
2009-03-06 04:06:48 +00:00
|
|
|
if (is_int($page) && $page >= 1) {
|
|
|
|
$numofpages = quiz_number_of_pages($quiz->questions);
|
|
|
|
if ($numofpages<$page) {
|
2008-11-20 06:59:11 +00:00
|
|
|
//the page specified does not exist in quiz
|
2009-03-06 04:06:48 +00:00
|
|
|
$page = 0;
|
|
|
|
} else {
|
2008-11-20 06:59:11 +00:00
|
|
|
// add ending page break - the following logic requires doing
|
|
|
|
//this at this point
|
|
|
|
$questions[] = 0;
|
2009-03-06 04:06:48 +00:00
|
|
|
$currentpage = 1;
|
|
|
|
$addnow = false;
|
|
|
|
foreach ($questions as $question) {
|
|
|
|
if ($question == 0) {
|
2008-11-20 06:59:11 +00:00
|
|
|
$currentpage++;
|
|
|
|
//The current page is the one after the one we want to add on,
|
|
|
|
//so we add the question before adding the current page.
|
2009-03-06 04:06:48 +00:00
|
|
|
if ($currentpage == $page + 1) {
|
|
|
|
$questions_new[] = $id;
|
2008-11-20 06:59:11 +00:00
|
|
|
}
|
|
|
|
}
|
2009-03-06 04:06:48 +00:00
|
|
|
$questions_new[] = $question;
|
2008-11-20 06:59:11 +00:00
|
|
|
}
|
2009-03-06 04:06:48 +00:00
|
|
|
$questions = $questions_new;
|
2008-11-20 06:59:11 +00:00
|
|
|
}
|
|
|
|
}
|
2009-03-06 04:06:48 +00:00
|
|
|
if ($page == 0) {
|
2008-11-20 06:59:11 +00:00
|
|
|
// add question
|
|
|
|
$questions[] = $id;
|
|
|
|
// add ending page break
|
|
|
|
$questions[] = 0;
|
|
|
|
}
|
2005-05-06 06:24:04 +00:00
|
|
|
|
|
|
|
// Save new questionslist in database
|
2009-03-06 04:06:48 +00:00
|
|
|
$quiz->questions = implode(',', $questions);
|
2010-09-03 18:14:55 +00:00
|
|
|
$DB->set_field('quiz', 'questions', $quiz->questions, array('id' => $quiz->id));
|
2005-05-06 06:24:04 +00:00
|
|
|
|
2011-02-10 20:44:47 +00:00
|
|
|
// Add the new question instance.
|
2011-02-21 18:10:19 +00:00
|
|
|
$instance = new stdClass();
|
2011-02-10 20:44:47 +00:00
|
|
|
$instance->quiz = $quiz->id;
|
|
|
|
$instance->question = $id;
|
|
|
|
$instance->grade = $DB->get_field('question', 'defaultmark', array('id' => $id));
|
|
|
|
$DB->insert_record('quiz_question_instances', $instance);
|
2005-05-06 06:24:04 +00:00
|
|
|
}
|
|
|
|
|
2011-05-13 00:33:44 +01:00
|
|
|
function quiz_add_random_questions($quiz, $addonpage, $categoryid, $number,
|
|
|
|
$includesubcategories) {
|
2011-02-10 20:44:47 +00:00
|
|
|
global $DB;
|
2010-11-22 09:52:42 +00:00
|
|
|
|
|
|
|
$category = $DB->get_record('question_categories', array('id' => $categoryid));
|
|
|
|
if (!$category) {
|
|
|
|
print_error('invalidcategoryid', 'error');
|
|
|
|
}
|
|
|
|
|
|
|
|
$catcontext = get_context_instance_by_id($category->contextid);
|
|
|
|
require_capability('moodle/question:useall', $catcontext);
|
|
|
|
|
|
|
|
// Find existing random questions in this category that are
|
|
|
|
// not used by any quiz.
|
|
|
|
if ($existingquestions = $DB->get_records_sql(
|
2011-05-12 00:30:25 +01:00
|
|
|
"SELECT q.id, q.qtype FROM {question} q
|
2011-02-10 20:44:47 +00:00
|
|
|
WHERE qtype = 'random'
|
2010-11-22 09:52:42 +00:00
|
|
|
AND category = ?
|
|
|
|
AND " . $DB->sql_compare_text('questiontext') . " = ?
|
2011-05-13 00:33:44 +01:00
|
|
|
AND NOT EXISTS (
|
|
|
|
SELECT *
|
|
|
|
FROM {quiz_question_instances}
|
|
|
|
WHERE question = q.id)
|
2010-11-22 09:52:42 +00:00
|
|
|
ORDER BY id", array($category->id, $includesubcategories))) {
|
|
|
|
// Take as many of these as needed.
|
|
|
|
while (($existingquestion = array_shift($existingquestions)) && $number > 0) {
|
|
|
|
quiz_add_quiz_question($existingquestion->id, $quiz, $addonpage);
|
|
|
|
$number -= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($number <= 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// More random questions are needed, create them.
|
|
|
|
for ($i = 0; $i < $number; $i += 1) {
|
2011-02-11 17:36:02 +00:00
|
|
|
$form = new stdClass();
|
|
|
|
$form->questiontext = array('text' => $includesubcategories, 'format' => 0);
|
2010-11-22 09:52:42 +00:00
|
|
|
$form->category = $category->id . ',' . $category->contextid;
|
2011-02-11 17:36:02 +00:00
|
|
|
$form->defaultmark = 1;
|
|
|
|
$form->hidden = 1;
|
2010-11-22 09:52:42 +00:00
|
|
|
$form->stamp = make_unique_id_code(); // Set the unique code (not to be changed)
|
2011-02-21 18:10:19 +00:00
|
|
|
$question = new stdClass();
|
2011-02-10 20:44:47 +00:00
|
|
|
$question->qtype = 'random';
|
|
|
|
$question = question_bank::get_qtype('random')->save_question($question, $form);
|
2010-11-22 09:52:42 +00:00
|
|
|
if (!isset($question->id)) {
|
|
|
|
print_error('cannotinsertrandomquestion', 'quiz');
|
|
|
|
}
|
|
|
|
quiz_add_quiz_question($question->id, $quiz, $addonpage);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-27 08:45:05 +00:00
|
|
|
/**
|
|
|
|
* Add a page break after at particular position$.
|
|
|
|
* @param string $layout the existinng layout, $quiz->questions.
|
2011-02-23 16:25:25 +00:00
|
|
|
* @param int $index the position into $layout where the empty page should be removed.
|
2009-02-27 08:45:05 +00:00
|
|
|
* @return the updated layout
|
|
|
|
*/
|
|
|
|
function quiz_add_page_break_at($layout, $index) {
|
|
|
|
$questionids = explode(',', $layout);
|
|
|
|
if ($index < 0 || $index >= count($questionids)) {
|
|
|
|
return $layout;
|
|
|
|
}
|
|
|
|
|
|
|
|
array_splice($questionids, $index, 0, '0');
|
|
|
|
|
|
|
|
return implode(',', $questionids);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a page break after a particular question.
|
|
|
|
* @param string $layout the existinng layout, $quiz->questions.
|
2011-02-23 16:25:25 +00:00
|
|
|
* @param int $qustionid the question to add the page break after.
|
2009-02-27 08:45:05 +00:00
|
|
|
* @return the updated layout
|
|
|
|
*/
|
|
|
|
function quiz_add_page_break_after($layout, $questionid) {
|
|
|
|
$questionids = explode(',', $layout);
|
|
|
|
$key = array_search($questionid, $questionids);
|
|
|
|
if ($key === false || !$questionid) {
|
|
|
|
return $layout;
|
|
|
|
}
|
|
|
|
|
|
|
|
array_splice($questionids, $key + 1, 0, '0');
|
|
|
|
|
|
|
|
return implode(',', $questionids);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the database after $quiz->questions has been changed. For example,
|
|
|
|
* this deletes preview attempts and updates $quiz->sumgrades.
|
|
|
|
* @param $quiz the quiz object.
|
|
|
|
*/
|
|
|
|
function quiz_save_new_layout($quiz) {
|
|
|
|
global $DB;
|
|
|
|
$DB->set_field('quiz', 'questions', $quiz->questions, array('id' => $quiz->id));
|
|
|
|
quiz_delete_previews($quiz);
|
2012-01-11 16:21:47 +00:00
|
|
|
quiz_update_sumgrades($quiz);
|
2009-02-27 08:45:05 +00:00
|
|
|
}
|
|
|
|
|
2005-05-06 06:24:04 +00:00
|
|
|
/**
|
2009-03-06 04:06:48 +00:00
|
|
|
* Save changes to question instance
|
|
|
|
*
|
|
|
|
* Saves changes to the question grades in the quiz_question_instances table.
|
|
|
|
* It does not update 'sumgrades' in the quiz table.
|
2011-02-10 20:44:47 +00:00
|
|
|
*
|
2011-02-23 16:25:25 +00:00
|
|
|
* @param int grade The maximal grade for the question
|
|
|
|
* @param int $questionid The id of the question
|
|
|
|
* @param int $quizid The id of the quiz to update / add the instances for.
|
2009-03-06 04:06:48 +00:00
|
|
|
*/
|
2011-02-10 20:44:47 +00:00
|
|
|
function quiz_update_question_instance($grade, $questionid, $quiz) {
|
2011-02-11 17:36:02 +00:00
|
|
|
global $DB;
|
|
|
|
$instance = $DB->get_record('quiz_question_instances', array('quiz' => $quiz->id,
|
2011-02-10 20:44:47 +00:00
|
|
|
'question' => $questionid));
|
|
|
|
$slot = quiz_get_slot_for_question($quiz, $questionid);
|
|
|
|
|
|
|
|
if (!$instance || !$slot) {
|
|
|
|
throw new coding_exception('Attempt to change the grade of a quesion not in the quiz.');
|
2005-05-06 06:24:04 +00:00
|
|
|
}
|
2011-02-10 20:44:47 +00:00
|
|
|
|
|
|
|
if (abs($grade - $instance->grade) < 1e-7) {
|
|
|
|
// Grade has not changed. Nothing to do.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$instance->grade = $grade;
|
|
|
|
$DB->update_record('quiz_question_instances', $instance);
|
2011-03-16 18:56:14 +00:00
|
|
|
question_engine::set_max_mark_in_attempts(new qubaids_for_quiz($quiz->id),
|
2011-02-10 20:44:47 +00:00
|
|
|
$slot, $grade);
|
2005-05-06 06:24:04 +00:00
|
|
|
}
|
|
|
|
|
2009-02-27 08:45:05 +00:00
|
|
|
// Private function used by the following two.
|
|
|
|
function _quiz_move_question($layout, $questionid, $shift) {
|
|
|
|
if (!$questionid || !($shift == 1 || $shift == -1)) {
|
|
|
|
return $layout;
|
|
|
|
}
|
|
|
|
|
|
|
|
$questionids = explode(',', $layout);
|
|
|
|
$key = array_search($questionid, $questionids);
|
|
|
|
if ($key === false) {
|
|
|
|
return $layout;
|
|
|
|
}
|
|
|
|
|
|
|
|
$otherkey = $key + $shift;
|
|
|
|
if ($otherkey < 0 || $otherkey >= count($questionids) - 1) {
|
|
|
|
return $layout;
|
|
|
|
}
|
|
|
|
|
|
|
|
$temp = $questionids[$otherkey];
|
|
|
|
$questionids[$otherkey] = $questionids[$key];
|
|
|
|
$questionids[$key] = $temp;
|
|
|
|
|
|
|
|
return implode(',', $questionids);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Move a particular question one space earlier in the $quiz->questions list.
|
|
|
|
* If that is not possible, do nothing.
|
|
|
|
* @param string $layout the existinng layout, $quiz->questions.
|
2011-02-23 16:25:25 +00:00
|
|
|
* @param int $questionid the id of a question.
|
2009-02-27 08:45:05 +00:00
|
|
|
* @return the updated layout
|
|
|
|
*/
|
|
|
|
function quiz_move_question_up($layout, $questionid) {
|
|
|
|
return _quiz_move_question($layout, $questionid, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Move a particular question one space later in the $quiz->questions list.
|
|
|
|
* If that is not possible, do nothing.
|
|
|
|
* @param string $layout the existinng layout, $quiz->questions.
|
2011-02-23 16:25:25 +00:00
|
|
|
* @param int $questionid the id of a question.
|
2009-02-27 08:45:05 +00:00
|
|
|
* @return the updated layout
|
|
|
|
*/
|
|
|
|
function quiz_move_question_down($layout, $questionid) {
|
|
|
|
return _quiz_move_question($layout, $questionid, +1);
|
|
|
|
}
|
|
|
|
|
2005-05-06 06:24:04 +00:00
|
|
|
/**
|
2009-03-06 04:06:48 +00:00
|
|
|
* Prints a list of quiz questions for the edit.php main view for edit
|
|
|
|
* ($reordertool = false) and order and paging ($reordertool = true) tabs
|
|
|
|
*
|
|
|
|
* @param object $quiz This is not the standard quiz object used elsewhere but
|
|
|
|
* it contains the quiz layout in $quiz->questions and the grades in
|
|
|
|
* $quiz->grades
|
2012-03-28 13:55:17 +01:00
|
|
|
* @param moodle_url $pageurl The url of the current page with the parameters required
|
2009-03-06 04:06:48 +00:00
|
|
|
* for links returning to the current page, as a moodle_url object
|
2011-02-23 16:25:25 +00:00
|
|
|
* @param bool $allowdelete Indicates whether the delete icons should be displayed
|
|
|
|
* @param bool $reordertool Indicates whether the reorder tool should be displayed
|
|
|
|
* @param bool $quiz_qbanktool Indicates whether the question bank should be displayed
|
|
|
|
* @param bool $hasattempts Indicates whether the quiz has attempts
|
2012-03-28 13:55:17 +01:00
|
|
|
* @param object $defaultcategoryobj
|
|
|
|
* @param bool $canaddquestion is the user able to add and use questions anywere?
|
|
|
|
* @param bool $canaddrandom is the user able to add random questions anywere?
|
2009-03-06 04:06:48 +00:00
|
|
|
*/
|
2010-11-24 09:05:22 +00:00
|
|
|
function quiz_print_question_list($quiz, $pageurl, $allowdelete, $reordertool,
|
2012-03-28 13:55:17 +01:00
|
|
|
$quiz_qbanktool, $hasattempts, $defaultcategoryobj, $canaddquestion, $canaddrandom) {
|
2012-01-30 17:47:11 +00:00
|
|
|
global $CFG, $DB, $OUTPUT;
|
2009-03-06 04:06:48 +00:00
|
|
|
$strorder = get_string('order');
|
|
|
|
$strquestionname = get_string('questionname', 'quiz');
|
2012-04-02 16:28:24 +01:00
|
|
|
$strmaxmark = get_string('markedoutof', 'question');
|
2005-05-06 06:24:04 +00:00
|
|
|
$strremove = get_string('remove', 'quiz');
|
2009-03-06 04:06:48 +00:00
|
|
|
$stredit = get_string('edit');
|
|
|
|
$strview = get_string('view');
|
|
|
|
$straction = get_string('action');
|
|
|
|
$strmove = get_string('move');
|
|
|
|
$strmoveup = get_string('moveup');
|
|
|
|
$strmovedown = get_string('movedown');
|
|
|
|
$strsave = get_string('save', 'quiz');
|
|
|
|
$strreorderquestions = get_string('reorderquestions', 'quiz');
|
|
|
|
|
|
|
|
$strselectall = get_string('selectall', 'quiz');
|
|
|
|
$strselectnone = get_string('selectnone', 'quiz');
|
|
|
|
$strtype = get_string('type', 'quiz');
|
|
|
|
$strpreview = get_string('preview', 'quiz');
|
2005-05-06 06:24:04 +00:00
|
|
|
|
2009-01-05 05:26:08 +00:00
|
|
|
if ($quiz->questions) {
|
2008-11-20 06:59:11 +00:00
|
|
|
list($usql, $params) = $DB->get_in_or_equal(explode(',', $quiz->questions));
|
2011-02-10 20:44:47 +00:00
|
|
|
$params[] = $quiz->id;
|
|
|
|
$questions = $DB->get_records_sql("SELECT q.*, qc.contextid, qqi.grade as maxmark
|
|
|
|
FROM {question} q
|
|
|
|
JOIN {question_categories} qc ON qc.id = q.category
|
|
|
|
JOIN {quiz_question_instances} qqi ON qqi.question = q.id
|
|
|
|
WHERE q.id $usql AND qqi.quiz = ?", $params);
|
2009-01-05 05:26:08 +00:00
|
|
|
} else {
|
|
|
|
$questions = array();
|
2005-05-06 06:24:04 +00:00
|
|
|
}
|
|
|
|
|
2009-03-06 04:06:48 +00:00
|
|
|
$layout = quiz_clean_layout($quiz->questions);
|
2008-11-20 06:59:11 +00:00
|
|
|
$order = explode(',', $layout);
|
2009-03-06 04:06:48 +00:00
|
|
|
$lastindex = count($order) - 1;
|
2008-11-20 06:59:11 +00:00
|
|
|
|
quiz editing: MDL-17454 first attemtp, and MDL-18554
This is a minimal fix for MDL-18554, I have just added a cancel button and made it work.
The more substantial part of this is MDL-17454, trying to make the quiz editing screen behave appropriately when shuffle questions is on. I am sure Olli will have opinions about this and want to change it further. Rought summary:
* When shufflequestions is off, never restrict manual paging, even if questionsperpage is set.
* When shuffle questions is on:
** Always display the quiz with the defined number of questions per page.
** Remove controls to add things except at the end of the quiz.
** Disable most of the order and paging tab, but still allow the question list to be reordered, in case that helps teachers track which questions they have added.
** Still allow questions to be reordered on the edit tab, but when moving the top question on a page up, reorder with the previous question, rather than moving to the previous page.
* Change the status bar, so that the yellow highlight is reserved for alert information. The more informative stuff is now plain, and moved to under the title. To my mind that associates it more closely with the quiz name. Also it moves Total of grades and Maximum grade closer together.
* JavaScript cleaned up. I learn more about YUI every day.
* Some PHP code clean ups that I forgot to commit separately before making substantive changes.
2009-03-17 09:51:34 +00:00
|
|
|
$disabled = '';
|
|
|
|
$pagingdisabled = '';
|
2009-01-05 05:26:08 +00:00
|
|
|
if ($hasattempts) {
|
2009-03-06 04:06:48 +00:00
|
|
|
$disabled = 'disabled="disabled"';
|
2008-11-20 06:59:11 +00:00
|
|
|
}
|
quiz editing: MDL-17454 first attemtp, and MDL-18554
This is a minimal fix for MDL-18554, I have just added a cancel button and made it work.
The more substantial part of this is MDL-17454, trying to make the quiz editing screen behave appropriately when shuffle questions is on. I am sure Olli will have opinions about this and want to change it further. Rought summary:
* When shufflequestions is off, never restrict manual paging, even if questionsperpage is set.
* When shuffle questions is on:
** Always display the quiz with the defined number of questions per page.
** Remove controls to add things except at the end of the quiz.
** Disable most of the order and paging tab, but still allow the question list to be reordered, in case that helps teachers track which questions they have added.
** Still allow questions to be reordered on the edit tab, but when moving the top question on a page up, reorder with the previous question, rather than moving to the previous page.
* Change the status bar, so that the yellow highlight is reserved for alert information. The more informative stuff is now plain, and moved to under the title. To my mind that associates it more closely with the quiz name. Also it moves Total of grades and Maximum grade closer together.
* JavaScript cleaned up. I learn more about YUI every day.
* Some PHP code clean ups that I forgot to commit separately before making substantive changes.
2009-03-17 09:51:34 +00:00
|
|
|
if ($hasattempts || $quiz->shufflequestions) {
|
2009-03-06 04:06:48 +00:00
|
|
|
$pagingdisabled = 'disabled="disabled"';
|
2005-05-24 16:11:55 +00:00
|
|
|
}
|
2005-05-06 06:24:04 +00:00
|
|
|
|
2009-03-06 04:06:48 +00:00
|
|
|
$reordercontrolssetdefaultsubmit = '<div style="display:none;">' .
|
|
|
|
'<input type="submit" name="savechanges" value="' .
|
quiz editing: MDL-17454 first attemtp, and MDL-18554
This is a minimal fix for MDL-18554, I have just added a cancel button and made it work.
The more substantial part of this is MDL-17454, trying to make the quiz editing screen behave appropriately when shuffle questions is on. I am sure Olli will have opinions about this and want to change it further. Rought summary:
* When shufflequestions is off, never restrict manual paging, even if questionsperpage is set.
* When shuffle questions is on:
** Always display the quiz with the defined number of questions per page.
** Remove controls to add things except at the end of the quiz.
** Disable most of the order and paging tab, but still allow the question list to be reordered, in case that helps teachers track which questions they have added.
** Still allow questions to be reordered on the edit tab, but when moving the top question on a page up, reorder with the previous question, rather than moving to the previous page.
* Change the status bar, so that the yellow highlight is reserved for alert information. The more informative stuff is now plain, and moved to under the title. To my mind that associates it more closely with the quiz name. Also it moves Total of grades and Maximum grade closer together.
* JavaScript cleaned up. I learn more about YUI every day.
* Some PHP code clean ups that I forgot to commit separately before making substantive changes.
2009-03-17 09:51:34 +00:00
|
|
|
$strreorderquestions . '" ' . $pagingdisabled . ' /></div>';
|
2009-03-06 04:06:48 +00:00
|
|
|
$reordercontrols1 = '<div class="addnewpagesafterselected">' .
|
|
|
|
'<input type="submit" name="addnewpagesafterselected" value="' .
|
|
|
|
get_string('addnewpagesafterselected', 'quiz') . '" ' .
|
|
|
|
$pagingdisabled . ' /></div>';
|
2009-02-13 07:11:55 +00:00
|
|
|
$reordercontrols1 .= '<div class="quizdeleteselected">' .
|
|
|
|
'<input type="submit" name="quizdeleteselected" ' .
|
|
|
|
'onclick="return confirm(\'' .
|
|
|
|
get_string('areyousureremoveselected', 'quiz') . '\');" value="' .
|
|
|
|
get_string('removeselected', 'quiz') . '" ' . $disabled . ' /></div>';
|
2008-11-20 06:59:11 +00:00
|
|
|
|
2012-04-11 17:18:58 +12:00
|
|
|
$a = '<input name="moveselectedonpagetop" type="text" size="2" ' .
|
2009-03-06 04:06:48 +00:00
|
|
|
$pagingdisabled . ' />';
|
2012-04-11 17:18:58 +12:00
|
|
|
$b = '<input name="moveselectedonpagebottom" type="text" size="2" ' .
|
2011-08-22 23:55:46 +01:00
|
|
|
$pagingdisabled . ' />';
|
2009-03-06 04:06:48 +00:00
|
|
|
|
|
|
|
$reordercontrols2top = '<div class="moveselectedonpage">' .
|
|
|
|
get_string('moveselectedonpage', 'quiz', $a) .
|
|
|
|
'<input type="submit" name="savechanges" value="' .
|
|
|
|
$strmove . '" ' . $pagingdisabled . ' />' . '
|
|
|
|
<br /><input type="submit" name="savechanges" value="' .
|
quiz editing: MDL-17454 first attemtp, and MDL-18554
This is a minimal fix for MDL-18554, I have just added a cancel button and made it work.
The more substantial part of this is MDL-17454, trying to make the quiz editing screen behave appropriately when shuffle questions is on. I am sure Olli will have opinions about this and want to change it further. Rought summary:
* When shufflequestions is off, never restrict manual paging, even if questionsperpage is set.
* When shuffle questions is on:
** Always display the quiz with the defined number of questions per page.
** Remove controls to add things except at the end of the quiz.
** Disable most of the order and paging tab, but still allow the question list to be reordered, in case that helps teachers track which questions they have added.
** Still allow questions to be reordered on the edit tab, but when moving the top question on a page up, reorder with the previous question, rather than moving to the previous page.
* Change the status bar, so that the yellow highlight is reserved for alert information. The more informative stuff is now plain, and moved to under the title. To my mind that associates it more closely with the quiz name. Also it moves Total of grades and Maximum grade closer together.
* JavaScript cleaned up. I learn more about YUI every day.
* Some PHP code clean ups that I forgot to commit separately before making substantive changes.
2009-03-17 09:51:34 +00:00
|
|
|
$strreorderquestions . '" /></div>';
|
2009-03-06 04:06:48 +00:00
|
|
|
$reordercontrols2bottom = '<div class="moveselectedonpage">' .
|
|
|
|
'<input type="submit" name="savechanges" value="' .
|
quiz editing: MDL-17454 first attemtp, and MDL-18554
This is a minimal fix for MDL-18554, I have just added a cancel button and made it work.
The more substantial part of this is MDL-17454, trying to make the quiz editing screen behave appropriately when shuffle questions is on. I am sure Olli will have opinions about this and want to change it further. Rought summary:
* When shufflequestions is off, never restrict manual paging, even if questionsperpage is set.
* When shuffle questions is on:
** Always display the quiz with the defined number of questions per page.
** Remove controls to add things except at the end of the quiz.
** Disable most of the order and paging tab, but still allow the question list to be reordered, in case that helps teachers track which questions they have added.
** Still allow questions to be reordered on the edit tab, but when moving the top question on a page up, reorder with the previous question, rather than moving to the previous page.
* Change the status bar, so that the yellow highlight is reserved for alert information. The more informative stuff is now plain, and moved to under the title. To my mind that associates it more closely with the quiz name. Also it moves Total of grades and Maximum grade closer together.
* JavaScript cleaned up. I learn more about YUI every day.
* Some PHP code clean ups that I forgot to commit separately before making substantive changes.
2009-03-17 09:51:34 +00:00
|
|
|
$strreorderquestions . '" /><br />' .
|
2011-08-22 23:55:46 +01:00
|
|
|
get_string('moveselectedonpage', 'quiz', $b) .
|
2009-03-06 04:06:48 +00:00
|
|
|
'<input type="submit" name="savechanges" value="' .
|
|
|
|
$strmove . '" ' . $pagingdisabled . ' /> ' . '</div>';
|
|
|
|
|
|
|
|
$reordercontrols3 = '<a href="javascript:select_all_in(\'FORM\', null, ' .
|
|
|
|
'\'quizquestions\');">' .
|
|
|
|
$strselectall . '</a> /';
|
|
|
|
$reordercontrols3.= ' <a href="javascript:deselect_all_in(\'FORM\', ' .
|
|
|
|
'null, \'quizquestions\');">' .
|
|
|
|
$strselectnone . '</a>';
|
|
|
|
|
|
|
|
$reordercontrolstop = '<div class="reordercontrols">' .
|
|
|
|
$reordercontrolssetdefaultsubmit .
|
|
|
|
$reordercontrols1 . $reordercontrols2top . $reordercontrols3 . "</div>";
|
|
|
|
$reordercontrolsbottom = '<div class="reordercontrols">' .
|
|
|
|
$reordercontrolssetdefaultsubmit .
|
|
|
|
$reordercontrols2bottom . $reordercontrols1 . $reordercontrols3 . "</div>";
|
|
|
|
|
|
|
|
if ($reordertool) {
|
2008-11-20 06:59:11 +00:00
|
|
|
echo '<form method="post" action="edit.php" id="quizquestions"><div>';
|
|
|
|
|
2010-01-17 09:06:55 +00:00
|
|
|
echo html_writer::input_hidden_params($pageurl);
|
2009-03-06 04:06:48 +00:00
|
|
|
echo '<input type="hidden" name="sesskey" value="' . sesskey() . '" />';
|
2008-11-20 06:59:11 +00:00
|
|
|
|
|
|
|
echo $reordercontrolstop;
|
2008-06-09 10:00:35 +00:00
|
|
|
}
|
2008-04-17 08:50:56 +00:00
|
|
|
|
2008-11-20 06:59:11 +00:00
|
|
|
//the current question ordinal (no descriptions)
|
|
|
|
$qno = 1;
|
|
|
|
//the current question (includes questions and descriptions)
|
2009-03-06 04:06:48 +00:00
|
|
|
$questioncount = 0;
|
2008-11-20 06:59:11 +00:00
|
|
|
//the current page number in iteration
|
|
|
|
$pagecount = 0;
|
|
|
|
|
2009-03-06 04:06:48 +00:00
|
|
|
$pageopen = false;
|
2008-11-20 06:59:11 +00:00
|
|
|
|
2011-08-24 15:31:56 +01:00
|
|
|
$returnurl = $pageurl->out_as_local_url(false);
|
2009-03-06 04:06:48 +00:00
|
|
|
$questiontotalcount = count($order);
|
2008-11-20 06:59:11 +00:00
|
|
|
|
2011-02-10 20:44:47 +00:00
|
|
|
foreach ($order as $count => $qnum) {
|
2005-05-06 06:24:04 +00:00
|
|
|
|
2009-03-06 04:06:48 +00:00
|
|
|
$reordercheckbox = '';
|
|
|
|
$reordercheckboxlabel = '';
|
|
|
|
$reordercheckboxlabelclose = '';
|
2008-11-20 06:59:11 +00:00
|
|
|
|
2006-03-24 21:21:59 +00:00
|
|
|
// If the questiontype is missing change the question type
|
2011-02-10 20:44:47 +00:00
|
|
|
if ($qnum && !array_key_exists($qnum, $questions)) {
|
|
|
|
$fakequestion = new stdClass();
|
2012-01-09 16:33:53 +00:00
|
|
|
$fakequestion->id = $qnum;
|
|
|
|
$fakequestion->category = 0;
|
2011-02-10 20:44:47 +00:00
|
|
|
$fakequestion->qtype = 'missingtype';
|
2012-01-09 16:33:53 +00:00
|
|
|
$fakequestion->name = get_string('missingquestion', 'quiz');
|
|
|
|
$fakequestion->questiontext = ' ';
|
|
|
|
$fakequestion->questiontextformat = FORMAT_HTML;
|
|
|
|
$fakequestion->length = 1;
|
2011-02-10 20:44:47 +00:00
|
|
|
$questions[$qnum] = $fakequestion;
|
|
|
|
$quiz->grades[$qnum] = 0;
|
|
|
|
|
2011-02-11 17:36:02 +00:00
|
|
|
} else if ($qnum && !question_bank::qtype_exists($questions[$qnum]->qtype)) {
|
2006-03-24 21:21:59 +00:00
|
|
|
$questions[$qnum]->qtype = 'missingtype';
|
|
|
|
}
|
2011-02-10 20:44:47 +00:00
|
|
|
|
2009-02-27 08:45:05 +00:00
|
|
|
if ($qnum != 0 || ($qnum == 0 && !$pageopen)) {
|
2008-11-20 06:59:11 +00:00
|
|
|
//this is either a question or a page break after another
|
|
|
|
// (no page is currently open)
|
2009-02-27 08:45:05 +00:00
|
|
|
if (!$pageopen) {
|
2008-11-20 06:59:11 +00:00
|
|
|
//if no page is open, start display of a page
|
|
|
|
$pagecount++;
|
2009-03-06 04:06:48 +00:00
|
|
|
echo '<div class="quizpage"><span class="pagetitle">' .
|
|
|
|
get_string('page') . ' ' . $pagecount .
|
2008-11-20 06:59:11 +00:00
|
|
|
'</span><div class="pagecontent">';
|
2009-02-27 08:45:05 +00:00
|
|
|
$pageopen = true;
|
2008-11-20 06:59:11 +00:00
|
|
|
}
|
2011-02-10 20:44:47 +00:00
|
|
|
if ($qnum == 0 && $count < $questiontotalcount) {
|
2009-02-27 08:45:05 +00:00
|
|
|
// This is the second successive page break. Tell the user the page is empty.
|
2008-11-20 06:59:11 +00:00
|
|
|
echo '<div class="pagestatus">';
|
2009-03-06 04:06:48 +00:00
|
|
|
print_string('noquestionsonpage', 'quiz');
|
2008-11-20 06:59:11 +00:00
|
|
|
echo '</div>';
|
2010-08-04 16:47:57 +00:00
|
|
|
if ($allowdelete) {
|
2008-11-20 06:59:11 +00:00
|
|
|
echo '<div class="quizpagedelete">';
|
2011-05-13 00:33:44 +01:00
|
|
|
echo $OUTPUT->action_icon($pageurl->out(true,
|
|
|
|
array('deleteemptypage' => $count - 1, 'sesskey'=>sesskey())),
|
2011-02-11 17:36:02 +00:00
|
|
|
new pix_icon('t/delete', $strremove),
|
2011-05-13 00:33:44 +01:00
|
|
|
new component_action('click',
|
|
|
|
'M.core_scroll_manager.save_scroll_action'),
|
2011-02-11 17:36:02 +00:00
|
|
|
array('title' => $strremove));
|
2008-11-20 06:59:11 +00:00
|
|
|
echo '</div>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-04 16:47:57 +00:00
|
|
|
if ($qnum != 0) {
|
2008-11-20 06:59:11 +00:00
|
|
|
$question = $questions[$qnum];
|
2010-10-18 15:28:59 +00:00
|
|
|
$questionparams = array(
|
|
|
|
'returnurl' => $returnurl,
|
|
|
|
'cmid' => $quiz->cmid,
|
|
|
|
'id' => $question->id);
|
|
|
|
$questionurl = new moodle_url('/question/question.php',
|
2008-11-20 06:59:11 +00:00
|
|
|
$questionparams);
|
|
|
|
$questioncount++;
|
|
|
|
//this is an actual question
|
2006-03-24 21:21:59 +00:00
|
|
|
|
2008-11-20 06:59:11 +00:00
|
|
|
/* Display question start */
|
2011-05-13 00:33:44 +01:00
|
|
|
?>
|
2008-11-20 06:59:11 +00:00
|
|
|
<div class="question">
|
2009-02-26 06:51:35 +00:00
|
|
|
<div class="questioncontainer <?php echo $question->qtype; ?>">
|
2008-11-20 06:59:11 +00:00
|
|
|
<div class="qnum">
|
2011-05-13 00:33:44 +01:00
|
|
|
<?php
|
|
|
|
$reordercheckbox = '';
|
|
|
|
$reordercheckboxlabel = '';
|
|
|
|
$reordercheckboxlabelclose = '';
|
|
|
|
if ($reordertool) {
|
|
|
|
$reordercheckbox = '<input type="checkbox" name="s' . $question->id .
|
|
|
|
'" id="s' . $question->id . '" />';
|
|
|
|
$reordercheckboxlabel = '<label for="s' . $question->id . '">';
|
|
|
|
$reordercheckboxlabelclose = '</label>';
|
|
|
|
}
|
2011-07-08 16:49:58 +01:00
|
|
|
if ($question->length == 0) {
|
|
|
|
$qnodisplay = get_string('infoshort', 'quiz');
|
|
|
|
} else if ($quiz->shufflequestions) {
|
|
|
|
$qnodisplay = '?';
|
|
|
|
} else {
|
|
|
|
if ($qno > 999 || ($reordertool && $qno > 99)) {
|
|
|
|
$qnodisplay = html_writer::tag('small', $qno);
|
2011-05-13 00:33:44 +01:00
|
|
|
} else {
|
2011-07-08 16:49:58 +01:00
|
|
|
$qnodisplay = $qno;
|
2011-05-13 00:33:44 +01:00
|
|
|
}
|
|
|
|
$qno += $question->length;
|
2008-11-20 06:59:11 +00:00
|
|
|
}
|
2011-07-08 16:49:58 +01:00
|
|
|
echo $reordercheckboxlabel . $qnodisplay . $reordercheckboxlabelclose .
|
|
|
|
$reordercheckbox;
|
2008-11-20 06:59:11 +00:00
|
|
|
|
2011-05-13 00:33:44 +01:00
|
|
|
?>
|
2008-11-20 06:59:11 +00:00
|
|
|
</div>
|
|
|
|
<div class="content">
|
|
|
|
<div class="questioncontrols">
|
|
|
|
<?php
|
2011-05-13 00:33:44 +01:00
|
|
|
if ($count != 0) {
|
|
|
|
if (!$hasattempts) {
|
|
|
|
$upbuttonclass = '';
|
|
|
|
if ($count >= $lastindex - 1) {
|
|
|
|
$upbuttonclass = 'upwithoutdown';
|
|
|
|
}
|
|
|
|
echo $OUTPUT->action_icon($pageurl->out(true,
|
|
|
|
array('up' => $question->id, 'sesskey'=>sesskey())),
|
|
|
|
new pix_icon('t/up', $strmoveup),
|
|
|
|
new component_action('click',
|
|
|
|
'M.core_scroll_manager.save_scroll_action'),
|
|
|
|
array('title' => $strmoveup));
|
2008-11-20 06:59:11 +00:00
|
|
|
}
|
2005-05-06 06:24:04 +00:00
|
|
|
|
|
|
|
}
|
2011-05-13 00:33:44 +01:00
|
|
|
if ($count < $lastindex - 1) {
|
|
|
|
if (!$hasattempts) {
|
|
|
|
echo $OUTPUT->action_icon($pageurl->out(true,
|
|
|
|
array('down' => $question->id, 'sesskey'=>sesskey())),
|
|
|
|
new pix_icon('t/down', $strmovedown),
|
|
|
|
new component_action('click',
|
|
|
|
'M.core_scroll_manager.save_scroll_action'),
|
|
|
|
array('title' => $strmovedown));
|
|
|
|
}
|
|
|
|
}
|
2012-01-09 16:33:53 +00:00
|
|
|
if ($allowdelete && ($question->qtype == 'missingtype' ||
|
2011-05-13 00:33:44 +01:00
|
|
|
question_has_capability_on($question, 'use', $question->category))) {
|
|
|
|
// remove from quiz, not question delete.
|
|
|
|
if (!$hasattempts) {
|
|
|
|
echo $OUTPUT->action_icon($pageurl->out(true,
|
|
|
|
array('remove' => $question->id, 'sesskey'=>sesskey())),
|
|
|
|
new pix_icon('t/delete', $strremove),
|
|
|
|
new component_action('click',
|
|
|
|
'M.core_scroll_manager.save_scroll_action'),
|
|
|
|
array('title' => $strremove));
|
|
|
|
}
|
2008-11-20 06:59:11 +00:00
|
|
|
}
|
|
|
|
?>
|
|
|
|
</div><?php
|
2012-01-09 16:33:53 +00:00
|
|
|
if (!in_array($question->qtype, array('description', 'missingtype')) && !$reordertool) {
|
2011-05-13 00:33:44 +01:00
|
|
|
?>
|
2008-11-20 06:59:11 +00:00
|
|
|
<div class="points">
|
2011-02-11 17:36:02 +00:00
|
|
|
<form method="post" action="edit.php" class="quizsavegradesform"><div>
|
2008-11-20 06:59:11 +00:00
|
|
|
<fieldset class="invisiblefieldset" style="display: block;">
|
2012-04-02 16:28:24 +01:00
|
|
|
<label for="<?php echo "inputq$question->id" ?>"><?php echo $strmaxmark; ?></label>:<br />
|
2009-01-02 10:51:26 +00:00
|
|
|
<input type="hidden" name="sesskey" value="<?php echo sesskey() ?>" />
|
2010-01-17 09:06:55 +00:00
|
|
|
<?php echo html_writer::input_hidden_params($pageurl); ?>
|
2008-11-20 06:59:11 +00:00
|
|
|
<input type="hidden" name="savechanges" value="save" />
|
2011-05-13 00:33:44 +01:00
|
|
|
<?php
|
|
|
|
echo '<input type="text" name="g' . $question->id .
|
|
|
|
'" id="inputq' . $question->id .
|
|
|
|
'" size="' . ($quiz->decimalpoints + 2) .
|
|
|
|
'" value="' . (0 + $quiz->grades[$qnum]) .
|
|
|
|
'" tabindex="' . ($lastindex + $qno) . '" />';
|
|
|
|
?>
|
2008-11-22 13:45:45 +00:00
|
|
|
<input type="submit" class="pointssubmitbutton" value="<?php echo $strsave; ?>" />
|
2008-11-20 06:59:11 +00:00
|
|
|
</fieldset>
|
2011-05-13 00:33:44 +01:00
|
|
|
<?php
|
|
|
|
if ($question->qtype == 'random') {
|
|
|
|
echo '<a href="' . $questionurl->out() .
|
|
|
|
'" class="configurerandomquestion">' .
|
|
|
|
get_string("configurerandomquestion", "quiz") . '</a>';
|
|
|
|
}
|
2009-01-19 05:30:01 +00:00
|
|
|
|
2011-05-13 00:33:44 +01:00
|
|
|
?>
|
2008-11-20 06:59:11 +00:00
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
|
|
|
|
</div>
|
2011-05-13 00:33:44 +01:00
|
|
|
<?php
|
|
|
|
} else if ($reordertool) {
|
|
|
|
if ($qnum) {
|
|
|
|
?>
|
2008-11-20 06:59:11 +00:00
|
|
|
<div class="qorder">
|
2011-05-13 00:33:44 +01:00
|
|
|
<?php
|
|
|
|
echo '<input type="text" name="o' . $question->id .
|
|
|
|
'" size="2" value="' . (10*$count + 10) .
|
|
|
|
'" tabindex="' . ($lastindex + $qno) . '" />';
|
|
|
|
?>
|
2008-11-20 06:59:11 +00:00
|
|
|
</div>
|
2011-05-13 00:33:44 +01:00
|
|
|
<?php
|
|
|
|
}
|
2008-11-20 06:59:11 +00:00
|
|
|
}
|
2011-05-13 00:33:44 +01:00
|
|
|
?>
|
2008-11-20 06:59:11 +00:00
|
|
|
<div class="questioncontentcontainer">
|
2011-05-13 00:33:44 +01:00
|
|
|
<?php
|
|
|
|
if ($question->qtype == 'random') { // it is a random question
|
|
|
|
if (!$reordertool) {
|
|
|
|
quiz_print_randomquestion($question, $pageurl, $quiz, $quiz_qbanktool);
|
|
|
|
} else {
|
|
|
|
quiz_print_randomquestion_reordertool($question, $pageurl, $quiz);
|
|
|
|
}
|
|
|
|
} else { // it is a single question
|
|
|
|
if (!$reordertool) {
|
|
|
|
quiz_print_singlequestion($question, $returnurl, $quiz);
|
|
|
|
} else {
|
|
|
|
quiz_print_singlequestion_reordertool($question, $returnurl, $quiz);
|
|
|
|
}
|
2008-11-20 06:59:11 +00:00
|
|
|
}
|
|
|
|
?>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2011-05-13 00:33:44 +01:00
|
|
|
<?php
|
2008-11-20 06:59:11 +00:00
|
|
|
}
|
2005-05-06 06:24:04 +00:00
|
|
|
}
|
2008-11-20 06:59:11 +00:00
|
|
|
//a page break: end the existing page.
|
2009-03-06 04:06:48 +00:00
|
|
|
if ($qnum == 0) {
|
|
|
|
if ($pageopen) {
|
2011-05-13 00:33:44 +01:00
|
|
|
if (!$reordertool && !($quiz->shufflequestions &&
|
|
|
|
$count < $questiontotalcount - 1)) {
|
2008-11-20 06:59:11 +00:00
|
|
|
quiz_print_pagecontrols($quiz, $pageurl, $pagecount,
|
2012-03-28 13:55:17 +01:00
|
|
|
$hasattempts, $defaultcategoryobj, $canaddquestion, $canaddrandom);
|
2011-02-10 20:44:47 +00:00
|
|
|
} else if ($count < $questiontotalcount - 1) {
|
2008-11-20 06:59:11 +00:00
|
|
|
//do not include the last page break for reordering
|
|
|
|
//to avoid creating a new extra page in the end
|
quiz editing: MDL-17454 first attemtp, and MDL-18554
This is a minimal fix for MDL-18554, I have just added a cancel button and made it work.
The more substantial part of this is MDL-17454, trying to make the quiz editing screen behave appropriately when shuffle questions is on. I am sure Olli will have opinions about this and want to change it further. Rought summary:
* When shufflequestions is off, never restrict manual paging, even if questionsperpage is set.
* When shuffle questions is on:
** Always display the quiz with the defined number of questions per page.
** Remove controls to add things except at the end of the quiz.
** Disable most of the order and paging tab, but still allow the question list to be reordered, in case that helps teachers track which questions they have added.
** Still allow questions to be reordered on the edit tab, but when moving the top question on a page up, reorder with the previous question, rather than moving to the previous page.
* Change the status bar, so that the yellow highlight is reserved for alert information. The more informative stuff is now plain, and moved to under the title. To my mind that associates it more closely with the quiz name. Also it moves Total of grades and Maximum grade closer together.
* JavaScript cleaned up. I learn more about YUI every day.
* Some PHP code clean ups that I forgot to commit separately before making substantive changes.
2009-03-17 09:51:34 +00:00
|
|
|
echo '<input type="hidden" name="opg' . $pagecount . '" size="2" value="' .
|
2009-03-06 04:06:48 +00:00
|
|
|
(10*$count + 10) . '" />';
|
2008-11-20 06:59:11 +00:00
|
|
|
}
|
|
|
|
echo "</div></div>";
|
|
|
|
|
quiz editing: MDL-17454 first attemtp, and MDL-18554
This is a minimal fix for MDL-18554, I have just added a cancel button and made it work.
The more substantial part of this is MDL-17454, trying to make the quiz editing screen behave appropriately when shuffle questions is on. I am sure Olli will have opinions about this and want to change it further. Rought summary:
* When shufflequestions is off, never restrict manual paging, even if questionsperpage is set.
* When shuffle questions is on:
** Always display the quiz with the defined number of questions per page.
** Remove controls to add things except at the end of the quiz.
** Disable most of the order and paging tab, but still allow the question list to be reordered, in case that helps teachers track which questions they have added.
** Still allow questions to be reordered on the edit tab, but when moving the top question on a page up, reorder with the previous question, rather than moving to the previous page.
* Change the status bar, so that the yellow highlight is reserved for alert information. The more informative stuff is now plain, and moved to under the title. To my mind that associates it more closely with the quiz name. Also it moves Total of grades and Maximum grade closer together.
* JavaScript cleaned up. I learn more about YUI every day.
* Some PHP code clean ups that I forgot to commit separately before making substantive changes.
2009-03-17 09:51:34 +00:00
|
|
|
if (!$reordertool && !$quiz->shufflequestions) {
|
2009-08-20 08:45:47 +00:00
|
|
|
echo $OUTPUT->container_start('addpage');
|
2011-05-13 00:33:44 +01:00
|
|
|
$url = new moodle_url($pageurl->out_omit_querystring(),
|
|
|
|
array('cmid' => $quiz->cmid, 'courseid' => $quiz->course,
|
|
|
|
'addpage' => $count, 'sesskey' => sesskey()));
|
2011-02-11 17:36:02 +00:00
|
|
|
echo $OUTPUT->single_button($url, get_string('addpagehere', 'quiz'), 'post',
|
|
|
|
array('disabled' => $hasattempts,
|
2011-05-13 00:33:44 +01:00
|
|
|
'actions' => array(new component_action('click',
|
|
|
|
'M.core_scroll_manager.save_scroll_action'))));
|
2009-08-20 08:45:47 +00:00
|
|
|
echo $OUTPUT->container_end();
|
2008-11-20 06:59:11 +00:00
|
|
|
}
|
2009-03-06 04:06:48 +00:00
|
|
|
$pageopen = false;
|
2008-11-20 06:59:11 +00:00
|
|
|
$count++;
|
|
|
|
}
|
2005-05-06 06:24:04 +00:00
|
|
|
}
|
|
|
|
|
2008-11-20 06:59:11 +00:00
|
|
|
}
|
2009-03-06 04:06:48 +00:00
|
|
|
if ($reordertool) {
|
2008-11-20 06:59:11 +00:00
|
|
|
echo $reordercontrolsbottom;
|
|
|
|
echo '</div></form>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Print all the controls for adding questions directly into the
|
|
|
|
* specific page in the edit tab of edit.php
|
|
|
|
*
|
2012-03-28 13:55:17 +01:00
|
|
|
* @param object $quiz This is not the standard quiz object used elsewhere but
|
|
|
|
* it contains the quiz layout in $quiz->questions and the grades in
|
|
|
|
* $quiz->grades
|
|
|
|
* @param moodle_url $pageurl The url of the current page with the parameters required
|
|
|
|
* for links returning to the current page, as a moodle_url object
|
|
|
|
* @param int $page the current page number.
|
|
|
|
* @param bool $hasattempts Indicates whether the quiz has attempts
|
|
|
|
* @param object $defaultcategoryobj
|
|
|
|
* @param bool $canaddquestion is the user able to add and use questions anywere?
|
|
|
|
* @param bool $canaddrandom is the user able to add random questions anywere?
|
2008-11-20 06:59:11 +00:00
|
|
|
*/
|
2012-03-28 13:55:17 +01:00
|
|
|
function quiz_print_pagecontrols($quiz, $pageurl, $page, $hasattempts,
|
|
|
|
$defaultcategoryobj, $canaddquestion, $canaddrandom) {
|
2009-08-18 05:16:08 +00:00
|
|
|
global $CFG, $OUTPUT;
|
quiz editing: MDL-17454 first attemtp, and MDL-18554
This is a minimal fix for MDL-18554, I have just added a cancel button and made it work.
The more substantial part of this is MDL-17454, trying to make the quiz editing screen behave appropriately when shuffle questions is on. I am sure Olli will have opinions about this and want to change it further. Rought summary:
* When shufflequestions is off, never restrict manual paging, even if questionsperpage is set.
* When shuffle questions is on:
** Always display the quiz with the defined number of questions per page.
** Remove controls to add things except at the end of the quiz.
** Disable most of the order and paging tab, but still allow the question list to be reordered, in case that helps teachers track which questions they have added.
** Still allow questions to be reordered on the edit tab, but when moving the top question on a page up, reorder with the previous question, rather than moving to the previous page.
* Change the status bar, so that the yellow highlight is reserved for alert information. The more informative stuff is now plain, and moved to under the title. To my mind that associates it more closely with the quiz name. Also it moves Total of grades and Maximum grade closer together.
* JavaScript cleaned up. I learn more about YUI every day.
* Some PHP code clean ups that I forgot to commit separately before making substantive changes.
2009-03-17 09:51:34 +00:00
|
|
|
static $randombuttoncount = 0;
|
|
|
|
$randombuttoncount++;
|
2008-11-20 06:59:11 +00:00
|
|
|
echo '<div class="pagecontrols">';
|
2009-02-25 07:14:03 +00:00
|
|
|
|
|
|
|
// Get the current context
|
2008-11-20 06:59:11 +00:00
|
|
|
$thiscontext = get_context_instance(CONTEXT_COURSE, $quiz->course);
|
|
|
|
$contexts = new question_edit_contexts($thiscontext);
|
2009-02-25 07:14:03 +00:00
|
|
|
|
|
|
|
// Get the default category.
|
2010-11-22 09:52:42 +00:00
|
|
|
list($defaultcategoryid) = explode(',', $pageurl->param('cat'));
|
2010-11-24 09:05:22 +00:00
|
|
|
if (empty($defaultcategoryid)) {
|
|
|
|
$defaultcategoryid = $defaultcategoryobj->id;
|
|
|
|
}
|
2009-02-25 07:14:03 +00:00
|
|
|
|
2012-03-28 13:55:17 +01:00
|
|
|
if ($canaddquestion) {
|
|
|
|
// Create the url the question page will return to
|
|
|
|
$returnurladdtoquiz = new moodle_url($pageurl, array('addonpage' => $page));
|
|
|
|
|
|
|
|
// Print a button linking to the choose question type page.
|
|
|
|
$returnurladdtoquiz = $returnurladdtoquiz->out_as_local_url(false);
|
|
|
|
$newquestionparams = array('returnurl' => $returnurladdtoquiz,
|
|
|
|
'cmid' => $quiz->cmid, 'appendqnumstring' => 'addquestion');
|
|
|
|
create_new_question_button($defaultcategoryid, $newquestionparams,
|
|
|
|
get_string('addaquestion', 'quiz'),
|
|
|
|
get_string('createquestionandadd', 'quiz'), $hasattempts);
|
|
|
|
}
|
2009-02-25 07:14:03 +00:00
|
|
|
|
2008-11-20 06:59:11 +00:00
|
|
|
if ($hasattempts) {
|
|
|
|
$disabled = 'disabled="disabled"';
|
|
|
|
} else {
|
|
|
|
$disabled = '';
|
|
|
|
}
|
2012-03-28 13:55:17 +01:00
|
|
|
if ($canaddrandom) {
|
2008-11-20 06:59:11 +00:00
|
|
|
?>
|
|
|
|
<div class="singlebutton">
|
2011-05-13 00:33:44 +01:00
|
|
|
<form class="randomquestionform" action="<?php echo $CFG->wwwroot;
|
|
|
|
?>/mod/quiz/addrandom.php" method="get">
|
2008-11-20 06:59:11 +00:00
|
|
|
<div>
|
2011-05-13 00:33:44 +01:00
|
|
|
<input type="hidden" class="addonpage_formelement" name="addonpage" value="<?php
|
|
|
|
echo $page; ?>" />
|
2008-11-20 06:59:11 +00:00
|
|
|
<input type="hidden" name="cmid" value="<?php echo $quiz->cmid; ?>" />
|
|
|
|
<input type="hidden" name="courseid" value="<?php echo $quiz->course; ?>" />
|
2011-05-13 00:33:44 +01:00
|
|
|
<input type="hidden" name="category" value="<?php
|
|
|
|
echo $pageurl->param('cat'); ?>" />
|
|
|
|
<input type="hidden" name="returnurl" value="<?php
|
|
|
|
echo s(str_replace($CFG->wwwroot, '', $pageurl->out(false))); ?>" />
|
|
|
|
<input type="submit" id="addrandomdialoglaunch_<?php
|
|
|
|
echo $randombuttoncount; ?>" value="<?php
|
|
|
|
echo get_string('addarandomquestion', 'quiz'); ?>" <?php
|
|
|
|
echo " $disabled"; ?> />
|
2008-11-20 06:59:11 +00:00
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
</div>
|
2012-03-28 13:55:17 +01:00
|
|
|
<?php echo $OUTPUT->help_icon('addarandomquestion', 'quiz');
|
|
|
|
}
|
2008-11-20 06:59:11 +00:00
|
|
|
echo "\n</div>";
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Print a given single question in quiz for the edit tab of edit.php.
|
|
|
|
* Meant to be used from quiz_print_question_list()
|
2009-03-06 04:06:48 +00:00
|
|
|
*
|
2008-11-22 15:28:46 +00:00
|
|
|
* @param object $question A question object from the database questions table
|
2009-02-11 10:08:07 +00:00
|
|
|
* @param object $returnurl The url to get back to this page, for example after editing.
|
2008-11-22 15:28:46 +00:00
|
|
|
* @param object $quiz The quiz in the context of which the question is being displayed
|
2008-11-20 06:59:11 +00:00
|
|
|
*/
|
2009-03-06 04:06:48 +00:00
|
|
|
function quiz_print_singlequestion($question, $returnurl, $quiz) {
|
2012-01-09 16:33:53 +00:00
|
|
|
echo '<div class="singlequestion ' . $question->qtype . '">';
|
2011-05-13 00:33:44 +01:00
|
|
|
echo quiz_question_edit_button($quiz->cmid, $question, $returnurl,
|
|
|
|
quiz_question_tostring($question) . ' ');
|
2009-02-11 10:08:07 +00:00
|
|
|
echo '<span class="questiontype">';
|
2011-11-08 15:12:58 +00:00
|
|
|
echo print_question_icon($question);
|
2011-02-10 20:44:47 +00:00
|
|
|
echo ' ' . question_bank::get_qtype_name($question->qtype) . '</span>';
|
2011-05-13 00:33:44 +01:00
|
|
|
echo '<span class="questionpreview">' .
|
|
|
|
quiz_question_preview_button($quiz, $question, true) . '</span>';
|
2009-02-11 10:08:07 +00:00
|
|
|
echo "</div>\n";
|
2008-11-20 06:59:11 +00:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Print a given random question in quiz for the edit tab of edit.php.
|
|
|
|
* Meant to be used from quiz_print_question_list()
|
2009-03-06 04:06:48 +00:00
|
|
|
*
|
2008-11-22 15:28:46 +00:00
|
|
|
* @param object $question A question object from the database questions table
|
|
|
|
* @param object $questionurl The url of the question editing page as a moodle_url object
|
|
|
|
* @param object $quiz The quiz in the context of which the question is being displayed
|
2011-02-23 16:25:25 +00:00
|
|
|
* @param bool $quiz_qbanktool Indicate to this function if the question bank window open
|
2008-11-20 06:59:11 +00:00
|
|
|
*/
|
2009-03-06 04:06:48 +00:00
|
|
|
function quiz_print_randomquestion(&$question, &$pageurl, &$quiz, $quiz_qbanktool) {
|
2011-02-10 20:44:47 +00:00
|
|
|
global $DB, $OUTPUT;
|
2008-11-20 06:59:11 +00:00
|
|
|
echo '<div class="quiz_randomquestion">';
|
|
|
|
|
2011-05-13 00:33:44 +01:00
|
|
|
if (!$category = $DB->get_record('question_categories',
|
|
|
|
array('id' => $question->category))) {
|
2009-08-18 05:16:08 +00:00
|
|
|
echo $OUTPUT->notification('Random question category not found!');
|
2008-11-20 06:59:11 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
echo '<div class="randomquestionfromcategory">';
|
2011-11-08 15:12:58 +00:00
|
|
|
echo print_question_icon($question);
|
2009-02-24 05:16:23 +00:00
|
|
|
print_random_option_icon($question);
|
2009-02-25 07:27:02 +00:00
|
|
|
echo ' ' . get_string('randomfromcategory', 'quiz') . '</div>';
|
2008-11-20 06:59:11 +00:00
|
|
|
|
2011-02-21 18:10:19 +00:00
|
|
|
$a = new stdClass();
|
2009-12-23 17:44:17 +00:00
|
|
|
$a->arrow = $OUTPUT->rarrow();
|
2009-02-11 10:08:07 +00:00
|
|
|
$strshowcategorycontents = get_string('showcategorycontents', 'quiz', $a);
|
2009-01-19 05:30:01 +00:00
|
|
|
|
2010-01-17 09:50:55 +00:00
|
|
|
$openqbankurl = $pageurl->out(true, array('qbanktool' => 1,
|
2009-02-11 10:08:07 +00:00
|
|
|
'cat' => $category->id . ',' . $category->contextid));
|
|
|
|
$linkcategorycontents = ' <a href="' . $openqbankurl . '">' . $strshowcategorycontents . '</a>';
|
2008-11-20 06:59:11 +00:00
|
|
|
|
2009-02-11 10:08:07 +00:00
|
|
|
echo '<div class="randomquestioncategory">';
|
2011-05-13 00:33:44 +01:00
|
|
|
echo '<a href="' . $openqbankurl . '" title="' . $strshowcategorycontents . '">' .
|
|
|
|
$category->name . '</a>';
|
|
|
|
echo '<span class="questionpreview">' .
|
|
|
|
quiz_question_preview_button($quiz, $question, true) . '</span>';
|
2009-02-11 10:08:07 +00:00
|
|
|
echo '</div>';
|
2008-11-20 06:59:11 +00:00
|
|
|
|
2011-02-11 17:36:02 +00:00
|
|
|
$questionids = question_bank::get_qtype('random')->get_available_questions_from_category(
|
2009-02-11 10:08:07 +00:00
|
|
|
$category->id, $question->questiontext == '1', '0');
|
|
|
|
$questioncount = count($questionids);
|
2008-11-20 06:59:11 +00:00
|
|
|
|
|
|
|
echo '<div class="randomquestionqlist">';
|
2009-02-11 10:08:07 +00:00
|
|
|
if ($questioncount == 0) {
|
|
|
|
// No questions in category, give an error plus instructions
|
2008-11-20 06:59:11 +00:00
|
|
|
echo '<span class="error">';
|
2009-02-11 10:08:07 +00:00
|
|
|
print_string('noquestionsnotinuse', 'quiz');
|
2008-11-28 14:07:06 +00:00
|
|
|
echo '</span>';
|
2008-11-20 06:59:11 +00:00
|
|
|
echo '<br />';
|
2008-11-28 14:07:06 +00:00
|
|
|
|
2009-02-11 10:08:07 +00:00
|
|
|
// Embed the link into the string with instructions
|
2011-02-21 18:10:19 +00:00
|
|
|
$a = new stdClass();
|
2008-11-28 14:07:06 +00:00
|
|
|
$a->catname = '<strong>' . $category->name . '</strong>';
|
2009-02-11 10:08:07 +00:00
|
|
|
$a->link = $linkcategorycontents;
|
2009-03-06 04:06:48 +00:00
|
|
|
echo get_string('addnewquestionsqbank', 'quiz', $a);
|
2005-08-31 16:32:49 +00:00
|
|
|
|
2009-02-11 10:08:07 +00:00
|
|
|
} else {
|
|
|
|
// Category has questions
|
2009-01-19 05:30:01 +00:00
|
|
|
|
2009-02-11 10:08:07 +00:00
|
|
|
// Get a sample from the database,
|
2011-02-11 17:36:02 +00:00
|
|
|
$questionidstoshow = array_slice($questionids, 0, NUM_QS_TO_SHOW_IN_RANDOM);
|
2009-02-11 10:08:07 +00:00
|
|
|
$questionstoshow = $DB->get_records_list('question', 'id', $questionidstoshow,
|
2011-05-12 00:30:25 +01:00
|
|
|
'', 'id, qtype, name, questiontext, questiontextformat');
|
2008-11-28 14:07:06 +00:00
|
|
|
|
2009-02-11 10:08:07 +00:00
|
|
|
// list them,
|
|
|
|
echo '<ul>';
|
|
|
|
foreach ($questionstoshow as $question) {
|
|
|
|
echo '<li>' . quiz_question_tostring($question, true) . '</li>';
|
|
|
|
}
|
2009-01-19 05:30:01 +00:00
|
|
|
|
2009-02-11 10:08:07 +00:00
|
|
|
// and then display the total number.
|
|
|
|
echo '<li class="totalquestionsinrandomqcategory">';
|
|
|
|
if ($questioncount > NUM_QS_TO_SHOW_IN_RANDOM) {
|
|
|
|
echo '... ';
|
|
|
|
}
|
|
|
|
print_string('totalquestionsinrandomqcategory', 'quiz', $questioncount);
|
|
|
|
echo ' ' . $linkcategorycontents;
|
|
|
|
echo '</li>';
|
|
|
|
echo '</ul>';
|
2005-05-06 06:24:04 +00:00
|
|
|
}
|
|
|
|
|
2009-02-11 10:08:07 +00:00
|
|
|
echo '</div>';
|
2008-11-20 06:59:11 +00:00
|
|
|
echo '<div class="randomquestioncategorycount">';
|
2009-02-11 10:08:07 +00:00
|
|
|
echo '</div>';
|
|
|
|
echo '</div>';
|
2008-11-20 06:59:11 +00:00
|
|
|
}
|
2005-05-06 06:24:04 +00:00
|
|
|
|
2008-11-20 06:59:11 +00:00
|
|
|
/**
|
|
|
|
* Print a given single question in quiz for the reordertool tab of edit.php.
|
|
|
|
* Meant to be used from quiz_print_question_list()
|
2009-03-06 04:06:48 +00:00
|
|
|
*
|
2008-11-22 15:28:46 +00:00
|
|
|
* @param object $question A question object from the database questions table
|
|
|
|
* @param object $questionurl The url of the question editing page as a moodle_url object
|
|
|
|
* @param object $quiz The quiz in the context of which the question is being displayed
|
2008-11-20 06:59:11 +00:00
|
|
|
*/
|
2009-03-06 04:06:48 +00:00
|
|
|
function quiz_print_singlequestion_reordertool($question, $returnurl, $quiz) {
|
2012-01-09 16:33:53 +00:00
|
|
|
echo '<div class="singlequestion ' . $question->qtype . '">';
|
2009-02-11 10:08:07 +00:00
|
|
|
echo '<label for="s' . $question->id . '">';
|
2011-11-08 15:12:58 +00:00
|
|
|
echo print_question_icon($question);
|
2009-02-11 10:08:07 +00:00
|
|
|
echo ' ' . quiz_question_tostring($question);
|
|
|
|
echo '</label>';
|
|
|
|
echo '<span class="questionpreview">' .
|
|
|
|
quiz_question_action_icons($quiz, $quiz->cmid, $question, $returnurl) . '</span>';
|
|
|
|
echo "</div>\n";
|
2008-11-20 06:59:11 +00:00
|
|
|
}
|
2009-02-24 05:16:23 +00:00
|
|
|
|
2008-11-20 06:59:11 +00:00
|
|
|
/**
|
|
|
|
* Print a given random question in quiz for the reordertool tab of edit.php.
|
|
|
|
* Meant to be used from quiz_print_question_list()
|
2009-03-06 04:06:48 +00:00
|
|
|
*
|
2008-11-22 15:28:46 +00:00
|
|
|
* @param object $question A question object from the database questions table
|
|
|
|
* @param object $questionurl The url of the question editing page as a moodle_url object
|
|
|
|
* @param object $quiz The quiz in the context of which the question is being displayed
|
2008-11-20 06:59:11 +00:00
|
|
|
*/
|
2009-03-06 04:06:48 +00:00
|
|
|
function quiz_print_randomquestion_reordertool(&$question, &$pageurl, &$quiz) {
|
2011-02-10 20:44:47 +00:00
|
|
|
global $DB, $OUTPUT;
|
2008-11-20 06:59:11 +00:00
|
|
|
|
2009-02-11 10:08:07 +00:00
|
|
|
// Load the category, and the number of available questions in it.
|
2008-11-20 06:59:11 +00:00
|
|
|
if (!$category = $DB->get_record('question_categories', array('id' => $question->category))) {
|
2009-08-18 05:16:08 +00:00
|
|
|
echo $OUTPUT->notification('Random question category not found!');
|
2008-11-20 06:59:11 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-05-13 00:33:44 +01:00
|
|
|
$questioncount = count(question_bank::get_qtype(
|
|
|
|
'random')->get_available_questions_from_category(
|
2009-02-11 10:08:07 +00:00
|
|
|
$category->id, $question->questiontext == '1', '0'));
|
2008-11-20 06:59:11 +00:00
|
|
|
|
2009-03-06 04:06:48 +00:00
|
|
|
$reordercheckboxlabel = '<label for="s' . $question->id . '">';
|
2009-02-11 10:08:07 +00:00
|
|
|
$reordercheckboxlabelclose = '</label>';
|
|
|
|
|
|
|
|
echo '<div class="quiz_randomquestion">';
|
|
|
|
echo '<div class="randomquestionfromcategory">';
|
2008-11-20 06:59:11 +00:00
|
|
|
echo $reordercheckboxlabel;
|
2011-11-08 15:12:58 +00:00
|
|
|
echo print_question_icon($question);
|
2009-02-24 05:16:23 +00:00
|
|
|
print_random_option_icon($question);
|
2008-11-20 06:59:11 +00:00
|
|
|
|
2009-02-11 10:08:07 +00:00
|
|
|
if ($questioncount == 0) {
|
2008-11-20 06:59:11 +00:00
|
|
|
echo '<span class="error">';
|
2009-02-11 10:08:07 +00:00
|
|
|
print_string('empty', 'quiz');
|
2008-11-20 06:59:11 +00:00
|
|
|
echo '</span> ';
|
|
|
|
}
|
|
|
|
|
2009-02-11 10:08:07 +00:00
|
|
|
print_string('random', 'quiz');
|
2008-11-20 06:59:11 +00:00
|
|
|
echo ": $reordercheckboxlabelclose</div>";
|
|
|
|
|
|
|
|
echo '<div class="randomquestioncategory">';
|
2009-02-11 10:08:07 +00:00
|
|
|
echo $reordercheckboxlabel . $category->name . $reordercheckboxlabelclose;
|
2008-11-28 15:43:10 +00:00
|
|
|
echo '<span class="questionpreview">';
|
2009-02-11 10:08:07 +00:00
|
|
|
echo quiz_question_preview_button($quiz, $question, false);
|
2008-11-20 06:59:11 +00:00
|
|
|
echo '</span>';
|
|
|
|
echo "</div>";
|
|
|
|
|
|
|
|
echo '<div class="randomquestioncategorycount">';
|
2009-02-11 10:08:07 +00:00
|
|
|
echo '</div>';
|
|
|
|
echo '</div>';
|
2008-11-20 06:59:11 +00:00
|
|
|
}
|
2009-02-24 05:16:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Print an icon to indicate the 'include subcategories' state of a random question.
|
|
|
|
* @param $question the random question.
|
|
|
|
*/
|
|
|
|
function print_random_option_icon($question) {
|
2009-07-02 10:26:02 +00:00
|
|
|
global $OUTPUT;
|
2009-02-24 05:16:23 +00:00
|
|
|
if (!empty($question->questiontext)) {
|
|
|
|
$icon = 'withsubcat';
|
|
|
|
$tooltip = get_string('randomwithsubcat', 'quiz');
|
|
|
|
} else {
|
|
|
|
$icon = 'nosubcat';
|
|
|
|
$tooltip = get_string('randomnosubcat', 'quiz');
|
|
|
|
}
|
2009-12-16 21:50:45 +00:00
|
|
|
echo '<img src="' . $OUTPUT->pix_url('i/' . $icon) . '" alt="' .
|
2009-02-25 07:27:02 +00:00
|
|
|
$tooltip . '" title="' . $tooltip . '" class="uihint" />';
|
2009-02-24 05:16:23 +00:00
|
|
|
}
|
|
|
|
|
2008-11-20 06:59:11 +00:00
|
|
|
/**
|
|
|
|
* Creates a textual representation of a question for display.
|
2009-03-06 04:06:48 +00:00
|
|
|
*
|
2008-11-22 15:28:46 +00:00
|
|
|
* @param object $question A question object from the database questions table
|
2011-02-23 16:25:25 +00:00
|
|
|
* @param bool $showicon If true, show the question's icon with the question. False by default.
|
|
|
|
* @param bool $showquestiontext If true (default), show question text after question name.
|
2008-11-22 15:28:46 +00:00
|
|
|
* If false, show only question name.
|
2011-02-23 16:25:25 +00:00
|
|
|
* @param bool $return If true (default), return the output. If false, print it.
|
2008-11-20 06:59:11 +00:00
|
|
|
*/
|
2011-05-13 00:33:44 +01:00
|
|
|
function quiz_question_tostring($question, $showicon = false,
|
|
|
|
$showquestiontext = true, $return = true) {
|
2011-02-10 20:44:47 +00:00
|
|
|
global $COURSE;
|
|
|
|
$result = '';
|
|
|
|
$result .= '<span class="questionname">';
|
|
|
|
if ($showicon) {
|
|
|
|
$result .= print_question_icon($question, true);
|
|
|
|
echo ' ';
|
|
|
|
}
|
|
|
|
$result .= shorten_text(format_string($question->name), 200) . '</span>';
|
|
|
|
if ($showquestiontext) {
|
2011-02-21 18:10:19 +00:00
|
|
|
$formatoptions = new stdClass();
|
2011-02-10 20:44:47 +00:00
|
|
|
$formatoptions->noclean = true;
|
|
|
|
$formatoptions->para = false;
|
|
|
|
$questiontext = strip_tags(format_text($question->questiontext,
|
|
|
|
$question->questiontextformat,
|
|
|
|
$formatoptions, $COURSE->id));
|
|
|
|
$questiontext = shorten_text($questiontext, 200);
|
|
|
|
$result .= '<span class="questiontext">';
|
|
|
|
if (!empty($questiontext)) {
|
|
|
|
$result .= $questiontext;
|
2009-03-06 04:06:48 +00:00
|
|
|
} else {
|
2011-02-10 20:44:47 +00:00
|
|
|
$result .= '<span class="error">';
|
|
|
|
$result .= get_string('questiontextisempty', 'quiz');
|
|
|
|
$result .= '</span>';
|
2008-11-20 06:59:11 +00:00
|
|
|
}
|
2011-02-10 20:44:47 +00:00
|
|
|
$result .= '</span>';
|
|
|
|
}
|
|
|
|
if ($return) {
|
|
|
|
return $result;
|
|
|
|
} else {
|
|
|
|
echo $result;
|
|
|
|
}
|
2008-11-20 06:59:11 +00:00
|
|
|
}
|
2008-08-22 02:46:54 +00:00
|
|
|
|
2009-01-22 05:38:18 +00:00
|
|
|
/**
|
|
|
|
* A column type for the add this question to the quiz.
|
2011-02-23 16:25:25 +00:00
|
|
|
*
|
|
|
|
* @copyright 2009 Tim Hunt
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
2009-01-22 05:38:18 +00:00
|
|
|
*/
|
|
|
|
class question_bank_add_to_quiz_action_column extends question_bank_action_column_base {
|
|
|
|
protected $stradd;
|
|
|
|
|
|
|
|
public function init() {
|
|
|
|
parent::init();
|
|
|
|
$this->stradd = get_string('addtoquiz', 'quiz');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function get_name() {
|
|
|
|
return 'addtoquizaction';
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function display_content($question, $rowclasses) {
|
2012-03-28 13:55:17 +01:00
|
|
|
if (!question_has_capability_on($question, 'use')) {
|
|
|
|
return;
|
|
|
|
}
|
2009-01-22 05:38:18 +00:00
|
|
|
// for RTL languages: switch right and left arrows
|
|
|
|
if (right_to_left()) {
|
2010-04-12 13:31:42 +00:00
|
|
|
$movearrow = 't/removeright';
|
2009-01-22 05:38:18 +00:00
|
|
|
} else {
|
2010-04-12 13:31:42 +00:00
|
|
|
$movearrow = 't/moveleft';
|
2009-01-22 05:38:18 +00:00
|
|
|
}
|
|
|
|
$this->print_icon($movearrow, $this->stradd, $this->qbank->add_to_quiz_url($question->id));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function get_required_fields() {
|
|
|
|
return array('q.id');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A column type for the name followed by the start of the question text.
|
2011-02-23 16:25:25 +00:00
|
|
|
*
|
|
|
|
* @copyright 2009 Tim Hunt
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
2009-01-22 05:38:18 +00:00
|
|
|
*/
|
|
|
|
class question_bank_question_name_text_column extends question_bank_question_name_column {
|
|
|
|
public function get_name() {
|
|
|
|
return 'questionnametext';
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function display_content($question, $rowclasses) {
|
|
|
|
echo '<div>';
|
|
|
|
$labelfor = $this->label_for($question);
|
|
|
|
if ($labelfor) {
|
|
|
|
echo '<label for="' . $labelfor . '">';
|
|
|
|
}
|
|
|
|
echo quiz_question_tostring($question, false, true, true);
|
|
|
|
if ($labelfor) {
|
|
|
|
echo '</label>';
|
|
|
|
}
|
|
|
|
echo '</div>';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function get_required_fields() {
|
|
|
|
$fields = parent::get_required_fields();
|
|
|
|
$fields[] = 'q.questiontext';
|
2009-01-22 09:19:37 +00:00
|
|
|
$fields[] = 'q.questiontextformat';
|
2009-01-22 05:38:18 +00:00
|
|
|
return $fields;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-19 05:30:01 +00:00
|
|
|
/**
|
|
|
|
* Subclass to customise the view of the question bank for the quiz editing screen.
|
2011-02-23 16:25:25 +00:00
|
|
|
*
|
|
|
|
* @copyright 2009 Tim Hunt
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
2009-01-19 05:30:01 +00:00
|
|
|
*/
|
|
|
|
class quiz_question_bank_view extends question_bank_view {
|
|
|
|
protected $quizhasattempts = false;
|
2011-05-27 11:49:23 +01:00
|
|
|
/** @var object the quiz settings. */
|
|
|
|
protected $quiz = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
* @param question_edit_contexts $contexts
|
|
|
|
* @param moodle_url $pageurl
|
|
|
|
* @param object $course course settings
|
|
|
|
* @param object $cm activity settings.
|
|
|
|
* @param object $quiz quiz settings.
|
|
|
|
*/
|
|
|
|
public function __construct($contexts, $pageurl, $course, $cm, $quiz) {
|
|
|
|
parent::__construct($contexts, $pageurl, $course, $cm);
|
|
|
|
$this->quiz = $quiz;
|
|
|
|
}
|
2008-08-22 02:46:54 +00:00
|
|
|
|
2009-02-25 07:14:03 +00:00
|
|
|
protected function known_field_types() {
|
|
|
|
$types = parent::known_field_types();
|
2009-01-22 05:38:18 +00:00
|
|
|
$types[] = new question_bank_add_to_quiz_action_column($this);
|
|
|
|
$types[] = new question_bank_question_name_text_column($this);
|
|
|
|
return $types;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function wanted_columns() {
|
2011-05-13 00:33:44 +01:00
|
|
|
return array('addtoquizaction', 'checkbox', 'qtype', 'questionnametext',
|
|
|
|
'editaction', 'previewaction');
|
2009-01-19 05:30:01 +00:00
|
|
|
}
|
2008-11-20 06:59:11 +00:00
|
|
|
|
2011-12-15 18:39:21 +00:00
|
|
|
protected function default_sort() {
|
|
|
|
return array('qtype' => 1, 'questionnametext' => 1);
|
|
|
|
}
|
|
|
|
|
2009-01-19 05:30:01 +00:00
|
|
|
/**
|
|
|
|
* Let the question bank display know whether the quiz has been attempted,
|
|
|
|
* hence whether some bits of UI, like the add this question to the quiz icon,
|
|
|
|
* should be displayed.
|
2011-02-23 16:25:25 +00:00
|
|
|
* @param bool $quizhasattempts whether the quiz has attempts.
|
2009-01-19 05:30:01 +00:00
|
|
|
*/
|
|
|
|
public function set_quiz_has_attempts($quizhasattempts) {
|
|
|
|
$this->quizhasattempts = $quizhasattempts;
|
2009-01-22 05:38:18 +00:00
|
|
|
if ($quizhasattempts && isset($this->visiblecolumns['addtoquizaction'])) {
|
|
|
|
unset($this->visiblecolumns['addtoquizaction']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-27 11:49:23 +01:00
|
|
|
public function preview_question_url($question) {
|
|
|
|
return quiz_question_preview_url($this->quiz, $question);
|
2009-01-22 09:19:37 +00:00
|
|
|
}
|
|
|
|
|
2009-01-22 05:38:18 +00:00
|
|
|
public function add_to_quiz_url($questionid) {
|
|
|
|
global $CFG;
|
2010-01-17 10:54:13 +00:00
|
|
|
$params = $this->baseurl->params();
|
|
|
|
$params['addquestion'] = $questionid;
|
|
|
|
$params['sesskey'] = sesskey();
|
|
|
|
return new moodle_url('/mod/quiz/edit.php', $params);
|
2009-01-19 05:30:01 +00:00
|
|
|
}
|
2008-11-20 06:59:11 +00:00
|
|
|
|
2011-08-04 13:53:02 +01:00
|
|
|
public function display($tabname, $page, $perpage, $cat,
|
|
|
|
$recurse, $showhidden, $showquestiontext) {
|
2009-08-10 05:00:41 +00:00
|
|
|
global $OUTPUT;
|
2009-01-21 07:21:43 +00:00
|
|
|
if ($this->process_actions_needing_ui()) {
|
2009-01-19 08:50:48 +00:00
|
|
|
return;
|
|
|
|
}
|
2009-01-19 05:30:01 +00:00
|
|
|
|
2009-01-22 05:38:18 +00:00
|
|
|
// Display the current category.
|
|
|
|
if (!$category = $this->get_current_category($cat)) {
|
2009-01-19 08:50:48 +00:00
|
|
|
return;
|
2008-11-20 06:59:11 +00:00
|
|
|
}
|
2009-01-22 05:38:18 +00:00
|
|
|
$this->print_category_info($category);
|
2009-01-19 08:50:48 +00:00
|
|
|
|
2009-08-10 05:00:41 +00:00
|
|
|
echo $OUTPUT->box_start('generalbox questionbank');
|
2009-01-19 08:50:48 +00:00
|
|
|
|
2009-01-21 07:21:43 +00:00
|
|
|
$this->display_category_form($this->contexts->having_one_edit_tab_cap($tabname),
|
2009-01-22 05:38:18 +00:00
|
|
|
$this->baseurl, $cat);
|
2009-01-19 08:50:48 +00:00
|
|
|
|
|
|
|
// continues with list of questions
|
2011-05-13 00:33:44 +01:00
|
|
|
$this->display_question_list($this->contexts->having_one_edit_tab_cap($tabname),
|
|
|
|
$this->baseurl, $cat, $this->cm, $recurse, $page,
|
2011-08-04 13:53:02 +01:00
|
|
|
$perpage, $showhidden, $showquestiontext,
|
2009-01-21 07:21:43 +00:00
|
|
|
$this->contexts->having_cap('moodle/question:add'));
|
2009-01-19 08:50:48 +00:00
|
|
|
|
2009-01-22 05:38:18 +00:00
|
|
|
$this->display_options($recurse, $showhidden, $showquestiontext);
|
2009-08-10 05:00:41 +00:00
|
|
|
echo $OUTPUT->box_end();
|
2009-01-19 05:30:01 +00:00
|
|
|
}
|
2009-01-19 08:50:48 +00:00
|
|
|
|
2009-01-22 05:38:18 +00:00
|
|
|
protected function print_choose_category_message($categoryandcontext) {
|
2009-08-10 05:00:41 +00:00
|
|
|
global $OUTPUT;
|
|
|
|
echo $OUTPUT->box_start('generalbox questionbank');
|
2011-05-13 00:33:44 +01:00
|
|
|
$this->display_category_form($this->contexts->having_one_edit_tab_cap('edit'),
|
|
|
|
$this->baseurl, $categoryandcontext);
|
2009-01-22 05:38:18 +00:00
|
|
|
echo "<p style=\"text-align:center;\"><b>";
|
2011-12-02 14:49:39 +00:00
|
|
|
print_string('selectcategoryabove', 'question');
|
2009-01-22 05:38:18 +00:00
|
|
|
echo "</b></p>";
|
2009-08-10 05:00:41 +00:00
|
|
|
echo $OUTPUT->box_end();
|
2009-01-21 07:21:43 +00:00
|
|
|
}
|
|
|
|
|
2009-01-22 05:38:18 +00:00
|
|
|
protected function print_category_info($category) {
|
2011-02-21 18:10:19 +00:00
|
|
|
$formatoptions = new stdClass();
|
2009-01-22 05:38:18 +00:00
|
|
|
$formatoptions->noclean = true;
|
|
|
|
$strcategory = get_string('category', 'quiz');
|
2009-03-06 04:06:48 +00:00
|
|
|
echo '<div class="categoryinfo"><div class="categorynamefieldcontainer">' .
|
2009-01-22 05:38:18 +00:00
|
|
|
$strcategory;
|
|
|
|
echo ': <span class="categorynamefield">';
|
2011-02-24 20:18:16 +00:00
|
|
|
echo shorten_text(strip_tags(format_string($category->name)), 60);
|
2011-05-13 00:33:44 +01:00
|
|
|
echo '</span></div><div class="categoryinfofieldcontainer">' .
|
|
|
|
'<span class="categoryinfofield">';
|
2011-02-24 20:18:16 +00:00
|
|
|
echo shorten_text(strip_tags(format_text($category->info, $category->infoformat,
|
2009-03-06 04:06:48 +00:00
|
|
|
$formatoptions, $this->course->id)), 200);
|
2009-01-22 05:38:18 +00:00
|
|
|
echo '</span></div></div>';
|
2009-01-21 07:21:43 +00:00
|
|
|
}
|
|
|
|
|
2011-08-05 09:04:48 +01:00
|
|
|
protected function display_options($recurse, $showhidden, $showquestiontext) {
|
2009-01-22 05:38:18 +00:00
|
|
|
echo '<form method="get" action="edit.php" id="displayoptions">';
|
|
|
|
echo "<fieldset class='invisiblefieldset'>";
|
2011-05-13 00:33:44 +01:00
|
|
|
echo html_writer::input_hidden_params($this->baseurl,
|
2011-08-26 17:01:06 +01:00
|
|
|
array('recurse', 'showhidden', 'qbshowtext'));
|
2011-08-05 09:04:48 +01:00
|
|
|
$this->display_category_form_checkbox('recurse', $recurse,
|
2011-05-13 00:33:44 +01:00
|
|
|
get_string('includesubcategories', 'question'));
|
2011-08-05 09:04:48 +01:00
|
|
|
$this->display_category_form_checkbox('showhidden', $showhidden,
|
2011-05-13 00:33:44 +01:00
|
|
|
get_string('showhidden', 'question'));
|
|
|
|
echo '<noscript><div class="centerpara"><input type="submit" value="' .
|
|
|
|
get_string('go') . '" />';
|
2009-01-22 05:38:18 +00:00
|
|
|
echo '</div></noscript></fieldset></form>';
|
2009-01-21 07:21:43 +00:00
|
|
|
}
|
2008-11-22 12:36:14 +00:00
|
|
|
}
|
2009-01-19 05:30:01 +00:00
|
|
|
|
2008-11-22 12:36:14 +00:00
|
|
|
/**
|
|
|
|
* Prints the form for setting a quiz' overall grade
|
2009-03-06 04:06:48 +00:00
|
|
|
*
|
2008-11-22 15:28:46 +00:00
|
|
|
* @param object $quiz The quiz object of the quiz in question
|
2009-03-06 04:06:48 +00:00
|
|
|
* @param object $pageurl The url of the current page with the parameters required
|
2008-11-22 15:28:46 +00:00
|
|
|
* for links returning to the current page, as a moodle_url object
|
2011-02-23 16:25:25 +00:00
|
|
|
* @param int $tabindex The tabindex to start from for the form elements created
|
|
|
|
* @return int The tabindex from which the calling page can continue, that is,
|
2008-11-22 15:28:46 +00:00
|
|
|
* the last value used +1.
|
2008-11-22 12:36:14 +00:00
|
|
|
*/
|
2009-03-06 04:06:48 +00:00
|
|
|
function quiz_print_grading_form($quiz, $pageurl, $tabindex) {
|
2012-01-30 17:47:11 +00:00
|
|
|
global $OUTPUT;
|
2009-03-06 04:06:48 +00:00
|
|
|
$strsave = get_string('save', 'quiz');
|
2011-02-11 17:36:02 +00:00
|
|
|
echo '<form method="post" action="edit.php" class="quizsavegradesform"><div>';
|
2008-11-22 12:36:14 +00:00
|
|
|
echo '<fieldset class="invisiblefieldset" style="display: block;">';
|
2009-03-06 04:06:48 +00:00
|
|
|
echo "<input type=\"hidden\" name=\"sesskey\" value=\"" . sesskey() . "\" />";
|
2010-01-17 09:06:55 +00:00
|
|
|
echo html_writer::input_hidden_params($pageurl);
|
2011-05-13 00:33:44 +01:00
|
|
|
$a = '<input type="text" id="inputmaxgrade" name="maxgrade" size="' .
|
|
|
|
($quiz->decimalpoints + 2) . '" tabindex="' . $tabindex
|
2009-03-06 04:06:48 +00:00
|
|
|
. '" value="' . quiz_format_grade($quiz, $quiz->grade) . '" />';
|
|
|
|
echo '<label for="inputmaxgrade">' . get_string('maximumgradex', '', $a) . "</label>";
|
|
|
|
echo '<input type="hidden" name="savechanges" value="save" />';
|
|
|
|
echo '<input type="submit" value="' . $strsave . '" />';
|
2008-11-22 12:36:14 +00:00
|
|
|
echo '</fieldset>';
|
|
|
|
echo "</div></form>\n";
|
2009-03-06 04:06:48 +00:00
|
|
|
return $tabindex + 1;
|
2008-11-22 12:36:14 +00:00
|
|
|
}
|
2009-01-19 05:30:01 +00:00
|
|
|
|
2008-11-22 12:36:14 +00:00
|
|
|
/**
|
|
|
|
* Print the status bar
|
|
|
|
*
|
2008-11-22 15:28:46 +00:00
|
|
|
* @param object $quiz The quiz object of the quiz in question
|
2008-11-22 12:36:14 +00:00
|
|
|
*/
|
2009-03-06 04:06:48 +00:00
|
|
|
function quiz_print_status_bar($quiz) {
|
2008-11-22 12:36:14 +00:00
|
|
|
global $CFG;
|
2011-06-23 18:53:07 +01:00
|
|
|
|
|
|
|
$bits = array();
|
|
|
|
|
|
|
|
$bits[] = html_writer::tag('span',
|
2012-04-02 16:28:24 +01:00
|
|
|
get_string('totalmarksx', 'quiz', quiz_format_grade($quiz, $quiz->sumgrades)),
|
2011-06-23 18:53:07 +01:00
|
|
|
array('class' => 'totalpoints'));
|
|
|
|
|
|
|
|
$bits[] = html_writer::tag('span',
|
|
|
|
get_string('numquestionsx', 'quiz', quiz_number_of_questions_in_quiz($quiz->questions)),
|
|
|
|
array('class' => 'numberofquestions'));
|
|
|
|
|
2009-01-09 03:17:18 +00:00
|
|
|
$timenow = time();
|
2011-06-23 18:53:07 +01:00
|
|
|
|
|
|
|
// Exact open and close dates for the tool-tip.
|
|
|
|
$dates = array();
|
2009-01-09 03:17:18 +00:00
|
|
|
if ($quiz->timeopen > 0) {
|
|
|
|
if ($timenow > $quiz->timeopen) {
|
2009-01-12 07:24:03 +00:00
|
|
|
$dates[] = get_string('quizopenedon', 'quiz', userdate($quiz->timeopen));
|
2009-01-09 03:17:18 +00:00
|
|
|
} else {
|
2009-01-12 07:24:03 +00:00
|
|
|
$dates[] = get_string('quizwillopen', 'quiz', userdate($quiz->timeopen));
|
2009-01-09 03:17:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($quiz->timeclose > 0) {
|
|
|
|
if ($timenow > $quiz->timeclose) {
|
2009-01-12 07:24:03 +00:00
|
|
|
$dates[] = get_string('quizclosed', 'quiz', userdate($quiz->timeclose));
|
2009-01-09 03:17:18 +00:00
|
|
|
} else {
|
2009-01-12 07:24:03 +00:00
|
|
|
$dates[] = get_string('quizcloseson', 'quiz', userdate($quiz->timeclose));
|
2009-01-09 03:17:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (empty($dates)) {
|
|
|
|
$dates[] = get_string('alwaysavailable', 'quiz');
|
|
|
|
}
|
2011-06-23 18:53:07 +01:00
|
|
|
$tooltip = implode(', ', $dates);;
|
|
|
|
|
|
|
|
// Brief summary on the page.
|
|
|
|
if ($timenow < $quiz->timeopen) {
|
|
|
|
$currentstatus = get_string('quizisclosedwillopen', 'quiz',
|
2011-09-29 09:06:11 +01:00
|
|
|
userdate($quiz->timeopen, get_string('strftimedatetimeshort', 'langconfig')));
|
2011-06-23 18:53:07 +01:00
|
|
|
} else if ($quiz->timeclose && $timenow <= $quiz->timeclose) {
|
|
|
|
$currentstatus = get_string('quizisopenwillclose', 'quiz',
|
|
|
|
userdate($quiz->timeclose, get_string('strftimedatetimeshort', 'langconfig')));
|
|
|
|
} else if ($quiz->timeclose && $timenow > $quiz->timeclose) {
|
|
|
|
$currentstatus = get_string('quizisclosed', 'quiz');
|
|
|
|
} else {
|
|
|
|
$currentstatus = get_string('quizisopen', 'quiz');
|
|
|
|
}
|
2009-01-12 07:24:03 +00:00
|
|
|
|
2011-06-23 18:53:07 +01:00
|
|
|
$bits[] = html_writer::tag('span', $currentstatus,
|
|
|
|
array('class' => 'quizopeningstatus', 'title' => implode(', ', $dates)));
|
|
|
|
|
|
|
|
echo html_writer::tag('div', implode(' | ', $bits), array('class' => 'statusbar'));
|
2008-11-22 12:36:14 +00:00
|
|
|
}
|