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,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/>.
/**
* The assignsubmission_comments comment created event.
*
* @package assignsubmission_comments
* @copyright 2013 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace assignsubmission_comments\event;
defined('MOODLE_INTERNAL') || die();
/**
* The assignsubmission_comments comment created event class.
*
* @package assignsubmission_comments
* @since Moodle 2.7
* @copyright 2013 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class comment_created extends \core\event\comment_created {
/**
* Get URL related to the action.
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/assign/view.php', array('id' => $this->contextinstanceid));
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' added the comment with id '$this->objectid' to the submission " .
"with id '{$this->other['itemid']}' for the assignment with course module id '$this->contextinstanceid'.";
}
}
@@ -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/>.
/**
* The assignsubmission_comments comment deleted event.
*
* @package assignsubmission_comments
* @copyright 2013 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace assignsubmission_comments\event;
defined('MOODLE_INTERNAL') || die();
/**
* The assignsubmission_comments comment deleted event.
*
* @package assignsubmission_comments
* @since Moodle 2.7
* @copyright 2013 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class comment_deleted extends \core\event\comment_deleted {
/**
* Get URL related to the action.
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/assign/view.php', array('id' => $this->contextinstanceid));
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' deleted the comment with id '$this->objectid' from the submission " .
"with id '{$this->other['itemid']}' for the assignment with course module id '$this->contextinstanceid'.";
}
}
@@ -0,0 +1,164 @@
<?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 assignsubmission_comments
* @copyright 2018 Adrian Greeve <adrian@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace assignsubmission_comments\privacy;
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/mod/assign/locallib.php');
use \core_privacy\local\metadata\collection;
use \core_privacy\local\metadata\provider as metadataprovider;
use \core_comment\privacy\provider as comments_provider;
use \core_privacy\local\request\contextlist;
use \mod_assign\privacy\assign_plugin_request_data;
/**
* Privacy class for requesting user data.
*
* @package assignsubmission_comments
* @copyright 2018 Adrian Greeve <adrian@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements metadataprovider,
\mod_assign\privacy\assignsubmission_provider,
\mod_assign\privacy\assignsubmission_user_provider {
/**
* Return meta data about this plugin.
*
* @param collection $collection A list of information to add to.
* @return collection Return the collection after adding to it.
*/
public static function get_metadata(collection $collection): collection {
$collection->link_subsystem('core_comment', 'privacy:metadata:commentpurpose');
return $collection;
}
/**
* It is possible to make a comment as a teacher without creating an entry in the submission table, so this is required
* to find those entries.
*
* @param int $userid The user ID that we are finding contexts for.
* @param contextlist $contextlist A context list to add sql and params to for contexts.
*/
public static function get_context_for_userid_within_submission(int $userid, contextlist $contextlist) {
$sql = "SELECT contextid
FROM {comments}
WHERE component = :component
AND commentarea = :commentarea
AND userid = :userid";
$params = ['userid' => $userid, 'component' => 'assignsubmission_comments', 'commentarea' => 'submission_comments'];
$contextlist->add_from_sql($sql, $params);
}
/**
* Due to the fact that we can't rely on the queries in the mod_assign provider we have to add some additional sql.
*
* @param \mod_assign\privacy\useridlist $useridlist An object for obtaining user IDs of students.
*/
public static function get_student_user_ids(\mod_assign\privacy\useridlist $useridlist) {
$params = ['assignid' => $useridlist->get_assignid(), 'commentuserid' => $useridlist->get_teacherid(),
'commentuserid2' => $useridlist->get_teacherid()];
$sql = "SELECT DISTINCT c.userid AS id
FROM {comments} c
JOIN (SELECT c.itemid
FROM {comments} c
JOIN {assign_submission} s ON s.id = c.itemid AND s.assignment = :assignid
WHERE c.userid = :commentuserid) aa ON aa.itemid = c.itemid
WHERE c.userid NOT IN (:commentuserid2)";
$useridlist->add_from_sql($sql, $params);
}
/**
* 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 \core_privacy\local\request\userlist $userlist The userlist object
*/
public static function get_userids_from_context(\core_privacy\local\request\userlist $userlist) {
$context = $userlist->get_context();
if ($context->contextlevel != CONTEXT_MODULE) {
return;
}
comments_provider::get_users_in_context_from_sql($userlist, 'c', 'assignsubmission_comments', 'submission_comments',
$context->id);
}
/**
* Export all user data for this plugin.
*
* @param assign_plugin_request_data $exportdata Data used to determine which context and user to export and other useful
* information to help with exporting.
*/
public static function export_submission_user_data(assign_plugin_request_data $exportdata) {
$component = 'assignsubmission_comments';
$commentarea = 'submission_comments';
$userid = ($exportdata->get_user() != null);
$submission = $exportdata->get_pluginobject();
// For the moment we are only showing the comments made by this user.
comments_provider::export_comments($exportdata->get_context(), $component, $commentarea, $submission->id,
$exportdata->get_subcontext(), $userid);
}
/**
* Delete all the comments made for this context.
*
* @param assign_plugin_request_data $requestdata Data to fulfill the deletion request.
*/
public static function delete_submission_for_context(assign_plugin_request_data $requestdata) {
comments_provider::delete_comments_for_all_users($requestdata->get_context(), 'assignsubmission_comments',
'submission_comments');
}
/**
* A call to this method should delete user data (where practical) using the userid and submission.
*
* @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) {
// Create an approved context list to delete the comments.
$contextlist = new \core_privacy\local\request\approved_contextlist($exportdata->get_user(), 'assignsubmission_comments',
[$exportdata->get_context()->id]);
comments_provider::delete_comments_for_user($contextlist, 'assignsubmission_comments', 'submission_comments');
}
/**
* 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) {
$userlist = new \core_privacy\local\request\approved_userlist($deletedata->get_context(), 'assignsubmission_comments',
$deletedata->get_userids());
comments_provider::delete_comments_for_users($userlist, 'assignsubmission_comments', 'submission_comments');
}
}
@@ -0,0 +1,30 @@
<?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/>.
/**
* Capability definitions for this module.
*
* @package assignsubmission_comments
* @copyright 2012 NetSpot {@link http://www.netspot.com.au}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$capabilities = array(
);
@@ -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/>.
/**
* Post-install code for the submission_comments module.
*
* @package assignsubmission_comments
* @copyright 2012 NetSpot {@link http://www.netspot.com.au}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* Code run after the module database tables have been created.
* Moves the comments plugin to the bottom
* @return bool
*/
function xmldb_assignsubmission_comments_install() {
global $CFG;
require_once($CFG->dirroot . '/mod/assign/adminlib.php');
// Set the correct initial order for the plugins.
$pluginmanager = new assign_plugin_manager('assignsubmission');
$pluginmanager->move_plugin('comments', 'down');
$pluginmanager->move_plugin('comments', 'down');
return true;
}
@@ -0,0 +1,44 @@
<?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/>.
/**
* Upgrade code for install
*
* @package assignsubmission_comments
* @copyright 2012 NetSpot {@link http://www.netspot.com.au}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* Stub for upgrade code
* @param int $oldversion
* @return bool
*/
function xmldb_assignsubmission_comments_upgrade($oldversion) {
// Automatically generated Moodle v4.1.0 release upgrade line.
// Put any upgrade step following this.
// Automatically generated Moodle v4.2.0 release upgrade line.
// Put any upgrade step following this.
// Automatically generated Moodle v4.3.0 release upgrade line.
// Put any upgrade step following this.
// Automatically generated Moodle v4.4.0 release upgrade line.
// Put any upgrade step following this.
return true;
}
@@ -0,0 +1,32 @@
<?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/>.
/**
* Strings for component 'submission_comments', language 'en'
*
* @package assignsubmission_comments
* @copyright 2012 NetSpot {@link http://www.netspot.com.au}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['blindmarkingname'] = 'Participant {$a}';
$string['blindmarkingviewfullname'] = 'Participant {$a->participantnumber} ({$a->participantfullname})';
$string['privacy:metadata:commentpurpose'] = 'Comments between the student and teacher about a submission.';
$string['default'] = 'Enabled by default';
$string['default_help'] = 'If set, this submission method will be enabled by default for all new assignments.';
$string['enabled'] = 'Submission comments';
$string['enabled_help'] = 'If enabled, students can leave comments on their own submission. For example, this can be used for students to specify which is the master file when submitting inter-linked files.';
$string['pluginname'] = 'Submission comments';
+204
View File
@@ -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 moodle hooks for the submission comments plugin
*
* @package assignsubmission_comments
* @copyright 2012 NetSpot {@link http://www.netspot.com.au}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
*
* Callback method for data validation---- required method for AJAXmoodle based comment API
*
* @param stdClass $options
* @return bool
*/
function assignsubmission_comments_comment_validate(stdClass $options) {
global $USER, $CFG, $DB;
if ($options->commentarea != 'submission_comments' &&
$options->commentarea != 'submission_comments_upgrade') {
throw new comment_exception('invalidcommentarea');
}
if (!$submission = $DB->get_record('assign_submission', array('id'=>$options->itemid))) {
throw new comment_exception('invalidcommentitemid');
}
$context = $options->context;
require_once($CFG->dirroot . '/mod/assign/locallib.php');
static $assignment = null;
if (is_null($assignment) || $assignment->get_context() != $context) {
$assignment = new assign($context, null, null);
}
if ($assignment->get_instance()->id != $submission->assignment) {
throw new comment_exception('invalidcontext');
}
return true;
}
/**
* Permission control method for submission plugin ---- required method for AJAXmoodle based comment API
*
* @param stdClass $options
* @return array
*/
function assignsubmission_comments_comment_permissions(stdClass $options) {
global $USER, $CFG, $DB;
if ($options->commentarea != 'submission_comments' &&
$options->commentarea != 'submission_comments_upgrade') {
throw new comment_exception('invalidcommentarea');
}
if (!$submission = $DB->get_record('assign_submission', array('id'=>$options->itemid))) {
throw new comment_exception('invalidcommentitemid');
}
$context = $options->context;
require_once($CFG->dirroot . '/mod/assign/locallib.php');
static $assignment = null;
if (is_null($assignment) || $assignment->get_context() != $context) {
$assignment = new assign($context, null, null);
}
if ($assignment->get_instance()->id != $submission->assignment) {
throw new comment_exception('invalidcontext');
}
if ($assignment->get_instance()->teamsubmission &&
!$assignment->can_view_group_submission($submission->groupid)) {
return array('post' => false, 'view' => false);
}
if (!$assignment->get_instance()->teamsubmission &&
!$assignment->can_view_submission($submission->userid)) {
return array('post' => false, 'view' => false);
}
return array('post' => true, 'view' => true);
}
/**
* Callback called by comment::get_comments() and comment::add(). Gives an opportunity to enforce blind-marking.
*
* @param array $comments
* @param stdClass $options
* @return array
* @throws comment_exception
*/
function assignsubmission_comments_comment_display($comments, $options) {
global $CFG, $DB, $USER;
if ($options->commentarea != 'submission_comments' &&
$options->commentarea != 'submission_comments_upgrade') {
throw new comment_exception('invalidcommentarea');
}
if (!$submission = $DB->get_record('assign_submission', array('id'=>$options->itemid))) {
throw new comment_exception('invalidcommentitemid');
}
$context = $options->context;
$cm = $options->cm;
$course = $options->courseid;
require_once($CFG->dirroot . '/mod/assign/locallib.php');
$assignment = new assign($context, $cm, $course);
if ($assignment->get_instance()->id != $submission->assignment) {
throw new comment_exception('invalidcontext');
}
if ($assignment->is_blind_marking() && !empty($comments)) {
// Blind marking is being used, may need to map unique anonymous ids to the comments.
$usermappings = array();
$guestuser = guest_user();
// Check group users first.
$userinteam = false;
if ($assignment->get_instance()->teamsubmission && has_capability('mod/assign:submit', $context)) {
$assignment->set_course(get_course($course));
$userinteam = $assignment->can_edit_group_submission($submission->groupid);
}
foreach ($comments as $comment) {
if (has_capability('mod/assign:viewblinddetails', $context) && $USER->id != $comment->userid) {
$anonid = $assignment->get_uniqueid_for_user($comment->userid);
// Show participant information and the user's full name to users with the view blind details capability.
$a = new stdClass();
$a->participantnumber = $anonid;
$a->participantfullname = $comment->fullname;
$comment->fullname = get_string('blindmarkingviewfullname', 'assignsubmission_comments', $a);
} else if ($USER->id == $comment->userid || $submission->userid == $USER->id || $userinteam) { // phpcs:ignore
// Do not anonymize the user details for this comment.
} else {
// Anonymize the comments.
if (empty($usermappings[$comment->userid])) {
$anonid = $assignment->get_uniqueid_for_user($comment->userid);
// The blind-marking information for this commenter has not been generated; do so now.
$commenter = new stdClass();
$commenter->firstname = get_string('blindmarkingname', 'assignsubmission_comments', $anonid);
$commenter->lastname = '';
$commenter->firstnamephonetic = '';
$commenter->lastnamephonetic = '';
$commenter->middlename = '';
$commenter->alternatename = '';
$commenter->picture = 0;
$commenter->id = $guestuser->id;
$commenter->email = $guestuser->email;
$commenter->imagealt = $guestuser->imagealt;
// Temporarily store blind-marking information for use in later comments if necessary.
$usermappings[$comment->userid] = new stdClass();
$usermappings[$comment->userid]->fullname = fullname($commenter);
$usermappings[$comment->userid]->avatar = $assignment->get_renderer()->user_picture($commenter,
array('size' => 18, 'link' => false));
}
// Set blind-marking information for this comment.
$comment->fullname = $usermappings[$comment->userid]->fullname;
$comment->avatar = $usermappings[$comment->userid]->avatar;
$comment->profileurl = null;
}
}
}
return $comments;
}
/**
* Callback to force the userid for all comments to be the userid of the submission and NOT the global $USER->id. This
* is required by the upgrade code. Note the comment area is used to identify upgrades.
*
* @param stdClass $comment
* @param stdClass $param
*/
function assignsubmission_comments_comment_add(stdClass $comment, stdClass $param) {
global $DB;
if ($comment->commentarea == 'submission_comments_upgrade') {
$submissionid = $comment->itemid;
$submission = $DB->get_record('assign_submission', array('id' => $submissionid));
$comment->userid = $submission->userid;
$comment->commentarea = 'submission_comments';
}
}
+200
View File
@@ -0,0 +1,200 @@
<?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 library class for online comment submission plugin
*
* @package assignsubmission_comments
* @copyright 2012 NetSpot {@link http://www.netspot.com.au}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/comment/lib.php');
require_once($CFG->dirroot . '/mod/assign/submissionplugin.php');
/**
* Library class for comment submission plugin extending submission plugin base class
*
* @package assignsubmission_comments
* @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_comments extends assign_submission_plugin {
/**
* Get the name of the online comment submission plugin
* @return string
*/
public function get_name() {
return get_string('pluginname', 'assignsubmission_comments');
}
/**
* Display AJAX based comment in the submission status table
*
* @param stdClass $submission
* @param bool $showviewlink - If the comments are long this is
* set to true so they can be shown in a separate page
* @return string
*/
public function view_summary(stdClass $submission, & $showviewlink) {
// Never show a link to view full submission.
$showviewlink = false;
// Need to used this init() otherwise it does not have the javascript includes.
comment::init();
$options = new stdClass();
$options->area = 'submission_comments';
$options->course = $this->assignment->get_course();
$options->context = $this->assignment->get_context();
$options->itemid = $submission->id;
$options->component = 'assignsubmission_comments';
$options->showcount = true;
$options->displaycancel = true;
$comment = new comment($options);
$o = $this->assignment->get_renderer()->container($comment->output(true), 'commentscontainer');
return $o;
}
/**
* Always return true because the submission comments are not part of the submission form.
*
* @param stdClass $submission
* @return bool
*/
public function is_empty(stdClass $submission) {
return true;
}
/**
* Return true if this plugin can upgrade an old Moodle 2.2 assignment of this type
* and version.
*
* @param string $type old assignment subtype
* @param int $version old assignment version
* @return bool True if upgrade is possible
*/
public function can_upgrade($type, $version) {
if ($type == 'upload' && $version >= 2011112900) {
return true;
}
return false;
}
/**
* Upgrade the settings from the old assignment to the new plugin based one
*
* @param context $oldcontext - the context for the old assignment
* @param stdClass $oldassignment - the data for the old assignment
* @param string $log - can be appended to by the upgrade
* @return bool was it a success? (false will trigger a rollback)
*/
public function upgrade_settings(context $oldcontext, stdClass $oldassignment, & $log) {
if ($oldassignment->assignmenttype == 'upload') {
// Disable if allow notes was not enabled.
if (!$oldassignment->var2) {
$this->disable();
}
}
return true;
}
/**
* Upgrade the submission from the old assignment to the new one
*
* @param context $oldcontext The context for the old assignment
* @param stdClass $oldassignment The data record for the old assignment
* @param stdClass $oldsubmission The data record for the old submission
* @param stdClass $submission The new submission record
* @param string $log Record upgrade messages in the log
* @return bool true or false - false will trigger a rollback
*/
public function upgrade(context $oldcontext,
stdClass $oldassignment,
stdClass $oldsubmission,
stdClass $submission,
& $log) {
if ($oldsubmission->data1 != '') {
// Need to used this init() otherwise it does not have the javascript includes.
comment::init();
$options = new stdClass();
$options->area = 'submission_comments_upgrade';
$options->course = $this->assignment->get_course();
$options->context = $this->assignment->get_context();
$options->itemid = $submission->id;
$options->component = 'assignsubmission_comments';
$options->showcount = true;
$options->displaycancel = true;
$comment = new comment($options);
$comment->add($oldsubmission->data1);
$comment->set_view_permission(true);
return $comment->output(true);
}
return true;
}
/**
* The submission comments plugin has no submission component so should not be counted
* when determining whether to show the edit submission link.
* @return boolean
*/
public function allow_submissions() {
return false;
}
/**
* Automatically enable or disable this plugin based on "$CFG->commentsenabled"
*
* @return bool
*/
public function is_enabled() {
global $CFG;
return (!empty($CFG->usecomments));
}
/**
* Automatically hide the setting for the submission plugin.
*
* @return bool
*/
public function is_configurable() {
return false;
}
/**
* Return the plugin configs for external functions.
*
* @return array the list of settings
* @since Moodle 3.2
*/
public function get_config_for_external() {
return (array) $this->get_config();
}
}
@@ -0,0 +1,132 @@
<?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/>.
/**
* Events tests.
*
* @package assignsubmission_comments
* @category test
* @copyright 2013 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace assignsubmission_comments\event;
use mod_assign_test_generator;
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot . '/mod/assign/lib.php');
require_once($CFG->dirroot . '/mod/assign/locallib.php');
require_once($CFG->dirroot . '/mod/assign/tests/generator.php');
require_once($CFG->dirroot . '/comment/lib.php');
/**
* Events tests class.
*
* @package assignsubmission_comments
* @category test
* @copyright 2013 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class events_test extends \advanced_testcase {
// Use the generator helper.
use mod_assign_test_generator;
/**
* Test comment_created event.
*/
public function test_comment_created(): void {
$this->resetAfterTest();
$course = $this->getDataGenerator()->create_course();
$teacher = $this->getDataGenerator()->create_and_enrol($course, 'teacher');
$student = $this->getDataGenerator()->create_and_enrol($course, 'student');
$assign = $this->create_instance($course);
$this->setUser($teacher);
$submission = $assign->get_user_submission($student->id, true);
$context = $assign->get_context();
$options = new \stdClass();
$options->area = 'submission_comments';
$options->course = $assign->get_course();
$options->context = $context;
$options->itemid = $submission->id;
$options->component = 'assignsubmission_comments';
$options->showcount = true;
$options->displaycancel = true;
$comment = new \comment($options);
// Triggering and capturing the event.
$sink = $this->redirectEvents();
$comment->add('New comment');
$events = $sink->get_events();
$this->assertCount(1, $events);
$event = reset($events);
$sink->close();
// Checking that the event contains the expected values.
$this->assertInstanceOf('\assignsubmission_comments\event\comment_created', $event);
$this->assertEquals($context, $event->get_context());
$url = new \moodle_url('/mod/assign/view.php', array('id' => $assign->get_course_module()->id));
$this->assertEquals($url, $event->get_url());
$this->assertEventContextNotUsed($event);
}
/**
* Test comment_deleted event.
*/
public function test_comment_deleted(): void {
$this->resetAfterTest();
$course = $this->getDataGenerator()->create_course();
$teacher = $this->getDataGenerator()->create_and_enrol($course, 'teacher');
$student = $this->getDataGenerator()->create_and_enrol($course, 'student');
$assign = $this->create_instance($course);
$this->setUser($teacher);
$submission = $assign->get_user_submission($student->id, true);
$context = $assign->get_context();
$options = new \stdClass();
$options->area = 'submission_comments';
$options->course = $assign->get_course();
$options->context = $context;
$options->itemid = $submission->id;
$options->component = 'assignsubmission_comments';
$options->showcount = true;
$options->displaycancel = true;
$comment = new \comment($options);
$newcomment = $comment->add('New comment 1');
// Triggering and capturing the event.
$sink = $this->redirectEvents();
$comment->delete($newcomment->id);
$events = $sink->get_events();
$this->assertCount(1, $events);
$event = reset($events);
// Checking that the event contains the expected values.
$this->assertInstanceOf('\assignsubmission_comments\event\comment_deleted', $event);
$this->assertEquals($context, $event->get_context());
$url = new \moodle_url('/mod/assign/view.php', array('id' => $assign->get_course_module()->id));
$this->assertEquals($url, $event->get_url());
$this->assertEventContextNotUsed($event);
}
}
@@ -0,0 +1,363 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Unit tests for assignsubmission_comments.
*
* @package assignsubmission_comments
* @copyright 2018 Adrian Greeve <adrian@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace assignsubmission_comments\privacy;
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot . '/mod/assign/tests/privacy/provider_test.php');
use mod_assign\privacy\useridlist;
/**
* Unit tests for mod/assign/submission/comments/classes/privacy/
*
* @copyright 2018 Adrian Greeve <adrian@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider_test extends \mod_assign\privacy\provider_test {
/**
* Convenience function for creating feedback data.
*
* @param object $assign assign object
* @param stdClass $student user object
* @param string $submissiontext Submission text
* @return array Submission plugin object and the submission object and the comment object.
*/
protected function create_comment_submission($assign, $student, $submissiontext) {
$submission = $assign->get_user_submission($student->id, true);
$plugin = $assign->get_submission_plugin_by_type('comments');
$context = $assign->get_context();
$options = new \stdClass();
$options->area = 'submission_comments';
$options->course = $assign->get_course();
$options->context = $context;
$options->itemid = $submission->id;
$options->component = 'assignsubmission_comments';
$options->showcount = true;
$options->displaycancel = true;
$comment = new \comment($options);
$comment->set_post_permission(true);
$this->setUser($student);
$comment->add($submissiontext);
return [$plugin, $submission, $comment];
}
/**
* Quick test to make sure that get_metadata returns something.
*/
public function test_get_metadata(): void {
$collection = new \core_privacy\local\metadata\collection('assignsubmission_comments');
$collection = \assignsubmission_comments\privacy\provider::get_metadata($collection);
$this->assertNotEmpty($collection);
}
/**
* Test returning the context for a user who has made a comment in an assignment.
*/
public function test_get_context_for_userid_within_submission(): void {
$this->resetAfterTest();
// Create course, assignment, submission, and then a feedback comment.
$course = $this->getDataGenerator()->create_course();
// Student.
$user1 = $this->getDataGenerator()->create_user();
// Teacher.
$user2 = $this->getDataGenerator()->create_user();
$this->getDataGenerator()->enrol_user($user1->id, $course->id, 'student');
$this->getDataGenerator()->enrol_user($user2->id, $course->id, 'editingteacher');
$assign = $this->create_instance(['course' => $course]);
$context = $assign->get_context();
$studentcomment = 'Comment from user 1';
list($plugin, $submission, $comment) = $this->create_comment_submission($assign, $user1, $studentcomment);
$teachercomment = 'From the teacher';
$this->setUser($user2);
$comment->add($teachercomment);
$contextlist = new \core_privacy\local\request\contextlist();
\assignsubmission_comments\privacy\provider::get_context_for_userid_within_submission($user2->id, $contextlist);
$this->assertEquals($context->id, $contextlist->get_contextids()[0]);
}
/**
* Test returning student ids given a user ID.
*/
public function test_get_student_user_ids(): void {
$this->resetAfterTest();
// Create course, assignment, submission, and then a feedback comment.
$course = $this->getDataGenerator()->create_course();
// Student.
$user1 = $this->getDataGenerator()->create_user();
// Teacher.
$user2 = $this->getDataGenerator()->create_user();
$this->getDataGenerator()->enrol_user($user1->id, $course->id, 'student');
$this->getDataGenerator()->enrol_user($user2->id, $course->id, 'editingteacher');
$assign = $this->create_instance(['course' => $course]);
$context = $assign->get_context();
$studentcomment = 'Comment from user 1';
list($plugin, $submission, $comment) = $this->create_comment_submission($assign, $user1, $studentcomment);
$teachercomment = 'From the teacher';
$this->setUser($user2);
$comment->add($teachercomment);
$useridlist = new useridlist($user2->id, $assign->get_instance()->id);
\assignsubmission_comments\privacy\provider::get_student_user_ids($useridlist);
$this->assertEquals($user1->id, $useridlist->get_userids()[0]->id);
}
/**
* Test returning users related to a given context.
*/
public function test_get_userids_from_context(): void {
// Get a bunch of users making comments.
// Some in one context some in another.
$this->resetAfterTest();
$course = $this->getDataGenerator()->create_course();
// Only in first context.
$user1 = $this->getDataGenerator()->create_user();
$user2 = $this->getDataGenerator()->create_user();
// First and second context.
$user3 = $this->getDataGenerator()->create_user();
// Second context only.
$user4 = $this->getDataGenerator()->create_user();
$this->getDataGenerator()->enrol_user($user1->id, $course->id, 'student');
$assign1 = $this->create_instance(['course' => $course]);
$assign2 = $this->create_instance(['course' => $course]);
$assigncontext1 = $assign1->get_context();
$assigncontext2 = $assign2->get_context();
$user1comment = 'Comment from user 1';
list($plugin, $submission, $comment) = $this->create_comment_submission($assign1, $user1, $user1comment);
$user2comment = 'From user 2';
$this->setUser($user2);
$comment->add($user2comment);
$user3comment = 'User 3 comment';
$this->setUser($user3);
$comment->add($user3comment);
$user4comment = 'Comment from user 4';
list($plugin, $submission, $comment) = $this->create_comment_submission($assign2, $user4, $user4comment);
$user3secondcomment = 'Comment on user 4 post.';
$this->setUser($user3);
$comment->add($user3comment);
$userlist = new \core_privacy\local\request\userlist($assigncontext1, 'assignsubmission_comments');
\assignsubmission_comments\privacy\provider::get_userids_from_context($userlist);
$userids = $userlist->get_userids();
$this->assertCount(3, $userids);
// User 1,2 and 3 are the expected ones in the array. User 4 isn't.
$this->assertContainsEquals($user1->id, $userids);
$this->assertContainsEquals($user2->id, $userids);
$this->assertContainsEquals($user3->id, $userids);
$this->assertNotContainsEquals($user4->id, $userids);
}
/**
* Test that comments are exported for a user.
*/
public function test_export_submission_user_data(): void {
$this->resetAfterTest();
// Create course, assignment, submission, and then a feedback comment.
$course = $this->getDataGenerator()->create_course();
// Student.
$user1 = $this->getDataGenerator()->create_user();
// Teacher.
$user2 = $this->getDataGenerator()->create_user();
$this->getDataGenerator()->enrol_user($user1->id, $course->id, 'student');
$this->getDataGenerator()->enrol_user($user2->id, $course->id, 'editingteacher');
$assign = $this->create_instance(['course' => $course]);
$context = $assign->get_context();
$studentcomment = 'Comment from user 1';
list($plugin, $submission, $comment) = $this->create_comment_submission($assign, $user1, $studentcomment);
$teachercomment = 'From the teacher';
$this->setUser($user2);
$comment->add($teachercomment);
$writer = \core_privacy\local\request\writer::with_context($context);
$this->assertFalse($writer->has_any_data());
// The student should be able to see the teachers feedback.
$exportdata = new \mod_assign\privacy\assign_plugin_request_data($context, $assign, $submission);
\assignsubmission_comments\privacy\provider::export_submission_user_data($exportdata);
$exportedcomments = $writer->get_data(['Comments']);
// Can't rely on these comments coming out in order.
if ($exportedcomments->comments[0]->userid == $user1->id) {
$exportedstudentcomment = $exportedcomments->comments[0]->content;
$exportedteachercomment = $exportedcomments->comments[1]->content;
} else {
$exportedstudentcomment = $exportedcomments->comments[1]->content;
$exportedteachercomment = $exportedcomments->comments[0]->content;
}
$this->assertCount(2, $exportedcomments->comments);
$this->assertStringContainsString($studentcomment, $exportedstudentcomment);
$this->assertStringContainsString($teachercomment, $exportedteachercomment);
}
/**
* Test that all comments are deleted for this context.
*/
public function test_delete_submission_for_context(): void {
global $DB;
$this->resetAfterTest();
// Create course, assignment, submission, and then a feedback comment.
$course = $this->getDataGenerator()->create_course();
// Student.
$user1 = $this->getDataGenerator()->create_user();
$user2 = $this->getDataGenerator()->create_user();
// Teacher.
$user3 = $this->getDataGenerator()->create_user();
$this->getDataGenerator()->enrol_user($user1->id, $course->id, 'student');
$this->getDataGenerator()->enrol_user($user2->id, $course->id, 'student');
$this->getDataGenerator()->enrol_user($user3->id, $course->id, 'editingteacher');
$assign = $this->create_instance(['course' => $course]);
$context = $assign->get_context();
$studentcomment = 'Comment from user 1';
list($plugin, $submission, $comment) = $this->create_comment_submission($assign, $user1, $studentcomment);
$studentcomment = 'Comment from user 2';
list($plugin2, $submission2, $comment2) = $this->create_comment_submission($assign, $user2, $studentcomment);
$teachercomment1 = 'From the teacher';
$teachercomment2 = 'From the teacher for second student.';
$this->setUser($user3);
$comment->add($teachercomment1);
$comment2->add($teachercomment2);
// Only need the context in this plugin for this operation.
$requestdata = new \mod_assign\privacy\assign_plugin_request_data($context, $assign);
\assignsubmission_comments\privacy\provider::delete_submission_for_context($requestdata);
$results = $DB->get_records('comments', ['contextid' => $context->id]);
$this->assertEmpty($results);
}
/**
* Test that the comments for a user are deleted.
*/
public function test_delete_submission_for_userid(): void {
global $DB;
$this->resetAfterTest();
// Create course, assignment, submission, and then a feedback comment.
$course = $this->getDataGenerator()->create_course();
// Student.
$user1 = $this->getDataGenerator()->create_user();
$user2 = $this->getDataGenerator()->create_user();
// Teacher.
$user3 = $this->getDataGenerator()->create_user();
$this->getDataGenerator()->enrol_user($user1->id, $course->id, 'student');
$this->getDataGenerator()->enrol_user($user2->id, $course->id, 'student');
$this->getDataGenerator()->enrol_user($user3->id, $course->id, 'editingteacher');
$assign = $this->create_instance(['course' => $course]);
$context = $assign->get_context();
$studentcomment = 'Comment from user 1';
list($plugin, $submission, $comment) = $this->create_comment_submission($assign, $user1, $studentcomment);
$studentcomment = 'Comment from user 2';
list($plugin2, $submission2, $comment2) = $this->create_comment_submission($assign, $user2, $studentcomment);
$teachercomment1 = 'From the teacher';
$teachercomment2 = 'From the teacher for second student.';
$this->setUser($user3);
$comment->add($teachercomment1);
$comment2->add($teachercomment2);
// Provide full details to delete the comments.
$requestdata = new \mod_assign\privacy\assign_plugin_request_data($context, $assign, null, [], $user1);
\assignsubmission_comments\privacy\provider::delete_submission_for_userid($requestdata);
$results = $DB->get_records('comments', ['contextid' => $context->id]);
// We are only deleting the comments for user1 (one comment) so we should have three left.
$this->assertCount(3, $results);
foreach ($results as $result) {
// Check that none of the comments are from user1.
$this->assertNotEquals($user1->id, $result->userid);
}
}
/**
* Test deletion of all submissions for a context works.
*/
public function test_delete_submissions(): void {
global $DB;
// Get a bunch of users making comments.
// Some in one context some in another.
$this->resetAfterTest();
$course = $this->getDataGenerator()->create_course();
// Only in first context.
$user1 = $this->getDataGenerator()->create_user();
$user2 = $this->getDataGenerator()->create_user();
// First and second context.
$user3 = $this->getDataGenerator()->create_user();
// Second context only.
$user4 = $this->getDataGenerator()->create_user();
$this->getDataGenerator()->enrol_user($user1->id, $course->id, 'student');
$assign1 = $this->create_instance(['course' => $course]);
$assign2 = $this->create_instance(['course' => $course]);
$assigncontext1 = $assign1->get_context();
$assigncontext2 = $assign2->get_context();
$user1comment = 'Comment from user 1';
list($plugin, $submission, $comment) = $this->create_comment_submission($assign1, $user1, $user1comment);
$user2comment = 'From user 2';
$this->setUser($user2);
$comment->add($user2comment);
$user3comment = 'User 3 comment';
$this->setUser($user3);
$comment->add($user3comment);
$user4comment = 'Comment from user 4';
list($plugin, $submission, $comment) = $this->create_comment_submission($assign2, $user4, $user4comment);
$user3secondcomment = 'Comment on user 4 post.';
$this->setUser($user3);
$comment->add($user3comment);
// There should be three entries. One for the first three users.
$results = $DB->get_records('comments', ['contextid' => $assigncontext1->id]);
$this->assertCount(3, $results);
$deletedata = new \mod_assign\privacy\assign_plugin_request_data($assigncontext1, $assign1);
$deletedata->set_userids([$user1->id, $user3->id]);
\assignsubmission_comments\privacy\provider::delete_submissions($deletedata);
// We should be left with just a comment from user 2.
$results = $DB->get_records('comments', ['contextid' => $assigncontext1->id]);
$this->assertCount(1, $results);
$this->assertEquals($user2comment, current($results)->content);
}
}
@@ -0,0 +1,29 @@
<?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 version information for the comments submission plugin
*
* @package assignsubmission_comments
* @copyright 2012 NetSpot {@link http://www.netspot.com.au}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2024042200;
$plugin->requires = 2024041600;
$plugin->component = 'assignsubmission_comments';