- >
if [ "$TASK" = 'PHPUNIT' ];
then
- vendor/bin/phpunit;
+ vendor/bin/phpunit --fail-on-risky --disallow-test-output --verbose;
fi
- >
public function setUp() {
global $DB;
- $this->course = $this->getDataGenerator()->create_course();
+ $this->course = $this->getDataGenerator()->create_course(['startdate' => 0]);
$this->stu1 = $this->getDataGenerator()->create_user();
$this->stu2 = $this->getDataGenerator()->create_user();
$this->both = $this->getDataGenerator()->create_user();
--- /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/>.
+
+/**
+ * Search area for course sections (title and summary).
+ *
+ * @package core_course
+ * @copyright 2018 The Open University
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+namespace core_course\search;
+
+defined('MOODLE_INTERNAL') || die();
+
+/**
+ * Search area for course sections (title and summary).
+ *
+ * Note this does not include the activities within the section, as these have their own search
+ * areas.
+ *
+ * @package core_course
+ * @copyright 2018 The Open University
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class section extends \core_search\base {
+ /**
+ * Sections are indexed at course context.
+ *
+ * @var array
+ */
+ protected static $levels = [CONTEXT_COURSE];
+
+ /**
+ * Returns recordset containing required data for indexing course sections.
+ *
+ * @param int $modifiedfrom timestamp
+ * @param \context|null $context Restriction context
+ * @return \moodle_recordset|null Recordset or null if no change possible
+ */
+ public function get_document_recordset($modifiedfrom = 0, \context $context = null) {
+ global $DB;
+
+ list ($contextjoin, $contextparams) = $this->get_course_level_context_restriction_sql($context, 'c');
+ if ($contextjoin === null) {
+ return null;
+ }
+
+ $comparetext = $DB->sql_compare_text('cs.summary', 1);
+
+ return $DB->get_recordset_sql("
+ SELECT cs.id,
+ cs.course,
+ cs.section,
+ cs.name,
+ cs.summary,
+ cs.summaryformat,
+ cs.timemodified
+ FROM {course_sections} cs
+ JOIN {course} c ON c.id = cs.course
+ $contextjoin
+ WHERE cs.timemodified >= ?
+ AND (cs.name != ? OR $comparetext != ?)
+ ORDER BY cs.timemodified ASC", array_merge($contextparams, [$modifiedfrom, '', '']));
+ }
+
+ /**
+ * Returns the document associated with this section.
+ *
+ * @param \stdClass $record
+ * @param array $options
+ * @return \core_search\document
+ */
+ public function get_document($record, $options = array()) {
+ // Get the context, modinfo, and section.
+ try {
+ $context = \context_course::instance($record->course);
+ } catch (\moodle_exception $ex) {
+ // Notify it as we run here as admin, we should see everything.
+ debugging('Error retrieving ' . $this->areaid . ' ' . $record->id .
+ ' document, not all required data is available: ' . $ex->getMessage(),
+ DEBUG_DEVELOPER);
+ return false;
+ }
+
+ // Title - use default if none given.
+ $title = get_section_name($record->course, $record->section);
+
+ // Prepare associative array with data from DB.
+ $doc = \core_search\document_factory::instance($record->id, $this->componentname, $this->areaname);
+ $doc->set('title', content_to_text($title, false));
+ $doc->set('content', content_to_text($record->summary, $record->summaryformat));
+ $doc->set('contextid', $context->id);
+ $doc->set('courseid', $record->course);
+ $doc->set('owneruserid', \core_search\manager::NO_OWNER_ID);
+ $doc->set('modified', $record->timemodified);
+
+ return $doc;
+ }
+
+ /**
+ * Whether the user can access the section or not.
+ *
+ * @param int $id The course section id.
+ * @return int One of the \core_search\manager:ACCESS_xx constants
+ */
+ public function check_access($id) {
+ global $DB;
+
+ // Check we can get the section and the course modinfo.
+ $sectionrec = $DB->get_record('course_sections', ['id' => $id], '*', IGNORE_MISSING);
+ if (!$sectionrec) {
+ return \core_search\manager::ACCESS_DELETED;
+ }
+ try {
+ $modinfo = get_fast_modinfo($sectionrec->course);
+ } catch (\moodle_exception $e) {
+ return \core_search\manager::ACCESS_DELETED;
+ }
+ $section = $modinfo->get_section_info($sectionrec->section, IGNORE_MISSING);
+ if (!$section) {
+ return \core_search\manager::ACCESS_DELETED;
+ }
+
+ // Check access to course and that the section is visible to current user.
+ if (can_access_course($modinfo->get_course()) && $section->uservisible) {
+ return \core_search\manager::ACCESS_GRANTED;
+ }
+
+ return \core_search\manager::ACCESS_DENIED;
+ }
+
+ /**
+ * Gets a link to the section.
+ *
+ * @param \core_search\document $doc
+ * @return \moodle_url
+ */
+ public function get_doc_url(\core_search\document $doc) {
+ global $DB;
+ $section = $DB->get_field('course_sections', 'section', ['id' => $doc->get('itemid')], MUST_EXIST);
+ $format = course_get_format($doc->get('courseid'));
+ return $format->get_view_url($section);
+ }
+
+ /**
+ * Gets a link to the section.
+ *
+ * @param \core_search\document $doc
+ * @return \moodle_url
+ */
+ public function get_context_url(\core_search\document $doc) {
+ return $this->get_doc_url($doc);
+ }
+
+ /**
+ * Returns true to include summary files in the index.
+ *
+ * @return bool True
+ */
+ public function uses_file_indexing() {
+ return true;
+ }
+
+ /**
+ * Return the file area that is used for summary files.
+ *
+ * @return array File area name
+ */
+ public function get_search_fileareas() {
+ return ['section'];
+ }
+
+ /**
+ * Returns the moodle component name, as used in the files table.
+ *
+ * @return string Component name
+ */
+ public function get_component_name() {
+ return 'course';
+ }
+}
| username | firstname | lastname | email |
| teacher1 | Teacher | 1 | teacher1@example.com |
And the following "courses" exist:
- | fullname | shortname | format | coursedisplay | numsections |
- | Course 1 | C1 | <courseformat> | <coursedisplay> | 5 |
+ | fullname | shortname | format | coursedisplay | numsections | startdate |
+ | Course 1 | C1 | <courseformat> | <coursedisplay> | 5 | 0 |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
| username | firstname | lastname | email |
| teacher1 | Teacher | 1 | teacher1@example.com |
And the following "courses" exist:
- | fullname | shortname | format | coursedisplay | numsections |
- | Course 1 | C1 | <courseformat> | <coursedisplay> | 5 |
+ | fullname | shortname | format | coursedisplay | numsections | startdate |
+ | Course 1 | C1 | <courseformat> | <coursedisplay> | 5 | 0 |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
@javascript @_cross_browser
Scenario Outline: Weekly and topics course formats with Javascript enabled
Given the following "courses" exist:
- | fullname | shortname | category | format | coursedisplay | numsections |
- | Course 1 | C1 | 0 | <courseformat> | 1 | 3 |
+ | fullname | shortname | category | format | coursedisplay | numsections | startdate |
+ | Course 1 | C1 | 0 | <courseformat> | 1 | 3 | 0 |
And I log in as "admin"
And I am on "Course 1" course homepage
Then I click on <section2> "link" in the <section2> "section"
Scenario Outline: Weekly and topics course formats with Javascript disabled
Given the following "courses" exist:
- | fullname | shortname | category | format | coursedisplay | numsections |
- | Course 1 | C1 | 0 | <courseformat> | 1 | 3 |
+ | fullname | shortname | category | format | coursedisplay | numsections | startdate |
+ | Course 1 | C1 | 0 | <courseformat> | 1 | 3 | 0 |
And I log in as "admin"
And I am on "Course 1" course homepage
Then I click on <section2> "link" in the <section2> "section"
*/
protected $mycoursesareaid = null;
+ /**
+ * @var string Area id for sections
+ */
+ protected $sectionareaid = null;
+
public function setUp() {
$this->resetAfterTest(true);
set_config('enableglobalsearch', true);
$this->mycoursesareaid = \core_search\manager::generate_areaid('core_course', 'mycourse');
+ $this->sectionareaid = \core_search\manager::generate_areaid('core_course', 'section');
// Set \core_search::instance to the mock_search_engine as we don't require the search engine to be working to test this.
$search = testable_core_search::instance();
$this->assertEquals(\core_search\manager::ACCESS_DENIED, $searcharea->check_access($course2->id));
$this->assertEquals(\core_search\manager::ACCESS_DENIED, $searcharea->check_access($course3->id));
}
+
+ /**
+ * Indexing section contents.
+ */
+ public function test_section_indexing() {
+ global $DB, $USER;
+
+ // Returns the instance as long as the area is supported.
+ $searcharea = \core_search\manager::get_search_area($this->sectionareaid);
+ $this->assertInstanceOf('\core_course\search\section', $searcharea);
+
+ // Create some courses in categories, and a forum.
+ $generator = $this->getDataGenerator();
+ $cat1 = $generator->create_category();
+ $cat2 = $generator->create_category(['parent' => $cat1->id]);
+ $course1 = $generator->create_course(['category' => $cat1->id]);
+ $course2 = $generator->create_course(['category' => $cat2->id]);
+ $forum = $generator->create_module('forum', ['course' => $course1->id]);
+
+ // Edit 2 sections on course 1 and one on course 2.
+ $existing = $DB->get_record('course_sections', ['course' => $course1->id, 'section' => 2]);
+ $course1section2id = $existing->id;
+ $new = clone($existing);
+ $new->name = 'Frogs';
+ course_update_section($course1->id, $existing, $new);
+
+ $existing = $DB->get_record('course_sections', ['course' => $course1->id, 'section' => 3]);
+ $course1section3id = $existing->id;
+ $new = clone($existing);
+ $new->summary = 'Frogs';
+ $new->summaryformat = FORMAT_HTML;
+ course_update_section($course1->id, $existing, $new);
+
+ $existing = $DB->get_record('course_sections', ['course' => $course2->id, 'section' => 1]);
+ $course2section1id = $existing->id;
+ $new = clone($existing);
+ $new->summary = 'Frogs';
+ $new->summaryformat = FORMAT_HTML;
+ course_update_section($course2->id, $existing, $new);
+
+ // Bodge timemodified into a particular order.
+ $DB->set_field('course_sections', 'timemodified', 1, ['id' => $course1section3id]);
+ $DB->set_field('course_sections', 'timemodified', 2, ['id' => $course1section2id]);
+ $DB->set_field('course_sections', 'timemodified', 3, ['id' => $course2section1id]);
+
+ // All records.
+ $results = self::recordset_to_ids($searcharea->get_document_recordset(0));
+ $this->assertEquals([$course1section3id, $course1section2id, $course2section1id], $results);
+
+ // Records after time 2.
+ $results = self::recordset_to_ids($searcharea->get_document_recordset(2));
+ $this->assertEquals([$course1section2id, $course2section1id], $results);
+
+ // Records after time 10 (there aren't any).
+ $results = self::recordset_to_ids($searcharea->get_document_recordset(10));
+ $this->assertEquals([], $results);
+
+ // Find the first block to use for a block context.
+ $blockid = array_values($DB->get_records('block_instances', null, 'id', 'id', 0, 1))[0]->id;
+ $blockcontext = context_block::instance($blockid);
+
+ // Check with block context - should be null.
+ $this->assertNull($searcharea->get_document_recordset(0, $blockcontext));
+
+ // Check with user context - should be null.
+ $this->setAdminUser();
+ $usercontext = context_user::instance($USER->id);
+ $this->assertNull($searcharea->get_document_recordset(0, $usercontext));
+
+ // Check with module context - should be null.
+ $modcontext = context_module::instance($forum->cmid);
+ $this->assertNull($searcharea->get_document_recordset(0, $modcontext));
+
+ // Check with course context - should return specific course entries.
+ $coursecontext = context_course::instance($course1->id);
+ $results = self::recordset_to_ids($searcharea->get_document_recordset(0, $coursecontext));
+ $this->assertEquals([$course1section3id, $course1section2id], $results);
+ $results = self::recordset_to_ids($searcharea->get_document_recordset(2, $coursecontext));
+ $this->assertEquals([$course1section2id], $results);
+
+ // Check with category context - should return course in categories and subcategories.
+ $catcontext = context_coursecat::instance($cat1->id);
+ $results = self::recordset_to_ids($searcharea->get_document_recordset(0, $catcontext));
+ $this->assertEquals([$course1section3id, $course1section2id, $course2section1id], $results);
+ $catcontext = context_coursecat::instance($cat2->id);
+ $results = self::recordset_to_ids($searcharea->get_document_recordset(0, $catcontext));
+ $this->assertEquals([$course2section1id], $results);
+
+ // Check with system context - should return everything (same as null, tested first).
+ $systemcontext = context_system::instance();
+ $results = self::recordset_to_ids($searcharea->get_document_recordset(0, $systemcontext));
+ $this->assertEquals([$course1section3id, $course1section2id, $course2section1id], $results);
+ }
+
+ /**
+ * Document contents for sections.
+ */
+ public function test_section_document() {
+ global $DB;
+
+ $searcharea = \core_search\manager::get_search_area($this->sectionareaid);
+
+ // Create a course.
+ $generator = $this->getDataGenerator();
+ $course = $generator->create_course();
+
+ // Test with default title.
+ $sectionrec = (object)['id' => 123, 'course' => $course->id,
+ 'section' => 3, 'timemodified' => 456,
+ 'summary' => 'Kermit', 'summaryformat' => FORMAT_HTML];
+ $doc = $searcharea->get_document($sectionrec);
+ $this->assertInstanceOf('\core_search\document', $doc);
+ $this->assertEquals(123, $doc->get('itemid'));
+ $this->assertEquals($this->sectionareaid . '-123', $doc->get('id'));
+ $this->assertEquals($course->id, $doc->get('courseid'));
+ $this->assertFalse($doc->is_set('userid'));
+ $this->assertEquals(\core_search\manager::NO_OWNER_ID, $doc->get('owneruserid'));
+ $this->assertEquals('Topic 3', $doc->get('title'));
+ $this->assertEquals('Kermit', $doc->get('content'));
+
+ // Test with user-set title.
+ $DB->set_field('course_sections', 'name', 'Frogs',
+ ['course' => $course->id, 'section' => 3]);
+ rebuild_course_cache($course->id, true);
+ $doc = $searcharea->get_document($sectionrec);
+ $this->assertEquals('Frogs', $doc->get('title'));
+ }
+
+ /**
+ * Document access for sections.
+ */
+ public function test_section_access() {
+ global $DB;
+
+ $searcharea = \core_search\manager::get_search_area($this->sectionareaid);
+
+ // Create a course.
+ $generator = $this->getDataGenerator();
+ $course = $generator->create_course();
+
+ // Create 2 users - student and manager. Initially, student is not even enrolled.
+ $student = $generator->create_user();
+ $manager = $generator->create_user();
+ $generator->enrol_user($manager->id, $course->id, 'manager');
+
+ // Two sections have content - one is hidden.
+ $DB->set_field('course_sections', 'name', 'Frogs',
+ ['course' => $course->id, 'section' => 1]);
+ $DB->set_field('course_sections', 'name', 'Toads',
+ ['course' => $course->id, 'section' => 2]);
+ $DB->set_field('course_sections', 'visible', '0',
+ ['course' => $course->id, 'section' => 2]);
+
+ // Make the modified time be in order of sections.
+ $DB->execute('UPDATE {course_sections} SET timemodified = section');
+
+ // Get the two document objects.
+ $rs = $searcharea->get_document_recordset();
+ $documents = [];
+ $index = 0;
+ foreach ($rs as $rec) {
+ $documents[$index++] = $searcharea->get_document($rec);
+ }
+ $this->assertCount(2, $documents);
+
+ // Log in as admin and check access.
+ $this->setAdminUser();
+ $this->assertEquals(\core_search\manager::ACCESS_GRANTED,
+ $searcharea->check_access($documents[0]->get('itemid')));
+ $this->assertEquals(\core_search\manager::ACCESS_GRANTED,
+ $searcharea->check_access($documents[1]->get('itemid')));
+
+ // Log in as manager and check access.
+ $this->setUser($manager);
+ $this->assertEquals(\core_search\manager::ACCESS_GRANTED,
+ $searcharea->check_access($documents[0]->get('itemid')));
+ $this->assertEquals(\core_search\manager::ACCESS_GRANTED,
+ $searcharea->check_access($documents[1]->get('itemid')));
+
+ // Log in as student and check access - none yet.
+ $this->setUser($student);
+ $this->assertEquals(\core_search\manager::ACCESS_DENIED,
+ $searcharea->check_access($documents[0]->get('itemid')));
+ $this->assertEquals(\core_search\manager::ACCESS_DENIED,
+ $searcharea->check_access($documents[1]->get('itemid')));
+
+ // Enrol student - now they should get access but not to the hidden one.
+ $generator->enrol_user($student->id, $course->id, 'student');
+ $this->assertEquals(\core_search\manager::ACCESS_GRANTED,
+ $searcharea->check_access($documents[0]->get('itemid')));
+ $this->assertEquals(\core_search\manager::ACCESS_DENIED,
+ $searcharea->check_access($documents[1]->get('itemid')));
+
+ // Delete the course and check it returns deleted.
+ delete_course($course, false);
+ $this->assertEquals(\core_search\manager::ACCESS_DELETED,
+ $searcharea->check_access($documents[0]->get('itemid')));
+ $this->assertEquals(\core_search\manager::ACCESS_DELETED,
+ $searcharea->check_access($documents[1]->get('itemid')));
+ }
}
$string['search:message_received'] = 'Messages - received';
$string['search:message_sent'] = 'Messages - sent';
$string['search:mycourse'] = 'My courses';
+$string['search:section'] = 'Course sections';
$string['search:user'] = 'Users';
$string['searcharea'] = 'Search area';
$string['searching'] = 'Searching in ...';
$record['category'] = $DB->get_field_select('course_categories', "MIN(id)", "parent=0");
}
+ if (!isset($record['startdate'])) {
+ $record['startdate'] = usergetmidnight(time());
+ }
+
if (isset($record['tags']) && !is_array($record['tags'])) {
$record['tags'] = preg_split('/\s*,\s*/', trim($record['tags']), -1, PREG_SPLIT_NO_EMPTY);
}
// Normalize paths to compare them.
$filepath = realpath($this->name); // File path comes in name.
$filename = basename($filepath);
- $structurepath = realpath($CFG->dirroot . DIRECTORY_SEPARATOR . $this->path . DIRECTORY_SEPARATOR . $filename);
+ $normalisedpath = $this->path;
+ if ($CFG->admin !== 'admin') {
+ $needle = 'admin/';
+ if (strpos($this->path, $needle) === 0) {
+ $normalisedpath = substr_replace($this->path, "$CFG->admin/", 0, strlen($needle));
+ }
+ }
+ $structurepath = realpath($CFG->dirroot . DIRECTORY_SEPARATOR . $normalisedpath . DIRECTORY_SEPARATOR . $filename);
if ($filepath !== $structurepath) {
$relativepath = dirname(str_replace(realpath($CFG->dirroot) . DIRECTORY_SEPARATOR, '', $filepath));
$this->errormsg = 'PATH attribute does not match file directory: ' . $relativepath;
.mediaplugin_videojs video {
min-height: 32px;
}
+
+/* MDL-61020: VideoJS timeline progress bar should not be flipped in RTL mode. */
+
+/* Prevent the progress bar from being flipped in RTL. */
+/*rtl:ignore*/
+.video-js .vjs-progress-holder .vjs-play-progress,
+.video-js .vjs-progress-holder .vjs-load-progress,
+.video-js .vjs-progress-holder .vjs-load-progress div {
+ left: 0;
+ right: auto;
+}
+/* Keep the video scrubber button at the end of the progress bar in RTL. */
+/*rtl:ignore*/
+.video-js .vjs-play-progress:before {
+ left: auto;
+ right: -0.5em;
+}
+/* Prevent the volume slider from being flipped in RTL. */
+/*rtl:ignore*/
+.video-js .vjs-volume-level {
+ left: 0;
+ right: auto;
+}
+/* Keep the volume slider handle at the end of the volume slider in RTL. */
+/*rtl:ignore*/
+.vjs-slider-horizontal .vjs-volume-level:before {
+ left: auto;
+ right: -0.5em;
+}
--- /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/>.
+
+/**
+ * Privacy class for requesting user data.
+ *
+ * @package message_airnotifier
+ * @copyright 2018 Adrian Greeve <adrian@moodle.com>
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+namespace message_airnotifier\privacy;
+
+defined('MOODLE_INTERNAL') || die();
+
+use \core_privacy\local\metadata\collection;
+use \core_privacy\local\request\contextlist;
+use \core_privacy\local\request\approved_contextlist;
+use \core_privacy\local\request\transform;
+
+/**
+ * Privacy class for requesting user data.
+ *
+ * @package message_airnotifier
+ * @copyright 2018 Adrian Greeve <adrian@moodle.com>
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class provider implements \core_privacy\local\metadata\provider, \core_privacy\local\request\plugin\provider {
+
+ /**
+ * Returns meta data about this system.
+ *
+ * @param collection $collection The initialised collection to add items to.
+ * @return collection A listing of user data stored through this system.
+ */
+ public static function get_metadata(collection $collection) : collection {
+ $collection->link_subsystem('core_user', 'privacy:metadata:usersubsystem');
+ $collection->add_database_table('message_airnotifier_devices', [
+ 'userdeviceid' => 'privacy:metadata:userdeviceid',
+ 'enabled' => 'privacy:metadata:enabled'
+ ], 'privacy:metadata:tableexplanation');
+ $collection->link_external_location('External airnotifier site.', [
+ 'userid' => 'privacy:metadata:userid',
+ 'username' => 'privacy:metadata:username',
+ 'userfromid' => 'privacy:metadata:userfromid',
+ 'userfromfullname' => 'privacy:metadata:userfromfullname',
+ 'date' => 'privacy:metadata:date',
+ 'subject' => 'privacy:metadata:subject',
+ 'notification' => 'privacy:metadata:notification',
+ 'smallmessage' => 'privacy:metadata:smallmessage',
+ 'fullmessage' => 'privacy:metadata:fullmessage'
+ ], 'privacy:metadata:externalpurpose');
+ // This system is unaware of user preferences such as message_provider_moodle_instantmessage_loggedin.
+ return $collection;
+ }
+
+ /**
+ * Get the list of contexts that contain user information for the specified user.
+ *
+ * @param int $userid The user to search.
+ * @return contextlist $contextlist The contextlist containing the list of contexts used in this plugin.
+ */
+ public static function get_contexts_for_userid(int $userid) : contextlist {
+ $sql = "SELECT ctx.id
+ FROM {message_airnotifier_devices} mad
+ JOIN {user_devices} ud ON ud.id = mad.userdeviceid
+ JOIN {user} u ON ud.userid = u.id
+ JOIN {context} ctx ON ctx.instanceid = u.id AND ctx.contextlevel = :contextlevel
+ WHERE ud.userid = :userid";
+
+ $params = ['userid' => $userid, 'contextlevel' => CONTEXT_USER];
+
+ $contextlist = new contextlist();
+ $contextlist->add_from_sql($sql, $params);
+ return $contextlist;
+ }
+
+ /**
+ * Export all user data for the specified user, in the specified contexts.
+ *
+ * @param approved_contextlist $contextlist The approved contexts to export information for.
+ */
+ public static function export_user_data(approved_contextlist $contextlist) {
+ $results = static::get_records($contextlist->get_user()->id);
+ $context = $contextlist->current();
+ foreach ($results as $result) {
+ $data = (object)[
+ 'appid' => $result->appid,
+ 'pushid' => $result->pushid,
+ 'name' => $result->name,
+ 'model' => $result->model,
+ 'platform' => $result->platform,
+ 'version' => $result->version,
+ 'timecreated' => transform::datetime($result->timecreated),
+ 'timemodified' => transform::datetime($result->timemodified),
+ 'enabled' => transform::yesno($result->enable)
+ ];
+ \core_privacy\local\request\writer::with_context($context)->export_data([
+ get_string('privacy:subcontext', 'message_airnotifier'),
+ $result->model . '_' . $result->pushid
+ ], $data);
+ }
+ }
+
+ /**
+ * Delete all use data which matches the specified deletion_criteria.
+ *
+ * @param context $context A user context.
+ */
+ public static function delete_data_for_all_users_in_context(\context $context) {
+ static::delete_data($context->instanceid);
+ }
+
+ /**
+ * Delete all user data for the specified user, in the specified contexts.
+ *
+ * @param approved_contextlist $contextlist The approved contexts and user information to delete information for.
+ */
+ public static function delete_data_for_user(approved_contextlist $contextlist) {
+ static::delete_data($contextlist->get_user()->id);
+ }
+
+ /**
+ * Delete data related to a userid.
+ *
+ * @param int $userid The user ID
+ */
+ protected static function delete_data(int $userid) {
+ global $DB;
+
+ foreach (static::get_records($userid) as $record) {
+ $DB->delete_records('message_airnotifier_devices', ['id' => $record->id]);
+ }
+ }
+
+ /**
+ * Get records related to this plugin and user.
+ *
+ * @param int $userid The user ID
+ * @return array An array of records.
+ */
+ protected static function get_records(int $userid) : array {
+ global $DB;
+ $sql = "SELECT mad.id, mad.enable, ud.appid, ud.name, ud.model, ud.platform, ud.version, ud.timecreated, ud.timemodified,
+ ud.pushid
+ FROM {message_airnotifier_devices} mad
+ JOIN {user_devices} ud ON mad.userdeviceid = ud.id
+ WHERE ud.userid = :userid";
+ $params = ['userid' => $userid];
+ return $DB->get_records_sql($sql, $params);
+ }
+}
$string['nopermissiontomanagedevices'] = 'You don\'t have permission to manage devices.';
$string['notconfigured'] = 'The Airnotifier server hasn\'t been configured so Airnotifier messages cannot be sent';
$string['pluginname'] = 'Mobile';
+$string['privacy:appiddescription'] = 'This is an identifier to the application being used.';
+$string['privacy:enableddescription'] = 'If this device is enabled for airnotifier.';
+$string['privacy:metadata:enabled'] = 'If the airnotifier device is enabled.';
+$string['privacy:metadata:date'] = 'The date that the message was sent.';
+$string['privacy:metadata:externalpurpose'] = 'This information is sent to an external site to be ultimately delivered to the mobile device of the user.';
+$string['privacy:metadata:fullmessage'] = 'The full message.';
+$string['privacy:metadata:notification'] = 'If this message is a notification.';
+$string['privacy:metadata:smallmessage'] = 'An section of the message.';
+$string['privacy:metadata:subject'] = 'The subject line of the message.';
+$string['privacy:metadata:tableexplanation'] = 'Airnotifier device information is stored here.';
+$string['privacy:metadata:userdeviceid'] = 'The ID linking to the user\'s mobile device';
+$string['privacy:metadata:userfromfullname'] = 'The full name of the user that sent the message.';
+$string['privacy:metadata:userfromid'] = 'The user ID of the author of the message.';
+$string['privacy:metadata:userid'] = 'The user ID.';
+$string['privacy:metadata:username'] = 'The username for the user.';
+$string['privacy:metadata:usersubsystem'] = 'This plugin is connected to the user subsystem.';
+$string['privacy:subcontext'] = 'Message Airnotifier';
$string['sitemustberegistered'] = 'In order to use the public Airnotifier instance you must register your site with Moodle.net';
$string['showhide'] = 'Enable/disable the device.';
$string['requestaccesskey'] = 'Request access key';
--- /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/>.
+/**
+ * Base class for unit tests for message_airnotifier.
+ *
+ * @package message_airnotifier
+ * @copyright 2018 Adrian Greeve <adrian@moodle.com>
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die();
+
+use \core_privacy\tests\provider_testcase;
+/**
+ * Unit tests for message\output\airnotifier\classes\privacy\provider.php
+ *
+ * @copyright 2018 Adrian Greeve <adrian@moodle.com>
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class message_airnotifier_testcase extends provider_testcase {
+
+ /**
+ * Basic setup for these tests.
+ */
+ public function setUp() {
+ $this->resetAfterTest(true);
+ }
+
+ /**
+ * /
+ * @param object $user User object
+ * @param string $pushid unique string
+ */
+ protected function add_device($user, $pushid) {
+ global $DB;
+
+ // Add fake core device.
+ $device = array(
+ 'appid' => 'com.moodle.moodlemobile',
+ 'name' => 'occam',
+ 'model' => 'Nexus 4',
+ 'platform' => 'Android',
+ 'version' => '4.2.2',
+ 'pushid' => $pushid,
+ 'uuid' => 'asdnfl348qlksfaasef859',
+ 'userid' => $user->id,
+ 'timecreated' => time(),
+ 'timemodified' => time(),
+ );
+ $coredeviceid = $DB->insert_record('user_devices', (object) $device);
+
+ $airnotifierdev = array(
+ 'userdeviceid' => $coredeviceid,
+ 'enable' => 1
+ );
+ $airnotifierdevid = $DB->insert_record('message_airnotifier_devices', (object) $airnotifierdev);
+ }
+
+ /**
+ * Test returning metadata.
+ */
+ public function test_get_metadata() {
+ $collection = new \core_privacy\local\metadata\collection('message_airnotifier');
+ $collection = \message_airnotifier\privacy\provider::get_metadata($collection);
+ $this->assertNotEmpty($collection);
+ }
+
+ /**
+ * Test getting the context for the user ID related to this plugin.
+ */
+ public function test_get_contexts_for_userid() {
+
+ $user = $this->getDataGenerator()->create_user();
+ $context = context_user::instance($user->id);
+
+ $this->add_device($user, 'apuJih874kj');
+ $this->add_device($user, 'bdu09Ikjjsu');
+
+ $contextlist = \message_airnotifier\privacy\provider::get_contexts_for_userid($user->id);
+ $this->assertEquals($context->id, $contextlist->current()->id);
+ }
+
+ /**
+ * Test that data is exported correctly for this plugin.
+ */
+ public function test_export_user_data() {
+ $user = $this->getDataGenerator()->create_user();
+ $context = context_user::instance($user->id);
+
+ $this->add_device($user, 'apuJih874kj');
+ $this->add_device($user, 'bdu09Ikjjsu');
+
+ $writer = \core_privacy\local\request\writer::with_context($context);
+ $this->assertFalse($writer->has_any_data());
+ $this->export_context_data_for_user($user->id, $context, 'message_airnotifier');
+
+ // First device.
+ $data = $writer->get_data([get_string('privacy:subcontext', 'message_airnotifier'), 'Nexus 4_apuJih874kj']);
+ $this->assertEquals('com.moodle.moodlemobile', $data->appid);
+
+ // Second device.
+ $data = $writer->get_data([get_string('privacy:subcontext', 'message_airnotifier'), 'Nexus 4_bdu09Ikjjsu']);
+ $this->assertEquals('bdu09Ikjjsu', $data->pushid);
+ }
+
+ /**
+ * Test that user data is deleted using the context.
+ */
+ public function test_delete_data_for_all_users_in_context() {
+ global $DB;
+
+ $user = $this->getDataGenerator()->create_user();
+ $context = context_user::instance($user->id);
+
+ $this->add_device($user, 'apuJih874kj');
+
+ // Check that we have an entry.
+ $devices = $DB->get_records('message_airnotifier_devices');
+ $this->assertCount(1, $devices);
+
+ \message_airnotifier\privacy\provider::delete_data_for_all_users_in_context($context);
+
+ // Check that it has now been deleted.
+ $devices = $DB->get_records('message_airnotifier_devices');
+ $this->assertCount(0, $devices);
+ }
+
+ /**
+ * Test that user data is deleted for this user.
+ */
+ public function test_delete_data_for_user() {
+ global $DB;
+
+ $user = $this->getDataGenerator()->create_user();
+ $context = context_user::instance($user->id);
+
+ $this->add_device($user, 'apuJih874kj');
+
+ // Check that we have an entry.
+ $devices = $DB->get_records('message_airnotifier_devices');
+ $this->assertCount(1, $devices);
+
+ $approvedlist = new \core_privacy\local\request\approved_contextlist($user, 'message_airnotifier', [$context->id]);
+ \message_airnotifier\privacy\provider::delete_data_for_user($approvedlist);
+
+ // Check that it has now been deleted.
+ $devices = $DB->get_records('message_airnotifier_devices');
+ $this->assertCount(0, $devices);
+ }
+}
*/
-namespace ltiservice_memberships\local\resource;
+namespace ltiservice_memberships\local\resources;
use \mod_lti\local\ltiservice\service_base;
use ltiservice_memberships\local\service\memberships;
*/
-namespace ltiservice_memberships\local\resource;
+namespace ltiservice_memberships\local\resources;
use \mod_lti\local\ltiservice\service_base;
use ltiservice_memberships\local\service\memberships;
if (empty($this->resources)) {
$this->resources = array();
- $this->resources[] = new \ltiservice_memberships\local\resource\contextmemberships($this);
- $this->resources[] = new \ltiservice_memberships\local\resource\linkmemberships($this);
+ $this->resources[] = new \ltiservice_memberships\local\resources\contextmemberships($this);
+ $this->resources[] = new \ltiservice_memberships\local\resources\linkmemberships($this);
}
return $this->resources;
--- /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/>.
+
+/**
+ * Lists renamed classes so that the autoloader can make the old names still work.
+ *
+ * @package mod_lti
+ * @copyright 2018 Thom Rawson
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die();
+
+// Array 'old_class_name' => 'new\class_name'.
+$renamedclasses = array(
+
+ // Changed for PHP 7.0 which now has the word "resource" as a reserved word.
+ 'ltiservice_memberships\local\resource\linkmemberships' => 'ltiservice_memberships\local\resources\linkmemberships',
+ 'ltiservice_memberships\local\resource\contextmemberships' => 'ltiservice_memberships\local\resources\contextmemberships',
+
+);
*/
-namespace ltiservice_profile\local\resource;
+namespace ltiservice_profile\local\resources;
use \mod_lti\local\ltiservice\service_base;
/**
* Class constructor.
*
- * @param ltiservice_profile\local\resource\profile $service Service instance
+ * @param ltiservice_profile\local\resources\profile $service Service instance
*/
public function __construct($service) {
if (empty($this->resources)) {
$this->resources = array();
- $this->resources[] = new \ltiservice_profile\local\resource\profile($this);
+ $this->resources[] = new \ltiservice_profile\local\resources\profile($this);
}
return $this->resources;
--- /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/>.
+
+/**
+ * Lists renamed classes so that the autoloader can make the old names still work.
+ *
+ * @package mod_lti
+ * @copyright 2018 Thom Rawson
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die();
+
+// Array 'old_class_name' => 'new\class_name'.
+$renamedclasses = array(
+
+ // Changed for PHP 7.0 which now has the word "resource" as a reserved word.
+ 'ltiservice_profile\local\resource\profile' => 'ltiservice_profile\local\resources\profile',
+);
+
*/
-namespace ltiservice_toolproxy\local\resource;
+namespace ltiservice_toolproxy\local\resources;
defined('MOODLE_INTERNAL') || die();
/**
* Class constructor.
*
- * @param ltiservice_toolproxy\local\resource\toolproxy $service Service instance
+ * @param ltiservice_toolproxy\local\resources\toolproxy $service Service instance
*/
public function __construct($service) {
if (empty($this->resources)) {
$this->resources = array();
- $this->resources[] = new \ltiservice_toolproxy\local\resource\toolproxy($this);
+ $this->resources[] = new \ltiservice_toolproxy\local\resources\toolproxy($this);
}
return $this->resources;
--- /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/>.
+
+/**
+ * Lists renamed classes so that the autoloader can make the old names still work.
+ *
+ * @package mod_lti
+ * @copyright 2018 Thom Rawson
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die();
+
+// Array 'old_class_name' => 'new\class_name'.
+$renamedclasses = array(
+
+ // Changed for PHP 7.0 which now has the word "resource" as a reserved word.
+ 'ltiservice_toolproxy\local\resource\toolproxy' => 'ltiservice_toolproxy\local\resources\toolproxy',
+);
+
*/
-namespace ltiservice_toolsettings\local\resource;
+namespace ltiservice_toolsettings\local\resources;
-use ltiservice_toolsettings\local\resource\systemsettings;
+use ltiservice_toolsettings\local\resources\systemsettings;
use ltiservice_toolsettings\local\service\toolsettings;
defined('MOODLE_INTERNAL') || die();
/**
* Class constructor.
*
- * @param ltiservice_toolsettings\local\resource\contextsettings $service Service instance
+ * @param ltiservice_toolsettings\local\resources\contextsettings $service Service instance
*/
public function __construct($service) {
*/
-namespace ltiservice_toolsettings\local\resource;
+namespace ltiservice_toolsettings\local\resources;
-use ltiservice_toolsettings\local\resource\systemsettings;
-use ltiservice_toolsettings\local\resource\contextsettings;
+use ltiservice_toolsettings\local\resources\systemsettings;
+use ltiservice_toolsettings\local\resources\contextsettings;
use ltiservice_toolsettings\local\service\toolsettings;
defined('MOODLE_INTERNAL') || die();
/**
* Class constructor.
*
- * @param ltiservice_toolsettings\local\resource\linksettings $service Service instance
+ * @param ltiservice_toolsettings\local\resources\linksettings $service Service instance
*/
public function __construct($service) {
*/
-namespace ltiservice_toolsettings\local\resource;
+namespace ltiservice_toolsettings\local\resources;
use ltiservice_toolsettings\local\service\toolsettings;
if (empty($this->resources)) {
$this->resources = array();
- $this->resources[] = new \ltiservice_toolsettings\local\resource\systemsettings($this);
- $this->resources[] = new \ltiservice_toolsettings\local\resource\contextsettings($this);
- $this->resources[] = new \ltiservice_toolsettings\local\resource\linksettings($this);
+ $this->resources[] = new \ltiservice_toolsettings\local\resources\systemsettings($this);
+ $this->resources[] = new \ltiservice_toolsettings\local\resources\contextsettings($this);
+ $this->resources[] = new \ltiservice_toolsettings\local\resources\linksettings($this);
}
return $this->resources;
--- /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/>.
+
+/**
+ * Lists renamed classes so that the autoloader can make the old names still work.
+ *
+ * @package mod_lti
+ * @copyright 2018 Thom Rawson
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die();
+
+// Array 'old_class_name' => 'new\class_name'.
+$renamedclasses = array(
+
+ // Changed for PHP 7.0 which now has the word "resource" as a reserved word.
+ 'ltiservice_toolsettings\local\resource\contextsettings' => 'ltiservice_toolsettings\local\resources\contextsettings',
+ 'ltiservice_toolsettings\local\resource\linksettings' => 'ltiservice_toolsettings\local\resources\linksettings',
+ 'ltiservice_toolsettings\local\resource\systemsettings' => 'ltiservice_toolsettings\local\resources\systemsettings',
+);
+
stopOnIncomplete="false"
stopOnSkipped="false"
beStrictAboutTestsThatDoNotTestAnything="false"
+ beStrictAboutOutputDuringTests="true"
printerClass="Hint_ResultPrinter"
testSuiteLoaderClass="phpunit_autoloader"
>
];
}
- $this->customfiles[$this->context->id] = array_replace_recursive($this->customfiles[$this->context->id], $finalcontent);
+ $this->files[$this->context->id] = array_replace_recursive($this->files[$this->context->id], $finalcontent);
}
return $this;
}
}
+ /**
+ * Like the parent method, except that when a response is gradable, but not
+ * completely, we move it to the invalid state.
+ * @param question_attempt_pending_step $pendingstep a partially initialised step
+ * containing all the information about the action that is being performed.
+ * @return bool either {@link question_attempt::KEEP} or {@link question_attempt::DISCARD}
+ */
+ public function process_save(question_attempt_pending_step $pendingstep) {
+ if ($this->qa->get_state()->is_finished()) {
+ return question_attempt::DISCARD;
+ } else if (!$this->qa->get_state()->is_active()) {
+ throw new coding_exception('Question is not active, cannot process_actions.');
+ }
+
+ if ($this->is_same_response($pendingstep)) {
+ return question_attempt::DISCARD;
+ }
+
+ if ($this->is_complete_response($pendingstep)) {
+ $pendingstep->set_state(question_state::$complete);
+ } else if ($this->question->is_gradable_response($pendingstep->get_qt_data())) {
+ $pendingstep->set_state(question_state::$invalid);
+ } else {
+ $pendingstep->set_state(question_state::$todo);
+ }
+ return question_attempt::KEEP;
+ }
+
public function summarise_action(question_attempt_step $step) {
if ($step->has_behaviour_var('comment')) {
return $this->summarise_manual_comment($step);
}
$response = $this->qa->get_last_step()->get_qt_data();
- if (!$this->question->is_complete_response($response)) {
+ if (!$this->question->is_gradable_response($response)) {
$pendingstep->set_state(question_state::$gaveup);
} else {
$pendingstep->set_state(question_state::$needsgrading);
$essay = new backup_nested_element('essay', array('id'), array(
'responseformat', 'responserequired', 'responsefieldlines',
'attachments', 'attachmentsrequired', 'graderinfo',
- 'graderinfoformat', 'responsetemplate', 'responsetemplateformat'));
+ 'graderinfoformat', 'responsetemplate', 'responsetemplateformat', 'filetypeslist'));
// Now the own qtype tree.
$pluginwrapper->add_child($essay);
<FIELD NAME="graderinfoformat" TYPE="int" LENGTH="4" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="The text format for graderinfo."/>
<FIELD NAME="responsetemplate" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="The template to pre-populate student's response field during attempt."/>
<FIELD NAME="responsetemplateformat" TYPE="int" LENGTH="4" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="The text format for responsetemplate."/>
+ <FIELD NAME="filetypeslist" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="What attachment file type a student is allowed to include with their response. * or empty means unlimited."/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
* @param int $oldversion the version we are upgrading from.
*/
function xmldb_qtype_essay_upgrade($oldversion) {
- global $CFG;
+ global $CFG, $DB;
+
+ $dbman = $DB->get_manager();
// Automatically generated Moodle v3.2.0 release upgrade line.
// Put any upgrade step following this.
// Automatically generated Moodle v3.4.0 release upgrade line.
// Put any upgrade step following this.
+ if ($oldversion < 2018021800) {
+
+ // Add "filetypeslist" column to the question type options to save the allowed file types.
+ $table = new xmldb_table('qtype_essay_options');
+ $field = new xmldb_field('filetypeslist', XMLDB_TYPE_TEXT, null, null, null, null, null, 'responsetemplateformat');
+
+ // Conditionally launch add field filetypeslist.
+ if (!$dbman->field_exists($table, $field)) {
+ $dbman->add_field($table, $field);
+ }
+
+ // Essay savepoint reached.
+ upgrade_plugin_savepoint(true, 2018021800, 'qtype', 'essay');
+ }
return true;
}
$mform->addHelpButton('attachmentsrequired', 'attachmentsrequired', 'qtype_essay');
$mform->disabledIf('attachmentsrequired', 'attachments', 'eq', 0);
+ $mform->addElement('filetypes', 'filetypeslist', get_string('acceptedfiletypes', 'qtype_essay'));
+ $mform->addHelpButton('filetypeslist', 'acceptedfiletypes', 'qtype_essay');
+ $mform->disabledIf('filetypeslist', 'attachments', 'eq', 0);
+
$mform->addElement('header', 'responsetemplateheader', get_string('responsetemplateheader', 'qtype_essay'));
$mform->addElement('editor', 'responsetemplate', get_string('responsetemplate', 'qtype_essay'),
array('rows' => 10), array_merge($this->editoroptions, array('maxfiles' => 0)));
$question->responsefieldlines = $question->options->responsefieldlines;
$question->attachments = $question->options->attachments;
$question->attachmentsrequired = $question->options->attachmentsrequired;
+ $question->filetypeslist = $question->options->filetypeslist;
$draftid = file_get_submitted_draft_itemid('graderinfo');
$question->graderinfo = array();
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
+$string['acceptedfiletypes'] = 'Accepted file types';
+$string['acceptedfiletypes_help'] = 'Accepted file types can be restricted by entering a list of file extensions. If the field is left empty, then all file types are allowed.';
$string['allowattachments'] = 'Allow attachments';
$string['attachmentsoptional'] = 'Attachments are optional';
$string['attachmentsrequired'] = 'Require attachments';
$string['mustrequire'] = 'When "No online text" is selected, or responses are optional, you must require at least one attachment.';
$string['mustrequirefewer'] = 'You cannot require more attachments than you allow.';
$string['nlines'] = '{$a} lines';
+$string['nonexistentfiletypes'] = 'The following file types were not recognised: {$a}';
$string['pluginname'] = 'Essay';
$string['pluginname_help'] = 'In response to a question, the respondent may upload one or more files and/or enter text online. A response template may be provided. Responses must be graded manually.';
$string['pluginname_link'] = 'question/type/essay';
public $responsetemplate;
public $responsetemplateformat;
+ /** @var array The string array of file types accepted upon file submission. */
+ public $filetypeslist;
+
public function make_behaviour(question_attempt $qa, $preferredbehaviour) {
return question_engine::make_behaviour('manualgraded', $qa, $preferredbehaviour);
}
// Determine the number of attachments present.
if ($hasattachments) {
+ // Check the filetypes.
+ $filetypesutil = new \core_form\filetypes_util();
+ $whitelist = $filetypesutil->normalize_file_types($this->filetypeslist);
+ $wrongfiles = array();
+ foreach ($response['attachments']->get_files() as $file) {
+ if (!$filetypesutil->is_allowed_file_type($file->get_filename(), $whitelist)) {
+ $wrongfiles[] = $file->get_filename();
+ }
+ }
+ if ($wrongfiles) { // At least one filetype is wrong.
+ return false;
+ }
$attachcount = count($response['attachments']->get_files());
} else {
$attachcount = 0;
return $hascontent && $meetsinlinereq && $meetsattachmentreq;
}
+ public function is_gradable_response(array $response) {
+ // Determine if the given response has online text and attachments.
+ if (array_key_exists('answer', $response) && ($response['answer'] !== '')) {
+ return true;
+ } else if (array_key_exists('attachments', $response)
+ && $response['attachments'] instanceof question_response_files) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
public function is_same_response(array $prevresponse, array $newresponse) {
if (array_key_exists('answer', $prevresponse) && $prevresponse['answer'] !== $this->responsetemplate) {
$value1 = (string) $prevresponse['answer'];
$options->responsefieldlines = $formdata->responsefieldlines;
$options->attachments = $formdata->attachments;
$options->attachmentsrequired = $formdata->attachmentsrequired;
+ if (!isset($formdata->filetypeslist)) {
+ $options->filetypeslist = "";
+ } else {
+ $options->filetypeslist = $formdata->filetypeslist;
+ }
$options->graderinfo = $this->import_or_save_files($formdata->graderinfo,
$context, 'qtype_essay', 'graderinfo', $formdata->id);
$options->graderinfoformat = $formdata->graderinfo['format'];
$question->graderinfoformat = $questiondata->options->graderinfoformat;
$question->responsetemplate = $questiondata->options->responsetemplate;
$question->responsetemplateformat = $questiondata->options->responsetemplateformat;
+ $filetypesutil = new \core_form\filetypes_util();
+ $question->filetypeslist = $filetypesutil->normalize_file_types($questiondata->options->filetypeslist);
}
public function delete_question($questionid, $contextid) {
$pickeroptions->itemid = $qa->prepare_response_files_draft_itemid(
'attachments', $options->context->id);
+ $pickeroptions->accepted_types = $qa->get_question()->filetypeslist;
$fm = new form_filemanager($pickeroptions);
$filesrenderer = $this->page->get_renderer('core', 'files');
+
+ $text = '';
+ if (!empty($qa->get_question()->filetypeslist)) {
+ $text = html_writer::tag('p', get_string('acceptedfiletypes', 'qtype_essay'));
+ $filetypesutil = new \core_form\filetypes_util();
+ $filetypes = $qa->get_question()->filetypeslist;
+ $filetypedescriptions = $filetypesutil->describe_file_types($filetypes);
+ $text .= $this->render_from_template('core_form/filetypes-descriptions', $filetypedescriptions);
+ }
return $filesrenderer->render($fm). html_writer::empty_tag(
'input', array('type' => 'hidden', 'name' => $qa->get_qt_field_name('attachments'),
- 'value' => $pickeroptions->itemid));
+ 'value' => $pickeroptions->itemid)) . $text;
}
public function manual_comment(question_attempt $qa, question_display_options $options) {
--- /dev/null
+@qtype @qtype_essay
+Feature: In a essay question, limit submittable file types
+In order to constrain student submissions for marking
+As a teacher
+I need to limit the submittable file types
+
+ Background:
+ Given the following "users" exist:
+ | username | firstname | lastname | email |
+ | teacher1 | Teacher | 1 | teacher1@example.com |
+ | student1 | Student | 1 | student0@example.com |
+ And the following "courses" exist:
+ | fullname | shortname | category |
+ | Course 1 | C1 | 0 |
+ And the following "course enrolments" exist:
+ | user | course | role |
+ | teacher1 | C1 | editingteacher |
+ | student1 | C1 | student |
+ And the following "question categories" exist:
+ | contextlevel | reference | name |
+ | Course | C1 | Test questions |
+ And the following "questions" exist:
+ | questioncategory | qtype | name | questiontext | defaultmark |
+ | Test questions | essay | TF1 | First question | 20 |
+ And the following "activities" exist:
+ | activity | name | intro | course | idnumber | grade |
+ | quiz | Quiz 1 | Quiz 1 description | C1 | quiz1 | 20 |
+ And quiz "Quiz 1" contains the following questions:
+ | question | page |
+ | TF1 | 1 |
+ Given I log in as "teacher1"
+ And I am on "Course 1" course homepage
+ And I follow "Quiz 1"
+ And I navigate to "Edit quiz" in current page administration
+ And I click on "Edit question TF1" "link"
+ And I set the field "Allow attachments" to "1"
+ And I set the field "Response format" to "No online text"
+ And I set the field "Require attachments" to "1"
+ And I set the field "filetypeslist[filetypes]" to ".txt"
+ And I press "Save changes"
+ Then I log out
+
+ @javascript @_file_upload
+ Scenario: Preview an Essay question and submit a response with a correct filetype.
+ When I log in as "student1"
+ And I follow "Manage private files"
+ And I upload "lib/tests/fixtures/empty.txt" file to "Files" filemanager
+ And I press "Save changes"
+ And I am on "Course 1" course homepage
+ And I follow "Quiz 1"
+ And I press "Attempt quiz now"
+ And I should see "First question"
+ And I should see "You can drag and drop files here to add them."
+ And I click on "Add..." "button"
+ And I click on "Private files" "link" in the ".fp-repo-area" "css_element"
+ And I click on "empty.txt" "link"
+ And I click on "Select this file" "button"
+ # Wait for the page to "settle".
+ And I wait until the page is ready
+ Then I should not see "These file types are not allowed here:"
+
+ @javascript @_file_upload
+ Scenario: Preview an Essay question and try to submit a response with an incorrect filetype.
+ When I log in as "student1"
+ And I follow "Manage private files"
+ And I upload "lib/tests/fixtures/upload_users.csv" file to "Files" filemanager
+ And I press "Save changes"
+ And I am on "Course 1" course homepage
+ And I follow "Quiz 1"
+ And I press "Attempt quiz now"
+ And I should see "First question"
+ And I should see "You can drag and drop files here to add them."
+ And I click on "Add..." "button"
+ And I click on "Private files" "link" in the ".fp-repo-area" "css_element"
+ Then I should see "No files available"
<responsefieldlines>15</responsefieldlines>
<attachments>0</attachments>
<attachmentsrequired>0</attachmentsrequired>
+ <filetypeslist></filetypeslist>
<graderinfo format="html">
<text></text>
</graderinfo>
$q->responsefieldlines = 10;
$q->attachments = 0;
$q->attachmentsrequired = 0;
+ $q->filetypeslist = '';
$q->graderinfo = '';
$q->graderinfoformat = FORMAT_HTML;
$q->qtype = question_bank::get_qtype('essay');
$fromform->responsefieldlines = 10;
$fromform->attachments = 0;
$fromform->attachmentsrequired = 0;
+ $fromform->filetypeslist = '';
$fromform->graderinfo = array('text' => '', 'format' => FORMAT_HTML);
$fromform->responsetemplate = array('text' => '', 'format' => FORMAT_HTML);
return $q;
}
+ /**
+ * Makes an essay question using the HTML editor allowing embedded files as
+ * input, and up to two attachments, two needed.
+ * @return qtype_essay_question
+ */
+ public function make_essay_question_editorfilepickertworequired() {
+ $q = $this->initialise_essay_question();
+ $q->responseformat = 'editorfilepicker';
+ $q->attachments = 2;
+ $q->attachmentsrequired = 2;
+ return $q;
+ }
+
/**
* Make the data what would be received from the editing form for an essay
* question using the HTML editor allowing embedded files as input, and up
$fromform->responsefieldlines = 10;
$fromform->attachments = 3;
$fromform->attachmentsrequired = 0;
+ $fromform->filetypeslist = '';
$fromform->graderinfo = array('text' => '', 'format' => FORMAT_HTML);
$fromform->responsetemplate = array('text' => '', 'format' => FORMAT_HTML);
$fromform->responsefieldlines = 10;
$fromform->attachments = 0;
$fromform->attachmentsrequired = 0;
+ $fromform->filetypeslist = '';
$fromform->graderinfo = array('text' => '', 'format' => FORMAT_HTML);
$fromform->responsetemplate = array('text' => '', 'format' => FORMAT_HTML);
$q->responseformat = 'noinline';
$q->attachments = 3;
$q->attachmentsrequired = 1;
+ $q->filetypeslist = '';
return $q;
}
// Test for the hash of an empty file area.
$this->assertNotContains('d41d8cd98f00b204e9800998ecf8427e', $this->currentoutput);
}
+
+ public function test_deferred_feedback_html_editor_with_files_attempt_wrong_filetypes() {
+ global $CFG, $USER, $PAGE;
+
+ $this->resetAfterTest(true);
+ $this->setAdminUser();
+ // Required to init a text editor.
+ $PAGE->set_url('/');
+ $usercontextid = context_user::instance($USER->id)->id;
+ $fs = get_file_storage();
+
+ // Create an essay question in the DB.
+ $generator = $this->getDataGenerator()->get_plugin_generator('core_question');
+ $cat = $generator->create_question_category();
+ $question = $generator->create_question('essay', 'editorfilepicker', array('category' => $cat->id));
+
+ // Start attempt at the question.
+ $q = question_bank::load_question($question->id);
+ $q->filetypeslist = ("pdf, docx");
+ $this->start_attempt_at_question($q, 'deferredfeedback', 1);
+
+ $this->check_current_state(question_state::$todo);
+ $this->check_current_mark(null);
+ $this->check_step_count(1);
+
+ // Process a response and check the expected result.
+ // First we need to get the draft item ids.
+ $this->render();
+ if (!preg_match('/env=editor&.*?itemid=(\d+)&/', $this->currentoutput, $matches)) {
+ throw new coding_exception('Editor draft item id not found.');
+ }
+ $editordraftid = $matches[1];
+ if (!preg_match('/env=filemanager&action=browse&.*?itemid=(\d+)&/', $this->currentoutput, $matches)) {
+ throw new coding_exception('File manager draft item id not found.');
+ }
+ $attachementsdraftid = $matches[1];
+
+ $this->save_file_to_draft_area($usercontextid, $editordraftid, 'smile.txt', ':-)');
+ $this->save_file_to_draft_area($usercontextid, $attachementsdraftid, 'greeting.txt', 'Hello world!');
+ $this->process_submission(array(
+ 'answer' => 'Here is a picture: <img src="' . $CFG->wwwroot .
+ "/draftfile.php/{$usercontextid}/user/draft/{$editordraftid}/smile.txt" .
+ '" alt="smile">.',
+ 'answerformat' => FORMAT_HTML,
+ 'answer:itemid' => $editordraftid,
+ 'attachments' => $attachementsdraftid));
+
+ $this->check_current_state(question_state::$invalid);
+ $this->check_current_mark(null);
+ $this->check_step_count(2);
+ $this->save_quba();
+
+ // Now submit all and finish.
+ $this->finish();
+ $this->check_current_state(question_state::$needsgrading);
+ $this->check_current_mark(null);
+ $this->check_step_count(3);
+ $this->save_quba();
+ }
+
+ public function test_deferred_feedback_html_editor_with_files_attempt_correct_filetypes() {
+ global $CFG, $USER, $PAGE;
+
+ $this->resetAfterTest(true);
+ $this->setAdminUser();
+ // Required to init a text editor.
+ $PAGE->set_url('/');
+ $usercontextid = context_user::instance($USER->id)->id;
+ $fs = get_file_storage();
+
+ // Create an essay question in the DB.
+ $generator = $this->getDataGenerator()->get_plugin_generator('core_question');
+ $cat = $generator->create_question_category();
+ $question = $generator->create_question('essay', 'editorfilepicker', array('category' => $cat->id));
+
+ // Start attempt at the question.
+ $q = question_bank::load_question($question->id);
+ $q->filetypeslist = ("txt, docx");
+ $this->start_attempt_at_question($q, 'deferredfeedback', 1);
+
+ $this->check_current_state(question_state::$todo);
+ $this->check_current_mark(null);
+ $this->check_step_count(1);
+
+ // Process a response and check the expected result.
+ // First we need to get the draft item ids.
+ $this->render();
+ if (!preg_match('/env=editor&.*?itemid=(\d+)&/', $this->currentoutput, $matches)) {
+ throw new coding_exception('Editor draft item id not found.');
+ }
+ $editordraftid = $matches[1];
+ if (!preg_match('/env=filemanager&action=browse&.*?itemid=(\d+)&/', $this->currentoutput, $matches)) {
+ throw new coding_exception('File manager draft item id not found.');
+ }
+ $attachementsdraftid = $matches[1];
+
+ $this->save_file_to_draft_area($usercontextid, $editordraftid, 'smile.txt', ':-)');
+ $this->save_file_to_draft_area($usercontextid, $attachementsdraftid, 'greeting.txt', 'Hello world!');
+ $this->process_submission(array(
+ 'answer' => 'Here is a picture: <img src="' . $CFG->wwwroot .
+ "/draftfile.php/{$usercontextid}/user/draft/{$editordraftid}/smile.txt" .
+ '" alt="smile">.',
+ 'answerformat' => FORMAT_HTML,
+ 'answer:itemid' => $editordraftid,
+ 'attachments' => $attachementsdraftid));
+
+ $this->check_current_state(question_state::$complete);
+ $this->check_current_mark(null);
+ $this->check_step_count(2);
+ $this->save_quba();
+
+ // Now submit all and finish.
+ $this->finish();
+ $this->check_current_state(question_state::$needsgrading);
+ $this->check_current_mark(null);
+ $this->check_step_count(3);
+ $this->save_quba();
+ }
}
defined('MOODLE_INTERNAL') || die();
$plugin->component = 'qtype_essay';
-$plugin->version = 2017111300;
+$plugin->version = 2018021800;
$plugin->requires = 2017110800;
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
interface question_manually_gradable {
+ /**
+ * Use by many of the behaviours to determine whether the student
+ * has provided enough of an answer for the question to be graded automatically,
+ * or whether it must be considered aborted.
+ *
+ * @param array $response responses, as returned by
+ * {@link question_attempt_step::get_qt_data()}.
+ * @return bool whether this response can be graded.
+ */
+ public function is_gradable_response(array $response);
+
/**
* Used by many of the behaviours, to work out whether the student's
* response to the question is complete. That is, whether the question attempt
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
interface question_automatically_gradable extends question_manually_gradable {
- /**
- * Use by many of the behaviours to determine whether the student
- * has provided enough of an answer for the question to be graded automatically,
- * or whether it must be considered aborted.
- *
- * @param array $response responses, as returned by
- * {@link question_attempt_step::get_qt_data()}.
- * @return bool whether this response can be graded.
- */
- public function is_gradable_response(array $response);
-
/**
* In situations where is_gradable_response() returns false, this method
* should generate a description of what the problem is.
public function classify_response(array $response) {
return array();
}
+
+ public function is_gradable_response(array $response) {
+ return $this->is_complete_response($response);
+ }
}
/** @var Some question types have the option to show the number of sub-parts correct. */
public $shownumcorrect = false;
- public function is_gradable_response(array $response) {
- return $this->is_complete_response($response);
- }
-
public function get_right_answer_summary() {
$correctresponse = $this->get_correct_response();
if (empty($correctresponse)) {
This files describes API changes for question type plugins.
-== 3.5 ==
+=== 3.5 ===
+ Added new classes backup_qtype_extrafields_plugin and restore_qtype_extrafields_plugin
in order to use extra fields method in backup/restore question type. Require and inherit new classes for using it. See
backup_qtype_shortanswer_plugin and restore_qtype_shortanswer_plugin for an example of using this.
+ + The declaration of is_gradable_response has been moved from question_automatically_gradable to
+ question_manually_gradable.
+ + The default implementation of is_gradable_response has been moved from question_graded_automatically to
+ question_with_responses.
=== 3.1.5, 3.2.2, 3.3 ===