Moodle plugin, allowing collaborative annotations in PDF files
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

382 lines
18 KiB

<?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();
}
}