Browse Source

resolved all but 4 more complicated linting/stylecheck issues.

master
Jan Koppe 1 year ago
parent
commit
43c9c57e61
Signed by: j <post@jankoppe.de> GPG Key ID: BE935B0735A2129B
25 changed files with 1439 additions and 1452 deletions
  1. +6
    -3
      action.php
  2. +32
    -31
      backup/moodle2/backup_pdfannotator_stepslib.php
  3. +13
    -7
      backup/moodle2/restore_pdfannotator_stepslib.php
  4. +1
    -1
      classes/event/report_added.php
  5. +12
    -6
      classes/output/comment.php
  6. +106
    -106
      classes/output/index.php
  7. +31
    -67
      classes/privacy/provider.php
  8. +391
    -382
      controller.php
  9. +2
    -2
      db/access.php
  10. +47
    -47
      db/messages.php
  11. +4
    -2
      db/upgrade.php
  12. +1
    -1
      index.php
  13. +7
    -7
      lang/de/pdfannotator.php
  14. +6
    -7
      lang/en/pdfannotator.php
  15. +33
    -60
      lib.php
  16. +78
    -59
      locallib.php
  17. +6
    -7
      mod_form.php
  18. +11
    -27
      model/comment.class.php
  19. +8
    -8
      model/overviewtable.php
  20. +350
    -339
      model/pdfannotator.php
  21. +219
    -204
      model/statistics.class.php
  22. +2
    -1
      renderer.php
  23. +72
    -72
      reportform.php
  24. +0
    -5
      styles.css
  25. +1
    -1
      view.php

+ 6
- 3
action.php View File

