$newcm = duplicate_module($course, get_fast_modinfo($course)->get_cm($quiz->cmid));
- $sql = "SELECT qa.answer
+ $sql = "SELECT qa.id, qa.answer
FROM {quiz} q
LEFT JOIN {quiz_slots} qs ON qs.quizid = q.id
LEFT JOIN {question_answers} qa ON qa.question = qs.questionid
WHERE q.id = :quizid";
$params = array('quizid' => $newcm->instance);
- $answers = $DB->get_fieldset_sql($sql, $params);
- $this->assertEquals($CFG->wwwroot . '/course/view.php?id=' . $course->id, $answers[0]);
- $this->assertEquals($CFG->wwwroot . '/mod/quiz/view.php?id=' . $quiz->cmid, $answers[1]);
- $this->assertEquals($CFG->wwwroot . '/grade/report/index.php?id=' . $quiz->cmid, $answers[2]);
- $this->assertEquals($CFG->wwwroot . '/mod/quiz/index.php?id=' . $quiz->cmid, $answers[3]);
+ $answers = $DB->get_records_sql_menu($sql, $params);
+
+ $this->assertEquals($CFG->wwwroot . '/course/view.php?id=' . $course->id, $answers[$firstanswer->id]);
+ $this->assertEquals($CFG->wwwroot . '/mod/quiz/view.php?id=' . $quiz->cmid, $answers[$secondanswer->id]);
+ $this->assertEquals($CFG->wwwroot . '/grade/report/index.php?id=' . $quiz->cmid, $answers[$thirdanswer->id]);
+ $this->assertEquals($CFG->wwwroot . '/mod/quiz/index.php?id=' . $quiz->cmid, $answers[$fourthanswer->id]);
}
}
// Filter out all pagination options which are too large for the amount of courses user is enrolled in.
var totalCourseCount = parseInt(root.find(Selectors.courseView.region).attr('data-totalcoursecount'), 10);
- if (totalCourseCount) {
- itemsPerPage = itemsPerPage.filter(function(pagingOption) {
- return pagingOption.value < totalCourseCount;
- });
- }
+ itemsPerPage = itemsPerPage.filter(function(pagingOption) {
+ return pagingOption.value < totalCourseCount || pagingOption.value === 0;
+ });
var filters = getFilterValues(root);
var config = $.extend({}, DEFAULT_PAGED_CONTENT_CONFIG);
pageCourses = $.merge(loadedPages[currentPage].courses, courses.slice(0, nextPageStart));
}
} else {
- nextPageStart = pageData.limit;
+ // When the page limit is zero, there is only one page of courses, no start for next page.
+ nextPageStart = pageData.limit || false;
pageCourses = (pageData.limit > 0) ? courses.slice(0, pageData.limit) : courses;
}
courses: pageCourses
};
- // Set up the next page
- var remainingCourses = nextPageStart ? courses.slice(nextPageStart, courses.length) : [];
+ // Set up the next page (if there is more than one page).
+ var remainingCourses = nextPageStart !== false ? courses.slice(nextPageStart, courses.length) : [];
if (remainingCourses.length) {
loadedPages[currentPage + 1] = {
courses: remainingCourses
// Check and remember the given view.
$this->view = $view ? $view : BLOCK_MYOVERVIEW_VIEW_CARD;
- // Check and remember the given page size.
- if ($paging == BLOCK_MYOVERVIEW_PAGING_ALL) {
+ // Check and remember the given page size, `null` indicates no page size set
+ // while a `0` indicates a paging size of `All`.
+ if (!is_null($paging) && $paging == BLOCK_MYOVERVIEW_PAGING_ALL) {
$this->paging = BLOCK_MYOVERVIEW_PAGING_ALL;
} else {
$this->paging = $paging ? $paging : BLOCK_MYOVERVIEW_PAGING_12;
| student1 | Student | X | student1@example.com | S1 |
And the following "courses" exist:
| fullname | shortname | category |
- | Course 1 | C1 | 0 |
- | Course 2 | C2 | 0 |
- | Course 3 | C3 | 0 |
- | Course 4 | C4 | 0 |
- | Course 5 | C5 | 0 |
- | Course 6 | C6 | 0 |
- | Course 7 | C7 | 0 |
- | Course 8 | C8 | 0 |
- | Course 9 | C9 | 0 |
+ | Course 1 | C01 | 0 |
+ | Course 2 | C02 | 0 |
+ | Course 3 | C03 | 0 |
+ | Course 4 | C04 | 0 |
+ | Course 5 | C05 | 0 |
+ | Course 6 | C06 | 0 |
+ | Course 7 | C07 | 0 |
+ | Course 8 | C08 | 0 |
+ | Course 9 | C09 | 0 |
| Course 10 | C10 | 0 |
| Course 11 | C11 | 0 |
| Course 12 | C12 | 0 |
| Course 13 | C13 | 0 |
And the following "course enrolments" exist:
| user | course | role |
- | student1 | C1 | student |
- | student1 | C2 | student |
- | student1 | C3 | student |
- | student1 | C4 | student |
- | student1 | C5 | student |
- | student1 | C6 | student |
- | student1 | C7 | student |
- | student1 | C8 | student |
- | student1 | C9 | student |
+ | student1 | C01 | student |
+ | student1 | C02 | student |
+ | student1 | C03 | student |
+ | student1 | C04 | student |
+ | student1 | C05 | student |
+ | student1 | C06 | student |
+ | student1 | C07 | student |
+ | student1 | C08 | student |
+ | student1 | C09 | student |
| student1 | C10 | student |
| student1 | C11 | student |
| student1 | C12 | student |
Scenario: Toggle the page limit between page reloads
Given I log in as "student1"
- When I click on "[data-toggle='dropdown']" "css_element" in the "Course overview" "block"
- And I click on "All" "link"
+ When I click on "[data-action='limit-toggle']" "css_element" in the "Course overview" "block"
+ And I click on "All" "link" in the ".dropdown-menu.show" "css_element"
Then I should see "Course 13"
And I reload the page
Then I should see "Course 13"
Scenario: Toggle the page limit between grouping changes
Given I log in as "student1"
- When I click on "[data-toggle='dropdown']" "css_element" in the "Course overview" "block"
- And I click on "All" "link"
+ When I click on "[data-action='limit-toggle']" "css_element" in the "Course overview" "block"
+ And I click on "All" "link" in the ".dropdown-menu.show" "css_element"
And I click on "All (except removed from view)" "button" in the "Course overview" "block"
And I click on "In progress" "link" in the "Course overview" "block"
Then I should see "Course 13"
--- /dev/null
+@block @block_myoverview @javascript
+Feature: My overview block pagination
+
+ Background:
+ Given the following "users" exist:
+ | username | firstname | lastname | email | idnumber |
+ | student1 | Student | X | student1@example.com | S1 |
+ And the following "courses" exist:
+ | fullname | shortname | category |
+ | Course 01 | C1 | 0 |
+ | Course 02 | C2 | 0 |
+ | Course 03 | C3 | 0 |
+ | Course 04 | C4 | 0 |
+ | Course 05 | C5 | 0 |
+ | Course 06 | C6 | 0 |
+ | Course 07 | C7 | 0 |
+ | Course 08 | C8 | 0 |
+ | Course 09 | C9 | 0 |
+ | Course 10 | C10 | 0 |
+ | Course 11 | C11 | 0 |
+ | Course 12 | C12 | 0 |
+ | Course 13 | C13 | 0 |
+ | Course 14 | C14 | 0 |
+ | Course 15 | C15 | 0 |
+ | Course 16 | C16 | 0 |
+ | Course 17 | C17 | 0 |
+ | Course 18 | C18 | 0 |
+ | Course 19 | C19 | 0 |
+ | Course 20 | C20 | 0 |
+ | Course 21 | C21 | 0 |
+ | Course 22 | C22 | 0 |
+ | Course 23 | C23 | 0 |
+ | Course 24 | C24 | 0 |
+ | Course 25 | C25 | 0 |
+
+ Scenario: The pagination controls should be hidden if I am not enrolled in any courses
+ When I log in as "student1"
+ Then I should see "No courses" in the "Course overview" "block"
+ And I should not see "Show" in the "Course overview" "block"
+ And ".block_myoverview .dropdown-menu.show" "css_element" should not be visible
+ And ".block_myoverview [data-control='next']" "css_element" should not be visible
+ And ".block_myoverview [data-control='previous']" "css_element" should not be visible
+ And I log out
+
+ Scenario: The pagination controls should be hidden if I am enrolled in 12 courses or less
+ Given the following "course enrolments" exist:
+ | user | course | role |
+ | student1 | C1 | student |
+ | student1 | C2 | student |
+ | student1 | C3 | student |
+ | student1 | C4 | student |
+ | student1 | C5 | student |
+ | student1 | C6 | student |
+ | student1 | C7 | student |
+ | student1 | C8 | student |
+ | student1 | C9 | student |
+ | student1 | C10 | student |
+ | student1 | C11 | student |
+ | student1 | C12 | student |
+ When I log in as "student1"
+ Then I should not see "Show" in the "Course overview" "block"
+ And ".block_myoverview .dropdown-menu.show" "css_element" should not be visible
+ And ".block_myoverview [data-control='next']" "css_element" should not be visible
+ And ".block_myoverview [data-control='previous']" "css_element" should not be visible
+ And I log out
+
+ Scenario: The default pagination should be 12 courses
+ Given the following "course enrolments" exist:
+ | user | course | role |
+ | student1 | C1 | student |
+ | student1 | C2 | student |
+ | student1 | C3 | student |
+ | student1 | C4 | student |
+ | student1 | C5 | student |
+ | student1 | C6 | student |
+ | student1 | C7 | student |
+ | student1 | C8 | student |
+ | student1 | C9 | student |
+ | student1 | C10 | student |
+ | student1 | C11 | student |
+ | student1 | C12 | student |
+ | student1 | C13 | student |
+ When I log in as "student1"
+ Then I should see "12" in the "[data-action='limit-toggle']" "css_element"
+ And I log out
+
+ Scenario: I should only see pagination limit options less than total number of enrolled courses
+ Given the following "course enrolments" exist:
+ | user | course | role |
+ | student1 | C1 | student |
+ | student1 | C2 | student |
+ | student1 | C3 | student |
+ | student1 | C4 | student |
+ | student1 | C5 | student |
+ | student1 | C6 | student |
+ | student1 | C7 | student |
+ | student1 | C8 | student |
+ | student1 | C9 | student |
+ | student1 | C10 | student |
+ | student1 | C11 | student |
+ | student1 | C12 | student |
+ | student1 | C13 | student |
+ And I log in as "student1"
+ When I click on "[data-action='limit-toggle']" "css_element" in the "Course overview" "block"
+ Then I should see "All" in the ".dropdown-menu.show" "css_element"
+ And I should see "12" in the ".dropdown-menu.show" "css_element"
+ And ".block_myoverview [data-control='next']" "css_element" should be visible
+ And ".block_myoverview [data-control='previous']" "css_element" should be visible
+ But I should not see "24" in the ".block_myoverview .dropdown-menu.show" "css_element"
+ And I log out
+
+ Scenario: Previous page button should be disabled when on the first page of courses
+ Given the following "course enrolments" exist:
+ | user | course | role |
+ | student1 | C1 | student |
+ | student1 | C2 | student |
+ | student1 | C3 | student |
+ | student1 | C4 | student |
+ | student1 | C5 | student |
+ | student1 | C6 | student |
+ | student1 | C7 | student |
+ | student1 | C8 | student |
+ | student1 | C9 | student |
+ | student1 | C10 | student |
+ | student1 | C11 | student |
+ | student1 | C12 | student |
+ | student1 | C13 | student |
+ When I log in as "student1"
+ Then the "class" attribute of ".block_myoverview [data-control='previous']" "css_element" should contain "disabled"
+ And I log out
+
+ Scenario: Next page button should be disabled when on the last page of courses
+ Given the following "course enrolments" exist:
+ | user | course | role |
+ | student1 | C1 | student |
+ | student1 | C2 | student |
+ | student1 | C3 | student |
+ | student1 | C4 | student |
+ | student1 | C5 | student |
+ | student1 | C6 | student |
+ | student1 | C7 | student |
+ | student1 | C8 | student |
+ | student1 | C9 | student |
+ | student1 | C10 | student |
+ | student1 | C11 | student |
+ | student1 | C12 | student |
+ | student1 | C13 | student |
+ When I log in as "student1"
+ And I click on "[data-control='next']" "css_element" in the "Course overview" "block"
+ And I wait until ".block_myoverview [data-control='next']" "css_element" exists
+ Then the "class" attribute of ".block_myoverview [data-control='next']" "css_element" should contain "disabled"
+ And I log out
+
+ Scenario: Next and previous page buttons should both be enabled when not on last or first page of courses
+ Given the following "course enrolments" exist:
+ | user | course | role |
+ | student1 | C1 | student |
+ | student1 | C2 | student |
+ | student1 | C3 | student |
+ | student1 | C4 | student |
+ | student1 | C5 | student |
+ | student1 | C6 | student |
+ | student1 | C7 | student |
+ | student1 | C8 | student |
+ | student1 | C9 | student |
+ | student1 | C10 | student |
+ | student1 | C11 | student |
+ | student1 | C12 | student |
+ | student1 | C13 | student |
+ | student1 | C14 | student |
+ | student1 | C15 | student |
+ | student1 | C16 | student |
+ | student1 | C17 | student |
+ | student1 | C18 | student |
+ | student1 | C19 | student |
+ | student1 | C20 | student |
+ | student1 | C21 | student |
+ | student1 | C22 | student |
+ | student1 | C23 | student |
+ | student1 | C24 | student |
+ | student1 | C25 | student |
+ When I log in as "student1"
+ And I click on "[data-control='next']" "css_element" in the "Course overview" "block"
+ And I wait until ".block_myoverview [data-control='next']" "css_element" exists
+ Then the "class" attribute of ".block_myoverview [data-control='next']" "css_element" should not contain "disabled"
+ And the "class" attribute of ".block_myoverview [data-control='previous']" "css_element" should not contain "disabled"
+ And I should see "Course 13" in the "Course overview" "block"
+ And I should see "Course 24" in the "Course overview" "block"
+ But I should not see "Course 12" in the "Course overview" "block"
+ And I should not see "Course 25" in the "Course overview" "block"
+ And I log out
<a href="{{url}}"
title={{#quote}}{{{name}}}{{/quote}}
aria-label='{{#str}} ariaeventlistitem, block_timeline, { "name": {{#quote}}{{{name}}}{{/quote}}, "course": {{#quote}}{{{course.fullnamedisplay}}}{{/quote}}, "date": "{{#userdate}} {{timesort}}, {{#str}} strftimedatetime, core_langconfig {{/str}} {{/userdate}}" } {{/str}}'
- ><h6 class="event-name text-truncate mb-0">{{#quote}}{{{name}}}{{/quote}}</h6></a>
+ ><h6 class="event-name text-truncate mb-0">{{{name}}}</h6></a>
{{#course.fullnamedisplay}}
- <small class="text-muted text-truncate mb-0">{{#quote}}{{{course.fullnamedisplay}}}{{/quote}}</small>
+ <small class="text-muted text-truncate mb-0">{{{course.fullnamedisplay}}}</small>
{{/course.fullnamedisplay}}
{{#action.actionable}}
<h6 class="mb-0 pt-2">
has_capability('moodle/course:changelockedcustomfields', $context));
} else {
$context = $this->get_parent_context();
- return (!$field->get_configdata_property('locked') ||
- guess_if_creator_will_have_course_capability('moodle/course:changelockedcustomfields', $context));
+ if ($context->contextlevel == CONTEXT_SYSTEM) {
+ return (!$field->get_configdata_property('locked') ||
+ has_capability('moodle/course:changelockedcustomfields', $context));
+ } else {
+ return (!$field->get_configdata_property('locked') ||
+ guess_if_creator_will_have_course_capability('moodle/course:changelockedcustomfields', $context));
+ }
}
}
--- /dev/null
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * Abstraction of general file archives.
+ *
+ * @package core_files
+ * @copyright 2020 Mark Nelson <mdjnelson@gmail.com>
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+namespace core_files;
+
+use core_files\local\archive_writer\file_writer_interface as file_writer_interface;
+use core_files\local\archive_writer\stream_writer_interface as stream_writer_interface;
+
+/**
+ * Each file archive type must extend this class.
+ *
+ * @package core_files
+ * @copyright 2020 Mark Nelson <mdjnelson@gmail.com>
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+abstract class archive_writer {
+
+ /**
+ * The zip writer class.
+ */
+ public const ZIP_WRITER = 'zip_writer';
+
+ /**
+ * Returns the stream writer.
+ *
+ * @param string $filename
+ * @param string $type
+ * @return stream_writer_interface
+ */
+ public static function get_stream_writer(string $filename, string $type): stream_writer_interface {
+ $classname = self::get_classname_for_type($type);
+
+ if (!is_a($classname, stream_writer_interface::class, true)) {
+ throw new \InvalidArgumentException("{$type} does not support streaming");
+ }
+
+ return $classname::stream_instance($filename);
+ }
+
+ /**
+ * Returns the file writer.
+ *
+ * @param string $filepath
+ * @param string $type
+ * @return file_writer_interface
+ */
+ public static function get_file_writer(string $filepath, string $type): file_writer_interface {
+ $classname = self::get_classname_for_type($type);
+
+ if (!is_a($classname, file_writer_interface::class, true)) {
+ throw new \InvalidArgumentException("{$type} does not support writing to files");
+ }
+
+ return $classname::file_instance($filepath);
+ }
+
+ /**
+ * Sanitise the file path, removing any unsuitable characters.
+ *
+ * @param string $filepath
+ * @return string
+ */
+ public function sanitise_filepath(string $filepath): string {
+ return clean_param($filepath, PARAM_PATH);
+ }
+
+ /**
+ * Returns the class name for the type that was provided in get_file_writer().
+ *
+ * @param string $type
+ * @return string
+ */
+ protected static function get_classname_for_type(string $type): string {
+ return "core_files\local\archive_writer\\" . $type;
+ }
+
+ /**
+ * The archive_writer Constructor.
+ */
+ protected function __construct() {
+
+ }
+
+ /**
+ * Adds a file from a file path.
+ *
+ * @param string $name The path of file in archive (including directory).
+ * @param string $path The path to file on disk (note: paths should be encoded using
+ * UNIX-style forward slashes -- e.g '/path/to/some/file').
+ */
+ abstract public function add_file_from_filepath(string $name, string $path): void;
+
+ /**
+ * Adds a file from a string.
+ *
+ * @param string $name The path of file in archive (including directory).
+ * @param string $data The contents of file
+ */
+ abstract public function add_file_from_string(string $name, string $data): void;
+
+ /**
+ * Adds a file from a stream.
+ *
+ * @param string $name The path of file in archive (including directory).
+ * @param resource $stream The contents of file as a stream resource
+ */
+ abstract public function add_file_from_stream(string $name, $stream): void;
+
+ /**
+ * Adds a stored_file to archive.
+ *
+ * @param string $name The path of file in archive (including directory).
+ * @param \stored_file $file
+ */
+ abstract public function add_file_from_stored_file(string $name, \stored_file $file): void;
+
+ /**
+ * Finish writing the zip footer.
+ */
+ abstract public function finish(): void;
+}
--- /dev/null
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * Interface used by archives that write to files.
+ *
+ * @package core_files
+ * @copyright 2020 Mark Nelson <mdjnelson@gmail.com>
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+namespace core_files\local\archive_writer;
+
+/**
+ * Interface used by archives that write to files.
+ *
+ * @package core_files
+ * @copyright 2020 Mark Nelson <mdjnelson@gmail.com>
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+interface file_writer_interface {
+
+ /**
+ * Return the file instance.
+ *
+ * @param string $filename
+ * @return static
+ */
+ public static function file_instance(string $filename): self;
+
+ /**
+ * Get the path of the zip.
+ *
+ * @return string
+ */
+ public function get_path_to_zip(): string;
+}
--- /dev/null
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * Interface used by archives that write to streams.
+ *
+ * @package core_files
+ * @copyright 2020 Mark Nelson <mdjnelson@gmail.com>
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+namespace core_files\local\archive_writer;
+
+/**
+ * Interface used by archives that write to streams.
+ *
+ * @package core_files
+ * @copyright 2020 Mark Nelson <mdjnelson@gmail.com>
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+interface stream_writer_interface {
+
+ /**
+ * Return the stream instance.
+ *
+ * @param string $filename
+ * @return static
+ */
+ public static function stream_instance(string $filename): self;
+}
--- /dev/null
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * Class used for creating ZIP archives.
+ *
+ * @package core_files
+ * @copyright 2020 Mark Nelson <mdjnelson@gmail.com>
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+namespace core_files\local\archive_writer;
+
+use ZipStream\Option\Archive;
+use ZipStream\ZipStream;
+use core_files\archive_writer;
+use core_files\local\archive_writer\file_writer_interface as file_writer_interface;
+use core_files\local\archive_writer\stream_writer_interface as stream_writer_interface;
+
+/**
+ * Class used for creating ZIP archives.
+ *
+ * @package core_files
+ * @copyright 2020 Mark Nelson <mdjnelson@gmail.com>
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class zip_writer extends archive_writer implements file_writer_interface, stream_writer_interface {
+
+ /**
+ * @var resource File resource for the file handle for a file-based zip stream
+ */
+ private $zipfilehandle = null;
+
+ /**
+ * @var String The location of the zip file.
+ */
+ private $zipfilepath = null;
+
+ /**
+ * @var ZipStream The zip stream.
+ */
+ private $archive;
+
+ /**
+ * The zip_writer constructor.
+ *
+ * @param ZipStream $archive
+ */
+ protected function __construct(ZipStream $archive) {
+ parent::__construct();
+ $this->archive = $archive;
+ }
+
+ public static function stream_instance(string $filename): stream_writer_interface {
+ $options = new Archive();
+ $options->setSendHttpHeaders(true);
+ $options->setContentDisposition('attachment');
+ $options->setContentType('application/x-zip');
+ $zipwriter = new ZipStream($filename, $options);
+
+ return new static($zipwriter);
+ }
+
+ public static function file_instance(string $filename): file_writer_interface {
+ $dir = make_request_directory();
+ $filepath = "$dir/$filename";
+ $fh = fopen($filepath, 'w');
+
+ $exportoptions = new Archive();
+ $exportoptions->setOutputStream($fh);
+ $exportoptions->setSendHttpHeaders(false);
+ $zipstream = new ZipStream($filename, $exportoptions);
+
+ $zipwriter = new static($zipstream);
+ // ZipStream only takes a file handle resource.
+ // It does not close this resource itself, and it does not know the location of this resource on disk.
+ // Store references to the filehandle, and the location of the filepath in the new class so that the `finish()`
+ // function can close the fh, and move the temporary file into place.
+ // The filehandle must be closed when finishing the archive. ZipStream does not close it automatically.
+ $zipwriter->zipfilehandle = $fh;
+ $zipwriter->zipfilepath = $filepath;
+
+ return $zipwriter;
+ }
+
+ public function add_file_from_filepath(string $name, string $path): void {
+ $this->archive->addFileFromPath($this->sanitise_filepath($name), $path);
+ }
+
+ public function add_file_from_string(string $name, string $data): void {
+ $this->archive->addFile($this->sanitise_filepath($name), $data);
+ }
+
+ public function add_file_from_stream(string $name, $stream): void {
+ $this->archive->addFileFromStream($this->sanitise_filepath($name), $stream);
+ fclose($stream);
+ }
+
+ public function add_file_from_stored_file(string $name, \stored_file $file): void {
+ $filehandle = $file->get_content_file_handle();
+ $this->archive->addFileFromStream($this->sanitise_filepath($name), $filehandle);
+ fclose($filehandle);
+ }
+
+ public function finish(): void {
+ $this->archive->finish();
+
+ if ($this->zipfilehandle) {
+ fclose($this->zipfilehandle);
+ }
+ }
+
+ public function get_path_to_zip(): string {
+ return $this->zipfilepath;
+ }
+
+ public function sanitise_filepath(string $filepath): string {
+ $filepath = parent::sanitise_filepath($filepath);
+
+ return \ZipStream\File::filterFilename($filepath);
+ }
+}
--- /dev/null
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * Unit tests for core_files\local\archive_writer/zip_archive.
+ *
+ * @package core_files
+ * @category test
+ * @copyright 2020 Mark Nelson <mdjnelson@gmail.com>
+ * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
+ */
+
+namespace core_files;
+
+use advanced_testcase;
+use core_files\local\archive_writer\zip_writer;
+
+/**
+ * Unit tests for \core_files\archive_writer.
+ *
+ * @coversDefaultClass \core_files\archive_writer
+ */
+class archive_writer_testcase extends advanced_testcase {
+
+ /**
+ * Test get_file_writer().
+ */
+ public function test_get_file_writer(): void {
+ $zipwriter = archive_writer::get_file_writer('file.zip', archive_writer::ZIP_WRITER);
+ $this->assertInstanceOf(zip_writer::class, $zipwriter);
+ $this->assertTrue(file_exists($zipwriter->get_path_to_zip()));
+ }
+
+ /**
+ * Test get_stream_writer().
+ */
+ public function test_get_stream_writer(): void {
+ $zipwriter = archive_writer::get_stream_writer('path/to/file.txt', archive_writer::ZIP_WRITER);
+ $this->assertInstanceOf(zip_writer::class, $zipwriter);
+ }
+}
--- /dev/null
+Hey, this is an awesome text file. Hello! :)
\ No newline at end of file
--- /dev/null
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * Unit tests for \core_files\local\archive_writer\zip_writer.
+ *
+ * @package core_files
+ * @category test
+ * @copyright 2020 Mark Nelson <mdjnelson@gmail.com>
+ * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
+ */
+
+namespace core_files\local\archive_writer;
+
+use advanced_testcase;
+use context_module;
+use core_files\archive_writer;
+use ZipArchive;
+
+/**
+ * Unit tests for \core_files\local\archive_writer\zip_writer.
+ *
+ * @coversDefaultClass \core_files\local\archive_writer\zip_writer
+ */
+class zip_writer_testcase extends advanced_testcase {
+
+ /**
+ * Test add_file_from_filepath().
+ */
+ public function test_add_file_from_filepath(): void {
+ global $CFG;
+
+ $pathtofileinzip = '/some/made/up/name.txt';
+ $filetoadd = $CFG->dirroot . '/files/tests/fixtures/awesome_file.txt';
+
+ $zipwriter = archive_writer::get_file_writer('test.zip', archive_writer::ZIP_WRITER);
+ $zipwriter->add_file_from_filepath($pathtofileinzip, $filetoadd);
+ $zipwriter->finish();
+
+ $pathtozip = $zipwriter->get_path_to_zip();
+ $zip = new ZipArchive();
+ $opened = $zip->open($pathtozip);
+ $this->assertTrue($opened);
+
+ $pathtofileinzip = $zipwriter->sanitise_filepath($pathtofileinzip);
+
+ $this->assertEquals("Hey, this is an awesome text file. Hello! :)", $zip->getFromName($pathtofileinzip));
+ }
+
+ /**
+ * Test add_file_from_string().
+ */
+ public function test_add_file_from_string(): void {
+ $pathtofileinzip = "/path/to/my/awesome/file.txt";
+ $mycontent = "This is some real awesome content, ya dig?";
+
+ $zipwriter = archive_writer::get_file_writer('test.zip', archive_writer::ZIP_WRITER);
+ $zipwriter->add_file_from_string($pathtofileinzip, $mycontent);
+ $zipwriter->finish();
+
+ $pathtozip = $zipwriter->get_path_to_zip();
+ $zip = new ZipArchive();
+ $opened = $zip->open($pathtozip);
+ $this->assertTrue($opened);
+
+ $pathtofileinzip = $zipwriter->sanitise_filepath($pathtofileinzip);
+
+ $this->assertEquals($mycontent, $zip->getFromName($pathtofileinzip));
+ }
+
+ /**
+ * Test add_file_from_stream().
+ */
+ public function test_add_file_from_stream(): void {
+ $this->resetAfterTest(true);
+ $this->setAdminUser();
+
+ $course = $this->getDataGenerator()->create_course();
+ $assign = $this->getDataGenerator()->create_module('assign', ['course' => $course->id]);
+
+ // Add a file to the intro.
+ $filerecord = [
+ 'contextid' => context_module::instance($assign->cmid)->id,
+ 'component' => 'mod_assign',
+ 'filearea' => 'intro',
+ 'itemid' => 0,
+ 'filepath' => '/',
+ 'filename' => 'fileintro.txt',
+ ];
+ $fs = get_file_storage();
+ $storedfile = $fs->create_file_from_string($filerecord, 'Contents for the assignment, yeow!');
+
+ $pathtofileinzip = $storedfile->get_filepath() . $storedfile->get_filename();
+
+ $zipwriter = archive_writer::get_file_writer('test.zip', archive_writer::ZIP_WRITER);
+ $zipwriter->add_file_from_stream($pathtofileinzip, $storedfile->get_content_file_handle());
+ $zipwriter->finish();
+
+ $pathtozip = $zipwriter->get_path_to_zip();
+ $zip = new ZipArchive();
+ $opened = $zip->open($pathtozip);
+ $this->assertTrue($opened);
+
+ $pathtofileinzip = $zipwriter->sanitise_filepath($pathtofileinzip);
+
+ $this->assertEquals($storedfile->get_content(), $zip->getFromName($pathtofileinzip));
+ }
+
+ /**
+ * Test add_file_from_stored_file().
+ */
+ public function test_add_file_from_stored_file(): void {
+ $this->resetAfterTest(true);
+ $this->setAdminUser();
+
+ $course = $this->getDataGenerator()->create_course();
+ $assign = $this->getDataGenerator()->create_module('assign', ['course' => $course->id]);
+
+ // Add a file to the intro.
+ $filerecord = [
+ 'contextid' => context_module::instance($assign->cmid)->id,
+ 'component' => 'mod_assign',
+ 'filearea' => 'intro',
+ 'itemid' => 0,
+ 'filepath' => '/',
+ 'filename' => 'fileintro.txt',
+ ];
+ $fs = get_file_storage();
+ $storedfile = $fs->create_file_from_string($filerecord, 'Contents for the assignment, yeow!');
+
+ $pathtofileinzip = $storedfile->get_filepath() . $storedfile->get_filename();
+
+ $zipwriter = archive_writer::get_file_writer('test.zip', archive_writer::ZIP_WRITER);
+ $zipwriter->add_file_from_stored_file($pathtofileinzip, $storedfile);
+ $zipwriter->finish();
+
+ $pathtozip = $zipwriter->get_path_to_zip();
+ $zip = new ZipArchive();
+ $opened = $zip->open($pathtozip);
+ $this->assertTrue($opened);
+
+ $pathtofileinzip = $zipwriter->sanitise_filepath($pathtofileinzip);
+
+ $this->assertEquals($storedfile->get_content(), $zip->getFromName($pathtofileinzip));
+ }
+
+ /**
+ * Test sanitise_filepath().
+ *
+ * @param string $providedfilepath The provided file path.
+ * @param string $expectedfilepath The expected file path.
+ * @dataProvider sanitise_filepath_provider
+ */
+ public function test_sanitise_filepath(string $providedfilepath, string $expectedfilepath): void {
+ $zipwriter = archive_writer::get_stream_writer('path/to/file.txt', archive_writer::ZIP_WRITER);
+ $this->assertEquals($expectedfilepath, $zipwriter->sanitise_filepath($providedfilepath));
+ }
+
+ /**
+ * Data provider for test_sanitise_filepath.
+ *
+ * @return array
+ */
+ public function sanitise_filepath_provider(): array {
+ return [
+ ['a../../file/path', 'a../file/path'],
+ ['a./file/path', 'a./file/path'],
+ ['../file/path', 'file/path'],
+ ['foo/bar/', 'foo/bar/'],
+ ['\\\\\\a\\\\\\file\\\\\\path', 'a/file/path'],
+ ['//a//file/////path////', 'a/file/path/']
+ ];
+ }
+}
* @return {int|array}
*/
var buildItemsPerPagePagingBarContext = function(itemsPerPage) {
+ var context = [];
+
if ($.isArray(itemsPerPage)) {
// Convert the array into a format accepted by the template.
- var context = itemsPerPage.map(function(num) {
+ context = itemsPerPage.map(function(num) {
if (typeof num === 'number') {
// If the item is just a plain number then convert it into
// an object with value and active keys.
if (!activeItems.length) {
context[0].active = true;
}
-
- return context;
} else {
- return itemsPerPage;
+ // Convert the integer into a format accepted by the template.
+ context = [{value: itemsPerPage, active: true}];
}
+
+ return context;
};
/**
* Notification constructor.
*
* @param string $message the message to print out
- * @param string $messagetype one of the NOTIFY_* constants..
+ * @param ?string $messagetype one of the NOTIFY_* constants..
+ * @param bool $closebutton Whether to show a close icon to remove the notification (default true).
*/
- public function __construct($message, $messagetype = null) {
+ public function __construct($message, $messagetype = null, $closebutton = true) {
$this->message = $message;
if (empty($messagetype)) {
}
$this->messagetype = $messagetype;
+
+ $this->closebutton = $closebutton;
}
/**
try {
$task = \core\task\manager::get_next_adhoc_task(time(), $checklimits);
- } catch (Exception $e) {
+ } catch (\Throwable $e) {
if ($adhoclock) {
// Release the adhoc task runner lock.
$adhoclock->release();
}
mtrace('Scheduled task complete: ' . $fullname);
\core\task\manager::scheduled_task_complete($task);
- } catch (Exception $e) {
+ } catch (\Throwable $e) {
if ($DB && $DB->is_transaction_started()) {
error_log('Database transaction aborted automatically in ' . get_class($task));
$DB->force_transaction_rollback();
}
mtrace("Adhoc task complete: " . get_class($task));
\core\task\manager::adhoc_task_complete($task);
- } catch (Exception $e) {
+ } catch (\Throwable $e) {
if ($DB && $DB->is_transaction_started()) {
error_log('Database transaction aborted automatically in ' . get_class($task));
$DB->force_transaction_rollback();
* If the return ID isn't required, then this just reports success as true/false.
* $data is an object containing needed data
* @param string $table The database table to be inserted into
- * @param object $dataobject A data object with values for one or more fields in the record
+ * @param object|array $dataobject A data object with values for one or more fields in the record
* @param bool $returnid Should the id of the newly created record entry be returned? If this option is not requested then true/false is returned.
* @param bool $bulk Set to true is multiple inserts are expected
* @return bool|int true or new id
* If the return ID isn't required, then this just reports success as true/false.
* $data is an object containing needed data
* @param string $table The database table to be inserted into
- * @param object $data A data object with values for one or more fields in the record
+ * @param object|array $dataobject A data object with values for one or more fields in the record
* @param bool $returnid Should the id of the newly created record entry be returned? If this option is not requested then true/false is returned.
* @return bool|int true or new id
* @throws dml_exception A DML specific exception is thrown for any errors.
* If the return ID isn't required, then this just reports success as true/false.
* $data is an object containing needed data
* @param string $table The database table to be inserted into
- * @param object $data A data object with values for one or more fields in the record
+ * @param object|array $dataobject A data object with values for one or more fields in the record
* @param bool $returnid Should the id of the newly created record entry be returned? If this option is not requested then true/false is returned.
* @return bool|int true or new id
* @throws dml_exception A DML specific exception is thrown for any errors.
* If the return ID isn't required, then this just reports success as true/false.
* $data is an object containing needed data
* @param string $table The database table to be inserted into
- * @param object $data A data object with values for one or more fields in the record
+ * @param object|array $dataobject A data object with values for one or more fields in the record
* @param bool $returnid Should the id of the newly created record entry be returned? If this option is not requested then true/false is returned.
* @param bool $bulk true means repeated inserts expected
* @return bool|int true or new id
* If the return ID isn't required, then this just reports success as true/false.
* $data is an object containing needed data
* @param string $table The database table to be inserted into
- * @param object $data A data object with values for one or more fields in the record
+ * @param object|array $dataobject A data object with values for one or more fields in the record
* @param bool $returnid Should the id of the newly created record entry be returned? If this option is not requested then true/false is returned.
* @return bool|int true or new id
* @throws dml_exception A DML specific exception is thrown for any errors.
* If the return ID isn't required, then this just reports success as true/false.
* $data is an object containing needed data
* @param string $table The database table to be inserted into
- * @param object $data A data object with values for one or more fields in the record
+ * @param object|array $dataobject A data object with values for one or more fields in the record
* @param bool $returnid Should the id of the newly created record entry be returned? If this option is not requested then true/false is returned.
* @return bool|int true or new id
* @throws dml_exception A DML specific exception is thrown for any errors.
/**
* Default implementation, throws Exception
* @param string $table
- * @param StdObject $dataobject
+ * @param object|array $dataobject
* @param bool $returnid
* @param bool $bulk
* @return bool|int true or new id
* Note: \core\notification::add() may be more suitable for your usage.
*
* @param string $message The message to print out.
- * @param string $type The type of notification. See constants on \core\output\notification.
+ * @param ?string $type The type of notification. See constants on \core\output\notification.
+ * @param bool $closebutton Whether to show a close icon to remove the notification (default true).
* @return string the HTML to output.
*/
- public function notification($message, $type = null) {
+ public function notification($message, $type = null, $closebutton = true) {
$typemappings = [
// Valid types.
'success' => \core\output\notification::NOTIFY_SUCCESS,
}
}
- $notification = new \core\output\notification($message, $type);
+ $notification = new \core\output\notification($message, $type, $closebutton);
if (count($extraclasses)) {
$notification->set_extra_classes($extraclasses);
}
*
* @param string $message The message to print out.
* @param string $type The type of notification. See constants on \core\output\notification.
+ * @param bool $closebutton Whether to show a close icon to remove the notification (default true).
* @return string A template fragment for a notification
*/
- public function notification($message, $type = null) {
+ public function notification($message, $type = null, $closebutton = true) {
$message = clean_text($message);
if ($type === 'notifysuccess' || $type === 'success') {
return "++ $message ++\n";
*
* @param string $message The message to print out.
* @param string $type The type of notification. See constants on \core\output\notification.
+ * @param bool $closebutton Whether to show a close icon to remove the notification (default true).
*/
- public function notification($message, $type = null) {}
+ public function notification($message, $type = null, $closebutton = true) {
+ }
/**
* Used to display a redirection message.
{{^activepagenumber}}
data-active-page-number="1"
{{/activepagenumber}}
- {{#showitemsperpageselector}}
- {{#itemsperpage}}
- {{#active}}
- data-items-per-page="{{value}}"
- {{/active}}
- {{/itemsperpage}}
- {{/showitemsperpageselector}}
- {{^showitemsperpageselector}}
- data-items-per-page="{{itemsperpage}}"
- {{/showitemsperpageselector}}
+ {{#itemsperpage}}
+ {{#active}}
+ data-items-per-page="{{value}}"
+ {{/active}}
+ {{/itemsperpage}}
{{#arialabels.paginationnav}}
aria-label="{{.}}"
{{/arialabels.paginationnav}}
aria-expanded="false"
aria-controls="searchform-navbar"
>
- <i class="icon fa fa-search fa-fw " aria-hidden="true"></i>
+ {{#pix}} a/search, core {{/pix}}
<span class="sr-only">{{#str}} togglesearch {{/str}}</span>
</a>
</div>
// The `before_subsequent_scenario_start_session` function will restart the session instead.
return;
}
- self::$firstjavascriptscenarioseen = true;
$docsurl = behat_command::DOCS_URL;
$driverexceptionmsg = <<<EOF
$this->resize_window('medium');
}
+ /**
+ * Mark the first Javascript Scenario as have been seen.
+ *
+ * @BeforeScenario
+ * @param BeforeScenarioScope $scope scope passed by event fired before scenario.
+ */
+ public function mark_first_js_scenario_as_seen(BeforeScenarioScope $scope) {
+ self::$firstjavascriptscenarioseen = true;
+ }
+
/**
* Hook to open the site root before the first step in the suite.
* Yes, this is in a strange location and should be in the BeforeScenario hook, but failures in the test setUp lead
return $useridlist;
}
- /**
- * Generate zip file from array of given files.
- *
- * @param array $filesforzipping - array of files to pass into archive_to_pathname.
- * This array is indexed by the final file name and each
- * element in the array is an instance of a stored_file object.
- * @return path of temp file - note this returned file does
- * not have a .zip extension - it is a temp file.
- */
- protected function pack_files($filesforzipping) {
- global $CFG;
- // Create path for new zip file.
- $tempzip = tempnam($CFG->tempdir . '/', 'assignment_');
- // Zip files.
- $zipper = new zip_packer();
- if ($zipper->archive_to_pathname($filesforzipping, $tempzip)) {
- return $tempzip;
- }
- return false;
- }
-
/**
* Finds all assignment notifications that have yet to be mailed out, and mails them.
*
'action'=>'grading'));
$result .= $this->get_renderer()->continue_button($url);
$result .= $this->view_footer();
- } else if ($zipfile = $this->pack_files($filesforzipping)) {
- \mod_assign\event\all_submissions_downloaded::create_from_assign($this)->trigger();
- // Send file and delete after sending.
- send_temp_file($zipfile, $filename);
- // We will not get here - send_temp_file calls exit.
+
+ return $result;
}
- return $result;
+
+ // Log zip as downloaded.
+ \mod_assign\event\all_submissions_downloaded::create_from_assign($this)->trigger();
+
+ // Close the session.
+ \core\session\manager::write_close();
+
+ $zipwriter = \core_files\archive_writer::get_stream_writer($filename, \core_files\archive_writer::ZIP_WRITER);
+
+ // Stream the files into the zip.
+ foreach ($filesforzipping as $pathinzip => $storedfile) {
+ $zipwriter->add_file_from_stored_file($pathinzip, $storedfile);
+ }
+
+ // Finish the archive.
+ $zipwriter->finish();
+ exit();
}
/**
define('NO_MOODLE_COOKIES', true); // Session not used here.
require('../../../config.php');
-require('../lib.php');
+require_once('../lib.php');
$chatsid = required_param('chat_sid', PARAM_ALPHANUM);
$chatlasttime = optional_param('chat_lasttime', 0, PARAM_INT);
define('NO_OUTPUT_BUFFERING', true);
require('../../../config.php');
-require('../lib.php');
+require_once('../lib.php');
// We are going to run for a long time.
// Avoid being terminated by php.
define('NO_MOODLE_COOKIES', true); // Session not used here.
require('../../../config.php');
-require('../lib.php');
+require_once('../lib.php');
$chatsid = required_param('chat_sid', PARAM_ALPHANUM);
print_error('cannotdownloaddir', 'repository');
}
-folder_downloaded($folder, $course, $cm, $context);
-
$fs = get_file_storage();
-$file = $fs->get_file($context->id, 'mod_folder', 'content', 0, '/', '.');
-if (!$file) {
+$files = $fs->get_area_files($context->id, 'mod_folder', 'content');
+if (empty($files)) {
print_error('cannotdownloaddir', 'repository');
}
-$zipper = get_file_packer('application/zip');
+// Log zip as downloaded.
+folder_downloaded($folder, $course, $cm, $context);
+
+// Close the session.
+\core\session\manager::write_close();
+
$filename = shorten_filename(clean_filename($folder->name . "-" . date("Ymd")) . ".zip");
-$temppath = make_request_directory() . $filename;
+$zipwriter = \core_files\archive_writer::get_stream_writer($filename, \core_files\archive_writer::ZIP_WRITER);
-if ($zipper->archive_to_pathname(array('/' => $file), $temppath)) {
- send_temp_file($temppath, $filename);
-} else {
- print_error('cannotdownloaddir', 'repository');
+foreach ($files as $file) {
+ if ($file->is_directory()) {
+ continue;
+ }
+ $pathinzip = $file->get_filepath() . $file->get_filename();
+ $zipwriter->add_file_from_stored_file($pathinzip, $file);
}
+
+// Finish the archive.
+$zipwriter->finish();
+exit();
if ($downloadable) {
$downloadbutton = $this->output->single_button(
new moodle_url('/mod/folder/download_folder.php', array('id' => $cm->id)),
- get_string('downloadfolder', 'folder')
+ get_string('downloadfolder', 'folder'),
+ 'get'
);
$buttons .= $downloadbutton;
return true;
}
+ /**
+ * Mark the get_forum_discussions_paginated web service as deprecated.
+ *
+ * @return bool
+ */
+ public static function get_forum_discussions_paginated_is_deprecated() {
+ return true;
+ }
+
/**
* Describes the parameters for get_forum_discussions_paginated.
*
=== 3.11 ===
+* The get_forum_discussions_paginated web service has been deprecated in favour of get_forum_discussions.
* The forum post exporter now includes a "timemodified" field for each post, which is included in several WS methods:
* mod_forum_get_discussion_posts
* get_discussion_posts_by_userid
* External function get_forums_by_courses now returns two additional fields "duedate" and "cutoffdate" containing the due date and the cutoff date for posting to the forums respectively.
* External function get_forum_discussion_posts now returns an additional field "tags" returning the post tags.
* New external function mod_forum_external::get_forum_discussions returns a list of forum discussions optionally sorted and paginated.
- * External function mod_forum_external::get_forum_discussions_paginated has been deprecated.
Use mod_forum_external::get_forum_discussions instead.
* External function mod_forum_external::add_discussion_post() has a new 'messageformat' param to be able to handle other formats different from FORMAT_HTML (that continues being the default one). Also a new 'topreferredformat' option enables the automatic conversion between any format and the preferred format (given the editor preference) before contents are saved.
*/
var configToVariant = (config) => {
const variant = {};
- ['name', 'toolurl', 'securetoolurl', 'instructorcustomparameters', 'icon', 'secureicon', 'launchcontainer'].forEach(
+ ['name', 'toolurl', 'securetoolurl', 'instructorcustomparameters', 'icon', 'secureicon',
+ 'launchcontainer', 'lineitemresourceid', 'lineitemtag'].forEach(
function(name) {
variant[name] = config[name] || '';
}
}
$config->instructorcustomparameters = implode("\n", $customparameters);
}
- // Including a JSON version of the form data to support adding many items in one submit.
- $config->contentitemjson = json_encode($item);
return $config;
}
// Transition to the appropriate state.
switch ($this->quizobj->get_quiz()->overduehandling) {
case 'autosubmit':
- $this->process_finish($timestamp, false);
+ $this->process_finish($timestamp, false, $studentisonline ? $timestamp : $timeclose);
return;
case 'graceperiod':
$transaction->allow_commit();
}
- public function process_finish($timestamp, $processsubmitted) {
+ /**
+ * Submit the attempt.
+ *
+ * The separate $timefinish argument should be used when the quiz attempt
+ * is being processed asynchronously (for example when cron is submitting
+ * attempts where the time has expired).
+ *
+ * @param int $timestamp the time to record as last modified time.
+ * @param bool $processsubmitted if true, and question responses in the current
+ * POST request are stored to be graded, before the attempt is finished.
+ * @param ?int $timefinish if set, use this as the finish time for the attempt.
+ * (otherwise use $timestamp as the finish time as well).
+ */
+ public function process_finish($timestamp, $processsubmitted, $timefinish = null) {
global $DB;
$transaction = $DB->start_delegated_transaction();
question_engine::save_questions_usage_by_activity($this->quba);
$this->attempt->timemodified = $timestamp;
- $this->attempt->timefinish = $timestamp;
+ $this->attempt->timefinish = $timefinish ?? $timestamp;
$this->attempt->sumgrades = $this->quba->get_total_mark();
$this->attempt->state = self::FINISHED;
$this->attempt->timecheckstate = null;
if ($becomingabandoned) {
$this->process_abandon($timenow, true);
} else {
- $this->process_finish($timenow, !$toolate);
+ $this->process_finish($timenow, !$toolate, $toolate ? $timeclose : $timenow);
}
} catch (question_out_of_sequence_exception $e) {
defined('MOODLE_INTERNAL') || die();
-$capabilities = array(
+$capabilities = [
// Ability to see that the quiz exists, and the basic information
// about it, for example the start date and time limit.
- 'mod/quiz:view' => array(
+ 'mod/quiz:view' => [
'captype' => 'read',
'contextlevel' => CONTEXT_MODULE,
- 'archetypes' => array(
+ 'archetypes' => [
'guest' => CAP_ALLOW,
'student' => CAP_ALLOW,
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW
- )
- ),
+ ]
+ ],
// Ability to add a new quiz to the course.
- 'mod/quiz:addinstance' => array(
+ 'mod/quiz:addinstance' => [
'riskbitmask' => RISK_XSS,
'captype' => 'write',
'contextlevel' => CONTEXT_COURSE,
- 'archetypes' => array(
+ 'archetypes' => [
'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW
- ),
+ ],
'clonepermissionsfrom' => 'moodle/course:manageactivities'
- ),
+ ],
// Ability to do the quiz as a 'student'.
- 'mod/quiz:attempt' => array(
+ 'mod/quiz:attempt' => [
'riskbitmask' => RISK_SPAM,
'captype' => 'write',
'contextlevel' => CONTEXT_MODULE,
- 'archetypes' => array(
+ 'archetypes' => [
'student' => CAP_ALLOW
- )
- ),
+ ]
+ ],
// Ability for a 'Student' to review their previous attempts. Review by
// 'Teachers' is controlled by mod/quiz:viewreports.
- 'mod/quiz:reviewmyattempts' => array(
+ 'mod/quiz:reviewmyattempts' => [
'captype' => 'read',
'contextlevel' => CONTEXT_MODULE,
- 'archetypes' => array(
+ 'archetypes' => [
'student' => CAP_ALLOW
- ),
+ ],
'clonepermissionsfrom' => 'moodle/quiz:attempt'
- ),
+ ],
// Edit the quiz settings, add and remove questions.
- 'mod/quiz:manage' => array(
+ 'mod/quiz:manage' => [
'riskbitmask' => RISK_SPAM,
'captype' => 'write',
'contextlevel' => CONTEXT_MODULE,
- 'archetypes' => array(
+ 'archetypes' => [
'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW
- )
- ),
+ ]
+ ],
// Edit the quiz overrides.
- 'mod/quiz:manageoverrides' => array(
+ 'mod/quiz:manageoverrides' => [
'captype' => 'write',
'contextlevel' => CONTEXT_MODULE,
- 'archetypes' => array(
+ 'archetypes' => [
'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW
- )
- ),
+ ]
+ ],
+
+ // View the quiz overrides (only checked for users who don't have mod/quiz:manageoverrides.
+ 'mod/quiz:viewoverrides' => [
+ 'captype' => 'read',
+ 'contextlevel' => CONTEXT_MODULE,
+ 'archetypes' => [
+ 'teacher' => CAP_ALLOW,
+ 'editingteacher' => CAP_ALLOW,
+ 'manager' => CAP_ALLOW
+ ]
+ ],
// Preview the quiz.
- 'mod/quiz:preview' => array(
+ 'mod/quiz:preview' => [
'captype' => 'write', // Only just a write.
'contextlevel' => CONTEXT_MODULE,
- 'archetypes' => array(
+ 'archetypes' => [
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW
- )
- ),
+ ]
+ ],
// Manually grade and comment on student attempts at a question.
- 'mod/quiz:grade' => array(
+ 'mod/quiz:grade' => [
'riskbitmask' => RISK_SPAM | RISK_XSS,
'captype' => 'write',
'contextlevel' => CONTEXT_MODULE,
- 'archetypes' => array(
+ 'archetypes' => [
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW
- )
- ),
+ ]
+ ],
// Regrade quizzes.
- 'mod/quiz:regrade' => array(
+ 'mod/quiz:regrade' => [
'riskbitmask' => RISK_SPAM,
'captype' => 'write',
'contextlevel' => CONTEXT_MODULE,
- 'archetypes' => array(
+ 'archetypes' => [
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW
- ),
+ ],
'clonepermissionsfrom' => 'mod/quiz:grade'
- ),
+ ],
// View the quiz reports.
- 'mod/quiz:viewreports' => array(
+ 'mod/quiz:viewreports' => [
'riskbitmask' => RISK_PERSONAL,
'captype' => 'read',
'contextlevel' => CONTEXT_MODULE,
- 'archetypes' => array(
+ 'archetypes' => [
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW
- )
- ),
+ ]
+ ],
// Delete attempts using the overview report.
- 'mod/quiz:deleteattempts' => array(
+ 'mod/quiz:deleteattempts' => [
'riskbitmask' => RISK_DATALOSS,
'captype' => 'write',
'contextlevel' => CONTEXT_MODULE,
- 'archetypes' => array(
+ 'archetypes' => [
'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW
- )
- ),
+ ]
+ ],
// Do not have the time limit imposed. Used for accessibility legislation compliance.
- 'mod/quiz:ignoretimelimits' => array(
+ 'mod/quiz:ignoretimelimits' => [
'captype' => 'read',
'contextlevel' => CONTEXT_MODULE,
- 'archetypes' => array()
- ),
+ 'archetypes' => []
+ ],
// Receive a confirmation message of own quiz submission.
- 'mod/quiz:emailconfirmsubmission' => array(
+ 'mod/quiz:emailconfirmsubmission' => [
'captype' => 'read',
'contextlevel' => CONTEXT_MODULE,
- 'archetypes' => array()
- ),
+ 'archetypes' => []
+ ],
// Receive a notification message of other peoples' quiz submissions.
- 'mod/quiz:emailnotifysubmission' => array(
+ 'mod/quiz:emailnotifysubmission' => [
'captype' => 'read',
'contextlevel' => CONTEXT_MODULE,
- 'archetypes' => array()
- ),
+ 'archetypes' => []
+ ],
// Receive a notification message when a quiz attempt becomes overdue.
- 'mod/quiz:emailwarnoverdue' => array(
+ 'mod/quiz:emailwarnoverdue' => [
'captype' => 'read',
'contextlevel' => CONTEXT_MODULE,
- 'archetypes' => array()
- ),
-);
+ 'archetypes' => []
+ ],
+];
numattemptsmade,mod_quiz
reviewofattempt,mod_quiz
-reviewofpreview,mod_quiz
\ No newline at end of file
+reviewofpreview,mod_quiz
+settingsoverrides,mod_quiz
$string['overridegroup'] = 'Override group';
$string['overridegroupeventname'] = '{$a->quiz} - {$a->group}';
$string['overrides'] = 'Overrides';
+$string['overridesforquiz'] = 'Settings overrides: {$a}';
+$string['overridesnoneforgroups'] = 'No group settings overrides have been created for this quiz.';
+$string['overridesnoneforusers'] = 'No user settings overrides have been created for this quiz.';
+$string['overridessummary'] = 'Settings overrides exist ({$a})';
+$string['overridessummarythisgroup'] = 'Settings overrides exist ({$a}) for this group';
+$string['overridessummaryyourgroups'] = 'Settings overrides exist ({$a}) for your groups';
+$string['overridessummarygroup'] = 'Groups: {$a}';
+$string['overridessummaryuser'] = 'Users: {$a}';
$string['overrideuser'] = 'Override user';
$string['overrideusereventname'] = '{$a->quiz} - Override';
$string['pageshort'] = 'P';
$string['quizisclosedwillopen'] = 'Quiz closed (opens {$a})';
$string['quizisopenwillclose'] = 'Quiz open (closes {$a})';
$string['quiz:manage'] = 'Manage quizzes';
-$string['quiz:manageoverrides'] = 'Manage quiz overrides';
+$string['quiz:manageoverrides'] = 'Manage quiz settings overrides';
+$string['quiz:viewoverrides'] = 'View quiz settings overrides';
$string['quiznavigation'] = 'Quiz navigation';
$string['quizopen'] = 'Open the quiz';
$string['quizeventopens'] = '{$a} opens';
$string['serverinfo'] = 'Server information';
$string['servers'] = 'Servers';
$string['serverurl'] = 'Server URL';
-$string['settingsoverrides'] = 'Settings overrides';
$string['shortanswer'] = 'Short answer';
$string['show'] = 'Show';
$string['showall'] = 'Show all questions on one page';
$string['numattemptsmade'] = '{$a} attempts made on this quiz';
$string['reviewofattempt'] = 'Review of attempt {$a}';
$string['reviewofpreview'] = 'Review of preview';
+$string['settingsoverrides'] = 'Settings overrides';
*/
function quiz_attempt_summary_link_to_reports($quiz, $cm, $context, $returnzero = false,
$currentgroup = 0) {
- global $CFG;
- $summary = quiz_num_attempt_summary($quiz, $cm, $returnzero, $currentgroup);
- if (!$summary) {
- return '';
- }
+ global $PAGE;
- require_once($CFG->dirroot . '/mod/quiz/report/reportlib.php');
- $url = new moodle_url('/mod/quiz/report.php', array(
- 'id' => $cm->id, 'mode' => quiz_report_default_report($context)));
- return html_writer::link($url, $summary);
+ return $PAGE->get_renderer('mod_quiz')->quiz_attempt_summary_link_to_reports(
+ $quiz, $cm, $context, $returnzero, $currentgroup);
}
/**
$beforekey = $keys[$i + 1];
}
- if (has_capability('mod/quiz:manageoverrides', $PAGE->cm->context)) {
+ if (has_any_capability(['mod/quiz:manageoverrides', 'mod/quiz:viewoverrides'], $PAGE->cm->context)) {
$url = new moodle_url('/mod/quiz/overrides.php', array('cmid'=>$PAGE->cm->id));
$node = navigation_node::create(get_string('groupoverrides', 'quiz'),
new moodle_url($url, array('mode'=>'group')),
}
}
+/**
+ * Return summary of the number of settings override that exist.
+ *
+ * To get a nice display of this, see the quiz_override_summary_links()
+ * quiz renderer method.
+ *
+ * @param stdClass $quiz the quiz settings. Only $quiz->id is used at the moment.
+ * @param stdClass|cm_info $cm the cm object. Only $cm->course, $cm->groupmode and
+ * $cm->groupingid fields are used at the moment.
+ * @param int $currentgroup if there is a concept of current group where this method is being called
+ * (e.g. a report) pass it in here. Default 0 which means no current group.
+ * @return array like 'group' => 3, 'user' => 12] where 3 is the number of group overrides,
+ * and 12 is the number of user ones.
+ */
+function quiz_override_summary(stdClass $quiz, stdClass $cm, int $currentgroup = 0): array {
+ global $DB;
+
+ if ($currentgroup) {
+ // Currently only interested in one group.
+ $groupcount = $DB->count_records('quiz_overrides', ['quiz' => $quiz->id, 'groupid' => $currentgroup]);
+ $usercount = $DB->count_records_sql("
+ SELECT COUNT(1)
+ FROM {quiz_overrides} o
+ JOIN {groups_members} gm ON o.userid = gm.userid
+ WHERE o.quiz = ?
+ AND gm.groupid = ?
+ ", [$quiz->id, $currentgroup]);
+ return ['group' => $groupcount, 'user' => $usercount, 'mode' => 'onegroup'];
+ }
+
+ $quizgroupmode = groups_get_activity_groupmode($cm);
+ $accessallgroups = ($quizgroupmode == NOGROUPS) ||
+ has_capability('moodle/site:accessallgroups', context_module::instance($cm->id));
+
+ if ($accessallgroups) {
+ // User can see all groups.
+ $groupcount = $DB->count_records_select('quiz_overrides',
+ 'quiz = ? AND groupid IS NOT NULL', [$quiz->id]);
+ $usercount = $DB->count_records_select('quiz_overrides',
+ 'quiz = ? AND userid IS NOT NULL', [$quiz->id]);
+ return ['group' => $groupcount, 'user' => $usercount, 'mode' => 'allgroups'];
+
+ } else {
+ // User can only see groups they are in.
+ $groups = groups_get_activity_allowed_groups($cm);
+ if (!$groups) {
+ return ['group' => 0, 'user' => 0, 'mode' => 'somegroups'];
+ }
+
+ list($groupidtest, $params) = $DB->get_in_or_equal(array_keys($groups));
+ $params[] = $quiz->id;
+
+ $groupcount = $DB->count_records_select('quiz_overrides',
+ "groupid $groupidtest AND quiz = ?", $params);
+ $usercount = $DB->count_records_sql("
+ SELECT COUNT(1)
+ FROM {quiz_overrides} o
+ JOIN {groups_members} gm ON o.userid = gm.userid
+ WHERE gm.groupid $groupidtest
+ AND o.quiz = ?
+ ", $params);
+
+ return ['group' => $groupcount, 'user' => $usercount, 'mode' => 'somegroups'];
+ }
+}
+
/**
* Efficiently update check state time on all open attempts
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-
require_once(__DIR__ . '/../../config.php');
require_once($CFG->dirroot.'/mod/quiz/lib.php');
require_once($CFG->dirroot.'/mod/quiz/locallib.php');
$mode = optional_param('mode', '', PARAM_ALPHA); // One of 'user' or 'group', default is 'group'.
list($course, $cm) = get_course_and_cm_from_cmid($cmid, 'quiz');
-$quiz = $DB->get_record('quiz', array('id' => $cm->instance), '*', MUST_EXIST);
+$quiz = $DB->get_record('quiz', ['id' => $cm->instance], '*', MUST_EXIST);
require_login($course, false, $cm);
$context = context_module::instance($cm->id);
// Check the user has the required capabilities to list overrides.
-require_capability('mod/quiz:manageoverrides', $context);
+$canedit = has_capability('mod/quiz:manageoverrides', $context);
+if (!$canedit) {
+ require_capability('mod/quiz:viewoverrides', $context);
+}
$quizgroupmode = groups_get_activity_groupmode($cm);
$accessallgroups = ($quizgroupmode == NOGROUPS) || has_capability('moodle/site:accessallgroups', $context);
}
$groupmode = ($mode == "group");
-$url = new moodle_url('/mod/quiz/overrides.php', array('cmid'=>$cm->id, 'mode'=>$mode));
+$url = new moodle_url('/mod/quiz/overrides.php', ['cmid' => $cm->id, 'mode' => $mode]);
+$title = get_string('overridesforquiz', 'quiz',
+ format_string($quiz->name, true, ['context' => $context]));
$PAGE->set_url($url);
-
-// Display a list of overrides.
$PAGE->set_pagelayout('admin');
-$PAGE->set_title(get_string('overrides', 'quiz'));
+$PAGE->set_title($title);
$PAGE->set_heading($course->fullname);
-echo $OUTPUT->header();
-echo $OUTPUT->heading(format_string($quiz->name, true, array('context' => $context)));
// Delete orphaned group overrides.
$sql = 'SELECT o.id
WHERE o.groupid IS NOT NULL
AND g.id IS NULL
AND o.quiz = ?';
-$params = array($quiz->id);
+$params = [$quiz->id];
$orphaned = $DB->get_records_sql($sql, $params);
if (!empty($orphaned)) {
$DB->delete_records_list('quiz_overrides', 'id', array_keys($orphaned));
$overrides = $DB->get_records_sql($sql, $params);
}
} else {
+ // User overrides.
$colname = get_string('user');
list($sort, $params) = users_order_by_sql('u');
$params['quizid'] = $quiz->id;
// Initialise table.
$table = new html_table();
-$table->headspan = array(1, 2, 1);
-$table->colclasses = array('colname', 'colsetting', 'colvalue', 'colaction');
-$table->head = array(
- $colname,
- get_string('overrides', 'quiz'),
- get_string('action'),
-);
+$table->headspan = [1, 2, 1];
+$table->colclasses = ['colname', 'colsetting', 'colvalue', 'colaction'];
+$table->head = [
+ $colname,
+ get_string('overrides', 'quiz'),
+];
+if ($canedit) {
+ $table->head[] = get_string('action');
+}
-$userurl = new moodle_url('/user/view.php', array());
-$groupurl = new moodle_url('/group/overview.php', array('id' => $cm->course));
+$userurl = new moodle_url('/user/view.php', []);
+$groupurl = new moodle_url('/group/overview.php', ['id' => $cm->course]);
$overridedeleteurl = new moodle_url('/mod/quiz/overridedelete.php');
$overrideediturl = new moodle_url('/mod/quiz/overrideedit.php');
foreach ($overrides as $override) {
- $fields = array();
- $values = array();
+ // Check if this override is active.
$active = true;
-
- // Check for inactive overrides.
if (!$groupmode) {
if (!has_capability('mod/quiz:attempt', $context, $override->userid)) {
// User not allowed to take the quiz.
$active = false;
}
}
+ if (!$active) {
+ $hasinactive = true;
+ }
+
+ // Prepare the information about which settings are overridden.
+ $fields = [];
+ $values = [];
// Format timeopen.
if (isset($override->timeopen)) {
$values[] = $override->timeopen > 0 ?
userdate($override->timeopen) : get_string('noopen', 'quiz');
}
-
// Format timeclose.
if (isset($override->timeclose)) {
$fields[] = get_string('quizcloses', 'quiz');
$values[] = $override->timeclose > 0 ?
userdate($override->timeclose) : get_string('noclose', 'quiz');
}
-
// 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.
if (isset($override->attempts)) {
$fields[] = get_string('attempts', 'quiz');
$values[] = $override->attempts > 0 ?
$override->attempts : get_string('unlimited');
}
-
// Format password.
if (isset($override->password)) {
$fields[] = get_string('requirepassword', 'quiz');
get_string('enabled', 'quiz') : get_string('none', 'quiz');
}
- // Icons.
- $iconstr = '';
-
- // Edit.
- $editurlstr = $overrideediturl->out(true, array('id' => $override->id));
- $iconstr = '<a title="' . get_string('edit') . '" href="'. $editurlstr . '">' .
- $OUTPUT->pix_icon('t/edit', get_string('edit')) . '</a> ';
- // Duplicate.
- $copyurlstr = $overrideediturl->out(true,
- array('id' => $override->id, 'action' => 'duplicate'));
- $iconstr .= '<a title="' . get_string('copy') . '" href="' . $copyurlstr . '">' .
- $OUTPUT->pix_icon('t/copy', get_string('copy')) . '</a> ';
- // Delete.
- $deleteurlstr = $overridedeleteurl->out(true,
- array('id' => $override->id, 'sesskey' => sesskey()));
- $iconstr .= '<a title="' . get_string('delete') . '" href="' . $deleteurlstr . '">' .
- $OUTPUT->pix_icon('t/delete', get_string('delete')) . '</a> ';
-
+ // Prepare the information about who this override applies to.
if ($groupmode) {
$usergroupstr = '<a href="' . $groupurl->out(true,
- array('group' => $override->groupid)) . '" >' . $override->name . '</a>';
+ ['group' => $override->groupid]) . '" >' . $override->name . '</a>';
} else {
$usergroupstr = '<a href="' . $userurl->out(true,
- array('id' => $override->userid)) . '" >' . fullname($override) . '</a>';
+ ['id' => $override->userid]) . '" >' . fullname($override) . '</a>';
}
-
- $class = '';
if (!$active) {
- $class = "dimmed_text";
$usergroupstr .= '*';
- $hasinactive = true;
}
-
$usergroupcell = new html_table_cell();
$usergroupcell->rowspan = count($fields);
$usergroupcell->text = $usergroupstr;
- $actioncell = new html_table_cell();
- $actioncell->rowspan = count($fields);
- $actioncell->text = $iconstr;
+ // Prepare the actions.
+ if ($canedit) {
+ // Icons.
+ $iconstr = '';
+
+ // Edit.
+ $editurlstr = $overrideediturl->out(true, ['id' => $override->id]);
+ $iconstr = '<a title="' . get_string('edit') . '" href="' . $editurlstr . '">' .
+ $OUTPUT->pix_icon('t/edit', get_string('edit')) . '</a> ';
+ // Duplicate.
+ $copyurlstr = $overrideediturl->out(true,
+ ['id' => $override->id, 'action' => 'duplicate']);
+ $iconstr .= '<a title="' . get_string('copy') . '" href="' . $copyurlstr . '">' .
+ $OUTPUT->pix_icon('t/copy', get_string('copy')) . '</a> ';
+ // Delete.
+ $deleteurlstr = $overridedeleteurl->out(true,
+ ['id' => $override->id, 'sesskey' => sesskey()]);
+ $iconstr .= '<a title="' . get_string('delete') . '" href="' . $deleteurlstr . '">' .
+ $OUTPUT->pix_icon('t/delete', get_string('delete')) . '</a> ';
+
+ $actioncell = new html_table_cell();
+ $actioncell->rowspan = count($fields);
+ $actioncell->text = $iconstr;
+ }
+
+ // Add the data to the table.
for ($i = 0; $i < count($fields); ++$i) {
$row = new html_table_row();
- $row->attributes['class'] = $class;
+ if (!$active) {
+ $row->attributes['class'] = 'dimmed_text';
+ }
+
if ($i == 0) {
$row->cells[] = $usergroupcell;
}
- $cell1 = new html_table_cell();
- $cell1->text = $fields[$i];
- $row->cells[] = $cell1;
- $cell2 = new html_table_cell();
- $cell2->text = $values[$i];
- $row->cells[] = $cell2;
- if ($i == 0) {
+
+ $labelcell = new html_table_cell();
+ $labelcell->text = $fields[$i];
+ $row->cells[] = $labelcell;
+ $valuecell = new html_table_cell();
+ $valuecell->text = $values[$i];
+ $row->cells[] = $valuecell;
+
+ if ($canedit && $i == 0) {
$row->cells[] = $actioncell;
}
+
$table->data[] = $row;
}
}
+// Display a list of overrides.
+echo $OUTPUT->header();
+echo $OUTPUT->heading($title);
+
// Output the table and button.
-echo html_writer::start_tag('div', array('id' => 'quizoverrides'));
+echo html_writer::start_tag('div', ['id' => 'quizoverrides']);
if (count($table->data)) {
echo html_writer::table($table);
+} else {
+ if ($groupmode) {
+ echo $OUTPUT->notification(get_string('overridesnoneforgroups', 'quiz'), 'info', false);
+ } else {
+ echo $OUTPUT->notification(get_string('overridesnoneforusers', 'quiz'), 'info', false);
+ }
}
if ($hasinactive) {
- echo $OUTPUT->notification(get_string('inactiveoverridehelp', 'quiz'), 'dimmed_text');
+ echo $OUTPUT->notification(get_string('inactiveoverridehelp', 'quiz'), 'info', false);
}
-echo html_writer::start_tag('div', array('class' => 'buttons'));
-$options = array();
-if ($groupmode) {
- if (empty($groups)) {
- // There are no groups.
- echo $OUTPUT->notification(get_string('groupsnone', 'quiz'), 'error');
- $options['disabled'] = true;
- }
- echo $OUTPUT->single_button($overrideediturl->out(true,
- array('action' => 'addgroup', 'cmid' => $cm->id)),
- get_string('addnewgroupoverride', 'quiz'), 'post', $options);
-} else {
- $users = array();
- // See if there are any students in the quiz.
- if ($accessallgroups) {
- $users = get_users_by_capability($context, 'mod/quiz:attempt', 'u.id');
- $nousermessage = get_string('usersnone', 'quiz');
- } else if ($groups) {
- $users = get_users_by_capability($context, 'mod/quiz:attempt', 'u.id', '', '', '', array_keys($groups));
- $nousermessage = get_string('usersnone', 'quiz');
+if ($canedit) {
+ echo html_writer::start_tag('div', ['class' => 'buttons']);
+ $options = [];
+ if ($groupmode) {
+ if (empty($groups)) {
+ // There are no groups.
+ echo $OUTPUT->notification(get_string('groupsnone', 'quiz'), 'error');
+ $options['disabled'] = true;
+ }
+ echo $OUTPUT->single_button($overrideediturl->out(true,
+ ['action' => 'addgroup', 'cmid' => $cm->id]),
+ get_string('addnewgroupoverride', 'quiz'), 'post', $options);
} else {
- $nousermessage = get_string('groupsnone', 'quiz');
- }
- $info = new \core_availability\info_module($cm);
- $users = $info->filter_user_list($users);
+ $users = [];
+ // See if there are any students in the quiz.
+ if ($accessallgroups) {
+ $users = get_users_by_capability($context, 'mod/quiz:attempt', 'u.id');
+ $nousermessage = get_string('usersnone', 'quiz');
+ } else if ($groups) {
+ $users = get_users_by_capability($context, 'mod/quiz:attempt', 'u.id', '', '', '', array_keys($groups));
+ $nousermessage = get_string('usersnone', 'quiz');
+ } else {
+ $nousermessage = get_string('groupsnone', 'quiz');
+ }
+ $info = new \core_availability\info_module($cm);
+ $users = $info->filter_user_list($users);
- if (empty($users)) {
- // There are no students.
- echo $OUTPUT->notification($nousermessage, 'error');
- $options['disabled'] = true;
+ if (empty($users)) {
+ // There are no students.
+ echo $OUTPUT->notification($nousermessage, 'error');
+ $options['disabled'] = true;
+ }
+ echo $OUTPUT->single_button($overrideediturl->out(true,
+ ['action' => 'adduser', 'cmid' => $cm->id]),
+ get_string('addnewuseroverride', 'quiz'), 'get', $options);
}
- echo $OUTPUT->single_button($overrideediturl->out(true,
- array('action' => 'adduser', 'cmid' => $cm->id)),
- get_string('addnewuseroverride', 'quiz'), 'get', $options);
+ echo html_writer::end_tag('div');
}
-echo html_writer::end_tag('div');
+
echo html_writer::end_tag('div');
// Finish the page.
*
* @param object $quiz the quiz settings.
* @param object $cm the course_module object.
- * @param object $context the quiz context.
+ * @param context $context the quiz context.
* @param array $messages any access messages that should be described.
* @return string HTML to output.
*/
array('class' => 'quizattemptcounts'));
}
}
+
+ if (has_any_capability(['mod/quiz:manageoverrides', 'mod/quiz:viewoverrides'], $context)) {
+ if ($overrideinfo = $this->quiz_override_summary_links($quiz, $cm)) {
+ $output .= html_writer::tag('div', $overrideinfo, ['class' => 'quizattemptcounts']);
+ }
+ }
+
return $output;
}
* Returns the same as {@link quiz_num_attempt_summary()} but wrapped in a link
* to the quiz reports.
*
- * @param object $quiz the quiz object. Only $quiz->id is used at the moment.
- * @param object $cm the cm object. Only $cm->course, $cm->groupmode and $cm->groupingid
+ * @param stdClass $quiz the quiz object. Only $quiz->id is used at the moment.
+ * @param stdClass $cm the cm object. Only $cm->course, $cm->groupmode and $cm->groupingid
* fields are used at the moment.
- * @param object $context the quiz context.
+ * @param context $context the quiz context.
* @param bool $returnzero if false (default), when no attempts have been made '' is returned
- * instead of 'Attempts: 0'.
+ * instead of 'Attempts: 0'.
* @param int $currentgroup if there is a concept of current group where this method is being
- * called
- * (e.g. a report) pass it in here. Default 0 which means no current group.
+ * called (e.g. a report) pass it in here. Default 0 which means no current group.
* @return string HTML fragment for the link.
*/
public function quiz_attempt_summary_link_to_reports($quiz, $cm, $context,
return html_writer::link($url, $summary);
}
+ /**
+ * Render a summary of the number of group and user overrides, with corresponding links.
+ *
+ * @param stdClass $quiz the quiz settings.
+ * @param stdClass|cm_info $cm the cm object.
+ * @param int $currentgroup currently selected group, if there is one.
+ * @return string HTML fragment for the link.
+ */
+ public function quiz_override_summary_links(stdClass $quiz, stdClass $cm, $currentgroup = 0): string {
+
+ $baseurl = new moodle_url('/mod/quiz/overrides.php', ['cmid' => $cm->id]);
+ $counts = quiz_override_summary($quiz, $cm, $currentgroup);
+
+ $links = [];
+ if ($counts['group']) {
+ $links[] = html_writer::link(new moodle_url($baseurl, ['mode' => 'group']),
+ get_string('overridessummarygroup', 'quiz', $counts['group']));
+ }
+ if ($counts['user']) {
+ $links[] = html_writer::link(new moodle_url($baseurl, ['mode' => 'user']),
+ get_string('overridessummaryuser', 'quiz', $counts['user']));
+ }
+
+ if (!$links) {
+ return '';
+ }
+
+ $links = implode(', ', $links);
+ switch ($counts['mode']) {
+ case 'onegroup':
+ return get_string('overridessummarythisgroup', 'quiz', $links);
+
+ case 'somegroups':
+ return get_string('overridessummaryyourgroups', 'quiz', $links);
+
+ case 'allgroups':
+ return get_string('overridessummary', 'quiz', $links);
+
+ default:
+ throw new coding_exception('Unexpected mode ' . $counts['mode']);
+ }
+ }
+
/**
* Outputs a chart.
*
return quiz_attempt::create($attempt->id);
}
- /**
- * Test the functions quiz_update_open_attempts() and get_list_of_overdue_attempts()
- */
public function test_attempt_url() {
$attempt = $this->create_quiz_and_attempt_with_layout('1,2,0,3,4,0,5,6,0');
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_quiz_attempt_overdue_testcase extends advanced_testcase {
+
/**
- * Test the functions quiz_update_open_attempts() and get_list_of_overdue_attempts()
+ * Test the functions quiz_update_open_attempts(), get_list_of_overdue_attempts() and
+ * update_overdue_attempts().
*/
public function test_bulk_update_functions() {
global $DB,$CFG;
$course = $this->getDataGenerator()->create_course();
$user1 = $this->getDataGenerator()->create_user();
- $studentrole = $DB->get_record('role', array('shortname'=>'student'));
+ $studentrole = $DB->get_record('role', ['shortname' => 'student']);
$this->assertNotEmpty($studentrole);
$this->assertTrue(enrol_try_internal_enrol($course->id, $user1->id, $studentrole->id));
- $group1 = $this->getDataGenerator()->create_group(array('courseid'=>$course->id));
- $group2 = $this->getDataGenerator()->create_group(array('courseid'=>$course->id));
- $group3 = $this->getDataGenerator()->create_group(array('courseid'=>$course->id));
+ $group1 = $this->getDataGenerator()->create_group(['courseid' => $course->id]);
+ $group2 = $this->getDataGenerator()->create_group(['courseid' => $course->id]);
+ $group3 = $this->getDataGenerator()->create_group(['courseid' => $course->id]);
$this->assertTrue(groups_add_member($group1, $user1));
$this->assertTrue(groups_add_member($group2, $user1));
- $uniqueid = 0;
- $usertimes = array();
+ $usertimes = [];
- $quiz_generator = $this->getDataGenerator()->get_plugin_generator('mod_quiz');
+ /** @var mod_quiz_generator $quizgenerator */
+ $quizgenerator = $this->getDataGenerator()->get_plugin_generator('mod_quiz');
// Basic quiz settings
- $quiz = $quiz_generator->create_instance(array('course'=>$course->id, 'timeclose'=>1200, 'timelimit'=>600));
- $attemptid = $DB->insert_record('quiz_attempts', array('quiz'=>$quiz->id, 'userid'=>$user1->id, 'state'=>'inprogress', 'timestart'=>100, 'timecheckstate'=>0, 'layout'=>'', 'uniqueid'=>$uniqueid++));
- $usertimes[$attemptid] = array('timeclose'=>1200, 'timelimit'=>600, 'message'=>'Test1A');
+ $quiz = $quizgenerator->create_instance(['course' => $course->id, 'timeclose' => 1200, 'timelimit' => 600]);
+ $attemptid = $DB->insert_record('quiz_attempts', ['quiz' => $quiz->id, 'userid' => $user1->id, 'state' => 'inprogress',
+ 'timestart' => 100, 'timecheckstate' => 0, 'layout' => '', 'uniqueid' => $this->usage_id($quiz)]);
+ $usertimes[$attemptid] = ['timeclose' => 1200, 'timelimit' => 600, 'message' => 'Test1A', 'time1000state' => 'finished'];
- $quiz = $quiz_generator->create_instance(array('course'=>$course->id, 'timeclose'=>1200, 'timelimit'=>1800));
- $attemptid = $DB->insert_record('quiz_attempts', array('quiz'=>$quiz->id, 'userid'=>$user1->id, 'state'=>'inprogress', 'timestart'=>100, 'timecheckstate'=>0, 'layout'=>'', 'uniqueid'=>$uniqueid++));
- $usertimes[$attemptid] = array('timeclose'=>1200, 'timelimit'=>1800, 'message'=>'Test1B');
+ $quiz = $quizgenerator->create_instance(['course' => $course->id, 'timeclose' => 1200, 'timelimit' => 1800]);
+ $attemptid = $DB->insert_record('quiz_attempts', ['quiz' => $quiz->id, 'userid' => $user1->id, 'state' => 'inprogress',
+ 'timestart' => 100, 'timecheckstate' => 0, 'layout' => '', 'uniqueid' => $this->usage_id($quiz)]);
+ $usertimes[$attemptid] = ['timeclose' => 1200, 'timelimit' => 1800, 'message' => 'Test1B', 'time1000state' => 'inprogress'];
- $quiz = $quiz_generator->create_instance(array('course'=>$course->id, 'timeclose'=>1200, 'timelimit'=>0));
- $attemptid = $DB->insert_record('quiz_attempts', array('quiz'=>$quiz->id, 'userid'=>$user1->id, 'state'=>'inprogress', 'timestart'=>100, 'timecheckstate'=>0, 'layout'=>'', 'uniqueid'=>$uniqueid++));
- $usertimes[$attemptid] = array('timeclose'=>1200, 'timelimit'=>0, 'message'=>'Test1C');
+ $quiz = $quizgenerator->create_instance(['course' => $course->id, 'timeclose' => 1200, 'timelimit' => 0]);
+ $attemptid = $DB->insert_record('quiz_attempts', ['quiz' => $quiz->id, 'userid' => $user1->id, 'state' => 'inprogress',
+ 'timestart' => 100, 'timecheckstate' => 0, 'layout' => '', 'uniqueid' => $this->usage_id($quiz)]);
+ $usertimes[$attemptid] = ['timeclose' => 1200, 'timelimit' => 0, 'message' => 'Test1C', 'time1000state' => 'inprogress'];
- $quiz = $quiz_generator->create_instance(array('course'=>$course->id, 'timeclose'=>0, 'timelimit'=>600));
- $attemptid = $DB->insert_record('quiz_attempts', array('quiz'=>$quiz->id, 'userid'=>$user1->id, 'state'=>'inprogress', 'timestart'=>100, 'timecheckstate'=>0, 'layout'=>'', 'uniqueid'=>$uniqueid++));
- $usertimes[$attemptid] = array('timeclose'=>0, 'timelimit'=>600, 'message'=>'Test1D');
+ $quiz = $quizgenerator->create_instance(['course' => $course->id, 'timeclose' => 0, 'timelimit' => 600]);
+ $attemptid = $DB->insert_record('quiz_attempts', ['quiz' => $quiz->id, 'userid' => $user1->id, 'state' => 'inprogress',
+ 'timestart' => 100, 'timecheckstate' => 0, 'layout' => '', 'uniqueid' => $this->usage_id($quiz)]);
+ $usertimes[$attemptid] = ['timeclose' => 0, 'timelimit' => 600, 'message' => 'Test1D', 'time1000state' => 'finished'];
- $quiz = $quiz_generator->create_instance(array('course'=>$course->id, 'timeclose'=>0, 'timelimit'=>0));
- $attemptid = $DB->insert_record('quiz_attempts', array('quiz'=>$quiz->id, 'userid'=>$user1->id, 'state'=>'inprogress', 'timestart'=>100, 'timecheckstate'=>0, 'layout'=>'', 'uniqueid'=>$uniqueid++));
- $usertimes[$attemptid] = array('timeclose'=>0, 'timelimit'=>0, 'message'=>'Test1E');
+ $quiz = $quizgenerator->create_instance(['course' => $course->id, 'timeclose' => 0, 'timelimit' => 0]);
+ $attemptid = $DB->insert_record('quiz_attempts', ['quiz' => $quiz->id, 'userid' => $user1->id, 'state' => 'inprogress',
+ 'timestart' => 100, 'timecheckstate' => 0, 'layout' => '', 'uniqueid' => $this->usage_id($quiz)]);
+ $usertimes[$attemptid] = ['timeclose' => 0, 'timelimit' => 0, 'message' => 'Test1E', 'time1000state' => 'inprogress'];
// Group overrides
- $quiz = $quiz_generator->create_instance(array('course'=>$course->id, 'timeclose'=>1200, 'timelimit'=>0));
- $attemptid = $DB->insert_record('quiz_attempts', array('quiz'=>$quiz->id, 'userid'=>$user1->id, 'state'=>'inprogress', 'timestart'=>100, 'timecheckstate'=>0, 'layout'=>'', 'uniqueid'=>$uniqueid++));
- $DB->insert_record('quiz_overrides', array('quiz'=>$quiz->id, 'groupid'=>$group1->id, 'timeclose'=>1300, 'timelimit'=>null));
- $usertimes[$attemptid] = array('timeclose'=>1300, 'timelimit'=>0, 'message'=>'Test2A');
-
- $quiz = $quiz_generator->create_instance(array('course'=>$course->id, 'timeclose'=>1200, 'timelimit'=>0));
- $DB->insert_record('quiz_overrides', array('quiz'=>$quiz->id, 'groupid'=>$group1->id, 'timeclose'=>1100, 'timelimit'=>null));
- $attemptid = $DB->insert_record('quiz_attempts', array('quiz'=>$quiz->id, 'userid'=>$user1->id, 'state'=>'inprogress', 'timestart'=>100, 'timecheckstate'=>0, 'layout'=>'', 'uniqueid'=>$uniqueid++));
- $usertimes[$attemptid] = array('timeclose'=>1100, 'timelimit'=>0, 'message'=>'Test2B');
-
- $quiz = $quiz_generator->create_instance(array('course'=>$course->id, 'timeclose'=>0, 'timelimit'=>600));
- $DB->insert_record('quiz_overrides', array('quiz'=>$quiz->id, 'groupid'=>$group1->id, 'timeclose'=>null, 'timelimit'=>700));
- $attemptid = $DB->insert_record('quiz_attempts', array('quiz'=>$quiz->id, 'userid'=>$user1->id, 'state'=>'inprogress', 'timestart'=>100, 'timecheckstate'=>0, 'layout'=>'', 'uniqueid'=>$uniqueid++));
- $usertimes[$attemptid] = array('timeclose'=>0, 'timelimit'=>700, 'message'=>'Test2C');
-
- $quiz = $quiz_generator->create_instance(array('course'=>$course->id, 'timeclose'=>0, 'timelimit'=>600));
- $DB->insert_record('quiz_overrides', array('quiz'=>$quiz->id, 'groupid'=>$group1->id, 'timeclose'=>null, 'timelimit'=>500));
- $attemptid = $DB->insert_record('quiz_attempts', array('quiz'=>$quiz->id, 'userid'=>$user1->id, 'state'=>'inprogress', 'timestart'=>100, 'timecheckstate'=>0, 'layout'=>'', 'uniqueid'=>$uniqueid++));
- $usertimes[$attemptid] = array('timeclose'=>0, 'timelimit'=>500, 'message'=>'Test2D');
-
- $quiz = $quiz_generator->create_instance(array('course'=>$course->id, 'timeclose'=>0, 'timelimit'=>600));
- $DB->insert_record('quiz_overrides', array('quiz'=>$quiz->id, 'groupid'=>$group1->id, 'timeclose'=>null, 'timelimit'=>0));
- $attemptid = $DB->insert_record('quiz_attempts', array('quiz'=>$quiz->id, 'userid'=>$user1->id, 'state'=>'inprogress', 'timestart'=>100, 'timecheckstate'=>0, 'layout'=>'', 'uniqueid'=>$uniqueid++));
- $usertimes[$attemptid] = array('timeclose'=>0, 'timelimit'=>0, '', 'message'=>'Test2E');
-
- $quiz = $quiz_generator->create_instance(array('course'=>$course->id, 'timeclose'=>1200, 'timelimit'=>600));
- $DB->insert_record('quiz_overrides', array('quiz'=>$quiz->id, 'groupid'=>$group1->id, 'timeclose'=>1300, 'timelimit'=>500));
- $attemptid = $DB->insert_record('quiz_attempts', array('quiz'=>$quiz->id, 'userid'=>$user1->id, 'state'=>'inprogress', 'timestart'=>100, 'timecheckstate'=>0, 'layout'=>'', 'uniqueid'=>$uniqueid++));
- $usertimes[$attemptid] = array('timeclose'=>1300, 'timelimit'=>500, '', 'message'=>'Test2F');
- $attemptid = $DB->insert_record('quiz_attempts', array('quiz'=>$quiz->id, 'userid'=>$user1->id, 'state'=>'inprogress', 'timestart'=>1000, 'timecheckstate'=>0, 'layout'=>'', 'uniqueid'=>$uniqueid++, 'attempt'=>1));
- $usertimes[$attemptid] = array('timeclose'=>1300, 'timelimit'=>500, '', 'message'=>'Test2G');
-
- $quiz = $quiz_generator->create_instance(array('course'=>$course->id, 'timeclose'=>1200, 'timelimit'=>600));
- $DB->insert_record('quiz_overrides', array('quiz'=>$quiz->id, 'groupid'=>$group3->id, 'timeclose'=>1300, 'timelimit'=>500)); // user not in group
- $attemptid = $DB->insert_record('quiz_attempts', array('quiz'=>$quiz->id, 'userid'=>$user1->id, 'state'=>'inprogress', 'timestart'=>100, 'timecheckstate'=>0, 'layout'=>'', 'uniqueid'=>$uniqueid++));
- $usertimes[$attemptid] = array('timeclose'=>1200, 'timelimit'=>600, '', 'message'=>'Test2H');
- $attemptid = $DB->insert_record('quiz_attempts', array('quiz'=>$quiz->id, 'userid'=>$user1->id, 'state'=>'inprogress', 'timestart'=>1000, 'timecheckstate'=>0, 'layout'=>'', 'uniqueid'=>$uniqueid++, 'attempt'=>1));
- $usertimes[$attemptid] = array('timeclose'=>1200, 'timelimit'=>600, '', 'message'=>'Test2I');
+ $quiz = $quizgenerator->create_instance(['course' => $course->id, 'timeclose' => 1200, 'timelimit' => 0]);
+ $attemptid = $DB->insert_record('quiz_attempts', ['quiz' => $quiz->id, 'userid' => $user1->id, 'state' => 'inprogress',
+ 'timestart' => 100, 'timecheckstate' => 0, 'layout' => '', 'uniqueid' => $this->usage_id($quiz)]);
+ $DB->insert_record('quiz_overrides',
+ ['quiz' => $quiz->id, 'groupid' => $group1->id, 'timeclose' => 1300, 'timelimit' => null]);
+ $usertimes[$attemptid] = ['timeclose' => 1300, 'timelimit' => 0, 'message' => 'Test2A', 'time1000state' => 'inprogress'];
+
+ $quiz = $quizgenerator->create_instance(['course' => $course->id, 'timeclose' => 1200, 'timelimit' => 0]);
+ $DB->insert_record('quiz_overrides',
+ ['quiz' => $quiz->id, 'groupid' => $group1->id, 'timeclose' => 1100, 'timelimit' => null]);
+ $attemptid = $DB->insert_record('quiz_attempts', ['quiz' => $quiz->id, 'userid' => $user1->id, 'state' => 'inprogress',
+ 'timestart' => 100, 'timecheckstate' => 0, 'layout' => '', 'uniqueid' => $this->usage_id($quiz)]);
+ $usertimes[$attemptid] = ['timeclose' => 1100, 'timelimit' => 0, 'message' => 'Test2B', 'time1000state' => 'inprogress'];
+
+ $quiz = $quizgenerator->create_instance(
+ ['course' => $course->id, 'timeclose' => 0, 'timelimit' => 600, 'overduehandling' => 'autoabandon']);
+ $DB->insert_record('quiz_overrides',
+ ['quiz' => $quiz->id, 'groupid' => $group1->id, 'timeclose' => null, 'timelimit' => 700]);
+ $attemptid = $DB->insert_record('quiz_attempts', ['quiz' => $quiz->id, 'userid' => $user1->id, 'state' => 'inprogress',
+ 'timestart' => 100, 'timecheckstate' => 0, 'layout' => '', 'uniqueid' => $this->usage_id($quiz)]);
+ $usertimes[$attemptid] = ['timeclose' => 0, 'timelimit' => 700, 'message' => 'Test2C', 'time1000state' => 'abandoned'];
+
+ $quiz = $quizgenerator->create_instance(['course' => $course->id, 'timeclose' => 0, 'timelimit' => 600]);
+ $DB->insert_record('quiz_overrides',
+ ['quiz' => $quiz->id, 'groupid' => $group1->id, 'timeclose' => null, 'timelimit' => 500]);
+ $attemptid = $DB->insert_record('quiz_attempts', ['quiz' => $quiz->id, 'userid' => $user1->id, 'state' => 'inprogress',
+ 'timestart' => 100, 'timecheckstate' => 0, 'layout' => '', 'uniqueid' => $this->usage_id($quiz)]);
+ $usertimes[$attemptid] = ['timeclose' => 0, 'timelimit' => 500, 'message' => 'Test2D', 'time1000state' => 'finished'];
+
+ $quiz = $quizgenerator->create_instance(['course' => $course->id, 'timeclose' => 0, 'timelimit' => 600]);
+ $DB->insert_record('quiz_overrides',
+ ['quiz' => $quiz->id, 'groupid' => $group1->id, 'timeclose' => null, 'timelimit' => 0]);
+ $attemptid = $DB->insert_record('quiz_attempts', ['quiz' => $quiz->id, 'userid' => $user1->id, 'state' => 'inprogress',
+ 'timestart' => 100, 'timecheckstate' => 0, 'layout' => '', 'uniqueid' => $this->usage_id($quiz)]);
+ $usertimes[$attemptid] = ['timeclose' => 0, 'timelimit' => 0, 'message' => 'Test2E', 'time1000state' => 'inprogress'];
+
+ $quiz = $quizgenerator->create_instance(['course' => $course->id, 'timeclose' => 1200, 'timelimit' => 600]);
+ $DB->insert_record('quiz_overrides',
+ ['quiz' => $quiz->id, 'groupid' => $group1->id, 'timeclose' => 1300, 'timelimit' => 500]);
+ $attemptid = $DB->insert_record('quiz_attempts', ['quiz' => $quiz->id, 'userid' => $user1->id, 'state' => 'inprogress',
+ 'timestart' => 100, 'timecheckstate' => 0, 'layout' => '', 'uniqueid' => $this->usage_id($quiz)]);
+ $usertimes[$attemptid] = ['timeclose' => 1300, 'timelimit' => 500, 'message' => 'Test2F', 'time1000state' => 'finished'];
+ $attemptid = $DB->insert_record('quiz_attempts', ['quiz' => $quiz->id, 'userid' => $user1->id, 'state' => 'inprogress',
+ 'timestart' => 1000, 'timecheckstate' => 0, 'layout' => '', 'uniqueid' => $this->usage_id($quiz), 'attempt' => 1]);
+ $usertimes[$attemptid] = ['timeclose' => 1300, 'timelimit' => 500, 'message' => 'Test2G', 'time1000state' => 'inprogress'];
+
+ $quiz = $quizgenerator->create_instance(['course' => $course->id, 'timeclose' => 1200, 'timelimit' => 600]);
+ $DB->insert_record('quiz_overrides',
+ ['quiz' => $quiz->id, 'groupid' => $group3->id, 'timeclose' => 1300, 'timelimit' => 500]); // User not in group.
+ $attemptid = $DB->insert_record('quiz_attempts', ['quiz' => $quiz->id, 'userid' => $user1->id, 'state' => 'inprogress',
+ 'timestart' => 100, 'timecheckstate' => 0, 'layout' => '', 'uniqueid' => $this->usage_id($quiz)]);
+ $usertimes[$attemptid] = ['timeclose' => 1200, 'timelimit' => 600, 'message' => 'Test2H', 'time1000state' => 'finished'];
+ $attemptid = $DB->insert_record('quiz_attempts', ['quiz' => $quiz->id, 'userid' => $user1->id, 'state' => 'inprogress',
+ 'timestart' => 1000, 'timecheckstate' => 0, 'layout' => '', 'uniqueid' => $this->usage_id($quiz), 'attempt' => 1]);
+ $usertimes[$attemptid] = ['timeclose' => 1200, 'timelimit' => 600, 'message' => 'Test2I', 'time1000state' => 'inprogress'];
// Multiple group overrides
- $quiz = $quiz_generator->create_instance(array('course'=>$course->id, 'timeclose'=>1200, 'timelimit'=>600));
- $DB->insert_record('quiz_overrides', array('quiz'=>$quiz->id, 'groupid'=>$group1->id, 'timeclose'=>1300, 'timelimit'=>501));
- $DB->insert_record('quiz_overrides', array('quiz'=>$quiz->id, 'groupid'=>$group2->id, 'timeclose'=>1301, 'timelimit'=>500));
- $attemptid = $DB->insert_record('quiz_attempts', array('quiz'=>$quiz->id, 'userid'=>$user1->id, 'state'=>'inprogress', 'timestart'=>100, 'timecheckstate'=>0, 'layout'=>'', 'uniqueid'=>$uniqueid++));
- $usertimes[$attemptid] = array('timeclose'=>1301, 'timelimit'=>501, '', 'message'=>'Test3A');
- $attemptid = $DB->insert_record('quiz_attempts', array('quiz'=>$quiz->id, 'userid'=>$user1->id, 'state'=>'inprogress', 'timestart'=>1000, 'timecheckstate'=>0, 'layout'=>'', 'uniqueid'=>$uniqueid++, 'attempt'=>1));
- $usertimes[$attemptid] = array('timeclose'=>1301, 'timelimit'=>501, '', 'message'=>'Test3B');
-
- $quiz = $quiz_generator->create_instance(array('course'=>$course->id, 'timeclose'=>1200, 'timelimit'=>600));
- $DB->insert_record('quiz_overrides', array('quiz'=>$quiz->id, 'groupid'=>$group1->id, 'timeclose'=>1301, 'timelimit'=>500));
- $DB->insert_record('quiz_overrides', array('quiz'=>$quiz->id, 'groupid'=>$group2->id, 'timeclose'=>1300, 'timelimit'=>501));
- $attemptid = $DB->insert_record('quiz_attempts', array('quiz'=>$quiz->id, 'userid'=>$user1->id, 'state'=>'inprogress', 'timestart'=>100, 'timecheckstate'=>0, 'layout'=>'', 'uniqueid'=>$uniqueid++));
- $usertimes[$attemptid] = array('timeclose'=>1301, 'timelimit'=>501, '', 'message'=>'Test3C');
- $attemptid = $DB->insert_record('quiz_attempts', array('quiz'=>$quiz->id, 'userid'=>$user1->id, 'state'=>'inprogress', 'timestart'=>1000, 'timecheckstate'=>0, 'layout'=>'', 'uniqueid'=>$uniqueid++, 'attempt'=>1));
- $usertimes[$attemptid] = array('timeclose'=>1301, 'timelimit'=>501, '', 'message'=>'Test3D');
-
- $quiz = $quiz_generator->create_instance(array('course'=>$course->id, 'timeclose'=>1200, 'timelimit'=>600));
- $DB->insert_record('quiz_overrides', array('quiz'=>$quiz->id, 'groupid'=>$group1->id, 'timeclose'=>1301, 'timelimit'=>500));
- $DB->insert_record('quiz_overrides', array('quiz'=>$quiz->id, 'groupid'=>$group2->id, 'timeclose'=>1300, 'timelimit'=>501));
- $DB->insert_record('quiz_overrides', array('quiz'=>$quiz->id, 'groupid'=>$group3->id, 'timeclose'=>1500, 'timelimit'=>1000)); // user not in group
- $attemptid = $DB->insert_record('quiz_attempts', array('quiz'=>$quiz->id, 'userid'=>$user1->id, 'state'=>'inprogress', 'timestart'=>100, 'timecheckstate'=>0, 'layout'=>'', 'uniqueid'=>$uniqueid++));
- $usertimes[$attemptid] = array('timeclose'=>1301, 'timelimit'=>501, '', 'message'=>'Test3E');
- $attemptid = $DB->insert_record('quiz_attempts', array('quiz'=>$quiz->id, 'userid'=>$user1->id, 'state'=>'inprogress', 'timestart'=>1000, 'timecheckstate'=>0, 'layout'=>'', 'uniqueid'=>$uniqueid++, 'attempt'=>1));
- $usertimes[$attemptid] = array('timeclose'=>1301, 'timelimit'=>501, '', 'message'=>'Test3F');
-
- $quiz = $quiz_generator->create_instance(array('course'=>$course->id, 'timeclose'=>1200, 'timelimit'=>600));
- $DB->insert_record('quiz_overrides', array('quiz'=>$quiz->id, 'groupid'=>$group1->id, 'timeclose'=>1300, 'timelimit'=>500));
- $DB->insert_record('quiz_overrides', array('quiz'=>$quiz->id, 'groupid'=>$group2->id, 'timeclose'=>null, 'timelimit'=>501));
- $attemptid = $DB->insert_record('quiz_attempts', array('quiz'=>$quiz->id, 'userid'=>$user1->id, 'state'=>'inprogress', 'timestart'=>100, 'timecheckstate'=>0, 'layout'=>'', 'uniqueid'=>$uniqueid++));
- $usertimes[$attemptid] = array('timeclose'=>1300, 'timelimit'=>501, '', 'message'=>'Test3G');
- $attemptid = $DB->insert_record('quiz_attempts', array('quiz'=>$quiz->id, 'userid'=>$user1->id, 'state'=>'inprogress', 'timestart'=>1000, 'timecheckstate'=>0, 'layout'=>'', 'uniqueid'=>$uniqueid++, 'attempt'=>1));
- $usertimes[$attemptid] = array('timeclose'=>1300, 'timelimit'=>501, '', 'message'=>'Test3H');
-
- $quiz = $quiz_generator->create_instance(array('course'=>$course->id, 'timeclose'=>1200, 'timelimit'=>600));
- $DB->insert_record('quiz_overrides', array('quiz'=>$quiz->id, 'groupid'=>$group1->id, 'timeclose'=>1300, 'timelimit'=>500));
- $DB->insert_record('quiz_overrides', array('quiz'=>$quiz->id, 'groupid'=>$group2->id, 'timeclose'=>1301, 'timelimit'=>null));
- $attemptid = $DB->insert_record('quiz_attempts', array('quiz'=>$quiz->id, 'userid'=>$user1->id, 'state'=>'inprogress', 'timestart'=>100, 'timecheckstate'=>0, 'layout'=>'', 'uniqueid'=>$uniqueid++));
- $usertimes[$attemptid] = array('timeclose'=>1301, 'timelimit'=>500, '', 'message'=>'Test3I');
- $attemptid = $DB->insert_record('quiz_attempts', array('quiz'=>$quiz->id, 'userid'=>$user1->id, 'state'=>'inprogress', 'timestart'=>1000, 'timecheckstate'=>0, 'layout'=>'', 'uniqueid'=>$uniqueid++, 'attempt'=>1));
- $usertimes[$attemptid] = array('timeclose'=>1301, 'timelimit'=>500, '', 'message'=>'Test3J');
-
- $quiz = $quiz_generator->create_instance(array('course'=>$course->id, 'timeclose'=>1200, 'timelimit'=>600));
- $DB->insert_record('quiz_overrides', array('quiz'=>$quiz->id, 'groupid'=>$group1->id, 'timeclose'=>1300, 'timelimit'=>500));
- $DB->insert_record('quiz_overrides', array('quiz'=>$quiz->id, 'groupid'=>$group2->id, 'timeclose'=>1301, 'timelimit'=>0));
- $attemptid = $DB->insert_record('quiz_attempts', array('quiz'=>$quiz->id, 'userid'=>$user1->id, 'state'=>'inprogress', 'timestart'=>100, 'timecheckstate'=>0, 'layout'=>'', 'uniqueid'=>$uniqueid++));
- $usertimes[$attemptid] = array('timeclose'=>1301, 'timelimit'=>0, '', 'message'=>'Test3K');
- $attemptid = $DB->insert_record('quiz_attempts', array('quiz'=>$quiz->id, 'userid'=>$user1->id, 'state'=>'inprogress', 'timestart'=>1000, 'timecheckstate'=>0, 'layout'=>'', 'uniqueid'=>$uniqueid++, 'attempt'=>1));
- $usertimes[$attemptid] = array('timeclose'=>1301, 'timelimit'=>0, '', 'message'=>'Test3L');
-
- $quiz = $quiz_generator->create_instance(array('course'=>$course->id, 'timeclose'=>1200, 'timelimit'=>600));
- $DB->insert_record('quiz_overrides', array('quiz'=>$quiz->id, 'groupid'=>$group1->id, 'timeclose'=>1300, 'timelimit'=>500));
- $DB->insert_record('quiz_overrides', array('quiz'=>$quiz->id, 'groupid'=>$group2->id, 'timeclose'=>0, 'timelimit'=>501));
- $attemptid = $DB->insert_record('quiz_attempts', array('quiz'=>$quiz->id, 'userid'=>$user1->id, 'state'=>'inprogress', 'timestart'=>100, 'timecheckstate'=>0, 'layout'=>'', 'uniqueid'=>$uniqueid++));
- $usertimes[$attemptid] = array('timeclose'=>0, 'timelimit'=>501, '', 'message'=>'Test3M');
- $attemptid = $DB->insert_record('quiz_attempts', array('quiz'=>$quiz->id, 'userid'=>$user1->id, 'state'=>'inprogress', 'timestart'=>1000, 'timecheckstate'=>0, 'layout'=>'', 'uniqueid'=>$uniqueid++, 'attempt'=>1));
- $usertimes[$attemptid] = array('timeclose'=>0, 'timelimit'=>501, '', 'message'=>'Test3N');
+ $quiz = $quizgenerator->create_instance(['course' => $course->id, 'timeclose' => 1200, 'timelimit' => 600]);
+ $DB->insert_record('quiz_overrides',
+ ['quiz' => $quiz->id, 'groupid' => $group1->id, 'timeclose' => 1300, 'timelimit' => 501]);
+ $DB->insert_record('quiz_overrides',
+ ['quiz' => $quiz->id, 'groupid' => $group2->id, 'timeclose' => 1301, 'timelimit' => 500]);
+ $attemptid = $DB->insert_record('quiz_attempts', ['quiz' => $quiz->id, 'userid' => $user1->id, 'state' => 'inprogress',
+ 'timestart' => 100, 'timecheckstate' => 0, 'layout' => '', 'uniqueid' => $this->usage_id($quiz)]);
+ $usertimes[$attemptid] = ['timeclose' => 1301, 'timelimit' => 501, 'message' => 'Test3A', 'time1000state' => 'finished'];
+ $attemptid = $DB->insert_record('quiz_attempts', ['quiz' => $quiz->id, 'userid' => $user1->id, 'state' => 'inprogress',
+ 'timestart' => 1000, 'timecheckstate' => 0, 'layout' => '', 'uniqueid' => $this->usage_id($quiz), 'attempt' => 1]);
+ $usertimes[$attemptid] = ['timeclose' => 1301, 'timelimit' => 501, 'message' => 'Test3B', 'time1000state' => 'inprogress'];
+
+ $quiz = $quizgenerator->create_instance(['course' => $course->id, 'timeclose' => 1200, 'timelimit' => 600]);
+ $DB->insert_record('quiz_overrides',
+ ['quiz' => $quiz->id, 'groupid' => $group1->id, 'timeclose' => 1301, 'timelimit' => 500]);
+ $DB->insert_record('quiz_overrides',
+ ['quiz' => $quiz->id, 'groupid' => $group2->id, 'timeclose' => 1300, 'timelimit' => 501]);
+ $attemptid = $DB->insert_record('quiz_attempts', ['quiz' => $quiz->id, 'userid' => $user1->id, 'state' => 'inprogress',
+ 'timestart' => 100, 'timecheckstate' => 0, 'layout' => '', 'uniqueid' => $this->usage_id($quiz)]);
+ $usertimes[$attemptid] = ['timeclose' => 1301, 'timelimit' => 501, 'message' => 'Test3C', 'time1000state' => 'finished'];
+ $attemptid = $DB->insert_record('quiz_attempts', ['quiz' => $quiz->id, 'userid' => $user1->id, 'state' => 'inprogress',
+ 'timestart' => 1000, 'timecheckstate' => 0, 'layout' => '', 'uniqueid' => $this->usage_id($quiz), 'attempt' => 1]);
+ $usertimes[$attemptid] = ['timeclose' => 1301, 'timelimit' => 501, 'message' => 'Test3D', 'time1000state' => 'inprogress'];
+
+ $quiz = $quizgenerator->create_instance(['course' => $course->id, 'timeclose' => 1200, 'timelimit' => 600,
+ 'overduehandling' => 'autoabandon']);
+ $DB->insert_record('quiz_overrides',
+ ['quiz' => $quiz->id, 'groupid' => $group1->id, 'timeclose' => 1301, 'timelimit' => 500]);
+ $DB->insert_record('quiz_overrides',
+ ['quiz' => $quiz->id, 'groupid' => $group2->id, 'timeclose' => 1300, 'timelimit' => 501]);
+ $DB->insert_record('quiz_overrides',
+ ['quiz' => $quiz->id, 'groupid' => $group3->id, 'timeclose' => 1500, 'timelimit' => 1000]); // User not in group.
+ $attemptid = $DB->insert_record('quiz_attempts', ['quiz' => $quiz->id, 'userid' => $user1->id, 'state' => 'inprogress',
+ 'timestart' => 100, 'timecheckstate' => 0, 'layout' => '', 'uniqueid' => $this->usage_id($quiz)]);
+ $usertimes[$attemptid] = ['timeclose' => 1301, 'timelimit' => 501, 'message' => 'Test3E', 'time1000state' => 'abandoned'];
+ $attemptid = $DB->insert_record('quiz_attempts', ['quiz' => $quiz->id, 'userid' => $user1->id, 'state' => 'inprogress',
+ 'timestart' => 1000, 'timecheckstate' => 0, 'layout' => '', 'uniqueid' => $this->usage_id($quiz), 'attempt' => 1]);
+ $usertimes[$attemptid] = ['timeclose' => 1301, 'timelimit' => 501, 'message' => 'Test3F', 'time1000state' => 'inprogress'];
+
+ $quiz = $quizgenerator->create_instance(['course' => $course->id, 'timeclose' => 1200, 'timelimit' => 600]);
+ $DB->insert_record('quiz_overrides',
+ ['quiz' => $quiz->id, 'groupid' => $group1->id, 'timeclose' => 1300, 'timelimit' => 500]);
+ $DB->insert_record('quiz_overrides',
+ ['quiz' => $quiz->id, 'groupid' => $group2->id, 'timeclose' => null, 'timelimit' => 501]);
+ $attemptid = $DB->insert_record('quiz_attempts', ['quiz' => $quiz->id, 'userid' => $user1->id, 'state' => 'inprogress',
+ 'timestart' => 100, 'timecheckstate' => 0, 'layout' => '', 'uniqueid' => $this->usage_id($quiz)]);
+ $usertimes[$attemptid] = ['timeclose' => 1300, 'timelimit' => 501, 'message' => 'Test3G', 'time1000state' => 'finished'];
+ $attemptid = $DB->insert_record('quiz_attempts', ['quiz' => $quiz->id, 'userid' => $user1->id, 'state' => 'inprogress',
+ 'timestart' => 1000, 'timecheckstate' => 0, 'layout' => '', 'uniqueid' => $this->usage_id($quiz), 'attempt' => 1]);
+ $usertimes[$attemptid] = ['timeclose' => 1300, 'timelimit' => 501, 'message' => 'Test3H', 'time1000state' => 'inprogress'];
+
+ $quiz = $quizgenerator->create_instance(['course' => $course->id, 'timeclose' => 1200, 'timelimit' => 600]);
+ $DB->insert_record('quiz_overrides',
+ ['quiz' => $quiz->id, 'groupid' => $group1->id, 'timeclose' => 1300, 'timelimit' => 500]);
+ $DB->insert_record('quiz_overrides',
+ ['quiz' => $quiz->id, 'groupid' => $group2->id, 'timeclose' => 1301, 'timelimit' => null]);
+ $attemptid = $DB->insert_record('quiz_attempts', ['quiz' => $quiz->id, 'userid' => $user1->id, 'state' => 'inprogress',
+ 'timestart' => 100, 'timecheckstate' => 0, 'layout' => '', 'uniqueid' => $this->usage_id($quiz)]);
+ $usertimes[$attemptid] = ['timeclose' => 1301, 'timelimit' => 500, 'message' => 'Test3I', 'time1000state' => 'finished'];
+ $attemptid = $DB->insert_record('quiz_attempts', ['quiz' => $quiz->id, 'userid' => $user1->id, 'state' => 'inprogress',
+ 'timestart' => 1000, 'timecheckstate' => 0, 'layout' => '', 'uniqueid' => $this->usage_id($quiz), 'attempt' => 1]);
+ $usertimes[$attemptid] = ['timeclose' => 1301, 'timelimit' => 500, 'message' => 'Test3J', 'time1000state' => 'inprogress'];
+
+ $quiz = $quizgenerator->create_instance(['course' => $course->id, 'timeclose' => 1200, 'timelimit' => 600]);
+ $DB->insert_record('quiz_overrides',
+ ['quiz' => $quiz->id, 'groupid' => $group1->id, 'timeclose' => 1300, 'timelimit' => 500]);
+ $DB->insert_record('quiz_overrides',
+ ['quiz' => $quiz->id, 'groupid' => $group2->id, 'timeclose' => 1301, 'timelimit' => 0]);
+ $attemptid = $DB->insert_record('quiz_attempts', ['quiz' => $quiz->id, 'userid' => $user1->id, 'state' => 'inprogress',
+ 'timestart' => 100, 'timecheckstate' => 0, 'layout' => '', 'uniqueid' => $this->usage_id($quiz)]);
+ $usertimes[$attemptid] = ['timeclose' => 1301, 'timelimit' => 0, 'message' => 'Test3K', 'time1000state' => 'inprogress'];
+ $attemptid = $DB->insert_record('quiz_attempts', ['quiz' => $quiz->id, 'userid' => $user1->id, 'state' => 'inprogress',
+ 'timestart' => 1000, 'timecheckstate' => 0, 'layout' => '', 'uniqueid' => $this->usage_id($quiz), 'attempt' => 1]);
+ $usertimes[$attemptid] = ['timeclose' => 1301, 'timelimit' => 0, 'message' => 'Test3L', 'time1000state' => 'inprogress'];
+
+ $quiz = $quizgenerator->create_instance(['course' => $course->id, 'timeclose' => 1200, 'timelimit' => 600]);
+ $DB->insert_record('quiz_overrides',
+ ['quiz' => $quiz->id, 'groupid' => $group1->id, 'timeclose' => 1300, 'timelimit' => 500]);
+ $DB->insert_record('quiz_overrides',
+ ['quiz' => $quiz->id, 'groupid' => $group2->id, 'timeclose' => 0, 'timelimit' => 501]);
+ $attemptid = $DB->insert_record('quiz_attempts', ['quiz' => $quiz->id, 'userid' => $user1->id, 'state' => 'inprogress',
+ 'timestart' => 100, 'timecheckstate' => 0, 'layout' => '', 'uniqueid' => $this->usage_id($quiz)]);
+ $usertimes[$attemptid] = ['timeclose' => 0, 'timelimit' => 501, 'message' => 'Test3M', 'time1000state' => 'finished'];
+ $attemptid = $DB->insert_record('quiz_attempts', ['quiz' => $quiz->id, 'userid' => $user1->id, 'state' => 'inprogress',
+ 'timestart' => 1000, 'timecheckstate' => 0, 'layout' => '', 'uniqueid' => $this->usage_id($quiz), 'attempt' => 1]);
+ $usertimes[$attemptid] = ['timeclose' => 0, 'timelimit' => 501, 'message' => 'Test3N', 'time1000state' => 'inprogress'];
// User overrides
- $quiz = $quiz_generator->create_instance(array('course'=>$course->id, 'timeclose'=>1200, 'timelimit'=>600));
- $DB->insert_record('quiz_overrides', array('quiz'=>$quiz->id, 'groupid'=>$group1->id, 'timeclose'=>1300, 'timelimit'=>700));
- $DB->insert_record('quiz_overrides', array('quiz'=>$quiz->id, 'userid'=>$user1->id, 'timeclose'=>1201, 'timelimit'=>601));
- $attemptid = $DB->insert_record('quiz_attempts', array('quiz'=>$quiz->id, 'userid'=>$user1->id, 'state'=>'inprogress', 'timestart'=>100, 'timecheckstate'=>0, 'layout'=>'', 'uniqueid'=>$uniqueid++));
- $usertimes[$attemptid] = array('timeclose'=>1201, 'timelimit'=>601, '', 'message'=>'Test4A');
- $attemptid = $DB->insert_record('quiz_attempts', array('quiz'=>$quiz->id, 'userid'=>$user1->id, 'state'=>'inprogress', 'timestart'=>1000, 'timecheckstate'=>0, 'layout'=>'', 'uniqueid'=>$uniqueid++, 'attempt'=>1));
- $usertimes[$attemptid] = array('timeclose'=>1201, 'timelimit'=>601, '', 'message'=>'Test4B');
-
- $quiz = $quiz_generator->create_instance(array('course'=>$course->id, 'timeclose'=>1200, 'timelimit'=>600));
- $DB->insert_record('quiz_overrides', array('quiz'=>$quiz->id, 'groupid'=>$group1->id, 'timeclose'=>1300, 'timelimit'=>700));
- $DB->insert_record('quiz_overrides', array('quiz'=>$quiz->id, 'userid'=>$user1->id, 'timeclose'=>0, 'timelimit'=>601));
- $attemptid = $DB->insert_record('quiz_attempts', array('quiz'=>$quiz->id, 'userid'=>$user1->id, 'state'=>'inprogress', 'timestart'=>100, 'timecheckstate'=>0, 'layout'=>'', 'uniqueid'=>$uniqueid++));
- $usertimes[$attemptid] = array('timeclose'=>0, 'timelimit'=>601, '', 'message'=>'Test4C');
- $attemptid = $DB->insert_record('quiz_attempts', array('quiz'=>$quiz->id, 'userid'=>$user1->id, 'state'=>'inprogress', 'timestart'=>1000, 'timecheckstate'=>0, 'layout'=>'', 'uniqueid'=>$uniqueid++, 'attempt'=>1));
- $usertimes[$attemptid] = array('timeclose'=>0, 'timelimit'=>601, '', 'message'=>'Test4D');
-
- $quiz = $quiz_generator->create_instance(array('course'=>$course->id, 'timeclose'=>1200, 'timelimit'=>600));
- $DB->insert_record('quiz_overrides', array('quiz'=>$quiz->id, 'groupid'=>$group1->id, 'timeclose'=>1300, 'timelimit'=>700));
- $DB->insert_record('quiz_overrides', array('quiz'=>$quiz->id, 'userid'=>$user1->id, 'timeclose'=>1201, 'timelimit'=>0));
- $attemptid = $DB->insert_record('quiz_attempts', array('quiz'=>$quiz->id, 'userid'=>$user1->id, 'state'=>'inprogress', 'timestart'=>100, 'timecheckstate'=>0, 'layout'=>'', 'uniqueid'=>$uniqueid++));
- $usertimes[$attemptid] = array('timeclose'=>1201, 'timelimit'=>0, '', 'message'=>'Test4E');
- $attemptid = $DB->insert_record('quiz_attempts', array('quiz'=>$quiz->id, 'userid'=>$user1->id, 'state'=>'inprogress', 'timestart'=>1000, 'timecheckstate'=>0, 'layout'=>'', 'uniqueid'=>$uniqueid++, 'attempt'=>1));
- $usertimes[$attemptid] = array('timeclose'=>1201, 'timelimit'=>0, '', 'message'=>'Test4F');
-
- $quiz = $quiz_generator->create_instance(array('course'=>$course->id, 'timeclose'=>1200, 'timelimit'=>600));
- $DB->insert_record('quiz_overrides', array('quiz'=>$quiz->id, 'groupid'=>$group1->id, 'timeclose'=>1300, 'timelimit'=>700));
- $DB->insert_record('quiz_overrides', array('quiz'=>$quiz->id, 'userid'=>$user1->id, 'timeclose'=>null, 'timelimit'=>601));
- $attemptid = $DB->insert_record('quiz_attempts', array('quiz'=>$quiz->id, 'userid'=>$user1->id, 'state'=>'inprogress', 'timestart'=>100, 'timecheckstate'=>0, 'layout'=>'', 'uniqueid'=>$uniqueid++));
- $usertimes[$attemptid] = array('timeclose'=>1300, 'timelimit'=>601, '', 'message'=>'Test4G');
- $attemptid = $DB->insert_record('quiz_attempts', array('quiz'=>$quiz->id, 'userid'=>$user1->id, 'state'=>'inprogress', 'timestart'=>1000, 'timecheckstate'=>0, 'layout'=>'', 'uniqueid'=>$uniqueid++, 'attempt'=>1));
- $usertimes[$attemptid] = array('timeclose'=>1300, 'timelimit'=>601, '', 'message'=>'Test4H');
-
- $quiz = $quiz_generator->create_instance(array('course'=>$course->id, 'timeclose'=>1200, 'timelimit'=>600));
- $DB->insert_record('quiz_overrides', array('quiz'=>$quiz->id, 'groupid'=>$group1->id, 'timeclose'=>null, 'timelimit'=>700));
- $DB->insert_record('quiz_overrides', array('quiz'=>$quiz->id, 'userid'=>$user1->id, 'timeclose'=>null, 'timelimit'=>601));
- $attemptid = $DB->insert_record('quiz_attempts', array('quiz'=>$quiz->id, 'userid'=>$user1->id, 'state'=>'inprogress', 'timestart'=>100, 'timecheckstate'=>0, 'layout'=>'', 'uniqueid'=>$uniqueid++));
- $usertimes[$attemptid] = array('timeclose'=>1200, 'timelimit'=>601, '', 'message'=>'Test4I');
- $attemptid = $DB->insert_record('quiz_attempts', array('quiz'=>$quiz->id, 'userid'=>$user1->id, 'state'=>'inprogress', 'timestart'=>1000, 'timecheckstate'=>0, 'layout'=>'', 'uniqueid'=>$uniqueid++, 'attempt'=>1));
- $usertimes[$attemptid] = array('timeclose'=>1200, 'timelimit'=>601, '', 'message'=>'Test4J');
-
- $quiz = $quiz_generator->create_instance(array('course'=>$course->id, 'timeclose'=>1200, 'timelimit'=>600));
- $DB->insert_record('quiz_overrides', array('quiz'=>$quiz->id, 'groupid'=>$group1->id, 'timeclose'=>1300, 'timelimit'=>700));
- $DB->insert_record('quiz_overrides', array('quiz'=>$quiz->id, 'userid'=>$user1->id, 'timeclose'=>1201, 'timelimit'=>null));
- $attemptid = $DB->insert_record('quiz_attempts', array('quiz'=>$quiz->id, 'userid'=>$user1->id, 'state'=>'inprogress', 'timestart'=>100, 'timecheckstate'=>0, 'layout'=>'', 'uniqueid'=>$uniqueid++));
- $usertimes[$attemptid] = array('timeclose'=>1201, 'timelimit'=>700, '', 'message'=>'Test4K');
- $attemptid = $DB->insert_record('quiz_attempts', array('quiz'=>$quiz->id, 'userid'=>$user1->id, 'state'=>'inprogress', 'timestart'=>1000, 'timecheckstate'=>0, 'layout'=>'', 'uniqueid'=>$uniqueid++, 'attempt'=>1));
- $usertimes[$attemptid] = array('timeclose'=>1201, 'timelimit'=>700, '', 'message'=>'Test4L');
-
- $quiz = $quiz_generator->create_instance(array('course'=>$course->id, 'timeclose'=>1200, 'timelimit'=>600));
- $DB->insert_record('quiz_overrides', array('quiz'=>$quiz->id, 'groupid'=>$group1->id, 'timeclose'=>1300, 'timelimit'=>null));
- $DB->insert_record('quiz_overrides', array('quiz'=>$quiz->id, 'userid'=>$user1->id, 'timeclose'=>1201, 'timelimit'=>null));
- $attemptid = $DB->insert_record('quiz_attempts', array('quiz'=>$quiz->id, 'userid'=>$user1->id, 'state'=>'inprogress', 'timestart'=>100, 'timecheckstate'=>0, 'layout'=>'', 'uniqueid'=>$uniqueid++));
- $usertimes[$attemptid] = array('timeclose'=>1201, 'timelimit'=>600, '', 'message'=>'Test4M');
- $attemptid = $DB->insert_record('quiz_attempts', array('quiz'=>$quiz->id, 'userid'=>$user1->id, 'state'=>'inprogress', 'timestart'=>1000, 'timecheckstate'=>0, 'layout'=>'', 'uniqueid'=>$uniqueid++, 'attempt'=>1));
- $usertimes[$attemptid] = array('timeclose'=>1201, 'timelimit'=>600, '', 'message'=>'Test4N');
-
- $quiz = $quiz_generator->create_instance(array('course'=>$course->id, 'timeclose'=>1200, 'timelimit'=>600));
- $DB->insert_record('quiz_overrides', array('quiz'=>$quiz->id, 'groupid'=>$group1->id, 'timeclose'=>1300, 'timelimit'=>700));
- $DB->insert_record('quiz_overrides', array('quiz'=>$quiz->id, 'userid'=>0, 'timeclose'=>1201, 'timelimit'=>601)); // not user
- $attemptid = $DB->insert_record('quiz_attempts', array('quiz'=>$quiz->id, 'userid'=>$user1->id, 'state'=>'inprogress', 'timestart'=>100, 'timecheckstate'=>0, 'layout'=>'', 'uniqueid'=>$uniqueid++));
- $usertimes[$attemptid] = array('timeclose'=>1300, 'timelimit'=>700, '', 'message'=>'Test4O');
- $attemptid = $DB->insert_record('quiz_attempts', array('quiz'=>$quiz->id, 'userid'=>$user1->id, 'state'=>'inprogress', 'timestart'=>1000, 'timecheckstate'=>0, 'layout'=>'', 'uniqueid'=>$uniqueid++, 'attempt'=>1));
- $usertimes[$attemptid] = array('timeclose'=>1300, 'timelimit'=>700, '', 'message'=>'Test4P');
+ $quiz = $quizgenerator->create_instance(['course' => $course->id, 'timeclose' => 1200, 'timelimit' => 600]);
+ $DB->insert_record('quiz_overrides',
+ ['quiz' => $quiz->id, 'groupid' => $group1->id, 'timeclose' => 1300, 'timelimit' => 700]);
+ $DB->insert_record('quiz_overrides',
+ ['quiz' => $quiz->id, 'userid' => $user1->id, 'timeclose' => 1201, 'timelimit' => 601]);
+ $attemptid = $DB->insert_record('quiz_attempts', ['quiz' => $quiz->id, 'userid' => $user1->id, 'state' => 'inprogress',
+ 'timestart' => 100, 'timecheckstate' => 0, 'layout' => '', 'uniqueid' => $this->usage_id($quiz)]);
+ $usertimes[$attemptid] = ['timeclose' => 1201, 'timelimit' => 601, 'message' => 'Test4A', 'time1000state' => 'finished'];
+ $attemptid = $DB->insert_record('quiz_attempts', ['quiz' => $quiz->id, 'userid' => $user1->id, 'state' => 'inprogress',
+ 'timestart' => 1000, 'timecheckstate' => 0, 'layout' => '', 'uniqueid' => $this->usage_id($quiz), 'attempt' => 1]);
+ $usertimes[$attemptid] = ['timeclose' => 1201, 'timelimit' => 601, 'message' => 'Test4B', 'time1000state' => 'inprogress'];
+
+ $quiz = $quizgenerator->create_instance(['course' => $course->id, 'timeclose' => 1200, 'timelimit' => 600]);
+ $DB->insert_record('quiz_overrides',
+ ['quiz' => $quiz->id, 'groupid' => $group1->id, 'timeclose' => 1300, 'timelimit' => 700]);
+ $DB->insert_record('quiz_overrides',
+ ['quiz' => $quiz->id, 'userid' => $user1->id, 'timeclose' => 0, 'timelimit' => 601]);
+ $attemptid = $DB->insert_record('quiz_attempts', ['quiz' => $quiz->id, 'userid' => $user1->id, 'state' => 'inprogress',
+ 'timestart' => 100, 'timecheckstate' => 0, 'layout' => '', 'uniqueid' => $this->usage_id($quiz)]);
+ $usertimes[$attemptid] = ['timeclose' => 0, 'timelimit' => 601, 'message' => 'Test4C', 'time1000state' => 'finished'];
+ $attemptid = $DB->insert_record('quiz_attempts', ['quiz' => $quiz->id, 'userid' => $user1->id, 'state' => 'inprogress',
+ 'timestart' => 1000, 'timecheckstate' => 0, 'layout' => '', 'uniqueid' => $this->usage_id($quiz), 'attempt' => 1]);
+ $usertimes[$attemptid] = ['timeclose' => 0, 'timelimit' => 601, 'message' => 'Test4D', 'time1000state' => 'inprogress'];
+
+ $quiz = $quizgenerator->create_instance(['course' => $course->id, 'timeclose' => 1200, 'timelimit' => 600]);
+ $DB->insert_record('quiz_overrides',
+ ['quiz' => $quiz->id, 'groupid' => $group1->id, 'timeclose' => 1300, 'timelimit' => 700]);
+ $DB->insert_record('quiz_overrides',
+ ['quiz' => $quiz->id, 'userid' => $user1->id, 'timeclose' => 1201, 'timelimit' => 0]);
+ $attemptid = $DB->insert_record('quiz_attempts', ['quiz' => $quiz->id, 'userid' => $user1->id, 'state' => 'inprogress',
+ 'timestart' => 100, 'timecheckstate' => 0, 'layout' => '', 'uniqueid' => $this->usage_id($quiz)]);
+ $usertimes[$attemptid] = ['timeclose' => 1201, 'timelimit' => 0, 'message' => 'Test4E', 'time1000state' => 'inprogress'];
+ $attemptid = $DB->insert_record('quiz_attempts', ['quiz' => $quiz->id, 'userid' => $user1->id, 'state' => 'inprogress',
+ 'timestart' => 1000, 'timecheckstate' => 0, 'layout' => '', 'uniqueid' => $this->usage_id($quiz), 'attempt' => 1]);
+ $usertimes[$attemptid] = ['timeclose' => 1201, 'timelimit' => 0, 'message' => 'Test4F', 'time1000state' => 'inprogress'];
+
+ $quiz = $quizgenerator->create_instance(['course' => $course->id, 'timeclose' => 1200, 'timelimit' => 600,
+ 'overduehandling' => 'autoabandon']);
+ $DB->insert_record('quiz_overrides',
+ ['quiz' => $quiz->id, 'groupid' => $group1->id, 'timeclose' => 1300, 'timelimit' => 700]);
+ $DB->insert_record('quiz_overrides',
+ ['quiz' => $quiz->id, 'userid' => $user1->id, 'timeclose' => null, 'timelimit' => 601]);
+ $attemptid = $DB->insert_record('quiz_attempts', ['quiz' => $quiz->id, 'userid' => $user1->id, 'state' => 'inprogress',
+ 'timestart' => 100, 'timecheckstate' => 0, 'layout' => '', 'uniqueid' => $this->usage_id($quiz)]);
+ $usertimes[$attemptid] = ['timeclose' => 1300, 'timelimit' => 601, 'message' => 'Test4G', 'time1000state' => 'abandoned'];
+ $attemptid = $DB->insert_record('quiz_attempts', ['quiz' => $quiz->id, 'userid' => $user1->id, 'state' => 'inprogress',
+ 'timestart' => 1000, 'timecheckstate' => 0, 'layout' => '', 'uniqueid' => $this->usage_id($quiz), 'attempt' => 1]);
+ $usertimes[$attemptid] = ['timeclose' => 1300, 'timelimit' => 601, 'message' => 'Test4H', 'time1000state' => 'inprogress'];
+
+ $quiz = $quizgenerator->create_instance(['course' => $course->id, 'timeclose' => 1200, 'timelimit' => 600]);
+ $DB->insert_record('quiz_overrides',
+ ['quiz' => $quiz->id, 'groupid' => $group1->id, 'timeclose' => null, 'timelimit' => 700]);
+ $DB->insert_record('quiz_overrides',
+ ['quiz' => $quiz->id, 'userid' => $user1->id, 'timeclose' => null, 'timelimit' => 601]);
+ $attemptid = $DB->insert_record('quiz_attempts', ['quiz' => $quiz->id, 'userid' => $user1->id, 'state' => 'inprogress',
+ 'timestart' => 100, 'timecheckstate' => 0, 'layout' => '', 'uniqueid' => $this->usage_id($quiz)]);
+ $usertimes[$attemptid] = ['timeclose' => 1200, 'timelimit' => 601, 'message' => 'Test4I', 'time1000state' => 'finished'];
+ $attemptid = $DB->insert_record('quiz_attempts', ['quiz' => $quiz->id, 'userid' => $user1->id, 'state' => 'inprogress',
+ 'timestart' => 1000, 'timecheckstate' => 0, 'layout' => '', 'uniqueid' => $this->usage_id($quiz), 'attempt' => 1]);
+ $usertimes[$attemptid] = ['timeclose' => 1200, 'timelimit' => 601, 'message' => 'Test4J', 'time1000state' => 'inprogress'];
+
+ $quiz = $quizgenerator->create_instance(['course' => $course->id, 'timeclose' => 1200, 'timelimit' => 600]);
+ $DB->insert_record('quiz_overrides',
+ ['quiz' => $quiz->id, 'groupid' => $group1->id, 'timeclose' => 1300, 'timelimit' => 700]);
+ $DB->insert_record('quiz_overrides',
+ ['quiz' => $quiz->id, 'userid' => $user1->id, 'timeclose' => 1201, 'timelimit' => null]);
+ $attemptid = $DB->insert_record('quiz_attempts', ['quiz' => $quiz->id, 'userid' => $user1->id, 'state' => 'inprogress',
+ 'timestart' => 100, 'timecheckstate' => 0, 'layout' => '', 'uniqueid' => $this->usage_id($quiz)]);
+ $usertimes[$attemptid] = ['timeclose' => 1201, 'timelimit' => 700, 'message' => 'Test4K', 'time1000state' => 'finished'];
+ $attemptid = $DB->insert_record('quiz_attempts', ['quiz' => $quiz->id, 'userid' => $user1->id, 'state' => 'inprogress',
+ 'timestart' => 1000, 'timecheckstate' => 0, 'layout' => '', 'uniqueid' => $this->usage_id($quiz), 'attempt' => 1]);
+ $usertimes[$attemptid] = ['timeclose' => 1201, 'timelimit' => 700, 'message' => 'Test4L', 'time1000state' => 'inprogress'];
+
+ $quiz = $quizgenerator->create_instance(['course' => $course->id, 'timeclose' => 1200, 'timelimit' => 600]);
+ $DB->insert_record('quiz_overrides',
+ ['quiz' => $quiz->id, 'groupid' => $group1->id, 'timeclose' => 1300, 'timelimit' => null]);
+ $DB->insert_record('quiz_overrides',
+ ['quiz' => $quiz->id, 'userid' => $user1->id, 'timeclose' => 1201, 'timelimit' => null]);
+ $attemptid = $DB->insert_record('quiz_attempts', ['quiz' => $quiz->id, 'userid' => $user1->id, 'state' => 'inprogress',
+ 'timestart' => 100, 'timecheckstate' => 0, 'layout' => '', 'uniqueid' => $this->usage_id($quiz)]);
+ $usertimes[$attemptid] = ['timeclose' => 1201, 'timelimit' => 600, 'message' => 'Test4M', 'time1000state' => 'finished'];
+ $attemptid = $DB->insert_record('quiz_attempts', ['quiz' => $quiz->id, 'userid' => $user1->id, 'state' => 'inprogress',
+ 'timestart' => 1000, 'timecheckstate' => 0, 'layout' => '', 'uniqueid' => $this->usage_id($quiz), 'attempt' => 1]);
+ $usertimes[$attemptid] = ['timeclose' => 1201, 'timelimit' => 600, 'message' => 'Test4N', 'time1000state' => 'inprogress'];
+
+ $quiz = $quizgenerator->create_instance(['course' => $course->id, 'timeclose' => 1200, 'timelimit' => 600]);
+ $DB->insert_record('quiz_overrides',
+ ['quiz' => $quiz->id, 'groupid' => $group1->id, 'timeclose' => 1300, 'timelimit' => 700]);
+ $DB->insert_record('quiz_overrides',
+ ['quiz' => $quiz->id, 'userid' => 0, 'timeclose' => 1201, 'timelimit' => 601]); // Not user.
+ $attemptid = $DB->insert_record('quiz_attempts', ['quiz' => $quiz->id, 'userid' => $user1->id, 'state' => 'inprogress',
+ 'timestart' => 100, 'timecheckstate' => 0, 'layout' => '', 'uniqueid' => $this->usage_id($quiz)]);
+ $usertimes[$attemptid] = ['timeclose' => 1300, 'timelimit' => 700, 'message' => 'Test4O', 'time1000state' => 'finished'];
+ $attemptid = $DB->insert_record('quiz_attempts', ['quiz' => $quiz->id, 'userid' => $user1->id, 'state' => 'inprogress',
+ 'timestart' => 1000, 'timecheckstate' => 0, 'layout' => '', 'uniqueid' => $this->usage_id($quiz), 'attempt' => 1]);
+ $usertimes[$attemptid] = ['timeclose' => 1300, 'timelimit' => 700, 'message' => 'Test4P', 'time1000state' => 'inprogress'];
// Attempt state overdue
- $quiz = $quiz_generator->create_instance(array('course'=>$course->id, 'timeclose'=>1200, 'timelimit'=>600, 'overduehandling'=>'graceperiod', 'graceperiod'=>250));
- $attemptid = $DB->insert_record('quiz_attempts', array('quiz'=>$quiz->id, 'userid'=>$user1->id, 'state'=>'overdue', 'timestart'=>100, 'timecheckstate'=>0, 'layout'=>'', 'uniqueid'=>$uniqueid++));
- $usertimes[$attemptid] = array('timeclose'=>1200, 'timelimit'=>600, '', 'message'=>'Test5A');
+ $quiz = $quizgenerator->create_instance(['course' => $course->id, 'timeclose' => 1200, 'timelimit' => 600,
+ 'overduehandling' => 'graceperiod', 'graceperiod' => 250]);
+ $attemptid = $DB->insert_record('quiz_attempts', ['quiz' => $quiz->id, 'userid' => $user1->id, 'state' => 'overdue',
+ 'timestart' => 100, 'timecheckstate' => 0, 'layout' => '', 'uniqueid' => $this->usage_id($quiz)]);
+ $usertimes[$attemptid] = ['timeclose' => 1200, 'timelimit' => 600, 'message' => 'Test5A', 'time1000state' => 'overdue'];
+
+ $quiz = $quizgenerator->create_instance(['course' => $course->id, 'timeclose' => 0, 'timelimit' => 600,
+ 'overduehandling' => 'graceperiod', 'graceperiod' => 250]);
+ $attemptid = $DB->insert_record('quiz_attempts', ['quiz' => $quiz->id, 'userid' => $user1->id, 'state' => 'overdue',
+ 'timestart' => 100, 'timecheckstate' => 0, 'layout' => '', 'uniqueid' => $this->usage_id($quiz)]);
+ $usertimes[$attemptid] = ['timeclose' => 0, 'timelimit' => 600, 'message' => 'Test5B', 'time1000state' => 'overdue'];
+
+ // Compute expected end time for each attempt.
+ foreach ($usertimes as $attemptid => $times) {
+ $attempt = $DB->get_record('quiz_attempts', ['id' => $attemptid], '*', MUST_EXIST);
- $quiz = $quiz_generator->create_instance(array('course'=>$course->id, 'timeclose'=>0, 'timelimit'=>600, 'overduehandling'=>'graceperiod', 'graceperiod'=>250));
- $attemptid = $DB->insert_record('quiz_attempts', array('quiz'=>$quiz->id, 'userid'=>$user1->id, 'state'=>'overdue', 'timestart'=>100, 'timecheckstate'=>0, 'layout'=>'', 'uniqueid'=>$uniqueid++));
- $usertimes[$attemptid] = array('timeclose'=>0, 'timelimit'=>600, '', 'message'=>'Test5B');
+ if ($times['timeclose'] > 0 && $times['timelimit'] > 0) {
+ $usertimes[$attemptid]['timedue'] = min($times['timeclose'], $attempt->timestart + $times['timelimit']);
+ } else if ($times['timeclose'] > 0) {
+ $usertimes[$attemptid]['timedue'] = $times['timeclose'];
+ } else if ($times['timelimit'] > 0) {
+ $usertimes[$attemptid]['timedue'] = $attempt->timestart + $times['timelimit'];
+ }
+ }
//
- // Test quiz_update_open_attempts()
+ // Test quiz_update_open_attempts().
//
- quiz_update_open_attempts(array('courseid'=>$course->id));
- foreach ($usertimes as $attemptid=>$times) {
- $attempt = $DB->get_record('quiz_attempts', array('id'=>$attemptid));
- $this->assertTrue(false !== $attempt, $times['message']);
+ quiz_update_open_attempts(['courseid' => $course->id]);
+ foreach ($usertimes as $attemptid => $times) {
+ $attempt = $DB->get_record('quiz_attempts', ['id' => $attemptid], '*', MUST_EXIST);
if ($attempt->state == 'overdue') {
- $graceperiod = $DB->get_field('quiz', 'graceperiod', array('id'=>$attempt->quiz));
+ $graceperiod = $DB->get_field('quiz', 'graceperiod', ['id' => $attempt->quiz]);
} else {
$graceperiod = 0;
}
- if ($times['timeclose'] > 0 and $times['timelimit'] > 0) {
- $this->assertEquals(min($times['timeclose'], $attempt->timestart + $times['timelimit']) + $graceperiod, $attempt->timecheckstate, $times['message']);
- } else if ($times['timeclose'] > 0) {
- $this->assertEquals($times['timeclose'] + $graceperiod, $attempt->timecheckstate <= $times['timeclose'], $times['message']);
- } else if ($times['timelimit'] > 0) {
- $this->assertEquals($attempt->timestart + $times['timelimit'] + $graceperiod, $attempt->timecheckstate, $times['message']);
+ if (isset($times['timedue'])) {
+ $this->assertEquals($times['timedue'] + $graceperiod, $attempt->timecheckstate, $times['message']);
} else {
$this->assertNull($attempt->timecheckstate, $times['message']);
}
}
//
- // Test get_list_of_overdue_attempts()
+ // Test get_list_of_overdue_attempts().
//
$overduehander = new mod_quiz_overdue_attempt_updater();
$attempts->close();
$this->assertEquals(0, $count);
+ //
+ // Test update_overdue_attempts().
+ //
+
+ [$count, $quizcount] = $overduehander->update_overdue_attempts(1000, 940);
+
+ $attempts = $DB->get_records('quiz_attempts', null, 'quiz, userid, attempt',
+ 'id, quiz, userid, attempt, state, timestart, timefinish, timecheckstate');
+ foreach ($attempts as $attempt) {
+ $this->assertTrue(isset($usertimes[$attempt->id]));
+ $times = $usertimes[$attempt->id];
+ $this->assertEquals($times['time1000state'], $attempt->state, $times['message']);
+ switch ($times['time1000state']) {
+ case 'finished':
+ $this->assertEquals($times['timedue'], $attempt->timefinish, $times['message']);
+ $this->assertNull($attempt->timecheckstate, $times['message']);
+ break;
+
+ case 'overdue':
+ $this->assertEquals(0, $attempt->timefinish, $times['message']);
+ $graceperiod = $DB->get_field('quiz', 'graceperiod', ['id' => $attempt->quiz]);
+ $this->assertEquals($times['timedue'] + $graceperiod, $attempt->timecheckstate, $times['message']);
+ break;
+
+ case 'abandoned':
+ $this->assertEquals(0, $attempt->timefinish, $times['message']);
+ $this->assertNull($attempt->timecheckstate, $times['message']);
+ break;
+ }
+ }
+
+ $this->assertEquals(19, $count);
+ $this->assertEquals(19, $quizcount);
+ }
+
+ /**
+ * Make any old question usage for a quiz.
+ *
+ * The attempts used in test_bulk_update_functions must have some
+ * question usage to store in uniqueid, but they don't have to be
+ * very realistic.
+ *
+ * @param stdClass $quiz
+ * @return int question usage id.
+ */
+ protected function usage_id(stdClass $quiz): int {
+ $quba = question_engine::make_questions_usage_by_activity('mod_quiz',
+ context_module::instance($quiz->cmid));
+ $quba->set_preferred_behaviour('deferredfeedback');
+ question_engine::save_questions_usage_by_activity($quba);
+ return $quba->get_id();
}
/**
* Test the group event handlers
*/
public function test_group_event_handlers() {
- global $DB,$CFG;
+ global $DB;
$this->resetAfterTest();
$course = $this->getDataGenerator()->create_course();
$user1 = $this->getDataGenerator()->create_user();
- $studentrole = $DB->get_record('role', array('shortname'=>'student'));
+ $studentrole = $DB->get_record('role', ['shortname' => 'student']);
$this->assertNotEmpty($studentrole);
$this->assertTrue(enrol_try_internal_enrol($course->id, $user1->id, $studentrole->id));
- $group1 = $this->getDataGenerator()->create_group(array('courseid'=>$course->id));
- $group2 = $this->getDataGenerator()->create_group(array('courseid'=>$course->id));
+ $group1 = $this->getDataGenerator()->create_group(['courseid' => $course->id]);
+ $group2 = $this->getDataGenerator()->create_group(['courseid' => $course->id]);
$this->assertTrue(groups_add_member($group1, $user1));
$this->assertTrue(groups_add_member($group2, $user1));
- $uniqueid = 0;
-
- $quiz_generator = $this->getDataGenerator()->get_plugin_generator('mod_quiz');
+ /** @var mod_quiz_generator $quizgenerator */
+ $quizgenerator = $this->getDataGenerator()->get_plugin_generator('mod_quiz');
- $quiz = $quiz_generator->create_instance(array('course'=>$course->id, 'timeclose'=>1200, 'timelimit'=>0));
+ $quiz = $quizgenerator->create_instance(['course' => $course->id, 'timeclose' => 1200, 'timelimit' => 0]);
// add a group1 override
- $DB->insert_record('quiz_overrides', array('quiz'=>$quiz->id, 'groupid'=>$group1->id, 'timeclose'=>1300, 'timelimit'=>null));
+ $DB->insert_record('quiz_overrides',
+ ['quiz' => $quiz->id, 'groupid' => $group1->id, 'timeclose' => 1300, 'timelimit' => null]);
// add an attempt
- $attemptid = $DB->insert_record('quiz_attempts', array('quiz'=>$quiz->id, 'userid'=>$user1->id, 'state'=>'inprogress', 'timestart'=>100, 'timecheckstate'=>0, 'layout'=>'', 'uniqueid'=>$uniqueid++));
+ $attemptid = $DB->insert_record('quiz_attempts', ['quiz' => $quiz->id, 'userid' => $user1->id, 'state' => 'inprogress',
+ 'timestart' => 100, 'timecheckstate' => 0, 'layout' => '', 'uniqueid' => $this->usage_id($quiz)]);
// update timecheckstate
- quiz_update_open_attempts(array('quizid'=>$quiz->id));
- $this->assertEquals(1300, $DB->get_field('quiz_attempts', 'timecheckstate', array('id'=>$attemptid)));
+ quiz_update_open_attempts(['quizid' => $quiz->id]);
+ $this->assertEquals(1300, $DB->get_field('quiz_attempts', 'timecheckstate', ['id' => $attemptid]));
// remove from group
$this->assertTrue(groups_remove_member($group1, $user1));
- $this->assertEquals(1200, $DB->get_field('quiz_attempts', 'timecheckstate', array('id'=>$attemptid)));
+ $this->assertEquals(1200, $DB->get_field('quiz_attempts', 'timecheckstate', ['id' => $attemptid]));
// add back to group
$this->assertTrue(groups_add_member($group1, $user1));
- $this->assertEquals(1300, $DB->get_field('quiz_attempts', 'timecheckstate', array('id'=>$attemptid)));
+ $this->assertEquals(1300, $DB->get_field('quiz_attempts', 'timecheckstate', ['id' => $attemptid]));
// delete group
groups_delete_group($group1);
- $this->assertEquals(1200, $DB->get_field('quiz_attempts', 'timecheckstate', array('id'=>$attemptid)));
- $this->assertEquals(0, $DB->count_records('quiz_overrides', array('quiz'=>$quiz->id)));
+ $this->assertEquals(1200, $DB->get_field('quiz_attempts', 'timecheckstate', ['id' => $attemptid]));
+ $this->assertEquals(0, $DB->count_records('quiz_overrides', ['quiz' => $quiz->id]));
// add a group2 override
- $DB->insert_record('quiz_overrides', array('quiz'=>$quiz->id, 'groupid'=>$group2->id, 'timeclose'=>1400, 'timelimit'=>null));
- quiz_update_open_attempts(array('quizid'=>$quiz->id));
- $this->assertEquals(1400, $DB->get_field('quiz_attempts', 'timecheckstate', array('id'=>$attemptid)));
+ $DB->insert_record('quiz_overrides',
+ ['quiz' => $quiz->id, 'groupid' => $group2->id, 'timeclose' => 1400, 'timelimit' => null]);
+ quiz_update_open_attempts(['quizid' => $quiz->id]);
+ $this->assertEquals(1400, $DB->get_field('quiz_attempts', 'timecheckstate', ['id' => $attemptid]));
// delete user1 from all groups
groups_delete_group_members($course->id, $user1->id);
- $this->assertEquals(1200, $DB->get_field('quiz_attempts', 'timecheckstate', array('id'=>$attemptid)));
+ $this->assertEquals(1200, $DB->get_field('quiz_attempts', 'timecheckstate', ['id' => $attemptid]));
// add back to group2
$this->assertTrue(groups_add_member($group2, $user1));
- $this->assertEquals(1400, $DB->get_field('quiz_attempts', 'timecheckstate', array('id'=>$attemptid)));
+ $this->assertEquals(1400, $DB->get_field('quiz_attempts', 'timecheckstate', ['id' => $attemptid]));
// delete everyone from all groups
groups_delete_group_members($course->id);
- $this->assertEquals(1200, $DB->get_field('quiz_attempts', 'timecheckstate', array('id'=>$attemptid)));
+ $this->assertEquals(1200, $DB->get_field('quiz_attempts', 'timecheckstate', ['id' => $attemptid]));
}
/**
$user1 = $this->getDataGenerator()->create_user();
$student = $this->getDataGenerator()->create_user();
$this->getDataGenerator()->enrol_user($student->id, $course->id, 'student');
+ /** @var mod_quiz_generator $quizgenerator */
$quizgenerator = $this->getDataGenerator()->get_plugin_generator('mod_quiz');
+ /** @var core_question_generator $questiongenerator */
$questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question');
- $quiz = $quizgenerator->create_instance(array('course' => $course->id, 'questionsperpage' => 0, 'grade' => 100.0,
- 'sumgrades' => 2));
+ $quiz = $quizgenerator->create_instance(['course' => $course->id, 'questionsperpage' => 0, 'grade' => 100.0,
+ 'sumgrades' => 2]);
// Create questions.
$cat = $questiongenerator->create_question_category();
- $saq = $questiongenerator->create_question('shortanswer', null, array('category' => $cat->id));
- $numq = $questiongenerator->create_question('numerical', null, array('category' => $cat->id));
+ $saq = $questiongenerator->create_question('shortanswer', null, ['category' => $cat->id]);
+ $numq = $questiongenerator->create_question('numerical', null, ['category' => $cat->id]);
// Add them to the quiz.
quiz_add_quiz_question($saq->id, $quiz);
quiz_add_quiz_question($numq->id, $quiz);
$quba->set_preferred_behaviour($quizobj->get_quiz()->preferredbehaviour);
$timenow = time();
// Create an attempt.
- $attempt = quiz_create_attempt($quizobj, 1, false, $timenow, false, $user1->id);
+ $attempt = quiz_create_attempt($quizobj, 1, null, $timenow, false, $user1->id);
quiz_start_new_attempt($quizobj, $quba, $attempt, 1, $timenow);
quiz_attempt_save_started($quizobj, $quba, $attempt);
$result = quiz_create_attempt_handling_errors($attempt->id, $quiz->cmid);
Feature: Quiz group override
In order to grant a group special access to a quiz
As a teacher
- I need to create an override for thta group.
+ I need to create an override for that group.
Background:
Given the following "users" exist:
| student2 | Sam 2 | Student 2 | student2@example.com |
| teacher3 | Terry 3 | Teacher 3 | teacher3@example.com |
| student3 | Sam 3 | Student 3 | student3@example.com |
+ | helper | Exam | Helper | helper@example.com |
And the following "courses" exist:
| fullname | shortname | category |
| Course 1 | C1 | 0 |
| student2 | C1 | student |
| teacher3 | C1 | editingteacher |
| student3 | C1 | student |
+ | helper | C1 | teacher |
And the following "groups" exist:
| name | course | idnumber |
| Group 1 | C1 | G1 |
| teacher2 | G2 |
| teacher2 | G3 |
| student3 | G3 |
+ | helper | G1 |
+ | helper | G2 |
+ | helper | G3 |
And the following "activities" exist:
| activity | name | intro | course | idnumber | groupmode |
| quiz | Test quiz | Test quiz description | C1 | quiz1 | 1 |
Then I should see "No groups you can access."
And the "Add group override" "button" should be disabled
- Scenario: A teacher with accessallgroups permission should see all group overrides
- When I am on the "Test quiz" "mod_quiz > Group overrides" page logged in as "admin"
+ Scenario: A teacher can create an override
+ When I am on the "Test quiz" "mod_quiz > Group overrides" page logged in as "teacher1"
And I press "Add group override"
And I set the following fields to these values:
- | Override group | Group 1 |
- | Attempts allowed | 2 |
+ | Override group | Group 1 |
+ | Attempts allowed | 2 |
And I press "Save and enter another override"
And I set the following fields to these values:
- | Override group | Group 2 |
+ | Override group | Group 3 |
| Attempts allowed | 2 |
And I press "Save"
- And I log out
- And I am on the "Test quiz" "mod_quiz > Group overrides" page logged in as "teacher1"
- Then I should see "Group 1" in the ".generaltable" "css_element"
- And I should see "Group 2" in the ".generaltable" "css_element"
+ Then "Group 1" "table_row" should exist
+
+ Scenario: A teacher with accessallgroups permission should see all group overrides
+ Given the following "mod_quiz > group overrides" exist:
+ | quiz | group | attempts |
+ | Test quiz | G1 | 2 |
+ | Test quiz | G2 | 2 |
+ When I am on the "Test quiz" "mod_quiz > View" page logged in as "teacher1"
+ Then I should see "Settings overrides exist (Groups: 2)"
+ And I follow "Groups: 2"
+ And "Group 1" "table_row" should exist
+ And "Group 2" "table_row" should exist
Scenario: A teacher without accessallgroups permission should only see the group overrides within his/her groups, when the activity's group mode is "separate groups"
Given the following "permission overrides" exist:
| capability | permission | role | contextlevel | reference |
| moodle/site:accessallgroups | Prevent | editingteacher | Course | C1 |
- When I am on the "Test quiz" "mod_quiz > Group overrides" page logged in as "admin"
- And I press "Add group override"
- And I set the following fields to these values:
- | Override group | Group 1 |
- | Attempts allowed | 2 |
- And I press "Save and enter another override"
- And I set the following fields to these values:
- | Override group | Group 2 |
- | Attempts allowed | 2 |
- And I press "Save"
- And I log out
- When I am on the "Test quiz" "mod_quiz > Group overrides" page logged in as "teacher1"
- Then I should see "Group 1" in the ".generaltable" "css_element"
- And I should not see "Group 2" in the ".generaltable" "css_element"
+ And the following "mod_quiz > group overrides" exist:
+ | quiz | group | attempts |
+ | Test quiz | G1 | 2 |
+ | Test quiz | G2 | 2 |
+ When I am on the "Test quiz" "mod_quiz > View" page logged in as "teacher1"
+ Then I should see "Settings overrides exist (Groups: 1) for your groups"
+ And I follow "Groups: 1"
+ Then "Group 1" "table_row" should exist
+ And "Group 2" "table_row" should not exist
+
+ Scenario: A non-editing teacher can see the overrides, but not change them
+ Given the following "mod_quiz > group overrides" exist:
+ | quiz | group | attempts |
+ | Test quiz | G1 | 2 |
+ | Test quiz | G2 | 2 |
+ When I am on the "Test quiz" "mod_quiz > Group overrides" page logged in as "helper"
+ Then "Group 1" "table_row" should exist
+ And "Group 2" "table_row" should exist
+ And "Add group override" "button" should not exist
+ And "Edit" "link" should not exist in the "Group 1" "table_row"
+ And "Copy" "link" should not exist in the "Group 1" "table_row"
+ And "Delete" "link" should not exist in the "Group 1" "table_row"
Background:
Given the following "users" exist:
| username | firstname | lastname | email |
- | teacher1 | Teacher | One | teacher1@example.com |
+ | teacher | Teacher | One | teacher@example.com |
+ | helper | Exam | Helper | helper@example.com |
| student1 | Student | One | student1@example.com |
| student2 | Student | Two | student2@example.com |
And the following "courses" exist:
| Course 1 | C1 | 0 |
And the following "course enrolments" exist:
| user | course | role |
- | teacher1 | C1 | editingteacher |
+ | teacher | C1 | editingteacher |
+ | helper | C1 | teacher |
| student1 | C1 | student |
| student2 | C1 | student |
- And the following "activities" exist:
- | activity | name | intro | course | idnumber |
- | quiz | Quiz 1 | Quiz 1 description | C1 | quiz1 |
@javascript
Scenario: Add, modify then delete a user override
- Given I log in as "teacher1"
- And I am on "Course 1" course homepage
- When I follow "Quiz 1"
+ Given the following "activities" exist:
+ | activity | name | course | idnumber |
+ | quiz | Test quiz | C1 | quiz1 |
+ And I am on the "Test quiz" "mod_quiz > View" page logged in as "teacher"
And I navigate to "User overrides" in current page administration
And I press "Add user override"
And I set the following fields to these values:
| timeclose[hour] | 08 |
| timeclose[minute] | 00 |
And I press "Save"
- And I should see "Wednesday, 1 January 2020, 8:00"
- Then I click on "Edit" "link" in the "Student One" "table_row"
+ Then I should see "Wednesday, 1 January 2020, 8:00"
+
+ And I click on "Edit" "link" in the "Student One" "table_row"
And I set the following fields to these values:
| timeclose[year] | 2030 |
And I press "Save"
And I should see "Tuesday, 1 January 2030, 8:00"
+
And I click on "Delete" "link"
And I press "Continue"
And I should not see "Student One"
@javascript
- Scenario: Being able to modify a user override when the quiz is not available to the student
- Given I log in as "teacher1"
- And I am on "Course 1" course homepage
- And I follow "Quiz 1"
- And I navigate to "Edit settings" in current page administration
- And I expand all fieldsets
- And I set the field "Availability" to "Hide from students"
- And I click on "Save and display" "button"
- When I navigate to "User overrides" in current page administration
+ Scenario: Can add a user override when the quiz is not available to the student
+ Given the following "activities" exist:
+ | activity | name | course | idnumber | visible |
+ | quiz | Test quiz | C1 | quiz1 | 0 |
+ When I am on the "Test quiz" "mod_quiz > User overrides" page logged in as "teacher"
And I press "Add user override"
And I set the following fields to these values:
| Override user | Student1 |
And the following "group members" exist:
| user | group |
| student1 | G1 |
- | teacher1 | G1 |
+ | teacher | G1 |
| student2 | G2 |
And the following "permission overrides" exist:
| capability | permission | role | contextlevel | reference |
| moodle/site:accessallgroups | Prevent | editingteacher | Course | C1 |
And the following "activities" exist:
- | activity | name | intro | course | idnumber | groupmode |
- | quiz | Quiz 2 | Quiz 2 description | C1 | quiz2 | 1 |
- When I log in as "teacher1"
- And I am on "Course 1" course homepage
- And I follow "Quiz 2"
- And I navigate to "User overrides" in current page administration
+ | activity | name | course | idnumber | groupmode |
+ | quiz | Test quiz | C1 | quiz1 | 1 |
+ When I am on the "Test quiz" "mod_quiz > User overrides" page logged in as "teacher"
And I press "Add user override"
Then the "Override user" select box should contain "Student One, student1@example.com"
And the "Override user" select box should not contain "Student Two, student2@example.com"
| capability | permission | role | contextlevel | reference |
| moodle/site:accessallgroups | Prevent | editingteacher | Course | C1 |
And the following "activities" exist:
- | activity | name | intro | course | idnumber | groupmode |
- | quiz | Quiz 2 | Quiz 2 description | C1 | quiz2 | 1 |
- When I log in as "teacher1"
- And I am on "Course 1" course homepage
- And I follow "Quiz 2"
- And I navigate to "User overrides" in current page administration
+ | activity | name | course | idnumber | groupmode |
+ | quiz | Test quiz | C1 | quiz1 | 1 |
+ When I am on the "Test quiz" "mod_quiz > User overrides" page logged in as "teacher"
Then I should see "No groups you can access."
And the "Add user override" "button" should be disabled
+
+ Scenario: A non-editing teacher can see the overrides, but not change them
+ Given the following "activities" exist:
+ | activity | name | course | idnumber |
+ | quiz | Test quiz | C1 | quiz1 |
+ And the following "mod_quiz > user overrides" exist:
+ | quiz | user | attempts |
+ | Test quiz | student1 | 2 |
+ | Test quiz | student2 | 2 |
+ And I am on the "Test quiz" "mod_quiz > View" page logged in as "helper"
+ When I navigate to "User overrides" in current page administration
+ Then "Student One" "table_row" should exist
+ And "Student Two" "table_row" should exist
+ And "Add user override" "button" should not exist
+ And "Edit" "link" should not exist in the "Student One" "table_row"
+ And "Copy" "link" should not exist in the "Student One" "table_row"
+ And "Delete" "link" should not exist in the "Student One" "table_row"
+ And I am on the "Test quiz" "mod_quiz > View" page
+ And I should see "Settings overrides exist (Users: 2)"
'timecreated' => time(),
'timemodified' => time(),
'timelimit' => 0,
- 'overduehandling' => 'autoabandon',
+ 'overduehandling' => 'autosubmit',
'graceperiod' => 86400,
'quizpassword' => '',
'subnet' => '',
$this->assertEquals($formattedexptected, $actual);
}
+
+ public function test_quiz_override_summary() {
+ global $DB, $PAGE;
+ $this->resetAfterTest();
+ $generator = $this->getDataGenerator();
+ /** @var mod_quiz_generator $quizgenerator */
+ $quizgenerator = $generator->get_plugin_generator('mod_quiz');
+ /** @var mod_quiz_renderer $renderer */
+ $renderer = $PAGE->get_renderer('mod_quiz');
+
+ // Course with quiz and a group - plus some others, to verify they don't get counted.
+ $course = $generator->create_course();
+ $quiz = $quizgenerator->create_instance(['course' => $course->id, 'groupmode' => SEPARATEGROUPS]);
+ $cm = get_coursemodule_from_id('quiz', $quiz->cmid, $course->id);
+ $group = $generator->create_group(['courseid' => $course->id]);
+ $othergroup = $generator->create_group(['courseid' => $course->id]);
+ $otherquiz = $quizgenerator->create_instance(['course' => $course->id]);
+
+ // Initial test (as admin) with no data.
+ $this->setAdminUser();
+ $this->assertEquals(['group' => 0, 'user' => 0, 'mode' => 'allgroups'],
+ quiz_override_summary($quiz, $cm));
+ $this->assertEquals(['group' => 0, 'user' => 0, 'mode' => 'onegroup'],
+ quiz_override_summary($quiz, $cm, $group->id));
+
+ // Editing teacher.
+ $teacher = $generator->create_user();
+ $generator->enrol_user($teacher->id, $course->id, 'editingteacher');
+
+ // Non-editing teacher.
+ $tutor = $generator->create_user();
+ $generator->enrol_user($tutor->id, $course->id, 'teacher');
+ $generator->create_group_member(['userid' => $tutor->id, 'groupid' => $group->id]);
+
+ // Three students.
+ $student1 = $generator->create_user();
+ $generator->enrol_user($student1->id, $course->id, 'student');
+ $generator->create_group_member(['userid' => $student1->id, 'groupid' => $group->id]);
+
+ $student2 = $generator->create_user();
+ $generator->enrol_user($student2->id, $course->id, 'student');
+ $generator->create_group_member(['userid' => $student2->id, 'groupid' => $othergroup->id]);
+
+ $student3 = $generator->create_user();
+ $generator->enrol_user($student3->id, $course->id, 'student');
+
+ // Initial test now users exist, but before overrides.
+ // Test as teacher.
+ $this->setUser($teacher);
+ $this->assertEquals(['group' => 0, 'user' => 0, 'mode' => 'allgroups'],
+ quiz_override_summary($quiz, $cm));
+ $this->assertEquals(['group' => 0, 'user' => 0, 'mode' => 'onegroup'],
+ quiz_override_summary($quiz, $cm, $group->id));
+
+ // Test as tutor.
+ $this->setUser($tutor);
+ $this->assertEquals(['group' => 0, 'user' => 0, 'mode' => 'somegroups'],
+ quiz_override_summary($quiz, $cm));
+ $this->assertEquals(['group' => 0, 'user' => 0, 'mode' => 'onegroup'],
+ quiz_override_summary($quiz, $cm, $group->id));
+ $this->assertEquals('', $renderer->quiz_override_summary_links($quiz, $cm));
+
+ // Quiz setting overrides for students 1 and 3.
+ $quizgenerator->create_override(['quiz' => $quiz->id, 'userid' => $student1->id, 'attempts' => 2]);
+ $quizgenerator->create_override(['quiz' => $quiz->id, 'userid' => $student3->id, 'attempts' => 2]);
+ $quizgenerator->create_override(['quiz' => $quiz->id, 'groupid' => $group->id, 'attempts' => 3]);
+ $quizgenerator->create_override(['quiz' => $quiz->id, 'groupid' => $othergroup->id, 'attempts' => 3]);
+ $quizgenerator->create_override(['quiz' => $otherquiz->id, 'userid' => $student2->id, 'attempts' => 2]);
+
+ // Test as teacher.
+ $this->setUser($teacher);
+ $this->assertEquals(['group' => 2, 'user' => 2, 'mode' => 'allgroups'],
+ quiz_override_summary($quiz, $cm));
+ $this->assertEquals('Settings overrides exist (Groups: 2, Users: 2)',
+ // Links checked by Behat, so strip them for these tests.
+ html_to_text($renderer->quiz_override_summary_links($quiz, $cm), 0, false));
+ $this->assertEquals(['group' => 1, 'user' => 1, 'mode' => 'onegroup'],
+ quiz_override_summary($quiz, $cm, $group->id));
+ $this->assertEquals('Settings overrides exist (Groups: 1, Users: 1) for this group',
+ html_to_text($renderer->quiz_override_summary_links($quiz, $cm, $group->id), 0, false));
+
+ // Test as tutor.
+ $this->setUser($tutor);
+ $this->assertEquals(['group' => 1, 'user' => 1, 'mode' => 'somegroups'],
+ quiz_override_summary($quiz, $cm));
+ $this->assertEquals('Settings overrides exist (Groups: 1, Users: 1) for your groups',
+ html_to_text($renderer->quiz_override_summary_links($quiz, $cm), 0, false));
+ $this->assertEquals(['group' => 1, 'user' => 1, 'mode' => 'onegroup'],
+ quiz_override_summary($quiz, $cm, $group->id));
+ $this->assertEquals('Settings overrides exist (Groups: 1, Users: 1) for this group',
+ html_to_text($renderer->quiz_override_summary_links($quiz, $cm, $group->id), 0, false));
+
+ // Now set the quiz to be group mode: no groups, and re-test as tutor.
+ // In this case, the tutor should see all groups.
+ $DB->set_field('course_modules', 'groupmode', NOGROUPS, ['id' => $cm->id]);
+ $cm = get_coursemodule_from_id('quiz', $quiz->cmid, $course->id);
+
+ $this->assertEquals(['group' => 2, 'user' => 2, 'mode' => 'allgroups'],
+ quiz_override_summary($quiz, $cm));
+ $this->assertEquals('Settings overrides exist (Groups: 2, Users: 2)',
+ html_to_text($renderer->quiz_override_summary_links($quiz, $cm), 0, false));
+ }
}
defined('MOODLE_INTERNAL') || die();
-$plugin->version = 2021052500;
+$plugin->version = 2021052501;
$plugin->requires = 2021052500;
$plugin->component = 'mod_quiz';
public static function get_all_response_file_areas() {
$variables = array();
foreach (question_bank::get_all_qtypes() as $qtype) {
- $variables += $qtype->response_file_areas();
+ $variables = array_merge($variables, $qtype->response_file_areas());
}
$areas = array();
$this->class_name() . ' qtype_essay_response'));
$output .= html_writer::tag('div', html_writer::tag('textarea', s($response),
- array('id' => $id, 'name' => $inputname, 'rows' => $lines, 'cols' => 60)));
+ array('id' => $id, 'name' => $inputname, 'rows' => $lines, 'cols' => 60, 'class' => 'form-control')));
$output .= html_writer::start_tag('div');
if (count($formats) == 1) {
* @return string the HTML for the textarea.
*/
protected function textarea($response, $lines, $attributes) {
- $attributes['class'] = $this->class_name() . ' qtype_essay_response';
+ $attributes['class'] = $this->class_name() . ' qtype_essay_response form-control';
$attributes['rows'] = $lines;
$attributes['cols'] = 60;
return html_writer::tag('textarea', s($response), $attributes);