first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-09-30 18:11:26 -04:00
commit e592ca6823
27270 changed files with 5002257 additions and 0 deletions
@@ -0,0 +1,66 @@
<?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/>.
/**
* Activity base class.
*
* @package mod_assign
* @copyright 2017 onwards Ankit Agarwal <ankit.agrr@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign\analytics\indicator;
defined('MOODLE_INTERNAL') || die();
/**
* Activity base class.
*
* @package mod_assign
* @copyright 2017 onwards Ankit Agarwal <ankit.agrr@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
abstract class activity_base extends \core_analytics\local\indicator\community_of_inquiry_activity {
/**
* feedback_viewed_events
*
* @return string[]
*/
protected function feedback_viewed_events() {
return array('\mod_assign\event\feedback_viewed');
}
/**
* feedback_check_grades
*
* @return bool
*/
protected function feedback_check_grades() {
// We need the grade to be released to the student to consider that feedback has been provided.
return true;
}
/**
* Returns the name of the field that controls activity availability.
*
* @return null|string
*/
protected function get_timeclose_field() {
return 'duedate';
}
}
@@ -0,0 +1,80 @@
<?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/>.
/**
* Cognitive depth indicator - assign.
*
* @package mod_assign
* @copyright 2017 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign\analytics\indicator;
defined('MOODLE_INTERNAL') || die();
/**
* Cognitive depth indicator - assign.
*
* @package mod_assign
* @copyright 2017 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class cognitive_depth extends activity_base {
/**
* Returns the name.
*
* If there is a corresponding '_help' string this will be shown as well.
*
* @return \lang_string
*/
public static function get_name(): \lang_string {
return new \lang_string('indicator:cognitivedepth', 'mod_assign');
}
public function get_indicator_type() {
return self::INDICATOR_COGNITIVE;
}
public function get_cognitive_depth_level(\cm_info $cm) {
return self::COGNITIVE_LEVEL_5;
}
/**
* feedback_submitted_events
*
* @return string[]
*/
protected function feedback_submitted_events() {
return array('\mod_assign\event\assessable_submitted');
}
/**
* feedback_replied
*
* @param \cm_info $cm
* @param int $contextid
* @param int $userid
* @param int $after
* @return bool
*/
protected function feedback_replied(\cm_info $cm, $contextid, $userid, $after = false) {
// No level 4.
return false;
}
}
@@ -0,0 +1,56 @@
<?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/>.
/**
* Social breadth indicator - assign.
*
* @package mod_assign
* @copyright 2017 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign\analytics\indicator;
defined('MOODLE_INTERNAL') || die();
/**
* Social breadth indicator - assign.
*
* @package mod_assign
* @copyright 2017 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class social_breadth extends activity_base {
/**
* Returns the name.
*
* If there is a corresponding '_help' string this will be shown as well.
*
* @return \lang_string
*/
public static function get_name(): \lang_string {
return new \lang_string('indicator:socialbreadth', 'mod_assign');
}
public function get_indicator_type() {
return self::INDICATOR_SOCIAL;
}
public function get_social_breadth_level(\cm_info $cm) {
return self::SOCIAL_LEVEL_2;
}
}
+110
View File
@@ -0,0 +1,110 @@
<?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/>.
/**
* Cache data source for the assign overrides.
*
* @package mod_assign
* @copyright 2021 Shamim Rezaie <shamim@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
declare(strict_types=1);
namespace mod_assign\cache;
use cache_definition;
/**
* Class assign_overrides
*
* @package mod_assign
* @copyright 2021 Shamim Rezaie <shamim@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class overrides implements \cache_data_source {
/** @var overrides the singleton instance of this class. */
protected static $instance = null;
/**
* Returns an instance of the data source class that the cache can use for loading data using the other methods
* specified by this interface.
*
* @param cache_definition $definition
* @return object
*/
public static function get_instance_for_cache(cache_definition $definition): overrides {
if (is_null(self::$instance)) {
self::$instance = new overrides();
}
return self::$instance;
}
/**
* Loads the data for the key provided ready formatted for caching.
*
* @param string|int $key The key to load.
* @return mixed What ever data should be returned, or false if it can't be loaded.
* @throws \coding_exception
*/
public function load_for_cache($key) {
global $DB;
[$assignid, $ug, $ugid] = explode('_', $key);
$assignid = (int) $assignid;
switch ($ug) {
case 'u':
$userid = (int) $ugid;
$override = $DB->get_record(
'assign_overrides',
['assignid' => $assignid, 'userid' => $userid],
'duedate, cutoffdate, allowsubmissionsfromdate'
);
break;
case 'g':
$groupid = (int) $ugid;
$override = $DB->get_record(
'assign_overrides',
['assignid' => $assignid, 'groupid' => $groupid],
'sortorder, duedate, cutoffdate, allowsubmissionsfromdate'
);
break;
default:
throw new \coding_exception('Invalid cache key');
}
// Return null instead of false, because false will not be cached.
return $override ?: null;
}
/**
* Loads several keys for the cache.
*
* @param array $keys An array of keys each of which will be string|int.
* @return array An array of matching data items.
*/
public function load_many_for_cache(array $keys) {
$results = [];
foreach ($keys as $key) {
$results[] = $this->load_for_cache($key);
}
return $results;
}
}
@@ -0,0 +1,95 @@
<?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/>.
declare(strict_types=1);
namespace mod_assign\completion;
use core_completion\activity_custom_completion;
/**
* Activity custom completion subclass for the assign activity.
*
* Class for defining mod_assign's custom completion rules and fetching the completion statuses
* of the custom completion rules for a given assign instance and a user.
*
* @package mod_assign
* @copyright Simey Lameze <simey@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class custom_completion extends activity_custom_completion {
/**
* Fetches the completion state for a given completion rule.
*
* @param string $rule The completion rule.
* @return int The completion state.
*/
public function get_state(string $rule): int {
global $CFG;
$this->validate_rule($rule);
$userid = $this->userid;
$cm = $this->cm;
require_once($CFG->dirroot . '/mod/assign/locallib.php');
$assign = new \assign(null, $cm, $cm->get_course());
if ($assign->get_instance()->teamsubmission) {
$submission = $assign->get_group_submission($userid, 0, false);
} else {
$submission = $assign->get_user_submission($userid, false);
}
$status = $submission && $submission->status == ASSIGN_SUBMISSION_STATUS_SUBMITTED;
return $status ? COMPLETION_COMPLETE : COMPLETION_INCOMPLETE;
}
/**
* Fetch the list of custom completion rules that this module defines.
*
* @return array
*/
public static function get_defined_custom_rules(): array {
return ['completionsubmit'];
}
/**
* Returns an associative array of the descriptions of custom completion rules.
*
* @return array
*/
public function get_custom_rule_descriptions(): array {
return [
'completionsubmit' => get_string('completiondetail:submit', 'assign')
];
}
/**
* Returns an array of all completion rules, in the order they should be displayed to users.
*
* @return array
*/
public function get_sort_order(): array {
return [
'completionview',
'completionsubmit',
'completionusegrade',
'completionpassgrade',
];
}
}
+99
View File
@@ -0,0 +1,99 @@
<?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/>.
/**
* Contains the class for fetching the important dates in mod_assign for a given module instance and a user.
*
* @package mod_assign
* @copyright 2021 Shamim Rezaie <shamim@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
declare(strict_types=1);
namespace mod_assign;
use core\activity_dates;
/**
* Class for fetching the important dates in mod_assign for a given module instance and a user.
*
* @copyright 2021 Shamim Rezaie <shamim@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class dates extends activity_dates {
/**
* Returns a list of important dates in mod_assign
*
* @return array
*/
protected function get_dates(): array {
global $CFG;
require_once($CFG->dirroot . '/mod/assign/locallib.php');
$course = get_course($this->cm->course);
$context = \context_module::instance($this->cm->id);
$assign = new \assign($context, $this->cm, $course);
$timeopen = $this->cm->customdata['allowsubmissionsfromdate'] ?? null;
$timedue = $this->cm->customdata['duedate'] ?? null;
$activitygroup = groups_get_activity_group($this->cm, true);
if ($activitygroup) {
if ($assign->can_view_grades()) {
$groupoverride = \cache::make('mod_assign', 'overrides')->get("{$this->cm->instance}_g_{$activitygroup}");
if (!empty($groupoverride->allowsubmissionsfromdate)) {
$timeopen = $groupoverride->allowsubmissionsfromdate;
}
if (!empty($groupoverride->duedate)) {
$timedue = $groupoverride->duedate;
}
}
}
$now = time();
$dates = [];
if ($timeopen) {
$openlabelid = $timeopen > $now ? 'activitydate:submissionsopen' : 'activitydate:submissionsopened';
$date = [
'dataid' => 'allowsubmissionsfromdate',
'label' => get_string($openlabelid, 'mod_assign'),
'timestamp' => (int) $timeopen,
];
if ($course->relativedatesmode && $assign->can_view_grades()) {
$date['relativeto'] = $course->startdate;
}
$dates[] = $date;
}
if ($timedue) {
$date = [
'dataid' => 'duedate',
'label' => get_string('activitydate:submissionsdue', 'mod_assign'),
'timestamp' => (int) $timedue,
];
if ($course->relativedatesmode && $assign->can_view_grades()) {
$date['relativeto'] = $course->startdate;
}
$dates[] = $date;
}
return $dates;
}
}
+289
View File
@@ -0,0 +1,289 @@
<?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/>.
namespace mod_assign;
use assign;
use core_php_time_limit;
use mod_assign\event\all_submissions_downloaded;
use core\session\manager as sessionmanager;
use core_files\archive_writer;
use stdClass;
use assign_plugin;
use stored_file;
/**
* Class to download user submissions.
*
* @package mod_assign
* @copyright 2022 Ferran Recio <ferran@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class downloader {
/** @var assign the module manager instance. */
private $manager;
/** @var stdClass the assign instance record. */
private $instance;
/** @var array|null the selected user ids, if any. */
private $userids = null;
/** @var int $groupmode the activity group mode. */
private $groupmode = '';
/** @var int $groupid the exported groupid. */
private $groupid = 0;
/** @var array $filesforzipping the files to zipo (path => file) */
protected $filesforzipping;
/** @var array $prefixes all loaded the student prefixes.
*
* A prefix will be converted into a file prefix or a folder name (depends on downloadasfolders).
*/
private $prefixes;
/** @var int $downloadasfolders the files to zipo (path => file) */
private $downloadasfolders;
/**
* Class constructor.
*
* @param assign $manager the instance manager
* @param array|null $userids the user ids to download.
*/
public function __construct(assign $manager, ?array $userids = null) {
$this->manager = $manager;
$this->userids = $userids;
$this->instance = $manager->get_instance();
$this->downloadasfolders = get_user_preferences('assign_downloadasfolders', 1);
$cm = $manager->get_course_module();
$this->groupmode = groups_get_activity_groupmode($cm);
if ($this->groupmode) {
$this->groupid = groups_get_activity_group($cm, true);
}
}
/**
* Load the filelist.
*
* @return bool true if there are some files to zip.
*/
public function load_filelist(): bool {
$manager = $this->manager;
$groupid = $this->groupid;
// Increase the server timeout to handle the creation and sending of large zip files.
core_php_time_limit::raise();
$manager->require_view_grades();
// Load all users with submit.
$students = get_enrolled_users(
$manager->get_context(),
"mod/assign:submit",
0,
'u.*',
null,
0,
0,
$manager->show_only_active_users()
);
// Build a list of files to zip.
$this->filesforzipping = [];
// Get all the files for each student.
foreach ($students as $student) {
// Download all assigments submission or only selected users.
if ($this->userids && !in_array($student->id, $this->userids)) {
continue;
}
if (!groups_is_member($groupid, $student->id) && $this->groupmode && $groupid) {
continue;
}
$this->load_student_filelist($student);
}
return !empty($this->filesforzipping);
}
/**
* Load an individual student filelist.
*
* @param stdClass $student the user record
*/
private function load_student_filelist(stdClass $student) {
$submission = $this->get_student_submission($student);
if (!$submission) {
return;
}
$prefix = $this->get_student_prefix($student);
if (isset($this->prefixes[$prefix])) {
// We already send that file (in group mode).
return;
}
$this->prefixes[$prefix] = $student->id;
foreach ($this->manager->get_submission_plugins() as $plugin) {
if (!$plugin->is_enabled() || !$plugin->is_visible()) {
continue;
}
$this->load_submissionplugin_filelist($student, $plugin, $submission, $prefix);
}
}
/**
* Return the student submission if any.
*
* @param stdClass $student the user record
* @return stdClass|null the user submission or null if none
*/
private function get_student_submission(stdClass $student): ?stdClass {
if ($this->instance->teamsubmission) {
$submission = $this->manager->get_group_submission($student->id, 0, false);
} else {
$submission = $this->manager->get_user_submission($student->id, false);
}
return $submission ?: null;
}
/**
* Return the file prefix used to generate the each submission folder or file.
*
* @param stdClass $student the user record
* @return string the submission prefix
*/
private function get_student_prefix(stdClass $student): string {
$manager = $this->manager;
// Team submissions are by group, not by student.
if ($this->instance->teamsubmission) {
$submissiongroup = $manager->get_submission_group($student->id);
if ($submissiongroup) {
$groupname = format_string($submissiongroup->name, true, ['context' => $manager->get_context()]);
$groupinfo = '_' . $submissiongroup->id;
} else {
$groupname = get_string('defaultteam', 'mod_assign');
$groupinfo = '';
}
$prefix = str_replace('_', ' ', $groupname);
return clean_filename($prefix . $groupinfo);
}
// Individual submissions are by user.
if ($manager->is_blind_marking()) {
$fullname = get_string('participant', 'mod_assign');
} else {
$fullname = fullname($student, has_capability('moodle/site:viewfullnames', $manager->get_context()));
}
$prefix = str_replace('_', ' ', $fullname);
$prefix = clean_filename($prefix . '_' . $manager->get_uniqueid_for_user($student->id));
return $prefix;
}
/**
* Load a submission plugin filelist for a specific user.
*
* @param stdClass $student the user record
* @param assign_plugin $plugin the submission plugin instance
* @param stdClass $submission the submission object
* @param string $prefix the files prefix
*/
private function load_submissionplugin_filelist(
stdClass $student,
assign_plugin $plugin,
stdClass $submission,
string $prefix
) {
$subtype = $plugin->get_subtype();
$type = $plugin->get_type();
if ($this->downloadasfolders) {
// Create a folder for each user for each assignment plugin.
// This is the default behavior for version of Moodle >= 3.1.
$submission->exportfullpath = true;
$pluginfiles = $plugin->get_files($submission, $student);
foreach ($pluginfiles as $zipfilepath => $file) {
$zipfilename = basename($zipfilepath);
$prefixedfilename = clean_filename($prefix . '_' . $subtype . '_' . $type);
if ($type == 'file') {
$pathfilename = $prefixedfilename . $file->get_filepath() . $zipfilename;
} else {
$pathfilename = $prefixedfilename . '/' . $zipfilename;
}
$pathfilename = clean_param($pathfilename, PARAM_PATH);
$this->filesforzipping[$pathfilename] = $file;
}
} else {
// Create a single folder for all users of all assignment plugins.
// This was the default behavior for version of Moodle < 3.1.
$submission->exportfullpath = false;
$pluginfiles = $plugin->get_files($submission, $student);
foreach ($pluginfiles as $zipfilename => $file) {
$prefixedfilename = clean_filename($prefix . '_' . $subtype . '_' . $type . '_' . $zipfilename);
$this->filesforzipping[$prefixedfilename] = $file;
}
}
}
/**
* Download the exported zip.
*
* This method will terminate the current script when the file is send.
*/
public function download_zip() {
$filename = $this->get_zip_filename();
all_submissions_downloaded::create_from_assign($this->manager)->trigger();
sessionmanager::write_close();
$zipwriter = archive_writer::get_stream_writer($filename, archive_writer::ZIP_WRITER);
// Stream the files into the zip.
foreach ($this->filesforzipping as $pathinzip => $file) {
if ($file instanceof stored_file) {
// Most of cases are stored_file.
$zipwriter->add_file_from_stored_file($pathinzip, $file);
} else if (is_array($file)) {
// Save $file as contents, from onlinetext subplugin.
$content = reset($file);
$zipwriter->add_file_from_string($pathinzip, $content);
}
}
// Finish the archive.
$zipwriter->finish();
exit();
}
/**
* Generate the zip filename.
*
* @return string the zip filename
*/
private function get_zip_filename(): string {
$manager = $this->manager;
$filenameparts = [
$manager->get_course()->shortname,
$this->instance->name,
];
if (!empty($this->groupid)) {
$filenameparts[] = format_string(groups_get_group_name($this->groupid), true, ['context' => $manager->get_context()]);
}
$filenameparts[] = $manager->get_course_module()->id;
return clean_filename(implode('-', $filenameparts). '.zip');
}
}
@@ -0,0 +1,112 @@
<?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/>.
/**
* The mod_assign all submissions downloaded event.
*
* @package mod_assign
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_assign all submissions downloaded event class.
*
* @package mod_assign
* @since Moodle 2.6
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class all_submissions_downloaded extends base {
/**
* Flag for prevention of direct create() call.
* @var bool
*/
protected static $preventcreatecall = true;
/**
* Create instance of event.
*
* @since Moodle 2.7
*
* @param \assign $assign
* @return all_submissions_downloaded
*/
public static function create_from_assign(\assign $assign) {
$data = array(
'context' => $assign->get_context(),
'objectid' => $assign->get_instance()->id
);
self::$preventcreatecall = false;
/** @var submission_graded $event */
$event = self::create($data);
self::$preventcreatecall = true;
$event->set_assign($assign);
return $event;
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' has downloaded all the submissions for the assignment " .
"with course module id '$this->contextinstanceid'.";
}
/**
* Return localised event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventallsubmissionsdownloaded', 'mod_assign');
}
/**
* Init method.
*
* @return void
*/
protected function init() {
$this->data['crud'] = 'r';
$this->data['edulevel'] = self::LEVEL_TEACHING;
$this->data['objecttable'] = 'assign';
}
/**
* Custom validation.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
if (self::$preventcreatecall) {
throw new \coding_exception('cannot call all_submissions_downloaded::create() directly, use all_submissions_downloaded::create_from_assign() instead.');
}
parent::validate_data();
}
public static function get_objectid_mapping() {
return array('db' => 'assign', 'restore' => 'assign');
}
}
@@ -0,0 +1,126 @@
<?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/>.
/**
* The mod_assign assessable submitted event.
*
* @package mod_assign
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_assign assessable submitted event class.
*
* @property-read array $other {
* Extra information about event.
*
* - bool submission_editable: is submission editable.
* }
*
* @package mod_assign
* @since Moodle 2.6
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class assessable_submitted extends base {
/**
* Create instance of event.
*
* @since Moodle 2.7
*
* @param \assign $assign
* @param \stdClass $submission
* @param bool $editable
* @return assessable_submitted
*/
public static function create_from_submission(\assign $assign, \stdClass $submission, $editable) {
global $USER;
$data = array(
'context' => $assign->get_context(),
'objectid' => $submission->id,
'other' => array(
'submission_editable' => $editable,
),
);
if (!empty($submission->userid) && ($submission->userid != $USER->id)) {
$data['relateduserid'] = $submission->userid;
}
/** @var assessable_submitted $event */
$event = self::create($data);
$event->set_assign($assign);
$event->add_record_snapshot('assign_submission', $submission);
return $event;
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' has submitted the submission with id '$this->objectid' " .
"for the assignment with course module id '$this->contextinstanceid'.";
}
/**
* Return localised event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventassessablesubmitted', 'mod_assign');
}
/**
* Init method.
*
* @return void
*/
protected function init() {
$this->data['objecttable'] = 'assign_submission';
$this->data['crud'] = 'u';
$this->data['edulevel'] = self::LEVEL_PARTICIPATING;
}
/**
* Custom validation.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
parent::validate_data();
if (!isset($this->other['submission_editable'])) {
throw new \coding_exception('The \'submission_editable\' value must be set in other.');
}
}
public static function get_objectid_mapping() {
return array('db' => 'assign_submission', 'restore' => 'submission');
}
public static function get_other_mapping() {
// Nothing to map.
return false;
}
}
+114
View File
@@ -0,0 +1,114 @@
<?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/>.
/**
* The mod_assign abstract base event.
*
* @package mod_assign
* @copyright 2014 Mark Nelson
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_assign abstract base event class.
*
* Most mod_assign events can extend this class.
*
* @package mod_assign
* @since Moodle 2.7
* @copyright 2014 Mark Nelson
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
abstract class base extends \core\event\base {
/** @var \assign */
protected $assign;
/**
* Legacy log data.
*
* @var array
*/
protected $legacylogdata;
/**
* Set assign instance for this event.
* @param \assign $assign
* @throws \coding_exception
*/
public function set_assign(\assign $assign) {
if ($this->is_triggered()) {
throw new \coding_exception('set_assign() must be done before triggerring of event');
}
if ($assign->get_context()->id != $this->get_context()->id) {
throw new \coding_exception('Invalid assign isntance supplied!');
}
if ($assign->is_blind_marking()) {
$this->data['anonymous'] = 1;
}
$this->assign = $assign;
}
/**
* Get assign instance.
*
* NOTE: to be used from observers only.
*
* @throws \coding_exception
* @return \assign
*/
public function get_assign() {
if ($this->is_restored()) {
throw new \coding_exception('get_assign() is intended for event observers only');
}
if (!isset($this->assign)) {
debugging('assign property should be initialised in each event', DEBUG_DEVELOPER);
global $CFG;
require_once($CFG->dirroot . '/mod/assign/locallib.php');
$cm = get_coursemodule_from_id('assign', $this->contextinstanceid, 0, false, MUST_EXIST);
$course = get_course($cm->course);
$this->assign = new \assign($this->get_context(), $cm, $course);
}
return $this->assign;
}
/**
* Returns relevant URL.
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/assign/view.php', array('id' => $this->contextinstanceid));
}
/**
* Custom validation.
*
* @throws \coding_exception
*/
protected function validate_data() {
parent::validate_data();
if ($this->contextlevel != CONTEXT_MODULE) {
throw new \coding_exception('Context level must be CONTEXT_MODULE.');
}
}
}
@@ -0,0 +1,122 @@
<?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/>.
/**
* The mod_assign batch set marker allocation viewed event.
*
* @package mod_assign
* @copyright 2014 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_assign batch set marker allocation viewed event class.
*
* @property-read array $other {
* Extra information about event.
*
* - int assignid: the id of the assignment.
* }
*
* @package mod_assign
* @since Moodle 2.7
* @copyright 2014 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class batch_set_marker_allocation_viewed extends base {
/**
* Flag for prevention of direct create() call.
* @var bool
*/
protected static $preventcreatecall = true;
/**
* Create instance of event.
*
* @param \assign $assign
* @return batch_set_marker_allocation_viewed
*/
public static function create_from_assign(\assign $assign) {
$data = array(
'context' => $assign->get_context(),
'other' => array(
'assignid' => $assign->get_instance()->id,
),
);
self::$preventcreatecall = false;
/** @var batch_set_marker_allocation_viewed $event */
$event = self::create($data);
self::$preventcreatecall = true;
$event->set_assign($assign);
return $event;
}
/**
* Init method.
*/
protected function init() {
$this->data['crud'] = 'r';
$this->data['edulevel'] = self::LEVEL_TEACHING;
}
/**
* Returns localised general event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventbatchsetmarkerallocationviewed', 'mod_assign');
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' viewed the batch set marker allocation for the assignment with course " .
"module id '$this->contextinstanceid'.";
}
/**
* Custom validation.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
if (self::$preventcreatecall) {
throw new \coding_exception('cannot call batch_set_marker_allocation_viewed::create() directly, use batch_set_marker_allocation_viewed::create_from_assign() instead.');
}
parent::validate_data();
if (!isset($this->other['assignid'])) {
throw new \coding_exception('The \'assignid\' value must be set in other.');
}
}
public static function get_other_mapping() {
$othermapped = array();
$othermapped['assignid'] = array('db' => 'assign', 'restore' => 'assign');
return $othermapped;
}
}
@@ -0,0 +1,122 @@
<?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/>.
/**
* The mod_assign assignment batch set workflow stated viewed event.
*
* @package mod_assign
* @copyright 2014 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_assign assignment batch set workflow stated viewed event.
*
* @property-read array $other {
* Extra information about event.
*
* - int assignid: the id of the assignment.
* }
*
* @package mod_assign
* @since Moodle 2.7
* @copyright 2014 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class batch_set_workflow_state_viewed extends base {
/**
* Flag for prevention of direct create() call.
* @var bool
*/
protected static $preventcreatecall = true;
/**
* Create instance of event.
*
* @param \assign $assign
* @return batch_set_workflow_state_viewed
*/
public static function create_from_assign(\assign $assign) {
$data = array(
'context' => $assign->get_context(),
'other' => array(
'assignid' => $assign->get_instance()->id,
),
);
self::$preventcreatecall = false;
/** @var batch_set_workflow_state_viewed $event */
$event = self::create($data);
self::$preventcreatecall = true;
$event->set_assign($assign);
return $event;
}
/**
* Init method.
*/
protected function init() {
$this->data['crud'] = 'r';
$this->data['edulevel'] = self::LEVEL_TEACHING;
}
/**
* Returns localised general event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventbatchsetworkflowstateviewed', 'mod_assign');
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' viewed the batch set workflow for the assignment with course " .
"module id '$this->contextinstanceid'.";
}
/**
* Custom validation.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
if (self::$preventcreatecall) {
throw new \coding_exception('cannot call batch_set_workflow_state_viewed::create() directly, use batch_set_workflow_state_viewed::create_from_assign() instead.');
}
parent::validate_data();
if (!isset($this->other['assignid'])) {
throw new \coding_exception('The \'assignid\' value must be set in other.');
}
}
public static function get_other_mapping() {
$othermapped = array();
$othermapped['assignid'] = array('db' => 'assign', 'restore' => 'assign');
return $othermapped;
}
}
@@ -0,0 +1,52 @@
<?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/>.
/**
* The mod_assign instance list viewed event.
*
* @package mod_assign
* @copyright 2014 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_assign instance list viewed event class.
*
* @package mod_assign
* @since Moodle 2.7
* @copyright 2014 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class course_module_instance_list_viewed extends \core\event\course_module_instance_list_viewed {
/**
* Create the event from course record.
*
* @param \stdClass $course
* @return course_module_instance_list_viewed
*/
public static function create_from_course(\stdClass $course) {
$params = array(
'context' => \context_course::instance($course->id)
);
$event = \mod_assign\event\course_module_instance_list_viewed::create($params);
$event->add_record_snapshot('course', $course);
return $event;
}
}
@@ -0,0 +1,56 @@
<?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/>.
/**
* The mod_assign course module viewed event.
*
* @package mod_assign
* @copyright 2018 Victor Deniz <victor@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign\event;
defined('MOODLE_INTERNAL') || die();
global $CFG;
/**
* The mod_assign course module viewed event class.
*
* @package mod_assign
* @since Moodle 3.6
* @copyright 2018 Victor Deniz <victor@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class course_module_viewed extends \core\event\course_module_viewed {
/**
* Init method.
*/
protected function init() {
$this->data['crud'] = 'r';
$this->data['edulevel'] = self::LEVEL_PARTICIPATING;
$this->data['objecttable'] = 'assign';
}
/**
* Get objectid mapping
*/
public static function get_objectid_mapping() {
return array('db' => 'assign', 'restore' => 'assign');
}
}
@@ -0,0 +1,118 @@
<?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/>.
/**
* The mod_assign extension granted event.
*
* @package mod_assign
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_assign extension granted event class.
*
* @package mod_assign
* @since Moodle 2.6
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class extension_granted extends base {
/**
* Flag for prevention of direct create() call.
* @var bool
*/
protected static $preventcreatecall = true;
/**
* Create instance of event.
*
* @since Moodle 2.7
*
* @param \assign $assign
* @param int $userid
* @return extension_granted
*/
public static function create_from_assign(\assign $assign, $userid) {
$data = array(
'context' => $assign->get_context(),
'objectid' => $assign->get_instance()->id,
'relateduserid' => $userid,
);
self::$preventcreatecall = false;
/** @var extension_granted $event */
$event = self::create($data);
self::$preventcreatecall = true;
$event->set_assign($assign);
return $event;
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' has granted an extension for the user with id '$this->relateduserid' " .
"for the assignment with course module id '$this->contextinstanceid'.";
}
/**
* Return localised event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventextensiongranted', 'mod_assign');
}
/**
* Init method.
*
* @return void
*/
protected function init() {
$this->data['crud'] = 'u';
$this->data['edulevel'] = self::LEVEL_TEACHING;
$this->data['objecttable'] = 'assign';
}
/**
* Custom validation.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
if (self::$preventcreatecall) {
throw new \coding_exception('cannot call extension_granted::create() directly, use extension_granted::create_from_assign() instead.');
}
parent::validate_data();
if (!isset($this->relateduserid)) {
throw new \coding_exception('The \'relateduserid\' must be set.');
}
}
public static function get_objectid_mapping() {
return array('db' => 'assign', 'restore' => 'assign');
}
}
@@ -0,0 +1,122 @@
<?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/>.
/**
* The mod_assign feedback viewed event.
*
* @package mod_assign
* @copyright 2014 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_assign feedback viewed event class.
*
* @property-read array $other {
* Extra information about event.
*
* - int assignid: the id of the assignment.
* }
*
* @package mod_assign
* @since Moodle 2.7
* @copyright 2014 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class feedback_viewed extends base {
/**
* Create instance of event.
*
* @param \assign $assign
* @param \stdClass $grade
* @return feedback_viewed
*/
public static function create_from_grade(\assign $assign, \stdClass $grade) {
$data = array(
'objectid' => $grade->id,
'relateduserid' => $grade->userid,
'context' => $assign->get_context(),
'other' => array(
'assignid' => $assign->get_instance()->id,
),
);
/** @var feedback_viewed $event */
$event = self::create($data);
$event->set_assign($assign);
$event->add_record_snapshot('assign_grades', $grade);
return $event;
}
/**
* Init method.
*/
protected function init() {
$this->data['objecttable'] = 'assign_grades';
$this->data['crud'] = 'r';
$this->data['edulevel'] = self::LEVEL_PARTICIPATING;
}
/**
* Returns localised general event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventfeedbackviewed', 'mod_assign');
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' viewed the feedback for the user with id '$this->relateduserid' " .
"for the assignment with course module id '$this->contextinstanceid'.";
}
/**
* Custom validation.
*
* @throws \coding_exception
*/
protected function validate_data() {
parent::validate_data();
if (!isset($this->relateduserid)) {
throw new \coding_exception('The \'relateduserid\' must be set.');
}
if (!isset($this->other['assignid'])) {
throw new \coding_exception('The \'assignid\' value must be set in other.');
}
}
public static function get_objectid_mapping() {
return array('db' => 'assign_grades', 'restore' => 'grade');
}
public static function get_other_mapping() {
$othermapped = array();
$othermapped['assignid'] = array('db' => 'assign', 'restore' => 'assign');
return $othermapped;
}
}
@@ -0,0 +1,128 @@
<?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/>.
/**
* The mod_assign grading form viewed event.
*
* @package mod_assign
* @copyright 2014 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_assign grading form viewed event class.
*
* @property-read array $other {
* Extra information about event.
*
* - int assignid: the id of the assignment.
* }
*
* @package mod_assign
* @since Moodle 2.7
* @copyright 2014 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class grading_form_viewed extends base {
/**
* Flag for prevention of direct create() call.
* @var bool
*/
protected static $preventcreatecall = true;
/**
* Create instance of event.
*
* @param \assign $assign
* @param \stdClass $user
* @return grading_form_viewed
*/
public static function create_from_user(\assign $assign, \stdClass $user) {
$data = array(
'relateduserid' => $user->id,
'context' => $assign->get_context(),
'other' => array(
'assignid' => $assign->get_instance()->id,
),
);
self::$preventcreatecall = false;
/** @var grading_form_viewed $event */
$event = self::create($data);
self::$preventcreatecall = true;
$event->set_assign($assign);
$event->add_record_snapshot('user', $user);
return $event;
}
/**
* Init method.
*/
protected function init() {
$this->data['crud'] = 'r';
$this->data['edulevel'] = self::LEVEL_TEACHING;
}
/**
* Returns localised general event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventgradingformviewed', 'mod_assign');
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' viewed the grading form for the user with id '$this->relateduserid' " .
"for the assignment with course module id '$this->contextinstanceid'.";
}
/**
* Custom validation.
*
* @throws \coding_exception
*/
protected function validate_data() {
if (self::$preventcreatecall) {
throw new \coding_exception('cannot call grading_form_viewed::create() directly, use grading_form_viewed::create_from_user() instead.');
}
parent::validate_data();
if (!isset($this->relateduserid)) {
throw new \coding_exception('The \'relateduserid\' must be set.');
}
if (!isset($this->other['assignid'])) {
throw new \coding_exception('The \'assignid\' value must be set in other.');
}
}
public static function get_other_mapping() {
$othermapped = array();
$othermapped['assignid'] = array('db' => 'assign', 'restore' => 'assign');
return $othermapped;
}
}
@@ -0,0 +1,122 @@
<?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/>.
/**
* The mod_assign grading table viewed event.
*
* @package mod_assign
* @copyright 2014 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_assign grading table viewed event class.
*
* @property-read array $other {
* Extra information about event.
*
* - int assignid: the id of the assignment.
* }
*
* @package mod_assign
* @since Moodle 2.7
* @copyright 2014 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class grading_table_viewed extends base {
/**
* Flag for prevention of direct create() call.
* @var bool
*/
protected static $preventcreatecall = true;
/**
* Create instance of event.
*
* @param \assign $assign
* @return grading_table_viewed
*/
public static function create_from_assign(\assign $assign) {
$data = array(
'context' => $assign->get_context(),
'other' => array(
'assignid' => $assign->get_instance()->id,
),
);
self::$preventcreatecall = false;
/** @var grading_table_viewed $event */
$event = self::create($data);
self::$preventcreatecall = true;
$event->set_assign($assign);
return $event;
}
/**
* Init method.
*/
protected function init() {
$this->data['crud'] = 'r';
$this->data['edulevel'] = self::LEVEL_TEACHING;
}
/**
* Returns localised general event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventgradingtableviewed', 'mod_assign');
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' viewed the grading table for the assignment with course module " .
"id '$this->contextinstanceid'.";
}
/**
* Custom validation.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
if (self::$preventcreatecall) {
throw new \coding_exception('cannot call grading_table_viewed::create() directly, use grading_table_viewed::create_from_assign() instead.');
}
parent::validate_data();
if (!isset($this->other['assignid'])) {
throw new \coding_exception('The \'assignid\' value must be set in other.');
}
}
public static function get_other_mapping() {
$othermapped = array();
$othermapped['assignid'] = array('db' => 'assign', 'restore' => 'assign');
return $othermapped;
}
}
@@ -0,0 +1,118 @@
<?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/>.
/**
* The mod_assign group override created event.
*
* @package mod_assign
* @copyright 2016 Ilya Tregubov
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_assign group override created event class.
*
* @property-read array $other {
* Extra information about event.
*
* - int assignid: the id of the assign.
* - int groupid: the id of the group.
* }
*
* @package mod_assign
* @since Moodle 3.2
* @copyright 2016 Ilya Tregubov
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class group_override_created extends \core\event\base {
/**
* Init method.
*/
protected function init() {
$this->data['objecttable'] = 'assign_overrides';
$this->data['crud'] = 'c';
$this->data['edulevel'] = self::LEVEL_TEACHING;
}
/**
* Returns localised general event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventoverridecreated', 'mod_assign');
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' created the override with id '$this->objectid' for the assign with " .
"course module id '$this->contextinstanceid' for the group with id '{$this->other['groupid']}'.";
}
/**
* Returns relevant URL.
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/assign/overrideedit.php', array('id' => $this->objectid));
}
/**
* Custom validation.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
parent::validate_data();
if (!isset($this->other['assignid'])) {
throw new \coding_exception('The \'assignid\' value must be set in other.');
}
if (!isset($this->other['groupid'])) {
throw new \coding_exception('The \'groupid\' value must be set in other.');
}
}
/**
* Get objectid mapping
*/
public static function get_objectid_mapping() {
return array('db' => 'assign_overrides', 'restore' => 'assign_override');
}
/**
* Get other mapping
*/
public static function get_other_mapping() {
$othermapped = array();
$othermapped['assignid'] = array('db' => 'assign', 'restore' => 'assign');
$othermapped['groupid'] = array('db' => 'groups', 'restore' => 'group');
return $othermapped;
}
}
@@ -0,0 +1,117 @@
<?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/>.
/**
* The mod_assign group override deleted event.
*
* @package mod_assign
* @copyright 2016 Ilya Tregubov
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_assign group override deleted event class.
*
* @property-read array $other {
* Extra information about event.
*
* - int assignid: the id of the assign.
* - int groupid: the id of the group.
* }
*
* @package mod_assign
* @since Moodle 3.2
* @copyright 2016 Ilya Tregubov
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class group_override_deleted extends \core\event\base {
/**
* Init method.
*/
protected function init() {
$this->data['objecttable'] = 'assign_overrides';
$this->data['crud'] = 'd';
$this->data['edulevel'] = self::LEVEL_TEACHING;
}
/**
* Returns localised general event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventoverridedeleted', 'mod_assign');
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' deleted the override with id '$this->objectid' for the assign with " .
"course module id '$this->contextinstanceid' for the group with id '{$this->other['groupid']}'.";
}
/**
* Returns relevant URL.
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/assign/overrides.php', array('cmid' => $this->contextinstanceid));
}
/**
* Custom validation.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
parent::validate_data();
if (!isset($this->other['assignid'])) {
throw new \coding_exception('The \'assignid\' value must be set in other.');
}
if (!isset($this->other['groupid'])) {
throw new \coding_exception('The \'groupid\' value must be set in other.');
}
}
/**
* Get objectid mapping
*/
public static function get_objectid_mapping() {
return array('db' => 'assign_overrides', 'restore' => 'assign_override');
}
/**
* Get other mapping
*/
public static function get_other_mapping() {
$othermapped = array();
$othermapped['assignid'] = array('db' => 'assign', 'restore' => 'assign');
$othermapped['groupid'] = array('db' => 'groups', 'restore' => 'group');
return $othermapped;
}
}
@@ -0,0 +1,117 @@
<?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/>.
/**
* The mod_assign group override updated event.
*
* @package mod_assign
* @copyright 2016 Ilya Tregubov
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_assign group override updated event class.
*
* @property-read array $other {
* Extra information about event.
*
* - int assignid: the id of the assign.
* - int groupid: the id of the group.
* }
*
* @package mod_assign
* @since Moodle 3.2
* @copyright 2016 Ilya Tregubov
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class group_override_updated extends \core\event\base {
/**
* Init method.
*/
protected function init() {
$this->data['objecttable'] = 'assign_overrides';
$this->data['crud'] = 'u';
$this->data['edulevel'] = self::LEVEL_TEACHING;
}
/**
* Returns localised general event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventoverrideupdated', 'mod_assign');
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' updated the override with id '$this->objectid' for the assign with " .
"course module id '$this->contextinstanceid' for the group with id '{$this->other['groupid']}'.";
}
/**
* Returns relevant URL.
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/assign/overrideedit.php', array('id' => $this->objectid));
}
/**
* Custom validation.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
parent::validate_data();
if (!isset($this->other['assignid'])) {
throw new \coding_exception('The \'assignid\' value must be set in other.');
}
if (!isset($this->other['groupid'])) {
throw new \coding_exception('The \'groupid\' value must be set in other.');
}
}
/**
* Get objectid mapping
*/
public static function get_objectid_mapping() {
return array('db' => 'assign_overrides', 'restore' => 'assign_override');
}
/**
* Get other mapping
*/
public static function get_other_mapping() {
$othermapped = array();
$othermapped['assignid'] = array('db' => 'assign', 'restore' => 'assign');
$othermapped['groupid'] = array('db' => 'groups', 'restore' => 'group');
return $othermapped;
}
}
@@ -0,0 +1,112 @@
<?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/>.
/**
* The mod_assign identities revealed event.
*
* @package mod_assign
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_assign identities revealed event class.
*
* @package mod_assign
* @since Moodle 2.6
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class identities_revealed extends base {
/**
* Flag for prevention of direct create() call.
* @var bool
*/
protected static $preventcreatecall = true;
/**
* Create instance of event.
*
* @since Moodle 2.7
*
* @param \assign $assign
* @return identities_revealed
*/
public static function create_from_assign(\assign $assign) {
$data = array(
'context' => $assign->get_context(),
'objectid' => $assign->get_instance()->id
);
self::$preventcreatecall = false;
/** @var identities_revealed $event */
$event = self::create($data);
self::$preventcreatecall = true;
$event->set_assign($assign);
return $event;
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' has revealed identities in the assignment with course module " .
"id '$this->contextinstanceid'.";
}
/**
* Return localised event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventidentitiesrevealed', 'mod_assign');
}
/**
* Init method.
*
* @return void
*/
protected function init() {
$this->data['crud'] = 'u';
$this->data['edulevel'] = self::LEVEL_TEACHING;
$this->data['objecttable'] = 'assign';
}
/**
* Custom validation.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
if (self::$preventcreatecall) {
throw new \coding_exception('cannot call identities_revealed::create() directly, use identities_revealed::create_from_assign() instead.');
}
parent::validate_data();
}
public static function get_objectid_mapping() {
return array('db' => 'assign', 'restore' => 'assign');
}
}
+140
View File
@@ -0,0 +1,140 @@
<?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/>.
/**
* The mod_assign marker updated event.
*
* @package mod_assign
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_assign marker updated event class.
*
* @property-read array $other {
* Extra information about event.
*
* - int markerid: user id of marker.
* }
*
* @package mod_assign
* @since Moodle 2.6
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class marker_updated extends base {
/**
* Flag for prevention of direct create() call.
* @var bool
*/
protected static $preventcreatecall = true;
/**
* Create instance of event.
*
* @since Moodle 2.7
*
* @param \assign $assign
* @param \stdClass $user
* @param \stdClass $marker
* @return marker_updated
*/
public static function create_from_marker(\assign $assign, \stdClass $user, \stdClass $marker) {
$data = array(
'context' => $assign->get_context(),
'objectid' => $assign->get_instance()->id,
'relateduserid' => $user->id,
'other' => array(
'markerid' => $marker->id,
),
);
self::$preventcreatecall = false;
/** @var marker_updated $event */
$event = self::create($data);
self::$preventcreatecall = true;
$event->set_assign($assign);
$event->add_record_snapshot('user', $user);
$event->add_record_snapshot('user', $marker);
return $event;
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' has set the marker for the user with id '$this->relateduserid' to " .
"'{$this->other['markerid']}' for the assignment with course module id '$this->contextinstanceid'.";
}
/**
* Return localised event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventmarkerupdated', 'mod_assign');
}
/**
* Init method.
*
* @return void
*/
protected function init() {
$this->data['crud'] = 'u';
$this->data['edulevel'] = self::LEVEL_TEACHING;
$this->data['objecttable'] = 'assign';
}
/**
* Custom validation.
*
* @throws \coding_exception
*/
protected function validate_data() {
if (self::$preventcreatecall) {
throw new \coding_exception('cannot call marker_updated::create() directly, use marker_updated::create_from_marker() instead.');
}
parent::validate_data();
if (!isset($this->relateduserid)) {
throw new \coding_exception('The \'relateduserid\' must be set.');
}
if (!isset($this->other['markerid'])) {
throw new \coding_exception('The \'markerid\' value must be set in other.');
}
}
public static function get_objectid_mapping() {
return array('db' => 'assign', 'restore' => 'assign');
}
public static function get_other_mapping() {
$othermapped = array();
$othermapped['markerid'] = array('db' => 'user', 'restore' => 'user');
return $othermapped;
}
}
@@ -0,0 +1,134 @@
<?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/>.
/**
* The mod_assign remove submission form viewed event.
*
* @package mod_assign
* @copyright 2019 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_assign remove submission form viewed event class.
*
* @package mod_assign
* @copyright 2019 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class remove_submission_form_viewed extends base {
/**
* Flag for prevention of direct create() call.
* @var bool
*/
protected static $preventcreatecall = true;
/**
* Create instance of event.
*
* @param \assign $assign
* @param \stdClass $user
* @return remove_submission_form_viewed
*/
public static function create_from_user(\assign $assign, \stdClass $user) {
$data = array(
'relateduserid' => $user->id,
'context' => $assign->get_context(),
'other' => array(
'assignid' => $assign->get_instance()->id,
),
);
self::$preventcreatecall = false;
/** @var remove_submission_form_viewed $event */
$event = self::create($data);
self::$preventcreatecall = true;
$event->set_assign($assign);
$event->add_record_snapshot('user', $user);
return $event;
}
/**
* Init method.
*/
protected function init() {
$this->data['crud'] = 'r';
$this->data['edulevel'] = self::LEVEL_OTHER;
}
/**
* Returns localised general event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventremovesubmissionformviewed', 'mod_assign');
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
if ($this->userid != $this->relateduserid) {
return "The user with id '$this->userid' viewed the " .
"remove submission form for the user with id '$this->relateduserid' " .
"for the assignment with course module id '$this->contextinstanceid'.";
}
return "The user with id '$this->userid' viewed their remove submission form for the assignment with course module id " .
"'$this->contextinstanceid'.";
}
/**
* Custom validation.
*
* @throws \coding_exception
*/
protected function validate_data() {
if (self::$preventcreatecall) {
throw new \coding_exception('cannot call remove_submission_form_viewed::create() directly, use ' .
'remove_submission_form_viewed::create_from_user() instead.');
}
parent::validate_data();
if (!isset($this->relateduserid)) {
throw new \coding_exception('The \'relateduserid\' must be set.');
}
if (!isset($this->other['assignid'])) {
throw new \coding_exception('The \'assignid\' value must be set in other.');
}
}
/**
* This is documented in the parent class.
*
* @return array an array of other values and their corresponding mapping
*/
public static function get_other_mapping() {
$othermapped = array();
$othermapped['assignid'] = array('db' => 'assign', 'restore' => 'assign');
return $othermapped;
}
}
@@ -0,0 +1,121 @@
<?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/>.
/**
* The mod_assign reveal identities confirmation page viewed event.
*
* @package mod_assign
* @copyright 2014 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_assign reveal identities confirmation page viewed event class.
*
* @property-read array $other {
* Extra information about event.
*
* - int assignid: the id of the assignment.
* }
*
* @package mod_assign
* @since Moodle 2.7
* @copyright 2014 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class reveal_identities_confirmation_page_viewed extends base {
/**
* Flag for prevention of direct create() call.
* @var bool
*/
protected static $preventcreatecall = true;
/**
* Create instance of event.
*
* @param \assign $assign
* @return reveal_identities_confirmation_page_viewed
*/
public static function create_from_assign(\assign $assign) {
$data = array(
'context' => $assign->get_context(),
'other' => array(
'assignid' => $assign->get_instance()->id,
),
);
self::$preventcreatecall = false;
/** @var reveal_identities_confirmation_page_viewed $event */
$event = self::create($data);
self::$preventcreatecall = true;
$event->set_assign($assign);
return $event;
}
/**
* Init method.
*/
protected function init() {
$this->data['crud'] = 'r';
$this->data['edulevel'] = self::LEVEL_TEACHING;
}
/**
* Returns localised general event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventrevealidentitiesconfirmationpageviewed', 'mod_assign');
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' viewed the confirmation page for revealing identities for the " .
"assignment with course module id '$this->contextinstanceid'.";
}
/**
* Custom validation.
*
* @throws \coding_exception
*/
protected function validate_data() {
if (self::$preventcreatecall) {
throw new \coding_exception('cannot call reveal_identities_confirmation_page_viewed::create() directly, use reveal_identities_confirmation_page_viewed::create_from_grade() instead.');
}
parent::validate_data();
if (!isset($this->other['assignid'])) {
throw new \coding_exception('The \'assignid\' value must be set in other.');
}
}
public static function get_other_mapping() {
$othermapped = array();
$othermapped['assignid'] = array('db' => 'assign', 'restore' => 'assign');
return $othermapped;
}
}
@@ -0,0 +1,114 @@
<?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/>.
/**
* The mod_assign statement accepted event.
*
* @package mod_assign
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_assign statement accepted event class.
*
* @package mod_assign
* @since Moodle 2.6
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class statement_accepted extends base {
/**
* Flag for prevention of direct create() call.
* @var bool
*/
protected static $preventcreatecall = true;
/**
* Create instance of event.
*
* @since Moodle 2.7
*
* @param \assign $assign
* @param \stdClass $submission
* @return statement_accepted
*/
public static function create_from_submission(\assign $assign, \stdClass $submission) {
$data = array(
'context' => $assign->get_context(),
'objectid' => $submission->id
);
self::$preventcreatecall = false;
/** @var statement_accepted $event */
$event = self::create($data);
self::$preventcreatecall = true;
$event->set_assign($assign);
$event->add_record_snapshot('assign_submission', $submission);
return $event;
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' has accepted the statement of the submission with id '$this->objectid' " .
"for the assignment with course module id '$this->contextinstanceid'.";
}
/**
* Return localised event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventstatementaccepted', 'mod_assign');
}
/**
* Init method.
*
* @return void
*/
protected function init() {
$this->data['crud'] = 'r';
$this->data['edulevel'] = self::LEVEL_OTHER;
$this->data['objecttable'] = 'assign_submission';
}
/**
* Custom validation.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
if (self::$preventcreatecall) {
throw new \coding_exception('cannot call statement_accepted::create() directly, use statement_accepted::create_from_submission() instead.');
}
parent::validate_data();
}
public static function get_objectid_mapping() {
return array('db' => 'assign_submission', 'restore' => 'submission');
}
}
@@ -0,0 +1,122 @@
<?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/>.
/**
* The mod_assign submission form viewed event.
*
* @package mod_assign
* @copyright 2014 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_assign submission form viewed event class.
*
* @property-read array $other {
* Extra information about event.
*
* - int assignid: the id of the assignment.
* }
*
* @package mod_assign
* @since Moodle 2.7
* @copyright 2014 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class submission_confirmation_form_viewed extends base {
/**
* Flag for prevention of direct create() call.
* @var bool
*/
protected static $preventcreatecall = true;
/**
* Create instance of event.
*
* @param \assign $assign
* @return submission_confirmation_form_viewed
*/
public static function create_from_assign(\assign $assign) {
$data = array(
'context' => $assign->get_context(),
'other' => array(
'assignid' => $assign->get_instance()->id,
),
);
self::$preventcreatecall = false;
/** @var submission_confirmation_form_viewed $event */
$event = self::create($data);
self::$preventcreatecall = true;
$event->set_assign($assign);
return $event;
}
/**
* Init method.
*/
protected function init() {
$this->data['crud'] = 'r';
$this->data['edulevel'] = self::LEVEL_OTHER;
}
/**
* Returns localised general event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventsubmissionconfirmationformviewed', 'mod_assign');
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' viewed the submission confirmation form for the assignment with " .
"course module id '$this->contextinstanceid'.";
}
/**
* Custom validation.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
if (self::$preventcreatecall) {
throw new \coding_exception('cannot call submission_confirmation_form_viewed::create() directly, use submission_confirmation_form_viewed::create_from_assign() instead.');
}
parent::validate_data();
if (!isset($this->other['assignid'])) {
throw new \coding_exception('The \'assignid\' value must be set in other.');
}
}
public static function get_other_mapping() {
$othermapped = array();
$othermapped['assignid'] = array('db' => 'assign', 'restore' => 'assign');
return $othermapped;
}
}
@@ -0,0 +1,92 @@
<?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/>.
/**
* The mod_assign submission_created abstract event.
*
* @package mod_assign
* @copyright 2014 Adrian Greeve <adrian@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_assign submission_created abstract event class.
*
* @property-read array $other {
* Extra information about the event.
*
* - int submissionid: ID number of this submission.
* - int submissionattempt: Number of attempts made on this submission.
* - string submissionstatus: Status of the submission.
* - int groupid: (optional) The group ID if this is a teamsubmission.
* - string groupname: (optional) The name of the group if this is a teamsubmission.
* }
*
* @package mod_assign
* @since Moodle 2.7
* @copyright 2014 Adrian Greeve <adrian@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
abstract class submission_created extends base {
/**
* Init method.
*/
protected function init() {
$this->data['crud'] = 'c';
$this->data['edulevel'] = self::LEVEL_PARTICIPATING;
}
/**
* Returns localised general event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventsubmissioncreated', 'mod_assign');
}
/**
* Custom validation.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
parent::validate_data();
if (!isset($this->other['submissionid'])) {
throw new \coding_exception('The \'submissionid\' value must be set in other.');
}
if (!isset($this->other['submissionattempt'])) {
throw new \coding_exception('The \'submissionattempt\' value must be set in other.');
}
if (!isset($this->other['submissionstatus'])) {
throw new \coding_exception('The \'submissionstatus\' value must be set in other.');
}
}
public static function get_other_mapping() {
$othermapped = array();
$othermapped['submissionid'] = array('db' => 'assign_submission', 'restore' => 'submission');
$othermapped['groupid'] = array('db' => 'groups', 'restore' => 'group');
return $othermapped;
}
}
@@ -0,0 +1,113 @@
<?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/>.
/**
* The mod_assign submission duplicated event.
*
* @package mod_assign
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_assign submission duplicated event class.
*
* @package mod_assign
* @since Moodle 2.6
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class submission_duplicated extends base {
/**
* Flag for prevention of direct create() call.
* @var bool
*/
protected static $preventcreatecall = true;
/**
* Create instance of event.
*
* @since Moodle 2.7
*
* @param \assign $assign
* @param \stdClass $submission
* @return submission_duplicated
*/
public static function create_from_submission(\assign $assign, \stdClass $submission) {
$data = array(
'objectid' => $submission->id,
'context' => $assign->get_context(),
);
self::$preventcreatecall = false;
/** @var submission_duplicated $event */
$event = self::create($data);
self::$preventcreatecall = true;
$event->set_assign($assign);
$event->add_record_snapshot('assign_submission', $submission);
return $event;
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' duplicated their submission with id '$this->objectid' for the " .
"assignment with course module id '$this->contextinstanceid'.";
}
/**
* Return localised event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventsubmissionduplicated', 'mod_assign');
}
/**
* Init method.
*
* @return void
*/
protected function init() {
$this->data['crud'] = 'c';
$this->data['edulevel'] = self::LEVEL_PARTICIPATING;
$this->data['objecttable'] = 'assign_submission';
}
/**
* Custom validation.
*
* @throws \coding_exception
*/
protected function validate_data() {
if (self::$preventcreatecall) {
throw new \coding_exception('cannot call submission_duplicated::create() directly, use submission_duplicated::create_from_submission() instead.');
}
parent::validate_data();
}
public static function get_objectid_mapping() {
return array('db' => 'assign_submission', 'restore' => 'submission');
}
}
@@ -0,0 +1,133 @@
<?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/>.
/**
* The mod_assign submission form viewed event.
*
* @package mod_assign
* @copyright 2014 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_assign submission form viewed event class.
*
* @property-read array $other {
* Extra information about event.
*
* - int assignid: the id of the assignment.
* }
*
* @package mod_assign
* @since Moodle 2.7
* @copyright 2014 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class submission_form_viewed extends base {
/**
* Flag for prevention of direct create() call.
* @var bool
*/
protected static $preventcreatecall = true;
/**
* Create instance of event.
*
* @param \assign $assign
* @param \stdClass $user
* @return submission_form_viewed
*/
public static function create_from_user(\assign $assign, \stdClass $user) {
$data = array(
'relateduserid' => $user->id,
'context' => $assign->get_context(),
'other' => array(
'assignid' => $assign->get_instance()->id,
),
);
self::$preventcreatecall = false;
/** @var submission_form_viewed $event */
$event = self::create($data);
self::$preventcreatecall = true;
$event->set_assign($assign);
$event->add_record_snapshot('user', $user);
return $event;
}
/**
* Init method.
*/
protected function init() {
$this->data['crud'] = 'r';
$this->data['edulevel'] = self::LEVEL_OTHER;
}
/**
* Returns localised general event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventsubmissionformviewed', 'mod_assign');
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
if ($this->userid != $this->relateduserid) {
return "The user with id '$this->userid' viewed the submission form for the user with id '$this->relateduserid' " .
"for the assignment with course module id '$this->contextinstanceid'.";
}
return "The user with id '$this->userid' viewed their submission for the assignment with course module id " .
"'$this->contextinstanceid'.";
}
/**
* Custom validation.
*
* @throws \coding_exception
*/
protected function validate_data() {
if (self::$preventcreatecall) {
throw new \coding_exception('cannot call submission_form_viewed::create() directly, use submission_form_viewed::create_from_user() instead.');
}
parent::validate_data();
if (!isset($this->relateduserid)) {
throw new \coding_exception('The \'relateduserid\' must be set.');
}
if (!isset($this->other['assignid'])) {
throw new \coding_exception('The \'assignid\' value must be set in other.');
}
}
public static function get_other_mapping() {
$othermapped = array();
$othermapped['assignid'] = array('db' => 'assign', 'restore' => 'assign');
return $othermapped;
}
}
@@ -0,0 +1,119 @@
<?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/>.
/**
* The mod_assign submission graded event.
*
* @package mod_assign
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_assign submission graded event class.
*
* @package mod_assign
* @since Moodle 2.6
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class submission_graded extends base {
/**
* Flag for prevention of direct create() call.
* @var bool
*/
protected static $preventcreatecall = true;
/**
* Create instance of event.
*
* @since Moodle 2.7
*
* @param \assign $assign
* @param \stdClass $grade
* @return submission_graded
*/
public static function create_from_grade(\assign $assign, \stdClass $grade) {
$data = array(
'context' => $assign->get_context(),
'objectid' => $grade->id,
'relateduserid' => $grade->userid
);
self::$preventcreatecall = false;
/** @var submission_graded $event */
$event = self::create($data);
self::$preventcreatecall = true;
$event->set_assign($assign);
$event->add_record_snapshot('assign_grades', $grade);
return $event;
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' has graded the submission '$this->objectid' for the user with " .
"id '$this->relateduserid' for the assignment with course module id '$this->contextinstanceid'.";
}
/**
* Return localised event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventsubmissiongraded', 'mod_assign');
}
/**
* Init method.
*
* @return void
*/
protected function init() {
$this->data['crud'] = 'u';
$this->data['edulevel'] = self::LEVEL_TEACHING;
$this->data['objecttable'] = 'assign_grades';
}
/**
* Custom validation.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
if (self::$preventcreatecall) {
throw new \coding_exception('cannot call submission_graded::create() directly, use submission_graded::create_from_grade() instead.');
}
parent::validate_data();
if (!isset($this->relateduserid)) {
throw new \coding_exception('The \'relateduserid\' must be set.');
}
}
public static function get_objectid_mapping() {
return array('db' => 'assign_grades', 'restore' => 'grade');
}
}
@@ -0,0 +1,118 @@
<?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/>.
/**
* The mod_assign submission locked event.
*
* @package mod_assign
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_assign submission locked event class.
*
* @package mod_assign
* @since Moodle 2.6
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class submission_locked extends base {
/**
* Flag for prevention of direct create() call.
* @var bool
*/
protected static $preventcreatecall = true;
/**
* Create instance of event.
*
* @since Moodle 2.7
*
* @param \assign $assign
* @param \stdClass $user
* @return submission_locked
*/
public static function create_from_user(\assign $assign, \stdClass $user) {
$data = array(
'context' => $assign->get_context(),
'objectid' => $assign->get_instance()->id,
'relateduserid' => $user->id,
);
self::$preventcreatecall = false;
/** @var submission_locked $event */
$event = self::create($data);
self::$preventcreatecall = true;
$event->set_assign($assign);
$event->add_record_snapshot('user', $user);
return $event;
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' locked the submission for the user with id '$this->relateduserid' for " .
"the assignment with course module id '$this->contextinstanceid'.";
}
/**
* Return localised event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventsubmissionlocked', 'mod_assign');
}
/**
* Init method.
*
* @return void
*/
protected function init() {
$this->data['crud'] = 'u';
$this->data['edulevel'] = self::LEVEL_TEACHING;
$this->data['objecttable'] = 'assign';
}
/**
* Custom validation.
*
* @throws \coding_exception
*/
protected function validate_data() {
if (self::$preventcreatecall) {
throw new \coding_exception('cannot call submission_locked::create() directly, use submission_locked::create_from_user() instead.');
}
parent::validate_data();
if (!isset($this->relateduserid)) {
throw new \coding_exception('The \'relateduserid\' must be set.');
}
}
public static function get_objectid_mapping() {
return array('db' => 'assign', 'restore' => 'assign');
}
}
@@ -0,0 +1,154 @@
<?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/>.
namespace mod_assign\event;
use assign;
use coding_exception;
use stdClass;
/**
* The mod_assign submission removed event class.
*
* @property-read array $other {
* Extra information about the event.
*
* - int submissionid: ID number of this submission.
* - int submissionattempt: Number of attempts made on this submission.
* - string submissionstatus: Status of the submission.
* - int groupid: (optional) The group ID if this is a teamsubmission.
* - string groupname: (optional) The name of the group if this is a teamsubmission.
* }
*
* @package mod_assign
* @since Moodle 4.0
* @copyright 2022 TU Berlin
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class submission_removed extends base {
/**
* Create instance of event.
*
* @param assign $assign
* @param stdClass $submission
* @return submission_removed
* @throws coding_exception
*/
public static function create_from_submission(assign $assign, stdClass $submission): submission_removed {
$groupname = null;
$groupid = 0;
if (empty($submission->userid) && !empty($submission->groupid)) {
$groupname = groups_get_group_name($submission->groupid);
$groupid = $submission->groupid;
}
$data = [
'context' => $assign->get_context(),
'objectid' => $submission->id,
'relateduserid' => $assign->get_instance()->teamsubmission ? null : $submission->userid,
'anonymous' => $assign->is_blind_marking() ? 1 : 0,
'other' => [
'submissionid' => $submission->id,
'submissionattempt' => $submission->attemptnumber,
'submissionstatus' => $submission->status,
'groupid' => $groupid,
'groupname' => $groupname
]
];
/** @var submission_removed $event */
$event = self::create($data);
$event->set_assign($assign);
$event->add_record_snapshot('assign_submission', $submission);
return $event;
}
/**
* Init method.
*/
protected function init() {
$this->data['crud'] = 'd';
$this->data['edulevel'] = self::LEVEL_PARTICIPATING;
$this->data['objecttable'] = 'assign_submission';
}
/**
* Returns localised general event name.
*
* @return string
* @throws coding_exception
*/
public static function get_name(): string {
return get_string('eventsubmissionremoved', 'mod_assign');
}
/**
* Returns non-localised description of what happened.
*
* @return string
*/
public function get_description(): string {
$descriptionstring = "The user with id '$this->userid' removed the submission with id '$this->objectid' in " .
"the assignment with course module id '$this->contextinstanceid' submitted by ";
if (!empty($this->other['groupid'])) {
$groupname = $this->other['groupname'];
$groupid = $this->other['groupid'];
$descriptionstring .= "the group '$groupname' with id '$groupid'.";
} else {
$descriptionstring .= "the user with id '$this->relateduserid'.";
}
return $descriptionstring;
}
/**
* Custom validation.
*
* @return void
* @throws coding_exception
*/
protected function validate_data() {
parent::validate_data();
if (!isset($this->other['submissionid'])) {
throw new coding_exception('The \'submissionid\' value must be set in other.');
}
if (!isset($this->other['submissionattempt'])) {
throw new coding_exception('The \'submissionattempt\' value must be set in other.');
}
if (!isset($this->other['submissionstatus'])) {
throw new coding_exception('The \'submissionstatus\' value must be set in other.');
}
}
/**
* Get objectid mapping.
*
* @return array
*/
public static function get_objectid_mapping(): array {
return ['db' => 'assign_submission', 'restore' => 'submission'];
}
/**
* Get other mapping.
*
* @return array
*/
public static function get_other_mapping(): array {
$othermapped = [];
$othermapped['submissionid'] = ['db' => 'assign_submission', 'restore' => 'submission'];
$othermapped['groupid'] = ['db' => 'groups', 'restore' => 'group'];
return $othermapped;
}
}
@@ -0,0 +1,120 @@
<?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/>.
/**
* The mod_assign submission status updated event.
*
* @package mod_assign
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_assign submission status updated event class.
*
* @property-read array $other {
* Extra information about event.
*
* - string newstatus: status of submission.
* }
*
* @package mod_assign
* @since Moodle 2.6
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class submission_status_updated extends base {
/**
* Create instance of event.
*
* @since Moodle 2.7
*
* @param \assign $assign
* @param \stdClass $submission
* @return submission_status_updated
*/
public static function create_from_submission(\assign $assign, \stdClass $submission) {
$data = array(
'context' => $assign->get_context(),
'objectid' => $submission->id,
'relateduserid' => ($assign->get_instance()->teamsubmission) ? null : $submission->userid,
'other' => array(
'newstatus' => $submission->status
)
);
/** @var submission_status_updated $event */
$event = self::create($data);
$event->set_assign($assign);
$event->add_record_snapshot('assign_submission', $submission);
return $event;
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' has updated the status of the submission with id '$this->objectid' for " .
"the assignment with course module id '$this->contextinstanceid' to the status '{$this->other['newstatus']}'.";
}
/**
* Return localised event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventsubmissionstatusupdated', 'mod_assign');
}
/**
* Init method.
*
* @return void
*/
protected function init() {
$this->data['crud'] = 'u';
$this->data['edulevel'] = self::LEVEL_TEACHING;
$this->data['objecttable'] = 'assign_submission';
}
/**
* Custom validation.
*
* @throws \coding_exception
*/
protected function validate_data() {
parent::validate_data();
if (!isset($this->other['newstatus'])) {
throw new \coding_exception('The \'newstatus\' value must be set in other.');
}
}
public static function get_objectid_mapping() {
return array('db' => 'assign_submission', 'restore' => 'submission');
}
public static function get_other_mapping() {
// Nothing to map.
return false;
}
}
@@ -0,0 +1,124 @@
<?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/>.
/**
* The mod_assign submission status viewed event.
*
* @package mod_assign
* @copyright 2014 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_assign submission status viewed event class.
*
* @property-read array $other {
* Extra information about event.
*
* - int assignid: the id of the assignment.
* }
*
* @package mod_assign
* @since Moodle 2.7
* @copyright 2014 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class submission_status_viewed extends base {
/**
* Flag for prevention of direct create() call.
* @var bool
*/
protected static $preventcreatecall = true;
/**
* Create instance of event.
*
* @param \assign $assign
* @return submission_status_viewed
*/
public static function create_from_assign(\assign $assign) {
$data = array(
'context' => $assign->get_context(),
'other' => array(
'assignid' => $assign->get_instance()->id,
),
);
self::$preventcreatecall = false;
/** @var submission_status_viewed $event */
$event = self::create($data);
self::$preventcreatecall = true;
$event->set_assign($assign);
return $event;
}
/**
* Init method.
*
* @return void
*/
protected function init() {
$this->data['crud'] = 'r';
$this->data['edulevel'] = self::LEVEL_OTHER;
}
/**
* Return localised event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventsubmissionstatusviewed', 'mod_assign');
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' has viewed the submission status page for the assignment with " .
"course module id '$this->contextinstanceid'.";
}
/**
* Custom validation.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
if (self::$preventcreatecall) {
throw new \coding_exception('cannot call submission_status_viewed::create() directly, use submission_status_viewed::create_from_assign() instead.');
}
parent::validate_data();
if (!isset($this->other['assignid'])) {
throw new \coding_exception('The \'assignid\' value must be set in other.');
}
}
public static function get_other_mapping() {
$othermapped = array();
$othermapped['assignid'] = array('db' => 'assign', 'restore' => 'assign');
return $othermapped;
}
}
@@ -0,0 +1,118 @@
<?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/>.
/**
* The mod_assign submission unlocked event.
*
* @package mod_assign
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_assign submission unlocked event class.
*
* @package mod_assign
* @since Moodle 2.6
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class submission_unlocked extends base {
/**
* Flag for prevention of direct create() call.
* @var bool
*/
protected static $preventcreatecall = true;
/**
* Create instance of event.
*
* @since Moodle 2.7
*
* @param \assign $assign
* @param \stdClass $user
* @return submission_unlocked
*/
public static function create_from_user(\assign $assign, \stdClass $user) {
$data = array(
'context' => $assign->get_context(),
'objectid' => $assign->get_instance()->id,
'relateduserid' => $user->id,
);
self::$preventcreatecall = false;
/** @var submission_unlocked $event */
$event = self::create($data);
self::$preventcreatecall = true;
$event->set_assign($assign);
$event->add_record_snapshot('user', $user);
return $event;
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' unlocked the submission for the user with id '$this->relateduserid' " .
"for the assignment with course module id '$this->contextinstanceid'.";
}
/**
* Return localised event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventsubmissionunlocked', 'mod_assign');
}
/**
* Init method.
*
* @return void
*/
protected function init() {
$this->data['crud'] = 'u';
$this->data['edulevel'] = self::LEVEL_TEACHING;
$this->data['objecttable'] = 'assign';
}
/**
* Custom validation.
*
* @throws \coding_exception
*/
protected function validate_data() {
if (self::$preventcreatecall) {
throw new \coding_exception('cannot call submission_unlocked::create() directly, use submission_unlocked::create_from_user() instead.');
}
parent::validate_data();
if (!isset($this->relateduserid)) {
throw new \coding_exception('The \'relateduserid\' must be set.');
}
}
public static function get_objectid_mapping() {
return array('db' => 'assign', 'restore' => 'assign');
}
}
@@ -0,0 +1,92 @@
<?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/>.
/**
* The mod_assign submission updated event.
*
* @package mod_assign
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_assign submission updated event class.
*
* @property-read array $other {
* Extra information about the event.
*
* - int submissionid: ID number of this submission.
* - int submissionattempt: Number of attempts made on this submission.
* - string submissionstatus: Status of the submission.
* - int groupid: (optional) The group ID if this is a teamsubmission.
* - string groupname: (optional) The name of the group if this is a teamsubmission.
* }
*
* @package mod_assign
* @since Moodle 2.6
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
abstract class submission_updated extends base {
/**
* Init method.
*/
protected function init() {
$this->data['crud'] = 'u';
$this->data['edulevel'] = self::LEVEL_PARTICIPATING;
}
/**
* Returns localised general event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventsubmissionupdated', 'mod_assign');
}
/**
* Custom validation.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
parent::validate_data();
if (!isset($this->other['submissionid'])) {
throw new \coding_exception('The \'submissionid\' value must be set in other.');
}
if (!isset($this->other['submissionattempt'])) {
throw new \coding_exception('The \'submissionattempt\' value must be set in other.');
}
if (!isset($this->other['submissionstatus'])) {
throw new \coding_exception('The \'submissionstatus\' value must be set in other.');
}
}
public static function get_other_mapping() {
$othermapped = array();
$othermapped['submissionid'] = array('db' => 'assign_submission', 'restore' => 'submission');
$othermapped['groupid'] = array('db' => 'groups', 'restore' => 'group');
return $othermapped;
}
}
@@ -0,0 +1,122 @@
<?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/>.
/**
* The mod_assign submission viewed event.
*
* @package mod_assign
* @copyright 2014 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_assign submission viewed event class.
*
* @property-read array $other {
* Extra information about the event.
*
* - int assignid: the id of the assignment.
* }
*
* @package mod_assign
* @since Moodle 2.7
* @copyright 2014 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class submission_viewed extends base {
/**
* Create instance of event.
*
* @param \assign $assign
* @param \stdClass $submission
* @return submission_viewed
*/
public static function create_from_submission(\assign $assign, \stdClass $submission) {
$data = array(
'objectid' => $submission->id,
'relateduserid' => $submission->userid,
'context' => $assign->get_context(),
'other' => array(
'assignid' => $assign->get_instance()->id,
),
);
/** @var submission_viewed $event */
$event = self::create($data);
$event->set_assign($assign);
$event->add_record_snapshot('assign_submission', $submission);
return $event;
}
/**
* Init method.
*/
protected function init() {
$this->data['objecttable'] = 'assign_submission';
$this->data['crud'] = 'r';
$this->data['edulevel'] = self::LEVEL_PARTICIPATING;
}
/**
* Returns localised general event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventsubmissionviewed', 'mod_assign');
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' viewed the submission for the user with id '$this->relateduserid' for the " .
"assignment with course module id '$this->contextinstanceid'.";
}
/**
* Custom validation.
*
* @throws \coding_exception
*/
protected function validate_data() {
parent::validate_data();
if (!isset($this->relateduserid)) {
throw new \coding_exception('The \'relateduserid\' must be set.');
}
if (!isset($this->other['assignid'])) {
throw new \coding_exception('The \'assignid\' value must be set in other.');
}
}
public static function get_objectid_mapping() {
return array('db' => 'assign_submission', 'restore' => 'submission');
}
public static function get_other_mapping() {
$othermapped = array();
$othermapped['assignid'] = array('db' => 'assign', 'restore' => 'assign');
return $othermapped;
}
}
@@ -0,0 +1,115 @@
<?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/>.
/**
* The mod_assign user override created event.
*
* @package mod_assign
* @copyright 2016 Ilya Tregubov
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_assign user override created event class.
*
* @property-read array $other {
* Extra information about event.
*
* - int assignid: the id of the assign.
* }
*
* @package mod_assign
* @since Moodle 3.2
* @copyright 2016 Ilya Tregubov
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class user_override_created extends \core\event\base {
/**
* Init method.
*/
protected function init() {
$this->data['objecttable'] = 'assign_overrides';
$this->data['crud'] = 'c';
$this->data['edulevel'] = self::LEVEL_TEACHING;
}
/**
* Returns localised general event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventoverridecreated', 'mod_assign');
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' created the override with id '$this->objectid' for the assign with " .
"course module id '$this->contextinstanceid' for the user with id '{$this->relateduserid}'.";
}
/**
* Returns relevant URL.
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/assign/overrideedit.php', array('id' => $this->objectid));
}
/**
* Custom validation.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
parent::validate_data();
if (!isset($this->relateduserid)) {
throw new \coding_exception('The \'relateduserid\' must be set.');
}
if (!isset($this->other['assignid'])) {
throw new \coding_exception('The \'assignid\' value must be set in other.');
}
}
/**
* Get objectid mapping
*/
public static function get_objectid_mapping() {
return array('db' => 'assign_overrides', 'restore' => 'assign_override');
}
/**
* Get other mapping
*/
public static function get_other_mapping() {
$othermapped = array();
$othermapped['assignid'] = array('db' => 'assign', 'restore' => 'assign');
return $othermapped;
}
}
@@ -0,0 +1,115 @@
<?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/>.
/**
* The mod_assign user override deleted event.
*
* @package mod_assign
* @copyright 2016 Ilya Tregubov
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_assign user override deleted event class.
*
* @property-read array $other {
* Extra information about event.
*
* - int assignid: the id of the assign.
* }
*
* @package mod_assign
* @since Moodle 3.2
* @copyright 2016 Ilya Tregubov
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class user_override_deleted extends \core\event\base {
/**
* Init method.
*/
protected function init() {
$this->data['objecttable'] = 'assign_overrides';
$this->data['crud'] = 'd';
$this->data['edulevel'] = self::LEVEL_TEACHING;
}
/**
* Returns localised general event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventoverridedeleted', 'mod_assign');
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' deleted the override with id '$this->objectid' for the assign with " .
"course module id '$this->contextinstanceid' for the user with id '{$this->relateduserid}'.";
}
/**
* Returns relevant URL.
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/assign/overrides.php', array('cmid' => $this->contextinstanceid));
}
/**
* Custom validation.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
parent::validate_data();
if (!isset($this->relateduserid)) {
throw new \coding_exception('The \'relateduserid\' must be set.');
}
if (!isset($this->other['assignid'])) {
throw new \coding_exception('The \'assignid\' value must be set in other.');
}
}
/**
* Get objectid mapping
*/
public static function get_objectid_mapping() {
return array('db' => 'assign_overrides', 'restore' => 'assign_override');
}
/**
* Get other mapping
*/
public static function get_other_mapping() {
$othermapped = array();
$othermapped['assignid'] = array('db' => 'assign', 'restore' => 'assign');
return $othermapped;
}
}
@@ -0,0 +1,116 @@
<?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/>.
/**
* The mod_assign user override updated event.
*
* @package mod_assign
* @copyright 2016 Ilya Tregubov
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_assign user override updated event class.
*
* @property-read array $other {
* Extra information about event.
*
* - int assignid: the id of the assign.
* }
*
* @package mod_assign
* @since Moodle 3.2
* @copyright 2016 Ilya Tregubov
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class user_override_updated extends \core\event\base {
/**
* Init method.
*/
protected function init() {
$this->data['objecttable'] = 'assign_overrides';
$this->data['crud'] = 'u';
$this->data['edulevel'] = self::LEVEL_TEACHING;
}
/**
* Returns localised general event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventoverrideupdated', 'mod_assign');
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' updated the override with id '$this->objectid' for the assign with " .
"course module id '$this->contextinstanceid' for the user with id '{$this->relateduserid}'.";
}
/**
* Returns relevant URL.
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/assign/overrideedit.php', array('id' => $this->objectid));
}
/**
* Custom validation.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
parent::validate_data();
if (!isset($this->relateduserid)) {
throw new \coding_exception('The \'relateduserid\' must be set.');
}
if (!isset($this->other['assignid'])) {
throw new \coding_exception('The \'assignid\' value must be set in other.');
}
}
/**
* Get objectid mapping
*/
public static function get_objectid_mapping() {
return array('db' => 'assign_overrides', 'restore' => 'assign_override');
}
/**
* Get other mapping
*/
public static function get_other_mapping() {
$othermapped = array();
$othermapped['assignid'] = array('db' => 'assign', 'restore' => 'assign');
return $othermapped;
}
}
@@ -0,0 +1,137 @@
<?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/>.
/**
* mod_assign workflow state updated event.
*
* @package mod_assign
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign\event;
defined('MOODLE_INTERNAL') || die();
/**
* mod_assign workflow state updated event class.
*
* @property-read array $other {
* Extra information about event.
*
* - string newstate: state of submission.
* }
*
* @package mod_assign
* @since Moodle 2.6
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class workflow_state_updated extends base {
/**
* Flag for prevention of direct create() call.
* @var bool
*/
protected static $preventcreatecall = true;
/**
* Create instance of event.
*
* @since Moodle 2.7
*
* @param \assign $assign
* @param \stdClass $user
* @param string $state
* @return workflow_state_updated
*/
public static function create_from_user(\assign $assign, \stdClass $user, $state) {
$data = array(
'context' => $assign->get_context(),
'objectid' => $assign->get_instance()->id,
'relateduserid' => $user->id,
'other' => array(
'newstate' => $state,
),
);
self::$preventcreatecall = false;
/** @var workflow_state_updated $event */
$event = self::create($data);
self::$preventcreatecall = true;
$event->set_assign($assign);
$event->add_record_snapshot('user', $user);
return $event;
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' has set the workflow state of the user with id '$this->relateduserid' " .
"to the state '{$this->other['newstate']}' for the assignment with course module id '$this->contextinstanceid'.";
}
/**
* Return localised event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventworkflowstateupdated', 'mod_assign');
}
/**
* Init method.
*
* @return void
*/
protected function init() {
$this->data['crud'] = 'u';
$this->data['edulevel'] = self::LEVEL_TEACHING;
$this->data['objecttable'] = 'assign';
}
/**
* Custom validation.
*
* @throws \coding_exception
*/
protected function validate_data() {
if (self::$preventcreatecall) {
throw new \coding_exception('cannot call workflow_state_updated::create() directly, use workflow_state_updated::create_from_user() instead.');
}
parent::validate_data();
if (!isset($this->relateduserid)) {
throw new \coding_exception('The \'relateduserid\' must be set.');
}
if (!isset($this->other['newstate'])) {
throw new \coding_exception('The \'newstate\' value must be set in other.');
}
}
public static function get_objectid_mapping() {
return array('db' => 'assign', 'restore' => 'assign');
}
public static function get_other_mapping() {
// Nothing to map.
return false;
}
}
+114
View File
@@ -0,0 +1,114 @@
<?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/>.
namespace mod_assign\external;
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once("$CFG->dirroot/mod/assign/locallib.php");
/**
* Extend the base external_api class with mod_assign utility methods.
*
* @package mod_assign
* @author Andrew Madden <andrewmadden@catalyst-au.net>
* @copyright 2021 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class external_api extends \core_external\external_api {
/**
* Generate a warning in a standard structure for a known failure.
*
* @param int $assignmentid - The assignment
* @param string $warningcode - The key for the warning message
* @param string $detail - A description of the error
* @return array - Warning structure containing item, itemid, warningcode, message
*/
protected static function generate_warning(int $assignmentid, string $warningcode, string $detail): array {
$warningmessages = [
'couldnotlock' => 'Could not lock the submission for this user.',
'couldnotunlock' => 'Could not unlock the submission for this user.',
'couldnotsubmitforgrading' => 'Could not submit assignment for grading.',
'couldnotrevealidentities' => 'Could not reveal identities.',
'couldnotgrantextensions' => 'Could not grant submission date extensions.',
'couldnotrevert' => 'Could not revert submission to draft.',
'invalidparameters' => 'Invalid parameters.',
'couldnotsavesubmission' => 'Could not save submission.',
'couldnotsavegrade' => 'Could not save grade.',
'couldnotstartsubmission' => 'Could not start submission with time limit.',
'submissionnotopen' => 'This assignment is not open for submissions',
'timelimitnotenabled' => 'Time limit is not enabled for assignment.',
'opensubmissionexists' => 'Open assignment submission already exists.',
];
$message = $warningmessages[$warningcode];
if (empty($message)) {
$message = 'Unknown warning type.';
}
return [
'item' => s($detail),
'itemid' => $assignmentid,
'warningcode' => $warningcode,
'message' => $message,
];
}
/**
* Utility function for validating an assign.
*
* @param int $assignid assign instance id
* @return array array containing the assign, course, context and course module objects
* @since Moodle 3.2
*/
protected static function validate_assign(int $assignid): array {
global $DB;
// Request and permission validation.
$assign = $DB->get_record('assign', ['id' => $assignid], 'id', MUST_EXIST);
list($course, $cm) = get_course_and_cm_from_instance($assign, 'assign');
$context = \context_module::instance($cm->id);
// Please, note that is not required to check mod/assign:view because is done by validate_context->require_login.
self::validate_context($context);
$assign = new \assign($context, $cm, $course);
return [$assign, $course, $cm, $context];
}
/**
* Get a submission from an assignment for a user. Encapsulates checking whether it's a solo or team submission.
*
* @param \assign $assignment Assignment object.
* @param int|null $userid User id.
* @param int $groupid Group id.
* @param bool $create Whether a new submission should be created.
* @param int $attemptnumber Attempt number. Use -1 for last attempt.
* @return bool|\stdClass
*/
protected static function get_user_or_group_submission(\assign $assignment, int $userid = null,
int $groupid = 0, bool $create = false, int $attemptnumber = -1) {
if ($assignment->get_instance($userid)->teamsubmission) {
$submission = $assignment->get_group_submission($userid, $groupid, $create, $attemptnumber);
} else {
$submission = $assignment->get_user_submission($userid, $create, $attemptnumber);
}
return $submission;
}
}
+118
View File
@@ -0,0 +1,118 @@
<?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/>.
namespace mod_assign\external;
use core_external\external_function_parameters;
use core_external\external_single_structure;
use core_external\external_value;
use core_external\external_warnings;
/**
* External function to notify Moodle that an assignment submission is starting.
*
* @package mod_assign
* @author Andrew Madden <andrewmadden@catalyst-au.net>
* @copyright 2021 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class start_submission extends external_api {
/**
* Describes the parameters for submission_start.
*
* @return external_function_parameters
* @since Moodle 4.0
*/
public static function execute_parameters(): external_function_parameters {
return new external_function_parameters ([
'assignid' => new external_value(PARAM_INT, 'Assignment instance id'),
]
);
}
/**
* Call to start an assignment submission.
*
* @param int $assignid Assignment ID.
* @return array
* @since Moodle 4.0
*/
public static function execute(int $assignid): array {
global $DB, $USER;
$result = $warnings = [];
$submission = null;
[
'assignid' => $assignid,
] = self::validate_parameters(self::execute_parameters(), [
'assignid' => $assignid,
]);
list($assignment, $course, $cm, $context) = self::validate_assign($assignid);
$assignment->update_effective_access($USER->id);
$latestsubmission = external_api::get_user_or_group_submission($assignment, $USER->id);
if (!$assignment->submissions_open($USER->id)) {
$warnings[] = self::generate_warning($assignid,
'submissionnotopen',
get_string('submissionnotopen', 'assign'));
}
if (!$assignment->is_time_limit_enabled()) {
$warnings[] = self::generate_warning($assignid,
'timelimitnotenabled',
get_string('timelimitnotenabled', 'assign'));
} else if ($assignment->is_attempt_in_progress()) {
$warnings[] = self::generate_warning($assignid,
'opensubmissionexists',
get_string('opensubmissionexists', 'assign'));
}
if (empty($warnings)) {
// If there is an open submission with no start time, use latest submission, otherwise create a new submission.
if (!empty($latestsubmission)
&& $latestsubmission->status !== ASSIGN_SUBMISSION_STATUS_SUBMITTED
&& empty($latestsubmission->timestarted)) {
$submission = $latestsubmission;
} else {
$submission = external_api::get_user_or_group_submission($assignment, $USER->id, 0, true);
}
// Set the start time of the submission.
$submission->timestarted = time();
$DB->update_record('assign_submission', $submission);
}
$result['submissionid'] = $submission ? $submission->id : 0;
$result['warnings'] = $warnings;
return $result;
}
/**
* Describes the submission_start return value.
*
* @return external_single_structure
* @since Moodle 4.0
*/
public static function execute_returns(): external_single_structure {
return new external_single_structure([
'submissionid' => new external_value(PARAM_INT, 'New submission ID.'),
'warnings' => new external_warnings(),
]);
}
}
+62
View File
@@ -0,0 +1,62 @@
<?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/>.
/**
* Grade item mappings for the activity.
*
* @package mod_assign
* @copyright Andrew Nicols <andrew@nicols.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
declare(strict_types = 1);
namespace mod_assign\grades;
use \core_grades\local\gradeitem\itemnumber_mapping;
use \core_grades\local\gradeitem\advancedgrading_mapping;
/**
* Grade item mappings for the activity.
*
* @package mod_assign
* @copyright Andrew Nicols <andrew@nicols.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class gradeitems implements itemnumber_mapping, advancedgrading_mapping {
/**
* Return the list of grade item mappings for the assign.
*
* @return array
*/
public static function get_itemname_mapping_for_component(): array {
return [
0 => 'submissions',
];
}
/**
* Get the list of advanced grading item names for this component.
*
* @return array
*/
public static function get_advancedgrading_itemnames(): array {
return [
'submissions',
];
}
}
+85
View File
@@ -0,0 +1,85 @@
<?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/>.
/**
* Group observers.
*
* @package mod_assign
* @copyright 2016 Ilya Tregubov
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign;
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/mod/assign/locallib.php');
/**
* Group observers class.
*
* @package mod_assign
* @copyright 2016 Ilya Tregubov
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class group_observers {
/**
* Flag whether a course reset is in progress or not.
*
* @var int The course ID.
*/
protected static $resetinprogress = false;
/**
* A course reset has started.
*
* @param \core\event\base $event The event.
* @return void
*/
public static function course_reset_started($event) {
self::$resetinprogress = $event->courseid;
}
/**
* A course reset has ended.
*
* @param \core\event\base $event The event.
* @return void
*/
public static function course_reset_ended($event) {
if (!empty(self::$resetinprogress)) {
if (!empty($event->other['reset_options']['reset_groups_remove'])) {
assign_process_group_deleted_in_course($event->courseid);
}
}
self::$resetinprogress = null;
}
/**
* A group was deleted.
*
* @param \core\event\base $event The event.
* @return void
*/
public static function group_deleted($event) {
if (!empty(self::$resetinprogress)) {
// We will take care of that once the course reset ends.
return;
}
assign_process_group_deleted_in_course($event->courseid, $event->objectid);
}
}
@@ -0,0 +1,45 @@
<?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/>.
namespace mod_assign\navigation\views;
use core\navigation\views\secondary as core_secondary;
/**
* Class secondary_navigation_view.
*
* Custom implementation for a plugin.
*
* @package mod_assign
* @category navigation
* @copyright 2021 onwards Peter Dias
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class secondary extends core_secondary {
protected function get_default_module_mapping(): array {
$defaultmaping = parent::get_default_module_mapping();
$defaultmaping[self::TYPE_SETTING] = array_merge($defaultmaping[self::TYPE_SETTING], [
'modedit' => 1,
"mod_{$this->page->activityname}_useroverrides" => 2, // Overrides are module specific.
"mod_{$this->page->activityname}_groupoverrides" => 3,
]);
$defaultmaping[self::TYPE_CUSTOM] = array_merge($defaultmaping[self::TYPE_CUSTOM], [
'advgrading' => 4,
]);
return $defaultmaping;
}
}
+61
View File
@@ -0,0 +1,61 @@
<?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/>.
namespace mod_assign\output;
use templatable;
use renderable;
use moodle_url;
/**
* Output the actionbar for this activity.
*
* @package mod_assign
* @copyright 2021 Adrian Greeve <adrian@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class actionmenu implements templatable, renderable {
/** @var int The course module ID. */
private $cmid;
/**
* Constructor for this object.
*
* @param int $cmid The course module ID.
*/
public function __construct(int $cmid) {
$this->cmid = $cmid;
}
/**
* Data to be used for a template.
*
* @param \renderer_base $output renderer base output.
* @return array Data to be used for a template.
*/
public function export_for_template(\renderer_base $output): array {
$submissionlink = new moodle_url('/mod/assign/view.php', ['id' => $this->cmid, 'action' => 'grading']);
$return = ['submissionlink' => $submissionlink->out(false)];
if (has_capability('mod/assign:grade', \context_module::instance($this->cmid))) {
$gradelink = new moodle_url('/mod/assign/view.php', ['id' => $this->cmid, 'action' => 'grader']);
$return['gradelink'] = $gradelink->out(false);
}
return $return;
}
}
@@ -0,0 +1,87 @@
<?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/>.
/**
* This file contains the definition for the renderable assign header.
*
* @package mod_assign
* @copyright 2020 Matt Porritt <mattp@catalyst-au.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign\output;
/**
* This file contains the definition for the renderable assign header.
*
* @package mod_assign
* @copyright 2012 NetSpot {@link http://www.netspot.com.au}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class assign_header implements \renderable {
/** @var \stdClass The assign record. */
public $assign;
/** @var mixed \context|null the context record. */
public $context;
/** @var bool $showintro Show or hide the intro. */
public $showintro;
/** @var int coursemoduleid The course module id. */
public $coursemoduleid;
/** @var string $subpage Optional subpage (extra level in the breadcrumbs). */
public $subpage;
/** @var string $preface Optional preface (text to show before the heading). */
public $preface;
/** @var string $postfix Optional postfix (text to show after the intro). */
public $postfix;
/** @var \moodle_url|null $subpageurl link for the sub page */
public $subpageurl;
/** @var bool $activity optional show activity text. */
public $activity;
/**
* Constructor
*
* @param \stdClass $assign The assign database record.
* @param \context|null $context The course module context.
* @param bool $showintro Show or hide the intro.
* @param int $coursemoduleid The course module id.
* @param string $subpage An optional sub page in the navigation.
* @param string $preface An optional preface to show before the heading.
* @param string $postfix An optional postfix to show after the intro.
* @param \moodle_url|null $subpageurl An optional sub page URL link for the subpage.
* @param bool $activity Optional show activity text if true.
*/
public function __construct(
\stdClass $assign,
$context,
$showintro,
$coursemoduleid,
$subpage = '',
$preface = '',
$postfix = '',
\moodle_url $subpageurl = null,
bool $activity = false
) {
$this->assign = $assign;
$this->context = $context;
$this->showintro = $showintro;
$this->coursemoduleid = $coursemoduleid;
$this->subpage = $subpage;
$this->preface = $preface;
$this->postfix = $postfix;
$this->subpageurl = $subpageurl;
$this->activity = $activity;
}
}
@@ -0,0 +1,204 @@
<?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/>.
/**
* This file contains the definition for the renderable assign submission status.
*
* @package mod_assign
* @copyright 2020 Matt Porritt <mattp@catalyst-au.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign\output;
/**
* This file contains the definition for the renderable assign submission status.
*
* @package mod_assign
* @copyright 2012 NetSpot {@link http://www.netspot.com.au}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class assign_submission_status implements \renderable {
/** @var int STUDENT_VIEW */
const STUDENT_VIEW = 10;
/** @var int GRADER_VIEW */
const GRADER_VIEW = 20;
/** @var int allowsubmissionsfromdate */
public $allowsubmissionsfromdate = 0;
/** @var bool alwaysshowdescription */
public $alwaysshowdescription = false;
/** @var mixed the submission info (may be null or an integer) */
public $submission = null;
/** @var boolean teamsubmissionenabled - true or false */
public $teamsubmissionenabled = false;
/** @var \stdClass teamsubmission the team submission info (may be null) */
public $teamsubmission = null;
/** @var mixed submissiongroup the submission group info (may be null) */
public $submissiongroup = null;
/** @var array submissiongroupmemberswhoneedtosubmit list of users who still need to submit */
public $submissiongroupmemberswhoneedtosubmit = array();
/** @var bool submissionsenabled */
public $submissionsenabled = false;
/** @var bool locked */
public $locked = false;
/** @var bool graded */
public $graded = false;
/** @var int duedate */
public $duedate = 0;
/** @var int cutoffdate */
public $cutoffdate = 0;
/** @var array submissionplugins - the list of submission plugins */
public $submissionplugins = array();
/** @var string returnaction */
public $returnaction = '';
/** @var string returnparams */
public $returnparams = array();
/** @var int courseid */
public $courseid = 0;
/** @var int coursemoduleid */
public $coursemoduleid = 0;
/** @var int the view (STUDENT_VIEW OR GRADER_VIEW) */
public $view = self::STUDENT_VIEW;
/** @var bool canviewfullnames */
public $canviewfullnames = false;
/** @var bool canedit */
public $canedit = false;
/** @var bool cansubmit */
public $cansubmit = false;
/** @var int extensionduedate */
public $extensionduedate = 0;
/** @var \context context */
public $context = 0;
/** @var bool blindmarking - Should we hide student identities from graders? */
public $blindmarking = false;
/** @var string gradingcontrollerpreview */
public $gradingcontrollerpreview = '';
/** @var string attemptreopenmethod */
public $attemptreopenmethod = 'none';
/** @var int maxattempts */
public $maxattempts = -1;
/** @var string gradingstatus */
public $gradingstatus = '';
/** @var bool preventsubmissionnotingroup */
public $preventsubmissionnotingroup = 0;
/** @var array usergroups */
public $usergroups = array();
/** @var int The time limit for the assignment */
public $timelimit = 0;
/** @var bool */
public $caneditowner;
/**
* Constructor
*
* @param int $allowsubmissionsfromdate
* @param bool $alwaysshowdescription
* @param mixed $submission
* @param bool $teamsubmissionenabled
* @param \stdClass $teamsubmission
* @param mixed $submissiongroup
* @param array $submissiongroupmemberswhoneedtosubmit
* @param bool $submissionsenabled
* @param bool $locked
* @param bool $graded
* @param int $duedate
* @param int $cutoffdate
* @param array $submissionplugins
* @param string $returnaction
* @param array $returnparams
* @param int $coursemoduleid
* @param int $courseid
* @param string $view
* @param bool $canedit
* @param bool $cansubmit
* @param bool $canviewfullnames
* @param int $extensionduedate Any extension to the due date granted for this user.
* @param \context $context Any extension to the due date granted for this user.
* @param bool $blindmarking Should we hide student identities from graders?
* @param string $gradingcontrollerpreview
* @param string $attemptreopenmethod The method of reopening student attempts.
* @param int $maxattempts How many attempts can a student make?
* @param string $gradingstatus The submission status (ie. Graded, Not Released etc).
* @param bool $preventsubmissionnotingroup Prevent submission if user is not in a group.
* @param array $usergroups Array containing all groups the user is assigned to.
* @param int $timelimit The time limit for the assignment.
*/
public function __construct(
$allowsubmissionsfromdate,
$alwaysshowdescription,
$submission,
$teamsubmissionenabled,
$teamsubmission,
$submissiongroup,
$submissiongroupmemberswhoneedtosubmit,
$submissionsenabled,
$locked,
$graded,
$duedate,
$cutoffdate,
$submissionplugins,
$returnaction,
$returnparams,
$coursemoduleid,
$courseid,
$view,
$canedit,
$cansubmit,
$canviewfullnames,
$extensionduedate,
$context,
$blindmarking,
$gradingcontrollerpreview,
$attemptreopenmethod,
$maxattempts,
$gradingstatus,
$preventsubmissionnotingroup,
$usergroups,
$timelimit
) {
$this->allowsubmissionsfromdate = $allowsubmissionsfromdate;
$this->alwaysshowdescription = $alwaysshowdescription;
$this->submission = $submission;
$this->teamsubmissionenabled = $teamsubmissionenabled;
$this->teamsubmission = $teamsubmission;
$this->submissiongroup = $submissiongroup;
$this->submissiongroupmemberswhoneedtosubmit = $submissiongroupmemberswhoneedtosubmit;
$this->submissionsenabled = $submissionsenabled;
$this->locked = $locked;
$this->graded = $graded;
$this->duedate = $duedate;
$this->cutoffdate = $cutoffdate;
$this->submissionplugins = $submissionplugins;
$this->returnaction = $returnaction;
$this->returnparams = $returnparams;
$this->coursemoduleid = $coursemoduleid;
$this->courseid = $courseid;
$this->view = $view;
$this->canedit = $canedit;
$this->cansubmit = $cansubmit;
$this->canviewfullnames = $canviewfullnames;
$this->extensionduedate = $extensionduedate;
$this->context = $context;
$this->blindmarking = $blindmarking;
$this->gradingcontrollerpreview = $gradingcontrollerpreview;
$this->attemptreopenmethod = $attemptreopenmethod;
$this->maxattempts = $maxattempts;
$this->gradingstatus = $gradingstatus;
$this->preventsubmissionnotingroup = $preventsubmissionnotingroup;
$this->usergroups = $usergroups;
$this->timelimit = $timelimit;
}
}
@@ -0,0 +1,77 @@
<?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/>.
/**
* Output the grading actionbar for this activity.
*
* @package mod_assign
* @copyright 2021 Adrian Greeve <adrian@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign\output;
use templatable;
use renderable;
use moodle_url;
/**
* Output the grading actionbar for this activity.
*
* @package mod_assign
* @copyright 2021 Adrian Greeve <adrian@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class grading_actionmenu implements templatable, renderable {
/** @var int Course module ID. */
protected $cmid;
/** @var bool If any submission plugins are enabled. */
protected $submissionpluginenabled;
/** @var int The number of submissions made. */
protected $submissioncount;
/**
* Constructor for this object.
*
* @param int $cmid Course module ID.
* @param bool $submissionpluginenabled If any submission plugins are enabled.
* @param int $submissioncount The number of submissions made.
*/
public function __construct(int $cmid, bool $submissionpluginenabled = false, int $submissioncount = 0) {
$this->cmid = $cmid;
$this->submissionpluginenabled = $submissionpluginenabled;
$this->submissioncount = $submissioncount;
}
/**
* Data to render in a template.
*
* @param \renderer_base $output renderer base output.
* @return array Data to render.
*/
public function export_for_template(\renderer_base $output): array {
$downloadall = '';
if ($this->submissionpluginenabled && $this->submissioncount) {
$downloadall = (new moodle_url('/mod/assign/view.php', ['id' => $this->cmid, 'action' => 'downloadall']))->out(false);
}
return [
'downloadall' => $downloadall
];
}
}
+181
View File
@@ -0,0 +1,181 @@
<?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/>.
/**
* Renderable that initialises the grading "app".
*
* @package mod_assign
* @copyright 2016 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign\output;
defined('MOODLE_INTERNAL') || die();
use renderer_base;
use renderable;
use templatable;
use stdClass;
/**
* Grading app renderable.
*
* @package mod_assign
* @since Moodle 3.1
* @copyright 2016 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class grading_app implements templatable, renderable {
/**
* @var $userid - The initial user id.
*/
public $userid = 0;
/**
* @var $groupid - The initial group id.
*/
public $groupid = 0;
/**
* @var $assignment - The assignment instance.
*/
public $assignment = null;
/**
* @var array - List of user records with extra fields.
*/
public $participants = [];
/**
* Constructor for this renderable.
*
* @param int $userid The user we will open the grading app too.
* @param int $groupid If groups are enabled this is the current course group.
* @param \assign $assignment The assignment class
*/
public function __construct($userid, $groupid, $assignment) {
$this->userid = $userid;
$this->groupid = $groupid;
$this->assignment = $assignment;
$this->participants = $assignment->list_participants_with_filter_status_and_group($groupid);
if (!$this->userid && count($this->participants)) {
$this->userid = reset($this->participants)->id;
}
}
/**
* Export this class data as a flat list for rendering in a template.
*
* @param renderer_base $output The current page renderer.
* @return stdClass - Flat list of exported data.
*/
public function export_for_template(renderer_base $output) {
global $CFG, $USER;
$export = new stdClass();
$export->userid = $this->userid;
$export->assignmentid = $this->assignment->get_instance()->id;
$export->cmid = $this->assignment->get_course_module()->id;
$export->contextid = $this->assignment->get_context()->id;
$export->groupid = $this->groupid;
$export->name = $this->assignment->get_context()->get_context_name(true, false, false);
$export->courseid = $this->assignment->get_course()->id;
$export->participants = array();
$export->filters = $this->assignment->get_filters();
$export->markingworkflowfilters = $this->assignment->get_marking_workflow_filters(true);
$export->hasmarkingworkflow = count($export->markingworkflowfilters) > 0;
$export->markingallocationfilters = $this->assignment->get_marking_allocation_filters(true);
$export->hasmarkingallocation = count($export->markingallocationfilters) > 0;
$num = 1;
foreach ($this->participants as $idx => $record) {
$user = new stdClass();
$user->id = $record->id;
$user->fullname = fullname($record);
$user->requiregrading = $record->requiregrading;
$user->grantedextension = $record->grantedextension;
$user->submitted = $record->submitted;
if (!empty($record->groupid)) {
$user->groupid = $record->groupid;
$user->groupname = $record->groupname;
}
if ($record->id == $this->userid) {
$export->index = $num;
$user->current = true;
}
$export->participants[] = $user;
$num++;
}
$feedbackplugins = $this->assignment->get_feedback_plugins();
$showreview = false;
foreach ($feedbackplugins as $plugin) {
if ($plugin->is_enabled() && $plugin->is_visible()) {
if ($plugin->supports_review_panel()) {
$showreview = true;
}
}
}
$export->actiongrading = 'grading';
$export->viewgrading = get_string('viewgrading', 'mod_assign');
$export->showreview = $showreview;
$time = time();
$export->count = count($export->participants);
$export->coursename = $this->assignment->get_course_context()->get_context_name(true, false, false);
$export->caneditsettings = has_capability('mod/assign:addinstance', $this->assignment->get_context());
$export->duedate = $this->assignment->get_instance()->duedate;
$export->duedatestr = userdate($this->assignment->get_instance()->duedate);
// Time remaining.
$due = '';
if ($export->duedate - $time <= 0) {
$due = get_string('assignmentisdue', 'assign');
} else {
$due = get_string('timeremainingcolon', 'assign', format_time($export->duedate - $time));
}
$export->timeremainingstr = $due;
if ($export->duedate < $time) {
$export->cutoffdate = $this->assignment->get_instance()->cutoffdate;
$cutoffdate = $export->cutoffdate;
if ($cutoffdate) {
if ($cutoffdate > $time) {
$late = get_string('latesubmissionsaccepted', 'assign', userdate($export->cutoffdate));
} else {
$late = get_string('nomoresubmissionsaccepted', 'assign');
}
$export->cutoffdatestr = $late;
}
}
$export->defaultsendnotifications = $this->assignment->get_instance()->sendstudentnotifications;
$export->rarrow = $output->rarrow();
$export->larrow = $output->larrow();
// List of identity fields to display (the user info will not contain any fields the user cannot view anyway).
// TODO Does not support custom user profile fields (MDL-70456).
$export->showuseridentity = implode(',', \core_user\fields::get_identity_fields(null, false));
$export->currentuserid = $USER->id;
$helpicon = new \help_icon('sendstudentnotifications', 'assign');
$export->helpicon = $helpicon->export_for_template($output);
return $export;
}
}
@@ -0,0 +1,161 @@
<?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/>.
/**
* Output the override actionbar for this activity.
*
* @package mod_assign
* @copyright 2021 Adrian Greeve <adrian@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign\output;
use core_availability\info_module;
use moodle_url;
use templatable;
use renderable;
use url_select;
use single_button;
/**
* Output the override actionbar for this activity.
*
* @package mod_assign
* @copyright 2021 Adrian Greeve <adrian@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class override_actionmenu implements templatable, renderable {
/** @var moodle_url The current url for this page. */
protected $currenturl;
/** @var \cm_info course module information */
protected $cm;
/** @var bool Can all groups be accessed */
protected $canaccessallgroups;
/** @var array Groups related to this activity */
protected $groups;
/**
* Constructor for this action menu.
*
* @param moodle_url $currenturl The current url for this page.
* @param \cm_info $cm course module information.
*/
public function __construct(moodle_url $currenturl, \cm_info $cm) {
$this->currenturl = $currenturl;
$this->cm = $cm;
$groupmode = groups_get_activity_groupmode($this->cm);
$this->canaccessallgroups = ($groupmode === NOGROUPS) ||
has_capability('moodle/site:accessallgroups', $this->cm->context);
$this->groups = $this->canaccessallgroups ? groups_get_all_groups($this->cm->course) :
groups_get_activity_allowed_groups($this->cm);
}
/**
* Create a select menu for overrides.
*
* @return url_select A url select object.
*/
protected function get_select_menu(): url_select {
$userlink = new moodle_url('/mod/assign/overrides.php', ['cmid' => $this->cm->id, 'mode' => 'user']);
$grouplink = new moodle_url('/mod/assign/overrides.php', ['cmid' => $this->cm->id, 'mode' => 'group']);
$menu = [
$userlink->out(false) => get_string('useroverrides', 'mod_assign'),
$grouplink->out(false) => get_string('groupoverrides', 'mod_assign'),
];
return new url_select($menu, $this->currenturl->out(false), null, 'mod_assign_override_select');
}
/**
* Whether to show groups or not. Assignments can be have group overrides if there are groups available in the course.
* There is no restriction related to the assignment group setting.
*
* @return bool
*/
protected function show_groups(): bool {
if ($this->canaccessallgroups) {
$groups = groups_get_all_groups($this->cm->course);
} else {
$groups = groups_get_activity_allowed_groups($this->cm);
}
return !(empty($groups));
}
/**
* Whether to enable/disable user override button or not.
*
* @return bool
*/
protected function show_useroverride(): bool {
global $DB;
$users = [];
$context = $this->cm->context;
if ($this->canaccessallgroups) {
$users = get_enrolled_users($context, '', 0, 'u.id');
} else if ($this->groups) {
$enrolledjoin = get_enrolled_join($context, 'u.id');
list($ingroupsql, $ingroupparams) = $DB->get_in_or_equal(array_keys($this->groups), SQL_PARAMS_NAMED);
$params = $enrolledjoin->params + $ingroupparams;
$sql = "SELECT u.id
FROM {user} u
JOIN {groups_members} gm ON gm.userid = u.id
{$enrolledjoin->joins}
WHERE gm.groupid $ingroupsql
AND {$enrolledjoin->wheres}";
$users = $DB->get_records_sql($sql, $params);
}
$info = new info_module($this->cm);
$users = $info->filter_user_list($users);
return !empty($users);
}
/**
* Data to be used in a template.
*
* @param \renderer_base $output renderer base output.
* @return array The data to be used in a template.
*/
public function export_for_template(\renderer_base $output): array {
$type = $this->currenturl->get_param('mode');
if ($type == 'user') {
$text = get_string('addnewuseroverride', 'mod_assign');
} else {
$text = get_string('addnewgroupoverride', 'mod_assign');
}
$action = ($type == 'user') ? 'adduser' : 'addgroup';
$params = ['cmid' => $this->currenturl->get_param('cmid'), 'action' => $action];
$url = new moodle_url('/mod/assign/overrideedit.php', $params);
$options = [];
if ($action == 'addgroup' && !$this->show_groups()) {
$options = ['disabled' => 'true'];
} else if ($action === 'adduser' && !$this->show_useroverride()) {
$options = ['disabled' => 'true'];
}
$overridebutton = new single_button($url, $text, 'post', single_button::BUTTON_PRIMARY, $options);
$urlselect = $this->get_select_menu();
return [
'addoverride' => $overridebutton->export_for_template($output),
'urlselect' => $urlselect->export_for_template($output)
];
}
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,82 @@
<?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/>.
/**
* Represents the timer panel.
*
* @package mod_assign
* @copyright 2020 Ilya Tregubov <ilyatregubov@catalyst-au.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign\output;
use renderable;
use renderer_base;
use stdClass;
use templatable;
/**
* Represents the timer panel.
*
* @package mod_assign
* @copyright 2020 Ilya Tregubov <ilyatregubov@catalyst-au.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class timelimit_panel implements templatable, renderable {
/** @var \stdClass assign submission attempt.*/
protected $submission;
/** @var object assign object.*/
protected $assign;
/**
* Constructor.
*
* @param \stdClass $submission assign submission.
* @param \stdClass $assign assign object.
*/
public function __construct(\stdClass $submission, \stdClass $assign) {
$this->submission = $submission;
$this->assign = $assign;
}
/**
* Render timer.
*
* @param renderer_base $output The current page renderer.
* @return stdClass - Flat list of exported data.
*/
public function export_for_template(renderer_base $output): stdClass {
return (object)['timerstartvalue' => $this->end_time() - time()];
}
/**
* Compute end time for this assign attempt.
*
* @return int the time when assign attempt is due.
*/
private function end_time(): int {
$timedue = $this->submission->timestarted + $this->assign->timelimit;
if ($this->assign->duedate) {
return min($timedue, $this->assign->duedate);
}
if ($this->assign->cutoffdate) {
return min($timedue, $this->assign->cutoffdate);
}
return $timedue;
}
}
@@ -0,0 +1,174 @@
<?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/>.
/**
* Output the user submission actionbar for this activity.
*
* @package mod_assign
* @copyright 2021 Adrian Greeve <adrian@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign\output;
use templatable;
use renderable;
use moodle_url;
use help_icon;
use single_button;
use stdClass;
/**
* Output the user submission actionbar for this activity.
*
* @package mod_assign
* @copyright 2021 Adrian Greeve <adrian@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class user_submission_actionmenu implements templatable, renderable {
/** @var int The course module ID. */
protected $cmid;
/** @var bool Whether to show the submit button. */
protected $showsubmit;
/** @var bool Whether to show the edit button. */
protected $showedit;
/** @var stdClass A submission for this activity. */
protected $submission;
/** @var stdClass A team submission for this activity. */
protected $teamsubmission;
/** @var int The time limit for the submission. 0 = no time limit. */
protected $timelimit;
/**
* Constructor for this object.
*
* @param int $cmid The course module ID.
* @param bool $showsubmit Whether to show the submit button.
* @param bool $showedit Whether to show the edit button.
* @param stdClass|null $submission A submission for this activity.
* @param stdClass|null $teamsubmission A team submission for this activity.
* @param int $timelimit The time limit for completing this activity.
*/
public function __construct(int $cmid, bool $showsubmit, bool $showedit, stdClass $submission = null,
stdClass $teamsubmission = null, int $timelimit = 0) {
$this->cmid = $cmid;
$this->showsubmit = $showsubmit;
$this->showedit = $showedit;
$this->submission = $submission;
$this->teamsubmission = $teamsubmission;
$this->timelimit = $timelimit;
}
/**
* Get the submission status.
*
* @return string The status of the submission.
*/
protected function get_current_status(): string {
if (!is_null($this->teamsubmission) && isset($this->teamsubmission->status)) {
return $this->teamsubmission->status;
} else if (!empty((array)$this->submission)) {
return $this->submission->status;
} else {
return ASSIGN_SUBMISSION_STATUS_NEW;
}
}
/**
* Export the submission buttons for the page.
*
* @param \renderer_base $output renderer base output.
* @return array The data to be rendered.
*/
public function export_for_template(\renderer_base $output): array {
$data = ['edit' => false, 'submit' => false, 'remove' => false, 'previoussubmission' => false];
if ($this->showedit) {
$url = new moodle_url('/mod/assign/view.php', ['id' => $this->cmid, 'action' => 'editsubmission']);
$button = new single_button($url, get_string('editsubmission', 'mod_assign'), 'get');
$data['edit'] = [
'button' => $button->export_for_template($output),
];
$status = $this->get_current_status();
if ($status !== ASSIGN_SUBMISSION_STATUS_NEW && $status !== ASSIGN_SUBMISSION_STATUS_REOPENED) {
$url = new moodle_url('/mod/assign/view.php', ['id' => $this->cmid, 'action' => 'removesubmissionconfirm']);
$button = new single_button($url, get_string('removesubmission', 'mod_assign'), 'get');
$data['remove'] = ['button' => $button->export_for_template($output)];
}
if ($status === ASSIGN_SUBMISSION_STATUS_REOPENED) {
$params = ['id' => $this->cmid, 'action' => 'editprevioussubmission', 'sesskey' => sesskey()];
$url = new moodle_url('/mod/assign/view.php', $params);
$button = new single_button($url, get_string('addnewattemptfromprevious', 'mod_assign'), 'get');
$help = new help_icon('addnewattemptfromprevious', 'mod_assign');
$data['previoussubmission'] = [
'button' => $button->export_for_template($output),
'help' => $help->export_for_template($output)
];
$url = new moodle_url('/mod/assign/view.php', ['id' => $this->cmid, 'action' => 'editsubmission']);
$newattemptbutton = new single_button(
$url,
get_string('addnewattempt', 'mod_assign'),
'get',
single_button::BUTTON_PRIMARY
);
$newattempthelp = new help_icon('addnewattempt', 'mod_assign');
$data['edit']['button'] = $newattemptbutton->export_for_template($output);
$data['edit']['help'] = $newattempthelp->export_for_template($output);
}
if ($status === ASSIGN_SUBMISSION_STATUS_NEW) {
$timelimitenabled = get_config('assign', 'enabletimelimit');
if ($timelimitenabled && $this->timelimit && empty($this->submission->timestarted)) {
$confirmation = new \confirm_action(
get_string('confirmstart', 'assign', format_time($this->timelimit)),
null,
get_string('beginassignment', 'assign')
);
$urlparams = array('id' => $this->cmid, 'action' => 'editsubmission');
$beginbutton = new \action_link(
new moodle_url('/mod/assign/view.php', $urlparams),
get_string('beginassignment', 'assign'),
$confirmation,
['class' => 'btn btn-primary']
);
$data['edit']['button'] = $beginbutton->export_for_template($output);
$data['edit']['begin'] = true;
$data['edit']['help'] = '';
} else {
$newattemptbutton = new single_button(
$url,
get_string('addsubmission', 'mod_assign'),
'get',
single_button::BUTTON_PRIMARY
);
$data['edit']['button'] = $newattemptbutton->export_for_template($output);
$data['edit']['help'] = '';
}
}
}
if ($this->showsubmit) {
$url = new moodle_url('/mod/assign/view.php', ['id' => $this->cmid, 'action' => 'submit']);
$button = new single_button($url, get_string('submitassignment', 'mod_assign'), 'get', single_button::BUTTON_PRIMARY);
$help = new help_icon('submitassignment', 'mod_assign');
$data['submit'] = [
'button' => $button->export_for_template($output),
'help' => $help->export_for_template($output)
];
}
return $data;
}
}
@@ -0,0 +1,150 @@
<?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/>.
namespace mod_assign\plugininfo;
use core\plugininfo\base;
use core_plugin_manager;
use moodle_url;
/**
* Assign feedback subplugin info class.
*
* @package mod_assign
* @copyright 2013 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class assignfeedback extends base {
public static function plugintype_supports_disabling(): bool {
return true;
}
/**
* Finds all enabled plugins, the result may include missing plugins.
* @return array|null of enabled plugins $pluginname=>$pluginname, null means unknown
*/
public static function get_enabled_plugins() {
global $DB;
$plugins = core_plugin_manager::instance()->get_installed_plugins('assignfeedback');
if (!$plugins) {
return array();
}
$installed = array();
foreach ($plugins as $plugin => $version) {
$installed[] = 'assignfeedback_'.$plugin;
}
list($installed, $params) = $DB->get_in_or_equal($installed, SQL_PARAMS_NAMED);
$disabled = $DB->get_records_select('config_plugins', "plugin $installed AND name = 'disabled'", $params, 'plugin ASC');
foreach ($disabled as $conf) {
if (empty($conf->value)) {
continue;
}
list($type, $name) = explode('_', $conf->plugin, 2);
unset($plugins[$name]);
}
$enabled = array();
foreach ($plugins as $plugin => $version) {
$enabled[$plugin] = $plugin;
}
return $enabled;
}
public static function enable_plugin(string $pluginname, int $enabled): bool {
$haschanged = false;
$plugin = 'assignfeedback_' . $pluginname;
$oldvalue = get_config($plugin, 'disabled');
$disabled = !$enabled;
// Only set value if there is no config setting or if the value is different from the previous one.
if ($oldvalue === false || ((bool) $oldvalue != $disabled)) {
set_config('disabled', $disabled, $plugin);
$haschanged = true;
add_to_config_log('disabled', $oldvalue, $disabled, $plugin);
\core_plugin_manager::reset_caches();
}
return $haschanged;
}
public function is_uninstall_allowed() {
return true;
}
/**
* Return URL used for management of plugins of this type.
* @return moodle_url
*/
public static function get_manage_url() {
return new moodle_url('/mod/assign/adminmanageplugins.php', array('subtype'=>'assignfeedback'));
}
/**
* Pre-uninstall hook.
* @private
*/
public function uninstall_cleanup() {
global $DB;
$DB->delete_records('assign_plugin_config', array('plugin'=>$this->name, 'subtype'=>'assignfeedback'));
parent::uninstall_cleanup();
}
public function get_settings_section_name() {
return $this->type . '_' . $this->name;
}
/**
* Loads plugin settings to the settings tree
*
* This function usually includes settings.php file in plugins folder.
* Alternatively it can create a link to some settings page (instance of admin_externalpage)
*
* @param \part_of_admin_tree $adminroot
* @param string $parentnodename
* @param bool $hassiteconfig whether the current user has moodle/site:config capability
*/
public function load_settings(\part_of_admin_tree $adminroot, $parentnodename, $hassiteconfig) {
global $CFG, $USER, $DB, $OUTPUT, $PAGE; // In case settings.php wants to refer to them.
$ADMIN = $adminroot; // May be used in settings.php.
$plugininfo = $this; // Also can be used inside settings.php.
if (!$this->is_installed_and_upgraded()) {
return;
}
if (!$hassiteconfig or !file_exists($this->full_path('settings.php'))) {
return;
}
$section = $this->get_settings_section_name();
$settings = new \admin_settingpage($section, $this->displayname, 'moodle/site:config', $this->is_enabled() === false);
if ($adminroot->fulltree) {
$shortsubtype = substr($this->type, strlen('assign'));
include($this->full_path('settings.php'));
}
$adminroot->add($this->type . 'plugins', $settings);
}
}
@@ -0,0 +1,150 @@
<?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/>.
namespace mod_assign\plugininfo;
use core\plugininfo\base;
use core_plugin_manager;
use moodle_url;
/**
* Assign submission subplugin info class.
*
* @package mod_assign
* @copyright 2013 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class assignsubmission extends base {
public static function plugintype_supports_disabling(): bool {
return true;
}
/**
* Finds all enabled plugins, the result may include missing plugins.
* @return array|null of enabled plugins $pluginname=>$pluginname, null means unknown
*/
public static function get_enabled_plugins() {
global $DB;
$plugins = core_plugin_manager::instance()->get_installed_plugins('assignsubmission');
if (!$plugins) {
return array();
}
$installed = array();
foreach ($plugins as $plugin => $version) {
$installed[] = 'assignsubmission_'.$plugin;
}
list($installed, $params) = $DB->get_in_or_equal($installed, SQL_PARAMS_NAMED);
$disabled = $DB->get_records_select('config_plugins', "plugin $installed AND name = 'disabled'", $params, 'plugin ASC');
foreach ($disabled as $conf) {
if (empty($conf->value)) {
continue;
}
list($type, $name) = explode('_', $conf->plugin, 2);
unset($plugins[$name]);
}
$enabled = array();
foreach ($plugins as $plugin => $version) {
$enabled[$plugin] = $plugin;
}
return $enabled;
}
public static function enable_plugin(string $pluginname, int $enabled): bool {
$haschanged = false;
$plugin = 'assignsubmission_' . $pluginname;
$oldvalue = get_config($plugin, 'disabled');
$disabled = !$enabled;
// Only set value if there is no config setting or if the value is different from the previous one.
if ($oldvalue === false || ((bool) $oldvalue != $disabled)) {
set_config('disabled', $disabled, $plugin);
$haschanged = true;
add_to_config_log('disabled', $oldvalue, $disabled, $plugin);
\core_plugin_manager::reset_caches();
}
return $haschanged;
}
public function is_uninstall_allowed() {
return true;
}
/**
* Return URL used for management of plugins of this type.
* @return moodle_url
*/
public static function get_manage_url() {
return new moodle_url('/mod/assign/adminmanageplugins.php', array('subtype'=>'assignsubmission'));
}
/**
* Pre-uninstall hook.
* @private
*/
public function uninstall_cleanup() {
global $DB;
$DB->delete_records('assign_plugin_config', array('plugin'=>$this->name, 'subtype'=>'assignsubmission'));
parent::uninstall_cleanup();
}
public function get_settings_section_name() {
return $this->type . '_' . $this->name;
}
/**
* Loads plugin settings to the settings tree
*
* This function usually includes settings.php file in plugins folder.
* Alternatively it can create a link to some settings page (instance of admin_externalpage)
*
* @param \part_of_admin_tree $adminroot
* @param string $parentnodename
* @param bool $hassiteconfig whether the current user has moodle/site:config capability
*/
public function load_settings(\part_of_admin_tree $adminroot, $parentnodename, $hassiteconfig) {
global $CFG, $USER, $DB, $OUTPUT, $PAGE; // In case settings.php wants to refer to them.
$ADMIN = $adminroot; // May be used in settings.php.
$plugininfo = $this; // Also can be used inside settings.php.
if (!$this->is_installed_and_upgraded()) {
return;
}
if (!$hassiteconfig or !file_exists($this->full_path('settings.php'))) {
return;
}
$section = $this->get_settings_section_name();
$settings = new \admin_settingpage($section, $this->displayname, 'moodle/site:config', $this->is_enabled() === false);
if ($adminroot->fulltree) {
$shortsubtype = substr($this->type, strlen('assign'));
include($this->full_path('settings.php'));
}
$adminroot->add($this->type . 'plugins', $settings);
}
}
@@ -0,0 +1,206 @@
<?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/>.
/**
* This file contains the mod_assign assign_plugin_request_data class
*
* For assign plugin privacy data to fulfill requests.
*
* @package mod_assign
* @copyright 2018 Adrian Greeve <adrian@moodle.com>
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign\privacy;
defined('MOODLE_INTERNAL') || die();
/**
* An object for fulfilling an assign plugin data request.
*
* @copyright 2018 Adrian Greeve <adrian@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class assign_plugin_request_data {
/** @var \context The context that we are dealing with. */
protected $context;
/** @var object For submisisons the submission object, for feedback the grade object. */
protected $pluginobject;
/** @var array The path or location that we are exporting data to. */
protected $subcontext;
/** @var object If set then only export data related directly to this user. */
protected $user;
/** @var array The user IDs of the users that will be affected. */
protected $userids;
/** @var array The submissions related to the users added. */
protected $submissions = [];
/** @var array The grades related to the users added. */
protected $grades = [];
/** @var \assign The assign object */
protected $assign;
/**
* Object creator for assign plugin request data.
*
* @param \context $context Context object.
* @param \stdClass $pluginobject The grade object.
* @param array $subcontext Directory / file location.
* @param \stdClass $user The user object.
* @param \assign $assign The assign object.
*/
public function __construct(\context $context, \assign $assign, \stdClass $pluginobject = null, array $subcontext = [],
\stdClass $user = null) {
$this->context = $context;
$this->pluginobject = $pluginobject;
$this->subcontext = $subcontext;
$this->user = $user;
$this->assign = $assign;
}
/**
* Method for adding an array of user IDs. This will do a query to populate the submissions and grades
* for these users.
*
* @param array $userids User IDs to do something with.
*/
public function set_userids(array $userids) {
$this->userids = $userids;
}
/**
* Getter for this attribute.
*
* @return \context Context
*/
public function get_context() {
return $this->context;
}
/**
* Getter for this attribute.
*
* @return object The assign plugin object
*/
public function get_pluginobject() {
return $this->pluginobject;
}
/**
* Getter for this attribute.
*
* @return array The location (path) that this data is being writter to.
*/
public function get_subcontext() {
return $this->subcontext;
}
/**
* Getter for this attribute.
*
* @return object The user id. If set then only information directly related to this user ID will be returned.
*/
public function get_user() {
return $this->user;
}
/**
* Getter for this attribute.
*
* @return \assign The assign object.
*/
public function get_assign() {
return $this->assign;
}
/**
* A method to conveniently fetch the assign id.
*
* @return int The assign id.
*/
public function get_assignid() {
return $this->assign->get_instance()->id;
}
/**
* Get all of the user IDs
*
* @return array User IDs
*/
public function get_userids() {
return $this->userids;
}
/**
* Returns all of the submission IDs
*
* @return array submission IDs
*/
public function get_submissionids() {
return array_keys($this->submissions);
}
/**
* Returns the submissions related to the user IDs
*
* @return array User submissions.
*/
public function get_submissions() {
return $this->submissions;
}
/**
* Returns the grade IDs related to the user IDs
*
* @return array User grade IDs.
*/
public function get_gradeids() {
return array_keys($this->grades);
}
/**
* Returns the grades related to the user IDs
*
* @return array User grades.
*/
public function get_grades() {
return $this->grades;
}
/**
* Fetches all of the submissions and grades related to the User IDs provided. Use get_grades, get_submissions etc to
* retrieve this information.
*/
public function populate_submissions_and_grades() {
global $DB;
if (empty($this->get_userids())) {
throw new \coding_exception('Please use set_userids() before calling this method.');
}
list($sql, $params) = $DB->get_in_or_equal($this->get_userids(), SQL_PARAMS_NAMED);
$params['assign'] = $this->get_assign()->get_instance()->id;
$this->submissions = $DB->get_records_select('assign_submission', "assignment = :assign AND userid $sql", $params);
$this->grades = $DB->get_records_select('assign_grades', "assignment = :assign AND userid $sql", $params);
}
}
@@ -0,0 +1,87 @@
<?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/>.
/**
* This file contains the assignfeedback_provider interface.
*
* Assignment Sub plugins should implement this if they store personal information.
*
* @package mod_assign
* @copyright 2018 Adrian Greeve <adrian@moodle.com>
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign\privacy;
use core_privacy\local\request\contextlist;
defined('MOODLE_INTERNAL') || die();
interface assignfeedback_provider extends \core_privacy\local\request\plugin\subplugin_provider {
/**
* Retrieves the contextids associated with the provided userid for this subplugin.
* NOTE if your subplugin must have an entry in the assign_grade table to work, then this
* method can be empty.
*
* @param int $userid The user ID to get context IDs for.
* @param \core_privacy\local\request\contextlist $contextlist Use add_from_sql with this object to add your context IDs.
*/
public static function get_context_for_userid_within_feedback(int $userid, contextlist $contextlist);
/**
* Returns student user ids related to the provided teacher ID. If an entry must be present in the assign_grade table for
* your plugin to work then there is no need to fill in this method. If you filled in get_context_for_userid_within_feedback()
* then you probably have to fill this in as well.
*
* @param useridlist $useridlist A list of user IDs of students graded by this user.
*/
public static function get_student_user_ids(useridlist $useridlist);
/**
* Export feedback data with the available grade and userid information provided.
* assign_plugin_request_data contains:
* - context
* - grade object
* - current path (subcontext)
* - user object
*
* @param assign_plugin_request_data $exportdata Contains data to help export the user information.
*/
public static function export_feedback_user_data(assign_plugin_request_data $exportdata);
/**
* Any call to this method should delete all user data for the context defined in the deletion_criteria.
* assign_plugin_request_data contains:
* - context
* - assign object
*
* @param assign_plugin_request_data $requestdata Data useful for deleting user data from this sub-plugin.
*/
public static function delete_feedback_for_context(assign_plugin_request_data $requestdata);
/**
* Calling this function should delete all user data associated with this grade.
* assign_plugin_request_data contains:
* - context
* - grade object
* - user object
* - assign object
*
* @param assign_plugin_request_data $requestdata Data useful for deleting user data.
*/
public static function delete_feedback_for_grade(assign_plugin_request_data $requestdata);
}
@@ -0,0 +1,55 @@
<?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/>.
/**
* This file contains the assignfeedback_user_provider interface.
*
* Assignment Sub plugins should implement this if they store personal information and can retrieve a userid.
*
* @package mod_assign
* @copyright 2018 Adrian Greeve <adrian@moodle.com>
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign\privacy;
defined('MOODLE_INTERNAL') || die();
interface assignfeedback_user_provider extends
\core_privacy\local\request\plugin\subplugin_provider,
\core_privacy\local\request\shared_userlist_provider
{
/**
* If you have tables that contain userids and you can generate entries in your tables without creating an
* entry in the assign_grades table then please fill in this method.
*
* @param \core_privacy\local\request\userlist $userlist The userlist object
*/
public static function get_userids_from_context(\core_privacy\local\request\userlist $userlist);
/**
* Deletes all feedback for the grade ids / userids provided in a context.
* assign_plugin_request_data contains:
* - context
* - assign object
* - grade ids (pluginids)
* - user ids
* @param assign_plugin_request_data $deletedata A class that contains the relevant information required for deletion.
*/
public static function delete_feedback_for_grades(assign_plugin_request_data $deletedata);
}
@@ -0,0 +1,88 @@
<?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/>.
/**
* This file contains the assignsubmission_provider interface.
*
* Assignment Sub plugins should implement this if they store personal information.
*
* @package mod_assign
* @copyright 2018 Adrian Greeve <adrian@moodle.com>
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign\privacy;
use core_privacy\local\request\contextlist;
defined('MOODLE_INTERNAL') || die();
interface assignsubmission_provider extends \core_privacy\local\request\plugin\subplugin_provider {
/**
* Retrieves the contextids associated with the provided userid for this subplugin.
* NOTE if your subplugin must have an entry in the assign_submission table to work, then this
* method can be empty.
*
* @param int $userid The user ID to get context IDs for.
* @param \core_privacy\local\request\contextlist $contextlist Use add_from_sql with this object to add your context IDs.
*/
public static function get_context_for_userid_within_submission(int $userid, contextlist $contextlist);
/**
* Returns student user ids related to the provided teacher ID. If it is possible that a student ID will not be returned by
* the sql query in \mod_assign\privacy\provider::find_grader_info() Then you need to provide some sql to retrive those
* student IDs. This is highly likely if you had to fill in get_context_for_userid_within_submission above.
*
* @param useridlist $useridlist A user ID list object that you can append your user IDs to.
*/
public static function get_student_user_ids(useridlist $useridlist);
/**
* This method is used to export any user data this sub-plugin has using the assign_plugin_request_data object to get the
* context and userid.
* assign_plugin_request_data contains:
* - context
* - submission object
* - current path (subcontext)
* - user object
*
* @param assign_plugin_request_data $exportdata Information to use to export user data for this sub-plugin.
*/
public static function export_submission_user_data(assign_plugin_request_data $exportdata);
/**
* Any call to this method should delete all user data for the context defined in the deletion_criteria.
* assign_plugin_request_data contains:
* - context
* - assign object
*
* @param assign_plugin_request_data $requestdata Information to use to delete user data for this submission.
*/
public static function delete_submission_for_context(assign_plugin_request_data $requestdata);
/**
* A call to this method should delete user data (where practicle) from the userid and context.
* assign_plugin_request_data contains:
* - context
* - submission object
* - user object
* - assign object
*
* @param assign_plugin_request_data $exportdata Details about the user and context to focus the deletion.
*/
public static function delete_submission_for_userid(assign_plugin_request_data $exportdata);
}
@@ -0,0 +1,57 @@
<?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/>.
/**
* This file contains the assignsubmission_user_provider interface.
*
* Assignment Sub plugins should implement this if they store personal information and can retrieve a userid.
*
* @package mod_assign
* @copyright 2018 Adrian Greeve <adrian@moodle.com>
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign\privacy;
use core_privacy\local\request\userlist;
defined('MOODLE_INTERNAL') || die();
interface assignsubmission_user_provider extends
\core_privacy\local\request\plugin\subplugin_provider,
\core_privacy\local\request\shared_userlist_provider
{
/**
* If you have tables that contain userids and you can generate entries in your tables without creating an
* entry in the assign_submission table then please fill in this method.
*
* @param userlist $userlist The userlist object
*/
public static function get_userids_from_context(userlist $userlist);
/**
* Deletes all submissions for the submission ids / userids provided in a context.
* assign_plugin_request_data contains:
* - context
* - assign object
* - submission ids (pluginids)
* - user ids
* @param assign_plugin_request_data $deletedata A class that contains the relevant information required for deletion.
*/
public static function delete_submissions(assign_plugin_request_data $deletedata);
}
@@ -0,0 +1,100 @@
<?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/>.
/**
* This file contains the polyfill to allow a plugin to operate with Moodle 3.3 up.
*
* @package mod_assign
* @copyright 2018 Adrian Greeve <adrian@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign\privacy;
use core_privacy\local\request\contextlist;
defined('MOODLE_INTERNAL') || die();
/**
* The trait used to provide backwards compatability for third-party plugins.
*
* @copyright 2018 Adrian Greeve <adrian@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
trait feedback_legacy_polyfill {
/**
* Retrieves the contextids associated with the provided userid for this subplugin.
* NOTE if your subplugin must have an entry in the assign_grade table to work, then this
* method can be empty.
*
* @param int $userid The user ID to get context IDs for.
* @param \core_privacy\local\request\contextlist $contextlist Use add_from_sql with this object to add your context IDs.
*/
public static function get_context_for_userid_within_feedback(int $userid, contextlist $contextlist) {
return static::_get_context_for_userid_within_feedback($userid, $contextlist);
}
/**
* Returns student user ids related to the provided teacher ID. If an entry must be present in the assign_grade table for
* your plugin to work then there is no need to fill in this method. If you filled in get_context_for_userid_within_feedback()
* then you probably have to fill this in as well.
*
* @param useridlist $useridlist A list of user IDs of students graded by this user.
*/
public static function get_student_user_ids(useridlist $useridlist) {
return static::_get_student_user_ids($useridlist);
}
/**
* Export feedback data with the available grade and userid information provided.
* assign_plugin_request_data contains:
* - context
* - grade object
* - current path (subcontext)
* - user object
*
* @param assign_plugin_request_data $exportdata Contains data to help export the user information.
*/
public static function export_feedback_user_data(assign_plugin_request_data $exportdata) {
return static::_export_feedback_user_data($exportdata);
}
/**
* Any call to this method should delete all user data for the context defined in the deletion_criteria.
* assign_plugin_request_data contains:
* - context
* - assign object
*
* @param assign_plugin_request_data $requestdata Data useful for deleting user data from this sub-plugin.
*/
public static function delete_feedback_for_context(assign_plugin_request_data $requestdata) {
return static::_delete_feedback_for_context($requestdata);
}
/**
* Calling this function should delete all user data associated with this grade.
* assign_plugin_request_data contains:
* - context
* - grade object
* - user object
* - assign object
*
* @param assign_plugin_request_data $requestdata Data useful for deleting user data.
*/
public static function delete_feedback_for_grade(assign_plugin_request_data $requestdata) {
return static::_delete_feedback_for_grade($requestdata);
}
}
+677
View File
@@ -0,0 +1,677 @@
<?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 mod_assign
* @copyright 2018 Adrian Greeve <adrian@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign\privacy;
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/mod/assign/locallib.php');
use \core_privacy\local\metadata\collection;
use \core_privacy\local\request\contextlist;
use \core_privacy\local\request\writer;
use \core_privacy\local\request\approved_contextlist;
use \core_privacy\local\request\transform;
use \core_privacy\local\request\helper;
use \core_privacy\local\request\userlist;
use \core_privacy\local\request\approved_userlist;
use \core_privacy\manager;
/**
* Privacy class for requesting user data.
*
* @package mod_assign
* @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,
\core_privacy\local\request\user_preference_provider,
\core_privacy\local\request\core_userlist_provider {
/** Interface for all assign submission sub-plugins. */
const ASSIGNSUBMISSION_INTERFACE = 'mod_assign\privacy\assignsubmission_provider';
/** Interface for all assign submission sub-plugins. This allows for deletion of users with a context. */
const ASSIGNSUBMISSION_USER_INTERFACE = 'mod_assign\privacy\assignsubmission_user_provider';
/** Interface for all assign feedback sub-plugins. This allows for deletion of users with a context. */
const ASSIGNFEEDBACK_USER_INTERFACE = 'mod_assign\privacy\assignfeedback_user_provider';
/** Interface for all assign feedback sub-plugins. */
const ASSIGNFEEDBACK_INTERFACE = 'mod_assign\privacy\assignfeedback_provider';
/**
* Provides meta data that is stored about a user with mod_assign
*
* @param collection $collection A collection of meta data items to be added to.
* @return collection Returns the collection of metadata.
*/
public static function get_metadata(collection $collection): collection {
$assigngrades = [
'userid' => 'privacy:metadata:userid',
'timecreated' => 'privacy:metadata:timecreated',
'timemodified' => 'timemodified',
'grader' => 'privacy:metadata:grader',
'grade' => 'privacy:metadata:grade',
'attemptnumber' => 'attemptnumber'
];
$assignoverrides = [
'groupid' => 'privacy:metadata:groupid',
'userid' => 'privacy:metadata:userid',
'allowsubmissionsfromdate' => 'allowsubmissionsfromdate',
'duedate' => 'duedate',
'cutoffdate' => 'cutoffdate'
];
$assignsubmission = [
'userid' => 'privacy:metadata:userid',
'timecreated' => 'privacy:metadata:timecreated',
'timemodified' => 'timemodified',
'timestarted' => 'privacy:metadata:timestarted',
'status' => 'gradingstatus',
'groupid' => 'privacy:metadata:groupid',
'attemptnumber' => 'attemptnumber',
'latest' => 'privacy:metadata:latest'
];
$assignuserflags = [
'userid' => 'privacy:metadata:userid',
'assignment' => 'privacy:metadata:assignmentid',
'locked' => 'locksubmissions',
'mailed' => 'privacy:metadata:mailed',
'extensionduedate' => 'extensionduedate',
'workflowstate' => 'markingworkflowstate',
'allocatedmarker' => 'allocatedmarker'
];
$assignusermapping = [
'assignment' => 'privacy:metadata:assignmentid',
'userid' => 'privacy:metadata:userid'
];
$collection->add_database_table('assign_grades', $assigngrades, 'privacy:metadata:assigngrades');
$collection->add_database_table('assign_overrides', $assignoverrides, 'privacy:metadata:assignoverrides');
$collection->add_database_table('assign_submission', $assignsubmission, 'privacy:metadata:assignsubmissiondetail');
$collection->add_database_table('assign_user_flags', $assignuserflags, 'privacy:metadata:assignuserflags');
$collection->add_database_table('assign_user_mapping', $assignusermapping, 'privacy:metadata:assignusermapping');
$collection->add_user_preference('assign_perpage', 'privacy:metadata:assignperpage');
$collection->add_user_preference('assign_filter', 'privacy:metadata:assignfilter');
$collection->add_user_preference('assign_markerfilter', 'privacy:metadata:assignmarkerfilter');
$collection->add_user_preference('assign_workflowfilter', 'privacy:metadata:assignworkflowfilter');
$collection->add_user_preference('assign_quickgrading', 'privacy:metadata:assignquickgrading');
$collection->add_user_preference('assign_downloadasfolders', 'privacy:metadata:assigndownloadasfolders');
// Link to subplugins.
$collection->add_plugintype_link('assignsubmission', [],'privacy:metadata:assignsubmissionpluginsummary');
$collection->add_plugintype_link('assignfeedback', [], 'privacy:metadata:assignfeedbackpluginsummary');
$collection->add_subsystem_link('core_message', [], 'privacy:metadata:assignmessageexplanation');
return $collection;
}
/**
* Returns all of the contexts that has information relating to the userid.
*
* @param int $userid The user ID.
* @return contextlist an object with the contexts related to a userid.
*/
public static function get_contexts_for_userid(int $userid): contextlist {
$params = ['modulename' => 'assign',
'contextlevel' => CONTEXT_MODULE,
'userid' => $userid,
'graderid' => $userid,
'aouserid' => $userid,
'asnuserid' => $userid,
'aufuserid' => $userid,
'aumuserid' => $userid];
$sql = "SELECT ctx.id
FROM {course_modules} cm
JOIN {modules} m ON cm.module = m.id AND m.name = :modulename
JOIN {assign} a ON cm.instance = a.id
JOIN {context} ctx ON cm.id = ctx.instanceid AND ctx.contextlevel = :contextlevel
JOIN {assign_grades} ag ON a.id = ag.assignment AND (ag.userid = :userid OR ag.grader = :graderid)";
$contextlist = new contextlist();
$contextlist->add_from_sql($sql, $params);
$sql = "SELECT ctx.id
FROM {course_modules} cm
JOIN {modules} m ON cm.module = m.id AND m.name = :modulename
JOIN {assign} a ON cm.instance = a.id
JOIN {context} ctx ON cm.id = ctx.instanceid AND ctx.contextlevel = :contextlevel
JOIN {assign_overrides} ao ON a.id = ao.assignid
WHERE ao.userid = :aouserid";
$contextlist->add_from_sql($sql, $params);
$sql = "SELECT ctx.id
FROM {course_modules} cm
JOIN {modules} m ON cm.module = m.id AND m.name = :modulename
JOIN {assign} a ON cm.instance = a.id
JOIN {context} ctx ON cm.id = ctx.instanceid AND ctx.contextlevel = :contextlevel
JOIN {assign_submission} asn ON a.id = asn.assignment
WHERE asn.userid = :asnuserid";
$contextlist->add_from_sql($sql, $params);
$sql = "SELECT ctx.id
FROM {course_modules} cm
JOIN {modules} m ON cm.module = m.id AND m.name = :modulename
JOIN {assign} a ON cm.instance = a.id
JOIN {context} ctx ON cm.id = ctx.instanceid AND ctx.contextlevel = :contextlevel
JOIN {assign_user_flags} auf ON a.id = auf.assignment
WHERE auf.userid = :aufuserid";
$contextlist->add_from_sql($sql, $params);
$sql = "SELECT ctx.id
FROM {course_modules} cm
JOIN {modules} m ON cm.module = m.id AND m.name = :modulename
JOIN {assign} a ON cm.instance = a.id
JOIN {context} ctx ON cm.id = ctx.instanceid AND ctx.contextlevel = :contextlevel
JOIN {assign_user_mapping} aum ON a.id = aum.assignment
WHERE aum.userid = :aumuserid";
$contextlist->add_from_sql($sql, $params);
manager::plugintype_class_callback('assignfeedback', self::ASSIGNFEEDBACK_INTERFACE,
'get_context_for_userid_within_feedback', [$userid, $contextlist]);
manager::plugintype_class_callback('assignsubmission', self::ASSIGNSUBMISSION_INTERFACE,
'get_context_for_userid_within_submission', [$userid, $contextlist]);
return $contextlist;
}
/**
* Get the list of users who have data within a context.
*
* @param userlist $userlist The userlist containing the list of users who have data in this context/plugin combination.
*/
public static function get_users_in_context(userlist $userlist) {
$context = $userlist->get_context();
if ($context->contextlevel != CONTEXT_MODULE) {
return;
}
$params = [
'modulename' => 'assign',
'contextid' => $context->id,
'contextlevel' => CONTEXT_MODULE
];
$sql = "SELECT g.userid, g.grader
FROM {context} ctx
JOIN {course_modules} cm ON cm.id = ctx.instanceid
JOIN {modules} m ON m.id = cm.module AND m.name = :modulename
JOIN {assign} a ON a.id = cm.instance
JOIN {assign_grades} g ON a.id = g.assignment
WHERE ctx.id = :contextid AND ctx.contextlevel = :contextlevel";
$userlist->add_from_sql('userid', $sql, $params);
$userlist->add_from_sql('grader', $sql, $params);
$sql = "SELECT o.userid
FROM {context} ctx
JOIN {course_modules} cm ON cm.id = ctx.instanceid
JOIN {modules} m ON m.id = cm.module AND m.name = :modulename
JOIN {assign} a ON a.id = cm.instance
JOIN {assign_overrides} o ON a.id = o.assignid
WHERE ctx.id = :contextid AND ctx.contextlevel = :contextlevel";
$userlist->add_from_sql('userid', $sql, $params);
$sql = "SELECT s.userid
FROM {context} ctx
JOIN {course_modules} cm ON cm.id = ctx.instanceid
JOIN {modules} m ON m.id = cm.module AND m.name = :modulename
JOIN {assign} a ON a.id = cm.instance
JOIN {assign_submission} s ON a.id = s.assignment
WHERE ctx.id = :contextid AND ctx.contextlevel = :contextlevel";
$userlist->add_from_sql('userid', $sql, $params);
$sql = "SELECT uf.userid
FROM {context} ctx
JOIN {course_modules} cm ON cm.id = ctx.instanceid
JOIN {modules} m ON m.id = cm.module AND m.name = :modulename
JOIN {assign} a ON a.id = cm.instance
JOIN {assign_user_flags} uf ON a.id = uf.assignment
WHERE ctx.id = :contextid AND ctx.contextlevel = :contextlevel";
$userlist->add_from_sql('userid', $sql, $params);
$sql = "SELECT um.userid
FROM {context} ctx
JOIN {course_modules} cm ON cm.id = ctx.instanceid
JOIN {modules} m ON m.id = cm.module AND m.name = :modulename
JOIN {assign} a ON a.id = cm.instance
JOIN {assign_user_mapping} um ON a.id = um.assignment
WHERE ctx.id = :contextid AND ctx.contextlevel = :contextlevel";
$userlist->add_from_sql('userid', $sql, $params);
manager::plugintype_class_callback('assignsubmission', self::ASSIGNSUBMISSION_USER_INTERFACE,
'get_userids_from_context', [$userlist]);
manager::plugintype_class_callback('assignfeedback', self::ASSIGNFEEDBACK_USER_INTERFACE,
'get_userids_from_context', [$userlist]);
}
/**
* Write out the user data filtered by contexts.
*
* @param approved_contextlist $contextlist contexts that we are writing data out from.
*/
public static function export_user_data(approved_contextlist $contextlist) {
foreach ($contextlist->get_contexts() as $context) {
// Check that the context is a module context.
if ($context->contextlevel != CONTEXT_MODULE) {
continue;
}
$user = $contextlist->get_user();
$assigndata = helper::get_context_data($context, $user);
helper::export_context_files($context, $user);
writer::with_context($context)->export_data([], $assigndata);
$assign = new \assign($context, null, null);
// I need to find out if I'm a student or a teacher.
if ($userids = self::get_graded_users($user->id, $assign)) {
// Return teacher info.
$currentpath = [get_string('privacy:studentpath', 'mod_assign')];
foreach ($userids as $studentuserid) {
$studentpath = array_merge($currentpath, [$studentuserid->id]);
static::export_submission($assign, $studentuserid, $context, $studentpath, true);
}
}
static::export_overrides($context, $assign, $user);
static::export_submission($assign, $user, $context, []);
// Meta data.
self::store_assign_user_flags($context, $assign, $user->id);
if ($assign->is_blind_marking()) {
$uniqueid = $assign->get_uniqueid_for_user_static($assign->get_instance()->id, $contextlist->get_user()->id);
if ($uniqueid) {
writer::with_context($context)
->export_metadata([get_string('blindmarking', 'mod_assign')], 'blindmarkingid', $uniqueid,
get_string('privacy:blindmarkingidentifier', 'mod_assign'));
}
}
}
}
/**
* Delete all use data which matches the specified context.
*
* @param \context $context The module context.
*/
public static function delete_data_for_all_users_in_context(\context $context) {
global $DB;
if ($context->contextlevel == CONTEXT_MODULE) {
$cm = get_coursemodule_from_id('assign', $context->instanceid);
if ($cm) {
// Get the assignment related to this context.
$assign = new \assign($context, null, null);
// What to do first... Get sub plugins to delete their stuff.
$requestdata = new assign_plugin_request_data($context, $assign);
manager::plugintype_class_callback('assignsubmission', self::ASSIGNSUBMISSION_INTERFACE,
'delete_submission_for_context', [$requestdata]);
$requestdata = new assign_plugin_request_data($context, $assign);
manager::plugintype_class_callback('assignfeedback', self::ASSIGNFEEDBACK_INTERFACE,
'delete_feedback_for_context', [$requestdata]);
$DB->delete_records('assign_grades', ['assignment' => $assign->get_instance()->id]);
// Delete advanced grading information.
$gradingmanager = get_grading_manager($context, 'mod_assign', 'submissions');
$controller = $gradingmanager->get_active_controller();
if (isset($controller)) {
\core_grading\privacy\provider::delete_instance_data($context);
}
// Time to roll my own method for deleting overrides.
static::delete_overrides_for_users($assign);
$DB->delete_records('assign_submission', ['assignment' => $assign->get_instance()->id]);
$DB->delete_records('assign_user_flags', ['assignment' => $assign->get_instance()->id]);
$DB->delete_records('assign_user_mapping', ['assignment' => $assign->get_instance()->id]);
}
}
}
/**
* 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) {
global $DB;
$user = $contextlist->get_user();
foreach ($contextlist as $context) {
if ($context->contextlevel != CONTEXT_MODULE) {
continue;
}
// Get the assign object.
$assign = new \assign($context, null, null);
$assignid = $assign->get_instance()->id;
$submissions = $DB->get_records('assign_submission', ['assignment' => $assignid, 'userid' => $user->id]);
foreach ($submissions as $submission) {
$requestdata = new assign_plugin_request_data($context, $assign, $submission, [], $user);
manager::plugintype_class_callback('assignsubmission', self::ASSIGNSUBMISSION_INTERFACE,
'delete_submission_for_userid', [$requestdata]);
}
$grades = $DB->get_records('assign_grades', ['assignment' => $assignid, 'userid' => $user->id]);
$gradingmanager = get_grading_manager($context, 'mod_assign', 'submissions');
$controller = $gradingmanager->get_active_controller();
foreach ($grades as $grade) {
$requestdata = new assign_plugin_request_data($context, $assign, $grade, [], $user);
manager::plugintype_class_callback('assignfeedback', self::ASSIGNFEEDBACK_INTERFACE,
'delete_feedback_for_grade', [$requestdata]);
// Delete advanced grading information.
if (isset($controller)) {
\core_grading\privacy\provider::delete_instance_data($context, $grade->id);
}
}
static::delete_overrides_for_users($assign, [$user->id]);
$DB->delete_records('assign_user_flags', ['assignment' => $assignid, 'userid' => $user->id]);
$DB->delete_records('assign_user_mapping', ['assignment' => $assignid, 'userid' => $user->id]);
$DB->delete_records('assign_grades', ['assignment' => $assignid, 'userid' => $user->id]);
$DB->delete_records('assign_submission', ['assignment' => $assignid, 'userid' => $user->id]);
}
}
/**
* Delete multiple users within a single context.
*
* @param approved_userlist $userlist The approved context and user information to delete information for.
*/
public static function delete_data_for_users(approved_userlist $userlist) {
global $DB;
$context = $userlist->get_context();
if ($context->contextlevel != CONTEXT_MODULE) {
return;
}
$userids = $userlist->get_userids();
$assign = new \assign($context, null, null);
$assignid = $assign->get_instance()->id;
$requestdata = new assign_plugin_request_data($context, $assign);
$requestdata->set_userids($userids);
$requestdata->populate_submissions_and_grades();
manager::plugintype_class_callback('assignsubmission', self::ASSIGNSUBMISSION_USER_INTERFACE, 'delete_submissions',
[$requestdata]);
manager::plugintype_class_callback('assignfeedback', self::ASSIGNFEEDBACK_USER_INTERFACE, 'delete_feedback_for_grades',
[$requestdata]);
// Update this function to delete advanced grading information.
$gradingmanager = get_grading_manager($context, 'mod_assign', 'submissions');
$controller = $gradingmanager->get_active_controller();
if (isset($controller)) {
$gradeids = $requestdata->get_gradeids();
// Careful here, if no gradeids are provided then all data is deleted for the context.
if (!empty($gradeids)) {
\core_grading\privacy\provider::delete_data_for_instances($context, $gradeids);
}
}
static::delete_overrides_for_users($assign, $userids);
list($sql, $params) = $DB->get_in_or_equal($userids, SQL_PARAMS_NAMED);
$params['assignment'] = $assignid;
$DB->delete_records_select('assign_user_flags', "assignment = :assignment AND userid $sql", $params);
$DB->delete_records_select('assign_user_mapping', "assignment = :assignment AND userid $sql", $params);
$DB->delete_records_select('assign_grades', "assignment = :assignment AND userid $sql", $params);
$DB->delete_records_select('assign_submission', "assignment = :assignment AND userid $sql", $params);
}
/**
* Deletes assignment overrides in bulk
*
* @param \assign $assign The assignment object
* @param array $userids An array of user IDs
*/
protected static function delete_overrides_for_users(\assign $assign, array $userids = []) {
global $DB;
$assignid = $assign->get_instance()->id;
$usersql = '';
$params = ['assignid' => $assignid];
if (!empty($userids)) {
list($usersql, $userparams) = $DB->get_in_or_equal($userids, SQL_PARAMS_NAMED);
$params = array_merge($params, $userparams);
$overrides = $DB->get_records_select('assign_overrides', "assignid = :assignid AND userid $usersql", $params);
} else {
$overrides = $DB->get_records('assign_overrides', $params);
}
if (!empty($overrides)) {
$params = ['modulename' => 'assign', 'instance' => $assignid];
if (!empty($userids)) {
$params = array_merge($params, $userparams);
$DB->delete_records_select('event', "modulename = :modulename AND instance = :instance AND userid $usersql",
$params);
// Setting up for the next query.
$params = $userparams;
$usersql = "AND userid $usersql";
} else {
$DB->delete_records('event', $params);
// Setting up for the next query.
$params = [];
}
list($overridesql, $overrideparams) = $DB->get_in_or_equal(array_keys($overrides), SQL_PARAMS_NAMED);
$params = array_merge($params, $overrideparams);
$DB->delete_records_select('assign_overrides', "id $overridesql $usersql", $params);
}
}
/**
* Find out if this user has graded any users.
*
* @param int $userid The user ID (potential teacher).
* @param \assign $assign The assignment object.
* @return array If successful an array of objects with userids that this user graded, otherwise false.
*/
protected static function get_graded_users(int $userid, \assign $assign) {
$params = ['grader' => $userid, 'assignid' => $assign->get_instance()->id];
$sql = "SELECT DISTINCT userid AS id
FROM {assign_grades}
WHERE grader = :grader AND assignment = :assignid";
$useridlist = new useridlist($userid, $assign->get_instance()->id);
$useridlist->add_from_sql($sql, $params);
// Call sub-plugins to see if they have information not already collected.
manager::plugintype_class_callback('assignsubmission', self::ASSIGNSUBMISSION_INTERFACE, 'get_student_user_ids',
[$useridlist]);
manager::plugintype_class_callback('assignfeedback', self::ASSIGNFEEDBACK_INTERFACE, 'get_student_user_ids', [$useridlist]);
$userids = $useridlist->get_userids();
return ($userids) ? $userids : false;
}
/**
* Writes out various user meta data about the assignment.
*
* @param \context $context The context of this assignment.
* @param \assign $assign The assignment object.
* @param int $userid The user ID
*/
protected static function store_assign_user_flags(\context $context, \assign $assign, int $userid) {
$datatypes = ['locked' => get_string('locksubmissions', 'mod_assign'),
'mailed' => get_string('privacy:metadata:mailed', 'mod_assign'),
'extensionduedate' => get_string('extensionduedate', 'mod_assign'),
'workflowstate' => get_string('markingworkflowstate', 'mod_assign'),
'allocatedmarker' => get_string('allocatedmarker_help', 'mod_assign')];
$userflags = (array)$assign->get_user_flags($userid, false);
foreach ($datatypes as $key => $description) {
if (isset($userflags[$key]) && !empty($userflags[$key])) {
$value = $userflags[$key];
if ($key == 'locked' || $key == 'mailed') {
$value = transform::yesno($value);
} else if ($key == 'extensionduedate') {
$value = transform::datetime($value);
}
writer::with_context($context)->export_metadata([], $key, $value, $description);
}
}
}
/**
* Formats and then exports the user's grade data.
*
* @param \stdClass $grade The assign grade object
* @param \context $context The context object
* @param array $currentpath Current directory path that we are exporting to.
*/
protected static function export_grade_data(\stdClass $grade, \context $context, array $currentpath) {
$gradedata = (object)[
'timecreated' => transform::datetime($grade->timecreated),
'timemodified' => transform::datetime($grade->timemodified),
'grader' => transform::user($grade->grader),
'grade' => $grade->grade,
'attemptnumber' => ($grade->attemptnumber + 1)
];
writer::with_context($context)
->export_data(array_merge($currentpath, [get_string('privacy:gradepath', 'mod_assign')]), $gradedata);
}
/**
* Formats and then exports the user's submission data.
*
* @param \stdClass $submission The assign submission object
* @param \context $context The context object
* @param array $currentpath Current directory path that we are exporting to.
*/
protected static function export_submission_data(\stdClass $submission, \context $context, array $currentpath) {
$submissiondata = (object)[
'timecreated' => transform::datetime($submission->timecreated),
'timemodified' => transform::datetime($submission->timemodified),
'timestarted' => transform::datetime($submission->timestarted),
'status' => get_string('submissionstatus_' . $submission->status, 'mod_assign'),
'groupid' => $submission->groupid,
'attemptnumber' => ($submission->attemptnumber + 1),
'latest' => transform::yesno($submission->latest)
];
writer::with_context($context)
->export_data(array_merge($currentpath, [get_string('privacy:submissionpath', 'mod_assign')]), $submissiondata);
}
/**
* Stores the user preferences related to mod_assign.
*
* @param int $userid The user ID that we want the preferences for.
*/
public static function export_user_preferences(int $userid) {
$context = \context_system::instance();
$assignpreferences = [
'assign_perpage' => ['string' => get_string('privacy:metadata:assignperpage', 'mod_assign'), 'bool' => false],
'assign_filter' => ['string' => get_string('privacy:metadata:assignfilter', 'mod_assign'), 'bool' => false],
'assign_markerfilter' => ['string' => get_string('privacy:metadata:assignmarkerfilter', 'mod_assign'), 'bool' => true],
'assign_workflowfilter' => ['string' => get_string('privacy:metadata:assignworkflowfilter', 'mod_assign'),
'bool' => true],
'assign_quickgrading' => ['string' => get_string('privacy:metadata:assignquickgrading', 'mod_assign'), 'bool' => true],
'assign_downloadasfolders' => ['string' => get_string('privacy:metadata:assigndownloadasfolders', 'mod_assign'),
'bool' => true]
];
foreach ($assignpreferences as $key => $preference) {
$value = get_user_preferences($key, null, $userid);
if ($preference['bool']) {
$value = transform::yesno($value);
}
if (isset($value)) {
writer::with_context($context)->export_user_preference('mod_assign', $key, $value, $preference['string']);
}
}
}
/**
* Export overrides for this assignment.
*
* @param \context $context Context
* @param \assign $assign The assign object.
* @param \stdClass $user The user object.
*/
public static function export_overrides(\context $context, \assign $assign, \stdClass $user) {
$overrides = $assign->override_exists($user->id);
// Overrides returns an array with data in it, but an override with actual data will have the assign ID set.
if (isset($overrides->assignid)) {
$data = new \stdClass();
if (!empty($overrides->duedate)) {
$data->duedate = transform::datetime($overrides->duedate);
}
if (!empty($overrides->cutoffdate)) {
$data->cutoffdate = transform::datetime($overrides->cutoffdate);
}
if (!empty($overrides->allowsubmissionsfromdate)) {
$data->allowsubmissionsfromdate = transform::datetime($overrides->allowsubmissionsfromdate);
}
if (!empty($data)) {
writer::with_context($context)->export_data([get_string('overrides', 'mod_assign')], $data);
}
}
}
/**
* Exports assignment submission data for a user.
*
* @param \assign $assign The assignment object
* @param \stdClass $user The user object
* @param \context_module $context The context
* @param array $path The path for exporting data
* @param bool|boolean $exportforteacher A flag for if this is exporting data as a teacher.
*/
protected static function export_submission(\assign $assign, \stdClass $user, \context_module $context, array $path,
bool $exportforteacher = false) {
$submissions = $assign->get_all_submissions($user->id);
$teacher = ($exportforteacher) ? $user : null;
$gradingmanager = get_grading_manager($context, 'mod_assign', 'submissions');
$controller = $gradingmanager->get_active_controller();
foreach ($submissions as $submission) {
// Attempt numbers start at zero, which is fine for programming, but doesn't make as much sense
// for users.
$submissionpath = array_merge($path,
[get_string('privacy:attemptpath', 'mod_assign', ($submission->attemptnumber + 1))]);
$params = new assign_plugin_request_data($context, $assign, $submission, $submissionpath ,$teacher);
manager::plugintype_class_callback('assignsubmission', self::ASSIGNSUBMISSION_INTERFACE,
'export_submission_user_data', [$params]);
if (!isset($teacher)) {
self::export_submission_data($submission, $context, $submissionpath);
}
$grade = $assign->get_user_grade($user->id, false, $submission->attemptnumber);
if ($grade) {
$params = new assign_plugin_request_data($context, $assign, $grade, $submissionpath, $teacher);
manager::plugintype_class_callback('assignfeedback', self::ASSIGNFEEDBACK_INTERFACE, 'export_feedback_user_data',
[$params]);
self::export_grade_data($grade, $context, $submissionpath);
// Check for advanced grading and retrieve that information.
if (isset($controller)) {
\core_grading\privacy\provider::export_item_data($context, $grade->id, $submissionpath);
}
}
}
}
}
@@ -0,0 +1,101 @@
<?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/>.
/**
* This file contains the polyfill to allow a plugin to operate with Moodle 3.3 up.
*
* @package mod_assign
* @copyright 2018 Adrian Greeve <adrian@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign\privacy;
use core_privacy\local\request\contextlist;
defined('MOODLE_INTERNAL') || die();
/**
* The trait used to provide backwards compatability for third-party plugins.
*
* @copyright 2018 Adrian Greeve <adrian@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
trait submission_legacy_polyfill {
/**
* Retrieves the contextids associated with the provided userid for this subplugin.
* NOTE if your subplugin must have an entry in the assign_submission table to work, then this
* method can be empty.
*
* @param int $userid The user ID to get context IDs for.
* @param \core_privacy\local\request\contextlist $contextlist Use add_from_sql with this object to add your context IDs.
*/
public static function get_context_for_userid_within_submission(int $userid, contextlist $contextlist) {
return static::_get_context_for_userid_within_submission($userid, $contextlist);
}
/**
* Returns student user ids related to the provided teacher ID. If it is possible that a student ID will not be returned by
* the sql query in \mod_assign\privacy\provider::find_grader_info() Then you need to provide some sql to retrive those
* student IDs. This is highly likely if you had to fill in get_context_for_userid_within_submission above.
*
* @param useridlist $useridlist A user ID list object that you can append your user IDs to.
*/
public static function get_student_user_ids(useridlist $useridlist) {
return static::_get_student_user_ids($useridlist);
}
/**
* This method is used to export any user data this sub-plugin has using the assign_plugin_request_data object to get the
* context and userid.
* assign_plugin_request_data contains:
* - context
* - submission object
* - current path (subcontext)
* - user object
*
* @param assign_plugin_request_data $exportdata Information to use to export user data for this sub-plugin.
*/
public static function export_submission_user_data(assign_plugin_request_data $exportdata) {
return static::_export_submission_user_data($exportdata);
}
/**
* Any call to this method should delete all user data for the context defined in the deletion_criteria.
* assign_plugin_request_data contains:
* - context
* - assign object
*
* @param assign_plugin_request_data $requestdata Information to use to delete user data for this submission.
*/
public static function delete_submission_for_context(assign_plugin_request_data $requestdata) {
return static::_delete_submission_for_context($requestdata);
}
/**
* A call to this method should delete user data (where practicle) from the userid and context.
* assign_plugin_request_data contains:
* - context
* - submission object
* - user object
* - assign object
*
* @param assign_plugin_request_data $exportdata Details about the user and context to focus the deletion.
*/
public static function delete_submission_for_userid(assign_plugin_request_data $exportdata) {
return static::_delete_submission_for_userid($exportdata);
}
}
+99
View File
@@ -0,0 +1,99 @@
<?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/>.
/**
* This file contains the mod_assign useridlist
*
* This is for collecting a list of user IDs
*
* @package mod_assign
* @copyright 2018 Adrian Greeve <adrian@moodle.com>
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign\privacy;
defined('MOODLE_INTERNAL') || die();
/**
* An object for collecting user IDs related to a teacher.
*
* @copyright 2018 Adrian Greeve <adrian@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class useridlist {
/** @var int The ID of the teacher. */
protected $teacherid;
/** @var int The ID of the assignment object. */
protected $assignid;
/** @var array A collection of user IDs (students). */
protected $userids = [];
/**
* Create this object.
*
* @param int $teacherid The teacher ID.
* @param int $assignid The assignment ID.
*/
public function __construct($teacherid, $assignid) {
$this->teacherid = $teacherid;
$this->assignid = $assignid;
}
/**
* Returns the teacher ID.
*
* @return int The teacher ID.
*/
public function get_teacherid() {
return $this->teacherid;
}
/**
* Returns the assign ID.
*
* @return int The assign ID.
*/
public function get_assignid() {
return $this->assignid;
}
/**
* Returns the user IDs.
*
* @return array User IDs.
*/
public function get_userids() {
return $this->userids;
}
/**
* Add sql and params to return user IDs.
*
* @param string $sql The sql string to return user IDs.
* @param array $params Parameters for the sql statement.
*/
public function add_from_sql($sql, $params) {
global $DB;
$userids = $DB->get_records_sql($sql, $params);
if (!empty($userids)) {
$this->userids = array_merge($this->userids, $userids);
}
}
}
+60
View File
@@ -0,0 +1,60 @@
<?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 mod_assign activities.
*
* @package mod_assign
* @copyright 2015 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign\search;
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/mod/assign/locallib.php');
/**
* Search area for mod_assign activities.
*
* @package mod_assign
* @copyright 2015 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class activity extends \core_search\base_activity {
/**
* Returns true if this area uses file indexing.
*
* @return bool
*/
public function uses_file_indexing() {
return true;
}
/**
* Return the context info required to index files for
* this search area.
*
* @return array
*/
public function get_search_fileareas() {
$fileareas = array('intro', ASSIGN_INTROATTACHMENT_FILEAREA); // Fileareas.
return $fileareas;
}
}
+69
View File
@@ -0,0 +1,69 @@
<?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/>.
namespace mod_assign\task;
defined('MOODLE_INTERNAL') || die();
/**
* A schedule task for assignment cron.
*
* @package mod_assign
* @copyright 2019 Simey Lameze <simey@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class cron_task extends \core\task\scheduled_task {
/**
* Get a descriptive name for this task (shown to admins).
*
* @return string
*/
public function get_name() {
return get_string('crontask', 'mod_assign');
}
/**
* Run assignment cron.
*/
public function execute() {
global $CFG;
require_once($CFG->dirroot . '/mod/assign/locallib.php');
\assign::cron();
$plugins = \core_component::get_plugin_list('assignsubmission');
foreach ($plugins as $name => $plugin) {
$disabled = get_config('assignsubmission_' . $name, 'disabled');
if (!$disabled) {
$class = 'assign_submission_' . $name;
require_once($CFG->dirroot . '/mod/assign/submission/' . $name . '/locallib.php');
$class::cron();
}
}
$plugins = \core_component::get_plugin_list('assignfeedback');
foreach ($plugins as $name => $plugin) {
$disabled = get_config('assignfeedback_' . $name, 'disabled');
if (!$disabled) {
$class = 'assign_feedback_' . $name;
require_once($CFG->dirroot . '/mod/assign/feedback/' . $name . '/locallib.php');
$class::cron();
}
}
return true;
}
}