Browse Source

checkin update from upstream

us-8-thumbtack
Jan Koppe 1 year ago
parent
commit
818a0b257a
Signed by: j <post@jankoppe.de> GPG Key ID: BE935B0735A2129B
69 changed files with 6924 additions and 4336 deletions
  1. +7
    -1
      README.md
  2. +217
    -144
      action.php
  3. +16
    -2
      backup/moodle2/backup_pdfannotator_activity_task.class.php
  4. +45
    -27
      backup/moodle2/backup_pdfannotator_stepslib.php
  5. +22
    -6
      backup/moodle2/restore_pdfannotator_activity_task.class.php
  6. +30
    -13
      backup/moodle2/restore_pdfannotator_stepslib.php
  7. +14
    -1
      classes/event/course_module_instance_list_viewed.php
  8. +14
    -0
      classes/event/course_module_viewed.php
  9. +2
    -2
      classes/event/report_added.php
  10. +179
    -0
      classes/output/comment.php
  11. +106
    -45
      classes/output/index.php
  12. +0
    -447
      classes/output/overview.php
  13. +51
    -0
      classes/output/printview.php
  14. +20
    -12
      classes/output/statistics.php
  15. +165
    -168
      classes/privacy/provider.php
  16. +34
    -0
      constants.php
  17. +382
    -171
      controller.php
  18. +221
    -29
      db/access.php
  19. +16
    -0
      db/events.php
  20. +37
    -0
      db/install.php
  21. +11
    -5
      db/install.xml
  22. +47
    -34
      db/messages.php
  23. +16
    -0
      db/mobile.php
  24. +504
    -0
      db/upgrade.php
  25. +72
    -0
      feedback_form.php
  26. +18
    -3
      index.php
  27. +256
    -75
      lang/de/pdfannotator.php
  28. +223
    -57
      lang/en/pdfannotator.php
  29. +65
    -82
      lib.php
  30. +1128
    -43
      locallib.php
  31. +50
    -61
      mod_form.php
  32. +112
    -62
      model/annotation.class.php
  33. +212
    -179
      model/comment.class.php
  34. +160
    -0
      model/overviewtable.php
  35. +339
    -311
      model/pdfannotator.php
  36. +18
    -3
      model/report.class.php
  37. +204
    -205
      model/statistics.class.php
  38. BIN
      pix/area.PNG
  39. +3
    -0
      pix/delete.svg
  40. +3
    -0
      pix/download.svg
  41. BIN
      pix/flagged.png
  42. BIN
      pix/highlight.png
  43. +0
    -0
      pix/link_small.png
  44. BIN
      pix/pin.PNG
  45. +5
    -0
      pix/print.svg
  46. +22
    -0
      pix/print_comments.svg
  47. BIN
      pix/strikeout.PNG
  48. +20
    -7
      renderable.php
  49. +31
    -51
      renderer.php
  50. +72
    -59
      reportform.php
  51. +24
    -19
      settings.php
  52. +869
    -547
      shared/index.js
  53. +168
    -52
      shared/locallib.js
  54. +372
    -786
      shared/overview.js
  55. +1
    -1
      shared/statistic.js
  56. +2
    -2
      shared/textclipper.js
  57. +139
    -106
      styles.css
  58. +76
    -0
      templates/comment.mustache
  59. +55
    -46
      templates/index.mustache
  60. +0
    -98
      templates/overview.mustache
  61. +0
    -55
      templates/overview_administrate_entries.mustache
  62. +0
    -54
      templates/overview_answers.mustache
  63. +0
    -53
      templates/overview_hidden_reports.mustache
  64. +0
    -46
      templates/overview_my_posts.mustache
  65. +0
    -45
      templates/overview_new_questions.mustache
  66. +0
    -54
      templates/overview_reports.mustache
  67. +14
    -34
      templates/statistic.mustache
  68. +7
    -5
      version.php
  69. +28
    -28
      view.php

+ 7
- 1
README.md View File

@@ -11,4 +11,10 @@ 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/>.
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
Please note that this plugin also contains files that are under the
- MIT License: namely index.js, jquery-3.2.1, textclipper.js.
- Apache License, Version 2.0: namely pdf.js.
Google Charts Api is used in download function to convert latex formulae to png: <https://chart.googleapis.com/chart>.

+ 217
- 144
action.php View File

@@ -1,4 +1,19 @@
<?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/>.

/**
* In this file, incoming AJAX request from the Store Adapter in index.js are handled.
* These requests concern the creation, retrieval and deletion of annotations
@@ -11,7 +26,8 @@
* 2. studentoverview: hide, redisplay and delete answer notifications (yet to be completed)
*
* @package mod_pdfannotator
* @copyright 2018 RWTH Aachen, Rabea de Groot and Anna Heynkes (see README.md)
* @author Ahmad Obeid (ahmad.obeid@rwth-aachen.de), Anna Heynkes, Friedericke Schwager
* @copyright 2018 RWTH Aachen
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once('../../config.php');
@@ -21,18 +37,20 @@ require_once('reportform.php');
require_once($CFG->dirroot . '/mod/pdfannotator/locallib.php');

$documentid = required_param('documentId', PARAM_PATH);
$action = required_param('action', PARAM_ALPHA); // '$action' determines what is to be done; see below:
$action = required_param('action', PARAM_ALPHA); // ...'$action' determines what is to be done; see below.

$pdfannotator = $DB->get_record('pdfannotator', array('id' => $documentid), '*', MUST_EXIST);
$cm = get_coursemodule_from_instance('pdfannotator', $documentid, $pdfannotator->course, false, MUST_EXIST);
require_course_login($pdfannotator->course, true, $cm);
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
$context = context_module::instance($cm->id);

require_course_login($pdfannotator->course, true, $cm);
require_capability('mod/pdfannotator:view', $context);
require_sesskey();

/* * ****************************************** 1. HANDLING ANNOTATIONS ****************************************** */
/* * ************************************************************************************************************* */

/* * ****************************************** Retrieve all annotations from db for display ****************************************** */
/* * ******************************* Retrieve all annotations from db for display ******************************* */

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

