Skip to content

Commit f2a6133

Browse files
committed
Begin develop subscription like forum.
1 parent bfe5038 commit f2a6133

22 files changed

+1758
-105
lines changed

backup/moodle2/backup_pdfannotator_stepslib.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ protected function define_structure() {
5555
// 2. Define each element separately.
5656
$pdfannotator = new backup_nested_element('pdfannotator', array('id'), array(
5757
'name', 'intro', 'introformat', 'usevotes', 'useprint', 'useprintcomments', 'use_studenttextbox', 'use_studentdrawing',
58-
'useprivatecomments', 'useprotectedcomments', 'timecreated', 'timemodified'));
58+
'useprivatecomments', 'useprotectedcomments', 'forcesubscribe', 'timecreated', 'timemodified'));
5959

6060
$annotations = new backup_nested_element('annotations');
6161
$annotation = new backup_nested_element('annotation', array('id'), array('page', 'userid', 'annotationtypeid',
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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+
* A type of pdfannotator.
19+
*
20+
* @package mod_pdfannotator
21+
* @copyright 2021 Luca Bösch <luca.boesch@bfh.ch>
22+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23+
*/
24+
25+
defined('MOODLE_INTERNAL') || die();
26+
27+
require_once($CFG->dirroot.'/user/selector/lib.php');
28+
29+
/**
30+
* User selector control for removing subscribed users
31+
* @package mod_pdfannotator
32+
* @copyright 2021 Luca Bösch <luca.boesch@bfh.ch>
33+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
34+
*/
35+
class mod_pdfannotator_existing_subscriber_selector extends mod_pdfannotator_subscriber_selector_base {
36+
37+
/**
38+
* Finds all subscribed users
39+
*
40+
* @param string $search
41+
* @return array
42+
*/
43+
public function find_users($search) {
44+
global $DB;
45+
list($wherecondition, $params) = $this->search_sql($search, 'u');
46+
$params['pdfannotatorid'] = $this->pdfannotatorid;
47+
48+
// Only active enrolled or everybody on the frontpage.
49+
list($esql, $eparams) = get_enrolled_sql($this->context, '', $this->currentgroup, true);
50+
$fields = $this->required_fields_sql('u');
51+
list($sort, $sortparams) = users_order_by_sql('u', $search, $this->accesscontext);
52+
$params = array_merge($params, $eparams, $sortparams);
53+
54+
$subscribers = $DB->get_records_sql("SELECT $fields
55+
FROM {user} u
56+
JOIN ($esql) je ON je.id = u.id
57+
JOIN {pdfannotator_subscriptions} s ON s.userid = u.id
58+
WHERE $wherecondition AND s.pdfannotator = :pdfannotatorid
59+
ORDER BY $sort", $params);
60+
61+
$cm = get_coursemodule_from_instance('pdfannotator', $this->pdfannotatorid);
62+
$modinfo = get_fast_modinfo($cm->course);
63+
$info = new \core_availability\info_module($modinfo->get_cm($cm->id));
64+
$subscribers = $info->filter_user_list($subscribers);
65+
66+
return array(get_string("existingsubscribers", 'pdfannotator') => $subscribers);
67+
}
68+
69+
}

classes/output/comment.php

Lines changed: 94 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,29 @@
2929
*/
3030
class 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
}

classes/output/index.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class index implements \renderable, \templatable { // Class should be placed els
4444
private $printurl;
4545
private $useprivatecomments;
4646
private $useprotectedcomments;
47+
private $forcesubscribe;
4748

4849
public function __construct($pdfannotator, $capabilities, $file) {
4950

@@ -55,6 +56,7 @@ public function __construct($pdfannotator, $capabilities, $file) {
5556
$this->useprintcomments = ($pdfannotator->useprintcomments || $capabilities->useprintcomments);
5657
$this->useprivatecomments = $pdfannotator->useprivatecomments;
5758
$this->useprotectedcomments = $pdfannotator->useprotectedcomments;
59+
$this->forcesubscribe = $pdfannotator->forcesubscribe;
5860

5961
$contextid = $file->get_contextid();
6062
$component = $file->get_component();
@@ -85,6 +87,7 @@ public function export_for_template(\renderer_base $output) {
8587
if ($data->useprivatecomments) {
8688
$data->privatehelpicon = $OUTPUT->help_icon('private_comments', 'mod_pdfannotator');
8789
}
90+
$data->forcesubscribe = $this->forcesubscribe;
8891
$data->printlink = $this->printurl;
8992
$data->pixprintdoc = $OUTPUT->image_url('download', 'mod_pdfannotator');
9093
$data->pixprintcomments = $OUTPUT->image_url('print_comments', 'mod_pdfannotator');

0 commit comments

Comments
 (0)