2929 */
3030class comment implements \renderable, \templatable {
3131
32+ /**
33+ * @var array An array of comments
34+ */
3235 private $ comments = [];
36+
37+ /**
38+ * @var bool Visibility of a question
39+ */
3340 private $ questionvisibility ;
3441
3542 /**
3643 * Constructor of renderable for comments.
3744 *
38- * @param object $data Comment or array of comments
39- * @param object $cm Course module
45+ * @param stdClass $data Comment or array of comments
46+ * @param stdClass $cm course module object
4047 * @param object $context Context
41- * @return type
4248 */
4349 public function __construct ($ data , $ cm , $ context ) {
4450 global $ USER ;
4551
4652 if (!is_array ($ data )) {
4753 $ data = [$ data ];
4854 }
49-
5055 $ report = has_capability ('mod/pdfannotator:report ' , $ context );
5156 $ closequestion = has_capability ('mod/pdfannotator:closequestion ' , $ context );
5257 $ closeanyquestion = has_capability ('mod/pdfannotator:closeanyquestion ' , $ context );
@@ -83,7 +88,7 @@ public function __construct($data, $cm, $context) {
8388 $ this ->addeditbutton ($ comment , $ editanypost );
8489 $ this ->addhidebutton ($ comment , $ seehiddencomments , $ hidecomments );
8590 $ this ->adddeletebutton ($ comment , $ deleteown , $ deleteany );
86- $ this ->addsubscribebutton ($ comment , $ subscribe );
91+ $ this ->addsubscribebutton ($ comment , $ subscribe, $ cm );
8792 $ this ->addforwardbutton ($ comment , $ forwardquestions , $ cm );
8893 $ this ->addmarksolvedbutton ($ comment , $ solve );
8994
@@ -94,8 +99,8 @@ public function __construct($data, $cm, $context) {
9499 }
95100
96101 if (!empty ($ comment ->modifiedby ) && ($ comment ->modifiedby != $ comment ->userid ) && ($ comment ->userid != 0 )) {
97- $ comment ->modifiedby = get_string ('modifiedby ' , 'pdfannotator ' ) . ' ' .
98- pdfannotator_get_username ($ comment ->modifiedby );
102+ $ comment ->modifiedby = get_string ('modifiedby ' , 'pdfannotator ' ) . ' ' .
103+ pdfannotator_get_username ($ comment ->modifiedby );
99104 } else {
100105 $ comment ->modifiedby = null ;
101106 }
@@ -112,15 +117,22 @@ public function __construct($data, $cm, $context) {
112117 /**
113118 * This function is required by any renderer to retrieve the data structure
114119 * passed into the template.
120+ *
115121 * @param \renderer_base $output
116- * @return type
122+ * @return stdClass
117123 */
118124 public function export_for_template (\renderer_base $ output ) {
119125 $ data = [];
120126 $ data ['comments ' ] = $ this ->comments ;
121127 return $ data ;
122128 }
123129
130+ /**
131+ * Add css class to a comment
132+ *
133+ * @param object $comment
134+ * @param bool $owner
135+ */
124136 private function addcssclasses ($ comment , $ owner ) {
125137 $ comment ->wrapperClass = 'chat-message comment-list-item ' ;
126138 if ($ comment ->isquestion ) {
@@ -136,6 +148,12 @@ private function addcssclasses($comment, $owner) {
136148 }
137149 }
138150
151+ /**
152+ * Set votes to a comment
153+ *
154+ * @param object $comment
155+ * @throws \coding_exception
156+ */
139157 public function setvotes ($ comment ) {
140158 if ($ comment ->usevotes && !$ comment ->isdeleted ) {
141159 if ($ comment ->owner ) {
@@ -163,7 +181,8 @@ public function setvotes($comment) {
163181
164182 /**
165183 * Add check icon if comment is marked as correct.
166- * @param type $comment
184+ *
185+ * @param object $comment
167186 */
168187 public function addsolvedicon ($ comment ) {
169188 if ($ comment ->solved ) {
@@ -179,9 +198,10 @@ public function addsolvedicon($comment) {
179198
180199 /**
181200 * Report comment if user is not the owner.
182- * @param type $comment
183- * @param type $owner
184- * @param type $report
201+ *
202+ * @param object $comment
203+ * @param bool $report
204+ * @param stdClass $cm course module object
185205 */
186206 private function addreportbutton ($ comment , $ report , $ cm ) {
187207 if (!$ comment ->isdeleted && $ report && !$ comment ->owner && !isset ($ comment ->type )) {
@@ -193,10 +213,11 @@ private function addreportbutton($comment, $report, $cm) {
193213
194214 /**
195215 * Open/close question if user is owner of the question or manager.
196- * @param type $comment
197- * @param type $owner
198- * @param type $closequestion
199- * @param type $closeanyquestion
216+ *
217+ * @param object $comment
218+ * @param bool $closequestion
219+ * @param bool $closeanyquestion
220+ * @throws \coding_exception
200221 */
201222 private function addcloseopenbutton ($ comment , $ closequestion , $ closeanyquestion ) {
202223
@@ -215,9 +236,10 @@ private function addcloseopenbutton($comment, $closequestion, $closeanyquestion)
215236
216237 /**
217238 * Button for editing comment if user is owner of the comment or manager.
218- * @param type $comment
219- * @param type $owner
220- * @param type $editanypost
239+ *
240+ * @param object $comment
241+ * @param bool $editanypost
242+ * @throws \coding_exception
221243 */
222244 private function addeditbutton ($ comment , $ editanypost ) {
223245 if (!$ comment ->isdeleted && !isset ($ comment ->type ) && ($ comment ->owner || $ editanypost )) {
@@ -228,6 +250,14 @@ private function addeditbutton($comment, $editanypost) {
228250 }
229251 }
230252
253+ /**
254+ * Add a hide button
255+ *
256+ * @param object $comment
257+ * @param bool $seehiddencomments
258+ * @param bool $hidecomments
259+ * @throws \coding_exception
260+ */
231261 private function addhidebutton ($ comment , $ seehiddencomments , $ hidecomments ) {
232262 // Don't need to hide personal notes.
233263 if ($ this ->questionvisibility == 'private ' ) {
@@ -257,32 +287,53 @@ private function addhidebutton($comment, $seehiddencomments, $hidecomments) {
257287
258288 /**
259289 * Delete comment if user is owner of the comment or manager.
260- * @param type $comment
261- * @param type $owner
262- * @param type $deleteown
263- * @param type $deleteany
290+ *
291+ * @param object $comment
292+ * @param bool $deleteown
293+ * @param bool $deleteany
294+ * @throws \coding_exception
264295 */
265296 private function adddeletebutton ($ comment , $ deleteown , $ deleteany ) {
266297 if (!$ comment ->isdeleted && ($ deleteany || ($ deleteown && $ comment ->owner ))) {
267298 $ comment ->buttons [] = ["classes " => "comment-delete-a " , "text " => get_string ('delete ' , 'pdfannotator ' ),
268299 "moodleicon " => ["key " => "delete " , "component " => "pdfannotator " ,
269- "title " => get_string ('delete ' , 'pdfannotator ' )]];
300+ "title " => get_string ('delete ' , 'pdfannotator ' )]];
270301 }
271302 }
272303
273- private function addsubscribebutton ($ comment , $ subscribe ) {
304+ /**
305+ * Add a subscribe button
306+ *
307+ * @param object $comment
308+ * @param bool $subscribe
309+ * @param stdClass $cm course module object
310+ * @throws \coding_exception
311+ */
312+ private function addsubscribebutton ($ comment , $ subscribe , $ cm ) {
274313 if (!isset ($ comment ->type ) && $ comment ->isquestion && $ subscribe && $ comment ->visibility != 'private ' ) {
275- // Only set for textbox and drawing.
276- if (!empty ($ comment ->issubscribed )) {
277- $ comment ->buttons [] = ["classes " => "comment-subscribe-a " , "faicon " => ["class " => "fa-bell-slash " ],
278- "text " => get_string ('unsubscribeQuestion ' , 'pdfannotator ' )];
279- } else {
280- $ comment ->buttons [] = ["classes " => "comment-subscribe-a " , "faicon " => ["class " => "fa-bell " ],
281- "text " => get_string ('subscribeQuestion ' , 'pdfannotator ' )];
314+ // Only set for textbox and drawing, and only if subscription mode is not disabled or forced.
315+ if ((pdfannotator_get_subscriptionmode ($ cm ->instance ) == PDFANNOTATOR_CHOOSESUBSCRIBE ) ||
316+ (pdfannotator_get_subscriptionmode ($ cm ->instance ) == PDFANNOTATOR_INITIALSUBSCRIBE )) {
317+ if (!empty ($ comment ->issubscribed )) {
318+ $ comment ->buttons [] = ["classes " => "comment-subscribe-a " , "faicon " => ["class " => "fa-bell-slash " ],
319+ "text " => get_string ('unsubscribeQuestion ' , 'pdfannotator ' )];
320+ } else {
321+ $ comment ->buttons [] = ["classes " => "comment-subscribe-a " , "faicon " => ["class " => "fa-bell " ],
322+ "text " => get_string ('subscribeQuestion ' , 'pdfannotator ' )];
323+ }
282324 }
283325 }
284326 }
285327
328+ /**
329+ * Add a forward button
330+ *
331+ * @param object $comment
332+ * @param bool $forwardquestions
333+ * @param stdClass $cm course module object
334+ * @throws \coding_exception
335+ * @throws \moodle_exception
336+ */
286337 private function addforwardbutton ($ comment , $ forwardquestions , $ cm ) {
287338 if (!isset ($ comment ->type ) && $ comment ->isquestion && !$ comment ->isdeleted && $ forwardquestions &&
288339 $ comment ->visibility != 'private ' ) {
@@ -291,22 +342,29 @@ private function addforwardbutton($comment, $forwardquestions, $cm) {
291342 $ url = new moodle_url ($ CFG ->wwwroot . '/mod/pdfannotator/view.php ' , $ urlparams );
292343
293344 $ comment ->buttons [] = ["classes " => "comment-forward-a " , "attributes " => ["name " => "onclick " ,
294- "value " => "window.location.href = ' $ url'; " ], " faicon " => [ " class " => " fa-share " ],
295- "text " => get_string ('forward ' , 'pdfannotator ' )];
345+ "value " => "window.location.href = ' $ url'; " ],
346+ "faicon " => [ " class " => " fa-share " ], " text " => get_string ('forward ' , 'pdfannotator ' )];
296347 }
297348 }
298349
350+ /**
351+ * Add a Mark as correct or a Remove mark as correct button
352+ *
353+ * @param object $comment
354+ * @param bool $solve
355+ * @throws \coding_exception
356+ */
299357 private function addmarksolvedbutton ($ comment , $ solve ) {
300358 if ($ solve && !$ comment ->isquestion && !$ comment ->isdeleted && !isset ($ comment ->type ) &&
301359 $ this ->questionvisibility != 'private ' ) {
302360 if ($ comment ->solved ) {
303361 $ comment ->buttons [] = ["classes " => "comment-solve-a " , "text " => get_string ('removeCorrect ' , 'pdfannotator ' ),
304362 "moodleicon " => ["key " => "i/completion-manual-n " , "component " => "core " ,
305- "title " => get_string ('removeCorrect ' , 'pdfannotator ' )]];
363+ "title " => get_string ('removeCorrect ' , 'pdfannotator ' )]];
306364 } else {
307365 $ comment ->buttons [] = ["classes " => "comment-solve-a " , "text " => get_string ('markCorrect ' , 'pdfannotator ' ),
308366 "moodleicon " => ["key " => "i/completion-manual-enabled " , "component " => "core " ,
309- "title " => get_string ('markCorrect ' , 'pdfannotator ' )]];
367+ "title " => get_string ('markCorrect ' , 'pdfannotator ' )]];
310368 }
311369 }
312370 }
0 commit comments