@@ -49,7 +67,7 @@ if ($action === 'read') {

$entry = json_decode($record->data); // StdClass Object containing data that is specific to the respective annotation type.
// Add general annotation data.
$entry->type = pdfannotator_get_name_of_annotationtype($record->annotationtypeid);
$entry->type = pdfannotator_get_annotationtype_name($record->annotationtypeid);
// The following 3 lines can be removed after deletion of the original annotation tables.
if ($entry->type == 'pin') {
$entry->type = 'point';
@@ -67,42 +85,39 @@ if ($action === 'read') {
echo json_encode($data);
}

/* * ************************************ Select a single annotation from db for shifting ****************************************** */
/* * **************************** Select a single annotation from db for shifting ********************************** */

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

global $DB;
global $DB, $USER;
$annotationid = required_param('annotationId', PARAM_INT);
$page = optional_param('page_Number', 1, PARAM_INT);

$records = $DB->get_records('pdfannotator_annotations', array('id' => $annotationid));
foreach ($records as $record) {
$annotation = json_decode($record->data);
// Add general annotation data.
$annotation->type = pdfannotator_get_name_of_annotationtype($record->annotationtypeid);
// The following 3 lines can be removed after deletion of the original annotation tables.
if ($annotation->type == 'pin') {
$annotation->type = 'point';
}
$annotation->class = "Annotation";
$annotation->page = $record->page;
$annotation->uuid = $record->id;
$data = array('documentId' => $documentid, 'annotation' => $annotation);
echo json_encode($data);
return;
$record = $DB->get_record('pdfannotator_annotations', array('id' => $annotationid), '*', MUST_EXIST);

$annotation = json_decode($record->data);
// Add general annotation data.
$annotation->type = pdfannotator_get_annotationtype_name($record->annotationtypeid);
// The following 3 lines can be removed after deletion of the original annotation tables.
if ($annotation->type == 'pin') {
$annotation->type = 'point';
}
$annotation->class = "Annotation";
$annotation->page = $record->page;
$annotation->uuid = $record->id;
$data = array('documentId' => $documentid, 'annotation' => $annotation);
echo json_encode($data);
return;
}

/* * ****************************************** Save (1) and display (2) a new annotation ****************************************** */
/* * ********************************** Save (1) and display (2) a new annotation ********************************** */

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

global $DB;
global $USER;

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

$isteacher = has_capability('mod/pdfannotator:administrateuserinput', $context);
require_capability('mod/pdfannotator:create', $context);

$table = "pdfannotator_annotations";

@@ -113,7 +128,7 @@ if ($action === 'create') {
$annotation = json_decode($annotationjs, true);
// 1.2 Determine the type of the annotation.
$type = $annotation['type'];
$typeid = pdfannotator_get_id_of_annotationtype($type);
$typeid = pdfannotator_get_annotationtype_id($type);
// 1.3 Set the type-specific data of the annotation.
$data = [];
switch ($type) {
@@ -124,8 +139,9 @@ if ($action === 'create') {
$data['height'] = $annotation['height'];
break;
case 'drawing':
$studentdrawingsallowed = $DB->get_field('pdfannotator', 'use_studentdrawing', array('id' => $documentid), $strictness = MUST_EXIST);
if ($studentdrawingsallowed !== 1 && !$isteacher) {
$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')]);
return;
}
@@ -147,7 +163,8 @@ if ($action === 'create') {
break;
case 'textbox':
$studenttextboxesallowed = $DB->get_field('pdfannotator', 'use_studenttextbox', array('id' => $documentid), $strictness = MUST_EXIST);
if ($studenttextboxesallowed !== 1 && !$isteacher) {
$alwaystextboxallowed = has_capability('mod/pdfannotator:usetextbox', $context);
if ($studenttextboxesallowed != 1 && !$alwaystextboxallowed) {
echo json_encode(['status' => 'error', 'reason' => get_string('studenttextboxforbidden', 'pdfannotator')]);
return;
}
@@ -187,6 +204,7 @@ if ($action === 'create') {
/* * ****************************************** Update an annotation ****************************************** */

if ($action === 'update') {
require_capability('mod/pdfannotator:edit', $context);

// 1. Get the id of the annotation that is to be shifted in position.
$annotationid = required_param('annotationId', PARAM_INT);
@@ -195,8 +213,9 @@ if ($action === 'update') {
$datajs = required_param('annotation', PARAM_TEXT);
$data = json_decode($datajs, true);

// 3. Check whether the current user is allowed to shift this annotation, i.e. whether it's his and hasn't been commented by other people.
if (pdfannotator_annotation::shifting_allowed($annotationid)) {
// 3. Check whether the current user is allowed to shift this annotation,
// i.e. whether it's theirs or they are an admin.
if (pdfannotator_annotation::shifting_allowed($annotationid, $context)) {

$annotation = $data['annotation'];
$type = $annotation['type'];
@@ -204,7 +223,8 @@ if ($action === 'update') {

// 4. If so, update the annotations 'data' attribute in mdl_pdfannotator_annotations.
// Note that while only part of the data may change, the whole JSON-string has to be construced anew.
// e.g. drawing: Only the 'lines' actually change, but the database stores them together with width and color in a single JSON-string called 'data'.
// e.g. drawing: Only the 'lines' actually change, but the database stores them together with width
// and color in a single JSON-string called 'data'.
switch ($type) {

case 'area':
@@ -236,16 +256,15 @@ if ($action === 'update') {
break;
}

$success = pdfannotator_annotation::update($annotationid, $newdata);
$result = pdfannotator_annotation::update($annotationid, $newdata);

// 5. If the updated data received from the Store Adapter could successfully be inserted in db, send it back for display.
if ($success != null && $success == 1) {
echo json_encode($data);
if ($result['status'] == 'success') {
echo json_encode($result);
} else {
echo json_encode(['status' => 'error']);
}
} else {

echo json_encode(['status' => 'error']);
}
}
@@ -254,10 +273,6 @@ if ($action === 'update') {

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

// Get current user.
global $USER;
$thisuser = $USER->id;

// Get annotation itemid and course module id.
$annotationid = required_param('annotation', PARAM_INT);

@@ -272,12 +287,17 @@ if ($action === 'delete') {
}
}

/* * ****************************************** Retrieve all questions of a specific page or document ****************************************** */
/* * ********************************** Retrieve all questions of a specific page or document ********************************** */

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

$pageid = optional_param('page_Number', -1, PARAM_INT); // Default is 1.
if ($pageid == -1) {
$pattern = optional_param('pattern', '', PARAM_TEXT);

if ($pattern !== '') {
$questions = pdfannotator_comment::get_questions_search($documentid, $pattern);
echo json_encode($questions);
} else if ($pageid == -1) {
$questions = pdfannotator_comment::get_all_questions($documentid);
$pdfannotatorname = $DB->get_field('pdfannotator', 'name', array('id' => $documentid), $strictness = MUST_EXIST);
$result = array('questions' => $questions, 'pdfannotatorname' => $pdfannotatorname);
@@ -288,50 +308,36 @@ if ($action === 'getQuestions') {
}
}

/* * ****************************************** 2. HANDLING COMMENTS ****************************************** */
/* * ************************************************************************************************************* */
/* * *************************************** 2. HANDLING COMMENTS ****************************************** */
/* * ******************************************************************************************************* */

/* * ****************************************** Save a new comment and return it for display ****************************************** */
/* * **************************** Save a new comment and return it for display ***************************** */

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

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

require_once($CFG->dirroot . '/mod/pdfannotator/classes/output/comment.php');
// Get the annotation to be commented.
$annotationid = required_param('annotationId', PARAM_TEXT);
$context = context_module::instance($cm->id);
$annotationid = required_param('annotationId', PARAM_INT);
$PAGE->set_context($context);

// Get the comment data.
$content = required_param('content', PARAM_TEXT);
$visibility = required_param('visibility', PARAM_TEXT);
$isquestion = required_param('isquestion', PARAM_TEXT);
$visibility = required_param('visibility', PARAM_ALPHA);
$isquestion = required_param('isquestion', PARAM_INT);

// Insert the comment into the mdl_pdfannotator_comments table and get its record id.
$commentid = pdfannotator_comment::create($documentid, $annotationid, $content, $visibility, $isquestion, $cm, $context);

// Get username or label 'anonymous' // XXX Could perhaps be delegated to a moodle setting.
$username = $USER->username;
if ($visibility === 'anonymous') {
$username = get_string('anonymous', 'pdfannotator');
}
$comment = pdfannotator_comment::create($documentid, $annotationid, $content, $visibility, $isquestion, $cm, $context);
$commentid = $comment->uuid;

// If successful, create a comment array and return it as json.
if (isset($commentid) && $commentid !== false && $commentid > 0) {

global $USER;
$comment = [];
$comment['class'] = 'Comment';
$comment['uuid'] = $commentid;
$comment['annotation'] = $annotationid;
$comment['content'] = $content;
$comment['userid'] = $USER->id;
$comment['username'] = $username;
$timestamp = pdfannotator_comment::get_timestamp($commentid);
$comment['timecreated'] = pdfannotator_get_user_date_time($timestamp);
$comment['visibility'] = $visibility;
$comment['isquestion'] = $isquestion;
$comment['usevotes'] = pdfannotator_instance::use_votes($documentid);

echo json_encode($comment);
if ($comment) {
$myrenderer = $PAGE->get_renderer('mod_pdfannotator');
$templatable = new comment($comment, $cm, $context);
$data = $templatable->export_for_template($myrenderer);

echo json_encode($data);
} else {
if ($commentid == -1) {
echo json_encode(['status' => '-1']);
@@ -341,32 +347,26 @@ if ($action === 'addComment') {
}
}

/* * ****************************************** Retrieve information about a specific annotation from db ****************************************** */
/* * ******************************* Retrieve information about a specific annotation from db ******************************* */

if ($action === 'getInformation') {
if ($action === 'getInformation') { // This concerns only textbox and drawing.

require_once($CFG->dirroot . '/mod/pdfannotator/classes/output/comment.php');
$annotationid = required_param('annotationId', PARAM_INT);

// Get the annotation information only if it is a drawing or textbox.
$annotationobject = new pdfannotator_annotation($annotationid);

if ($annotationobject->get_annotationtype() === "drawing" || $annotationobject->get_annotationtype() === "textbox") {
$returnanno = [];
$returnanno['type'] = $annotationobject->get_annotationtype();
$returnanno['class'] = "Annotation";
$returnanno['page'] = $annotationobject->get_page_of_annotation();
$returnanno['uuid'] = $annotationid;
$returnanno['user'] = pdfannotator_get_username($annotationobject->userid);
$returnanno['userid'] = $annotationobject->userid;
$returnanno['timecreated'] = userdate($annotationobject->timecreated, $format = '', $timezone = 99, $fixday = true, $fixhour = true);
;
echo json_encode($returnanno);
$comment = pdfannotator_annotation::get_information($annotationid);
if ($comment) {
$myrenderer = $PAGE->get_renderer('mod_pdfannotator');
$templatable = new comment($comment, $cm, $context);
$data = $templatable->export_for_template($myrenderer);

echo json_encode($data);
} else {
echo json_encode(['status' => 'error']);
}
}

/* * ****************************************** Retrieve all comments for a specific annotation from db ****************************************** */
/* * ********************************* Retrieve all comments for a specific annotation from db ********************************* */

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

@@ -374,7 +374,14 @@ if ($action === 'getComments') {

// Create an array of all comment objects on the specified page and annotation.
$comments = pdfannotator_comment::read($documentid, $annotationid);
echo json_encode($comments);

require_once($CFG->dirroot . '/mod/pdfannotator/classes/output/comment.php');
$myrenderer = $PAGE->get_renderer('mod_pdfannotator');
$templatable = new comment($comments, $cm, $context);

$data = $templatable->export_for_template($myrenderer);

echo json_encode($data);
}

/* * ****************************************** Delete a comment ****************************************** */
@@ -383,15 +390,31 @@ if ($action === 'deleteComment') {

$commentid = required_param('commentId', PARAM_INT);

$context = context_module::instance($cm->id);
$data = pdfannotator_comment::delete_comment($commentid, $cm->id);
echo json_encode($data);
}

/* * ****************************************** Edit a comment ****************************************** */

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

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

$editanypost = has_capability('mod/pdfannotator:editanypost', $context);

$commentid = required_param('commentId', PARAM_INT);
$content = required_param('content', PARAM_TEXT);

pdfannotator_comment::delete_comment($commentid, $context);
$data = pdfannotator_comment::update($commentid, $content, $editanypost);
echo json_encode($data);
}

/* * ****************************************** Vote for a comment ****************************************** */

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

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

global $DB;

$commentid = required_param('commentid', PARAM_INT);
@@ -408,6 +431,9 @@ if ($action === 'voteComment') {
/* * ****************************************** Subscribe to a question ****************************************** */

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

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

global $DB;
$annotationid = required_param('annotationid', PARAM_INT);

@@ -423,96 +449,87 @@ if ($action === 'subscribeQuestion') {
/* * ****************************************** Unsubscribe from a question ****************************************** */

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

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

global $DB;
$annotationid = required_param('annotationid', PARAM_INT);

$annotatorid = $DB->get_field('pdfannotator_annotations', 'pdfannotatorid', ['id' => $annotationid], $strictness = MUST_EXIST);

$subscriptionid = pdfannotator_comment::delete_subscription($annotationid);

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

if ($action === 'markSolved') {
global $DB;
$commentid = required_param('commentid', PARAM_INT);
$success = pdfannotator_comment::mark_solved($commentid, $context);

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

/* * ****************************************** 3. HANDLING REPORTS (teacheroverview) ****************************************** */
/* * ************************************************************************************************************* */

/* * ************************************** 3.1 Mark a report as seen and don't display it any longer ******************************** */
/* * ********************************* 3.1 Mark a report as seen and don't display it any longer *************************** */

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

require_once($CFG->dirroot.'/mod/pdfannotator/classes/output/overview.php');
require_once($CFG->dirroot.'/mod/pdfannotator/model/pdfannotator.php');
require_capability('mod/pdfannotator:viewreports', $context);
require_once($CFG->dirroot . '/mod/pdfannotator/model/pdfannotator.php');

global $DB;
$reportid = required_param('reportid', PARAM_INT);
$openannotator = required_param('openannotator', PARAM_INT);

if ($DB->update_record('pdfannotator_reports', array("id" => $reportid, "seen" => 1), $bulk = false)) {

$myrenderer = $PAGE->get_renderer('mod_pdfannotator');
$templatable = new overviewUpdateHiddenReports($pdfannotator->course, $openannotator);
$newdata = $templatable->export_for_template($myrenderer);

echo json_encode(['status' => 'success', 'reportid' => $reportid, 'pdfannotatorid' => $documentid, 'newdata' => $newdata]);
echo json_encode(['status' => 'success', 'reportid' => $reportid]);
} else {
echo json_encode(['status' => 'error']);
}
}


/* * ************************************** 3.2 Mark a hidden report as unseen and display it once more ****************************** */
/* * ********************************* 3.2 Mark a hidden report as unseen and display it once more ************************* */

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

require_once($CFG->dirroot.'/mod/pdfannotator/classes/output/overview.php');
require_once($CFG->dirroot.'/mod/pdfannotator/model/pdfannotator.php');
require_capability('mod/pdfannotator:viewreports', $context);
require_once($CFG->dirroot . '/mod/pdfannotator/model/pdfannotator.php');

global $DB;
$reportid = required_param('reportid', PARAM_INT);
$openannotator = required_param('openannotator', PARAM_INT);

if ($DB->update_record('pdfannotator_reports', array("id" => $reportid, "seen" => 0), $bulk = false)) {

$myrenderer = $PAGE->get_renderer('mod_pdfannotator');
$templatable = new overviewUpdateReports($pdfannotator->course, $openannotator);
$newdata = $templatable->export_for_template($myrenderer);

echo json_encode(['status' => 'success', 'reportid' => $reportid, 'pdfannotatorid' => $documentid, 'newdata' => $newdata]);
} else {
echo json_encode(['status' => 'error']);
}
}


/* * ************************************** 3.3 Delete a displayed or hidden report permanently ****************************** */

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

global $DB;

$reportid = required_param('reportid', PARAM_INT);

if ($DB->delete_records('pdfannotator_reports', array("id" => $reportid))) {
echo json_encode(['status' => 'success', 'reportid' => $reportid, 'pdfannotatorid' => $documentid]);
echo json_encode(['status' => 'success', 'reportid' => $reportid]);
} else {
echo json_encode(['status' => 'error']);
}
}

/******************************************** 3. HANDLING ANSWERS TO ONE'S QUESTIONS (studentoverview) *******************************************/
/****************************************************************************************************************/
/* * ********************************* 4. HANDLING ANSWERS TO ONE'S QUESTIONS (studentoverview) ********************************* */
/* * ************************************************************************************************************* */

/* * ****************************************** Mark a question as seen and don't display it any longer ****************************************** */
/* * ********************************** Mark a question as seen and don't display it any longer ********************************* */

// Students can mark answers to their own questions as seen on their personal overview page.

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

require_once($CFG->dirroot.'/mod/pdfannotator/classes/output/overview.php');
require_once($CFG->dirroot.'/mod/pdfannotator/model/pdfannotator.php');
require_capability('mod/pdfannotator:viewanswers', $context);

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

global $DB;

@@ -531,11 +548,12 @@ if ($action === 'markAnswerAsSeen') {
}
}


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

require_once($CFG->dirroot.'/mod/pdfannotator/classes/output/overview.php');
require_once($CFG->dirroot.'/mod/pdfannotator/model/pdfannotator.php');
require_capability('mod/pdfannotator:viewanswers', $context);

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

global $DB;

@@ -545,13 +563,68 @@ if ($action === 'markAnswerAsUnseen') {
$success = $DB->update_record('pdfannotator_comments', array("id" => $answerid, "seen" => 0), $bulk = false);

if ($success == 1) {
echo json_encode(['status' => 'success', 'answerid' => $answerid]);
} else {
echo json_encode(['status' => 'error']);
}
}

$myrenderer = $PAGE->get_renderer('mod_pdfannotator');
$templatable = new overviewUpdateAnswers($pdfannotator->course, $openannotator);
$newdata = $templatable->export_for_template($myrenderer);
/******************************************** 6. HANDLE PRINT REQUEST FOR ANNOTATIONS *******************************************/
/****************************************************************************************************************/

echo json_encode(['status' => 'success', 'answerid' => $answerid, 'pdfannotatorid' => $documentid, 'newdata' => $newdata]);
} else {
if ($action === 'getCommentsToPrint') {

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

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

global $DB;

// The model retrieves and selects data.
$conversations = pdfannotator_instance::get_conversations($documentid);

if ($conversations === -1) { // Sth. went wrong with the database query.
echo json_encode(['status' => 'error']);
return;

} else if (empty($conversations)) { // There are no comments that could be printed.
echo json_encode(['status' => 'empty']);
return;

} else { // Everything is fine.
$documentname = pdfannotator_get_instance_name($documentid);

$posts = [];
$count = 0;
foreach ($conversations as $conversation) {
$post = new stdClass();
$post->answeredquestion = pdfannotator_handle_latex($conversation->answeredquestion);
$post->page = $conversation->page;
$post->annotationtypeid = $conversation->annotationtypeid;
$post->author = $conversation->author;
$post->timemodified = $conversation->timemodified;
$post->answers = [];

$answercount = 0;
foreach ($conversation->answers as $ca) {
$answer = new stdClass();
$answer->answer = pdfannotator_handle_latex($ca->answer);
$answer->author = $ca->author;
$answer->timemodified = $ca->timemodified;
$post->answers[$answercount] = $answer;
$answercount++;
}

$posts[$count] = $post;
$count++;
}

$myrenderer = $PAGE->get_renderer('mod_pdfannotator');
$templatable = new printview($documentname, $posts);
$newdata = $templatable->export_for_template($myrenderer);// Viewcontroller takes model's data and arranges it for display.

echo json_encode(['status' => 'success', 'pdfannotatorid' => $documentid, 'newdata' => $newdata]);

}

}

+ 16
- 2
backup/moodle2/backup_pdfannotator_activity_task.class.php View File

@@ -1,4 +1,18 @@
<?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/>.
/**
* Defines backup_pdfannotator_activity_task class
*
@@ -64,7 +78,7 @@ class backup_pdfannotator_activity_task extends backup_activity_task {

global $CFG, $DB;

$base = preg_quote($CFG->wwwroot,"/");
$base = preg_quote($CFG->wwwroot, "/");

// Link to the list of pdfannotators.
$search = "/(".$base."\/mod\/pdfannotator\/index.php\?id\=)([0-9]+)/";
@@ -72,7 +86,7 @@ class backup_pdfannotator_activity_task extends backup_activity_task {

// Link to pdfannotator view by moduleid.
$search = "/(".$base."\/mod\/pdfannotator\/view.php\?id\=)([0-9]+)/";
// Link to pdfannotator view by recordid
// Link to pdfannotator view by recordid.
$search2 = "/(".$base."\/mod\/pdfannotator\/view.php\?r\=)([0-9]+)/";

return $content;


+ 45
- 27
backup/moodle2/backup_pdfannotator_stepslib.php View File

@@ -1,4 +1,19 @@
<?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/>.

/**
* Define all the backup steps that will be used by the backup_pdfannotator_activity_task
*
@@ -33,24 +48,26 @@ class backup_pdfannotator_activity_structure_step extends backup_activity_struct
*/
protected function define_structure() {

// 1. To know if we are including userinfo
$userinfo = $this->get_setting_value('userinfo'); // is 0
// 1. To know if we are including userinfo.
$userinfo = $this->get_setting_value('userinfo'); // This variable is always 0.

// 2. Define each element separately
// 2. Define each element separately.
$pdfannotator = new backup_nested_element('pdfannotator', array('id'), array(
'name', 'intro', 'introformat', 'usevotes', 'use_studenttextbox', 'use_studentdrawing', 'newsspan', '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'));
$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'));

$comments_archiv = new backup_nested_element('comments_archiv');
$comment_archiv = new backup_nested_element('comment_archiv', array('id'), array('pdfannotatorid', 'userid', 'content', 'timecreated', 'timemodified', 'visibility', 'isquestion', 'isdeleted', 'seen'));
$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');
$comment = new backup_nested_element('comment', array('id'), array('pdfannotatorid', 'userid', 'content', 'timecreated', 'timemodified', 'visibility', 'isquestion', 'isdeleted', 'seen'));
$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'));
@@ -65,8 +82,8 @@ class backup_pdfannotator_activity_structure_step extends backup_activity_struct
$annotation->add_child($subscriptions);
$subscriptions->add_child($subscription);

$annotation->add_child($comments_archiv);
$comments_archiv->add_child($comment_archiv);
$annotation->add_child($commentsarchive);
$commentsarchive->add_child($commentarchive);

$annotation->add_child($comments);
$comments->add_child($comment);
@@ -78,46 +95,47 @@ class backup_pdfannotator_activity_structure_step extends backup_activity_struct
$reports->add_child($report);

// 4. Define db sources
$pdfannotator->set_source_table('pdfannotator', array('id' => backup::VAR_ACTIVITYID)); // backup::VAR_ACTIVITYID is the 'course module id'.
// backup::VAR_ACTIVITYID is the 'course module id'.
$pdfannotator->set_source_table('pdfannotator', array('id' => backup::VAR_ACTIVITYID));

// if ($userinfo) {
// ... if ($userinfo) {?

// add all annotations specific to this annotator instance
// 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
// Add any subscriptions to this annotation.
$subscription->set_source_table('pdfannotator_subscriptions', array('annotationid' => backup::VAR_PARENTID));

// add any archived comments on the annotation
$comment_archiv->set_source_table('pdfannotator_comments_archiv', 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
// Add any comments of this annotation.
$comment->set_source_table('pdfannotator_comments', array('annotationid' => backup::VAR_PARENTID));

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

// add any reports of this comment
// 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)
// 5. Define id annotations (some attributes are foreign keys).
$annotation->annotate_ids('user', 'userid');
$subscription->annotate_ids('user', 'userid');
$comment_archiv->annotate_ids('user', 'userid');
$comment_archiv->annotate_ids('pdfannotator', 'pdfannotatorid');
$commentarchive->annotate_ids('user', 'userid');
$commentarchive->annotate_ids('pdfannotator', 'pdfannotatorid');
$comment->annotate_ids('user', 'userid');
$comment->annotate_ids('pdfannotator', 'pdfannotatorid');
$vote->annotate_ids('user', 'userid');
$report->annotate_ids('user', 'userid');
$report->annotate_ids('pdfannotator', 'pdfannotatorid');

// 6. Define file annotations (comparable with resource activity)
$pdfannotator->annotate_files('mod_pdfannotator', 'intro', null); // This file area does not have an itemid
$pdfannotator->annotate_files('mod_pdfannotator', 'content', null); // see above
// 6. Define file annotations (vgl. resource activity).
$pdfannotator->annotate_files('mod_pdfannotator', 'intro', null); // This file area does not have an itemid.
$pdfannotator->annotate_files('mod_pdfannotator', 'content', null); // See above.

// 7. Return the root element (pdfannotator), wrapped into standard activity structure
// 7. Return the root element (pdfannotator), wrapped into standard activity structure.
return $this->prepare_activity_structure($pdfannotator);
}
}

+ 22
- 6
backup/moodle2/restore_pdfannotator_activity_task.class.php View File

@@ -1,9 +1,25 @@
<?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/>.

/**
* Moodle restores data from course backups by executing so called restore plan.
* The restore plan consists of a set of restore tasks and finally each restore task consists of one or more restore steps.
* You as the developer of a plugin will have to implement one restore task that deals with your plugin data. Most plugins
* have their restore tasks consisting of a single restore step - the one that parses the plugin XML file and puts the data into its tables.
* You as the developer of a plugin will have to implement one restore task that deals with your plugin data.
* Most plugins have their restore tasks consisting of a single restore step
* - the one that parses the plugin XML file and puts the data into its tables.
*
* @package mod_pdfannotator
* @category backup
@@ -13,7 +29,7 @@

defined('MOODLE_INTERNAL') || die();

require_once($CFG->dirroot . '/mod/pdfannotator/backup/moodle2/restore_pdfannotator_stepslib.php'); // Because it exists (must)
require_once($CFG->dirroot . '/mod/pdfannotator/backup/moodle2/restore_pdfannotator_stepslib.php'); // Because it exists (must).

/**
* pdfannotator restore task that provides all the settings and steps to perform one
@@ -25,20 +41,20 @@ class restore_pdfannotator_activity_task extends restore_activity_task {
* Define (add) particular settings this activity can have
*/
protected function define_my_settings() {
// No particular settings for this activity
// No particular settings for this activity.
}

/**
* Define (add) particular steps this activity can have
*/
protected function define_my_steps() {
// Pdfannotator only has one structure step
// Pdfannotator only has one structure step.
$this->add_step(new restore_pdfannotator_activity_structure_step('pdfannotator_structure', 'pdfannotator.xml'));
}

/**
* Define the contents in the activity that must be
* processed by the link decoder
* processed by the link decoder.
*/
static public function define_decode_contents() {
$contents = array();


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

@@ -1,9 +1,25 @@
<?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/>.

/**
* Moodle restores data from course backups by executing so called restore plan.
* The restore plan consists of a set of restore tasks and finally each restore task consists of one or more restore steps.
* You as the developer of a plugin will have to implement one restore task that deals with your plugin data. Most plugins
* have their restore tasks consisting of a single restore step - the one that parses the plugin XML file and puts the data into its tables.
* You as the developer of a plugin will have to implement one restore task that deals with your plugin data.
* Most plugins have their restore tasks consisting of a single restore step
* - the one that parses the plugin XML file and puts the data into its tables.
*
* @package mod_pdfannotator
* @category backup
@@ -11,6 +27,8 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

defined('MOODLE_INTERNAL') || die();

/**
* Define all the restore steps that will be used by the restore_pdfannotator_activity_task
*/
@@ -24,20 +42,20 @@ class restore_pdfannotator_activity_structure_step extends restore_activity_stru

$paths = array();

$userinfo = $this->get_setting_value('userinfo'); // is 0
$userinfo = $this->get_setting_value('userinfo'); // Is 0 //TODO is not used.

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

$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_comment_archiv', '/activity/pdfannotator/annotations/annotation/comments_archiv/comment_archiv');
$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 the paths wrapped into standard activity structure.
return $this->prepare_activity_structure($paths);
}

@@ -51,9 +69,9 @@ class restore_pdfannotator_activity_structure_step extends restore_activity_stru
$data->timecreated = $this->apply_date_offset($data->timecreated);
$data->timemodified = $this->apply_date_offset($data->timemodified);

$newitemid = $DB->insert_record('pdfannotator', $data); // insert the pdfannotator record
$newitemid = $DB->insert_record('pdfannotator', $data); // Insert the pdfannotator record.

$this->apply_activity_instance($newitemid); // immediately after inserting "activity" record, call this
$this->apply_activity_instance($newitemid); // Immediately after inserting "activity" record, call this.
}

protected function process_pdfannotator_annotation($data) {
@@ -89,7 +107,7 @@ class restore_pdfannotator_activity_structure_step extends restore_activity_stru

}

protected function process_pdfannotator_comment_archiv($data) {
protected function process_pdfannotator_commentarchive($data) {
global $DB;

$data = (object)$data;
@@ -103,8 +121,8 @@ class restore_pdfannotator_activity_structure_step extends restore_activity_stru

$data->pdfannotatorid = $this->get_mappingid('pdfannotator', $data->pdfannotatorid);

$newitemid = $DB->insert_record('pdfannotator_comments_archiv', $data);
$this->set_mapping('pdfannotator_comment_archiv', $oldid, $newitemid);
$newitemid = $DB->insert_record('pdfannotator_commentsarchive', $data);
$this->set_mapping('pdfannotator_commentarchive', $oldid, $newitemid);
}


@@ -151,15 +169,14 @@ 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
$data->pdfannotatorid = $this->get_mappingid('pdfannotator', $data->pdfannotatorid); // Params: 1. Object class as defined in structure, 2. attribute&/column name.

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


protected function after_execute() {
// Add pdfannotator related files, no need to match by itemname (just internally handled context)
// Add pdfannotator related files, no need to match by itemname (just internally handled context).
$this->add_related_files('mod_pdfannotator', 'intro', null);
$this->add_related_files('mod_pdfannotator', 'content', null);
}


+ 14
- 1
classes/event/course_module_instance_list_viewed.php View File

@@ -1,5 +1,18 @@
<?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/>.

namespace mod_pdfannotator\event;



+ 14
- 0
classes/event/course_module_viewed.php View File

@@ -1,4 +1,18 @@
<?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/>.

namespace mod_pdfannotator\event;



+ 2
- 2
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'; // ... c(reate), r(ead), u(pdate), d(elete).
$this->data['edulevel'] = self::LEVEL_PARTICIPATING;
$this->data['objecttable'] = 'pdfannotator_reports';
}
@@ -52,6 +52,6 @@ class report_added extends \core\event\base {
}

public function get_url() {
return new \moodle_url('/mod/pdfannotator/view.php', array('id' => $this->other['cmid'],'action' => 'overview'));
return new \moodle_url('/mod/pdfannotator/view.php', array('id' => $this->other['cmid'], 'action' => 'overview'));
}
}

+ 179
- 0
classes/output/comment.php View File

@@ -0,0 +1,179 @@
<?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 statistic template and
* make it available to the renderer. The data is collected via the statistic model and then processed.
* Therefore, class statistic can be seen as a view controller.
*
* @package mod_pdfannotator
* @copyright 2018 RWTH Aachen, Friederike Schwager (see README.md)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();

class comment implements \renderable, \templatable {

private $comments = [];

public function __construct($data, $cm, $context) {
global $USER;

if (!is_array($data)) {
$data = [$data];
}
$editanypost = has_capability('mod/pdfannotator:editanypost', $context);
foreach ($data as $comment) {

$comment->buttons = [];

$comment->isdeleted = boolval($comment->isdeleted);
$comment->isquestion = boolval($comment->isquestion);
$comment->solved = boolval($comment->solved);

$owner = ($comment->userid == $USER->id);

$comment->wrapperClass = 'chat-message comment-list-item';
if ($comment->isquestion) {
$comment->wrapperClass .= ' questioncomment';
} else if ($comment->solved) {
$comment->wrapperClass .= ' correct';
}
if ($owner) {
$comment->wrapperClass .= ' owner';
}
if ($comment->usevotes) {
$comment->wrapperClass .= ' usevotes';
if (!$comment->isdeleted) {
if ($owner) {
$comment->voteBtn = get_string('likeOwnComment', 'pdfannotator');
} else if ($comment->isvoted) {
if ($comment->isquestion) {
$comment->voteBtn = get_string('likeQuestionForbidden', 'pdfannotator');
} else {
$comment->voteBtn = get_string('likeAnswerForbidden', 'pdfannotator');
}
} else {
if ($comment->isquestion) {
$comment->voteBtn = get_string('likeQuestion', 'pdfannotator');
} else {
$comment->voteBtn = get_string('likeAnswer', 'pdfannotator');
}
}
}

if (!$comment->votes) {
$comment->votes = "0";
}
if ($comment->isquestion) {
$comment->voteTitle = $comment->votes . " " . get_string('likeCountQuestion', 'pdfannotator');
} else {
$comment->voteTitle = $comment->votes . " " . get_string('likeCountAnswer', 'pdfannotator');
}
}

if ($comment->isdeleted || isset($comment->type)) {
$comment->content = '<em>' . $comment->content . '</em>';
}

if (!$comment->isdeleted) {
$deleteany = has_capability('mod/pdfannotator:deleteany', $context);
$deleteown = has_capability('mod/pdfannotator:deleteown', $context);
$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')]];
}
// Report (textbox/drawing can't be reported because of a missing commentid).
if ($report && !$owner && !isset($comment->type) ) {
$comment->report = true;
$comment->cm = json_encode($cm); // Course module object.
$comment->cmid = $cm->id;
}
if (!isset($comment->type) && ($owner || $editanypost)) {
$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')];
}
}

if (!empty($comment->modifiedby) && ($comment->modifiedby != $comment->userid)) {
$comment->modifiedby = get_string('modifiedby', 'pdfannotator') . pdfannotator_get_username($comment->modifiedby);
} else {
$comment->modifiedby = null;
}

if ($comment->isquestion || !$comment->isdeleted) {
$comment->dropdown = true;
}

if (!isset($comment->type) && $comment->isquestion) { // Only set for textbox and drawing.
if (!empty($comment->issubscribed)) {
$comment->buttons[] = ["classes" => "comment-subscribe-a", "faicon" => ["class" => "fa-bell-slash"],
"text" => get_string('unsubscribeQuestion', 'pdfannotator')];
} else {
$comment->buttons[] = ["classes" => "comment-subscribe-a", "faicon" => ["class" => "fa-bell"],
"text" => get_string('subscribeQuestion', 'pdfannotator')];
}
// Open/Close.
$closequestion = has_capability('mod/pdfannotator:closequestion', $context);
$closeanyquestion = has_capability('mod/pdfannotator:closeanyquestion', $context);
if (($owner && $closequestion) || $closeanyquestion) {
if ($comment->solved) {
$comment->buttons[] = ["classes" => "comment-solve-a", "faicon" => ["class" => "fa-unlock"],
"text" => get_string('markUnsolved', 'pdfannotator')];
} else {
$comment->buttons[] = ["classes" => "comment-solve-a", "faicon" => ["class" => "fa-lock"],
"text" => get_string('markSolved', 'pdfannotator')];
}
}
}

$solve = has_capability('mod/pdfannotator:markcorrectanswer', $context);
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')]];
} 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')]];
}
}
if ($comment->solved) {
if ($comment->isquestion) {
$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')];
}
}
$this->comments[] = $comment;
}
return;
}

/**
* This function is required by any renderer to retrieve the data structure
* passed into the template.
* @param \renderer_base $output
* @return type
*/
public function export_for_template(\renderer_base $output) {
$data = [];
$data['comments'] = $this->comments;
return $data;
}

}

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

@@ -1,45 +1,106 @@
<?php

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

/**
* Description of index
*
* @author degroot
*/
class index implements renderable, templatable { // should be placed elsewhere

private $use_studenttextbox;
private $use_studentdrawing;

public function __construct($pdfannotator, $isAllowedForUser) {
// if the textbox should be allowed for students, the array should have a single value.
$this->use_studenttextbox = array();
if($pdfannotator->use_studenttextbox || $isAllowedForUser){
$this->use_studenttextbox = array('use');
}

// if the drawing should be allowed for students, the array should have a single value.
$this->use_studentdrawing = array();
if($pdfannotator->use_studentdrawing || $isAllowedForUser){
$this->use_studentdrawing = array('use');
}
}

public function export_for_template(renderer_base $output) {
global $OUTPUT,$PAGE;
$url = $PAGE->url;
$data = new stdClass();
$data->use_studenttextbox = $this->use_studenttextbox;
$data->use_studentdrawing = $this->use_studentdrawing;
$data->pixhide = $OUTPUT->image_url('/e/accessibility_checker');
$data->pixopenbook = $OUTPUT->image_url('openbook', 'mod_pdfannotator');
$data->pixsinglefile = $OUTPUT->image_url('/e/new_document');

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;
}
}

+ 0
- 447
classes/output/overview.php View File

@@ -1,447 +0,0 @@
<?php
/**
* The purpose of this script is to collect the output data for the teacheroverview 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
*
*/
defined('MOODLE_INTERNAL') || die();

class overview implements \renderable, \templatable {

private $courseid;
private $openannotator;
private $newsspan;
private $viewreports;
private $viewanswers;
private $viewquestions;
private $viewposts;
private $annotators_with_reports = [];
private $annotators_with_answers = [];
private $annotators_with_questions = [];
private $annotators_with_posts_by_this_user = [];
private $annotators_with_hiddenentries = [];
private $annotators_with_hidden_reports = [];
private $count0 = 0;
private $count1 = 0;
private $count2 = 0;
private $count3 = 0;
private $count4 = 0;
private $count5 = 0;

/**
*
* @global type $USER
* @param int $courseid
* @param int $thisannotator id of the currently opened annotator
* @param int $newsspan number of days that a new comment is to be displayed as new on the overview page
* @param user capability $viewreports
* @param user capability $viewanswers
* @param user capability $viewquestions
* @param user capability $viewposts
*/
public function __construct($thisannotator, $courseid, $newsspan = 3, $viewreports = false, $viewanswers = false, $viewquestions = false, $viewposts = false) {

$this->openannotator = $thisannotator;
$this->courseid = $courseid;
// $this->newsspan = $newsspan;

$this->viewreports = $viewreports;
$this->viewanswers = $viewanswers;
$this->viewquestions = $viewquestions;
$this->viewposts = $viewposts;

global $USER;

// 0. Access/create the model
$annotator_list = pdfannotator_instance::get_pdfannotator_instances($courseid, $thisannotator);

foreach ($annotator_list as $annotator) {

// 1. Model is told to retrieve certain data from db, depending on the user's capabilities
if ($viewreports) {
$annotator->set_reports($courseid);
$annotator->set_hidden_reports();
}
if ($viewanswers) {
$annotator->set_answers();
$annotator->set_hidden_answers();
}
if ($viewquestions) {
$annotator->set_latest_questions($newsspan);
}
if ($viewposts) {
$annotator->set_posts_by_user($USER->id);
}
// 2. Select and organize the model's data for display, depending on the user's capabilities

if ($viewreports) {
// 2.0.1 Collect all reports of inappropriate comments
$reports = array_reverse($annotator->get_reports()); // most recent entries come first
$this->count0 += count($reports);
if (count($reports) > 0) {
$this->annotators_with_reports[] = array('annotatorid' => $annotator->get_id(), 'annotatorname' => $annotator->get_name(), 'reportcount' => count($reports), 'reports' => $reports);
}
// 2.0.2 Collect all hidden reports in this course // XXX administrate category is to be separated
$hiddenentries = array_reverse($annotator->get_hidden_reports());
$this->count5 += count($hiddenentries);
if (count($hiddenentries) > 0) {
$this->annotators_with_hidden_reports[] = array('annotatorid' => $annotator->get_id(), 'annotatorname' => $annotator->get_name(), 'hiddenreportcount' => count($hiddenentries), 'hiddenreports' => $hiddenentries);
}
}
if ($viewanswers) {
// 2.1.1 Collect new answers to the user's questions
$answers = $annotator->get_answers_for_me();
$this->count1 += count($answers);
if (count($answers) > 0) {
$answers = array_reverse($answers);
$this->annotators_with_answers[] = array('annotatorid' => $annotator->get_id(), 'annotatorname' => $annotator->get_name(), 'answers' => $answers, 'answercount' => count($answers));
}
// 2.1.2 Collect all hidden entries/answers
$hiddenanswers = $annotator->get_hidden_answers();
$this->count4 += count($hiddenanswers);
if (count($hiddenanswers) > 0) {
$hiddenanswers = array_reverse($hiddenanswers);
$this->annotators_with_hiddenentries[] = array('annotatorid' => $annotator->get_id(), 'annotatorname' => $annotator->get_name(), 'hiddenentries' => $hiddenanswers, 'hiddenentrycount' => count($hiddenanswers));
}
}
// 2.2 Collect all new questions
if ($viewquestions) {
$questions = array_reverse($annotator->get_latest_questions()); // most recent entries come first
$this->count2 += count($questions);
if (count($questions) > 0) {
$this->annotators_with_questions[] = array('annotatorid' => $annotator->get_id(), 'annotatorname' => $annotator->get_name(), 'questions' => $questions, 'questioncount' => count($questions));
}
}
// 2.3 Collect all questions/comments posted by this user in this course
if ($viewposts) {
$userposts = $annotator->get_posts_by_user();
$posts = array_reverse($userposts); // most recent entries come first
$this->count3 += count($posts);
if (count($posts) > 0) {
$this->annotators_with_posts_by_this_user[] = array('annotatorid' => $annotator->get_id(), 'annotatorname' => $annotator->get_name(), 'posts' => $posts, 'postcount' => count($posts));
}
}

}
}
/**
*
* @global type $USER
* @param \renderer_base $output
* @return type
*/
public function export_for_template(\renderer_base $output) {

global $USER, $OUTPUT;

$data = [];
$data['openannotator'] = $this->openannotator;

// 0. reports of inappropriate comments in this course
if ($this->viewreports) {
$data['annotators_with_reports'] = $this->annotators_with_reports;
if (empty($this->annotators_with_reports)) {
$data['noreports'] = get_string('noreports', 'pdfannotator');
}
// 5. hidden reports in this course
$data['annotators_with_hidden_reports'] = $this->annotators_with_hidden_reports;
if (empty($this->annotators_with_hidden_reports)) {
$data['nohiddenentries'] = get_string('nohiddenentries_manager', 'pdfannotator');
}
$data['count0'] = $this->count0;
$data['count5'] = $this->count5;
$data['viewreports'] = true;
}
// 1. annotators with answers to questions this user wrote or subscribed to
if ($this->viewanswers) {
$data['annotators_with_answers'] = $this->annotators_with_answers;
if (empty($this->annotators_with_answers)) {
$data['noanswers'] = get_string('noanswers', 'pdfannotator');
}
// 4. hidden reports in this course
$data['annotators_with_hiddenentries'] = $this->annotators_with_hiddenentries;
if (empty($this->annotators_with_hiddenentries)) {
$data['nohiddenentries'] = get_string('nohiddenentries_manager', 'pdfannotator');
}
$data['count1'] = $this->count1;
$data['count4'] = $this->count4;
$data['viewanswers'] = true;
}
// 2. new questions in this course
if ($this->viewquestions) {
$data['annotators_with_questions'] = $this->annotators_with_questions;
if (empty($this->annotators_with_questions)) {
$data['noquestions'] = get_string('noquestions_overview', 'pdfannotator');
}
$data['count2'] = $this->count2;
}
// 3. questions/comments posted by this user in this course
if ($this->viewposts) {
$data['annotators_with_posts_by_this_user'] = $this->annotators_with_posts_by_this_user;
if (empty($this->annotators_with_posts_by_this_user)) {
$data['nomyposts'] = get_string('nomyposts', 'pdfannotator');
}
$data['count3'] = $this->count3;
}

// 5. icons
$data['pixunsubscribe'] = $OUTPUT->image_url("/i/notifications");
$data['pixcollapsed'] = $OUTPUT->image_url("/t/collapsed"); // moodle icon 'moodle/pix/t/collapsed.png';
$data['pixgotox'] = $OUTPUT->image_url('link_klein', 'mod_pdfannotator'); // plugin-specific icon, not part of a theme '/moodle/mod/pdfannotator/pix/link_klein.png'
$data['pixhide'] = $OUTPUT->image_url('/e/accessibility_checker');
$data['pixdisplay'] = $OUTPUT->image_url('/i/hide'); // '/moodle/pix/i/hide.png'
$data['pixdelete'] = $OUTPUT->image_url('/t/delete');

// 6. link to individual settings page
$data['linktosettingspage'] = new moodle_url('/message/notificationpreferences.php', array('userid' => $USER->id));
$data['linktooverview'] = new moodle_url('/course/recent.php', array('id' => $this->courseid));
// "moodle/message/notificationpreferences.php?userid=$USER->id";

// $data['timespan'] = $this->newsspan;

return $data;
}

}


/*****************************************************************************************************************************/

class overviewUpdateReports implements \renderable, \templatable {

private $openannotator;
private $annotators_with_reports = [];

/**
* @param type $courseid
*/
public function __construct($courseid, $thisannotator) {

$this->openannotator = $thisannotator;

// 0. Access/create the model
$annotator_list = pdfannotator_instance::get_pdfannotator_instances($courseid);

foreach ($annotator_list as $annotator) {

// 1. Model is told to retrieve its data from db
$annotator->set_reports($courseid, true);

// 2. Select and organize the model's data for display

// 2.1. Collect all reports of inappropriate comments
$reports = array_reverse($annotator->get_reports()); // most recent entries come first
if (count($reports) > 0) {
$this->annotators_with_reports[] = array('annotatorid' => $annotator->get_id(), 'annotatorname' => $annotator->get_name(), 'reportcount' => count($reports), 'reports' => $reports);
}

}
}
/**
*
* @global type $USER
* @param \renderer_base $output
* @return type
*/
public function export_for_template(\renderer_base $output) {

$data = array('openannotator' => $this->openannotator, 'annotators_with_reports' => $this->annotators_with_reports);
if (empty($this->annotators_with_reports)) {
$data['noreports'] = get_string('noreports', 'pdfannotator');
}
$data['viewreports'] = true;

return $data;
}

}

/*****************************************************************************************************************************/

class overviewUpdateHiddenReports implements \renderable, \templatable {

private $openannotator;
private $annotators_with_hidden_reports = [];

/**
* Constructor (not necessary)
* @param type $pdfannotators
*/
public function __construct($courseid, $thisannotator) {

$this->openannotator = $thisannotator;

// 1. Create the model
$annotator_list = pdfannotator_instance::get_pdfannotator_instances($courseid);

foreach ($annotator_list as $annotator) {

// 2. Model is told to retrieve its data from db
$annotator->set_hidden_reports(true);

// 3. Collect all hidden reports in this course
$hiddenentries = array_reverse($annotator->get_hidden_reports());
if (count($hiddenentries) > 0) {
$this->annotators_with_hidden_reports[] = array('annotatorid' => $annotator->get_id(), 'annotatorname' => $annotator->get_name(), 'hiddenreportcount' => count($hiddenentries), 'hiddenreports' => $hiddenentries);
}
}

}
/**
*
* @global type $USER
* @param \renderer_base $output
* @return type
*/
public function export_for_template(\renderer_base $output) {

$data = [];
$data['openannotator'] = $this->openannotator;
// hidden reports in this course
$data['annotators_with_hidden_reports'] = $this->annotators_with_hidden_reports;
if (empty($this->annotators_with_hidden_reports)) {
$data['nohiddenentries_manager'] = get_string('nohiddenentries_manager', 'pdfannotator');
}

return $data;
}

}


class overviewUpdateAnswers implements \renderable, \templatable {

private $openannotator;
private $annotators_with_answers = [];

/**
* Konstruktor (not necessary)
* @param type $pdfannotators
*/
public function __construct($courseid, $thisannotator) {

$this->openannotator = $thisannotator;

global $USER;

// 0. Access/create the model
$annotator_list = pdfannotator_instance::get_pdfannotator_instances($courseid, $thisannotator);

foreach($annotator_list as $annotator) {

// 1. Model is told to retrieve its data from db
$annotator->set_answers(true);

// 2.1 Collect new answers to the user's questions
$answers = $annotator->get_answers_for_me();

if (count($answers) > 0) {
$answers = array_reverse($answers);
$this->annotators_with_answers[] = array('annotatorid' => $annotator->get_id(), 'annotatorname' => $annotator->get_name(), 'answers' => $answers, 'answercount' => count($answers));
}

}

}
/**
*
* @global type $USER
* @param \renderer_base $output
* @return type
*/
public function export_for_template(\renderer_base $output) {

global $USER; global $OUTPUT;

$data = [];

$data['openannotator'] = $this->openannotator;

$data['annotators_with_answers'] = $this->annotators_with_answers;
if (empty($this->annotators_with_answers)) {
$data['noanswers'] = get_string('noanswers', 'pdfannotator');
}
$data['viewanswers'] = true;
// icons
$data['pixunsubscribe'] = $OUTPUT->image_url("/i/notifications");
$data['pixcollapsed'] = $OUTPUT->image_url("/t/collapsed"); // moodle icon 'moodle/pix/t/collapsed.png';
$data['pixgotox'] = $OUTPUT->image_url('link_klein', 'mod_pdfannotator'); // plugin-specific icon, not part of a theme '/moodle/mod/pdfannotator/pix/link_klein.png'
$data['pixhide'] = $OUTPUT->image_url('/e/accessibility_checker');
$data['pixdisplay'] = $OUTPUT->image_url('/i/hide'); // '/moodle/pix/i/hide.png'

return $data;
}

}


class overviewUpdateHiddenAnswers implements \renderable, \templatable {

private $openannotator;
private $annotators_with_hiddenentries = [];

/**
* Konstruktor (not necessary)
* @param type $pdfannotators
*/
public function __construct($courseid, $thisannotator) {

$this->openannotator = $thisannotator;

global $USER;

// 0. Access/create the model
$annotator_list = pdfannotator_instance::get_pdfannotator_instances($courseid, $thisannotator);

foreach ($annotator_list as $annotator) {

// 1. Model is told to retrieve its data from db
$annotator->set_hidden_answers(true);

// 2. Select and organize the model's data for display: Collect all hidden entries/answers
$hiddenanswers = $annotator->get_hidden_answers();

if (count($hiddenanswers) > 0) {
$hiddenanswers = array_reverse($hiddenanswers);
$this->annotators_with_hiddenentries[] = array('annotatorid' => $annotator->get_id(), 'annotatorname' => $annotator->get_name(), 'hiddenentries' => $hiddenanswers, 'hiddenentrycount' => count($hiddenanswers));

}

}

}
/**
*
* @global type $USER
* @param \renderer_base $output
* @return type
*/
public function export_for_template(\renderer_base $output) {

global $OUTPUT;

$data = [];

$data['openannotator'] = $this->openannotator;

$data['annotators_with_hiddenentries'] = $this->annotators_with_hiddenentries;
if (empty($this->annotators_with_hiddenentries)) {
$data['noanswers'] = get_string('noanswers', 'pdfannotator');
}

// 5. icons
$data['pixcollapsed'] = $OUTPUT->image_url("/t/collapsed"); // moodle icon 'moodle/pix/t/collapsed.png';
$data['pixgotox'] = $OUTPUT->image_url('link_klein', 'mod_pdfannotator'); // plugin-specific icon, not part of a theme '/moodle/mod/pdfannotator/pix/link_klein.png'
$data['pixhide'] = $OUTPUT->image_url('/e/accessibility_checker');
$data['pixdisplay'] = $OUTPUT->image_url('/i/hide'); // '/moodle/pix/i/hide.png'
$data['pixdelete'] = $OUTPUT->image_url('/t/delete');

return $data;
}

}

+ 51
- 0
classes/output/printview.php View File

@@ -0,0 +1,51 @@
<?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 printview template
* and make it available to the renderer. The data is collected via the pdfannotator model
* and then processed. Therefore, class printview 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
*
*/
defined('MOODLE_INTERNAL') || die();

class printview implements \renderable, \templatable {

private $documentname;
private $conversations;
private $url;


public function __construct($documentname=null, $conversations=null, $url=null) {

$this->documentname = $documentname;
$this->conversations = $conversations;
$this->url = $url;
}

public function export_for_template(\renderer_base $output) {

$data = [];
$data['documentname'] = $this->documentname;
$data['posts'] = $this->conversations;
return $data;
}

}

+ 20
- 12
classes/output/statistics.php View File

@@ -1,4 +1,18 @@
<?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 statistic template and
@@ -21,19 +35,17 @@ class statistics implements \renderable, \templatable {
private $tabledata1;
private $tabledata2;

public function __construct($annotatorid, $courseid, $isteacher) {
public function __construct($annotatorid, $courseid, $capabilities, $id) {
global $USER, $PAGE;
$userid = $USER->id;
$this->isteacher = $isteacher;
$this->isteacher = $capabilities->viewteacherstatistics;

$statistics = new pdfannotator_statistics($courseid, $annotatorid, $userid, $isteacher);
$statistics = new pdfannotator_statistics($courseid, $annotatorid, $userid, $this->isteacher);

$this->tabledata1 = $statistics->get_tabledata_1();
if (!$isteacher) {
$this->tabledata2 = $statistics->get_tabledata_2();
}
$this->tabledata = $statistics->get_tabledata();

$params = $statistics->get_chartdata();
$PAGE->requires->js_init_call('addDropdownNavigation', array($capabilities, $id), true);
$PAGE->requires->js_init_call('setCharts', $params, true);
}

@@ -46,12 +58,8 @@ class statistics implements \renderable, \templatable {
public function export_for_template(\renderer_base $output) {