2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 * This file contains the definition for the library class for online comment submission plugin
20 * @package assignsubmission_comments
21 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 defined('MOODLE_INTERNAL') || die();
27 require_once($CFG->dirroot . '/comment/lib.php');
28 require_once($CFG->dirroot . '/mod/assign/submissionplugin.php');
31 * Library class for comment submission plugin extending submission plugin base class
33 * @package assignsubmission_comments
34 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
35 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37 class assign_submission_comments extends assign_submission_plugin {
40 * Get the name of the online comment submission plugin
43 public function get_name() {
44 return get_string('pluginname', 'assignsubmission_comments');
48 * Display AJAX based comment in the submission status table
50 * @param stdClass $submission
51 * @param bool $showviewlink - If the comments are long this is
52 * set to true so they can be shown in a separate page
55 public function view_summary(stdClass $submission, & $showviewlink) {
57 // Never show a link to view full submission.
58 $showviewlink = false;
59 // Need to used this init() otherwise it does not have the javascript includes.
62 $options = new stdClass();
63 $options->area = 'submission_comments';
64 $options->course = $this->assignment->get_course();
65 $options->context = $this->assignment->get_context();
66 $options->itemid = $submission->id;
67 $options->component = 'assignsubmission_comments';
68 $options->showcount = true;
69 $options->displaycancel = true;
71 $comment = new comment($options);
72 $comment->set_view_permission(true);
74 return $comment->output(true);
78 * Always return true because the submission comments are not part of the submission form.
80 * @param stdClass $submission
83 public function is_empty(stdClass $submission) {
88 * Return true if this plugin can upgrade an old Moodle 2.2 assignment of this type
91 * @param string $type old assignment subtype
92 * @param int $version old assignment version
93 * @return bool True if upgrade is possible
95 public function can_upgrade($type, $version) {
97 if ($type == 'upload' && $version >= 2011112900) {
105 * Upgrade the settings from the old assignment to the new plugin based one
107 * @param context $oldcontext - the context for the old assignment
108 * @param stdClass $oldassignment - the data for the old assignment
109 * @param string $log - can be appended to by the upgrade
110 * @return bool was it a success? (false will trigger a rollback)
112 public function upgrade_settings(context $oldcontext, stdClass $oldassignment, & $log) {
113 if ($oldassignment->assignmenttype == 'upload') {
114 // Disable if allow notes was not enabled.
115 if (!$oldassignment->var2) {
123 * Upgrade the submission from the old assignment to the new one
125 * @param context $oldcontext The context for the old assignment
126 * @param stdClass $oldassignment The data record for the old assignment
127 * @param stdClass $oldsubmission The data record for the old submission
128 * @param stdClass $submission The new submission record
129 * @param string $log Record upgrade messages in the log
130 * @return bool true or false - false will trigger a rollback
132 public function upgrade(context $oldcontext,
133 stdClass $oldassignment,
134 stdClass $oldsubmission,
135 stdClass $submission,
138 if ($oldsubmission->data1 != '') {
140 // Need to used this init() otherwise it does not have the javascript includes.
143 $options = new stdClass();
144 $options->area = 'submission_comments_upgrade';
145 $options->course = $this->assignment->get_course();
146 $options->context = $this->assignment->get_context();
147 $options->itemid = $submission->id;
148 $options->component = 'assignsubmission_comments';
149 $options->showcount = true;
150 $options->displaycancel = true;
152 $comment = new comment($options);
153 $comment->add($oldsubmission->data1);
154 $comment->set_view_permission(true);
156 return $comment->output(true);
163 * The submission comments plugin has no submission component so should not be counted
164 * when determining whether to show the edit submission link.
167 public function allow_submissions() {
172 * If blind marking is enabled then disable this plugin (it shows names)
176 public function is_enabled() {
177 if ($this->assignment->has_instance() && $this->assignment->is_blind_marking()) {
180 return parent::is_enabled();