mirror of
https://github.com/moodle/moodle.git
synced 2025-08-06 17:36:38 +02:00
quiz: MDL-16478 Allow different open/close dates, etc. for individual students or groups.
This was implemented by Matt Petro of the University of Wisconsin - Madison Engineering School and Math Department. Many thanks. Reviewed by and committed by Tim Hunt. This adds a new Overrides tab to the UI, with sub-tabs Group overrides and User overrides. Each of those lists all the overrides that currently exist, and lets you manage them and create more. When a quiz is being attempted, the override that applies to the current user is combined with the current quiz settings loaded from the quiz table (normally called $quiz). If there are both user and group overrides, then just the specific user override is used (more specific). If the user is in several groups, then the overrides are combined to give the most permissive set of options. There is one new database table quiz_overrides, to store the overrides.
This commit is contained in:
parent
cdede6fbfe
commit
990650f94c
25 changed files with 1309 additions and 127 deletions
|
@ -90,6 +90,32 @@ class quiz {
|
|||
$this->determine_layout();
|
||||
}
|
||||
|
||||
/**
|
||||
* Static function to create a new quiz object for a specific user.
|
||||
*
|
||||
* @param integer $quizid the the quiz id.
|
||||
* @param integer $userid the the userid.
|
||||
* @return object the new quiz object
|
||||
*/
|
||||
static public function create($quizid, $userid) {
|
||||
global $DB;
|
||||
|
||||
if (!$quiz = $DB->get_record('quiz', array('id' => $quizid))) {
|
||||
throw new moodle_exception('invalidquizid', 'quiz');
|
||||
}
|
||||
if (!$course = $DB->get_record('course', array('id' => $quiz->course))) {
|
||||
throw new moodle_exception('invalidcoursemodule');
|
||||
}
|
||||
if (!$cm = get_coursemodule_from_instance('quiz', $quiz->id, $course->id)) {
|
||||
throw new moodle_exception('invalidcoursemodule');
|
||||
}
|
||||
|
||||
// Update quiz with override information
|
||||
$quiz = quiz_update_effective_access($quiz, $userid);
|
||||
|
||||
return new quiz($quiz, $cm, $course);
|
||||
}
|
||||
|
||||
// Functions for loading more data =====================================================
|
||||
/**
|
||||
* Convenience method. Calls {@link load_questions()} with the list of
|
||||
|
@ -418,17 +444,33 @@ class quiz_attempt extends quiz {
|
|||
|
||||
// Constructor =========================================================================
|
||||
/**
|
||||
* Constructor from just an attemptid.
|
||||
* Constructor assuming we already have the necessary data loaded.
|
||||
*
|
||||
* @param integer $attemptid the id of the attempt to load. We automatically load the
|
||||
* associated quiz, course, etc.
|
||||
* @param object $attempt the row of the quiz_attempts table.
|
||||
* @param object $quiz the quiz object for this attempt and user.
|
||||
* @param object $cm the course_module object for this quiz.
|
||||
* @param object $course the row from the course table for the course we belong to.
|
||||
*/
|
||||
function __construct($attemptid) {
|
||||
function __construct($attempt, $quiz, $cm, $course) {
|
||||
$this->attempt = $attempt;
|
||||
parent::__construct($quiz, $cm, $course);
|
||||
$this->preload_questions();
|
||||
$this->preload_question_states();
|
||||
}
|
||||
|
||||
/**
|
||||
* Static function to create a new quiz_attempt object given an attemptid.
|
||||
*
|
||||
* @param integer $attemptid the attempt id.
|
||||
* @return object the new quiz_attempt object
|
||||
*/
|
||||
static public function create($attemptid) {
|
||||
global $DB;
|
||||
if (!$this->attempt = quiz_load_attempt($attemptid)) {
|
||||
|
||||
if (!$attempt = quiz_load_attempt($attemptid)) {
|
||||
throw new moodle_exception('invalidattemptid', 'quiz');
|
||||
}
|
||||
if (!$quiz = $DB->get_record('quiz', array('id' => $this->attempt->quiz))) {
|
||||
if (!$quiz = $DB->get_record('quiz', array('id' => $attempt->quiz))) {
|
||||
throw new moodle_exception('invalidquizid', 'quiz');
|
||||
}
|
||||
if (!$course = $DB->get_record('course', array('id' => $quiz->course))) {
|
||||
|
@ -437,9 +479,10 @@ class quiz_attempt extends quiz {
|
|||
if (!$cm = get_coursemodule_from_instance('quiz', $quiz->id, $course->id)) {
|
||||
throw new moodle_exception('invalidcoursemodule');
|
||||
}
|
||||
parent::__construct($quiz, $cm, $course);
|
||||
$this->preload_questions();
|
||||
$this->preload_question_states();
|
||||
// Update quiz with override information
|
||||
$quiz = quiz_update_effective_access($quiz, $attempt->userid);
|
||||
|
||||
return new quiz_attempt($attempt, $quiz, $cm, $course);
|
||||
}
|
||||
|
||||
// Functions for loading more data =====================================================
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue