MDL-31284: Fix for plugin summary display in grading table with team submissions
[moodle.git] / mod / assign / submission / comments / locallib.php
CommitLineData
bbd0e548
DW
1<?php
2// This file is part of Moodle - http://moodle.org/
3//
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.
8//
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.
13//
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/>.
16
17/**
18 * This file contains the definition for the library class for online comment submission plugin
19 *
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
23 */
24
25 defined('MOODLE_INTERNAL') || die();
26
27 /** Include comment core lib.php */
28 require_once($CFG->dirroot . '/comment/lib.php');
29 /** Include submissionplugin.php */
30 require_once($CFG->dirroot . '/mod/assign/submissionplugin.php');
31
32/**
33 * library class for comment submission plugin extending submission plugin base class
34 *
35 * @package assignsubmission_comments
36 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
37 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
38 */
39class assign_submission_comments extends assign_submission_plugin {
40
41 /**
42 * get the name of the online comment submission plugin
43 * @return string
44 */
45 public function get_name() {
46 return get_string('pluginname', 'assignsubmission_comments');
47 }
48
49 /**
50 * display AJAX based comment in the submission status table
51 *
52 * @param stdClass $submission
53 * @param bool $showviewlink - If the comments are long this is set to true so they can be shown in a separate page
54 * @return string
55 */
7ee1548a 56 public function view_summary(stdClass $submission, & $showviewlink) {
bbd0e548
DW
57
58 // never show a link to view full submission
59 $showviewlink = false;
60 // need to used this init() otherwise it shows up undefined !
61 // require js for commenting
62 comment::init();
63
64 $options = new stdClass();
65 $options->area = 'submission_comments';
66 $options->course = $this->assignment->get_course();
67 $options->context = $this->assignment->get_context();
68 $options->itemid = $submission->id;
69 $options->component = 'assignsubmission_comments';
70 $options->showcount = true;
71 $options->displaycancel = true;
72
73 $comment = new comment($options);
74 $comment->set_view_permission(true);
75
76 return $comment->output(true);
77
78 }
79
80 /**
81 * Always return false because at a minimum there is the comments control
82 * @param stdClass $submission
83 * @return bool
84 */
85 public function is_empty(stdClass $submission) {
86 return false;
87 }
88
89 /**
90 * Return true if this plugin can upgrade an old Moodle 2.2 assignment of this type
91 * and version.
92 *
93 * @param string $type old assignment subtype
94 * @param int $version old assignment version
95 * @return bool True if upgrade is possible
96 */
97 public function can_upgrade($type, $version) {
98
99 if ($type == 'upload' && $version >= 2011112900) {
100 return true;
101 }
102 return false;
103 }
104
105
106 /**
107 * Upgrade the settings from the old assignment to the new plugin based one
108 *
109 * @param context $oldcontext - the context for the old assignment
110 * @param stdClass $oldassignment - the data for the old assignment
111 * @param string $log - can be appended to by the upgrade
112 * @return bool was it a success? (false will trigger a rollback)
113 */
114 public function upgrade_settings(context $oldcontext, stdClass $oldassignment, & $log) {
115 // first upgrade settings (nothing to do)
116 return true;
117 }
118
119 /**
120 * Upgrade the submission from the old assignment to the new one
121 *
122 * @param context $oldcontext The context for the old assignment
123 * @param stdClass $oldassignment The data record for the old assignment
124 * @param stdClass $oldsubmission The data record for the old submission
125 * @param stdClass $submission The new submission record
126 * @param string $log Record upgrade messages in the log
127 * @return bool true or false - false will trigger a rollback
128 */
129 public function upgrade(context $oldcontext, stdClass $oldassignment, stdClass $oldsubmission, stdClass $submission, & $log) {
130
131 if ($oldsubmission->data1 != '') {
132
133 // need to used this innit() otherwise it shows up undefined !
134 // require js for commenting
135 comment::init();
136
137 $options = new stdClass();
138 $options->area = 'submission_comments_upgrade';
139 $options->course = $this->assignment->get_course();
140 $options->context = $this->assignment->get_context();
141 $options->itemid = $submission->id;
142 $options->component = 'assignsubmission_comments';
143 $options->showcount = true;
144 $options->displaycancel = true;
145
146 $comment = new comment($options);
147 $comment->add($oldsubmission->data1);
148 $comment->set_view_permission(true);
149
150
151 return $comment->output(true);
152 }
153
154
155 return true;
156 }
157
158 /**
159 * The submission comments plugin has no submission component so should not be counted
160 * when determining whether to show the edit submission link.
161 * @return boolean
162 */
163 public function allow_submissions() {
164 return false;
165 }
166
167}