@@ -139,7 +139,8 @@ if ($action === 'create') {
$data['height'] = $annotation['height'];
break;
case 'drawing':
$studentdrawingsallowed = $DB->get_field('pdfannotator', 'use_studentdrawing', ['id' => $documentid], $strictness = MUST_EXIST);
$studentdrawingsallowed = $DB->get_field('pdfannotator', 'use_studentdrawing', ['id' => $documentid],
$strictness = MUST_EXIST);
$alwaysdrawingallowed = has_capability('mod/pdfannotator:usedrawing', $context);
if ($studentdrawingsallowed != 1 && !$alwaysdrawingallowed) {
echo json_encode(['status' => 'error', 'reason' => get_string('studentdrawingforbidden', 'pdfannotator')]);
@@ -162,7 +163,8 @@ if ($action === 'create') {
$data['rectangles'] = $annotation['rectangles'];
break;
case 'textbox':
$studenttextboxesallowed = $DB->get_field('pdfannotator', 'use_studenttextbox', array('id' => $documentid), $strictness = MUST_EXIST);
$studenttextboxesallowed = $DB->get_field('pdfannotator', 'use_studenttextbox', array('id' => $documentid),
$strictness = MUST_EXIST);
$alwaystextboxallowed = has_capability('mod/pdfannotator:usetextbox', $context);
if ($studenttextboxesallowed != 1 && !$alwaystextboxallowed) {
echo json_encode(['status' => 'error', 'reason' => get_string('studenttextboxforbidden', 'pdfannotator')]);
@@ -460,7 +462,8 @@ if ($action === 'unsubscribeQuestion') {
$subscriptionid = pdfannotator_comment::delete_subscription($annotationid);

if ($subscriptionid) {
echo json_encode(['status' => 'success', 'annotationid' => $annotationid, 'subscriptionid' => $subscriptionid, 'annotatorid' => $annotatorid]);
echo json_encode(['status' => 'success', 'annotationid' => $annotationid, 'subscriptionid' => $subscriptionid,
'annotatorid' => $annotatorid]);
} else {
echo json_encode(['status' => 'error']);
}


+ 32
- 31
backup/moodle2/backup_pdfannotator_stepslib.php View File

@@ -53,27 +53,32 @@ class backup_pdfannotator_activity_structure_step extends backup_activity_struct

// 2. Define each element separately.
$pdfannotator = new backup_nested_element('pdfannotator', array('id'), array(
'name', 'intro', 'introformat', 'usevotes', 'useprint', 'use_studenttextbox', 'use_studentdrawing', 'timecreated', 'timemodified'));
'name', 'intro', 'introformat', 'usevotes', 'useprint', 'use_studenttextbox', 'use_studentdrawing', 'timecreated',
'timemodified'));

$annotations = new backup_nested_element('annotations');
$annotation = new backup_nested_element('annotation', array('id'), array('page', 'userid', 'annotationtypeid', 'data', 'timecreated', 'timemodified', 'modifiedby'));
$annotations = new backup_nested_element('annotations');
$annotation = new backup_nested_element('annotation', array('id'), array('page', 'userid', 'annotationtypeid', 'data',
'timecreated', 'timemodified', 'modifiedby'));

$subscriptions = new backup_nested_element('subscriptions');
$subscription = new backup_nested_element('subscription', array('id'), array('userid'));
$subscriptions = new backup_nested_element('subscriptions');
$subscription = new backup_nested_element('subscription', array('id'), array('userid'));

$commentsarchive = new backup_nested_element('commentsarchive');
$ca = array('pdfannotatorid', 'userid', 'content', 'timecreated', 'timemodified', 'modifiedby', 'visibility', 'isquestion', 'isdeleted', 'seen');
$commentarchive = new backup_nested_element('commentarchive', array('id'), $ca);
$commentsarchive = new backup_nested_element('commentsarchive');
$ca = array('pdfannotatorid', 'userid', 'content', 'timecreated', 'timemodified', 'modifiedby', 'visibility',
'isquestion', 'isdeleted', 'seen');
$commentarchive = new backup_nested_element('commentarchive', array('id'), $ca);

$comments = new backup_nested_element('comments');
$c = array('pdfannotatorid', 'userid', 'content', 'timecreated', 'timemodified', 'modifiedby', 'visibility', 'isquestion', 'isdeleted', 'seen');
$comment = new backup_nested_element('comment', array('id'), $c);
$comments = new backup_nested_element('comments');
$c = array('pdfannotatorid', 'userid', 'content', 'timecreated', 'timemodified', 'modifiedby', 'visibility',
'isquestion', 'isdeleted', 'seen');
$comment = new backup_nested_element('comment', array('id'), $c);

$votes = new backup_nested_element('votes');
$vote = new backup_nested_element('vote', array('id'), array('userid', 'annotationid'));
$votes = new backup_nested_element('votes');
$vote = new backup_nested_element('vote', array('id'), array('userid', 'annotationid'));

$reports = new backup_nested_element('reports');
$report = new backup_nested_element('report', array('id'), array('courseid', 'pdfannotatorid', 'message', 'userid', 'timecreated', 'seen'));
$reports = new backup_nested_element('reports');
$report = new backup_nested_element('report', array('id'), array('courseid', 'pdfannotatorid', 'message',
'userid', 'timecreated', 'seen'));

// 3. Build the tree (mind the right order!)
$pdfannotator->add_child($annotations);
@@ -98,27 +103,23 @@ class backup_pdfannotator_activity_structure_step extends backup_activity_struct
// backup::VAR_ACTIVITYID is the 'course module id'.
$pdfannotator->set_source_table('pdfannotator', array('id' => backup::VAR_ACTIVITYID));

// ... if ($userinfo) {?
// Add all annotations specific to this annotator instance.
$annotation->set_source_table('pdfannotator_annotations', array('pdfannotatorid' => backup::VAR_PARENTID));

// Add all annotations specific to this annotator instance.
$annotation->set_source_table('pdfannotator_annotations', array('pdfannotatorid' => backup::VAR_PARENTID));
// Add any subscriptions to this annotation.
$subscription->set_source_table('pdfannotator_subscriptions', array('annotationid' => backup::VAR_PARENTID));

// Add any subscriptions to this annotation.
$subscription->set_source_table('pdfannotator_subscriptions', array('annotationid' => backup::VAR_PARENTID));
// Add any archived comments on the annotation.
$commentarchive->set_source_table('pdfannotator_commentsarchive', array('annotationid' => backup::VAR_PARENTID));

// Add any archived comments on the annotation.
$commentarchive->set_source_table('pdfannotator_commentsarchive', array('annotationid' => backup::VAR_PARENTID));
// Add any comments of this annotation.
$comment->set_source_table('pdfannotator_comments', array('annotationid' => backup::VAR_PARENTID));

// Add any comments of this annotation.
$comment->set_source_table('pdfannotator_comments', array('annotationid' => backup::VAR_PARENTID));
// Add any votes for this comment.
$vote->set_source_table('pdfannotator_votes', array('commentid' => backup::VAR_PARENTID));

// Add any votes for this comment.
$vote->set_source_table('pdfannotator_votes', array('commentid' => backup::VAR_PARENTID));

// Add any reports of this comment.
$report->set_source_table('pdfannotator_reports', array('commentid' => backup::VAR_PARENTID));

// ... }?
// Add any reports of this comment.
$report->set_source_table('pdfannotator_reports', array('commentid' => backup::VAR_PARENTID));

// 5. Define id annotations (some attributes are foreign keys).
$annotation->annotate_ids('user', 'userid');


+ 13
- 7
backup/moodle2/restore_pdfannotator_stepslib.php View File

@@ -48,12 +48,17 @@ class restore_pdfannotator_activity_structure_step extends restore_activity_stru

$paths[] = new restore_path_element('pdfannotator_annotation', '/activity/pdfannotator/annotations/annotation');

$paths[] = new restore_path_element('pdfannotator_subscription', '/activity/pdfannotator/annotations/annotation/subscriptions/subscription');
$paths[] = new restore_path_element('pdfannotator_commentarchive', '/activity/pdfannotator/annotations/annotation/commentsarchive/commentarchive');
$paths[] = new restore_path_element('pdfannotator_comment', '/activity/pdfannotator/annotations/annotation/comments/comment');

$paths[] = new restore_path_element('pdfannotator_vote', '/activity/pdfannotator/annotations/annotation/comments/comment/votes/vote');
$paths[] = new restore_path_element('pdfannotator_report', '/activity/pdfannotator/annotations/annotation/comments/comment/reports/report');
$paths[] = new restore_path_element('pdfannotator_subscription',
'/activity/pdfannotator/annotations/annotation/subscriptions/subscription');
$paths[] = new restore_path_element('pdfannotator_commentarchive',
'/activity/pdfannotator/annotations/annotation/commentsarchive/commentarchive');
$paths[] = new restore_path_element('pdfannotator_comment',
'/activity/pdfannotator/annotations/annotation/comments/comment');

$paths[] = new restore_path_element('pdfannotator_vote',
'/activity/pdfannotator/annotations/annotation/comments/comment/votes/vote');
$paths[] = new restore_path_element('pdfannotator_report',
'/activity/pdfannotator/annotations/annotation/comments/comment/reports/report');

// Return the paths wrapped into standard activity structure.
return $this->prepare_activity_structure($paths);
@@ -169,7 +174,8 @@ class restore_pdfannotator_activity_structure_step extends restore_activity_stru
$data->userid = $this->get_mappingid('user', $data->userid);

$data->timecreated = $this->apply_date_offset($data->timecreated);
$data->pdfannotatorid = $this->get_mappingid('pdfannotator', $data->pdfannotatorid); // Params: 1. Object class as defined in structure, 2. attribute&/column name.
// Params: 1. Object class as defined in structure, 2. attribute&/column name.
$data->pdfannotatorid = $this->get_mappingid('pdfannotator', $data->pdfannotatorid);

$newitemid = $DB->insert_record('pdfannotator_reports', $data);
$this->set_mapping('pdfannotator_report', $oldid, $newitemid);


+ 1
- 1
classes/event/report_added.php View File

@@ -38,7 +38,7 @@ defined('MOODLE_INTERNAL') || die();
**/
class report_added extends \core\event\base {
protected function init() {
$this->data['crud'] = 'c'; // ... c(reate), r(ead), u(pdate), d(elete).
$this->data['crud'] = 'c';
$this->data['edulevel'] = self::LEVEL_PARTICIPATING;
$this->data['objecttable'] = 'pdfannotator_reports';
}


+ 12
- 6
classes/output/comment.php View File

@@ -95,7 +95,8 @@ class comment implements \renderable, \templatable {
$report = has_capability('mod/pdfannotator:report', $context);
if ($deleteany || ($deleteown && $owner)) { // Delete.
$comment->buttons[] = ["classes" => "comment-delete-a", "text" => get_string('delete', 'pdfannotator'),
"moodleicon" => ["key" => "delete", "component" => "pdfannotator", "title" => get_string('delete', 'pdfannotator')]];
"moodleicon" => ["key" => "delete", "component" => "pdfannotator",
"title" => get_string('delete', 'pdfannotator')]];
}
// Report (textbox/drawing can't be reported because of a missing commentid).
if ($report && !$owner && !isset($comment->type) ) {
@@ -104,7 +105,8 @@ class comment implements \renderable, \templatable {
$comment->cmid = $cm->id;
}
if (!isset($comment->type) && ($owner || $editanypost)) {
$comment->buttons[] = ["classes" => "comment-edit-a", "attributes" => ["name" => "id", "value" => "editButton" . $comment->uuid],
$comment->buttons[] = ["classes" => "comment-edit-a",
"attributes" => ["name" => "id", "value" => "editButton" . $comment->uuid],
"moodleicon" => ["key" => "i/edit", "component" => "core", "title" => get_string('edit', 'pdfannotator')],
"text" => get_string('edit', 'pdfannotator')];
}
@@ -146,17 +148,21 @@ class comment implements \renderable, \templatable {
if ($solve && !$comment->isquestion && !$comment->isdeleted && !isset($comment->type)) {
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')]];
"moodleicon" => ["key" => "i/completion-manual-n", "component" => "core",
"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')]];
"moodleicon" => ["key" => "i/completion-manual-enabled", "component" => "core",
"title" => get_string('markCorrect', 'pdfannotator')]];
}
}
if ($comment->solved) {
if ($comment->isquestion) {
$comment->solvedicon = ["classes" => "icon fa fa-lock fa-fw solvedquestionicon", "title" => get_string('questionSolved', 'pdfannotator')];
$comment->solvedicon = ["classes" => "icon fa fa-lock fa-fw solvedquestionicon",
"title" => get_string('questionSolved', 'pdfannotator')];
} else if (!$comment->isdeleted) {
$comment->solvedicon = ["classes" => "icon fa fa-check fa-fw correctanswericon", "title" => get_string('answerSolved', 'pdfannotator')];
$comment->solvedicon = ["classes" => "icon fa fa-check fa-fw correctanswericon",
"title" => get_string('answerSolved', 'pdfannotator')];
}
}
$this->comments[] = $comment;


+ 106
- 106
classes/output/index.php View File

@@ -1,106 +1,106 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* The purpose of this script is to collect the output data for the index.mustache template
* and make it available to the renderer. The data is collected via the pdfannotator model
* and then processed. Therefore, class teacheroverview can be seen as a view controller.
*
* @package mod_pdfannotator
* @copyright 2018 RWTH Aachen, Anna Heynkes (see README.md)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*
* Description of index
*
* @author degroot
*/
defined('MOODLE_INTERNAL') || die();
class index implements renderable, templatable { // Class should be placed elsewhere.
private $usestudenttextbox;
private $usestudentdrawing;
private $useprint;
private $printurl;
private $pdfannotatortextboxvisibility;
private $pdfannotatorpenvisibility;
private $pdfannotatorprintvisibility;
public function __construct($pdfannotator, $isallowedforuser, $file) {
global $CFG, $USER;
// If the textbox/drawing is allowed for students, the array should have a single value.
$this->usestudenttextbox = array();
if ($pdfannotator->use_studenttextbox || $isallowedforuser) {
$this->usestudenttextbox = array('use');
if (!$pdfannotator->use_studenttextbox) {
$this->pdfannotatortextboxvisibility = 'teachersonly';
} else {
$this->pdfannotatortextboxvisibility = '';
}
}
$this->usestudentdrawing = array();
if ($pdfannotator->use_studentdrawing || $isallowedforuser) {
$this->usestudentdrawing = array('use');
if (!$pdfannotator->use_studentdrawing) {
$this->pdfannotatorpenvisibility = 'teachersonly';
} else {
$this->pdfannotatorpenvisibility = '';
}
}
$this->useprint = array();
$studentsmayprint = pdfannotator_instance::useprint($pdfannotator->id);
if ($studentsmayprint || $isallowedforuser) {
$this->useprint = array('use');
if (!$studentsmayprint) {
$this->pdfannotatorprintvisibility = 'teachersonly';
} else {
$this->pdfannotatorprintvisibility = '';
}
}
$contextid = $file->get_contextid();
$component = $file->get_component();
$filearea = $file->get_filearea();
$itemid = $file->get_itemid();
$filename = $file->get_filename();
$this->printurl = "$CFG->wwwroot/pluginfile.php/$contextid/$component/$filearea/$itemid/$filename?forcedownload=1";
}
public function export_for_template(renderer_base $output) {
global $OUTPUT, $PAGE;
$url = $PAGE->url;
$data = new stdClass();
$data->usestudenttextbox = $this->usestudenttextbox;
$data->usestudentdrawing = $this->usestudentdrawing;
$data->pixhide = $OUTPUT->image_url('/e/accessibility_checker');
$data->pixopenbook = $OUTPUT->image_url('openbook', 'mod_pdfannotator');
$data->pixsinglefile = $OUTPUT->image_url('/e/new_document');
$data->useprint = $this->useprint;
$data->printlink = $this->printurl;
$data->pixprintdoc = $OUTPUT->image_url('download', 'mod_pdfannotator');
$data->pixprintcomments = $OUTPUT->image_url('print_comments', 'mod_pdfannotator');
$data->pdfannotatorprintvisibility = $this->pdfannotatorprintvisibility;
$data->pdfannotatortextboxvisibility = $this->pdfannotatortextboxvisibility;
$data->pdfannotatorpenvisibility = $this->pdfannotatorpenvisibility;
return $data;
}
}
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* The purpose of this script is to collect the output data for the index.mustache template
* and make it available to the renderer. The data is collected via the pdfannotator model
* and then processed. Therefore, class teacheroverview can be seen as a view controller.
*
* @package mod_pdfannotator
* @copyright 2018 RWTH Aachen, Anna Heynkes (see README.md)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*
* Description of index
*
* @author degroot
*/
defined('MOODLE_INTERNAL') || die();
class index implements renderable, templatable { // Class should be placed elsewhere.
private $usestudenttextbox;
private $usestudentdrawing;
private $useprint;
private $printurl;
private $pdfannotatortextboxvisibility;
private $pdfannotatorpenvisibility;
private $pdfannotatorprintvisibility;
public function __construct($pdfannotator, $isallowedforuser, $file) {
global $CFG, $USER;
// If the textbox/drawing is allowed for students, the array should have a single value.
$this->usestudenttextbox = array();
if ($pdfannotator->use_studenttextbox || $isallowedforuser) {
$this->usestudenttextbox = array('use');
if (!$pdfannotator->use_studenttextbox) {
$this->pdfannotatortextboxvisibility = 'teachersonly';
} else {
$this->pdfannotatortextboxvisibility = '';
}
}
$this->usestudentdrawing = array();
if ($pdfannotator->use_studentdrawing || $isallowedforuser) {
$this->usestudentdrawing = array('use');
if (!$pdfannotator->use_studentdrawing) {
$this->pdfannotatorpenvisibility = 'teachersonly';
} else {
$this->pdfannotatorpenvisibility = '';
}
}
$this->useprint = array();
$studentsmayprint = pdfannotator_instance::useprint($pdfannotator->id);
if ($studentsmayprint || $isallowedforuser) {
$this->useprint = array('use');
if (!$studentsmayprint) {
$this->pdfannotatorprintvisibility = 'teachersonly';
} else {
$this->pdfannotatorprintvisibility = '';
}
}
$contextid = $file->get_contextid();
$component = $file->get_component();
$filearea = $file->get_filearea();
$itemid = $file->get_itemid();
$filename = $file->get_filename();
$this->printurl = "$CFG->wwwroot/pluginfile.php/$contextid/$component/$filearea/$itemid/$filename?forcedownload=1";
}
public function export_for_template(renderer_base $output) {
global $OUTPUT, $PAGE;
$url = $PAGE->url;
$data = new stdClass();
$data->usestudenttextbox = $this->usestudenttextbox;
$data->usestudentdrawing = $this->usestudentdrawing;
$data->pixhide = $OUTPUT->image_url('/e/accessibility_checker');
$data->pixopenbook = $OUTPUT->image_url('openbook', 'mod_pdfannotator');
$data->pixsinglefile = $OUTPUT->image_url('/e/new_document');
$data->useprint = $this->useprint;
$data->printlink = $this->printurl;
$data->pixprintdoc = $OUTPUT->image_url('download', 'mod_pdfannotator');
$data->pixprintcomments = $OUTPUT->image_url('print_comments', 'mod_pdfannotator');
$data->pdfannotatorprintvisibility = $this->pdfannotatorprintvisibility;
$data->pdfannotatortextboxvisibility = $this->pdfannotatortextboxvisibility;
$data->pdfannotatorpenvisibility = $this->pdfannotatorpenvisibility;
return $data;
}
}

+ 31
- 67
classes/privacy/provider.php View File

@@ -186,8 +186,6 @@ class provider implements \core_privacy\local\metadata\provider, \core_privacy\l
)
";

// $params = [];
// $params += $contextparams;
// Keep a mapping of pdfannotatorid to contextid.
$mappings = [];

@@ -202,9 +200,6 @@ class provider implements \core_privacy\local\metadata\provider, \core_privacy\l
$sql1 = "SELECT c.content, c.timecreated, c.visibility
FROM {pdfannotator_comments} c
WHERE c.isquestion = 1 AND c.userid = :userid AND c.pdfannotatorid = :pdfannotator";
// $sql1 = "SELECT c.content, c.timecreated, c.visibility
// FROM {pdfannotator_comments} c JOIN {pdfannotator_annotations} a ON c.annotationid = a.id
// WHERE c.isquestion = 1 AND c.userid = :userid AND a.pdfannotatorid = :pdfannotator";
$myquestions = $DB->get_records_sql($sql1, array('userid' => $userid, 'pdfannotator' => $pdfannotator->id));

foreach ($myquestions as $myquestion) {
@@ -216,8 +211,10 @@ class provider implements \core_privacy\local\metadata\provider, \core_privacy\l
. "FROM {pdfannotator_comments} c "
. "JOIN {pdfannotator_annotations} a ON c.annotationid = a.id "
. "JOIN {pdfannotator_comments} q ON q.annotationid = c.annotationid "
. "WHERE q.isquestion = :question AND c.isquestion = :normalcomment AND c.userid = :userid AND a.pdfannotatorid = :pdfannotator";
$mycomments = $DB->get_records_sql($sql2, array('question' => 1, 'normalcomment' => 0, 'userid' => $userid, 'pdfannotator' => $pdfannotator->id));
. "WHERE q.isquestion = :question AND c.isquestion = :normalcomment AND "
. "c.userid = :userid AND a.pdfannotatorid = :pdfannotator";
$mycomments = $DB->get_records_sql($sql2,
array('question' => 1, 'normalcomment' => 0, 'userid' => $userid, 'pdfannotator' => $pdfannotator->id));

foreach ($mycomments as $mycomment) {
$mycomment->timecreated = pdfannotator_get_user_datetime($mycomment->timecreated);
@@ -225,24 +222,19 @@ class provider implements \core_privacy\local\metadata\provider, \core_privacy\l

// Get all subscriptions of this user (exluding their own questions which they're automatically subscribed to).
$sql3 = "SELECT c.content
FROM {pdfannotator_subscriptions} s JOIN {pdfannotator_annotations} a ON s.annotationid = a.id JOIN {pdfannotator_comments} c ON c.annotationid = a.id
FROM {pdfannotator_subscriptions} s JOIN {pdfannotator_annotations} a
ON s.annotationid = a.id JOIN {pdfannotator_comments} c ON c.annotationid = a.id
WHERE c.isquestion = 1 AND s.userid = :userid AND a.pdfannotatorid = :pdfannotator AND NOT a.userid = :u";
$mysubscriptions = $DB->get_records_sql($sql3, array('userid' => $userid, 'pdfannotator' => $pdfannotator->id, 'u' => $userid));
$mysubscriptions = $DB->get_records_sql($sql3,
array('userid' => $userid, 'pdfannotator' => $pdfannotator->id, 'u' => $userid));

// Get all comments this user voted for in this annotator.
$sql4 = "SELECT c.content
FROM {pdfannotator_comments} c JOIN {pdfannotator_votes} v on v.commentid = c.id
WHERE v.userid = :userid AND c.pdfannotatorid = :pdfannotator";
// $sql4 = "SELECT c.content
// FROM {pdfannotator_comments} c JOIN {pdfannotator_votes} v on v.commentid = c.id JOIN {pdfannotator_annotations} a ON c.annotationid = a.id
// WHERE v.userid = :userid AND a.pdfannotatorid = :pdfannotator";

$myvotes = $DB->get_records_sql($sql4, array('userid' => $userid, 'pdfannotator' => $pdfannotator->id));

// Get all archived comments by this user
// $sql5 = "SELECT c.*
// FROM {pdfannotator_commentsarchive} c JOIN {pdfannotator_annotations} a ON c.annotationid = a.id
// WHERE AND c.userid = :userid AND c.pdfannotatorid = :pdfannotator";
// $myarchive = $DB->get_records_sql($sql5, array('userid' => $userid, 'pdfannotator' => $pdfannotator->id));
// Get all reports this user wrote.
$sql6 = "SELECT r.message
FROM {pdfannotator_reports} r JOIN {pdfannotator_comments} c ON c.id = r.commentid
@@ -253,7 +245,8 @@ class provider implements \core_privacy\local\metadata\provider, \core_privacy\l
$sql7 = "SELECT a.data, a.timecreated
FROM {pdfannotator_annotations} a JOIN {pdfannotator_annotationtypes} t ON a.annotationtypeid = t.id
WHERE t.name IN (:type1, :type2) AND a.userid = :userid AND a.pdfannotatorid = :pdfannotator";
$mydrawingsandtextboxes = $DB->get_records_sql($sql7, array('type1' => 'drawing', 'type2' => 'textbox', 'userid' => $userid, 'pdfannotator' => $pdfannotator->id));
$mydrawingsandtextboxes = $DB->get_records_sql($sql7,
array('type1' => 'drawing', 'type2' => 'textbox', 'userid' => $userid, 'pdfannotator' => $pdfannotator->id));

foreach ($mydrawingsandtextboxes as $mydrawingortextbox) {
$mydrawingortextbox->timecreated = pdfannotator_get_user_datetime($mydrawingortextbox->timecreated);
@@ -265,7 +258,6 @@ class provider implements \core_privacy\local\metadata\provider, \core_privacy\l
$pdfannotator->myvotes = $myvotes;
$pdfannotator->myreportmessages = $myreportmessages;
$pdfannotator->mydrawingsandtextboxes = $mydrawingsandtextboxes;
// $pdfannotator->myarchive = $myarchive;

writer::with_context($context)->export_data([], $pdfannotator);
}
@@ -280,8 +272,6 @@ class provider implements \core_privacy\local\metadata\provider, \core_privacy\l
public static function delete_data_for_all_users_in_context(\context $context) {
global $DB;

// require_once($CFG->dirroot.'/mod/pdfannotator/model/annotation.class.php');

if ($context->contextlevel != CONTEXT_MODULE) {
return;
}
@@ -316,34 +306,18 @@ class provider implements \core_privacy\local\metadata\provider, \core_privacy\l
// 4. Delete all comments in this annotator.
$sql = "SELECT c.id, c.isquestion, c.annotationid FROM {pdfannotator_comments} c "
. "WHERE c.annotationid IN (SELECT a.id FROM {pdfannotator_annotations} a WHERE a.pdfannotatorid = ?)";
// $comments = $DB->get_records_sql($sql, array($instanceid));
$sql = "SELECT c.id FROM {pdfannotator_comments} c WHERE c.annotationid IN (SELECT a.id FROM {pdfannotator_annotations} a WHERE a.pdfannotatorid = ?)";
$sql = "SELECT c.id FROM {pdfannotator_comments} c WHERE c.annotationid IN
(SELECT a.id FROM {pdfannotator_annotations} a WHERE a.pdfannotatorid = ?)";
$comments = $DB->get_records_sql($sql, array($instanceid));
foreach ($comments as $comment) {
$DB->delete_records('pdfannotator_comments', array("id" => $comment->id));
// if ($comment->isquestion === 1) { // delete question comments, their underlying annotation as well as all answers and subscriptions
// annotation::delete($comment->annotationid, null, true);
// } else { // empty all other comments
// $DB->update_record('pdfannotator_comments', array("id" => $comment->id, "content" => "", "isdeleted" => 1), $bulk=false);
// }
}

// 5. Select the ID and isquestion attributes of every archived comment this user made in this annotator
// $sql = "SELECT c.id, c.isquestion FROM {pdfannotator_commentsarchive} c "
// . "WHERE c.annotationid IN (SELECT a.id FROM {pdfannotator_annotations} a WHERE a.pdfannotatorid = ?)";
// $archivedcomments = $DB->get_records_sql($sql, array($instanceid));
// foreach($archivedcomments as $archivedcomment) {
// if ($archivedcomment->isquestion === 1) { // delete question comments, their underlying annotation as well as all answers and subscriptions
// annotation::delete($archivedcomment->annotationid, null, true);
// } else { // empty all other comments
// $DB->update_record('pdfannotator_commentsarchive', array("id" => $archivedcomment->id, "userid" => -1, "content" => "", "isdeleted" => 1), $bulk=false);
// }
// }
// 6. Select the IDs of all annotations that were made by this user in this annotator. Then call the function to delete the annotation and any adjacent comments.
// 5. Select the IDs of all annotations that were made by this user in this annotator.
// Then call the function to delete the annotation and any adjacent comments.
$annotations = $DB->get_fieldset_select('pdfannotator_annotations', 'id', "pdfannotatorid = ?", array($instanceid));
foreach ($annotations as $annotationid) {
$DB->delete_records('pdfannotator_annotations', array("id" => $annotationid));
// annotation::delete($annotationid, null, true);
}
}

@@ -357,8 +331,6 @@ class provider implements \core_privacy\local\metadata\provider, \core_privacy\l

global $DB;

// require_once($CFG->dirroot.'/mod/pdfannotator/model/annotation.class.php');

if (empty($contextlist->count())) {
return;
}
@@ -372,11 +344,9 @@ class provider implements \core_privacy\local\metadata\provider, \core_privacy\l
$DB->delete_records('pdfannotator_reports', ['pdfannotatorid' => $instanceid, 'userid' => $userid]);

// 2. Delete all votes this user made in this annotator.
$sql = "SELECT v.id FROM {pdfannotator_votes} v WHERE v.userid = ? AND v.commentid IN (SELECT c.id FROM {pdfannotator_comments} c WHERE c.pdfannotatorid = ?)";
$sql = "SELECT v.id FROM {pdfannotator_votes} v WHERE v.userid = ? AND v.commentid IN
(SELECT c.id FROM {pdfannotator_comments} c WHERE c.pdfannotatorid = ?)";
$votes = $DB->get_records_sql($sql , array($userid, $instanceid));
// $sql = "SELECT v.id FROM {pdfannotator_votes} v WHERE v.userid = ? AND v.commentid IN "
// . "(SELECT c.id FROM {pdfannotator_comments} c JOIN {pdfannotator_annotations} a ON c.annotationid = a.id WHERE a.pdfannotatorid = ?)";
// $votes = $DB->get_records_sql($sql, array($userid, $instanceid));
foreach ($votes as $vote) {
$DB->delete_records('pdfannotator_votes', array("id" => $vote->id));
}
@@ -390,10 +360,8 @@ class provider implements \core_privacy\local\metadata\provider, \core_privacy\l
}

// 4. Select (the ID and isquestion attributes of) every comment this user made in this annotator.
$comments = $DB->get_records_sql("SELECT c.* FROM {pdfannotator_comments} c WHERE c.pdfannotatorid = ? AND c.userid = ?", array($instanceid, $userid));
// $sql = "SELECT c.* FROM {pdfannotator_comments} c WHERE c.annotationid IN "
// . "(SELECT a.id FROM {pdfannotator_annotations} a WHERE a.pdfannotatorid = ?) AND c.userid = ?";
// $comments = $DB->get_records_sql($sql, array($instanceid, $userid));
$comments = $DB->get_records_sql("SELECT c.* FROM {pdfannotator_comments} c WHERE c.pdfannotatorid = ? AND
c.userid = ?", array($instanceid, $userid));
foreach ($comments as $comment) {

// Delete question comments, their underlying annotation as well as all answers and subscriptions.
@@ -408,27 +376,21 @@ class provider implements \core_privacy\local\metadata\provider, \core_privacy\l
// 5. Select the ID and isquestion attributes of every archived comment this user made in this annotator.
$sql = "SELECT c.id, c.isquestion FROM {pdfannotator_commentsarchive} c WHERE c.annotationid IN "
. "(SELECT a.id FROM {pdfannotator_annotations} a WHERE a.pdfannotatorid = ?) AND c.userid = ?";
// $archivedcomments = $DB->get_records_sql($sql, array($instanceid, $userid));
// foreach($archivedcomments as $archivedcomment) {
// if ($archivedcomment->isquestion === 1) { // Delete question comments, their underlying annotation as well as all answers and subscriptions.
// annotation::delete($archivedcomment->annotationid, null, true);
// } else { // Empty all other comments.
// $DB->update_record('pdfannotator_commentsarchive', array("id" => $archivedcomment->id, "userid" => -1, "content" => "", "isdeleted" => 1), $bulk=false);
// }
// }
// 6. Select the IDs of all annotations that were made by this user in this annotator. Then call the function to delete the annotation and any adjacent comments.
$annotations = $DB->get_fieldset_select('pdfannotator_annotations', 'id', "pdfannotatorid = ? AND userid = ?", array($instanceid, $userid));

// 6. Select the IDs of all annotations that were made by this user in this annotator.
// Then call the function to delete the annotation and any adjacent comments.
$annotations = $DB->get_fieldset_select('pdfannotator_annotations', 'id', "pdfannotatorid = ? AND userid = ?",
array($instanceid, $userid));
foreach ($annotations as $annotationid) {
self::delete_annotation($annotationid);
// $DB->delete_records('pdfannotator_annotations', array("id" => $annotationid));
// annotation::delete($annotationid, null, true);
}
}
}

// Status quo:
// Deleting the initial or final comment of a 'thread' will remove it from the comments table.
// Deleting any other comment will merely set the field isdeleted of the comments table to 1, so that the comment will be displayed as deleted within the 'thread'.
// Deleting any other comment will merely set the field isdeleted of the comments table to 1,
// so that the comment will be displayed as deleted within the 'thread'.
// When a reported comment is deleted, a copy is saved in the archive table (but no longer visible to users).
// The archive tables field isdeleted should be set to 1 per default (is currently 0).
/**
@@ -473,7 +435,8 @@ class provider implements \core_privacy\local\metadata\provider, \core_privacy\l

self::archive_comment_if_necessary($comment);
$select = "annotationid = ? AND timecreated > ? AND isdeleted = ?";
$wasanswered = $DB->record_exists_select('pdfannotator_comments', $select, array($comment->annotationid, $comment->timecreated, 0));
$wasanswered = $DB->record_exists_select('pdfannotator_comments', $select,
array($comment->annotationid, $comment->timecreated, 0));

// If the comment was answered, empty it and mark it as deleted for a special display.
if ($wasanswered) {
@@ -482,7 +445,8 @@ class provider implements \core_privacy\local\metadata\provider, \core_privacy\l
} else {

// But first: Check if the predecessor was already marked as deleted, too and if so, delete it completely.
$sql = "SELECT id, isdeleted from {pdfannotator_comments} WHERE annotationid = ? AND isquestion = ? AND timecreated < ? ORDER BY id DESC";
$sql = "SELECT id, isdeleted from {pdfannotator_comments} WHERE annotationid = ? AND isquestion = ? AND
timecreated < ? ORDER BY id DESC";
$params = array($comment->annotationid, 0, $comment->timecreated);

$predecessors = $DB->get_records_sql($sql, $params);
@@ -506,7 +470,7 @@ class provider implements \core_privacy\local\metadata\provider, \core_privacy\l

$wasreported = $DB->record_exists('pdfannotator_reports', ['commentid' => $comment->id]);

// Before updating, insert the comment into the archive, if it was reported. // TODO: Mit Datenschutzbeauftragtem klären!
// Before updating, insert the comment into the archive, if it was reported.
if ($wasreported) {
$reportedcomment = clone $comment;
unset($reportedcomment->id);


+ 391
- 382
controller.php View File

@@ -1,382 +1,391 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* @package mod_pdfannotator
* @copyright 2018 RWTH Aachen, Anna Heynkes (see README.md)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$action = optional_param('action', 'view', PARAM_ALPHA); // The default action is 'view'.
$taburl = new moodle_url('/mod/pdfannotator/view.php', array('id' => $id));
$myrenderer = $PAGE->get_renderer('mod_pdfannotator');
/* *********************************************** Display overview page *********************************************** */
if ($action === 'overview') {
$action = 'overviewquestions';
}
/*
* This section prints a subpage of overview called 'unsolved questions'.
*/
if ($action === 'overviewquestions') {
global $OUTPUT;
require_once($CFG->libdir . '/tablelib.php');
require_once($CFG->dirroot . '/mod/pdfannotator/locallib.php');
global $CFG;
$currentpage = optional_param('page', 0, PARAM_INT);
$itemsperpage = optional_param('itemsperpage', 5, PARAM_INT);
$thisannotator = $pdfannotator->id;
$thiscourse = $pdfannotator->course;
$cmid = get_coursemodule_from_instance('pdfannotator', $thisannotator, $thiscourse, false, MUST_EXIST)->id;
pdfannotator_prepare_overviewpage($id, $myrenderer, $taburl, 'overview', $pdfannotator, $context);
echo $OUTPUT->heading(get_string('questionstab', 'pdfannotator') . ' ' . $OUTPUT->help_icon('questionstabicon', 'mod_pdfannotator'));
$questions = pdfannotator_get_unsolved_questions($thiscourse);
if (empty($questions)) {
$info = get_string('noquestions_overview', 'pdfannotator');
echo "<span class='notification'><div class='alert alert-info alert-block fade in' role='alert'>$info</div></span>";
} else {
$urlparams = array('action' => 'overviewquestions', 'id' => $cmid, 'page' => $currentpage, 'itemsperpage' => $itemsperpage);
pdfannotator_print_questions($questions, $thiscourse, $urlparams, $currentpage, $itemsperpage);
}
}
/*
* This section prints a subpage of overview called 'answers'. It lists all answers to questions the current
* user asked or subscribed to.
*/
if ($action === 'overviewanswers') {
require_once($CFG->libdir . '/tablelib.php');
require_once($CFG->dirroot . '/mod/pdfannotator/locallib.php');
global $CFG, $OUTPUT;
$currentpage = optional_param('page', 0, PARAM_INT);
$itemsperpage = optional_param('itemsperpage', 5, PARAM_INT);
$thisannotator = $pdfannotator->id;
$thiscourse = $pdfannotator->course;
$cmid = get_coursemodule_from_instance('pdfannotator', $thisannotator, $thiscourse, false, MUST_EXIST)->id;
pdfannotator_prepare_overviewpage($id, $myrenderer, $taburl, 'overview', $pdfannotator, $context);
echo $OUTPUT->heading(get_string('answerstab', 'pdfannotator'). ' ' . $OUTPUT->help_icon('answerstabicon', 'pdfannotator'));
$data = pdfannotator_get_answers_for_this_user($thiscourse);
if (empty($data)) {
$info = get_string('noanswers', 'pdfannotator');
echo "<span class='notification'><div class='alert alert-info alert-block fade in' role='alert'>$info</div></span>";
} else {
$urlparams = array('action' => 'overviewanswers', 'id' => $cmid, 'page' => $currentpage, 'itemsperpage' => $itemsperpage);
$url = new moodle_url($CFG->wwwroot . '/mod/pdfannotator/view.php', $urlparams);
pdfannotator_print_answers($data, $thiscourse, $url, $currentpage, $itemsperpage);
}
}
/*
* This section prints a subpage of overview called "My posts".
*/
if ($action === 'overviewownposts') {
require_once($CFG->libdir . '/tablelib.php');
require_once($CFG->dirroot . '/mod/pdfannotator/locallib.php');
global $CFG, $OUTPUT;
$currentpage = optional_param('page', 0, PARAM_INT);
$itemsperpage = optional_param('itemsperpage', 5, PARAM_INT);
$thisannotator = $pdfannotator->id;
$thiscourse = $pdfannotator->course;
$cmid = get_coursemodule_from_instance('pdfannotator', $thisannotator, $thiscourse, false, MUST_EXIST)->id;
pdfannotator_prepare_overviewpage($id, $myrenderer, $taburl, 'overview', $pdfannotator, $context);
echo $OUTPUT->heading(get_string('ownpoststab', 'pdfannotator'). ' ' . $OUTPUT->help_icon('ownpoststabicon', 'mod_pdfannotator'));
$posts = pdfannotator_get_posts_by_this_user($thiscourse);
if (empty($posts)) {
$info = get_string('nomyposts', 'pdfannotator');
echo "<span class='notification'><div class='alert alert-info alert-block fade in' role='alert'>$info</div></span>";
} else {
$urlparams = array('action' => 'overviewownposts', 'id' => $cmid, 'page' => $currentpage, 'itemsperpage' => $itemsperpage);
$url = new moodle_url($CFG->wwwroot . '/mod/pdfannotator/view.php', $urlparams);
pdfannotator_print_this_users_posts($posts, $thiscourse, $url, $currentpage, $itemsperpage);
}
}
/*
* This section prints a subpage of overview called "Reports" were comments that were reported as inappropriate are listed.
*/
if ($action === 'overviewreports') {
require_once($CFG->libdir . '/tablelib.php');
require_once($CFG->dirroot . '/mod/pdfannotator/locallib.php');
global $CFG, $OUTPUT;
$currentpage = optional_param('page', 0, PARAM_INT);
$itemsperpage = optional_param('itemsperpage', 5, PARAM_INT);
$thisannotator = $pdfannotator->id;
$thiscourse = $pdfannotator->course;
$cmid = get_coursemodule_from_instance('pdfannotator', $thisannotator, $thiscourse, false, MUST_EXIST)->id;
pdfannotator_prepare_overviewpage($id, $myrenderer, $taburl, 'overview', $pdfannotator, $context);
echo $OUTPUT->heading(get_string('reportstab', 'pdfannotator'). ' ' . $OUTPUT->help_icon('reportstabicon', 'mod_pdfannotator'));
$reports = pdfannotator_get_reports($thiscourse);
if (empty($reports)) {
$info = get_string('noreports', 'pdfannotator');
echo "<span class='notification'><div class='alert alert-info alert-block fade in' role='alert'>$info</div></span>";
} else {
$urlparams = array('action' => 'overviewreports', 'id' => $cmid, 'page' => $currentpage, 'itemsperpage' => $itemsperpage);
$url = new moodle_url($CFG->wwwroot . '/mod/pdfannotator/view.php', $urlparams);
pdfannotator_print_reports($reports, $thiscourse, $url, $currentpage, $itemsperpage);
}
}
/* This section prints a subpage of overview called "Read" were comments that were reported as inappropriate are listed
* after they were marked as seen/read/ackknowledged.
*/
if ($action === 'overviewrecyclebin') {
require_once($CFG->libdir . '/tablelib.php');
require_once($CFG->dirroot . '/mod/pdfannotator/locallib.php');
global $CFG, $USER, $OUTPUT;
$currentpage = optional_param('page', 0, PARAM_INT);
$itemsperpage = optional_param('itemsperpage', 5, PARAM_INT);
$currentview = optional_param('currentview', 0, PARAM_INT); // Answers or reports.
$thisannotator = $pdfannotator->id;
$thiscourse = $pdfannotator->course;
$cmid = get_coursemodule_from_instance('pdfannotator', $thisannotator, $thiscourse, false, MUST_EXIST)->id;
pdfannotator_prepare_overviewpage($id, $myrenderer, $taburl, 'overview', $pdfannotator, $context);
echo $OUTPUT->heading(get_string('recyclebintab', 'pdfannotator'). ' ' . $OUTPUT->help_icon('recyclebintabicon', 'pdfannotator'));
if (has_capability('mod/pdfannotator:viewreports', $context)) {
$reports = pdfannotator_get_reports($thiscourse, 1);
if (empty($reports)) {
$info = get_string('nohiddenreports', 'pdfannotator');
echo "<div><span class='notification'><div class='alert alert-info alert-block fade in' role='alert'>$info</div></span></div>";
} else {
$urlparams = array('action' => 'overviewrecyclebin', 'id' => $cmid, 'page' => $currentpage, 'currentview' => $currentview, 'itemsperpage' => $itemsperpage);
$url = new moodle_url($CFG->wwwroot . '/mod/pdfannotator/view.php', $urlparams);
pdfannotator_print_reports($reports, $thiscourse, $url, $currentpage, $itemsperpage, true);
}
}
}
/* *********************************** Display the pdf in its editor (default action) *************************************** */
if ($action === 'view') { // Default.
$PAGE->set_title("annotatorview");
echo $myrenderer->pdfannotator_render_tabs($taburl, $action, $pdfannotator->name, $context);
pdfannotator_display_embed($pdfannotator, $cm, $course, $file, $page, $annoid, $commid);
}
/* *********************************************** Display statistics *********************************************** */
if ($action === 'statistic') {
require_capability('mod/pdfannotator:viewstatistics', $context);
require_once($CFG->dirroot . '/mod/pdfannotator/model/statistics.class.php');
require_once($CFG->dirroot . '/mod/pdfannotator/classes/output/statistics.php');
echo $myrenderer->pdfannotator_render_tabs($taburl, $action, $pdfannotator->name, $context);
$PAGE->set_title("statisticview");
echo $OUTPUT->heading(get_string('activities', 'pdfannotator'));
// Give javascript access to the language string repository.
$stringman = get_string_manager();
$strings = $stringman->load_component_strings('pdfannotator', 'en'); // Method gets the strings of the language files.
$PAGE->requires->strings_for_js(array_keys($strings), 'pdfannotator'); // Method to use the language-strings in javascript.
$PAGE->requires->js(new moodle_url("/mod/pdfannotator/shared/locallib.js?ver=00002"));
$PAGE->requires->js(new moodle_url("/mod/pdfannotator/shared/statistic.js"));
$myrenderer = $PAGE->get_renderer('mod_pdfannotator');
$capabilities = new stdClass();
$capabilities->viewquestions = has_capability('mod/pdfannotator:viewquestions', $context);
$capabilities->viewanswers = has_capability('mod/pdfannotator:viewanswers', $context);
$capabilities->viewposts = has_capability('mod/pdfannotator:viewposts', $context);
$capabilities->viewreports = has_capability('mod/pdfannotator:viewreports', $context);
$capabilities->viewteacherstatistics = has_capability('mod/pdfannotator:viewteacherstatistics', $context);
echo $myrenderer->render_statistic(new statistics($cm->instance, $course->id, $capabilities, $id)); // Param 'statistics' is a renderable/templatable.
}
/* ****************************************** Display form for reporting a comment ******************************************** */
if ($action === 'report') {
require_once($CFG->dirroot . '/mod/pdfannotator/reportform.php');
require_once($CFG->dirroot . '/mod/pdfannotator/model/comment.class.php');
require_once($CFG->dirroot . '/mod/pdfannotator/model/report.class.php');
// Get comment id.
$commentid = optional_param('commentid', 0, PARAM_INT);
// Contextual data to pass on to the report form.
$data = new stdClass();
$data->course = $cm->course;
$data->pdfannotatorid = $cm->instance;
$data->pdfname = $cm->name;
$data->commentid = $commentid;
$data->id = $id; // Course module id.
$data->action = 'report';
// Initialise mform and pass on $data-object to it.
$mform = new pdfannotator_reportform();
$mform->set_data($data);
/* ******************** Form processing and displaying is done here ************************ */
if ($mform->is_cancelled()) {
$action = 'view';
echo $myrenderer->pdfannotator_render_tabs($taburl, $action, $pdfannotator->name, $context);
pdfannotator_display_embed($pdfannotator, $cm, $course, $file);
} else if ($report = $mform->get_data()) { // In this case you process validated data. $mform->get_data() returns data posted in form.
global $DB, $USER;
// 1. Notify course manager(s).
$recipients = get_enrolled_users($context, 'mod/pdfannotator:administrateuserinput');
$name = 'newreport';
$report->reportinguser = fullname($USER);
$report->url = $CFG->wwwroot . '/mod/pdfannotator/view.php?id=' . $cm->id . '&action=overview';
$messagetext = new stdClass();
$messagetext->text = pdfannotator_format_notification_message_text($course, $cm, $context, get_string('modulename', 'pdfannotator'), $cm->name, $report, 'reportadded');
$messagetext->html = pdfannotator_format_notification_message_html($course, $cm, $context, get_string('modulename', 'pdfannotator'), $cm->name, $report, 'reportadded');
$messagetext->url = $report->url;
try {
foreach ($recipients as $recipient) {
$messageid = pdfannotator_notify_manager($recipient, $course, $cm, $name, $messagetext);
}
// 2. Notify the reporting user that their report has been sent off (display blue toast box at top of page).
\core\notification::info(get_string('reportwassentoff', 'pdfannotator'));
} catch (Exception $ex) {
$info = $ex->getMessage();
\core\notification::error($info);
}
// 3. Save report in db.
$record = new stdClass();
$record->commentid = $report->commentid;
$record->courseid = $cm->course;
$record->pdfannotatorid = $cm->instance;
$record->message = $report->introduction;
$record->userid = $USER->id;
$record->timecreated = time();
$record->seen = 0;
$reportid = $DB->insert_record('pdfannotator_reports', $record, $returnid = true, $bulk = false);
if (empty($reportid)) {
\core\notification::error(get_string('error:reportComment', 'pdfannotator'));
}
$action = 'view';
echo $myrenderer->pdfannotator_render_tabs($taburl, $action, $pdfannotator->name, $context);
pdfannotator_display_embed($pdfannotator, $cm, $course, $file);
} else { // This branch is executed if the form is submitted but the data doesn't validate and the form should be redisplayed
// or on the first display of the form.
$PAGE->set_title("reportform");
echo $OUTPUT->heading(get_string('titleforreportcommentform', 'pdfannotator'));
// Get information about the comment to be reported.
$comment = new pdfannotator_comment($commentid);
$info = pdfannotator_comment_info::make_from_comment($comment);
// Display it in a table.
$myrenderer = $PAGE->get_renderer('mod_pdfannotator');
echo $myrenderer->render_pdfannotator_comment_info($info);
// Now display the complaint form itself.
$mform->display();
}
return;
}
/* *********************************************** Display feedback page *********************************************** */
if ($action === 'feedback') {
global $PAGE;
require_once($CFG->dirroot . '/mod/pdfannotator/feedback_form.php');
$PAGE->requires->js(new moodle_url("/mod/pdfannotator/shared/locallib.js?ver=00002"));
// Contextual data to pass on to the feedback form.
$data = new stdClass();
$data->id = $id;
$data->course = $cm->course;
$data->pdfid = $cm->instance;
$data->pdfname = $cm->name;
$data->action = 'feedback';
$mform = new pdfannotator_feedback_form();
$mform->set_data($data);
if ($mform->is_cancelled()) {
echo $myrenderer->pdfannotator_render_tabs($taburl, 'view', $pdfannotator->name);
pdfannotator_display_embed($pdfannotator, $cm, $course, $file);
} else if ($formdata = $mform->get_data()) {
global $USER;
// 1. Send email to Ahmad, Rabea and Anna.
$formdata = $mform->get_data();
pdfannotator_send_feedbackmail($formdata);
// 2. Thank user for their feedback (display 'blue box' at top of page).
\core\notification::info(get_string('feedbackwassentoff', 'pdfannotator'));
// 3. Display pdf once more.
echo $myrenderer->pdfannotator_render_tabs($taburl, 'view', $pdfannotator->name, $context);
pdfannotator_display_embed($pdfannotator, $cm, $course, $file);
} else {
$PAGE->set_title("feedback");
echo $myrenderer->pdfannotator_render_tabs($taburl, $action, $pdfannotator->name, $context);
$capabilities = new stdClass();
$capabilities->viewquestions = has_capability('mod/pdfannotator:viewquestions', $context);
$capabilities->viewanswers = has_capability('mod/pdfannotator:viewanswers', $context);
$capabilities->viewposts = has_capability('mod/pdfannotator:viewposts', $context);
$capabilities->viewreports = has_capability('mod/pdfannotator:viewreports', $context);
$stringman = get_string_manager();
$strings = $stringman->load_component_strings('pdfannotator', 'en'); // With this method you get the strings of the language-Files.
$PAGE->requires->strings_for_js(array_keys($strings), 'pdfannotator'); // Method to use the language-strings in javascript.
$PAGE->requires->js_init_call('addDropdownNavigation', array($capabilities, $id), true);
echo "<p>" . get_string('pleaforfeedback', 'pdfannotator') . "</p>";
$mform->display();
}
}
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* @package mod_pdfannotator
* @copyright 2018 RWTH Aachen, Anna Heynkes (see README.md)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();

$action = optional_param('action', 'view', PARAM_ALPHA); // The default action is 'view'.

$taburl = new moodle_url('/mod/pdfannotator/view.php', array('id' => $id));

$myrenderer = $PAGE->get_renderer('mod_pdfannotator');

/* *********************************************** Display overview page *********************************************** */

if ($action === 'overview') {

$action = 'overviewquestions';
}
/*
* This section prints a subpage of overview called 'unsolved questions'.
*/
if ($action === 'overviewquestions') {

global $OUTPUT;

require_once($CFG->libdir . '/tablelib.php');
require_once($CFG->dirroot . '/mod/pdfannotator/locallib.php');

global $CFG;

$currentpage = optional_param('page', 0, PARAM_INT);
$itemsperpage = optional_param('itemsperpage', 5, PARAM_INT);

$thisannotator = $pdfannotator->id;
$thiscourse = $pdfannotator->course;
$cmid = get_coursemodule_from_instance('pdfannotator', $thisannotator, $thiscourse, false, MUST_EXIST)->id;

pdfannotator_prepare_overviewpage($id, $myrenderer, $taburl, 'overview', $pdfannotator, $context);
echo $OUTPUT->heading(get_string('questionstab', 'pdfannotator').' '.
$OUTPUT->help_icon('questionstabicon', 'mod_pdfannotator'));

$questions = pdfannotator_get_unsolved_questions($thiscourse);

if (empty($questions)) {
$info = get_string('noquestions_overview', 'pdfannotator');
echo "<span class='notification'><div class='alert alert-info alert-block fade in' role='alert'>$info</div></span>";
} else {
$urlparams = array('action' => 'overviewquestions', 'id' => $cmid, 'page' => $currentpage, 'itemsperpage' => $itemsperpage);
pdfannotator_print_questions($questions, $thiscourse, $urlparams, $currentpage, $itemsperpage);
}
}
/*
* This section prints a subpage of overview called 'answers'. It lists all answers to questions the current
* user asked or subscribed to.
*/
if ($action === 'overviewanswers') {

require_once($CFG->libdir . '/tablelib.php');
require_once($CFG->dirroot . '/mod/pdfannotator/locallib.php');

global $CFG, $OUTPUT;

$currentpage = optional_param('page', 0, PARAM_INT);
$itemsperpage = optional_param('itemsperpage', 5, PARAM_INT);

$thisannotator = $pdfannotator->id;
$thiscourse = $pdfannotator->course;
$cmid = get_coursemodule_from_instance('pdfannotator', $thisannotator, $thiscourse, false, MUST_EXIST)->id;

pdfannotator_prepare_overviewpage($id, $myrenderer, $taburl, 'overview', $pdfannotator, $context);
echo $OUTPUT->heading(get_string('answerstab', 'pdfannotator'). ' ' . $OUTPUT->help_icon('answerstabicon', 'pdfannotator'));

$data = pdfannotator_get_answers_for_this_user($thiscourse);

if (empty($data)) {
$info = get_string('noanswers', 'pdfannotator');
echo "<span class='notification'><div class='alert alert-info alert-block fade in' role='alert'>$info</div></span>";
} else {
$urlparams = array('action' => 'overviewanswers', 'id' => $cmid, 'page' => $currentpage, 'itemsperpage' => $itemsperpage);
$url = new moodle_url($CFG->wwwroot . '/mod/pdfannotator/view.php', $urlparams);
pdfannotator_print_answers($data, $thiscourse, $url, $currentpage, $itemsperpage);
}
}
/*
* This section prints a subpage of overview called "My posts".
*/
if ($action === 'overviewownposts') {

require_once($CFG->libdir . '/tablelib.php');
require_once($CFG->dirroot . '/mod/pdfannotator/locallib.php');

global $CFG, $OUTPUT;

$currentpage = optional_param('page', 0, PARAM_INT);
$itemsperpage = optional_param('itemsperpage', 5, PARAM_INT);

$thisannotator = $pdfannotator->id;
$thiscourse = $pdfannotator->course;
$cmid = get_coursemodule_from_instance('pdfannotator', $thisannotator, $thiscourse, false, MUST_EXIST)->id;

pdfannotator_prepare_overviewpage($id, $myrenderer, $taburl, 'overview', $pdfannotator, $context);
echo $OUTPUT->heading(get_string('ownpoststab', 'pdfannotator').' '.$OUTPUT->help_icon('ownpoststabicon', 'mod_pdfannotator'));

$posts = pdfannotator_get_posts_by_this_user($thiscourse);

if (empty($posts)) {
$info = get_string('nomyposts', 'pdfannotator');
echo "<span class='notification'><div class='alert alert-info alert-block fade in' role='alert'>$info</div></span>";
} else {
$urlparams = array('action' => 'overviewownposts', 'id' => $cmid, 'page' => $currentpage, 'itemsperpage' => $itemsperpage);
$url = new moodle_url($CFG->wwwroot . '/mod/pdfannotator/view.php', $urlparams);
pdfannotator_print_this_users_posts($posts, $thiscourse, $url, $currentpage, $itemsperpage);
}
}
/*
* This section prints a subpage of overview called "Reports" were comments that were reported as inappropriate are listed.
*/
if ($action === 'overviewreports') {

require_once($CFG->libdir . '/tablelib.php');
require_once($CFG->dirroot . '/mod/pdfannotator/locallib.php');

global $CFG, $OUTPUT;

$currentpage = optional_param('page', 0, PARAM_INT);
$itemsperpage = optional_param('itemsperpage', 5, PARAM_INT);

$thisannotator = $pdfannotator->id;
$thiscourse = $pdfannotator->course;
$cmid = get_coursemodule_from_instance('pdfannotator', $thisannotator, $thiscourse, false, MUST_EXIST)->id;

pdfannotator_prepare_overviewpage($id, $myrenderer, $taburl, 'overview', $pdfannotator, $context);
echo $OUTPUT->heading(get_string('reportstab', 'pdfannotator'). ' ' . $OUTPUT->help_icon('reportstabicon', 'mod_pdfannotator'));

$reports = pdfannotator_get_reports($thiscourse);

if (empty($reports)) {
$info = get_string('noreports', 'pdfannotator');
echo "<span class='notification'><div class='alert alert-info alert-block fade in' role='alert'>$info</div></span>";

} else {
$urlparams = array('action' => 'overviewreports', 'id' => $cmid, 'page' => $currentpage, 'itemsperpage' => $itemsperpage);
$url = new moodle_url($CFG->wwwroot . '/mod/pdfannotator/view.php', $urlparams);
pdfannotator_print_reports($reports, $thiscourse, $url, $currentpage, $itemsperpage);
}
}
/* This section prints a subpage of overview called "Read" were comments that were reported as inappropriate are listed
* after they were marked as seen/read/ackknowledged.
*/
if ($action === 'overviewrecyclebin') {

require_once($CFG->libdir . '/tablelib.php');
require_once($CFG->dirroot . '/mod/pdfannotator/locallib.php');

global $CFG, $USER, $OUTPUT;

$currentpage = optional_param('page', 0, PARAM_INT);
$itemsperpage = optional_param('itemsperpage', 5, PARAM_INT);
$currentview = optional_param('currentview', 0, PARAM_INT); // Answers or reports.

$thisannotator = $pdfannotator->id;
$thiscourse = $pdfannotator->course;
$cmid = get_coursemodule_from_instance('pdfannotator', $thisannotator, $thiscourse, false, MUST_EXIST)->id;

pdfannotator_prepare_overviewpage($id, $myrenderer, $taburl, 'overview', $pdfannotator, $context);

echo $OUTPUT->heading(get_string('recyclebintab', 'pdfannotator').' '.$OUTPUT->help_icon('recyclebintabicon', 'pdfannotator'));

if (has_capability('mod/pdfannotator:viewreports', $context)) {
$reports = pdfannotator_get_reports($thiscourse, 1);
if (empty($reports)) {
$info = get_string('nohiddenreports', 'pdfannotator');
echo "<div><span class='notification'><div class='alert alert-info".
"alert-block fade in' role='alert'>$info</div></span></div>";
} else {
$urlparams = array('action' => 'overviewrecyclebin', 'id' => $cmid, 'page' => $currentpage,
'currentview' => $currentview, 'itemsperpage' => $itemsperpage);
$url = new moodle_url($CFG->wwwroot . '/mod/pdfannotator/view.php', $urlparams);
pdfannotator_print_reports($reports, $thiscourse, $url, $currentpage, $itemsperpage, true);
}
}
}

/* *********************************** Display the pdf in its editor (default action) *************************************** */

if ($action === 'view') { // Default.
$PAGE->set_title("annotatorview");
echo $myrenderer->pdfannotator_render_tabs($taburl, $action, $pdfannotator->name, $context);

pdfannotator_display_embed($pdfannotator, $cm, $course, $file, $page, $annoid, $commid);
}

/* *********************************************** Display statistics *********************************************** */

if ($action === 'statistic') {

require_capability('mod/pdfannotator:viewstatistics', $context);

require_once($CFG->dirroot . '/mod/pdfannotator/model/statistics.class.php');
require_once($CFG->dirroot . '/mod/pdfannotator/classes/output/statistics.php');

echo $myrenderer->pdfannotator_render_tabs($taburl, $action, $pdfannotator->name, $context);
$PAGE->set_title("statisticview");
echo $OUTPUT->heading(get_string('activities', 'pdfannotator'));

// Give javascript access to the language string repository.
$stringman = get_string_manager();
$strings = $stringman->load_component_strings('pdfannotator', 'en'); // Method gets the strings of the language files.
$PAGE->requires->strings_for_js(array_keys($strings), 'pdfannotator'); // Method to use the language-strings in javascript.
$PAGE->requires->js(new moodle_url("/mod/pdfannotator/shared/locallib.js?ver=00002"));
$PAGE->requires->js(new moodle_url("/mod/pdfannotator/shared/statistic.js"));
$myrenderer = $PAGE->get_renderer('mod_pdfannotator');
$capabilities = new stdClass();
$capabilities->viewquestions = has_capability('mod/pdfannotator:viewquestions', $context);
$capabilities->viewanswers = has_capability('mod/pdfannotator:viewanswers', $context);
$capabilities->viewposts = has_capability('mod/pdfannotator:viewposts', $context);
$capabilities->viewreports = has_capability('mod/pdfannotator:viewreports', $context);
$capabilities->viewteacherstatistics = has_capability('mod/pdfannotator:viewteacherstatistics', $context);

// Param 'statistics' is a renderable/templatable.
echo $myrenderer->render_statistic(new statistics($cm->instance, $course->id, $capabilities, $id));
}

/* ****************************************** Display form for reporting a comment ******************************************** */

if ($action === 'report') {

require_once($CFG->dirroot . '/mod/pdfannotator/reportform.php');
require_once($CFG->dirroot . '/mod/pdfannotator/model/comment.class.php');
require_once($CFG->dirroot . '/mod/pdfannotator/model/report.class.php');

// Get comment id.
$commentid = optional_param('commentid', 0, PARAM_INT);

// Contextual data to pass on to the report form.
$data = new stdClass();
$data->course = $cm->course;
$data->pdfannotatorid = $cm->instance;
$data->pdfname = $cm->name;
$data->commentid = $commentid;
$data->id = $id; // Course module id.
$data->action = 'report';

// Initialise mform and pass on $data-object to it.
$mform = new pdfannotator_reportform();
$mform->set_data($data);

/* ******************** Form processing and displaying is done here ************************ */
if ($mform->is_cancelled()) {
$action = 'view';
echo $myrenderer->pdfannotator_render_tabs($taburl, $action, $pdfannotator->name, $context);
pdfannotator_display_embed($pdfannotator, $cm, $course, $file);
} else if ($report = $mform->get_data()) {
// In this case you process validated data. $mform->get_data() returns data posted in form.
global $DB, $USER;

// 1. Notify course manager(s).
$recipients = get_enrolled_users($context, 'mod/pdfannotator:administrateuserinput');
$name = 'newreport';
$report->reportinguser = fullname($USER);
$report->url = $CFG->wwwroot . '/mod/pdfannotator/view.php?id=' . $cm->id . '&action=overview';
$messagetext = new stdClass();
$messagetext->text = pdfannotator_format_notification_message_text($course, $cm, $context,
get_string('modulename', 'pdfannotator'), $cm->name, $report, 'reportadded');
$messagetext->html = pdfannotator_format_notification_message_html($course, $cm, $context,
get_string('modulename', 'pdfannotator'), $cm->name, $report, 'reportadded');
$messagetext->url = $report->url;
try {
foreach ($recipients as $recipient) {
$messageid = pdfannotator_notify_manager($recipient, $course, $cm, $name, $messagetext);
}
// 2. Notify the reporting user that their report has been sent off (display blue toast box at top of page).
\core\notification::info(get_string('reportwassentoff', 'pdfannotator'));
} catch (Exception $ex) {
$info = $ex->getMessage();
\core\notification::error($info);
}

// 3. Save report in db.
$record = new stdClass();
$record->commentid = $report->commentid;
$record->courseid = $cm->course;
$record->pdfannotatorid = $cm->instance;
$record->message = $report->introduction;
$record->userid = $USER->id;
$record->timecreated = time();
$record->seen = 0;

$reportid = $DB->insert_record('pdfannotator_reports', $record, $returnid = true, $bulk = false);
if (empty($reportid)) {
\core\notification::error(get_string('error:reportComment', 'pdfannotator'));
}

$action = 'view';
echo $myrenderer->pdfannotator_render_tabs($taburl, $action, $pdfannotator->name, $context);
pdfannotator_display_embed($pdfannotator, $cm, $course, $file);
} else { // This branch is executed if the form is submitted but the data doesn't validate and the form should be redisplayed
// or on the first display of the form.
$PAGE->set_title("reportform");
echo $OUTPUT->heading(get_string('titleforreportcommentform', 'pdfannotator'));

// Get information about the comment to be reported.
$comment = new pdfannotator_comment($commentid);
$info = pdfannotator_comment_info::make_from_comment($comment);

// Display it in a table.
$myrenderer = $PAGE->get_renderer('mod_pdfannotator');
echo $myrenderer->render_pdfannotator_comment_info($info);

// Now display the complaint form itself.
$mform->display();
}
return;
}

/* *********************************************** Display feedback page *********************************************** */

if ($action === 'feedback') {

global $PAGE;

require_once($CFG->dirroot . '/mod/pdfannotator/feedback_form.php');
$PAGE->requires->js(new moodle_url("/mod/pdfannotator/shared/locallib.js?ver=00002"));

// Contextual data to pass on to the feedback form.
$data = new stdClass();
$data->id = $id;
$data->course = $cm->course;
$data->pdfid = $cm->instance;
$data->pdfname = $cm->name;
$data->action = 'feedback';

$mform = new pdfannotator_feedback_form();
$mform->set_data($data);

if ($mform->is_cancelled()) {
echo $myrenderer->pdfannotator_render_tabs($taburl, 'view', $pdfannotator->name);
pdfannotator_display_embed($pdfannotator, $cm, $course, $file);
} else if ($formdata = $mform->get_data()) {

global $USER;

// 1. Send email to Ahmad, Rabea and Anna.
$formdata = $mform->get_data();
pdfannotator_send_feedbackmail($formdata);

// 2. Thank user for their feedback (display 'blue box' at top of page).
\core\notification::info(get_string('feedbackwassentoff', 'pdfannotator'));

// 3. Display pdf once more.
echo $myrenderer->pdfannotator_render_tabs($taburl, 'view', $pdfannotator->name, $context);
pdfannotator_display_embed($pdfannotator, $cm, $course, $file);
} else {

$PAGE->set_title("feedback");

echo $myrenderer->pdfannotator_render_tabs($taburl, $action, $pdfannotator->name, $context);
$capabilities = new stdClass();
$capabilities->viewquestions = has_capability('mod/pdfannotator:viewquestions', $context);
$capabilities->viewanswers = has_capability('mod/pdfannotator:viewanswers', $context);
$capabilities->viewposts = has_capability('mod/pdfannotator:viewposts', $context);
$capabilities->viewreports = has_capability('mod/pdfannotator:viewreports', $context);
$stringman = get_string_manager();
// With this method you get the strings of the language-Files.
$strings = $stringman->load_component_strings('pdfannotator', 'en');
// Method to use the language-strings in javascript.
$PAGE->requires->strings_for_js(array_keys($strings), 'pdfannotator');
$PAGE->requires->js_init_call('addDropdownNavigation', array($capabilities, $id), true);

echo "<p>" . get_string('pleaforfeedback', 'pdfannotator') . "</p>";

$mform->display();
}
}

+ 2
- 2
db/access.php View File

@@ -239,7 +239,7 @@ $capabilities = array(
),
),

// ********************** capabilities for viewing the overview page **********************
/* ********************** capabilities for viewing the overview page ********************** */

// View reports of comments.
'mod/pdfannotator:viewreports' => array (
@@ -286,7 +286,7 @@ $capabilities = array(
),


// ********************** capabilities for viewing the statistics page **********************
/* ********************** capabilities for viewing the statistics page ********************** */
'mod/pdfannotator:viewstatistics' => array ( // View statistics page.
'captype' => 'write',
'contextlevel' => CONTEXT_MODULE,


+ 47
- 47
db/messages.php View File

@@ -1,47 +1,47 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* The pdfannotator plugin is registered as a message provider and the messages
* produced are defined.
*
* @package mod_pdfannotator
* @copyright 2018 RWTH Aachen, Rabea de Groot and Anna Heynkes(see README.md)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*
*/
defined('MOODLE_INTERNAL') || die();
$messageproviders = array (
// Notify student that one of her/his questions received a new answer.
'newanswer' => array (
'capability' => 'mod/pdfannotator:viewanswers' // Student capability.
),
// Notify teacher about a newly reported comment.
'newreport' => array (
'capability' => 'mod/pdfannotator:viewreports' // Teacher capability.
),
'newquestion' => array (
'capability' => 'mod/pdfannotator:recievenewquestionnotifications' // All capabilities.
),
'pdfannotator_feedback' => array (
'capability' => 'mod/pdfannotator:givefeedback', // Student, editing teacher and manager capability.
)
);
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* The pdfannotator plugin is registered as a message provider and the messages
* produced are defined.
*
* @package mod_pdfannotator
* @copyright 2018 RWTH Aachen, Rabea de Groot and Anna Heynkes(see README.md)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*
*/
defined('MOODLE_INTERNAL') || die();
$messageproviders = array (
// Notify student that one of her/his questions received a new answer.
'newanswer' => array (
'capability' => 'mod/pdfannotator:viewanswers' // Student capability.
),
// Notify teacher about a newly reported comment.
'newreport' => array (
'capability' => 'mod/pdfannotator:viewreports' // Teacher capability.
),
'newquestion' => array (
'capability' => 'mod/pdfannotator:recievenewquestionnotifications' // All capabilities.
),
'pdfannotator_feedback' => array (
'capability' => 'mod/pdfannotator:givefeedback', // Student, editing teacher and manager capability.
)
);

+ 4
- 2
db/upgrade.php View File

@@ -187,7 +187,8 @@ function xmldb_pdfannotator_upgrade($oldversion) {

// Define field use_studentdrawing to be added to pdfannotator.
$table = new xmldb_table('pdfannotator');
$field = new xmldb_field('use_studentdrawing', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0', 'use_studenttextbox');
$field = new xmldb_field('use_studentdrawing', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL,
null, '0', 'use_studenttextbox');

// Conditionally launch add field use_studentdrawing.
if (!$dbman->field_exists($table, $field)) {
@@ -341,7 +342,8 @@ function xmldb_pdfannotator_upgrade($oldversion) {

// Define key annotationtypeid (foreign) to be added to pdfannotator_annotations.
$table = new xmldb_table('pdfannotator_annotations');
$key = new xmldb_key('annotationtypeid', XMLDB_KEY_FOREIGN, array('annotationtypeid'), 'pdfannotator_annotationtypes', array('id'));
$key = new xmldb_key('annotationtypeid', XMLDB_KEY_FOREIGN, array('annotationtypeid'),
'pdfannotator_annotationtypes', array('id'));

// Launch add key annotationtypeid.
$dbman->add_key($table, $key);


+ 1
- 1
index.php View File

@@ -29,7 +29,7 @@ $id = required_param('id', PARAM_INT); // Course ID.
if (!$course = $DB->get_record('course', array('id' => $id))) {
print_error('Course ID is incorrect');
}
// $course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST);
require_course_login($course, true);
$PAGE->set_pagelayout('incourse');



+ 7
- 7
lang/de/pdfannotator.php View File

@@ -433,7 +433,7 @@ $string['successfullyEdited'] = 'Ihre Änderungen wurden übernommen.';

$string['unsubscribingDidNotWork'] = 'Bei der Kündigung des Abonnements ist ein Fehler aufgetreten.';

$string['seeabove'] = ''; // 's.o.';
$string['seeabove'] = '';

/* *********************************** statistics-tab ***********************************/

@@ -491,32 +491,32 @@ $string['answerSolved'] = 'Diese Antwort wurde vom Manager als richtig markiert.

$string['privacy:metadata:core_files'] = 'Der Pdfannotator speichert Dateien, die ein Benutzer als Annotations- und Diskussionsgrundlage hochgeladen hat.';

// pdfannotator_annotations-table
/* pdfannotator_annotations-table */
$string['privacy:metadata:pdfannotator_annotations'] = "Informationen über die Annotationen eines Nutzers. Dies beinhaltet den Annotationstypen (z.B. Textmarkierung oder Freihandzeichnung), die Position innerhalb einer bestimmten Pdf-Datei sowie den Erstellungszeitpunkt.";
$string['privacy:metadata:pdfannotator_annotations:userid'] = 'Die ID des Nutzers, der diese Annotation angelegt hat.';
$string['privacy:metadata:pdfannotator_annotations:annotationid'] = 'Die ID der vom Nutzer angelegten Annotation. Unter dieser ID sind die oben genannten Daten gespeichert.';

// pdfannotator_comments-table
/* pdfannotator_comments-table */
$string['privacy:metadata:pdfannotator_comments'] = "Informationen über die Kommentare eines Nutzers. Dies beinhaltet den Inhalt und Erstellungszeitpunkt des Kommentars sowie die Annotation, auf die sich der Kommentar bezieht.";
$string['privacy:metadata:pdfannotator_comments:userid'] = 'Die ID des Nutzers, der diesen Kommentar verfasst hat.';
$string['privacy:metadata:pdfannotator_comments:annotationid'] = 'Die ID der zugrunde liegenden Annotation.';
$string['privacy:metadata:pdfannotator_comments:content'] = 'Der Wortlaut des Kommentars.';

// pdfannotator_commentsarchive-table
/* pdfannotator_commentsarchive-table */
$string['privacy:metadata:pdfannotator_commentsarchive'] = "Kommentare die gemeldet und anschließend gelöscht wurde, werden hier archiviert. Dabei werden dieselben Daten wie bei anderen Kommentaren gespeichert.";

// pdfannotator_reports-table
/* pdfannotator_reports-table */
$string['privacy:metadata:pdfannotator_reports'] = "Nutzer können die Kommentare anderer Nutzer als unangemessen melden. Diese Meldung werden gespeichert. Folgende Informationen über Meldung werden gespeichert: Die ID des gemeldeten Kommentars sowie der Verfasser, Wortlaut und Zeitpunkt der Meldung.";
$string['privacy:metadata:pdfannotator_reports:commentid'] = 'Die ID des gemeldeten Kommentars.';
$string['privacy:metadata:pdfannotator_reports:message'] = 'Der Inhalt der Meldung.';
$string['privacy:metadata:pdfannotator_reports:userid'] = 'Der Verfasser der Meldung.';

// pdfannotator_subscriptions-table
/* pdfannotator_subscriptions-table */
$string['privacy:metadata:pdfannotator_subscriptions'] = "Informationen über abonnierte Fragen bzw. Diskussionen.";
$string['privacy:metadata:pdfannotator_subscriptions:annotationid'] = 'Die ID der abonnierten Frage bzw. Diskussion.';
$string['privacy:metadata:pdfannotator_subscriptions:userid'] = 'Die ID des Nutzers, der diese Frage bzw. Diskussion abonniert hat.';

// pdfannotator_votes-table
/* pdfannotator_votes-table */
$string['privacy:metadata:pdfannotator_votes'] = "Informationen über Fragen und Kommentare, die als interessant bzw. hilfreich markiert wurden.";
$string['privacy:metadata:pdfannotator_votes:commentid'] = "Die ID des Kommentars.";
$string['privacy:metadata:pdfannotator_votes:userid'] = "Die ID des Nutzers, der den Kommentar markiert hat. Diese wird gespeichert, damit ein Nutzer nicht mehrfach für denselben Kommentar stimmen kann.";


+ 6
- 7
lang/en/pdfannotator.php View File

@@ -366,7 +366,6 @@ $string['timecouldnotbeset'] = 'An error has occured.';

$string['hideforever'] = 'Hide permanently';
$string['hideanswerforever'] = 'Hide permanently';
// $string['displayagain'] = 'Display this report once more';
$string['displayagain'] = 'Display once more';
$string['displayreportagain'] = 'Display report';
$string['deletereport'] = 'Delete this report permanently';
@@ -477,32 +476,32 @@ $string['answerSolved'] = 'This answer was marked as correct by the manager.';

$string['privacy:metadata:core_files'] = 'The Pdfannotator stores files which have been uploaded by the user as a basis for annotation and discussion.';

// pdfannotator_annotations table
/* pdfannotator_annotations table */
$string['privacy:metadata:pdfannotator_annotations'] = "Information about the annotations a user made. This includes the type of annotation (e.g. highlight or drawing), its position within a specific file, as well as the time of creation.";
$string['privacy:metadata:pdfannotator_annotations:userid'] = 'The ID of the user who made this annotation.';
$string['privacy:metadata:pdfannotator_annotations:annotationid'] = 'The ID of the annotation that was made. It refers to the data listed above.';

// pdfannotator_comments table
/* pdfannotator_comments table */
$string['privacy:metadata:pdfannotator_comments'] = "Information about a user's comments. This includes the content and time of creation of the comment, as well as the underlying annotation.";
$string['privacy:metadata:pdfannotator_comments:userid'] = "The ID of the comment's author.";
$string['privacy:metadata:pdfannotator_comments:annotationid'] = 'The ID of the underlying annotation.';
$string['privacy:metadata:pdfannotator_comments:content'] = 'The literal comment.';

// pdfannotator_commentsarchive table
/* pdfannotator_commentsarchive table */
$string['privacy:metadata:pdfannotator_commentsarchive'] = "Comments which were reported and subsequently deleted are archived here. The information stored is the same as for other comments.";

// pdfannotator_reports table
/* pdfannotator_reports table */
$string['privacy:metadata:pdfannotator_reports'] = "Users can report other users' comments as inappropriate. These reports stored. This includes the ID of the reported comment as well as the author, content and time of the report.";
$string['privacy:metadata:pdfannotator_reports:commentid'] = 'The ID of the reported comment.';
$string['privacy:metadata:pdfannotator_reports:message'] = 'The text content of the report.';
$string['privacy:metadata:pdfannotator_reports:userid'] = 'The author of the report.';

// pdfannotator_subscriptions table
/* pdfannotator_subscriptions table */
$string['privacy:metadata:pdfannotator_subscriptions'] = "Information about the subscriptions to individual questions/discussions.";
$string['privacy:metadata:pdfannotator_subscriptions:annotationid'] = 'The ID of the question/discussion that was subscribed to.';
$string['privacy:metadata:pdfannotator_subscriptions:userid'] = 'The ID of the user with this subscription.';

// pdfannotator_votes table
/* pdfannotator_votes table */
$string['privacy:metadata:pdfannotator_votes'] = "Information about questions and comments that were marked as interesting or helpful.";
$string['privacy:metadata:pdfannotator_votes:commentid'] = "The ID of the comment.";
$string['privacy:metadata:pdfannotator_votes:userid'] = "The ID of the user who marked the comment as interesting or helpful. It is saved in order to prevent users from voting for the same comment repeatedly.";


+ 33
- 60
lib.php View File

@@ -27,14 +27,15 @@ defined('MOODLE_INTERNAL') || die;
*/
function pdfannotator_supports($feature) {
switch($feature) {
case FEATURE_GROUPS: return true;
case FEATURE_GROUPINGS: return true;
case FEATURE_MOD_INTRO: return true;
case FEATURE_COMPLETION_TRACKS_VIEWS: return true;
case FEATURE_BACKUP_MOODLE2: return true;
case FEATURE_SHOW_DESCRIPTION: return true;

default: return null;
case FEATURE_GROUPS:
case FEATURE_GROUPINGS:
case FEATURE_MOD_INTRO:
case FEATURE_COMPLETION_TRACKS_VIEWS:
case FEATURE_BACKUP_MOODLE2:
case FEATURE_SHOW_DESCRIPTION:
return true;
default:
return null;
}
}
/**
@@ -236,7 +237,8 @@ function pdfannotator_get_coursemodule_info($coursemodule) {

$context = context_module::instance($coursemodule->id);

if (!$pdfannotator = $DB->get_record('pdfannotator', array('id' => $coursemodule->instance), 'id, name, course, timemodified, timecreated, intro, introformat')) {
if (!$pdfannotator = $DB->get_record('pdfannotator', array('id' => $coursemodule->instance),
'id, name, course, timemodified, timecreated, intro, introformat')) {
return null;
}

@@ -252,7 +254,6 @@ function pdfannotator_get_coursemodule_info($coursemodule) {
$files = $fs->get_area_files($context->id, 'mod_pdfannotator', 'content', 0, 'sortorder DESC, id ASC', false, 0, 0, 1);
if (count($files) >= 1) {
$mainfile = reset($files);
// $info->icon = file_file_icon($mainfile, 24); // Uncomment to use pdf icon.
$pdfannotator->mainfile = $mainfile->get_filename();
}
// If any optional extra details are turned on, store in custom data,
@@ -331,7 +332,8 @@ function pdfannotator_get_file_info($browser, $areas, $course, $cm, $context, $f
}
}
require_once("$CFG->dirroot/mod/pdfannotator/locallib.php");
return new pdfannotator_content_file_info($browser, $context, $storedfile, $urlbase, $areas[$filearea], true, true, true, false);
return new pdfannotator_content_file_info($browser, $context, $storedfile, $urlbase,
$areas[$filearea], true, true, true, false);
}

// Note: pdfannotator_intro handled in file_browser automatically.
@@ -393,7 +395,8 @@ function pdfannotator_pluginfile($course, $cm, $context, $filearea, $args, $forc
if ($pdfannotator->legacyfiles != RESOURCELIB_LEGACYFILES_ACTIVE) {
return false;
}
if (!$file = resourcelib_try_file_migration('/' . $relativepath, $cm->id, $cm->course, 'mod_pdfannotator', 'content', 0)) {
if (!$file = resourcelib_try_file_migration('/' . $relativepath, $cm->id, $cm->course,
'mod_pdfannotator', 'content', 0)) {
return false;
}
// File migrate - update flag.
@@ -403,7 +406,6 @@ function pdfannotator_pluginfile($course, $cm, $context, $filearea, $args, $forc
} while (false);

// Should we apply filters?
// $mimetype = $file->get_mimetype();
$filter = 0;
// Finally send the file.
send_stored_file($file, null, $filter, $forcedownload, $options);
@@ -441,7 +443,8 @@ function pdfannotator_export_contents($cm, $baseurl) {
$file['filesize'] = $fileinfo->get_filesize();
$file['mimetype'] = 'pdf';
$file['fileurl'] = moodle_url::make_webservice_pluginfile_url(
$context->id, 'mod_pdfannotator', 'content', '1', $fileinfo->get_filepath(), $fileinfo->get_filename())->out(false);
$context->id, 'mod_pdfannotator', 'content', '1', $fileinfo->get_filepath(),
$fileinfo->get_filename())->out(false);
$file['timecreated'] = $fileinfo->get_timecreated();
$file['timemodified'] = $fileinfo->get_timemodified();
$file['sortorder'] = $fileinfo->get_sortorder();
@@ -458,37 +461,6 @@ function pdfannotator_export_contents($cm, $baseurl) {
return $contents;
}

/**
* Register the ability to handle drag and drop file uploads
* @return array containing details of the files / types the mod can handle
*/
// function pdfannotator_dndupload_register() {
// return array('files' => array(
// array('extension' => 'pdf', 'message' => get_string('dnduploadpdfannotator', 'mod_pdfannotator'))
// ));
// }

/**
* Handle a file that has been uploaded
* @param object $uploadinfo details of the file / content that has been uploaded
* @return int instance id of the newly created mod
*/
// function pdfannotator_dndupload_handle($uploadinfo) {
// // Gather the required info.
// $data = new stdClass();
// $data->course = $uploadinfo->course->id;
// $data->name = $uploadinfo->displayname;
// $data->intro = '';
// $data->introformat = FORMAT_HTML;
// $data->coursemodule = $uploadinfo->coursemodule;
// $data->files = $uploadinfo->draftitemid;
//
// // Set the display options to the site defaults.
// $config = get_config('pdfannotator');//
//
// return pdfannotator_add_instance($data, null);
// }

/**
* Mark the activity completed (if required) and trigger the course_module_viewed event.
*
@@ -592,15 +564,16 @@ function pdfannotator_get_recent_mod_activity(&$activities, &$index, $timestart,
$groupselect = "";
}
$allnames = get_all_user_name_fields(true, 'u');
if (!$posts = $DB->get_records_sql("SELECT p.*,c.id, c.userid AS duserid, c.visibility, c.content, c.timecreated, c.annotationid, c.isquestion,
$allnames, u.email, u.picture, u.imagealt, u.email, a.page
FROM {pdfannotator} p
JOIN {pdfannotator_annotations} a ON a.pdfannotatorid=p.id
JOIN {pdfannotator_comments} c ON c.annotationid = a.id
JOIN {user} u ON u.id = a.userid
WHERE c.timecreated > ? AND p.id = ?
$userselect AND c.isdeleted=0
ORDER BY p.id ASC ", $params)) { // Order by initial posting date.
if (!$posts = $DB->get_records_sql(
"SELECT p.*,c.id, c.userid AS duserid, c.visibility, c.content, c.timecreated, c.annotationid, c.isquestion,
$allnames, u.email, u.picture, u.imagealt, u.email, a.page
FROM {pdfannotator} p
JOIN {pdfannotator_annotations} a ON a.pdfannotatorid=p.id
JOIN {pdfannotator_comments} c ON c.annotationid = a.id
JOIN {user} u ON u.id = a.userid
WHERE c.timecreated > ? AND p.id = ?
$userselect AND c.isdeleted=0
ORDER BY p.id ASC ", $params)) { // Order by initial posting date.
return;
}
$printposts = array();
@@ -632,7 +605,6 @@ function pdfannotator_get_recent_mod_activity(&$activities, &$index, $timestart,
$tmpactivity->visible = $post->visibility;

$tmpactivity->user = new stdClass();
// $additionalfields = array('id' => 'userid', 'picture', 'imagealt', 'email');
$additionalfields = explode(',', user_picture::fields());
$tmpactivity->user = username_load_fields_from_object($tmpactivity->user, $post, null, $additionalfields);
$tmpactivity->user->id = $post->duserid;
@@ -677,9 +649,9 @@ function pdfannotator_print_recent_mod_activity($activity, $courseid, $detail, $
if (!$authorhidden) {
$picture = $OUTPUT->user_picture($activity->user, $pictureoptions);
} else {
// $pictureoptions = [ 'courseid' => $courseid, 'link' => $authorhidden, 'alttext' => $authorhidden, ];
$pic = $OUTPUT->image_url('/u/f2');
$picture = '<img src="' . $pic . '" class="userpicture" alt="' . get_string('anonymous', 'pdfannotator') . '" width="35" height="35">';
$picture = '<img src="'.$pic.'" class="userpicture" alt="'.get_string('anonymous', 'pdfannotator').
'" width="35" height="35">';
}
$output .= html_writer::tag('td', $picture, ['class' => 'userpicture', 'valign' => 'top']);

@@ -693,10 +665,11 @@ function pdfannotator_print_recent_mod_activity($activity, $courseid, $detail, $
$aname = s($activity->name);
$output .= $OUTPUT->image_icon('icon', $aname, $activity->type);
}
$isquestion = ($content->isquestion) ? '<img src="' . $OUTPUT->image_url('t/message') . '" alt="' . get_string('question', 'pdfannotator')
$isquestion = ($content->isquestion) ? '<img src="' . $OUTPUT->image_url('t/message')
. '" alt="' . get_string('question', 'pdfannotator')
. '" title="' . get_string('question', 'pdfannotator') . '"> ' : '';
$discussionurl = new moodle_url('/mod/pdfannotator/view.php', ['id' => $activity->cmid, 'page' => $content->page, 'annoid' => $content->id, 'commid' => $content->commid]);
// $discussionurl->set_anchor('p' . $activity->content->id);
$discussionurl = new moodle_url('/mod/pdfannotator/view.php',
['id' => $activity->cmid, 'page' => $content->page, 'annoid' => $content->id, 'commid' => $content->commid]);
$output .= html_writer::link($discussionurl, ($isquestion . $content->discussion));
$output .= html_writer::end_div();



+ 78
- 59
locallib.php View File

@@ -36,12 +36,13 @@ function pdfannotator_display_embed($pdfannotator, $cm, $course, $file, $page =
global $CFG, $PAGE, $OUTPUT, $USER;
require_once($CFG->dirroot . '/mod/pdfannotator/classes/output/index.php');

// The revision attribute's existance is demanded by moodle for versioning and could be saved in the pdfannotator table in the future.
// The revision attribute's existance is demanded by moodle for versioning and could
// be saved in the pdfannotator table in the future.
// Note, however, that we forbid file replacement in order to prevent a change of meaning in other people's comments.
$pdfannotator->revision = 1;

$context = context_module::instance($cm->id);
$path = '/' . $context->id . '/mod_pdfannotator/content/' . $pdfannotator->revision . $file->get_filepath() . $file->get_filename();
$path = '/'.$context->id.'/mod_pdfannotator/content/'.$pdfannotator->revision.$file->get_filepath().$file->get_filename();
$fullurl = file_encode_url($CFG->wwwroot . '/pluginfile.php', $path, false);

$documentobject = new stdClass();
@@ -83,7 +84,8 @@ function pdfannotator_display_embed($pdfannotator, $cm, $course, $file, $page =
$capabilities->usetextbox = has_capability('mod/pdfannotator:usetextbox', $context);
$capabilities->usedrawing = has_capability('mod/pdfannotator:usedrawing', $context);

$params = array($cm, $documentobject, $USER->id, $administratesuserinput, $toolbarsettings, $page, $annoid, $commid, $capabilities);
$params = array($cm, $documentobject, $USER->id, $administratesuserinput, $toolbarsettings,
$page, $annoid, $commid, $capabilities);
$PAGE->requires->js_init_call('adjustPdfannotatorNavbar', null, true);
$PAGE->requires->js_init_call('startIndex', $params, true);
// The renderer renders the original index.php / takes the template and renders it.
@@ -132,23 +134,14 @@ function pdfannotator_get_annotationtype_name($typeid) {
}
}

/* function pdfannotator_get_typename_of_annotation($annotationid) {
global $DB;
$result = $DB->get_records('pdfannotator_annotations', array('id' => $annotationid));
return pdfannotator_get_annotationtype_name($result[$annotationid]->annotationtypeid);
} */

function pdfannotator_handle_latex($subject) {

global $CFG;
require_once($CFG->dirroot . '/mod/pdfannotator/constants.php');

// Look for these formulae: $$ ... $$, \( ... \) and \[ ... \]
// !!! keep indentation!
$pattern = <<<'SIGN'
~(?:\$\$.*?\$\$)|(?:\\\(.*?\\\))|(?:\\\[.*?\\\])~