diff --git a/action.php b/action.php
index 0efcba60f75ec6356735a7e9af567596d3605372..f5a0b7aed5a92fdafae16e168b46507b011da00e 100644
--- a/action.php
+++ b/action.php
@@ -401,8 +401,12 @@ if ($action === 'getCommentContent') {
$content = $DB->get_field('pdfannotator_comments', 'content', ['id' => $commentid]);
-
- echo json_encode($content);
+ $comment = $DB->get_record('pdfannotator_comments', ['id' => $commentid]);
+ if (pdfannotator_can_see_comment($comment, $context)) {
+ echo json_encode($comment->content);
+ } else {
+ echo json_encode("false");
+ }
}
/* * ****************************************** Hide a comment for participants ****************************************** */
@@ -483,7 +487,7 @@ if ($action === 'subscribeQuestion') {
$annotatorid = $DB->get_field('pdfannotator_annotations', 'pdfannotatorid', ['id' => $annotationid], $strictness = MUST_EXIST);
- $subscriptionid = pdfannotator_comment::insert_subscription($annotationid);
+ $subscriptionid = pdfannotator_comment::insert_subscription($annotationid, $context);
if ($departure == 1) {
$thisannotator = $pdfannotator->id;
diff --git a/controller.php b/controller.php
index 8695c925b9b3c870f7d6d79bd2936dd5e50bea25..4cbd5ea5ca24c11d9e30d990aee93957b7be8605 100644
--- a/controller.php
+++ b/controller.php
@@ -194,7 +194,7 @@ if ($action === 'subscribeQuestion') {
$annotatorid = $DB->get_field('pdfannotator_annotations', 'pdfannotatorid', ['id' => $annotationid], $strictness = MUST_EXIST);
- $subscriptionid = pdfannotator_comment::insert_subscription($annotationid);
+ $subscriptionid = pdfannotator_comment::insert_subscription($annotationid, $context);
if (!empty($subscriptionid)) {
$info = get_string('successfullySubscribed', 'pdfannotator');
diff --git a/lang/en/pdfannotator.php b/lang/en/pdfannotator.php
index 25eb1c859f3043e0a7133d3d3080a0dc7ef050c2..b9b693277fe9d4869aca6d9be823180055dba9fd 100644
--- a/lang/en/pdfannotator.php
+++ b/lang/en/pdfannotator.php
@@ -293,11 +293,14 @@ $string['pdfannotator:usetextbox'] = 'Use textbox (even if the option is disable
$string['pdfannotator:view'] = 'View PDF Annotation';
$string['pdfannotator:viewanswers'] = 'View answers to subscribed questions (overview page)';
$string['pdfannotator:viewposts'] = 'View own comments (overview page)';
+$string['pdfannotator:viewprotectedcomments'] = 'See private comments';
$string['pdfannotator:viewquestions'] = 'View open questions (overview page)';
$string['pdfannotator:viewreports'] = 'View reported comments (overview page)';
$string['pdfannotator:viewstatistics'] = 'View statistics page';
$string['pdfannotator:viewteacherstatistics'] = 'See additional information on statistics page';
$string['pdfannotator:vote'] = "Vote for an interesting question or helpful answer";
+$string['pdfannotator:writeprivatecomments'] = 'Make personal notes';
+$string['pdfannotator:writeprotectedcomments'] = 'Write private comments';
$string['pdfannotator'] = 'Document';
$string['pdfannotatorcolumn'] = 'Document';
$string['pdfannotatorcontent'] = 'Files and subfolders';
diff --git a/locallib.php b/locallib.php
index bf70e9eabffd52c6f955bb22a6cd4aeb623b56ae..79ac2e5a0c714aed5e56dcc1c1784279bb233457 100644
--- a/locallib.php
+++ b/locallib.php
@@ -593,7 +593,7 @@ function pdfannotator_render_action_menu($menu) {
return $OUTPUT->render($menu);
}
-function pdfannotator_subscribe_all($annotatorid) {
+function pdfannotator_subscribe_all($annotatorid, $context) {
global $DB;
$sql = "SELECT id FROM {pdfannotator_annotations} "
. "WHERE pdfannotatorid = ? AND annotationtypeid NOT IN "
@@ -601,7 +601,7 @@ function pdfannotator_subscribe_all($annotatorid) {
$params = [$annotatorid, 'drawing', 'textbox'];
$ids = $DB->get_fieldset_sql($sql, $params);
foreach ($ids as $annotationid) {
- pdfannotator_comment::insert_subscription($annotationid);
+ pdfannotator_comment::insert_subscription($annotationid, $context);
}
}
diff --git a/model/comment.class.php b/model/comment.class.php
index bb5236c568a13622176b93f9412d8073872eeeac..a24eb4d336cceb105be232fe6cdd8727fce3318f 100644
--- a/model/comment.class.php
+++ b/model/comment.class.php
@@ -94,8 +94,8 @@ class pdfannotator_comment {
$messageid = pdfannotator_notify_manager($recipient, $course, $cm, 'newanswer', $messagetext, $anonymous);
}
}
- } else {
- self::insert_subscription($annotationid);
+ } else if ($visibility != 'private') {
+ self::insert_subscription($annotationid, $context);
// Notify all users, that there is a new question.
$recipients = get_enrolled_users($context, 'mod/pdfannotator:recievenewquestionnotifications');
@@ -111,6 +111,9 @@ class pdfannotator_comment {
$messagetext->text = pdfannotator_format_notification_message_text($course, $cm, $context, get_string('modulename', 'pdfannotator'), $modulename, $question, 'newquestion');
$messagetext->url = $question->urltoanswer;
foreach ($recipients as $recipient) {
+ if (!pdfannotator_can_see_comment($datarecord, $context) ){
+ continue;
+ }
if ($recipient->id == $USER->id) {
continue;
}
@@ -160,6 +163,7 @@ class pdfannotator_comment {
$comment->visibility = $data->visibility;
$comment->isquestion = $data->isquestion;
$comment->annotationid = $annotationid;
+ $comment->annotation = $annotationid;
if ( !pdfannotator_can_see_comment($comment, $context)) {
continue;
}
@@ -460,18 +464,24 @@ class pdfannotator_comment {
* @param type $annotationid
* @return boolean
*/
- public static function insert_subscription($annotationid) {
+ public static function insert_subscription($annotationid, $context) {
global $DB, $USER;
// Check if subscription already exists.
if ($DB->record_exists('pdfannotator_subscriptions', array('annotationid' => $annotationid, 'userid' => $USER->id))) {
return false;
}
+
+ $comment = $DB->get_record('pdfannotator_comments', array('annotationid' => $annotationid, 'isquestion' => '1'));
+ if (!pdfannotator_can_see_comment($comment, $context)) {
+ return false;
+ }
$datarecord = new stdClass();
$datarecord->annotationid = $annotationid;
$datarecord->userid = $USER->id;
+
$subscriptionid = $DB->insert_record('pdfannotator_subscriptions', $datarecord, $returnid = true);
return $subscriptionid;
}
diff --git a/shared/index.js b/shared/index.js
index 7b8edc72046fe337419e5cf08aedb9a12eba3988..b44bc2cbe37a569a88f119c459492b3eb8024e63 100644
--- a/shared/index.js
+++ b/shared/index.js
@@ -7455,12 +7455,16 @@ function read_visibility_of_checkbox(){
if (document.querySelector('#anonymousCheckbox').checked) {
commentVisibility = "anonymous";
document.querySelector('#anonymousCheckbox').checked = false;
- } else if (document.querySelector('#privateCheckbox') != null) {
+ }
+
+ if (document.querySelector('#privateCheckbox') != null) {
if (document.querySelector('#privateCheckbox').checked) {
commentVisibility = "private";
document.querySelector('#privateCheckbox').checked = false;
}
- } else if (document.querySelector('#protectedCheckbox') != null) {
+ }
+
+ if (document.querySelector('#protectedCheckbox') != null) {
if (document.querySelector('#protectedCheckbox').checked) {
commentVisibility = "protected";
document.querySelector('#protectedCheckbox').checked = false;