MDL-32788 quiz: clean up codechecker issues before the 2.3 release.

This commit is contained in:
Tim Hunt
2012-05-04 15:12:23 +01:00
parent e16e2300c5
commit 9e83f3d11d
36 changed files with 425 additions and 424 deletions
+1 -1
View File
@@ -101,7 +101,7 @@ class quizaccess_openclosedate extends quiz_access_rule_base {
}
// Otherwise, return to the time left until the close date, providing
// that is less than QUIZ_SHOW_TIME_BEFORE_DEADLINE
// that is less than QUIZ_SHOW_TIME_BEFORE_DEADLINE.
if ($this->quiz->timeclose) {
$timeleft = $this->quiz->timeclose - $timenow;
if ($timeleft < QUIZ_SHOW_TIME_BEFORE_DEADLINE) {
+2 -2
View File
@@ -61,7 +61,7 @@ class quizaccess_password extends quiz_access_rule_base {
$mform->addElement('static', 'passwordmessage', '',
get_string('requirepasswordmessage', 'quizaccess_password'));
// don't use the 'proper' field name of 'password' since that get's
// Don't use the 'proper' field name of 'password' since that get's
// Firefox's password auto-complete over-excited.
$mform->addElement('password', 'quizpassword',
get_string('quizpassword', 'quizaccess_password'));
@@ -74,7 +74,7 @@ class quizaccess_password extends quiz_access_rule_base {
return $errors; // Password is OK.
} else if (isset($this->quiz->extrapasswords)) {
// Group overrides may have additional passwords
// Group overrides may have additional passwords.
foreach ($this->quiz->extrapasswords as $password) {
if (strcmp($password, $enteredpassword) === 0) {
return $errors; // Password is OK.
+1 -1
View File
@@ -70,7 +70,7 @@ class quizaccess_securewindow extends quiz_access_rule_base {
}
public function setup_attempt_page($page) {
$page->set_popup_notification_allowed(false); // Prevent message notifications
$page->set_popup_notification_allowed(false); // Prevent message notifications.
$page->set_title($this->quizobj->get_course()->shortname . ': ' . $page->title);
$page->set_cacheable(false);
$page->set_pagelayout('popup');
+1 -1
View File
@@ -34,7 +34,7 @@ list($thispageurl, $contexts, $cmid, $cm, $quiz, $pagevars) =
question_edit_setup('editq', '/mod/quiz/addrandom.php', true);
// These params are only passed from page request to request while we stay on
// this page otherwise they would go in question_edit_setup
// this page otherwise they would go in question_edit_setup.
$returnurl = optional_param('returnurl', '', PARAM_LOCALURL);
$addonpage = optional_param('addonpage', 0, PARAM_INT);
$category = optional_param('category', 0, PARAM_INT);
+3 -3
View File
@@ -44,7 +44,7 @@ class quiz_add_random_form extends moodleform {
$contexts = $this->_customdata;
$usablecontexts = $contexts->having_cap('moodle/question:useall');
//--------------------------------------------------------------------------------
// Random from existing category section.
$mform->addElement('header', 'categoryheader',
get_string('randomfromexistingcategory', 'quiz'));
@@ -55,7 +55,7 @@ class quiz_add_random_form extends moodleform {
$mform->addElement('submit', 'existingcategory', get_string('addrandomquestion', 'quiz'));
//--------------------------------------------------------------------------------
// Random from a new category section.
$mform->addElement('header', 'categoryheader',
get_string('randomquestionusinganewcategory', 'quiz'));
@@ -69,7 +69,7 @@ class quiz_add_random_form extends moodleform {
$mform->addElement('submit', 'newcategory',
get_string('createcategoryandaddrandomquestion', 'quiz'));
//--------------------------------------------------------------------------------
// Submit buttons.
$mform->addElement('cancel');
$mform->closeHeaderBefore('cancel');
+4 -4
View File
@@ -25,7 +25,7 @@
require_once(dirname(__FILE__) . '/../../config.php');
require_once($CFG->dirroot . '/mod/quiz/locallib.php');
// Look for old-style URLs, such as may be in the logs, and redirect them to startattemtp.php
// Look for old-style URLs, such as may be in the logs, and redirect them to startattemtp.php.
if ($id = optional_param('id', 0, PARAM_INTEGER)) {
redirect($CFG->wwwroot . '/mod/quiz/startattempt.php?cmid=' . $id . '&sesskey=' . sesskey());
} else if ($qid = optional_param('q', 0, PARAM_INTEGER)) {
@@ -55,7 +55,7 @@ if ($attemptobj->get_userid() != $USER->id) {
}
}
// Check capabilities and block settings
// Check capabilities and block settings.
if (!$attemptobj->is_preview_user()) {
$attemptobj->require_capability('mod/quiz:attempt');
if (empty($attemptobj->get_quiz()->showblocks)) {
@@ -97,10 +97,10 @@ if (empty($slots)) {
throw new moodle_quiz_exception($attemptobj->get_quizobj(), 'noquestionsfound');
}
// Update attempt page
// Update attempt page.
if ($attemptobj->get_currentpage() != $page) {
if ($attemptobj->get_navigation_method() == QUIZ_NAVMETHOD_SEQ && $attemptobj->get_currentpage() > $page) {
// Prevent out of sequence access
// Prevent out of sequence access.
redirect($attemptobj->start_attempt_url(null, $attemptobj->get_currentpage()));
}
$DB->set_field('quiz_attempts', 'currentpage', $page);
+22 -22
View File
@@ -72,7 +72,7 @@ class quiz {
protected $accessmanager = null;
protected $ispreviewuser = null;
// Constructor =========================================================================
// Constructor =============================================================
/**
* Constructor, assuming we already have the necessary data loaded.
*
@@ -111,7 +111,7 @@ class quiz {
$course = $DB->get_record('course', array('id' => $quiz->course), '*', MUST_EXIST);
$cm = get_coursemodule_from_instance('quiz', $quiz->id, $course->id, false, MUST_EXIST);
// Update quiz with override information
// Update quiz with override information.
$quiz = quiz_update_effective_access($quiz, $userid);
return new quiz($quiz, $cm, $course);
@@ -126,7 +126,7 @@ class quiz {
return new quiz_attempt($attemptdata, $this->quiz, $this->cm, $this->course);
}
// Functions for loading more data =====================================================
// Functions for loading more data =========================================
/**
* Load just basic information about all the questions in this quiz.
@@ -160,7 +160,7 @@ class quiz {
get_question_options($questionstoprocess);
}
// Simple getters ======================================================================
// Simple getters ==========================================================
/** @return int the course id. */
public function get_courseid() {
return $this->course->id;
@@ -282,7 +282,7 @@ class quiz {
return require_capability($capability, $this->context, $userid, $doanything);
}
// URLs related to this attempt ========================================================
// URLs related to this attempt ============================================
/**
* @return string the URL of this quiz's view page.
*/
@@ -340,7 +340,7 @@ class quiz {
return new moodle_url('/mod/quiz/summary.php', array('attempt' => $attemptid));
}
// Bits of content =====================================================================
// Bits of content =========================================================
/**
* @param bool $unfinished whether there is currently an unfinished attempt active.
@@ -405,7 +405,7 @@ class quiz {
return '';
}
// Private methods =====================================================================
// Private methods =========================================================
/**
* Check that the definition of a particular question is loaded, and if not throw an exception.
* @param $id a questionid.
@@ -437,16 +437,16 @@ class quiz_attempt {
/** @var string to identify the abandoned state. */
const ABANDONED = 'abandoned';
// Basic data
// Basic data.
protected $quizobj;
protected $attempt;
// More details of what happened for each question.
protected $quba;
protected $pagelayout; // array page no => array of numbers on the page in order.
protected $pagelayout; // Array page no => array of numbers on the page in order.
protected $reviewoptions = null;
// Constructor =========================================================================
// Constructor =============================================================
/**
* Constructor assuming we already have the necessary data loaded.
*
@@ -482,7 +482,7 @@ class quiz_attempt {
$course = $DB->get_record('course', array('id' => $quiz->course), '*', MUST_EXIST);
$cm = get_coursemodule_from_instance('quiz', $quiz->id, $course->id, false, MUST_EXIST);
// Update quiz with override information
// Update quiz with override information.
$quiz = quiz_update_effective_access($quiz, $attempt->userid);
return new quiz_attempt($attempt, $quiz, $cm, $course);
@@ -555,7 +555,7 @@ class quiz_attempt {
}
}
// Simple getters ======================================================================
// Simple getters ==========================================================
public function get_quiz() {
return $this->quizobj->get_quiz();
}
@@ -998,7 +998,7 @@ class quiz_attempt {
* student should next do something.
* @return int timestamp by which the student needs to do something.
*/
function get_due_date() {
public function get_due_date() {
$deadlines = array();
if ($this->quizobj->get_quiz()->timelimit) {
$deadlines[] = $this->attempt->timestart + $this->quizobj->get_quiz()->timelimit;
@@ -1024,7 +1024,7 @@ class quiz_attempt {
}
}
// URLs related to this attempt ========================================================
// URLs related to this attempt ============================================
/**
* @return string quiz view url.
*/
@@ -1086,7 +1086,7 @@ class quiz_attempt {
return $this->page_and_question_url('review', $slot, $page, $showall, $thispage);
}
// Bits of content =====================================================================
// Bits of content =========================================================
/**
* If $reviewoptions->attempt is false, meaning that students can't review this
@@ -1259,7 +1259,7 @@ class quiz_attempt {
}
// If the attempt is already overdue, look to see if it should be abandoned ...
if ($this->attempt->state == quiz_attempt::OVERDUE) {
if ($this->attempt->state == self::OVERDUE) {
$timeoverdue = -$timeleft;
if ($timeoverdue > $this->quizobj->get_quiz()->graceperiod) {
$this->process_abandon($timestamp, $studentisonline);
@@ -1268,7 +1268,7 @@ class quiz_attempt {
return; // ... and we are done.
}
if ($this->attempt->state != quiz_attempt::IN_PROGRESS) {
if ($this->attempt->state != self::IN_PROGRESS) {
return; // Attempt is already in a final state.
}
@@ -1313,7 +1313,7 @@ class quiz_attempt {
$DB->update_record('quiz_attempts', $this->attempt);
}
if (!$this->is_preview() && $this->attempt->state == quiz_attempt::FINISHED) {
if (!$this->is_preview() && $this->attempt->state == self::FINISHED) {
quiz_save_best_grade($this->get_quiz(), $this->get_userid());
}
@@ -1352,7 +1352,7 @@ class quiz_attempt {
if (!$this->is_preview()) {
quiz_save_best_grade($this->get_quiz(), $this->attempt->userid);
// Trigger event
// Trigger event.
$this->fire_state_transition_event('quiz_attempt_submitted', $timestamp);
// Tell any access rules that care that the attempt is over.
@@ -1406,7 +1406,7 @@ class quiz_attempt {
protected function fire_state_transition_event($event, $timestamp) {
global $USER;
// Trigger event
// Trigger event.
$eventdata = new stdClass();
$eventdata->component = 'mod_quiz';
$eventdata->attemptid = $this->attempt->id;
@@ -1451,7 +1451,7 @@ class quiz_attempt {
get_string('gradingattempt', 'quiz_grading', $a));
}
// Private methods =====================================================================
// Private methods =========================================================
/**
* Get a URL for a particular question on a particular page of the quiz.
@@ -1468,7 +1468,7 @@ class quiz_attempt {
* @return The requested URL.
*/
protected function page_and_question_url($script, $slot, $page, $showall, $thispage) {
// Fix up $page
// Fix up $page.
if ($page == -1) {
if (!is_null($slot) && !$showall) {
$page = $this->quba->get_question($slot)->_page;
+14 -15
View File
@@ -18,8 +18,7 @@
* Provides support for the conversion of moodle1 backup to the moodle2 format
* Based off of a template @ http://docs.moodle.org/dev/Backup_1.9_conversion_for_developers
*
* @package mod
* @subpackage quiz
* @package mod_quiz
* @copyright 2011 Aparup Banerjee <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@@ -87,38 +86,38 @@ class moodle1_mod_quiz_handler extends moodle1_mod_handler {
public function process_quiz($data) {
global $CFG;
// replay the upgrade step 2008081501
// Replay the upgrade step 2008081501.
if (is_null($data['sumgrades'])) {
$data['sumgrades'] = 0;
//@todo for user data: quiz_attempts SET sumgrades=0 WHERE sumgrades IS NULL
//@todo for user data: quiz_grades.grade should be not be null , convert to default 0
// TODO for user data: quiz_attempts SET sumgrades=0 WHERE sumgrades IS NULL.
// TODO for user data: quiz_grades.grade should be not be null , convert to default 0.
}
// replay the upgrade step 2009042000
// Replay the upgrade step 2009042000.
if ($CFG->texteditors !== 'textarea') {
$data['intro'] = text_to_html($data['intro'], false, false, true);
$data['introformat'] = FORMAT_HTML;
}
// replay the upgrade step 2009031001
// Replay the upgrade step 2009031001.
$data['timelimit'] *= 60;
// get the course module id and context id
// Get the course module id and context id.
$instanceid = $data['id'];
$cminfo = $this->get_cminfo($instanceid);
$this->moduleid = $cminfo['id'];
$contextid = $this->converter->get_contextid(CONTEXT_MODULE, $this->moduleid);
// get a fresh new file manager for this instance
// Get a fresh new file manager for this instance.
$this->fileman = $this->converter->get_file_manager($contextid, 'mod_quiz');
// convert course files embedded into the intro
// Convert course files embedded into the intro.
$this->fileman->filearea = 'intro';
$this->fileman->itemid = 0;
$data['intro'] = moodle1_converter::migrate_referenced_files(
$data['intro'], $this->fileman);
// start writing quiz.xml
// Start writing quiz.xml.
$this->open_xml_writer("activities/quiz_{$this->moduleid}/quiz.xml");
$this->xmlwriter->begin_tag('activity', array('id' => $instanceid,
'moduleid' => $this->moduleid, 'modulename' => 'quiz',
@@ -155,7 +154,7 @@ class moodle1_mod_quiz_handler extends moodle1_mod_handler {
}
public function process_quiz_feedback($data) {
// replay the upgrade step 2010122302
// Replay the upgrade step 2010122302.
if (is_null($data['mingrade'])) {
$data['mingrade'] = 0;
}
@@ -171,15 +170,15 @@ class moodle1_mod_quiz_handler extends moodle1_mod_handler {
*/
public function on_quiz_end() {
// append empty <overrides> subpath element
// Append empty <overrides> subpath element.
$this->write_xml('overrides', array());
// finish writing quiz.xml
// Finish writing quiz.xml.
$this->xmlwriter->end_tag('quiz');
$this->xmlwriter->end_tag('activity');
$this->close_xml_writer();
// write inforef.xml
// Write inforef.xml.
$this->open_xml_writer("activities/quiz_{$this->moduleid}/inforef.xml");
$this->xmlwriter->begin_tag('inforef');
$this->xmlwriter->begin_tag('fileref');
@@ -46,21 +46,21 @@ class backup_quiz_activity_task extends backup_activity_task {
*/
protected function define_my_steps() {
// Generate the quiz.xml file containing all the quiz information
// and annotating used questions
// and annotating used questions.
$this->add_step(new backup_quiz_activity_structure_step('quiz_structure', 'quiz.xml'));
// Note: Following steps must be present
// in all the activities using question banks (only quiz for now)
// TODO: Specialise these step to a new subclass of backup_activity_task
// TODO: Specialise these step to a new subclass of backup_activity_task.
// Process all the annotated questions to calculate the question
// categories needing to be included in backup for this activity
// plus the categories belonging to the activity context itself
// plus the categories belonging to the activity context itself.
$this->add_step(new backup_calculate_question_categories('activity_question_categories'));
// Clean backup_temp_ids table from questions. We already
// have used them to detect question_categories and aren't
// needed anymore
// needed anymore.
$this->add_step(new backup_delete_temp_questions('clean_temp_questions'));
}
@@ -75,15 +75,15 @@ class backup_quiz_activity_task extends backup_activity_task {
$base = preg_quote($CFG->wwwroot, '/');
// Link to the list of quizzes
// Link to the list of quizzes.
$search="/(".$base."\/mod\/quiz\/index.php\?id\=)([0-9]+)/";
$content= preg_replace($search, '$@QUIZINDEX*$2@$', $content);
// Link to quiz view by moduleid
// Link to quiz view by moduleid.
$search="/(".$base."\/mod\/quiz\/view.php\?id\=)([0-9]+)/";
$content= preg_replace($search, '$@QUIZVIEWBYID*$2@$', $content);
// Link to quiz view by quizid
// Link to quiz view by quizid.
$search="/(".$base."\/mod\/quiz\/view.php\?q\=)([0-9]+)/";
$content= preg_replace($search, '$@QUIZVIEWBYQ*$2@$', $content);
@@ -35,10 +35,10 @@ class backup_quiz_activity_structure_step extends backup_questions_activity_stru
protected function define_structure() {
// To know if we are including userinfo
// To know if we are including userinfo.
$userinfo = $this->get_setting_value('userinfo');
// Define each element separated
// Define each element separated.
$quiz = new backup_nested_element('quiz', array('id'), array(
'name', 'intro', 'introformat', 'timeopen', 'timeclose', 'timelimit',
'overduehandling', 'graceperiod', 'preferredbehaviour', 'attempts_number',
@@ -82,14 +82,13 @@ class backup_quiz_activity_structure_step extends backup_questions_activity_stru
'state', 'timestart', 'timefinish', 'timemodified', 'sumgrades'));
// This module is using questions, so produce the related question states and sessions
// attaching them to the $attempt element based in 'uniqueid' matching
// attaching them to the $attempt element based in 'uniqueid' matching.
$this->add_question_usages($attempt, 'uniqueid');
// Define elements for access rule subplugin attempt data.
$this->add_subplugin_structure('quizaccess', $attempt, true);
// Build the tree
// Build the tree.
$quiz->add_child($qinstances);
$qinstances->add_child($qinstance);
@@ -105,7 +104,7 @@ class backup_quiz_activity_structure_step extends backup_questions_activity_stru
$quiz->add_child($attempts);
$attempts->add_child($attempt);
// Define sources
// Define sources.
$quiz->set_source_table('quiz', array('id' => backup::VAR_ACTIVITYID));
$qinstance->set_source_table('quiz_question_instances',
@@ -114,15 +113,15 @@ class backup_quiz_activity_structure_step extends backup_questions_activity_stru
$feedback->set_source_table('quiz_feedback',
array('quizid' => backup::VAR_PARENTID));
// Quiz overrides to backup are different depending of user info
// Quiz overrides to backup are different depending of user info.
$overrideparams = array('quiz' => backup::VAR_PARENTID);
if (!$userinfo) { // Without userinfo, skip user overrides
if (!$userinfo) { // Without userinfo, skip user overrides.
$overrideparams['userid'] = backup_helper::is_sqlparam(null);
}
$override->set_source_table('quiz_overrides', $overrideparams);
// All the rest of elements only happen if we are including user info
// All the rest of elements only happen if we are including user info.
if ($userinfo) {
$grade->set_source_table('quiz_grades', array('quiz' => backup::VAR_PARENTID));
$attempt->set_source_sql('
@@ -132,23 +131,23 @@ class backup_quiz_activity_structure_step extends backup_questions_activity_stru
array('quiz' => backup::VAR_PARENTID));
}
// Define source alias
// Define source alias.
$quiz->set_source_alias('attempts', 'attempts_number');
$grade->set_source_alias('grade', 'gradeval');
$attempt->set_source_alias('attempt', 'attemptnum');
// Define id annotations
// Define id annotations.
$qinstance->annotate_ids('question', 'question');
$override->annotate_ids('user', 'userid');
$override->annotate_ids('group', 'groupid');
$grade->annotate_ids('user', 'userid');
$attempt->annotate_ids('user', 'userid');
// Define file annotations
$quiz->annotate_files('mod_quiz', 'intro', null); // This file area hasn't itemid
// Define file annotations.
$quiz->annotate_files('mod_quiz', 'intro', null); // This file area hasn't itemid.
$feedback->annotate_files('mod_quiz', 'feedback', 'id');
// Return the root element (quiz), wrapped into standard activity structure
// Return the root element (quiz), wrapped into standard activity structure.
return $this->prepare_activity_structure($quiz);
}
}
@@ -25,7 +25,6 @@
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/mod/quiz/backup/moodle2/restore_quiz_stepslib.php');
// Because it exists (must)
/**
@@ -41,14 +40,14 @@ class restore_quiz_activity_task extends restore_activity_task {
* Define (add) particular settings this activity can have
*/
protected function define_my_settings() {
// No particular settings for this activity
// No particular settings for this activity.
}
/**
* Define (add) particular steps this activity can have
*/
protected function define_my_steps() {
// quiz only has one structure step
// Quiz only has one structure step.
$this->add_step(new restore_quiz_activity_structure_step('quiz_structure', 'quiz.xml'));
}
@@ -120,44 +119,44 @@ class restore_quiz_activity_task extends restore_activity_task {
$rules[] = new restore_log_rule('quiz', 'manualgrading',
'report.php?mode=grading&q={quiz}', '{quiz}');
// All the ones calling to review.php have two rules to handle both old and new urls
// in any case they are always converted to new urls on restore
// TODO: In Moodle 2.x (x >= 5) kill the old rules
// in any case they are always converted to new urls on restore.
// TODO: In Moodle 2.x (x >= 5) kill the old rules.
// Note we are using the 'quiz_attempt_id' mapping because that is the
// one containing the quiz_attempt->ids old an new for quiz-attempt
// one containing the quiz_attempt->ids old an new for quiz-attempt.
$rules[] = new restore_log_rule('quiz', 'attempt',
'review.php?id={course_module}&attempt={quiz_attempt}', '{quiz}',
null, null, 'review.php?attempt={quiz_attempt}');
// old an new for quiz-submit
// Old an new for quiz-submit.
$rules[] = new restore_log_rule('quiz', 'submit',
'review.php?id={course_module}&attempt={quiz_attempt_id}', '{quiz}',
null, null, 'review.php?attempt={quiz_attempt_id}');
$rules[] = new restore_log_rule('quiz', 'submit',
'review.php?attempt={quiz_attempt_id}', '{quiz}');
// old an new for quiz-review
// Old an new for quiz-review.
$rules[] = new restore_log_rule('quiz', 'review',
'review.php?id={course_module}&attempt={quiz_attempt_id}', '{quiz}',
null, null, 'review.php?attempt={quiz_attempt_id}');
$rules[] = new restore_log_rule('quiz', 'review',
'review.php?attempt={quiz_attempt_id}', '{quiz}');
// old an new for quiz-start attemp
// Old an new for quiz-start attemp.
$rules[] = new restore_log_rule('quiz', 'start attempt',
'review.php?id={course_module}&attempt={quiz_attempt_id}', '{quiz}',
null, null, 'review.php?attempt={quiz_attempt_id}');
$rules[] = new restore_log_rule('quiz', 'start attempt',
'review.php?attempt={quiz_attempt_id}', '{quiz}');
// old an new for quiz-close attemp
// Old an new for quiz-close attemp.
$rules[] = new restore_log_rule('quiz', 'close attempt',
'review.php?id={course_module}&attempt={quiz_attempt_id}', '{quiz}',
null, null, 'review.php?attempt={quiz_attempt_id}');
$rules[] = new restore_log_rule('quiz', 'close attempt',
'review.php?attempt={quiz_attempt_id}', '{quiz}');
// old an new for quiz-continue attempt
// Old an new for quiz-continue attempt.
$rules[] = new restore_log_rule('quiz', 'continue attempt',
'review.php?id={course_module}&attempt={quiz_attempt_id}', '{quiz}',
null, null, 'review.php?attempt={quiz_attempt_id}');
$rules[] = new restore_log_rule('quiz', 'continue attempt',
'review.php?attempt={quiz_attempt_id}', '{quiz}');
// old an new for quiz-continue attemp
// Old an new for quiz-continue attemp.
$rules[] = new restore_log_rule('quiz', 'continue attemp',
'review.php?id={course_module}&attempt={quiz_attempt_id}', '{quiz}',
null, 'continue attempt', 'review.php?attempt={quiz_attempt_id}');
@@ -59,7 +59,7 @@ class restore_quiz_activity_structure_step extends restore_questions_activity_st
'/activity/quiz/attempts/attempt');
$paths[] = $quizattempt;
// Add states and sessions
// Add states and sessions.
$this->add_question_usages($quizattempt, $paths);
// A chance for access subplugings to set up their attempt data.
@@ -76,7 +76,7 @@ class restore_quiz_activity_structure_step extends restore_questions_activity_st
}
}
// Return the paths wrapped into standard activity structure
// Return the paths wrapped into standard activity structure.
return $this->prepare_activity_structure($paths);
}
@@ -92,19 +92,19 @@ class restore_quiz_activity_structure_step extends restore_questions_activity_st
$data->timecreated = $this->apply_date_offset($data->timecreated);
$data->timemodified = $this->apply_date_offset($data->timemodified);
// Needed by {@link process_quiz_attempt_legacy}
// Needed by {@link process_quiz_attempt_legacy}.
$this->oldquizlayout = $data->questions;
$data->questions = $this->questions_recode_layout($data->questions);
// quiz->attempts can come both in data->attempts and
// data->attempts_number, handle both. MDL-26229
// The setting quiz->attempts can come both in data->attempts and
// data->attempts_number, handle both. MDL-26229.
if (isset($data->attempts_number)) {
$data->attempts = $data->attempts_number;
unset($data->attempts_number);
}
// The old optionflags and penaltyscheme from 2.0 need to be mapped to
// the new preferredbehaviour. MDL-20636
// the new preferredbehaviour. See MDL-20636.
if (!isset($data->preferredbehaviour)) {
if (empty($data->optionflags)) {
$data->preferredbehaviour = 'deferredfeedback';
@@ -118,7 +118,7 @@ class restore_quiz_activity_structure_step extends restore_questions_activity_st
}
// The old review column from 2.0 need to be split into the seven new
// review columns. MDL-20636
// review columns. See MDL-20636.
if (isset($data->review)) {
require_once($CFG->dirroot . '/mod/quiz/locallib.php');
@@ -206,7 +206,7 @@ class restore_quiz_activity_structure_step extends restore_questions_activity_st
}
// The old popup column from from <= 2.1 need to be mapped to
// the new browsersecurity. MDL-29627
// the new browsersecurity. See MDL-29627.
if (!isset($data->browsersecurity)) {
if (empty($data->popup)) {
$data->browsersecurity = '-';
@@ -220,9 +220,9 @@ class restore_quiz_activity_structure_step extends restore_questions_activity_st
unset($data->popup);
}
// insert the quiz record
// Insert the quiz record.
$newitemid = $DB->insert_record('quiz', $data);
// immediately after inserting "activity" record, call this
// Immediately after inserting "activity" record, call this.
$this->apply_activity_instance($newitemid);
}
@@ -248,7 +248,7 @@ class restore_quiz_activity_structure_step extends restore_questions_activity_st
$data->quizid = $this->get_new_parentid('quiz');
$newitemid = $DB->insert_record('quiz_feedback', $data);
$this->set_mapping('quiz_feedback', $oldid, $newitemid, true); // Has related files
$this->set_mapping('quiz_feedback', $oldid, $newitemid, true); // Has related files.
}
protected function process_quiz_override($data) {
@@ -257,10 +257,10 @@ class restore_quiz_activity_structure_step extends restore_questions_activity_st
$data = (object)$data;
$oldid = $data->id;
// Based on userinfo, we'll restore user overides or no
// Based on userinfo, we'll restore user overides or no.
$userinfo = $this->get_setting_value('userinfo');
// Skip user overrides if we are not restoring userinfo
// Skip user overrides if we are not restoring userinfo.
if (!$userinfo && !is_null($data->userid)) {
return;
}
@@ -275,7 +275,7 @@ class restore_quiz_activity_structure_step extends restore_questions_activity_st
$newitemid = $DB->insert_record('quiz_overrides', $data);
// Add mapping, restore of logs needs it
// Add mapping, restore of logs needs it.
$this->set_mapping('quiz_override', $oldid, $newitemid);
}
@@ -331,15 +331,15 @@ class restore_quiz_activity_structure_step extends restore_questions_activity_st
$newitemid = $DB->insert_record('quiz_attempts', $data);
// Save quiz_attempt->id mapping, because logs use it
// Save quiz_attempt->id mapping, because logs use it.
$this->set_mapping('quiz_attempt', $oldid, $newitemid, false);
}
protected function after_execute() {
parent::after_execute();
// Add quiz related files, no need to match by itemname (just internally handled context)
// Add quiz related files, no need to match by itemname (just internally handled context).
$this->add_related_files('mod_quiz', 'intro', null);
// Add feedback related files, matching by itemname = 'quiz_feedback'
// Add feedback related files, matching by itemname = 'quiz_feedback'.
$this->add_related_files('mod_quiz', 'feedback', 'quiz_feedback');
}
}
+3 -3
View File
@@ -27,8 +27,8 @@
require_once('../../config.php');
require_once('locallib.php');
$attemptid = required_param('attempt', PARAM_INT); // attempt id
$slot = required_param('slot', PARAM_INT); // question number in attempt
$attemptid = required_param('attempt', PARAM_INT);
$slot = required_param('slot', PARAM_INT); // The question number in the attempt.
$PAGE->set_url('/mod/quiz/comment.php', array('attempt' => $attemptid, 'slot' => $slot));
@@ -48,7 +48,7 @@ add_to_log($attemptobj->get_courseid(), 'quiz', 'manualgrade', 'comment.php?atte
$attemptobj->get_attemptid() . '&slot=' . $slot,
$attemptobj->get_quizid(), $attemptobj->get_cmid());
// Print the page header
// Print the page header.
$PAGE->set_pagelayout('popup');
echo $OUTPUT->header();
echo $OUTPUT->heading(format_string($attemptobj->get_question_name($slot)));
+1 -1
View File
@@ -85,7 +85,7 @@ $capabilities = array(
)
),
// Edit the quiz overrides
// Edit the quiz overrides.
'mod/quiz:manageoverrides' => array(
'captype' => 'write',
'contextlevel' => CONTEXT_MODULE,
+29 -30
View File
@@ -36,42 +36,41 @@ function xmldb_quiz_upgrade($oldversion) {
$dbman = $DB->get_manager();
// Moodle v2.2.0 release upgrade line
// Put any upgrade step following this
// Moodle v2.2.0 release upgrade line.
// Put any upgrade step following this.
if ($oldversion < 2011120700) {
// Define field lastcron to be dropped from quiz_reports
// Define field lastcron to be dropped from quiz_reports.
$table = new xmldb_table('quiz_reports');
$field = new xmldb_field('lastcron');
// Conditionally launch drop field lastcron
// Conditionally launch drop field lastcron.
if ($dbman->field_exists($table, $field)) {
$dbman->drop_field($table, $field);
}
// quiz savepoint reached
// Quiz savepoint reached.
upgrade_mod_savepoint(true, 2011120700, 'quiz');
}
if ($oldversion < 2011120701) {
// Define field cron to be dropped from quiz_reports
// Define field cron to be dropped from quiz_reports.
$table = new xmldb_table('quiz_reports');
$field = new xmldb_field('cron');
// Conditionally launch drop field cron
// Conditionally launch drop field cron.
if ($dbman->field_exists($table, $field)) {
$dbman->drop_field($table, $field);
}
// quiz savepoint reached
// Quiz savepoint reached.
upgrade_mod_savepoint(true, 2011120701, 'quiz');
}
if ($oldversion < 2011120703) {
// Track page of quiz attempts
// Track page of quiz attempts.
$table = new xmldb_table('quiz_attempts');
$field = new xmldb_field('currentpage', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 0);
@@ -83,7 +82,7 @@ function xmldb_quiz_upgrade($oldversion) {
}
if ($oldversion < 2012030901) {
// Configuration option for navigation method
// Configuration option for navigation method.
$table = new xmldb_table('quiz');
$field = new xmldb_field('navmethod', XMLDB_TYPE_CHAR, '16', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 'free');
@@ -95,59 +94,59 @@ function xmldb_quiz_upgrade($oldversion) {
}
if ($oldversion < 2012040200) {
// Define index quiz-userid-attempt (unique) to be dropped form quiz_attempts
// Define index quiz-userid-attempt (unique) to be dropped form quiz_attempts.
$table = new xmldb_table('quiz_attempts');
$index = new xmldb_index('userid', XMLDB_INDEX_NOTUNIQUE, array('userid'));
// Conditionally launch drop index quiz-userid-attempt
// Conditionally launch drop index quiz-userid-attempt.
if ($dbman->index_exists($table, $index)) {
$dbman->drop_index($table, $index);
}
// quiz savepoint reached
// Quiz savepoint reached.
upgrade_mod_savepoint(true, 2012040200, 'quiz');
}
if ($oldversion < 2012040201) {
// Define key userid (foreign) to be added to quiz_attempts
// Define key userid (foreign) to be added to quiz_attempts.
$table = new xmldb_table('quiz_attempts');
$key = new xmldb_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
// Launch add key userid
// Launch add key userid.
$dbman->add_key($table, $key);
// quiz savepoint reached
// Quiz savepoint reached.
upgrade_mod_savepoint(true, 2012040201, 'quiz');
}
if ($oldversion < 2012040202) {
// Define index quiz-userid-attempt (unique) to be added to quiz_attempts
// Define index quiz-userid-attempt (unique) to be added to quiz_attempts.
$table = new xmldb_table('quiz_attempts');
$index = new xmldb_index('quiz-userid-attempt', XMLDB_INDEX_UNIQUE, array('quiz', 'userid', 'attempt'));
// Conditionally launch add index quiz-userid-attempt
// Conditionally launch add index quiz-userid-attempt.
if (!$dbman->index_exists($table, $index)) {
$dbman->add_index($table, $index);
}
// quiz savepoint reached
// Quiz savepoint reached.
upgrade_mod_savepoint(true, 2012040202, 'quiz');
}
if ($oldversion < 2012040203) {
// Define field state to be added to quiz_attempts
// Define field state to be added to quiz_attempts.
$table = new xmldb_table('quiz_attempts');
$field = new xmldb_field('state', XMLDB_TYPE_CHAR, '16', null, XMLDB_NOTNULL, null, 'inprogress', 'preview');
// Conditionally launch add field state
// Conditionally launch add field state.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// quiz savepoint reached
// Quiz savepoint reached.
upgrade_mod_savepoint(true, 2012040203, 'quiz');
}
@@ -159,37 +158,37 @@ function xmldb_quiz_upgrade($oldversion) {
// Other, more complex transitions (basically abandoned attempts), will
// be handled by cron later.
// quiz savepoint reached
// Quiz savepoint reached.
upgrade_mod_savepoint(true, 2012040204, 'quiz');
}
if ($oldversion < 2012040205) {
// Define field overduehandling to be added to quiz
// Define field overduehandling to be added to quiz.
$table = new xmldb_table('quiz');
$field = new xmldb_field('overduehandling', XMLDB_TYPE_CHAR, '16', null, XMLDB_NOTNULL, null, 'autoabandon', 'timelimit');
// Conditionally launch add field overduehandling
// Conditionally launch add field overduehandling.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// quiz savepoint reached
// Quiz savepoint reached.
upgrade_mod_savepoint(true, 2012040205, 'quiz');
}
if ($oldversion < 2012040206) {
// Define field graceperiod to be added to quiz
// Define field graceperiod to be added to quiz.
$table = new xmldb_table('quiz');
$field = new xmldb_field('graceperiod', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'overduehandling');
// Conditionally launch add field graceperiod
// Conditionally launch add field graceperiod.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// quiz savepoint reached
// Quiz savepoint reached.
upgrade_mod_savepoint(true, 2012040206, 'quiz');
}
+19 -20
View File
@@ -111,8 +111,8 @@ function module_specific_controls($totalnumber, $recurse, $category, $cmid, $cmo
return $out;
}
//these params are only passed from page request to request while we stay on
//this page otherwise they would go in question_edit_setup
// These params are only passed from page request to request while we stay on
// this page otherwise they would go in question_edit_setup.
$quiz_reordertool = optional_param('reordertool', -1, PARAM_BOOL);
$quiz_qbanktool = optional_param('qbanktool', -1, PARAM_BOOL);
$scrollpos = optional_param('scrollpos', '', PARAM_INT);
@@ -204,7 +204,7 @@ if (($down = optional_param('down', false, PARAM_INT)) && confirm_sesskey()) {
}
if (optional_param('repaginate', false, PARAM_BOOL) && confirm_sesskey()) {
// Re-paginate the quiz
// Re-paginate the quiz.
$questionsperpage = optional_param('questionsperpage', $quiz->questionsperpage, PARAM_INT);
$quiz->questions = quiz_repaginate($quiz->questions, $questionsperpage );
$DB->set_field('quiz', 'questions', $quiz->questions, array('id' => $quiz->id));
@@ -213,7 +213,7 @@ if (optional_param('repaginate', false, PARAM_BOOL) && confirm_sesskey()) {
}
if (($addquestion = optional_param('addquestion', 0, PARAM_INT)) && confirm_sesskey()) {
// Add a single question to the current quiz
// Add a single question to the current quiz.
quiz_require_question_use($addquestion);
$addonpage = optional_param('addonpage', 0, PARAM_INT);
quiz_add_quiz_question($addquestion, $quiz, $addonpage);
@@ -224,9 +224,9 @@ if (($addquestion = optional_param('addquestion', 0, PARAM_INT)) && confirm_sess
}
if (optional_param('add', false, PARAM_BOOL) && confirm_sesskey()) {
// Add selected questions to the current quiz
// Add selected questions to the current quiz.
$rawdata = (array) data_submitted();
foreach ($rawdata as $key => $value) { // Parse input for question ids
foreach ($rawdata as $key => $value) { // Parse input for question ids.
if (preg_match('!^q([0-9]+)$!', $key, $matches)) {
$key = $matches[1];
quiz_require_question_use($key);
@@ -239,7 +239,7 @@ if (optional_param('add', false, PARAM_BOOL) && confirm_sesskey()) {
}
if ((optional_param('addrandom', false, PARAM_BOOL)) && confirm_sesskey()) {
// Add random questions to the quiz
// Add random questions to the quiz.
$recurse = optional_param('recurse', 0, PARAM_BOOL);
$addonpage = optional_param('addonpage', 0, PARAM_INT);
$categoryid = required_param('categoryid', PARAM_INT);
@@ -305,8 +305,8 @@ if (optional_param('savechanges', false, PARAM_BOOL) && confirm_sesskey()) {
$deletepreviews = false;
$recomputesummarks = false;
$oldquestions = explode(',', $quiz->questions); // the questions in the old order
$questions = array(); // for questions in the new order
$oldquestions = explode(',', $quiz->questions); // The questions in the old order.
$questions = array(); // For questions in the new order.
$rawdata = (array) data_submitted();
$moveonpagequestions = array();
$moveselectedonpage = optional_param('moveselectedonpagetop', 0, PARAM_INT);
@@ -316,7 +316,7 @@ if (optional_param('savechanges', false, PARAM_BOOL) && confirm_sesskey()) {
foreach ($rawdata as $key => $value) {
if (preg_match('!^g([0-9]+)$!', $key, $matches)) {
// Parse input for question -> grades
// Parse input for question -> grades.
$questionid = $matches[1];
$quiz->grades[$questionid] = clean_param($value, PARAM_FLOAT);
quiz_update_question_instance($quiz->grades[$questionid], $questionid, $quiz);
@@ -324,7 +324,7 @@ if (optional_param('savechanges', false, PARAM_BOOL) && confirm_sesskey()) {
$recomputesummarks = true;
} else if (preg_match('!^o(pg)?([0-9]+)$!', $key, $matches)) {
// Parse input for ordering info
// Parse input for ordering info.
$questionid = $matches[2];
// Make sure two questions don't overwrite each other. If we get a second
// question with the same position, shift the second one along to the next gap.
@@ -342,7 +342,7 @@ if (optional_param('savechanges', false, PARAM_BOOL) && confirm_sesskey()) {
}
}
// If ordering info was given, reorder the questions
// If ordering info was given, reorder the questions.
if ($questions) {
ksort($questions);
$questions[] = 0;
@@ -351,12 +351,12 @@ if (optional_param('savechanges', false, PARAM_BOOL) && confirm_sesskey()) {
$deletepreviews = true;
}
//get a list of questions to move, later to be added in the appropriate
//place in the string
// Get a list of questions to move, later to be added in the appropriate
// place in the string.
if ($moveselectedonpage) {
$questions = explode(',', $quiz->questions);
$newquestions = array();
//remove the questions from their original positions first
// Remove the questions from their original positions first.
foreach ($questions as $questionid) {
if (!in_array($questionid, $selectedquestionids)) {
$newquestions[] = $questionid;
@@ -364,7 +364,7 @@ if (optional_param('savechanges', false, PARAM_BOOL) && confirm_sesskey()) {
}
$questions = $newquestions;
//move to the end of the selected page
// Move to the end of the selected page.
$pagebreakpositions = array_keys($questions, 0);
$numpages = count($pagebreakpositions);
@@ -384,7 +384,7 @@ if (optional_param('savechanges', false, PARAM_BOOL) && confirm_sesskey()) {
$deletepreviews = true;
}
// If rescaling is required save the new maximum
// If rescaling is required save the new maximum.
$maxgrade = optional_param('maxgrade', -1, PARAM_FLOAT);
if ($maxgrade >= 0) {
quiz_set_grade($maxgrade, $quiz);
@@ -539,8 +539,7 @@ if ($quiz_reordertool) {
echo '<fieldset class="invisiblefieldset">';
echo html_writer::input_hidden_params($thispageurl);
echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
//YUI does not submit the value of the submit button so
//we need to add the value:
// YUI does not submit the value of the submit button so we need to add the value.
echo '<input type="hidden" name="repaginate" value="'.$gostring.'" />';
$attributes = array();
$attributes['disabled'] = $repaginatingdisabledhtml ? 'disabled' : null;
@@ -563,7 +562,7 @@ quiz_print_question_list($quiz, $thispageurl, true, $quiz_reordertool, $quiz_qba
$quizhasattempts, $defaultcategoryobj, $canaddquestion, $canaddrandom);
echo '</div>';
// Close <div class="quizcontents">:
// Close <div class="quizcontents">.
echo '</div>';
if (!$quiz_reordertool && $canaddrandom) {
+34 -36
View File
@@ -120,9 +120,9 @@ function quiz_add_quiz_question($id, $quiz, $page = 0) {
return false;
}
// remove ending page break if it is not needed
// Remove ending page break if it is not needed.
if ($breaks = array_keys($questions, 0)) {
// determine location of the last two page breaks
// Determine location of the last two page breaks.
$end = end($breaks);
$last = prev($breaks);
$last = $last ? $last : -1;
@@ -133,19 +133,19 @@ function quiz_add_quiz_question($id, $quiz, $page = 0) {
if (is_int($page) && $page >= 1) {
$numofpages = quiz_number_of_pages($quiz->questions);
if ($numofpages<$page) {
//the page specified does not exist in quiz
// The page specified does not exist in quiz.
$page = 0;
} else {
// add ending page break - the following logic requires doing
//this at this point
// Add ending page break - the following logic requires doing
// this at this point.
$questions[] = 0;
$currentpage = 1;
$addnow = false;
foreach ($questions as $question) {
if ($question == 0) {
$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.
// The current page is the one after the one we want to add on,
// so we add the question before adding the current page.
if ($currentpage == $page + 1) {
$questions_new[] = $id;
}
@@ -156,13 +156,13 @@ function quiz_add_quiz_question($id, $quiz, $page = 0) {
}
}
if ($page == 0) {
// add question
// Add question.
$questions[] = $id;
// add ending page break
// Add ending page break.
$questions[] = 0;
}
// Save new questionslist in database
// Save new questionslist in database.
$quiz->questions = implode(',', $questions);
$DB->set_field('quiz', 'questions', $quiz->questions, array('id' => $quiz->id));
@@ -216,7 +216,7 @@ function quiz_add_random_questions($quiz, $addonpage, $categoryid, $number,
$form->category = $category->id . ',' . $category->contextid;
$form->defaultmark = 1;
$form->hidden = 1;
$form->stamp = make_unique_id_code(); // Set the unique code (not to be changed)
$form->stamp = make_unique_id_code(); // Set the unique code (not to be changed).
$question = new stdClass();
$question->qtype = 'random';
$question = question_bank::get_qtype('random')->save_question($question, $form);
@@ -468,11 +468,11 @@ function quiz_print_question_list($quiz, $pageurl, $allowdelete, $reordertool,
echo $reordercontrolstop;
}
//the current question ordinal (no descriptions)
// The current question ordinal (no descriptions).
$qno = 1;
//the current question (includes questions and descriptions)
// The current question (includes questions and descriptions).
$questioncount = 0;
//the current page number in iteration
// The current page number in iteration.
$pagecount = 0;
$pageopen = false;
@@ -486,7 +486,7 @@ function quiz_print_question_list($quiz, $pageurl, $allowdelete, $reordertool,
$reordercheckboxlabel = '';
$reordercheckboxlabelclose = '';
// If the questiontype is missing change the question type
// If the questiontype is missing change the question type.
if ($qnum && !array_key_exists($qnum, $questions)) {
$fakequestion = new stdClass();
$fakequestion->id = $qnum;
@@ -504,10 +504,9 @@ function quiz_print_question_list($quiz, $pageurl, $allowdelete, $reordertool,
}
if ($qnum != 0 || ($qnum == 0 && !$pageopen)) {
//this is either a question or a page break after another
// (no page is currently open)
// This is either a question or a page break after another (no page is currently open).
if (!$pageopen) {
//if no page is open, start display of a page
// If no page is open, start display of a page.
$pagecount++;
echo '<div class="quizpage"><span class="pagetitle">' .
get_string('page') . '&nbsp;' . $pagecount .
@@ -540,9 +539,8 @@ function quiz_print_question_list($quiz, $pageurl, $allowdelete, $reordertool,
$questionurl = new moodle_url('/question/question.php',
$questionparams);
$questioncount++;
//this is an actual question
/* Display question start */
// This is an actual question.
?>
<div class="question">
<div class="questioncontainer <?php echo $question->qtype; ?>">
@@ -604,7 +602,7 @@ function quiz_print_question_list($quiz, $pageurl, $allowdelete, $reordertool,
}
if ($allowdelete && ($question->qtype == 'missingtype' ||
question_has_capability_on($question, 'use', $question->category))) {
// remove from quiz, not question delete.
// Remove from quiz, not question delete.
if (!$hasattempts) {
echo $OUTPUT->action_icon($pageurl->out(true,
array('remove' => $question->id, 'sesskey'=>sesskey())),
@@ -663,13 +661,13 @@ function quiz_print_question_list($quiz, $pageurl, $allowdelete, $reordertool,
?>
<div class="questioncontentcontainer">
<?php
if ($question->qtype == 'random') { // it is a random question
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
} else { // It is a single question.
if (!$reordertool) {
quiz_print_singlequestion($question, $returnurl, $quiz);
} else {
@@ -685,7 +683,7 @@ function quiz_print_question_list($quiz, $pageurl, $allowdelete, $reordertool,
<?php
}
}
//a page break: end the existing page.
// A page break: end the existing page.
if ($qnum == 0) {
if ($pageopen) {
if (!$reordertool && !($quiz->shufflequestions &&
@@ -693,8 +691,8 @@ function quiz_print_question_list($quiz, $pageurl, $allowdelete, $reordertool,
quiz_print_pagecontrols($quiz, $pageurl, $pagecount,
$hasattempts, $defaultcategoryobj, $canaddquestion, $canaddrandom);
} else if ($count < $questiontotalcount - 1) {
//do not include the last page break for reordering
//to avoid creating a new extra page in the end
// Do not include the last page break for reordering
// to avoid creating a new extra page in the end.
echo '<input type="hidden" name="opg' . $pagecount . '" size="2" value="' .
(10*$count + 10) . '" />';
}
@@ -745,7 +743,7 @@ function quiz_print_pagecontrols($quiz, $pageurl, $page, $hasattempts,
$randombuttoncount++;
echo '<div class="pagecontrols">';
// Get the current context
// Get the current context.
$thiscontext = get_context_instance(CONTEXT_COURSE, $quiz->course);
$contexts = new question_edit_contexts($thiscontext);
@@ -756,7 +754,7 @@ function quiz_print_pagecontrols($quiz, $pageurl, $page, $hasattempts,
}
if ($canaddquestion) {
// Create the url the question page will return to
// 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.
@@ -863,33 +861,33 @@ function quiz_print_randomquestion(&$question, &$pageurl, &$quiz, $quiz_qbanktoo
echo '<div class="randomquestionqlist">';
if ($questioncount == 0) {
// No questions in category, give an error plus instructions
// No questions in category, give an error plus instructions.
echo '<span class="error">';
print_string('noquestionsnotinuse', 'quiz');
echo '</span>';
echo '<br />';
// Embed the link into the string with instructions
// Embed the link into the string with instructions.
$a = new stdClass();
$a->catname = '<strong>' . $category->name . '</strong>';
$a->link = $linkcategorycontents;
echo get_string('addnewquestionsqbank', 'quiz', $a);
} else {
// Category has questions
// Category has questions.
// Get a sample from the database,
// Get a sample from the database.
$questionidstoshow = array_slice($questionids, 0, NUM_QS_TO_SHOW_IN_RANDOM);
$questionstoshow = $DB->get_records_list('question', 'id', $questionidstoshow,
'', 'id, qtype, name, questiontext, questiontextformat');
// list them,
// Then list them.
echo '<ul>';
foreach ($questionstoshow as $question) {
echo '<li>' . quiz_question_tostring($question, true) . '</li>';
}
// and then display the total number.
// Finally display the total number.
echo '<li class="totalquestionsinrandomqcategory">';
if ($questioncount > NUM_QS_TO_SHOW_IN_RANDOM) {
echo '... ';
@@ -1058,7 +1056,7 @@ class question_bank_add_to_quiz_action_column extends question_bank_action_colum
if (!question_has_capability_on($question, 'use')) {
return;
}
// for RTL languages: switch right and left arrows
// For RTL languages: switch right and left arrows.
if (right_to_left()) {
$movearrow = 't/removeright';
} else {
@@ -1187,7 +1185,7 @@ class quiz_question_bank_view extends question_bank_view {
$this->display_category_form($this->contexts->having_one_edit_tab_cap($tabname),
$this->baseurl, $cat);
// continues with list of questions
// Continues with list of questions.
$this->display_question_list($this->contexts->having_one_edit_tab_cap($tabname),
$this->baseurl, $cat, $this->cm, $recurse, $page,
$perpage, $showhidden, $showquestiontext,
+1 -1
View File
@@ -68,7 +68,7 @@ if ($userid) {
case QUIZ_GRADEHIGHEST:
$maxmark = 0;
foreach ($attempts as $at) {
// >=, since we want to most recent relevant attempt.
// Operator >=, since we want to most recent relevant attempt.
if ((float) $at->sumgrades >= $maxmark) {
$maxmark = $at->sumgrades;
$attempt = $at;
+6 -6
View File
@@ -38,7 +38,7 @@ $PAGE->set_pagelayout('incourse');
add_to_log($course->id, "quiz", "view all", "index.php?id=$course->id", "");
// Print the header
// Print the header.
$strquizzes = get_string("modulenameplural", "quiz");
$streditquestions = '';
$editqcontexts = new question_edit_contexts($coursecontext);
@@ -57,14 +57,14 @@ $PAGE->set_button($streditquestions);
$PAGE->set_heading($course->fullname);
echo $OUTPUT->header();
// Get all the appropriate data
// Get all the appropriate data.
if (!$quizzes = get_all_instances_in_course("quiz", $course)) {
notice(get_string('thereareno', 'moodle', $strquizzes), "../../course/view.php?id=$course->id");
die;
}
$sections = get_all_sections($course->id);
// Check if we need the closing date header
// Check if we need the closing date header.
$showclosingheader = false;
$showfeedback = false;
foreach ($quizzes as $quiz) {
@@ -91,7 +91,7 @@ if ($showclosingheader) {
array_unshift($headings, get_string('sectionname', 'format_'.$course->format));
array_unshift($align, 'center');
$showing = ''; // default
$showing = '';
if (has_capability('mod/quiz:viewreports', $coursecontext)) {
array_push($headings, get_string('attempts', 'quiz'));
@@ -106,7 +106,7 @@ if (has_capability('mod/quiz:viewreports', $coursecontext)) {
array_push($headings, get_string('feedback', 'quiz'));
array_push($align, 'left');
}
$showing = 'grades'; // default
$showing = 'grades';
$grades = $DB->get_records_sql_menu('
SELECT qg.quiz, qg.grade
@@ -192,5 +192,5 @@ foreach ($quizzes as $quiz) {
// Display the table.
echo html_writer::table($table);
// Finish the page
// Finish the page.
echo $OUTPUT->footer();
+49 -50
View File
@@ -53,10 +53,10 @@ define('QUIZ_ATTEMPTLAST', '4');
/**#@-*/
/**
* If start and end date for the quiz are more than this many seconds apart
* @var int If start and end date for the quiz are more than this many seconds apart
* they will be represented by two separate events in the calendar
*/
define('QUIZ_MAX_EVENT_LENGTH', 5*24*60*60); // 5 days
define('QUIZ_MAX_EVENT_LENGTH', 5*24*60*60); // 5 days.
/**#@+
* Options for navigation method within quizzes.
@@ -138,7 +138,7 @@ function quiz_update_instance($quiz, $mform) {
quiz_update_grades($quiz);
}
// Delete any previous preview attempts
// Delete any previous preview attempts.
quiz_delete_previews($quiz);
return true;
@@ -187,7 +187,7 @@ function quiz_delete_override($quiz, $overrideid) {
$override = $DB->get_record('quiz_overrides', array('id' => $overrideid), '*', MUST_EXIST);
// Delete the events
// Delete the events.
$events = $DB->get_records('event', array('modulename' => 'quiz',
'instance' => $quiz->id, 'groupid' => (int)$override->groupid,
'userid' => (int)$override->userid));
@@ -232,7 +232,7 @@ function quiz_delete_all_overrides($quiz) {
function quiz_update_effective_access($quiz, $userid) {
global $DB;
// check for user override
// Check for user override.
$override = $DB->get_record('quiz_overrides', array('quiz' => $quiz->id, 'userid' => $userid));
if (!$override) {
@@ -244,18 +244,18 @@ function quiz_update_effective_access($quiz, $userid) {
$override->password = null;
}
// check for group overrides
// Check for group overrides.
$groupings = groups_get_user_groups($quiz->course, $userid);
if (!empty($groupings[0])) {
// Select all overrides that apply to the User's groups
// Select all overrides that apply to the User's groups.
list($extra, $params) = $DB->get_in_or_equal(array_values($groupings[0]));
$sql = "SELECT * FROM {quiz_overrides}
WHERE groupid $extra AND quiz = ?";
$params[] = $quiz->id;
$records = $DB->get_records_sql($sql, $params);
// Combine the overrides
// Combine the overrides.
$opens = array();
$closes = array();
$limits = array();
@@ -279,7 +279,7 @@ function quiz_update_effective_access($quiz, $userid) {
$passwords[] = $gpoverride->password;
}
}
// If there is a user override for a setting, ignore the group override
// If there is a user override for a setting, ignore the group override.
if (is_null($override->timeopen) && count($opens)) {
$override->timeopen = min($opens);
}
@@ -301,7 +301,7 @@ function quiz_update_effective_access($quiz, $userid) {
}
// merge with quiz defaults
// Merge with quiz defaults.
$keys = array('timeopen', 'timeclose', 'timelimit', 'attempts', 'password', 'extrapasswords');
foreach ($keys as $key) {
if (isset($override->{$key})) {
@@ -385,10 +385,10 @@ function quiz_user_outline($course, $user, $mod, $quiz) {
$result = new stdClass();
$result->info = get_string('grade') . ': ' . $grade->str_long_grade;
//datesubmitted == time created. dategraded == time modified or time overridden
//if grade was last modified by the user themselves use date graded. Otherwise use
// date submitted
// TODO: move this copied & pasted code somewhere in the grades API. See MDL-26704
// Datesubmitted == time created. dategraded == time modified or time overridden
// if grade was last modified by the user themselves use date graded. Otherwise use
// date submitted.
// TODO: move this copied & pasted code somewhere in the grades API. See MDL-26704.
if ($grade->usermodified == $user->id || empty($grade->datesubmitted)) {
$result->time = $grade->dategraded;
} else {
@@ -631,7 +631,7 @@ function quiz_upgrade_grades() {
$i=0;
foreach ($rs as $quiz) {
$i++;
upgrade_set_timeout(60*5); // set up timeout, may also abort execution
upgrade_set_timeout(60*5); // Set up timeout, may also abort execution.
quiz_update_grades($quiz, 0, false);
$pbar->update($i, $count, "Updating Quiz grades ($i/$count).");
}
@@ -652,7 +652,7 @@ function quiz_grade_item_update($quiz, $grades = null) {
require_once($CFG->dirroot . '/mod/quiz/locallib.php');
require_once($CFG->libdir.'/gradelib.php');
if (array_key_exists('cmidnumber', $quiz)) { // may not be always present
if (array_key_exists('cmidnumber', $quiz)) { // May not be always present.
$params = array('itemname' => $quiz->name, 'idnumber' => $quiz->cmidnumber);
} else {
$params = array('itemname' => $quiz->name);
@@ -667,7 +667,7 @@ function quiz_grade_item_update($quiz, $grades = null) {
$params['gradetype'] = GRADE_TYPE_NONE;
}
// description by TJ:
// What this is trying to do:
// 1. If the quiz is set to not show grades while the quiz is still open,
// and is set to show grades after the quiz is closed, then create the
// grade_item with a show-after date that is the quiz close date.
@@ -691,9 +691,10 @@ function quiz_grade_item_update($quiz, $grades = null) {
}
} else {
// Either
// a) both open and closed enabled
// b) open enabled, closed disabled - we can not "hide after",
// grades are kept visible even after closing
// grades are kept visible even after closing.
$params['hidden'] = 0;
}
@@ -706,7 +707,7 @@ function quiz_grade_item_update($quiz, $grades = null) {
if (!empty($gradebook_grades->items)) {
$grade_item = $gradebook_grades->items[0];
if ($grade_item->locked) {
// NOTE: this is an extremely nasty hack! It is not a bug if this confirmation fails badly. --skodak
// NOTE: this is an extremely nasty hack! It is not a bug if this confirmation fails badly. --skodak.
$confirm_regrade = optional_param('confirm_regrade', 0, PARAM_INT);
if (!$confirm_regrade) {
$message = get_string('gradeitemislocked', 'grades');
@@ -851,7 +852,7 @@ function quiz_get_recent_mod_activity(&$activities, &$index, $timestart,
$groupmode = groups_get_activity_groupmode($cm, $course);
if (is_null($modinfo->groups)) {
// load all my groups and cache it in modinfo
// Load all my groups and cache it in modinfo.
$modinfo->groups = groups_get_user_groups($course->id);
}
@@ -860,7 +861,7 @@ function quiz_get_recent_mod_activity(&$activities, &$index, $timestart,
foreach ($attempts as $attempt) {
if ($attempt->userid != $USER->id) {
if (!$grader) {
// Grade permission required
// Grade permission required.
continue;
}
@@ -974,7 +975,7 @@ function quiz_process_options($quiz) {
$quiz->password = $quiz->quizpassword;
unset($quiz->quizpassword);
// Quiz feedback
// Quiz feedback.
if (isset($quiz->feedbacktext)) {
// Clean up the boundary text.
for ($i = 0; $i < count($quiz->feedbacktext); $i += 1) {
@@ -1078,11 +1079,11 @@ function quiz_after_add_or_update($quiz) {
global $DB;
$cmid = $quiz->coursemodule;
// we need to use context now, so we need to make sure all needed info is already in db
// We need to use context now, so we need to make sure all needed info is already in db.
$DB->set_field('course_modules', 'instance', $quiz->id, array('id'=>$cmid));
$context = get_context_instance(CONTEXT_MODULE, $cmid);
// Save the feedback
// Save the feedback.
$DB->delete_records('quiz_feedback', array('quizid' => $quiz->id));
for ($i = 0; $i <= $quiz->feedbackboundarycount; $i++) {
@@ -1107,7 +1108,7 @@ function quiz_after_add_or_update($quiz) {
// Update the events relating to this quiz.
quiz_update_events($quiz);
//update related grade item
// Update related grade item.
quiz_grade_item_update($quiz);
}
@@ -1127,21 +1128,21 @@ function quiz_update_events($quiz, $override = null) {
$conds = array('modulename'=>'quiz',
'instance'=>$quiz->id);
if (!empty($override)) {
// only load events for this override
// Only load events for this override.
$conds['groupid'] = isset($override->groupid)? $override->groupid : 0;
$conds['userid'] = isset($override->userid)? $override->userid : 0;
}
$oldevents = $DB->get_records('event', $conds);
// Now make a todo list of all that needs to be updated
// Now make a todo list of all that needs to be updated.
if (empty($override)) {
// We are updating the primary settings for the quiz, so we
// need to add all the overrides
// need to add all the overrides.
$overrides = $DB->get_records('quiz_overrides', array('quiz' => $quiz->id));
// as well as the original quiz (empty override)
// As well as the original quiz (empty override).
$overrides[] = new stdClass();
} else {
// Just do the one override
// Just do the one override.
$overrides = array($override);
}
@@ -1151,13 +1152,13 @@ function quiz_update_events($quiz, $override = null) {
$timeopen = isset($current->timeopen)? $current->timeopen : $quiz->timeopen;
$timeclose = isset($current->timeclose)? $current->timeclose : $quiz->timeclose;
// only add open/close events for an override if they differ from the quiz default
// Only add open/close events for an override if they differ from the quiz default.
$addopen = empty($current->id) || !empty($current->timeopen);
$addclose = empty($current->id) || !empty($current->timeclose);
$event = new stdClass();
$event->description = $quiz->intro;
// Events module won't show user events when the courseid is nonzero
// Events module won't show user events when the courseid is nonzero.
$event->courseid = ($userid) ? 0 : $quiz->course;
$event->groupid = $groupid;
$event->userid = $userid;
@@ -1168,13 +1169,13 @@ function quiz_update_events($quiz, $override = null) {
$event->visible = instance_is_visible('quiz', $quiz);
$event->eventtype = 'open';
// Determine the event name
// Determine the event name.
if ($groupid) {
$params = new stdClass();
$params->quiz = $quiz->name;
$params->group = groups_get_group_name($groupid);
if ($params->group === false) {
// group doesn't exist, just skip it
// Group doesn't exist, just skip it.
continue;
}
$eventname = get_string('overridegroupeventname', 'quiz', $params);
@@ -1194,7 +1195,7 @@ function quiz_update_events($quiz, $override = null) {
unset($event->id);
}
$event->name = $eventname;
// calendar_event::create will reuse a db record if the id field is set
// The method calendar_event::create will reuse a db record if the id field is set.
calendar_event::create($event);
} else {
// Separate start and end events.
@@ -1206,7 +1207,7 @@ function quiz_update_events($quiz, $override = null) {
unset($event->id);
}
$event->name = $eventname.' ('.get_string('quizopens', 'quiz').')';
// calendar_event::create will reuse a db record if the id field is set
// The method calendar_event::create will reuse a db record if the id field is set.
calendar_event::create($event);
}
if ($timeclose && $addclose) {
@@ -1224,7 +1225,7 @@ function quiz_update_events($quiz, $override = null) {
}
}
// Delete any leftover events
// Delete any leftover events.
foreach ($oldevents as $badevent) {
$badevent = calendar_event::load($badevent);
$badevent->delete();
@@ -1334,7 +1335,7 @@ function quiz_reset_userdata($data) {
'item' => get_string('attemptsdeleted', 'quiz'),
'error' => false);
// Remove all grades from gradebook
// Remove all grades from gradebook.
$DB->delete_records_select('quiz_grades',
'quiz IN (SELECT id FROM {quiz} WHERE course = ?)', array($data->courseid));
if (empty($data->reset_gradebook_grades)) {
@@ -1346,7 +1347,7 @@ function quiz_reset_userdata($data) {
'error' => false);
}
// Updating dates - shift may be negative too
// Updating dates - shift may be negative too.
if ($data->timeshift) {
shift_course_mod_dates('quiz', array('timeopen', 'timeclose'),
$data->timeshift, $data->courseid);
@@ -1375,7 +1376,7 @@ function quiz_check_file_access($attemptuniqueid, $questionid, $context = null)
$attempt = $DB->get_record('quiz_attempts', array('uniqueid' => $attemptuniqueid));
$attemptobj = quiz_attempt::create($attempt->id);
// does question exist?
// Does the question exist?
if (!$question = $DB->get_record('question', array('id' => $questionid))) {
return false;
}
@@ -1390,16 +1391,16 @@ function quiz_check_file_access($attemptuniqueid, $questionid, $context = null)
$attemptobj->load_questions(array($questionid));
$attemptobj->load_question_states(array($questionid));
// obtain state
// Obtain the state.
$state = $attemptobj->get_question_state($questionid);
// obtain questoin
// Obtain the question.
$question = $attemptobj->get_question($questionid);
// access granted if the current user submitted this file
// Access granted if the current user submitted this file.
if ($attempt->userid != $USER->id) {
return false;
}
// access granted if the current user has permission to grade quizzes in this course
// Access granted if the current user has permission to grade quizzes in this course.
if (!(has_capability('mod/quiz:viewreports', $context) ||
has_capability('mod/quiz:grade', $context))) {
return false;
@@ -1415,7 +1416,7 @@ function quiz_check_file_access($attemptuniqueid, $questionid, $context = null)
*/
function quiz_print_overview($courses, &$htmlarray) {
global $USER, $CFG;
// These next 6 Lines are constant in all modules (just change module name)
// These next 6 Lines are constant in all modules (just change module name).
if (empty($courses) || !is_array($courses) || count($courses) == 0) {
return array();
}
@@ -1634,10 +1635,8 @@ function quiz_extend_navigation($quiznode, $course, $module, $cm) {
function quiz_extend_settings_navigation($settings, $quiznode) {
global $PAGE, $CFG;
/**
* Require {@link questionlib.php}
* Included here as we only ever want to include this file if we really need to.
*/
// Require {@link questionlib.php}
// Included here as we only ever want to include this file if we really need to.
require_once($CFG->libdir . '/questionlib.php');
// We want to add these new nodes after the Edit settings node, and before the
@@ -1711,7 +1710,7 @@ function quiz_pluginfile($course, $cm, $context, $filearea, $args, $forcedownloa
return false;
}
// 'intro' area is served by pluginfile.php
// The 'intro' area is served by pluginfile.php.
$fileareas = array('feedback');
if (!in_array($filearea, $fileareas)) {
return false;
+29 -29
View File
@@ -43,7 +43,7 @@ require_once($CFG->libdir . '/filelib.php');
/**
* We show the countdown timer if there is less than this amount of time left before the
* @var int We show the countdown timer if there is less than this amount of time left before the
* the quiz close date. (1 hour)
*/
define('QUIZ_SHOW_TIME_BEFORE_DEADLINE', '3600');
@@ -56,7 +56,7 @@ define('QUIZ_SHOW_TIME_BEFORE_DEADLINE', '3600');
define('QUIZ_MIN_TIME_TO_CONTINUE', '2');
/// Functions related to attempts /////////////////////////////////////////
// Functions related to attempts ///////////////////////////////////////////////
/**
* Creates an object to represent a new attempt at a quiz
@@ -158,7 +158,7 @@ function quiz_delete_attempt($attempt, $quiz) {
// Search quiz_attempts for other instances by this user.
// If none, then delete record for this quiz, this user from quiz_grades
// else recalculate best grade
// else recalculate best grade.
$userid = $attempt->userid;
if (!$DB->record_exists('quiz_attempts', array('userid' => $userid, 'quiz' => $quiz->id))) {
$DB->delete_records('quiz_grades', array('userid' => $userid, 'quiz' => $quiz->id));
@@ -196,7 +196,7 @@ function quiz_has_attempts($quizid) {
return $DB->record_exists('quiz_attempts', array('quiz' => $quizid, 'preview' => 0));
}
/// Functions to do with quiz layout and pages ////////////////////////////////
// Functions to do with quiz layout and pages //////////////////////////////////
/**
* Returns a comma separated list of question ids for the quiz
@@ -277,7 +277,7 @@ function quiz_repaginate($layout, $perpage, $shuffle = false) {
return implode(',', $layout);
}
/// Functions to do with quiz grades //////////////////////////////////////////
// Functions to do with quiz grades ////////////////////////////////////////////
/**
* Creates an array of maximum grades for a quiz
@@ -500,7 +500,7 @@ function quiz_set_grade($newgrade, $quiz) {
", array($factor, $factor, $quiz->id));
}
// update grade item and send all grades to gradebook
// Update grade item and send all grades to gradebook.
quiz_grade_item_update($quiz);
quiz_update_grades($quiz);
@@ -526,15 +526,15 @@ function quiz_save_best_grade($quiz, $userid = null, $attempts = array()) {
}
if (!$attempts) {
// Get all the attempts made by the user
// Get all the attempts made by the user.
$attempts = quiz_get_user_attempts($quiz->id, $userid);
}
// Calculate the best grade
// Calculate the best grade.
$bestgrade = quiz_calculate_best_grade($quiz, $attempts);
$bestgrade = quiz_rescale_grade($bestgrade, $quiz, false);
// Save the best grade in the database
// Save the best grade in the database.
if (is_null($bestgrade)) {
$DB->delete_records('quiz_grades', array('quiz' => $quiz->id, 'userid' => $userid));
@@ -768,7 +768,7 @@ function quiz_calculate_best_attempt($quiz, $attempts) {
}
break;
case QUIZ_GRADEAVERAGE: // need to do something with it :-)
case QUIZ_GRADEAVERAGE: // We need to do something with it.
case QUIZ_ATTEMPTLAST:
foreach ($attempts as $attempt) {
$final = $attempt;
@@ -842,7 +842,7 @@ function quiz_attempt_state_name($state) {
}
}
/// Other quiz functions ////////////////////////////////////////////////////
// Other quiz functions ////////////////////////////////////////////////////////
/**
* @param object $quiz the quiz.
@@ -1013,7 +1013,7 @@ function quiz_get_review_options($quiz, $attempt, $context) {
array('attempt' => $attempt->id));
}
// Show a link to the comment box only for closed attempts
// Show a link to the comment box only for closed attempts.
if (!empty($attempt->id) && $attempt->state == quiz_attempt::FINISHED && !$attempt->preview &&
!is_null($context) && has_capability('mod/quiz:grade', $context)) {
$options->manualcomment = question_display_options::VISIBLE;
@@ -1096,7 +1096,7 @@ function quiz_clean_layout($layout, $removeemptypages = false) {
// id to relink to.
$layout = preg_replace('/,{2,}/', ',', trim($layout, ','));
// Remove duplicate question ids
// Remove duplicate question ids.
$layout = explode(',', $layout);
$cleanerlayout = array();
$seen = array();
@@ -1110,7 +1110,7 @@ function quiz_clean_layout($layout, $removeemptypages = false) {
}
if ($removeemptypages) {
// Avoid duplicate page breaks
// Avoid duplicate page breaks.
$layout = $cleanerlayout;
$cleanerlayout = array();
$stripfollowingbreaks = true; // Ensure breaks are stripped from the start.
@@ -1123,7 +1123,7 @@ function quiz_clean_layout($layout, $removeemptypages = false) {
}
}
// Add a page break at the end if there is none
// Add a page break at the end if there is none.
if (end($cleanerlayout) !== '0') {
$cleanerlayout[] = '0';
}
@@ -1147,7 +1147,7 @@ function quiz_get_slot_for_question($quiz, $questionid) {
return null;
}
/// FUNCTIONS FOR SENDING NOTIFICATION MESSAGES ///////////////////////////////
// Functions for sending notification messages /////////////////////////////////
/**
* Sends a confirmation message to the student confirming that the attempt was processed.
@@ -1159,12 +1159,12 @@ function quiz_get_slot_for_question($quiz, $questionid) {
*/
function quiz_send_confirmation($recipient, $a) {
// Add information about the recipient to $a
// Add information about the recipient to $a.
// Don't do idnumber. we want idnumber to be the submitter's idnumber.
$a->username = fullname($recipient);
$a->userusername = $recipient->username;
// Prepare message
// Prepare the message.
$eventdata = new stdClass();
$eventdata->component = 'mod_quiz';
$eventdata->name = 'confirmation';
@@ -1195,12 +1195,12 @@ function quiz_send_confirmation($recipient, $a) {
*/
function quiz_send_notification($recipient, $submitter, $a) {
// Recipient info for template
// Recipient info for template.
$a->useridnumber = $recipient->idnumber;
$a->username = fullname($recipient);
$a->userusername = $recipient->username;
// Prepare message
// Prepare the message.
$eventdata = new stdClass();
$eventdata->component = 'mod_quiz';
$eventdata->name = 'submission';
@@ -1235,14 +1235,14 @@ function quiz_send_notification($recipient, $submitter, $a) {
function quiz_send_notification_messages($course, $quiz, $attempt, $context, $cm) {
global $CFG, $DB;
// Do nothing if required objects not present
// Do nothing if required objects not present.
if (empty($course) or empty($quiz) or empty($attempt) or empty($context)) {
throw new coding_exception('$course, $quiz, $attempt, $context and $cm must all be set.');
}
$submitter = $DB->get_record('user', array('id' => $attempt->userid), '*', MUST_EXIST);
// Check for confirmation required
// Check for confirmation required.
$sendconfirm = false;
$notifyexcludeusers = '';
if (has_capability('mod/quiz:emailconfirmsubmission', $context, $submitter, false)) {
@@ -1250,7 +1250,7 @@ function quiz_send_notification_messages($course, $quiz, $attempt, $context, $cm
$sendconfirm = true;
}
// check for notifications required
// Check for notifications required.
$notifyfields = 'u.id, u.username, u.firstname, u.lastname, u.idnumber, u.email, u.emailstop, ' .
'u.lang, u.timezone, u.mailformat, u.maildisplay';
$groups = groups_get_all_groups($course->id, $submitter->id);
@@ -1272,30 +1272,30 @@ function quiz_send_notification_messages($course, $quiz, $attempt, $context, $cm
}
$a = new stdClass();
// Course info
// Course info.
$a->coursename = $course->fullname;
$a->courseshortname = $course->shortname;
// Quiz info
// Quiz info.
$a->quizname = $quiz->name;
$a->quizreporturl = $CFG->wwwroot . '/mod/quiz/report.php?id=' . $cm->id;
$a->quizreportlink = '<a href="' . $a->quizreporturl . '">' .
format_string($quiz->name) . ' report</a>';
$a->quizurl = $CFG->wwwroot . '/mod/quiz/view.php?id=' . $cm->id;
$a->quizlink = '<a href="' . $a->quizurl . '">' . format_string($quiz->name) . '</a>';
// Attempt info
// Attempt info.
$a->submissiontime = userdate($attempt->timefinish);
$a->timetaken = format_time($attempt->timefinish - $attempt->timestart);
$a->quizreviewurl = $CFG->wwwroot . '/mod/quiz/review.php?attempt=' . $attempt->id;
$a->quizreviewlink = '<a href="' . $a->quizreviewurl . '">' .
format_string($quiz->name) . ' review</a>';
// Student who sat the quiz info
// Student who sat the quiz info.
$a->studentidnumber = $submitter->idnumber;
$a->studentname = fullname($submitter);
$a->studentusername = $submitter->username;
$allok = true;
// Send notifications if required
// Send notifications if required.
if (!empty($userstonotify)) {
foreach ($userstonotify as $recipient) {
$allok = $allok && quiz_send_notification($recipient, $submitter, $a);
@@ -1325,7 +1325,7 @@ function quiz_send_notification_messages($course, $quiz, $attempt, $context, $cm
function quiz_send_overdue_message($course, $quiz, $attempt, $context, $cm) {
global $CFG, $DB;
// Do nothing if required objects not present
// Do nothing if required objects not present.
if (empty($course) or empty($quiz) or empty($attempt) or empty($context)) {
throw new coding_exception('$course, $quiz, $attempt, $context and $cm must all be set.');
}
+22 -23
View File
@@ -58,7 +58,7 @@ class mod_quiz_mod_form extends moodleform_mod {
$quizconfig = get_config('quiz');
$mform = $this->_form;
//-------------------------------------------------------------------------------
// -------------------------------------------------------------------------------
$mform->addElement('header', 'general', get_string('general', 'form'));
// Name.
@@ -73,7 +73,7 @@ class mod_quiz_mod_form extends moodleform_mod {
// Introduction.
$this->add_intro_editor(false, get_string('introduction', 'quiz'));
//-------------------------------------------------------------------------------
// -------------------------------------------------------------------------------
$mform->addElement('header', 'timing', get_string('timing', 'quiz'));
// Open and close dates.
@@ -108,8 +108,8 @@ class mod_quiz_mod_form extends moodleform_mod {
$mform->setDefault('graceperiod', $quizconfig->graceperiod);
$mform->disabledIf('graceperiod', 'overduehandling', 'neq', 'graceperiod');
//-------------------------------------------------------------------------------
// Grade settings
// -------------------------------------------------------------------------------
// Grade settings.
$this->standard_grading_coursemodule_elements();
$mform->removeElement('grade');
@@ -134,7 +134,7 @@ class mod_quiz_mod_form extends moodleform_mod {
$mform->setDefault('grademethod', $quizconfig->grademethod);
$mform->disabledIf('grademethod', 'attempts', 'eq', 1);
//-------------------------------------------------------------------------------
// -------------------------------------------------------------------------------
$mform->addElement('header', 'layouthdr', get_string('layout', 'quiz'));
// Shuffle questions.
@@ -174,14 +174,14 @@ class mod_quiz_mod_form extends moodleform_mod {
$mform->addHelpButton('questionsperpagegrp', 'newpage', 'quiz');
$mform->setAdvanced('questionsperpagegrp', $quizconfig->questionsperpage_adv);
// Navigation method
// Navigation method.
$mform->addElement('select', 'navmethod', get_string('navmethod', 'quiz'),
quiz_get_navigation_options());
$mform->addHelpButton('navmethod', 'navmethod', 'quiz');
$mform->setAdvanced('navmethod', $quizconfig->navmethod_adv);
$mform->setDefault('navmethod', $quizconfig->navmethod);
//-------------------------------------------------------------------------------
// -------------------------------------------------------------------------------
$mform->addElement('header', 'interactionhdr', get_string('questionbehaviour', 'quiz'));
// Shuffle within questions.
@@ -210,7 +210,7 @@ class mod_quiz_mod_form extends moodleform_mod {
$mform->setDefault('attemptonlast', $quizconfig->attemptonlast);
$mform->disabledIf('attemptonlast', 'attempts', 'eq', 1);
//-------------------------------------------------------------------------------
// -------------------------------------------------------------------------------
$mform->addElement('header', 'reviewoptionshdr',
get_string('reviewoptionsheading', 'quiz'));
$mform->addHelpButton('reviewoptionshdr', 'reviewoptionsheading', 'quiz');
@@ -237,7 +237,7 @@ class mod_quiz_mod_form extends moodleform_mod {
$mform->disabledIf('overallfeedbackduring', 'preferredbehaviour',
'neq', 'wontmatch');
//-------------------------------------------------------------------------------
// -------------------------------------------------------------------------------
$mform->addElement('header', 'display', get_string('display', 'form'));
// Show user picture.
@@ -269,13 +269,13 @@ class mod_quiz_mod_form extends moodleform_mod {
$mform->setAdvanced('questiondecimalpoints', $quizconfig->questiondecimalpoints_adv);
$mform->setDefault('questiondecimalpoints', $quizconfig->questiondecimalpoints);
// Show blocks during quiz attempt
// Show blocks during quiz attempt.
$mform->addElement('selectyesno', 'showblocks', get_string('showblocks', 'quiz'));
$mform->addHelpButton('showblocks', 'showblocks', 'quiz');
$mform->setAdvanced('showblocks', $quizconfig->showblocks_adv);
$mform->setDefault('showblocks', $quizconfig->showblocks);
//-------------------------------------------------------------------------------
// -------------------------------------------------------------------------------
$mform->addElement('header', 'security', get_string('extraattemptrestrictions', 'quiz'));
// Require password to begin quiz attempt.
@@ -308,7 +308,7 @@ class mod_quiz_mod_form extends moodleform_mod {
$mform->disabledIf('delay2', 'attempts', 'eq', 1);
$mform->disabledIf('delay2', 'attempts', 'eq', 2);
// 'Secure' window.
// Browser security choices.
$mform->addElement('select', 'browsersecurity', get_string('browsersecurity', 'quiz'),
quiz_access_manager::get_browser_security_choices());
$mform->addHelpButton('browsersecurity', 'browsersecurity', 'quiz');
@@ -318,7 +318,7 @@ class mod_quiz_mod_form extends moodleform_mod {
// Any other rule plugins.
quiz_access_manager::add_settings_form_fields($this, $mform);
//-------------------------------------------------------------------------------
// -------------------------------------------------------------------------------
$mform->addElement('header', 'overallfeedbackhdr', get_string('overallfeedback', 'quiz'));
$mform->addHelpButton('overallfeedbackhdr', 'overallfeedback', 'quiz');
@@ -357,7 +357,7 @@ class mod_quiz_mod_form extends moodleform_mod {
$repeatedoptions, 'boundary_repeats', 'boundary_add_fields', 3,
get_string('addmoreoverallfeedbacks', 'quiz'), true);
// Put some extra elements in before the button
// Put some extra elements in before the button.
$mform->insertElementBefore($mform->createElement('editor',
"feedbacktext[$nextel]", get_string('feedback', 'quiz'), null,
array('maxfiles' => EDITOR_UNLIMITED_FILES, 'noclean' => true,
@@ -374,11 +374,10 @@ class mod_quiz_mod_form extends moodleform_mod {
$mform->disabledIf('feedbacktext[' . ($i + 1) . ']', 'grade', 'eq', 0);
}
//-------------------------------------------------------------------------------
// -------------------------------------------------------------------------------
$this->standard_coursemodule_elements();
//-------------------------------------------------------------------------------
// buttons
// -------------------------------------------------------------------------------
$this->add_action_buttons();
}
@@ -435,13 +434,13 @@ class mod_quiz_mod_form extends moodleform_mod {
foreach ($this->_feedbacks as $feedback) {
$draftid = file_get_submitted_draft_itemid('feedbacktext['.$key.']');
$toform['feedbacktext['.$key.']']['text'] = file_prepare_draft_area(
$draftid, // draftid
$this->context->id, // context
'mod_quiz', // component
'feedback', // filarea
!empty($feedback->id) ? (int) $feedback->id : null, // itemid
$draftid, // Draftid.
$this->context->id, // Context.
'mod_quiz', // Component.
'feedback', // Filarea.
!empty($feedback->id) ? (int) $feedback->id : null, // Itemid.
null,
$feedback->feedbacktext // text
$feedback->feedbacktext // Text.
);
$toform['feedbacktext['.$key.']']['format'] = $feedback->feedbacktextformat;
$toform['feedbacktext['.$key.']']['itemid'] = $draftid;
+40 -21
View File
@@ -37,13 +37,33 @@ require_once($CFG->libdir . '/formslib.php');
*/
class quiz_override_form extends moodleform {
protected $cm; // course module object
protected $quiz; // quiz object
protected $context; // context object
protected $groupmode; // editing group override (true) or user override (false)
protected $groupid; // groupid, if provided
protected $userid; // userid, if provided
/** @var object course module object. */
protected $cm;
/** @var object the quiz settings object. */
protected $quiz;
/** @var context the quiz context. */
protected $context;
/** @var bool editing group override (true) or user override (false). */
protected $groupmode;
/** @var int groupid, if provided. */
protected $groupid;
/** @var int userid, if provided. */
protected $userid;
/**
* Constructor.
* @param moodle_url $submiturl the form action URL.
* @param object course module object.
* @param object the quiz settings object.
* @param context the quiz context.
* @param bool editing group override (true) or user override (false).
* @param object $override the override being edited, if it already exists.
*/
public function __construct($submiturl, $cm, $quiz, $context, $groupmode, $override) {
$this->cm = $cm;
@@ -66,19 +86,19 @@ class quiz_override_form extends moodleform {
$mform->addElement('header', 'override', get_string('override', 'quiz'));
if ($this->groupmode) {
// group override
// Group override.
if ($this->groupid) {
// There is already a groupid, so freeze the selector
// There is already a groupid, so freeze the selector.
$groupchoices = array();
$groupchoices[$this->groupid] = groups_get_group_name($this->groupid);
$mform->addElement('select', 'groupid',
get_string('overridegroup', 'quiz'), $groupchoices);
$mform->freeze('groupid');
} else {
// Prepare the list of groups
// Prepare the list of groups.
$groups = groups_get_all_groups($cm->course);
if (empty($groups)) {
// generate an error
// Generate an error.
$link = new moodle_url('/mod/quiz/overrides.php', array('cmid'=>$cm->id));
print_error('groupsnone', 'quiz', $link);
}
@@ -98,9 +118,9 @@ class quiz_override_form extends moodleform {
$mform->addRule('groupid', get_string('required'), 'required', null, 'client');
}
} else {
//user override
// User override.
if ($this->userid) {
// There is already a userid, so freeze the selector
// There is already a userid, so freeze the selector.
$user = $DB->get_record('user', array('id'=>$this->userid));
$userchoices = array();
$userchoices[$this->userid] = fullname($user);
@@ -108,10 +128,10 @@ class quiz_override_form extends moodleform {
get_string('overrideuser', 'quiz'), $userchoices);
$mform->freeze('userid');
} else {
// Prepare the list of users
// Prepare the list of users.
$users = array();
if (!empty($CFG->enablegroupmembersonly) && $cm->groupmembersonly) {
// only users from the grouping
// Only users from the grouping.
$groups = groups_get_all_groups($cm->course, 0, $cm->groupingid);
if (!empty($groups)) {
$users = get_users_by_capability($this->context, 'mod/quiz:attempt',
@@ -125,7 +145,7 @@ class quiz_override_form extends moodleform {
'firstname ASC, lastname ASC', '', '', '', '', false, true);
}
if (empty($users)) {
// generate an error
// Generate an error.
$link = new moodle_url('/mod/quiz/overrides.php', array('cmid'=>$cm->id));
print_error('usersnone', 'quiz', $link);
}
@@ -148,9 +168,9 @@ class quiz_override_form extends moodleform {
}
}
// Password
// Password.
// This field has to be above the date and timelimit fields,
// otherwise browsers will clear it when those fields are changed
// otherwise browsers will clear it when those fields are changed.
$mform->addElement('passwordunmask', 'password', get_string('requirepassword', 'quiz'));
$mform->setType('password', PARAM_TEXT);
$mform->addHelpButton('password', 'requirepassword', 'quiz');
@@ -180,7 +200,7 @@ class quiz_override_form extends moodleform {
get_string('attemptsallowed', 'quiz'), $attemptoptions);
$mform->setDefault('attempts', $this->quiz->attempts);
// Submit buttons
// Submit buttons.
$mform->addElement('submit', 'resetbutton',
get_string('reverttodefaults', 'quiz'));
@@ -196,7 +216,6 @@ class quiz_override_form extends moodleform {
}
// form verification
public function validation($data, $files) {
global $COURSE, $DB;
$errors = parent::validation($data, $files);
@@ -216,14 +235,14 @@ class quiz_override_form extends moodleform {
}
}
// Ensure that the dates make sense
// Ensure that the dates make sense.
if (!empty($data['timeopen']) && !empty($data['timeclose'])) {
if ($data['timeclose'] < $data['timeopen'] ) {
$errors['timeclose'] = get_string('closebeforeopen', 'quiz');
}
}
// Ensure that at least one quiz setting was changed
// Ensure that at least one quiz setting was changed.
$changed = false;
$keys = array('timeopen', 'timeclose', 'timelimit', 'attempts', 'password');
foreach ($keys as $key) {
+6 -10
View File
@@ -17,8 +17,7 @@
/**
* This page handles deleting quiz overrides
*
* @package mod
* @subpackage quiz
* @package mod_quiz
* @copyright 2010 Matt Petro
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@@ -29,8 +28,8 @@ require_once($CFG->dirroot.'/mod/quiz/lib.php');
require_once($CFG->dirroot.'/mod/quiz/locallib.php');
require_once($CFG->dirroot.'/mod/quiz/override_form.php');
$overrideid = required_param('id', PARAM_INT); // override ID
$confirm = optional_param('confirm', false, PARAM_BOOL); // already confirmed?
$overrideid = required_param('id', PARAM_INT);
$confirm = optional_param('confirm', false, PARAM_BOOL);
if (! $override = $DB->get_record('quiz_overrides', array('id' => $overrideid))) {
print_error('invalidoverrideid', 'quiz');
@@ -47,7 +46,7 @@ $context = get_context_instance(CONTEXT_MODULE, $cm->id);
require_login($course, false, $cm);
// Check the user has the required capabilities to modify an override
// Check the user has the required capabilities to modify an override.
require_capability('mod/quiz:manageoverrides', $context);
$url = new moodle_url('/mod/quiz/overridedelete.php', array('id'=>$override->id));
@@ -58,22 +57,19 @@ if (!empty($override->userid)) {
$cancelurl->param('mode', 'user');
}
// If confirm is set (PARAM_BOOL) then we have confirmation of intention to delete
// If confirm is set (PARAM_BOOL) then we have confirmation of intention to delete.
if ($confirm) {
// Confirm the session key to stop CSRF
require_sesskey();
// Remove the override
quiz_delete_override($quiz, $override->id);
add_to_log($cm->course, 'quiz', 'delete override',
"overrides.php?cmid=$cm->id", $quiz->id, $cm->id);
// And redirect
redirect($cancelurl);
}
// Prepare the page to show the confirmation form
// Prepare the page to show the confirmation form.
$stroverride = get_string('override', 'quiz');
$title = get_string('deletecheck', null, $stroverride);
+15 -17
View File
@@ -76,19 +76,18 @@ require_login($course, false, $cm);
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
// Add or edit an override
// Add or edit an override.
require_capability('mod/quiz:manageoverrides', $context);
if ($overrideid) {
// editing override
// Editing an override.
$data = clone $override;
} else {
// new override
// Creating a new override.
$data = new stdClass();
}
// merge quiz defaults with data
// Merge quiz defaults with data.
$keys = array('timeopen', 'timeclose', 'timelimit', 'attempts', 'password');
foreach ($keys as $key) {
if (!isset($data->{$key}) || $reset) {
@@ -104,7 +103,7 @@ if ($action === 'duplicate') {
$override->groupid = null;
}
// true if group-based override
// True if group-based override.
$groupmode = !empty($data->groupid) || ($action === 'addgroup' && empty($overrideid));
$overridelisturl = new moodle_url('/mod/quiz/overrides.php', array('cmid'=>$cm->id));
@@ -117,24 +116,24 @@ $mform = new quiz_override_form($url, $cm, $quiz, $context, $groupmode, $overrid
$mform->set_data($data);
if ($mform->is_cancelled()) {
// redirect back to override list
redirect($overridelisturl);
} else if (optional_param('resetbutton', 0, PARAM_ALPHA)) {
// redirect back to current page and reset the form.
$url->param('reset', true);
redirect($url);
} else if ($fromform = $mform->get_data()) {
// Process the data
// Process the data.
$fromform->quiz = $quiz->id;
// Replace unchanged values with null
// Replace unchanged values with null.
foreach ($keys as $key) {
if ($fromform->{$key} == $quiz->{$key}) {
$fromform->{$key} = null;
}
}
// See if we are replacing an existing override
// See if we are replacing an existing override.
$userorgroupchanged = false;
if (empty($override->id)) {
$userorgroupchanged = true;
@@ -143,6 +142,7 @@ if ($mform->is_cancelled()) {
} else {
$userorgroupchanged = $fromform->groupid !== $override->groupid;
}
if ($userorgroupchanged) {
$conditions = array(
'quiz' => $quiz->id,
@@ -150,13 +150,13 @@ if ($mform->is_cancelled()) {
'groupid' => empty($fromform->groupid)? null : $fromform->groupid);
if ($oldoverride = $DB->get_record('quiz_overrides', $conditions)) {
// There is an old override, so we merge any new settings on top of
// the older override
// the older override.
foreach ($keys as $key) {
if (is_null($fromform->{$key})) {
$fromform->{$key} = $oldoverride->{$key};
}
}
// Delete the old override
// Delete the old override.
$DB->delete_records('quiz_overrides', array('id' => $oldoverride->id));
}
}
@@ -175,11 +175,10 @@ if ($mform->is_cancelled()) {
"overrideedit.php?id=$fromform->id", $quiz->id, $cm->id);
if (!empty($fromform->submitbutton)) {
// redirect back to override list
redirect($overridelisturl);
}
// 'again' button pressed, so redirect back to this page
// The user pressed the 'again' button, so redirect back to this page.
$url->remove_params('cmid');
$url->param('action', 'duplicate');
$url->param('id', $fromform->id);
@@ -187,8 +186,7 @@ if ($mform->is_cancelled()) {
}
// Print the form
// Print the form.
$pagetitle = get_string('editoverride', 'quiz');
$PAGE->navbar->add($pagetitle);
$PAGE->set_pagelayout('admin');
+30 -34
View File
@@ -17,8 +17,7 @@
/**
* This page handles listing of quiz overrides
*
* @package mod
* @subpackage quiz
* @package mod_quiz
* @copyright 2010 Matt Petro
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@@ -30,8 +29,8 @@ require_once($CFG->dirroot.'/mod/quiz/locallib.php');
require_once($CFG->dirroot.'/mod/quiz/override_form.php');
$cmid = required_param('cmid', PARAM_INT); // course module ID, or
$mode = optional_param('mode', '', PARAM_ALPHA); // one of 'user' or 'group', default is 'group'
$cmid = required_param('cmid', PARAM_INT);
$mode = optional_param('mode', '', PARAM_ALPHA); // One of 'user' or 'group', default is 'group'.
if (! $cm = get_coursemodule_from_id('quiz', $cmid)) {
print_error('invalidcoursemodule');
@@ -41,13 +40,13 @@ if (! $quiz = $DB->get_record('quiz', array('id' => $cm->instance))) {
}
$course = $DB->get_record('course', array('id'=>$cm->course), '*', MUST_EXIST);
// Get the course groups
// Get the course groups.
$groups = groups_get_all_groups($cm->course);
if ($groups === false) {
$groups = array();
}
// Default mode is "group", unless there are no groups
// Default mode is "group", unless there are no groups.
if ($mode != "user" and $mode != "group") {
if (!empty($groups)) {
$mode = "group";
@@ -65,17 +64,16 @@ require_login($course, false, $cm);
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
// Check the user has the required capabilities to list overrides
// Check the user has the required capabilities to list overrides.
require_capability('mod/quiz:manageoverrides', $context);
// Display a list of overrides
// Display a list of overrides.
$PAGE->set_pagelayout('admin');
$PAGE->set_title(get_string('overrides', 'quiz'));
$PAGE->set_heading($course->fullname);
echo $OUTPUT->header();
// Delete orphaned group overrides
// Delete orphaned group overrides.
$sql = 'SELECT o.id
FROM {quiz_overrides} o LEFT JOIN {groups} g
ON o.groupid = g.id
@@ -88,7 +86,7 @@ if (!empty($orphaned)) {
$DB->delete_records_list('quiz_overrides', 'id', array_keys($orphaned));
}
// Fetch all overrides
// Fetch all overrides.
if ($groupmode) {
$colname = get_string('group');
$sql = 'SELECT o.*, g.name
@@ -108,7 +106,7 @@ if ($groupmode) {
$params = array($quiz->id);
$overrides = $DB->get_records_sql($sql, $params);
// Initialise table
// Initialise table.
$table = new html_table();
$table->headspan = array(1, 2, 1);
$table->colclasses = array('colname', 'colsetting', 'colvalue', 'colaction');
@@ -124,7 +122,7 @@ $groupurl = new moodle_url('/group/overview.php', array('id' => $cm->course));
$overridedeleteurl = new moodle_url('/mod/quiz/overridedelete.php');
$overrideediturl = new moodle_url('/mod/quiz/overrideedit.php');
$hasinactive = false; // are there any inactive overrides
$hasinactive = false; // Whether there are any inactive overrides.
foreach ($overrides as $override) {
@@ -132,71 +130,70 @@ foreach ($overrides as $override) {
$values = array();
$active = true;
// check for inactive overrides
// Check for inactive overrides.
if (!$groupmode) {
if (!has_capability('mod/quiz:attempt', $context, $override->userid)) {
// user not allowed to take the quiz
// User not allowed to take the quiz.
$active = false;
} else if (!empty($CFG->enablegroupmembersonly) && $cm->groupmembersonly &&
!groups_has_membership($cm, $override->userid)) {
// user does not belong to the current grouping
// User does not belong to the current grouping.
$active = false;
}
}
// Format timeopen
// Format timeopen.
if (isset($override->timeopen)) {
$fields[] = get_string('quizopens', 'quiz');
$values[] = $override->timeopen > 0 ?
userdate($override->timeopen) : get_string('noopen', 'quiz');
}
// Format timeclose
// Format timeclose.
if (isset($override->timeclose)) {
$fields[] = get_string('quizcloses', 'quiz');
$values[] = $override->timeclose > 0 ?
userdate($override->timeclose) : get_string('noclose', 'quiz');
}
// Format timelimit
// Format timelimit.
if (isset($override->timelimit)) {
$fields[] = get_string('timelimit', 'quiz');
$values[] = $override->timelimit > 0 ?
format_time($override->timelimit) : get_string('none', 'quiz');
}
// Format number of attempts
// Format number of attempts.
if (isset($override->attempts)) {
$fields[] = get_string('attempts', 'quiz');
$values[] = $override->attempts > 0 ?
$override->attempts : get_string('unlimited');
}
// Format password
// Format password.
if (isset($override->password)) {
$fields[] = get_string('requirepassword', 'quiz');
$values[] = $override->password !== '' ?
get_string('enabled', 'quiz') : get_string('none', 'quiz');
}
// Icons:
// Icons.
$iconstr = '';
if ($active) {
// edit
// Edit.
$editurlstr = $overrideediturl->out(true, array('id' => $override->id));
$iconstr = '<a title="' . get_string('edit') . '" href="'. $editurlstr . '">' .
'<img src="' . $OUTPUT->pix_url('t/edit') . '" class="iconsmall" alt="' .
get_string('edit') . '" /></a> ';
// duplicate
// Duplicate.
$copyurlstr = $overrideediturl->out(true,
array('id' => $override->id, 'action' => 'duplicate'));
$iconstr .= '<a title="' . get_string('copy') . '" href="' . $copyurlstr . '">' .
'<img src="' . $OUTPUT->pix_url('t/copy') . '" class="iconsmall" alt="' .
get_string('copy') . '" /></a> ';
}
// delete
// Delete.
$deleteurlstr = $overridedeleteurl->out(true,
array('id' => $override->id, 'sesskey' => sesskey()));
$iconstr .= '<a title="' . get_string('delete') . '" href="' . $deleteurlstr . '">' .
@@ -244,8 +241,7 @@ foreach ($overrides as $override) {
}
}
// Output the table and button
// Output the table and button.
echo html_writer::start_tag('div', array('id' => 'quizoverrides'));
if (count($table->data)) {
echo html_writer::table($table);
@@ -258,7 +254,7 @@ echo html_writer::start_tag('div', array('class' => 'buttons'));
$options = array();
if ($groupmode) {
if (empty($groups)) {
// there are no groups
// There are no groups.
echo $OUTPUT->notification(get_string('groupsnone', 'quiz'), 'error');
$options['disabled'] = true;
}
@@ -267,13 +263,13 @@ if ($groupmode) {
get_string('addnewgroupoverride', 'quiz'), 'post', $options);
} else {
$users = array();
// See if there are any students in the quiz
// See if there are any students in the quiz.
if (!empty($CFG->enablegroupmembersonly) && $cm->groupmembersonly) {
// restrict to grouping
// Restrict to grouping.
$limitgroups = groups_get_all_groups($cm->course, 0, $cm->groupingid);
if (!empty($limitgroups)) {
$users = get_users_by_capability($context, 'mod/quiz:attempt', 'u.id',
'', '', 1, array_keys($limitgroups)); // Limit to one user for speed
'', '', 1, array_keys($limitgroups)); // Limit to one user for speed.
}
} else {
// Limit to one user for speed.
@@ -281,7 +277,7 @@ if ($groupmode) {
}
if (empty($users)) {
// there are no students
// There are no students.
echo $OUTPUT->notification(get_string('usersnone', 'quiz'), 'error');
$options['disabled'] = true;
}
@@ -292,5 +288,5 @@ if ($groupmode) {
echo html_writer::end_tag('div');
echo html_writer::end_tag('div');
// Finish the page
// Finish the page.
echo $OUTPUT->footer();
+1 -1
View File
@@ -33,7 +33,7 @@ require_once(dirname(__FILE__) . '/../../config.php');
require_once($CFG->dirroot . '/mod/quiz/locallib.php');
// Remember the current time as the time any responses were submitted
// (so as to make sure students don't get penalized for slow processing on this page)
// (so as to make sure students don't get penalized for slow processing on this page).
$timenow = time();
// Get submitted parameters.
+11 -10
View File
@@ -435,14 +435,14 @@ class mod_quiz_renderer extends plugin_renderer_base {
public function attempt_form($attemptobj, $page, $slots, $id, $nextpage) {
$output = '';
//Start Form
// Start the form.
$output .= html_writer::start_tag('form',
array('action' => $attemptobj->processattempt_url(), 'method' => 'post',
'enctype' => 'multipart/form-data', 'accept-charset' => 'utf-8',
'id' => 'responseform'));
$output .= html_writer::start_tag('div');
// Print all the questions
// Print all the questions.
foreach ($slots as $slot) {
$output .= $attemptobj->render_question($slot, false,
$attemptobj->attempt_url($slot, $page));
@@ -473,7 +473,7 @@ class mod_quiz_renderer extends plugin_renderer_base {
$output .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'slots',
'value' => implode(',', $slots)));
//Finish form
// Finish the form.
$output .= html_writer::end_tag('div');
$output .= html_writer::end_tag('form');
@@ -560,7 +560,7 @@ class mod_quiz_renderer extends plugin_renderer_base {
* @param mod_quiz_display_options $displayoptions
*/
public function summary_table($attemptobj, $displayoptions) {
// Prepare the summary table header
// Prepare the summary table header.
$table = new html_table();
$table->attributes['class'] = 'generaltable quizsummaryofattempt boxaligncenter';
$table->head = array(get_string('question', 'quiz'), get_string('status', 'quiz'));
@@ -590,7 +590,8 @@ class mod_quiz_renderer extends plugin_renderer_base {
$attemptobj->get_question_number($slot) . $flag),
$attemptobj->get_question_status($slot, $displayoptions->correctness));
} else {
$row = array($attemptobj->get_question_number($slot) . $flag, $attemptobj->get_question_status($slot, $displayoptions->correctness));
$row = array($attemptobj->get_question_number($slot) . $flag,
$attemptobj->get_question_status($slot, $displayoptions->correctness));
}
if ($markscolumn) {
$row[] = $attemptobj->get_question_mark($slot);
@@ -614,7 +615,7 @@ class mod_quiz_renderer extends plugin_renderer_base {
public function summary_page_controls($attemptobj) {
$output = '';
// Return to place button
// Return to place button.
if ($attemptobj->get_state() == quiz_attempt::IN_PROGRESS) {
$button = new single_button(
new moodle_url($attemptobj->attempt_url(null, $attemptobj->get_currentpage())),
@@ -827,7 +828,7 @@ class mod_quiz_renderer extends plugin_renderer_base {
global $CFG;
$output = '';
// Print quiz name and description
// Print quiz name and description.
$output .= $this->heading(format_string($quiz->name));
if (trim(strip_tags($quiz->intro))) {
$output .= $this->box(format_module_intro('quiz', $quiz, $cm->id), 'generalbox',
@@ -882,7 +883,7 @@ class mod_quiz_renderer extends plugin_renderer_base {
return '';
}
// Prepare table header
// Prepare table header.
$table = new html_table();
$table->attributes['class'] = 'generaltable quizattemptsummary';
$table->head = array();
@@ -919,7 +920,7 @@ class mod_quiz_renderer extends plugin_renderer_base {
$table->size[] = '';
}
// One row for each attempt
// One row for each attempt.
foreach ($viewobj->attemptobjs as $attemptobj) {
$attemptoptions = $attemptobj->get_display_options(true);
$row = array();
@@ -951,7 +952,7 @@ class mod_quiz_renderer extends plugin_renderer_base {
if ($attemptoptions->marks >= question_display_options::MARK_AND_MAX &&
$attemptobj->is_finished()) {
// Highlight the highest grade if appropriate
// Highlight the highest grade if appropriate.
if ($viewobj->overallstats && !$attemptobj->is_preview()
&& $viewobj->numattempts > 1 && !is_null($viewobj->mygrade)
&& $attemptgrade == $viewobj->mygrade
+2 -2
View File
@@ -86,7 +86,7 @@ if (!is_readable("report/$mode/report.php")) {
add_to_log($course->id, 'quiz', 'report', 'report.php?id=' . $cm->id . '&mode=' . $mode,
$quiz->id, $cm->id);
// Open the selected quiz report and display it
// Open the selected quiz report and display it.
$file = $CFG->dirroot . '/mod/quiz/report/' . $mode . '/report.php';
if (is_readable($file)) {
include_once($file);
@@ -99,5 +99,5 @@ if (!class_exists($reportclassname)) {
$report = new $reportclassname();
$report->display($quiz, $cm, $course);
// Print footer
// Print footer.
echo $OUTPUT->footer();
@@ -66,7 +66,7 @@ class quiz_statistics_question_stats_testcase extends basic_testcase {
// contrib/tools/generators/qagenerator/.
$steps = $this->get_records_from_csv(__DIR__.'/fixtures/mdl_question_states.csv');
// Data is taken from questions mostly generated by
// contrib/tools/generators/generator.php
// contrib/tools/generators/generator.php.
$questions = $this->get_records_from_csv(__DIR__.'/fixtures/mdl_question.csv');
$this->qstats = new testable_quiz_statistics_question_stats($questions, 22, 10045.45455);
$this->qstats->set_step_data($steps);
+4 -4
View File
@@ -86,7 +86,7 @@ if ($options->flags == question_display_options::EDITABLE && optional_param('sav
add_to_log($attemptobj->get_courseid(), 'quiz', 'review', 'review.php?attempt=' .
$attemptobj->get_attemptid(), $attemptobj->get_quizid(), $attemptobj->get_cmid());
// Work out appropriate title and whether blocks should be shown
// Work out appropriate title and whether blocks should be shown.
if ($attemptobj->is_preview_user() && $attemptobj->is_own_attempt()) {
$strreviewtitle = get_string('reviewofpreview', 'quiz');
navigation_node::override_active_url($attemptobj->start_attempt_url());
@@ -98,13 +98,13 @@ if ($attemptobj->is_preview_user() && $attemptobj->is_own_attempt()) {
}
}
// Set up the page header
// Set up the page header.
$headtags = $attemptobj->get_html_head_contributions($page, $showall);
$PAGE->set_title(format_string($attemptobj->get_quiz_name()));
$PAGE->set_heading($attemptobj->get_course()->fullname);
$accessmanager->setup_attempt_page($PAGE);
// Summary table start ============================================================================
// Summary table start. ============================================================================
// Work out some time-related things.
$attempt = $attemptobj->get_attempt();
@@ -235,7 +235,7 @@ if ($options->overallfeedback && $feedback) {
);
}
// Summary table end ==============================================================================
// Summary table end. ==============================================================================
if ($showall) {
$slots = $attemptobj->get_slots();
+3 -3
View File
@@ -28,9 +28,9 @@
require_once(dirname(__FILE__) . '/../../config.php');
require_once('locallib.php');
$attemptid = required_param('attempt', PARAM_INT); // attempt id
$slot = required_param('slot', PARAM_INT); // question number in usage
$seq = optional_param('step', null, PARAM_INT); // sequence number
$attemptid = required_param('attempt', PARAM_INT);
$slot = required_param('slot', PARAM_INT);
$seq = optional_param('step', null, PARAM_INT);
$baseurl = new moodle_url('/mod/quiz/reviewquestion.php',
array('attempt' => $attemptid, 'slot' => $slot));
+12 -12
View File
@@ -50,7 +50,7 @@ $quizsettings = new admin_settingpage('modsettingquiz', $pagetitle, 'moodle/site
// Introductory explanation that all the settings are defaults for the add quiz form.
$quizsettings->add(new admin_setting_heading('quizintro', '', get_string('configintro', 'quiz')));
// Time limit
// Time limit.
$quizsettings->add(new admin_setting_configtext_with_advanced('quiz/timelimit',
get_string('timelimitsec', 'quiz'), get_string('configtimelimitsec', 'quiz'),
array('value' => '0', 'fix' => false), PARAM_INT));
@@ -70,7 +70,7 @@ $quizsettings->add(new admin_setting_configtext('quiz/graceperiodmin',
get_string('graceperiodmin', 'quiz'), get_string('graceperiodmin_desc', 'quiz'),
60, PARAM_INT));
// Number of attempts
// Number of attempts.
$options = array(get_string('unlimited'));
for ($i = 1; $i <= QUIZ_MAX_ATTEMPT_OPTION; $i++) {
$options[$i] = $i;
@@ -84,16 +84,16 @@ $quizsettings->add(new mod_quiz_admin_setting_grademethod('quiz/grademethod',
get_string('grademethod', 'quiz'), get_string('configgrademethod', 'quiz'),
array('value' => QUIZ_GRADEHIGHEST, 'fix' => false), null));
// Maximum grade
// Maximum grade.
$quizsettings->add(new admin_setting_configtext('quiz/maximumgrade',
get_string('maximumgrade'), get_string('configmaximumgrade', 'quiz'), 10, PARAM_INT));
// Shuffle questions
// Shuffle questions.
$quizsettings->add(new admin_setting_configcheckbox_with_advanced('quiz/shufflequestions',
get_string('shufflequestions', 'quiz'), get_string('configshufflequestions', 'quiz'),
array('value' => 0, 'adv' => false)));
// Questions per page
// Questions per page.
$perpage = array();
$perpage[0] = get_string('never');
$perpage[1] = get_string('aftereachquestion', 'quiz');
@@ -104,12 +104,12 @@ $quizsettings->add(new admin_setting_configselect_with_advanced('quiz/questionsp
get_string('newpageevery', 'quiz'), get_string('confignewpageevery', 'quiz'),
array('value' => 1, 'fix' => false), $perpage));
// Navigation method
// Navigation method.
$quizsettings->add(new admin_setting_configselect_with_advanced('quiz/navmethod',
get_string('navmethod', 'quiz'), get_string('confignavmethod', 'quiz'),
array('value' => QUIZ_NAVMETHOD_FREE, 'adv' => true), quiz_get_navigation_options()));
// Shuffle within questions
// Shuffle within questions.
$quizsettings->add(new admin_setting_configcheckbox_with_advanced('quiz/shuffleanswers',
get_string('shufflewithin', 'quiz'), get_string('configshufflewithin', 'quiz'),
array('value' => 1, 'adv' => false)));
@@ -141,7 +141,7 @@ foreach (mod_quiz_admin_review_setting::fields() as $field => $name) {
$name, '', $default, $forceduring));
}
// Show the user's picture
// Show the user's picture.
$quizsettings->add(new admin_setting_configcheckbox_with_advanced('quiz/showuserpicture',
get_string('showuserpicture', 'quiz'), get_string('configshowuserpicture', 'quiz'),
array('value' => 0, 'adv' => false)));
@@ -165,7 +165,7 @@ $quizsettings->add(new admin_setting_configselect_with_advanced('quiz/questionde
get_string('configdecimalplacesquestion', 'quiz'),
array('value' => -1, 'fix' => true), $options));
// Show blocks during quiz attempts
// Show blocks during quiz attempts.
$quizsettings->add(new admin_setting_configcheckbox_with_advanced('quiz/showblocks',
get_string('showblocks', 'quiz'), get_string('configshowblocks', 'quiz'),
array('value' => 0, 'adv' => true)));
@@ -188,7 +188,7 @@ $quizsettings->add(new admin_setting_configtext_with_advanced('quiz/delay2',
get_string('delaylater', 'quiz'), get_string('configdelaylater', 'quiz'),
array('value' => 0, 'fix' => true), PARAM_INTEGER));
// 'Secure' window.
// Browser security.
$quizsettings->add(new mod_quiz_admin_setting_browsersecurity('quiz/browsersecurity',
get_string('showinsecurepopup', 'quiz'), get_string('configpopup', 'quiz'),
array('value' => '-', 'adv' => true), null));
@@ -202,7 +202,7 @@ if (empty($reportsbyname)) {
get_string('modulename', 'quiz'), !$module->visible));
$ADMIN->add('modsettingsquizcat', $quizsettings);
// Add the report pages for the settings.php files in sub directories of mod/quiz/report
// Add the report pages for the settings.php files in sub directories of mod/quiz/report.
foreach ($reportsbyname as $strreportname => $report) {
$reportname = $report;
@@ -215,4 +215,4 @@ if (empty($reportsbyname)) {
}
}
$settings = null; // we do not want standard settings link
$settings = null; // We do not want standard settings link.
+4 -4
View File
@@ -49,7 +49,7 @@ $PAGE->set_url($quizobj->view_url());
require_login($quizobj->get_course(), false, $quizobj->get_cm());
require_sesskey();
// if no questions have been set up yet redirect to edit.php or display an error.
// If no questions have been set up yet redirect to edit.php or display an error.
if (!$quizobj->has_questions()) {
if ($quizobj->has_capability('mod/quiz:manage')) {
redirect($quizobj->edit_url());
@@ -73,7 +73,7 @@ if (!$quizobj->is_preview_user()) {
// Check to see if a new preview was requested.
if ($quizobj->is_preview_user() && $forcenew) {
// To force the creation of a new preview, we mark the current attempt (if any)
// as finished. It will then automatically be deleted below
// as finished. It will then automatically be deleted below.
$DB->set_field('quiz_attempts', 'state', quiz_attempt::FINISHED,
array('quiz' => $quizobj->get_quizid(), 'userid' => $USER->id));
}
@@ -104,7 +104,7 @@ if ($lastattempt && ($lastattempt->state == quiz_attempt::IN_PROGRESS ||
}
} else {
// Get number for the next or unfinished attempt
// Get number for the next or unfinished attempt.
if ($lastattempt && !$lastattempt->preview && !$quizobj->is_preview_user()) {
$attemptnumber = $lastattempt->attempt + 1;
} else {
@@ -259,7 +259,7 @@ if ($attempt->preview) {
$quizobj->get_quizid(), $quizobj->get_cmid());
}
// Trigger event
// Trigger event.
$eventdata = new stdClass();
$eventdata->component = 'mod_quiz';
$eventdata->attemptid = $attempt->id;
+3 -3
View File
@@ -25,7 +25,7 @@
defined('MOODLE_INTERNAL') || die();
$module->version = 2012040206; // The current module version (Date: YYYYMMDDXX)
$module->requires = 2012030100.04; // Requires this Moodle version
$module->component = 'mod_quiz'; // Full name of the plugin (used for diagnostics)
$module->version = 2012040206; // The current module version (Date: YYYYMMDDXX).
$module->requires = 2012030100.04; // Requires this Moodle version.
$module->component = 'mod_quiz'; // Full name of the plugin (used for diagnostics).
$module->cron = 60;
+4 -4
View File
@@ -30,8 +30,8 @@ require_once($CFG->libdir.'/gradelib.php');
require_once($CFG->dirroot.'/mod/quiz/locallib.php');
require_once($CFG->libdir . '/completionlib.php');
$id = optional_param('id', 0, PARAM_INT); // Course Module ID, or
$q = optional_param('q', 0, PARAM_INT); // quiz ID
$id = optional_param('id', 0, PARAM_INT); // Course Module ID, or ...
$q = optional_param('q', 0, PARAM_INT); // Quiz ID.
if ($id) {
if (!$cm = get_coursemodule_from_id('quiz', $id)) {
@@ -75,7 +75,7 @@ add_to_log($course->id, 'quiz', 'view', 'view.php?id=' . $cm->id, $quiz->id, $cm
$completion = new completion_info($course);
$completion->set_module_viewed($cm);
// Initialize $PAGE, compute blocks
// Initialize $PAGE, compute blocks.
$PAGE->set_url('/mod/quiz/view.php', array('id' => $cm->id));
// Create view object which collects all the information the renderer will need.
@@ -144,7 +144,7 @@ $PAGE->set_title($title);
$PAGE->set_heading($course->fullname);
$output = $PAGE->get_renderer('mod_quiz');
// Print table with existing attempts
// Print table with existing attempts.
if ($attempts) {
// Work out which columns we need, taking account what data is available in each attempt.
list($someoptions, $alloptions) = quiz_get_combined_reviewoptions($quiz, $attempts, $context);