Skip to content

Commit

Permalink
Pdfannotator comment subscription like forum fixes #20.
Browse files Browse the repository at this point in the history
The subscription setting will distinguish between optional
subscription, auto subscription, forced subscription and
subscription disabled for comments, auto subscription being the
default as it has been up to now.
If disabled or forced, no subscribe/unsubscribe menu entry is
shown.
Contrary to forum if you change this in hindsight, for
example it will not subscribe or unsubscribe all person
who have subscribed/unsubscribed to a comment.
Also, Behat tests are introduced hereby.
  • Loading branch information
lucaboesch committed Nov 30, 2021
1 parent 2c4329d commit df6803a
Show file tree
Hide file tree
Showing 19 changed files with 1,409 additions and 75 deletions.
2 changes: 1 addition & 1 deletion backup/moodle2/backup_pdfannotator_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ protected function define_structure() {
// 2. Define each element separately.
$pdfannotator = new backup_nested_element('pdfannotator', array('id'), array(
'name', 'intro', 'introformat', 'usevotes', 'useprint', 'useprintcomments', 'use_studenttextbox', 'use_studentdrawing',
'useprivatecomments', 'useprotectedcomments', 'timecreated', 'timemodified'));
'useprivatecomments', 'useprotectedcomments', 'forcesubscribe', 'timecreated', 'timemodified'));

$annotations = new backup_nested_element('annotations');
$annotation = new backup_nested_element('annotation', array('id'), array('page', 'userid', 'annotationtypeid',
Expand Down
130 changes: 94 additions & 36 deletions classes/output/comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,29 @@
*/
class comment implements \renderable, \templatable {

/**
* @var array An array of comments
*/
private $comments = [];

/**
* @var bool Visibility of a question
*/
private $questionvisibility;

/**
* Constructor of renderable for comments.
*
* @param object $data Comment or array of comments
* @param object $cm Course module
* @param stdClass $data Comment or array of comments
* @param stdClass $cm course module object
* @param object $context Context
* @return type
*/
public function __construct($data, $cm, $context) {
global $USER;

if (!is_array($data)) {
$data = [$data];
}

$report = has_capability('mod/pdfannotator:report', $context);
$closequestion = has_capability('mod/pdfannotator:closequestion', $context);
$closeanyquestion = has_capability('mod/pdfannotator:closeanyquestion', $context);
Expand Down Expand Up @@ -83,7 +88,7 @@ public function __construct($data, $cm, $context) {
$this->addeditbutton($comment, $editanypost);
$this->addhidebutton($comment, $seehiddencomments, $hidecomments);
$this->adddeletebutton($comment, $deleteown, $deleteany);
$this->addsubscribebutton($comment, $subscribe);
$this->addsubscribebutton($comment, $subscribe, $cm);
$this->addforwardbutton($comment, $forwardquestions, $cm);
$this->addmarksolvedbutton($comment, $solve);

Expand All @@ -94,8 +99,8 @@ public function __construct($data, $cm, $context) {
}

if (!empty($comment->modifiedby) && ($comment->modifiedby != $comment->userid) && ($comment->userid != 0)) {
$comment->modifiedby = get_string('modifiedby', 'pdfannotator') . ' '.
pdfannotator_get_username($comment->modifiedby);
$comment->modifiedby = get_string('modifiedby', 'pdfannotator') . ' ' .
pdfannotator_get_username($comment->modifiedby);
} else {
$comment->modifiedby = null;
}
Expand All @@ -112,15 +117,22 @@ public function __construct($data, $cm, $context) {
/**
* This function is required by any renderer to retrieve the data structure
* passed into the template.
*
* @param \renderer_base $output
* @return type
* @return stdClass
*/
public function export_for_template(\renderer_base $output) {
$data = [];
$data['comments'] = $this->comments;
return $data;
}

/**
* Add css class to a comment
*
* @param object $comment
* @param bool $owner
*/
private function addcssclasses($comment, $owner) {
$comment->wrapperClass = 'chat-message comment-list-item';
if ($comment->isquestion) {
Expand All @@ -136,6 +148,12 @@ private function addcssclasses($comment, $owner) {
}
}

/**
* Set votes to a comment
*
* @param object $comment
* @throws \coding_exception
*/
public function setvotes($comment) {
if ($comment->usevotes && !$comment->isdeleted) {
if ($comment->owner) {
Expand Down Expand Up @@ -163,7 +181,8 @@ public function setvotes($comment) {

/**
* Add check icon if comment is marked as correct.
* @param type $comment
*
* @param object $comment
*/
public function addsolvedicon($comment) {
if ($comment->solved) {
Expand All @@ -179,9 +198,10 @@ public function addsolvedicon($comment) {

/**
* Report comment if user is not the owner.
* @param type $comment
* @param type $owner
* @param type $report
*
* @param object $comment
* @param bool $report
* @param stdClass $cm course module object
*/
private function addreportbutton($comment, $report, $cm) {
if (!$comment->isdeleted && $report && !$comment->owner && !isset($comment->type)) {
Expand All @@ -193,10 +213,11 @@ private function addreportbutton($comment, $report, $cm) {

/**
* Open/close question if user is owner of the question or manager.
* @param type $comment
* @param type $owner
* @param type $closequestion
* @param type $closeanyquestion
*
* @param object $comment
* @param bool $closequestion
* @param bool $closeanyquestion
* @throws \coding_exception
*/
private function addcloseopenbutton($comment, $closequestion, $closeanyquestion) {

Expand All @@ -215,9 +236,10 @@ private function addcloseopenbutton($comment, $closequestion, $closeanyquestion)

/**
* Button for editing comment if user is owner of the comment or manager.
* @param type $comment
* @param type $owner
* @param type $editanypost
*
* @param object $comment
* @param bool $editanypost
* @throws \coding_exception
*/
private function addeditbutton($comment, $editanypost) {
if (!$comment->isdeleted && !isset($comment->type) && ($comment->owner || $editanypost)) {
Expand All @@ -228,6 +250,14 @@ private function addeditbutton($comment, $editanypost) {
}
}

/**
* Add a hide button
*
* @param object $comment
* @param bool $seehiddencomments
* @param bool $hidecomments
* @throws \coding_exception
*/
private function addhidebutton($comment, $seehiddencomments, $hidecomments) {
// Don't need to hide personal notes.
if ($this->questionvisibility == 'private') {
Expand Down Expand Up @@ -257,32 +287,53 @@ private function addhidebutton($comment, $seehiddencomments, $hidecomments) {

/**
* Delete comment if user is owner of the comment or manager.
* @param type $comment
* @param type $owner
* @param type $deleteown
* @param type $deleteany
*
* @param object $comment
* @param bool $deleteown
* @param bool $deleteany
* @throws \coding_exception
*/
private function adddeletebutton($comment, $deleteown, $deleteany) {
if (!$comment->isdeleted && ($deleteany || ($deleteown && $comment->owner))) {
$comment->buttons[] = ["classes" => "comment-delete-a", "text" => get_string('delete', 'pdfannotator'),
"moodleicon" => ["key" => "delete", "component" => "pdfannotator",
"title" => get_string('delete', 'pdfannotator')]];
"title" => get_string('delete', 'pdfannotator')]];
}
}

private function addsubscribebutton($comment, $subscribe) {
/**
* Add a subscribe button
*
* @param object $comment
* @param bool $subscribe
* @param stdClass $cm course module object
* @throws \coding_exception
*/
private function addsubscribebutton($comment, $subscribe, $cm) {
if (!isset($comment->type) && $comment->isquestion && $subscribe && $comment->visibility != 'private') {
// Only set for textbox and drawing.
if (!empty($comment->issubscribed)) {
$comment->buttons[] = ["classes" => "comment-subscribe-a", "faicon" => ["class" => "fa-bell-slash"],
"text" => get_string('unsubscribeQuestion', 'pdfannotator')];
} else {
$comment->buttons[] = ["classes" => "comment-subscribe-a", "faicon" => ["class" => "fa-bell"],
"text" => get_string('subscribeQuestion', 'pdfannotator')];
// Only set for textbox and drawing, and only if subscription mode is not disabled or forced.
if ((pdfannotator_get_subscriptionmode($cm->instance) == PDFANNOTATOR_CHOOSESUBSCRIBE) ||
(pdfannotator_get_subscriptionmode($cm->instance) == PDFANNOTATOR_INITIALSUBSCRIBE)) {
if (!empty($comment->issubscribed)) {
$comment->buttons[] = ["classes" => "comment-subscribe-a", "faicon" => ["class" => "fa-bell-slash"],
"text" => get_string('unsubscribeQuestion', 'pdfannotator')];
} else {
$comment->buttons[] = ["classes" => "comment-subscribe-a", "faicon" => ["class" => "fa-bell"],
"text" => get_string('subscribeQuestion', 'pdfannotator')];
}
}
}
}

/**
* Add a forward button
*
* @param object $comment
* @param bool $forwardquestions
* @param stdClass $cm course module object
* @throws \coding_exception
* @throws \moodle_exception
*/
private function addforwardbutton($comment, $forwardquestions, $cm) {
if (!isset($comment->type) && $comment->isquestion && !$comment->isdeleted && $forwardquestions &&
$comment->visibility != 'private') {
Expand All @@ -291,22 +342,29 @@ private function addforwardbutton($comment, $forwardquestions, $cm) {
$url = new moodle_url($CFG->wwwroot . '/mod/pdfannotator/view.php', $urlparams);

$comment->buttons[] = ["classes" => "comment-forward-a", "attributes" => ["name" => "onclick",
"value" => "window.location.href = '$url';"], "faicon" => ["class" => "fa-share"],
"text" => get_string('forward', 'pdfannotator')];
"value" => "window.location.href = '$url';"],
"faicon" => ["class" => "fa-share"], "text" => get_string('forward', 'pdfannotator')];
}
}

/**
* Add a Mark as correct or a Remove mark as correct button
*
* @param object $comment
* @param bool $solve
* @throws \coding_exception
*/
private function addmarksolvedbutton($comment, $solve) {
if ($solve && !$comment->isquestion && !$comment->isdeleted && !isset($comment->type) &&
$this->questionvisibility != 'private') {
if ($comment->solved) {
$comment->buttons[] = ["classes" => "comment-solve-a", "text" => get_string('removeCorrect', 'pdfannotator'),
"moodleicon" => ["key" => "i/completion-manual-n", "component" => "core",
"title" => get_string('removeCorrect', 'pdfannotator')]];
"title" => get_string('removeCorrect', 'pdfannotator')]];
} else {
$comment->buttons[] = ["classes" => "comment-solve-a", "text" => get_string('markCorrect', 'pdfannotator'),
"moodleicon" => ["key" => "i/completion-manual-enabled", "component" => "core",
"title" => get_string('markCorrect', 'pdfannotator')]];
"title" => get_string('markCorrect', 'pdfannotator')]];
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions classes/output/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class index implements \renderable, \templatable { // Class should be placed els
private $printurl;
private $useprivatecomments;
private $useprotectedcomments;
private $forcesubscribe;

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

Expand All @@ -55,6 +56,7 @@ public function __construct($pdfannotator, $capabilities, $file) {
$this->useprintcomments = ($pdfannotator->useprintcomments || $capabilities->useprintcomments);
$this->useprivatecomments = $pdfannotator->useprivatecomments;
$this->useprotectedcomments = $pdfannotator->useprotectedcomments;
$this->forcesubscribe = $pdfannotator->forcesubscribe;

$contextid = $file->get_contextid();
$component = $file->get_component();
Expand Down Expand Up @@ -85,6 +87,7 @@ public function export_for_template(\renderer_base $output) {
if ($data->useprivatecomments) {
$data->privatehelpicon = $OUTPUT->help_icon('private_comments', 'mod_pdfannotator');
}
$data->forcesubscribe = $this->forcesubscribe;
$data->printlink = $this->printurl;
$data->pixprintdoc = $OUTPUT->image_url('download', 'mod_pdfannotator');
$data->pixprintcomments = $OUTPUT->image_url('print_comments', 'mod_pdfannotator');
Expand Down
Loading

0 comments on commit df6803a

Please sign in to comment.