diff --git a/.github/workflows/moodle-plugin-ci.yml b/.github/workflows/moodle-plugin-ci.yml
index 9069f71..ac4f851 100644
--- a/.github/workflows/moodle-plugin-ci.yml
+++ b/.github/workflows/moodle-plugin-ci.yml
@@ -8,7 +8,7 @@ jobs:
services:
postgres:
- image: postgres:13
+ image: postgres:14
env:
POSTGRES_USER: 'postgres'
POSTGRES_HOST_AUTH_METHOD: 'trust'
@@ -31,6 +31,25 @@ jobs:
fail-fast: false
matrix:
include:
+ - php: 8.4
+ moodle-branch: MOODLE_500_STABLE
+ database: pgsql
+ - php: 8.4
+ moodle-branch: MOODLE_500_STABLE
+ database: mariadb
+ - php: 8.3
+ moodle-branch: MOODLE_500_STABLE
+ database: pgsql
+ - php: 8.3
+ moodle-branch: MOODLE_500_STABLE
+ database: mariadb
+ - php: 8.2
+ moodle-branch: MOODLE_500_STABLE
+ database: pgsql
+ - php: 8.2
+ moodle-branch: MOODLE_500_STABLE
+ database: mariadb
+
- php: 8.3
moodle-branch: MOODLE_405_STABLE
database: pgsql
@@ -42,13 +61,13 @@ jobs:
database: pgsql
- php: 8.2
moodle-branch: MOODLE_405_STABLE
- database: mariadb
+ database: mariadb
- php: 8.1
moodle-branch: MOODLE_405_STABLE
database: pgsql
- php: 8.1
moodle-branch: MOODLE_405_STABLE
- database: mariadb
+ database: mariadb
- php: 8.3
moodle-branch: MOODLE_404_STABLE
@@ -61,13 +80,13 @@ jobs:
database: pgsql
- php: 8.2
moodle-branch: MOODLE_404_STABLE
- database: mariadb
+ database: mariadb
- php: 8.1
moodle-branch: MOODLE_404_STABLE
database: pgsql
- php: 8.1
moodle-branch: MOODLE_404_STABLE
- database: mariadb
+ database: mariadb
- php: 8.2
moodle-branch: MOODLE_403_STABLE
@@ -170,11 +189,11 @@ jobs:
- name: Moodle Code Checker
if: ${{ !cancelled() }}
- run: moodle-plugin-ci codechecker --max-warnings 0 ./plugin || true
+ run: moodle-plugin-ci codechecker --max-warnings 0 ./plugin
- name: Moodle PHPDoc Checker
if: ${{ !cancelled() }}
- run: moodle-plugin-ci phpdoc --max-warnings 0 ./plugin || true
+ run: moodle-plugin-ci phpdoc --max-warnings 0 ./plugin
- name: Validating
if: ${{ !cancelled() }}
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7f01c28..471d83a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,9 @@
## 2025070803 v1.5.9
-* Improve version file for 4.4+
+* fix images not being displayed in comments
+* remove explicit mathjax calls for rendering
+* download comment as CSV feature
+* mathjax3 and php84 changes
+* Incorrect display of checkbox under editor for Moodle 5
* Annotation separation: Public Private and All comments
## 2025032500 v1.5.8
diff --git a/action.php b/action.php
index 95f6e28..5661986 100644
--- a/action.php
+++ b/action.php
@@ -43,7 +43,7 @@
$documentid = required_param('documentId', PARAM_PATH);
$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);
+$pdfannotator = $DB->get_record('pdfannotator', ['id' => $documentid], '*', MUST_EXIST);
$cm = get_coursemodule_from_instance('pdfannotator', $documentid, $pdfannotator->course, false, MUST_EXIST);
$context = context_module::instance($cm->id);
@@ -62,13 +62,13 @@
$page = optional_param('page_Number', 1, PARAM_INT); // Default page number is 1.
- $annotations = array();
+ $annotations = [];
- $records = $DB->get_records('pdfannotator_annotations', array('pdfannotatorid' => $documentid, 'page' => $page));
+ $records = $DB->get_records('pdfannotator_annotations', ['pdfannotatorid' => $documentid, 'page' => $page]);
foreach ($records as $record) {
- $comment = $DB->get_record('pdfannotator_comments', array('annotationid' => $record->id, 'isquestion' => 1));
+ $comment = $DB->get_record('pdfannotator_comments', ['annotationid' => $record->id, 'isquestion' => 1]);
if ($comment && !pdfannotator_can_see_comment($comment, $context)) {
continue;
}
@@ -89,7 +89,7 @@
$annotations[] = $entry;
}
- $data = array('documentId' => $documentid, 'pageNumber' => $page, 'annotations' => $annotations);
+ $data = ['documentId' => $documentid, 'pageNumber' => $page, 'annotations' => $annotations];
echo json_encode($data);
}
@@ -101,7 +101,7 @@
$annotationid = required_param('annotationId', PARAM_INT);
$page = optional_param('page_Number', 1, PARAM_INT);
- $record = $DB->get_record('pdfannotator_annotations', array('id' => $annotationid), '*', MUST_EXIST);
+ $record = $DB->get_record('pdfannotator_annotations', ['id' => $annotationid], '*', MUST_EXIST);
$annotation = json_decode($record->data);
// Add general annotation data.
@@ -113,7 +113,7 @@
$annotation->class = "Annotation";
$annotation->page = $record->page;
$annotation->uuid = $record->id;
- $data = array('documentId' => $documentid, 'annotation' => $annotation);
+ $data = ['documentId' => $documentid, 'annotation' => $annotation];
echo json_encode($data);
return;
}
@@ -175,7 +175,7 @@
$data['rectangles'] = $annotation['rectangles'];
break;
case 'textbox':
- $studenttextboxesallowed = $DB->get_field('pdfannotator', 'use_studenttextbox', array('id' => $documentid),
+ $studenttextboxesallowed = $DB->get_field('pdfannotator', 'use_studenttextbox', ['id' => $documentid],
$strictness = MUST_EXIST);
$alwaystextboxallowed = has_capability('mod/pdfannotator:usetextbox', $context);
if ($studenttextboxesallowed != 1 && !$alwaystextboxallowed) {
@@ -194,8 +194,8 @@
$insertiondata = json_encode($data);
// 1.4 Insert a new record into mdl_pdfannotator_annotations.
- $newannotationid = $DB->insert_record($table, array("pdfannotatorid" => $documentid, "page" => $pageid, "userid" => $USER->id,
- "annotationtypeid" => $typeid, "data" => $insertiondata, "timecreated" => time()), true, false);
+ $newannotationid = $DB->insert_record($table, ["pdfannotatorid" => $documentid, "page" => $pageid, "userid" => $USER->id,
+ "annotationtypeid" => $typeid, "data" => $insertiondata, "timecreated" => time()], true, false);
// 2. If the insertion was successful...
if (isset($newannotationid) && $newannotationid !== false && $newannotationid > 0) {
// 2.1 set additional data to send back to the client.
@@ -313,8 +313,8 @@
echo json_encode($questions);
} else if ($pageid == -1) {
$questions = pdfannotator_comment::get_all_questions($documentid, $context);
- $pdfannotatorname = $DB->get_field('pdfannotator', 'name', array('id' => $documentid), $strictness = MUST_EXIST);
- $result = array('questions' => $questions, 'pdfannotatorname' => $pdfannotatorname);
+ $pdfannotatorname = $DB->get_field('pdfannotator', 'name', ['id' => $documentid], $strictness = MUST_EXIST);
+ $result = ['questions' => $questions, 'pdfannotatorname' => $pdfannotatorname];
echo json_encode($result);
} else {
$questions = pdfannotator_comment::get_questions($documentid, $pageid, $context);
@@ -482,8 +482,8 @@
$thiscourse = $pdfannotator->course;
$cmid = get_coursemodule_from_instance('pdfannotator', $thisannotator, $thiscourse, false, MUST_EXIST)->id;
- $urlparams = array('action' => 'overviewanswers', 'id' => $cmid, 'page' => 0, 'itemsperpage' => $itemsperpage,
- 'answerfilter' => 0);
+ $urlparams = ['action' => 'overviewanswers', 'id' => $cmid, 'page' => 0, 'itemsperpage' => $itemsperpage,
+ 'answerfilter' => 0];
$url = new moodle_url($CFG->wwwroot . '/mod/pdfannotator/view.php', $urlparams);
redirect($url->out());
return;
@@ -516,7 +516,7 @@
$thiscourse = $pdfannotator->course;
$cmid = get_coursemodule_from_instance('pdfannotator', $thisannotator, $thiscourse, false, MUST_EXIST)->id;
- $urlparams = array('action' => 'overviewanswers', 'id' => $cmid, 'page' => 0, 'itemsperpage' => $itemsperpage);
+ $urlparams = ['action' => 'overviewanswers', 'id' => $cmid, 'page' => 0, 'itemsperpage' => $itemsperpage];
$url = new moodle_url($CFG->wwwroot . '/mod/pdfannotator/view.php', $urlparams);
redirect($url->out());
return;
@@ -558,7 +558,7 @@
$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)) {
+ if ($DB->update_record('pdfannotator_reports', ["id" => $reportid, "seen" => 1], $bulk = false)) {
echo json_encode(['status' => 'success', 'reportid' => $reportid]);
} else {
echo json_encode(['status' => 'error']);
@@ -576,7 +576,7 @@
$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)) {
+ if ($DB->update_record('pdfannotator_reports', ["id" => $reportid, "seen" => 0], $bulk = false)) {
echo json_encode(['status' => 'success', 'reportid' => $reportid]);
} else {
echo json_encode(['status' => 'error']);
diff --git a/backup/moodle2/backup_pdfannotator_stepslib.php b/backup/moodle2/backup_pdfannotator_stepslib.php
index bd0cdec..c7d419e 100644
--- a/backup/moodle2/backup_pdfannotator_stepslib.php
+++ b/backup/moodle2/backup_pdfannotator_stepslib.php
@@ -29,7 +29,6 @@
* @author Anna Heynkes
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-defined('MOODLE_INTERNAL') || die;
/**
* Define the complete pdfannotator structure for backup, with file and id annotations
@@ -53,28 +52,28 @@ protected function define_structure() {
$userinfo = $this->get_setting_value('userinfo');
// 2. Define each element separately.
- $pdfannotator = new backup_nested_element('pdfannotator', array('id'), array(
+ $pdfannotator = new backup_nested_element('pdfannotator', ['id'], [
'name', 'intro', 'introformat', 'usevotes', 'useprint', 'useprintcomments', 'use_studenttextbox', 'use_studentdrawing',
- 'useprivatecomments', 'useprotectedcomments', 'timecreated', 'timemodified'));
+ 'useprivatecomments', 'useprotectedcomments', 'timecreated', 'timemodified']);
$annotations = new backup_nested_element('annotations');
- $annotation = new backup_nested_element('annotation', array('id'), array('page', 'userid', 'annotationtypeid',
- 'data', 'timecreated', 'timemodified', 'modifiedby'));
+ $annotation = new backup_nested_element('annotation', ['id'], ['page', 'userid', 'annotationtypeid',
+ 'data', 'timecreated', 'timemodified', 'modifiedby']);
$subscriptions = new backup_nested_element('subscriptions');
- $subscription = new backup_nested_element('subscription', array('id'), array('userid'));
+ $subscription = new backup_nested_element('subscription', ['id'], ['userid']);
$comments = new backup_nested_element('comments');
- $c = array('pdfannotatorid', 'userid', 'content', 'timecreated', 'timemodified', 'modifiedby', 'visibility',
- 'isquestion', 'isdeleted', 'ishidden', 'solved');
- $comment = new backup_nested_element('comment', array('id'), $c);
+ $c = ['pdfannotatorid', 'userid', 'content', 'timecreated', 'timemodified', 'modifiedby', 'visibility',
+ 'isquestion', 'isdeleted', 'ishidden', 'solved'];
+ $comment = new backup_nested_element('comment', ['id'], $c);
$votes = new backup_nested_element('votes');
- $vote = new backup_nested_element('vote', array('id'), array('userid', 'annotationid'));
+ $vote = new backup_nested_element('vote', ['id'], ['userid', 'annotationid']);
$reports = new backup_nested_element('reports');
- $report = new backup_nested_element('report', array('id'), array('courseid', 'pdfannotatorid', 'message',
- 'userid', 'timecreated', 'seen'));
+ $report = new backup_nested_element('report', ['id'], ['courseid', 'pdfannotatorid', 'message',
+ 'userid', 'timecreated', 'seen']);
// 3. Build the tree (mind the right order!)
$pdfannotator->add_child($annotations);
@@ -94,7 +93,7 @@ protected function define_structure() {
// 4. Define db sources
// backup::VAR_ACTIVITYID is the 'course module id'.
- $pdfannotator->set_source_table('pdfannotator', array('id' => backup::VAR_ACTIVITYID));
+ $pdfannotator->set_source_table('pdfannotator', ['id' => backup::VAR_ACTIVITYID]);
if ($userinfo) {
// Add all annotations specific to this annotator instance.
@@ -102,19 +101,19 @@ protected function define_structure() {
. 'JOIN {pdfannotator_comments} c ON a.id = c.annotationid '
. "WHERE a.pdfannotatorid = ? AND c.isquestion = 1 AND "
. "(c.visibility = 'public' OR c.visibility = 'anonymous') ",
- array('pdfannotatorid' => backup::VAR_PARENTID));
+ ['pdfannotatorid' => backup::VAR_PARENTID]);
// Add any subscriptions to this annotation.
- $subscription->set_source_table('pdfannotator_subscriptions', array('annotationid' => backup::VAR_PARENTID));
+ $subscription->set_source_table('pdfannotator_subscriptions', ['annotationid' => backup::VAR_PARENTID]);
// Add any comments of this annotation.
- $comment->set_source_table('pdfannotator_comments', array('annotationid' => backup::VAR_PARENTID));
+ $comment->set_source_table('pdfannotator_comments', ['annotationid' => backup::VAR_PARENTID]);
// Add any votes for this comment.
- $vote->set_source_table('pdfannotator_votes', array('commentid' => backup::VAR_PARENTID));
+ $vote->set_source_table('pdfannotator_votes', ['commentid' => backup::VAR_PARENTID]);
// Add any reports of this comment.
- $report->set_source_table('pdfannotator_reports', array('commentid' => backup::VAR_PARENTID));
+ $report->set_source_table('pdfannotator_reports', ['commentid' => backup::VAR_PARENTID]);
}
// 5. Define id annotations (some attributes are foreign keys).
diff --git a/backup/moodle2/restore_pdfannotator_activity_task.class.php b/backup/moodle2/restore_pdfannotator_activity_task.class.php
index 25ca6b9..6f5d31c 100644
--- a/backup/moodle2/restore_pdfannotator_activity_task.class.php
+++ b/backup/moodle2/restore_pdfannotator_activity_task.class.php
@@ -58,9 +58,9 @@ protected function define_my_steps() {
* processed by the link decoder.
*/
public static function define_decode_contents() {
- $contents = array();
+ $contents = [];
- $contents[] = new restore_decode_content('pdfannotator', array('intro'), 'pdfannotator');
+ $contents[] = new restore_decode_content('pdfannotator', ['intro'], 'pdfannotator');
return $contents;
}
@@ -70,7 +70,7 @@ public static function define_decode_contents() {
* to the activity to be executed by the link decoder
*/
public static function define_decode_rules() {
- $rules = array();
+ $rules = [];
$rules[] = new restore_decode_rule('PDFANNOTATORVIEWBYID', '/mod/pdfannotator/view.php?id=$1', 'course_module');
$rules[] = new restore_decode_rule('PDFANNOTATORINDEX', '/mod/pdfannotator/index.php?id=$1', 'course');
@@ -86,7 +86,7 @@ public static function define_decode_rules() {
* of {@see restore_log_rule} objects
*/
public static function define_restore_log_rules() {
- $rules = array();
+ $rules = [];
$rules[] = new restore_log_rule('pdfannotator', 'add', 'view.php?id={course_module}', '{pdfannotator}');
$rules[] = new restore_log_rule('pdfannotator', 'update', 'view.php?id={course_module}', '{pdfannotator}');
@@ -106,7 +106,7 @@ public static function define_restore_log_rules() {
* activity level. All them are rules not linked to any module instance (cmid = 0)
*/
public static function define_restore_log_rules_for_course() {
- $rules = array();
+ $rules = [];
$rules[] = new restore_log_rule('pdfannotator', 'view all', 'index.php?id={course}', null);
diff --git a/backup/moodle2/restore_pdfannotator_stepslib.php b/backup/moodle2/restore_pdfannotator_stepslib.php
index f255af2..e614c5e 100644
--- a/backup/moodle2/restore_pdfannotator_stepslib.php
+++ b/backup/moodle2/restore_pdfannotator_stepslib.php
@@ -28,8 +28,6 @@
* @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
*/
@@ -46,7 +44,7 @@ class restore_pdfannotator_activity_structure_step extends restore_activity_stru
*/
protected function define_structure() {
- $paths = array();
+ $paths = [];
$userinfo = $this->get_setting_value('userinfo');
@@ -185,7 +183,6 @@ protected function process_pdfannotator_report($data) {
$data->commentid = $this->get_new_parentid('pdfannotator_comment');
$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.
diff --git a/classes/event/course_module_instance_list_viewed.php b/classes/event/course_module_instance_list_viewed.php
index 822ef90..82ebe33 100644
--- a/classes/event/course_module_instance_list_viewed.php
+++ b/classes/event/course_module_instance_list_viewed.php
@@ -16,8 +16,6 @@
namespace mod_pdfannotator\event;
-defined('MOODLE_INTERNAL') || die();
-
/**
* The mod_pdfannotator instance list viewed event class.
*
diff --git a/classes/event/course_module_viewed.php b/classes/event/course_module_viewed.php
index bf5c8c3..f56a8c1 100644
--- a/classes/event/course_module_viewed.php
+++ b/classes/event/course_module_viewed.php
@@ -16,8 +16,6 @@
namespace mod_pdfannotator\event;
-defined('MOODLE_INTERNAL') || die();
-
/**
* The mod_pdfannotator instance list viewed event class.
*
@@ -43,6 +41,6 @@ protected function init() {
* Get objectid mapping for restore.
*/
public static function get_objectid_mapping() {
- return array('db' => 'pdfannotator', 'restore' => 'pdfannotator');
+ return ['db' => 'pdfannotator', 'restore' => 'pdfannotator'];
}
}
diff --git a/classes/event/report_added.php b/classes/event/report_added.php
index 97c0603..09951bd 100644
--- a/classes/event/report_added.php
+++ b/classes/event/report_added.php
@@ -21,8 +21,9 @@
* @copyright 2014 CIL
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
+
namespace mod_pdfannotator\event;
-defined('MOODLE_INTERNAL') || die();
+
/**
*
* The mod_pdfannotator report_added event class.
@@ -37,7 +38,7 @@ class report_added extends \core\event\base {
* the initialising function
*/
protected function init() {
- $this->data['crud'] = 'c'; // ... c(reate), r(ead), u(pdate), d(elete).
+ $this->data['crud'] = 'c'; // This m eans c(reate), r(ead), u(pdate), d(elete).
$this->data['edulevel'] = self::LEVEL_PARTICIPATING;
$this->data['objecttable'] = 'pdfannotator_reports';
}
@@ -59,6 +60,6 @@ public function get_description() {
* the url fetch function
*/
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', ['id' => $this->other['cmid'], 'action' => 'overview']);
}
}
diff --git a/classes/output/answermenu.php b/classes/output/answermenu.php
index 725376f..576d5d7 100644
--- a/classes/output/answermenu.php
+++ b/classes/output/answermenu.php
@@ -26,13 +26,29 @@
namespace mod_pdfannotator\output;
use moodle_url;
-defined('MOODLE_INTERNAL') || die();
-
+/**
+ * Class for rendering a dropdown menu in the answerstable on the overview tab.
+ */
class answermenu implements \renderable, \templatable {
+ /**
+ * @var moodle_url
+ */
private $url;
+
+ /**
+ * @var string
+ */
private $iconclass;
+
+ /**
+ * @var \lang_string|string
+ */
private $label;
+
+ /**
+ * @var string
+ */
private $buttonclass;
/**
@@ -49,12 +65,12 @@ public function __construct($annotationid, $issubscribed, $cmid, $currentpage, $
global $CFG;
if ($answerfilter == 0 && empty($issubscribed)) { // Show all answers and this answer is not subscribed.
// No one size fits all.
- $urlparams = array('action' => 'subscribeQuestion');
+ $urlparams = ['action' => 'subscribeQuestion'];
$iconclass = "icon fa fa-bell fa-fw";
$label = get_string('subscribeQuestion', 'pdfannotator');
$buttonclass = 'comment-subscribe subscribe';
} else { // Show answers to subscribed questions.
- $urlparams = array('action' => 'unsubscribeQuestion');
+ $urlparams = ['action' => 'unsubscribeQuestion'];
$iconclass = "icon fa fa-bell-slash fa-fw";
$label = get_string('unsubscribeQuestion', 'pdfannotator');
$buttonclass = 'comment-subscribe unsubscribe';
@@ -81,8 +97,9 @@ public function __construct($annotationid, $issubscribed, $cmid, $currentpage, $
/**
* This function is required by any renderer to retrieve the data structure
* passed into the template.
+ *
* @param \renderer_base $output
- * @return type
+ * @return array
*/
public function export_for_template(\renderer_base $output) {
$data = [];
diff --git a/classes/output/comment.php b/classes/output/comment.php
index e3b3745..1c5a7a1 100644
--- a/classes/output/comment.php
+++ b/classes/output/comment.php
@@ -17,8 +17,6 @@
namespace mod_pdfannotator\output;
use moodle_url;
-defined('MOODLE_INTERNAL') || die();
-
/**
* Renderable for comments.
*
@@ -29,7 +27,14 @@
*/
class comment implements \renderable, \templatable {
+ /**
+ * @var array
+ */
private $comments = [];
+
+ /**
+ * @var string
+ */
private $questionvisibility;
/**
@@ -38,7 +43,7 @@ class comment implements \renderable, \templatable {
* @param object $data Comment or array of comments
* @param object $cm Course module
* @param object $context Context
- * @return type
+ * @return void
*/
public function __construct($data, $cm, $context) {
global $USER;
@@ -112,8 +117,9 @@ public function __construct($data, $cm, $context) {
/**
* This function is required by any renderer to retrieve the data structure
* passed into the template.
+ *
* @param \renderer_base $output
- * @return type
+ * @return array
*/
public function export_for_template(\renderer_base $output) {
$data = [];
@@ -122,11 +128,18 @@ public function export_for_template(\renderer_base $output) {
return $data;
}
+ /**
+ * Add CSS classes to comment wrapper.
+ *
+ * @param string $comment
+ * @param \stdClass $owner
+ * @return void
+ */
private function addcssclasses($comment, $owner) {
$comment->wrapperClass = 'chat-message comment-list-item';
if ($comment->isquestion) {
$comment->wrapperClass .= ' questioncomment';
- if($comment->visibility == 'private' || $comment->visibility == 'protected') {
+ if ($comment->visibility == 'private' || $comment->visibility == 'protected') {
$comment->wrapperClass .= ' questions-private';
}
} else if ($comment->solved) {
@@ -140,6 +153,13 @@ private function addcssclasses($comment, $owner) {
}
}
+ /**
+ * Set votes for comment.
+ *
+ * @param string $comment
+ * @return void
+ * @throws \coding_exception
+ */
public function setvotes($comment) {
if ($comment->usevotes && !$comment->isdeleted) {
if ($comment->owner) {
@@ -167,7 +187,8 @@ public function setvotes($comment) {
/**
* Add check icon if comment is marked as correct.
- * @param type $comment
+ *
+ * @param string $comment
*/
public function addsolvedicon($comment) {
if ($comment->solved) {
@@ -183,9 +204,10 @@ public function addsolvedicon($comment) {
/**
* Report comment if user is not the owner.
- * @param type $comment
- * @param type $owner
- * @param type $report
+ *
+ * @param string $comment
+ * @param \stdClass $report
+ * @param \context_module $cm Course module object
*/
private function addreportbutton($comment, $report, $cm) {
if (!$comment->isdeleted && $report && !$comment->owner && !isset($comment->type)) {
@@ -197,10 +219,10 @@ private function addreportbutton($comment, $report, $cm) {
/**
* Open/close question if user is owner of the question or manager.
- * @param type $comment
- * @param type $owner
- * @param type $closequestion
- * @param type $closeanyquestion
+ *
+ * @param string $comment
+ * @param bool $closequestion
+ * @param bool $closeanyquestion
*/
private function addcloseopenbutton($comment, $closequestion, $closeanyquestion) {
@@ -219,9 +241,9 @@ private function addcloseopenbutton($comment, $closequestion, $closeanyquestion)
/**
* Button for editing comment if user is owner of the comment or manager.
- * @param type $comment
- * @param type $owner
- * @param type $editanypost
+ *
+ * @param string $comment
+ * @param bool $editanypost
*/
private function addeditbutton($comment, $editanypost) {
if (!$comment->isdeleted && !isset($comment->type) && ($comment->owner || $editanypost)) {
@@ -232,6 +254,15 @@ private function addeditbutton($comment, $editanypost) {
}
}
+ /**
+ * Add button to hide or unhide comment.
+ *
+ * @param string $comment
+ * @param bool $seehiddencomments
+ * @param bool $hidecomments
+ * @return void
+ * @throws \coding_exception
+ */
private function addhidebutton($comment, $seehiddencomments, $hidecomments) {
// Don't need to hide personal notes.
if ($this->questionvisibility == 'private') {
@@ -259,11 +290,12 @@ private function addhidebutton($comment, $seehiddencomments, $hidecomments) {
}
/**
+ * Add button to delete comment.
* Delete comment if user is owner of the comment or manager.
- * @param type $comment
- * @param type $owner
- * @param type $deleteown
- * @param type $deleteany
+ *
+ * @param string $comment
+ * @param bool $deleteown
+ * @param bool $deleteany
*/
private function adddeletebutton($comment, $deleteown, $deleteany) {
if (!$comment->isdeleted && ($deleteany || ($deleteown && $comment->owner))) {
@@ -273,6 +305,14 @@ private function adddeletebutton($comment, $deleteown, $deleteany) {
}
}
+ /**
+ * Add button to subscribe to question.
+ *
+ * @param string $comment
+ * @param bool $subscribe
+ * @return void
+ * @throws \coding_exception
+ */
private function addsubscribebutton($comment, $subscribe) {
if (!isset($comment->type) && $comment->isquestion && $subscribe && $comment->visibility != 'private') {
// Only set for textbox and drawing.
@@ -286,6 +326,16 @@ private function addsubscribebutton($comment, $subscribe) {
}
}
+ /**
+ * Add button to forward question to other users.
+ *
+ * @param string $comment
+ * @param bool $forwardquestions
+ * @param \context_module $cm
+ * @return void
+ * @throws \coding_exception
+ * @throws \core\exception\moodle_exception
+ */
private function addforwardbutton($comment, $forwardquestions, $cm) {
if (!isset($comment->type) && $comment->isquestion && !$comment->isdeleted && $forwardquestions &&
$comment->visibility != 'private') {
@@ -299,6 +349,14 @@ private function addforwardbutton($comment, $forwardquestions, $cm) {
}
}
+ /**
+ * Add button to mark comment as solved or remove solved status.
+ *
+ * @param string $comment
+ * @param bool $solve
+ * @return void
+ * @throws \coding_exception
+ */
private function addmarksolvedbutton($comment, $solve) {
if ($solve && !$comment->isquestion && !$comment->isdeleted && !isset($comment->type) &&
$this->questionvisibility != 'private') {
diff --git a/classes/output/index.php b/classes/output/index.php
index c857b53..280ebb4 100644
--- a/classes/output/index.php
+++ b/classes/output/index.php
@@ -34,19 +34,48 @@
use moodle_url;
use stdClass;
-defined('MOODLE_INTERNAL') || die();
-
+/**
+ *
+ */
class index implements \renderable, \templatable {
// Class should be placed elsewhere.
+ /**
+ * @var bool
+ */
private $usestudenttextbox;
+ /**
+ * @var bool
+ */
private $usestudentdrawing;
+ /**
+ * @var bool
+ */
private $useprint;
+ /**
+ * @var bool
+ */
private $useprintcomments;
+ /**
+ * @var string
+ */
private $printurl;
+ /**
+ * @var bool
+ */
private $useprivatecomments;
+ /**
+ * @var bool
+ */
private $useprotectedcomments;
+ /**
+ * Constructor for the index class.
+ *
+ * @param stdClass $pdfannotator
+ * @param array $capabilities
+ * @param stdClass $file
+ */
public function __construct($pdfannotator, $capabilities, $file) {
$this->usestudenttextbox = ($pdfannotator->use_studenttextbox || $capabilities->usetextbox);
$this->usestudentdrawing = ($pdfannotator->use_studentdrawing || $capabilities->usedrawing);
@@ -60,6 +89,12 @@ public function __construct($pdfannotator, $capabilities, $file) {
$file->get_itemid(), $file->get_filepath(), $file->get_filename(), true)->out(false);
}
+ /**
+ * Export data for the template.
+ *
+ * @param \renderer_base $output
+ * @return stdClass
+ */
public function export_for_template(\renderer_base $output) {
global $OUTPUT, $PAGE;
$url = $PAGE->url;
diff --git a/classes/output/printview.php b/classes/output/printview.php
index b6bbff0..fe7ca90 100644
--- a/classes/output/printview.php
+++ b/classes/output/printview.php
@@ -28,15 +28,31 @@
namespace mod_pdfannotator\output;
-defined('MOODLE_INTERNAL') || die();
-
+/**
+ * The purpose of this script is to collect the output data for the printview template
+ */
class printview implements \renderable, \templatable {
+ /**
+ * @var mixed|null
+ */
private $documentname;
+ /**
+ * @var mixed|null
+ */
private $conversations;
+ /**
+ * @var mixed|null
+ */
private $url;
-
+ /**
+ * Constructor for the printview class.
+ *
+ * @param string $documentname
+ * @param array $conversations
+ * @param string $url
+ */
public function __construct($documentname=null, $conversations=null, $url=null) {
$this->documentname = $documentname;
@@ -44,6 +60,12 @@ public function __construct($documentname=null, $conversations=null, $url=null)
$this->url = $url;
}
+ /**
+ * This method returns an array containing the data that is needed
+ *
+ * @param \renderer_base $output
+ * @return array
+ */
public function export_for_template(\renderer_base $output) {
$data = [];
diff --git a/classes/output/questionmenu.php b/classes/output/questionmenu.php
index a43d1d0..b0ffbac 100644
--- a/classes/output/questionmenu.php
+++ b/classes/output/questionmenu.php
@@ -26,13 +26,26 @@
namespace mod_pdfannotator\output;
use moodle_url;
-defined('MOODLE_INTERNAL') || die();
-
+/**
+ * Class for the question menu in the questionstable on overview tab.
+ */
class questionmenu implements \renderable, \templatable {
+ /**
+ * @var moodle_url
+ */
private $url;
+ /**
+ * @var string
+ */
private $iconclass;
+ /**
+ * @var \lang_string|string
+ */
private $label;
+ /**
+ * @var string
+ */
private $buttonclass;
/**
@@ -64,8 +77,9 @@ public function __construct($commentid, $urlparams) {
/**
* This function is required by any renderer to retrieve the data structure
* passed into the template.
+ *
* @param \renderer_base $output
- * @return type
+ * @return array
*/
public function export_for_template(\renderer_base $output) {
$data = [];
diff --git a/classes/output/reportmenu.php b/classes/output/reportmenu.php
index bb6ecf3..811e3aa 100644
--- a/classes/output/reportmenu.php
+++ b/classes/output/reportmenu.php
@@ -26,12 +26,22 @@
namespace mod_pdfannotator\output;
use moodle_url;
-defined('MOODLE_INTERNAL') || die();
-
+/**
+ * Class for the report menu in the reportstable on overview tab.
+ */
class reportmenu implements \renderable, \templatable {
+ /**
+ * @var moodle_url
+ */
private $url;
+ /**
+ * @var string
+ */
private $iconclass;
+ /**
+ * @var \lang_string|string
+ */
private $label;
/**
@@ -45,11 +55,11 @@ class reportmenu implements \renderable, \templatable {
public function __construct($report, $cmid, $currentpage, $itemsperpage, $reportfilter) {
global $CFG;
if ($report->seen == 0) {
- $urlparams = array('action' => 'markreportasread');
+ $urlparams = ['action' => 'markreportasread'];
$iconclass = "icon fa fa-eye-slash fa-fw";
$label = get_string('markasread', 'pdfannotator');
} else {
- $urlparams = array('action' => 'markreportasunread');
+ $urlparams = ['action' => 'markreportasunread'];
$iconclass = "icon fa fa-eye fa-fw";
$label = get_string('markasunread', 'pdfannotator');
}
@@ -74,8 +84,9 @@ public function __construct($report, $cmid, $currentpage, $itemsperpage, $report
/**
* This function is required by any renderer to retrieve the data structure
* passed into the template.
+ *
* @param \renderer_base $output
- * @return type
+ * @return array
*/
public function export_for_template(\renderer_base $output) {
$data = [];
diff --git a/classes/output/statistics.php b/classes/output/statistics.php
index 06825db..138adc8 100644
--- a/classes/output/statistics.php
+++ b/classes/output/statistics.php
@@ -29,15 +29,19 @@
use pdfannotator_statistics;
-defined('MOODLE_INTERNAL') || die();
-
/**
* The purpose of this script is to collect the output data for the template and
* make it available to the renderer.
*/
class statistics implements \renderable, \templatable {
+ /**
+ * @var bool
+ */
private $isteacher;
+ /**
+ * @var array
+ */
private $tabledata;
/**
@@ -57,15 +61,16 @@ public function __construct($annotatorid, $courseid, $capabilities, $id) {
$this->tabledata = $statistics->get_tabledata();
$params = $statistics->get_chartdata();
- $PAGE->requires->js_init_call('addDropdownNavigation', array($capabilities, $id), true);
+ $PAGE->requires->js_init_call('addDropdownNavigation', [$capabilities, $id], true);
$PAGE->requires->js_init_call('setCharts', $params, true);
}
/**
* This function is required by any renderer to retrieve the data structure
* passed into the template.
+ *
* @param \renderer_base $output
- * @return type
+ * @return array
*/
public function export_for_template(\renderer_base $output) {
diff --git a/classes/privacy/provider.php b/classes/privacy/provider.php
index d723727..0735df7 100644
--- a/classes/privacy/provider.php
+++ b/classes/privacy/provider.php
@@ -26,8 +26,6 @@
namespace mod_pdfannotator\privacy;
-defined('MOODLE_INTERNAL') || die();
-
use core_privacy\local\request\approved_contextlist;
use core_privacy\local\request\writer;
use core_privacy\local\metadata\collection;
@@ -201,7 +199,7 @@ public static function export_user_data(approved_contextlist $contextlist) {
$sql1 = "SELECT c.content, c.timecreated, c.visibility
FROM {pdfannotator_comments} c
WHERE c.isquestion = 1 AND c.userid = :userid AND c.pdfannotatorid = :pdfannotator";
- $myquestions = $DB->get_records_sql($sql1, array('userid' => $userid, 'pdfannotator' => $pdfannotator->id));
+ $myquestions = $DB->get_records_sql($sql1, ['userid' => $userid, 'pdfannotator' => $pdfannotator->id]);
foreach ($myquestions as $myquestion) {
$myquestion->timecreated = pdfannotator_get_user_datetime($myquestion->timecreated);
@@ -212,8 +210,10 @@ public static function export_user_data(approved_contextlist $contextlist) {
. "FROM {pdfannotator_comments} c "
. "JOIN {pdfannotator_annotations} a ON c.annotationid = a.id "
. "JOIN {pdfannotator_comments} q ON q.annotationid = c.annotationid "
- . "WHERE q.isquestion = :question AND c.isquestion = :normalcomment AND c.userid = :userid AND a.pdfannotatorid = :pdfannotator";
- $mycomments = $DB->get_records_sql($sql2, array('question' => 1, 'normalcomment' => 0, 'userid' => $userid, 'pdfannotator' => $pdfannotator->id));
+ . "WHERE q.isquestion = :question AND c.isquestion = :normalcomment AND c.userid = :userid AND "
+ . "a.pdfannotatorid = :pdfannotator";
+ $mycomments = $DB->get_records_sql($sql2, ['question' => 1, 'normalcomment' => 0, 'userid' => $userid,
+ 'pdfannotator' => $pdfannotator->id]);
foreach ($mycomments as $mycomment) {
$mycomment->timecreated = pdfannotator_get_user_datetime($mycomment->timecreated);
@@ -221,27 +221,31 @@ public static function export_user_data(approved_contextlist $contextlist) {
// Get all subscriptions of this user (exluding their own questions which they're automatically subscribed to).
$sql3 = "SELECT c.content
- FROM {pdfannotator_subscriptions} s JOIN {pdfannotator_annotations} a ON s.annotationid = a.id JOIN {pdfannotator_comments} c ON c.annotationid = a.id
+ FROM {pdfannotator_subscriptions} s
+ JOIN {pdfannotator_annotations} a ON s.annotationid = a.id
+ JOIN {pdfannotator_comments} c ON c.annotationid = a.id
WHERE c.isquestion = 1 AND s.userid = :userid AND a.pdfannotatorid = :pdfannotator AND NOT a.userid = :u";
- $mysubscriptions = $DB->get_records_sql($sql3, array('userid' => $userid, 'pdfannotator' => $pdfannotator->id, 'u' => $userid));
+ $mysubscriptions = $DB->get_records_sql($sql3, ['userid' => $userid, 'pdfannotator' => $pdfannotator->id,
+ 'u' => $userid]);
// Get all comments this user voted for in this annotator.
$sql4 = "SELECT c.content
FROM {pdfannotator_comments} c JOIN {pdfannotator_votes} v on v.commentid = c.id
WHERE v.userid = :userid AND c.pdfannotatorid = :pdfannotator";
- $myvotes = $DB->get_records_sql($sql4, array('userid' => $userid, 'pdfannotator' => $pdfannotator->id));
+ $myvotes = $DB->get_records_sql($sql4, ['userid' => $userid, 'pdfannotator' => $pdfannotator->id]);
// Get all reports this user wrote.
$sql6 = "SELECT r.message
FROM {pdfannotator_reports} r JOIN {pdfannotator_comments} c ON c.id = r.commentid
WHERE r.userid = :userid AND r.pdfannotatorid = :pdfannotator";
- $myreportmessages = $DB->get_records_sql($sql6, array('userid' => $userid, 'pdfannotator' => $pdfannotator->id));
+ $myreportmessages = $DB->get_records_sql($sql6, ['userid' => $userid, 'pdfannotator' => $pdfannotator->id]);
// Get all drawings and textboxes this user made in this annotator.
$sql7 = "SELECT a.data, a.timecreated
FROM {pdfannotator_annotations} a JOIN {pdfannotator_annotationtypes} t ON a.annotationtypeid = t.id
WHERE t.name IN (:type1, :type2) AND a.userid = :userid AND a.pdfannotatorid = :pdfannotator";
- $mydrawingsandtextboxes = $DB->get_records_sql($sql7, array('type1' => 'drawing', 'type2' => 'textbox', 'userid' => $userid, 'pdfannotator' => $pdfannotator->id));
+ $mydrawingsandtextboxes = $DB->get_records_sql($sql7, ['type1' => 'drawing', 'type2' => 'textbox', 'userid' => $userid,
+ 'pdfannotator' => $pdfannotator->id]);
foreach ($mydrawingsandtextboxes as $mydrawingortextbox) {
$mydrawingortextbox->timecreated = pdfannotator_get_user_datetime($mydrawingortextbox->timecreated);
@@ -285,30 +289,31 @@ public static function delete_data_for_all_users_in_context(\context $context) {
$sql = "SELECT v.id FROM {pdfannotator_votes} v WHERE v.commentid IN "
. "(SELECT c.id FROM {pdfannotator_comments} c "
. "JOIN {pdfannotator_annotations} a ON c.annotationid = a.id WHERE a.pdfannotatorid = ?)";
- $votes = $DB->get_records_sql($sql, array($instanceid));
+ $votes = $DB->get_records_sql($sql, [$instanceid]);
foreach ($votes as $vote) {
- $DB->delete_records('pdfannotator_votes', array("id" => $vote->id));
+ $DB->delete_records('pdfannotator_votes', ["id" => $vote->id]);
}
// 3. Delete all subscriptions in this annotator.
$sql = "SELECT s.id FROM {pdfannotator_subscriptions} s "
. "WHERE s.annotationid IN (SELECT a.id FROM {pdfannotator_annotations} a WHERE a.pdfannotatorid = ?)";
- $subscriptions = $DB->get_records_sql($sql, array($instanceid));
+ $subscriptions = $DB->get_records_sql($sql, [$instanceid]);
foreach ($subscriptions as $subscription) {
- $DB->delete_records('pdfannotator_subscriptions', array("id" => $subscription->id));
+ $DB->delete_records('pdfannotator_subscriptions', ["id" => $subscription->id]);
}
// 4. Delete all comments in this annotator.
- $sql = "SELECT c.id FROM {pdfannotator_comments} c WHERE c.annotationid IN (SELECT a.id FROM {pdfannotator_annotations} a WHERE a.pdfannotatorid = ?)";
- $comments = $DB->get_records_sql($sql, array($instanceid));
+ $sql = "SELECT c.id FROM {pdfannotator_comments} c WHERE c.annotationid IN (SELECT a.id FROM {pdfannotator_annotations} a" .
+ " WHERE a.pdfannotatorid = ?)";
+ $comments = $DB->get_records_sql($sql, [$instanceid]);
foreach ($comments as $comment) {
- $DB->delete_records('pdfannotator_comments', array("id" => $comment->id));
+ $DB->delete_records('pdfannotator_comments', ["id" => $comment->id]);
}
// 5. Delete all annotations in this annotator.
- $annotations = $DB->get_fieldset_select('pdfannotator_annotations', 'id', "pdfannotatorid = ?", array($instanceid));
+ $annotations = $DB->get_fieldset_select('pdfannotator_annotations', 'id', "pdfannotatorid = ?", [$instanceid]);
foreach ($annotations as $annotationid) {
- $DB->delete_records('pdfannotator_annotations', array("id" => $annotationid));
+ $DB->delete_records('pdfannotator_annotations', ["id" => $annotationid]);
}
}
@@ -344,9 +349,9 @@ public static function delete_data_for_user(approved_contextlist $contextlist) {
(SELECT c.id
FROM {pdfannotator_comments} c
WHERE c.pdfannotatorid = ?)";
- $votes = $DB->get_records_sql($sql , array($userid, $instanceid));
+ $votes = $DB->get_records_sql($sql , [$userid, $instanceid]);
foreach ($votes as $vote) {
- $DB->delete_records('pdfannotator_votes', array("id" => $vote->id));
+ $DB->delete_records('pdfannotator_votes', ["id" => $vote->id]);
}
// 3. Delete all subscriptions this user made in this annotator.
@@ -356,16 +361,16 @@ public static function delete_data_for_user(approved_contextlist $contextlist) {
(SELECT a.id
FROM {pdfannotator_annotations} a
WHERE a.pdfannotatorid = ?)";
- $subscriptions = $DB->get_records_sql($sql, array($userid, $instanceid));
+ $subscriptions = $DB->get_records_sql($sql, [$userid, $instanceid]);
foreach ($subscriptions as $subscription) {
- $DB->delete_records('pdfannotator_subscriptions', array("id" => $subscription->id));
+ $DB->delete_records('pdfannotator_subscriptions', ["id" => $subscription->id]);
}
// 4. Select all comments this user made in this annotator.
$sql = "SELECT c.*
FROM {pdfannotator_comments} c
WHERE c.pdfannotatorid = ? AND c.userid = ?";
- $comments = $DB->get_records_sql($sql, array($instanceid, $userid));
+ $comments = $DB->get_records_sql($sql, [$instanceid, $userid]);
foreach ($comments as $comment) {
// Delete question comments, their underlying annotation as well as all answers and subscriptions.
if ($comment->isquestion) {
@@ -376,8 +381,10 @@ public static function delete_data_for_user(approved_contextlist $contextlist) {
self::empty_or_delete_comment($comment);
}
- // 5. Select the IDs of all annotations that were made by this user in this annotator. Then call the function to delete the annotation and any adjacent comments.
- $annotations = $DB->get_fieldset_select('pdfannotator_annotations', 'id', "pdfannotatorid = ? AND userid = ?", array($instanceid, $userid));
+ // 5. Select the IDs of all annotations that were made by this user in this annotator. Then call the function to delete
+ // the annotation and any adjacent comments.
+ $annotations = $DB->get_fieldset_select('pdfannotator_annotations', 'id', "pdfannotatorid = ? " .
+ "AND userid = ?", [$instanceid, $userid]);
foreach ($annotations as $annotationid) {
self::delete_annotation($annotationid);
}
@@ -386,7 +393,8 @@ public static function delete_data_for_user(approved_contextlist $contextlist) {
// Status quo:
// Deleting the initial or final comment of a 'thread' will remove it from the comments table.
- // Deleting any other comment will merely set the field isdeleted of the comments table to 1, so that the comment will be displayed as deleted within the 'thread'.
+ // Deleting any other comment will merely set the field isdeleted of the comments table to 1, so that the comment will be
+ // displayed as deleted within the 'thread'.
/**
* Function deletes an annotation and all comments and subscriptions attached to it.
@@ -399,25 +407,25 @@ public static function delete_annotation($annotationid) {
// 1. Get all comments on this annotation and prepare them for deletion.
// 1.1 Retrieve comments from DB.
- $comments = $DB->get_records('pdfannotator_comments', array("annotationid" => $annotationid));
+ $comments = $DB->get_records('pdfannotator_comments', ["annotationid" => $annotationid]);
foreach ($comments as $comment) {
// 1.2 Delete any votes for these comments.
- $DB->delete_records('pdfannotator_votes', array("commentid" => $comment->id));
+ $DB->delete_records('pdfannotator_votes', ["commentid" => $comment->id]);
// Delete any pictures of the comment.
- $DB->delete_records('files', array("component" => "mod_pdfannotator", "filearea" => "post", "itemid" => $comment->id));
+ $DB->delete_records('files', ["component" => "mod_pdfannotator", "filearea" => "post", "itemid" => $comment->id]);
}
// 1.3 Now delete all comments.
- $DB->delete_records('pdfannotator_comments', array("annotationid" => $annotationid));
+ $DB->delete_records('pdfannotator_comments', ["annotationid" => $annotationid]);
// 2. Delete subscriptions to the question.
- $DB->delete_records('pdfannotator_subscriptions', array('annotationid' => $annotationid));
+ $DB->delete_records('pdfannotator_subscriptions', ['annotationid' => $annotationid]);
// 3. Delete the annotation itself.
- $DB->delete_records('pdfannotator_annotations', array("id" => $annotationid));
+ $DB->delete_records('pdfannotator_annotations', ["id" => $annotationid]);
}
/**
@@ -432,30 +440,32 @@ public static function empty_or_delete_comment($comment) {
global $DB;
$select = "annotationid = ? AND timecreated > ? AND isdeleted = ?";
- $wasanswered = $DB->record_exists_select('pdfannotator_comments', $select, array($comment->annotationid, $comment->timecreated, 0));
+ $wasanswered = $DB->record_exists_select('pdfannotator_comments', $select,
+ [$comment->annotationid, $comment->timecreated, 0]);
// If the comment was answered, empty it and mark it as deleted for a special display.
if ($wasanswered) {
- $DB->update_record('pdfannotator_comments', array("id" => $comment->id, "content" => "", "isdeleted" => 1));
+ $DB->update_record('pdfannotator_comments', ["id" => $comment->id, "content" => "", "isdeleted" => 1]);
// If not, just delete it.
} else {
// But first: Check if the predecessor was already marked as deleted, too and if so, delete it completely.
- $sql = "SELECT id, isdeleted from {pdfannotator_comments} WHERE annotationid = ? AND isquestion = ? AND timecreated < ? ORDER BY id DESC";
- $params = array($comment->annotationid, 0, $comment->timecreated);
+ $sql = "SELECT id, isdeleted from {pdfannotator_comments} WHERE annotationid = ? AND isquestion = ? AND ".
+ "timecreated < ? ORDER BY id DESC";
+ $params = [$comment->annotationid, 0, $comment->timecreated];
$predecessors = $DB->get_records_sql($sql, $params);
foreach ($predecessors as $predecessor) {
if ($predecessor->isdeleted) {
- $DB->delete_records('pdfannotator_comments', array("id" => $predecessor->id));
+ $DB->delete_records('pdfannotator_comments', ["id" => $predecessor->id]);
} else {
break;
}
}
// Now delete the selected comment.
- $DB->delete_records('pdfannotator_comments', array("id" => $comment->id));
+ $DB->delete_records('pdfannotator_comments', ["id" => $comment->id]);
}
}
@@ -512,7 +522,7 @@ public static function get_users_in_context(userlist $userlist) {
WHERE cm.id = :contextid";
$userlist->add_from_sql('userid', $sql, $params);
- // Subscriptions
+ // Subscriptions.
$sql = "SELECT asub.userid
FROM {course_modules} cm
JOIN {modules} m ON m.id = cm.module AND m.name = :modulename
diff --git a/constants.php b/constants.php
index 02dc955..f0994e0 100644
--- a/constants.php
+++ b/constants.php
@@ -22,8 +22,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-defined('MOODLE_INTERNAL') || die();
-
/**
* Request URL for transforming latex code into a png image
* The latex data needs to be added after chl=
diff --git a/controller.php b/controller.php
index e304068..0b9fefc 100644
--- a/controller.php
+++ b/controller.php
@@ -15,6 +15,8 @@
// along with Moodle. If not, see
";
}
- $table->data[] = array (
+ $table->data[] = [
$printsection,
"
' .
'' .
format_string($course->shortname, true, $formatparams) .
@@ -641,15 +811,22 @@ function pdfannotator_format_notification_message_html($course, $cm, $context, $
$posthtml .= ' ' . get_string($messagetype . 'html', 'pdfannotator', $report) . ' ' . get_string('unsubscribe_notification', 'pdfannotator', $linktonotificationsettingspage) . ' ' . get_string('unsubscribe_notification', 'pdfannotator',
+ $linktonotificationsettingspage) . '
';
$report->urltoreport = $CFG->wwwroot . '/mod/pdfannotator/view.php?id=' . $cm->id . '&action=overviewreports';
$posthtml .= '
';
- $posthtml .= '
" . get_string('hiddenfromstudents') . ""; // XXX use moodle method if exists.
+ $labelhidden = "
" . get_string('hiddenfromstudents') . "";
+ // XXX use moodle method if exists.
$labelunavailable = "
" . get_string('restricted') . "";
$res = [];
@@ -1090,8 +1333,8 @@ function pdfannotator_get_questions($courseid, $context, $questionfilter) {
$question->content = pdfannotator_get_relativelink($question->content, $question->commentid, $context);
$question->content = format_text($question->content, FORMAT_MOODLE);
- $question->link = (new moodle_url('/mod/pdfannotator/view.php', array('id' => $question->cmid,
- 'page' => $question->page, 'annoid' => $question->annoid, 'commid' => $question->commentid)))->out();
+ $question->link = (new moodle_url('/mod/pdfannotator/view.php', ['id' => $question->cmid,
+ 'page' => $question->page, 'annoid' => $question->annoid, 'commid' => $question->commentid]))->out();
$res[] = $question;
@@ -1104,7 +1347,8 @@ function pdfannotator_get_questions($courseid, $context, $questionfilter) {
* questions and answers this user posted in the course.
*
* @param int $courseid
- * @return type
+ * @param \context $context the context of the PDF annotator instance
+ * @return array
*/
function pdfannotator_get_posts_by_this_user($courseid, $context) {
@@ -1126,7 +1370,8 @@ function pdfannotator_get_posts_by_this_user($courseid, $context) {
. "JOIN {course_modules} cm ON p.id = cm.instance "
. "LEFT JOIN {pdfannotator_votes} v ON c.id = v.commentid "
. "WHERE c.userid = ? AND p.course = ? AND cm.id $insql "
- . "GROUP BY a.id, p.name, p.usevotes, cm.id, c.id, c.annotationid, c.content, c.timemodified, c.ishidden, a.page, a.pdfannotatorid";
+ . "GROUP BY a.id, p.name, p.usevotes, cm.id, c.id, c.annotationid, c.content, c.timemodified, c.ishidden, a.page, "
+ . "a.pdfannotatorid";
$params = array_merge([$USER->id, $courseid], $inparams);
@@ -1163,7 +1408,7 @@ function pdfannotator_get_posts_by_this_user($courseid, $context) {
$post->displayhidden = true;
}
- $params = array('id' => $post->cmid, 'page' => $post->page, 'annoid' => $post->annotationid, 'commid' => $post->commid);
+ $params = ['id' => $post->cmid, 'page' => $post->page, 'annoid' => $post->annotationid, 'commid' => $post->commid];
$post->link = (new moodle_url('/mod/pdfannotator/view.php', $params))->out();
$post->content = pdfannotator_get_relativelink($post->content, $post->commid, $context);
$post->content = format_text($post->content, FORMAT_MOODLE);
@@ -1177,7 +1422,7 @@ function pdfannotator_get_posts_by_this_user($courseid, $context) {
* in this course.
*
* @param int $courseid
- * @param Moodle object? $context
+ * @param \context $context the context of the PDF annotator instance
* @param int $answerfilter
* @return array of stdClass objects
*/
@@ -1220,7 +1465,8 @@ function pdfannotator_get_answers_for_this_user($courseid, $context, $answerfilt
. "JOIN {pdfannotator_comments} c ON c.annotationid = a.id " // Answer comment.
. "JOIN {pdfannotator} p ON a.pdfannotatorid = p.id "
. "JOIN {course_modules} cm ON p.id = cm.instance "
- . "WHERE s.userid = ? AND p.course = ? AND q.isquestion = 1 AND NOT c.isquestion = 1 AND NOT c.isdeleted = 1 AND cm.id $insql "
+ . "WHERE s.userid = ? AND p.course = ? AND q.isquestion = 1 AND NOT c.isquestion = 1 AND NOT c.isdeleted = 1 AND "
+ . "cm.id $insql "
. "ORDER BY annoid ASC";
}
@@ -1234,9 +1480,9 @@ function pdfannotator_get_answers_for_this_user($courseid, $context, $answerfilt
continue;
}
$entry->link = (new moodle_url('/mod/pdfannotator/view.php',
- array('id' => $entry->cmid, 'page' => $entry->page, 'annoid' => $entry->annoid, 'commid' => $entry->answerid)))->out();
+ ['id' => $entry->cmid, 'page' => $entry->page, 'annoid' => $entry->annoid, 'commid' => $entry->answerid]))->out();
$entry->questionlink = (new moodle_url('/mod/pdfannotator/view.php',
- array('id' => $entry->cmid, 'page' => $entry->page, 'annoid' => $entry->annoid, 'commid' => $entry->questionid)))->out();
+ ['id' => $entry->cmid, 'page' => $entry->page, 'annoid' => $entry->annoid, 'commid' => $entry->questionid]))->out();
if ($entry->questiondeleted == 1) {
$entry->answeredquestion = get_string('deletedComment', 'pdfannotator');
@@ -1290,8 +1536,13 @@ function pdfannotator_get_answers_for_this_user($courseid, $context, $answerfilt
* Depending on the reportfilter, only read/unread reports or all reports are retrieved.
*
* @param int $courseid
- * @param int $reportfilter: 0 for unread, 1 for read, 2 for all
+ * @param \context $context the context of the PDF annotator instance
+ * @param int $reportfilter 0 for unread, 1 for read, 2 for all
* @return array of report objects
+ * @throws \core\exception\moodle_exception
+ * @throws coding_exception
+ * @throws dml_exception
+ * @throws moodle_exception
*/
function pdfannotator_get_reports($courseid, $context, $reportfilter = 0) {
@@ -1302,7 +1553,8 @@ function pdfannotator_get_reports($courseid, $context, $reportfilter = 0) {
// Retrieve reports from db as an array of stdClass objects, representing a report record each.
$sql = "SELECT r.id as reportid, r.commentid, r.message as report, r.userid AS reportinguser, r.timecreated, r.seen, "
- . "a.page, c.id AS commentid, c.annotationid, c.userid AS commentauthor, c.content AS reportedcomment, c.timecreated AS commenttime, c.visibility, "
+ . "a.page, c.id AS commentid, c.annotationid, c.userid AS commentauthor, c.content AS reportedcomment, "
+ . "c.timecreated AS commenttime, c.visibility, "
. "p.id AS annotatorid, p.name AS pdfannotatorname, cm.id AS cmid, cm.visible AS cmvisible "
. "FROM {pdfannotator_reports} r "
. "JOIN {pdfannotator_comments} c ON r.commentid = c.id "
@@ -1313,16 +1565,17 @@ function pdfannotator_get_reports($courseid, $context, $reportfilter = 0) {
if ($reportfilter != 2) {
$sql = $sql . ' AND r.seen = ?';
- $params = array($courseid, $reportfilter);
+ $params = [$courseid, $reportfilter];
} else {
- $params = array($courseid);
+ $params = [$courseid];
}
$params = array_merge($inparams, $params); // Be careful with order of parameters!
$reports = $DB->get_records_sql($sql, $params);
foreach ($reports as $report) {
$report->link = (new moodle_url('/mod/pdfannotator/view.php',
- array('id' => $report->cmid, 'page' => $report->page, 'annoid' => $report->annotationid, 'commid' => $report->commentid)))->out();
+ ['id' => $report->cmid, 'page' => $report->page, 'annoid' => $report->annotationid,
+ 'commid' => $report->commentid]))->out();
$report->reportedcomment = pdfannotator_get_relativelink($report->reportedcomment, $report->commentid, $context);
$report->reportedcomment = format_text($report->reportedcomment, FORMAT_MOODLE);
$questionid = $DB->get_record('pdfannotator_comments', ['annotationid' => $report->annotationid, 'isquestion' => 1], 'id');
@@ -1337,6 +1590,13 @@ function pdfannotator_get_reports($courseid, $context, $reportfilter = 0) {
*/
class pdfannotator_compare {
+ /**
+ * Function compares two annotators by number of votes in ascending order.
+ *
+ * @param stdClass $a
+ * @param stdClass $b
+ * @return int
+ */
public static function compare_votes_ascending($a, $b) {
if ($a->usevotes == 0 && $b->usevotes == 0 && $a->votes == $b->votes) {
return 0;
@@ -1344,6 +1604,13 @@ public static function compare_votes_ascending($a, $b) {
return ($a->usevotes != 1 || ($a->votes < $b->votes)) ? -1 : 1;
}
+ /**
+ * Function compares two annotators by number of votes in descending order.
+ *
+ * @param stdClass $a
+ * @param stdClass $b
+ * @return int
+ */
public static function compare_votes_descending($a, $b) {
if ($a->usevotes == 0 && $b->usevotes == 0 && $a->votes == $b->votes) {
return 0;
@@ -1351,6 +1618,13 @@ public static function compare_votes_descending($a, $b) {
return ($b->usevotes != 1 || ($a->votes > $b->votes)) ? -1 : 1;
}
+ /**
+ * Function compares two annotators by answer count in ascending order.
+ *
+ * @param stdClass $a
+ * @param stdClass $b
+ * @return int
+ */
public static function compare_answers_ascending($a, $b) {
if ($a->answercount == $b->answercount) {
return 0;
@@ -1358,6 +1632,13 @@ public static function compare_answers_ascending($a, $b) {
return ($a->answercount < $b->answercount) ? -1 : 1;
}
+ /**
+ * Function compares two annotators by number of answers in descending order.
+ *
+ * @param stdClass $a
+ * @param stdClass $b
+ * @return int
+ */
public static function compare_answers_descending($a, $b) {
if ($a->answercount == $b->answercount) {
return 0;
@@ -1365,6 +1646,13 @@ public static function compare_answers_descending($a, $b) {
return ($a->answercount > $b->answercount) ? -1 : 1;
}
+ /**
+ * Function compares two annotators by last modified time in ascending order.
+ *
+ * @param stdClass $a
+ * @param stdClass $b
+ * @return int
+ */
public static function compare_time_ascending($a, $b) {
if ($a->timemodified == $b->timemodified) {
return 0;
@@ -1372,6 +1660,13 @@ public static function compare_time_ascending($a, $b) {
return ($a->timemodified < $b->timemodified) ? -1 : 1;
}
+ /**
+ * Function compares two annotators by last modified time in descending order.
+ *
+ * @param stdClass $a
+ * @param stdClass $b
+ * @return int
+ */
public static function compare_time_descending($a, $b) {
if ($a->timemodified == $b->timemodified) {
return 0;
@@ -1379,6 +1674,13 @@ public static function compare_time_descending($a, $b) {
return ($a->timemodified > $b->timemodified) ? -1 : 1;
}
+ /**
+ * Function compares two annotators by last answer time in ascending order.
+ *
+ * @param stdClass $a
+ * @param stdClass $b
+ * @return int
+ */
public static function compare_lastanswertime_ascending($a, $b) {
if ($a->lastanswered == $b->lastanswered) {
return 0;
@@ -1386,6 +1688,13 @@ public static function compare_lastanswertime_ascending($a, $b) {
return ($a->lastanswered < $b->lastanswered) ? -1 : 1;
}
+ /**
+ * Function compares two annotators by last answer time in descending order.
+ *
+ * @param stdClass $a
+ * @param stdClass $b
+ * @return int
+ */
public static function compare_lastanswertime_descending($a, $b) {
if ($a->lastanswered == $b->lastanswered) {
return 0;
@@ -1393,6 +1702,13 @@ public static function compare_lastanswertime_descending($a, $b) {
return ($a->lastanswered > $b->lastanswered) ? -1 : 1;
}
+ /**
+ * Function compares two annotators by comment time in ascending order.
+ *
+ * @param stdClass $a
+ * @param stdClass $b
+ * @return int
+ */
public static function compare_commenttime_ascending($a, $b) {
if ($a->commenttime == $b->commenttime) {
return 0;
@@ -1400,6 +1716,13 @@ public static function compare_commenttime_ascending($a, $b) {
return ($a->commenttime < $b->commenttime) ? -1 : 1;
}
+ /**
+ * Function compares two annotators by comment time in descending order.
+ *
+ * @param stdClass $a
+ * @param stdClass $b
+ * @return int
+ */
public static function compare_commenttime_descending($a, $b) {
if ($a->commenttime == $b->commenttime) {
return 0;
@@ -1407,6 +1730,13 @@ public static function compare_commenttime_descending($a, $b) {
return ($a->commenttime > $b->commenttime) ? -1 : 1;
}
+ /**
+ * Function compares two annotators by creation time in ascending order.
+ *
+ * @param stdClass $a
+ * @param stdClass $b
+ * @return int
+ */
public static function compare_creationtime_ascending($a, $b) {
if ($a->timecreated == $b->timecreated) {
return 0;
@@ -1414,6 +1744,13 @@ public static function compare_creationtime_ascending($a, $b) {
return ($a->timecreated < $b->timecreated) ? -1 : 1;
}
+ /**
+ * Function compares two annotators by creation time in descending order.
+ *
+ * @param stdClass $a
+ * @param stdClass $b
+ * @return int
+ */
public static function compare_creationtime_descending($a, $b) {
if ($a->timecreated == $b->timecreated) {
return 0;
@@ -1421,6 +1758,13 @@ public static function compare_creationtime_descending($a, $b) {
return ($a->timecreated > $b->timecreated) ? -1 : 1;
}
+ /**
+ * Function compares two annotators alphabetically in ascending order.
+ *
+ * @param stdClass $a
+ * @param stdClass $b
+ * @return int
+ */
public static function compare_alphabetically_ascending($a, $b) {
if ($a->pdfannotatorname == $b->pdfannotatorname) {
return 0;
@@ -1432,6 +1776,13 @@ public static function compare_alphabetically_ascending($a, $b) {
}
}
+ /**
+ * Function compares two annotators alphabetically in descending order.
+ *
+ * @param stdClass $a
+ * @param stdClass $b
+ * @return int
+ */
public static function compare_alphabetically_descending($a, $b) {
if ($a->pdfannotatorname == $b->pdfannotatorname) {
return 0;
@@ -1443,6 +1794,13 @@ public static function compare_alphabetically_descending($a, $b) {
}
}
+ /**
+ * Function compares two questions in ascending order.
+ *
+ * @param stdClass $a
+ * @param stdClass $b
+ * @return int
+ */
public static function compare_question_ascending($a, $b) {
if ($a->answeredquestion == $b->answeredquestion) {
return 0;
@@ -1454,6 +1812,13 @@ public static function compare_question_ascending($a, $b) {
}
}
+ /**
+ * Function compares two questions in descending order.
+ *
+ * @param stdClass $a
+ * @param stdClass $b
+ * @return int
+ */
public static function compare_question_descending($a, $b) {
if ($a->answeredquestion == $b->answeredquestion) {
return 0;
@@ -1503,6 +1868,14 @@ function pdfannotator_sort_entries($questions, $sortcriterium, $sortorder) {
return $questions;
}
+/**
+ * Sorts questions in the overview page according to the selected criterium.
+ *
+ * @param array $questions
+ * @param string $sortcriterium
+ * @param string $sortorder
+ * @return mixed
+ */
function pdfannotator_sort_questions($questions, $sortcriterium, $sortorder) {
switch ($sortcriterium) {
case 'col1':
@@ -1628,6 +2001,10 @@ function pdfannotator_get_first_key_in_array($array) {
* @return mixed
*/
+ /**
+ * Gets the first key of an array
+ * @param array $array
+ */
function array_key_first(array $array) {
if (count($array)) {
reset($array);
@@ -1645,8 +2022,10 @@ function array_key_first(array $array) {
*
* @param array $questions
* @param int $thiscourse
- * @param Moodle url object $url
+ * @param array $urlparams
* @param int $currentpage
+ * @param int $itemsperpage
+ * @param \context $context the context of the PDF annotator instance
*/
function pdfannotator_print_questions($questions, $thiscourse, $urlparams, $currentpage, $itemsperpage, $context) {
@@ -1667,10 +2046,10 @@ function pdfannotator_print_questions($questions, $thiscourse, $urlparams, $curr
// Define flexible table.
$table = new questionstable($url, $showdropdown);
$table->setup();
- // $table->pageable(false);
// Sort the entries of the table according to time or number of votes.
if (!empty($sortinfo = $table->get_sort_columns())) {
- $sortcriterium = pdfannotator_get_first_key_in_array($sortinfo); // Returns the name (e.g. col2) of the column which was clicked for sorting.
+ $sortcriterium = pdfannotator_get_first_key_in_array($sortinfo); // Returns the name (e.g. col2) of the column which was
+ // clicked for sorting.
$sortorder = $sortinfo[$sortcriterium]; // 3 for descending, 4 for ascending.
$questions = pdfannotator_sort_questions($questions, $sortcriterium, $sortorder);
}
@@ -1698,9 +2077,15 @@ function pdfannotator_print_questions($questions, $thiscourse, $urlparams, $curr
* Function prints a table view of all answers to questions the current
* user asked or subscribed to.
*
- * @param int $annotator
- * @param Moodle url object $url
+ * @param array $data
* @param int $thiscourse
+ * @param moodle_url $url Moodle url object
+ * @param int $currentpage
+ * @param int $itemsperpage
+ * @param int $cmid
+ * @param int $answerfilter
+ * @param \context $context the context of the PDF annotator instance
+ * @return void
*/
function pdfannotator_print_answers($data, $thiscourse, $url, $currentpage, $itemsperpage, $cmid, $answerfilter, $context) {
@@ -1712,7 +2097,8 @@ function pdfannotator_print_answers($data, $thiscourse, $url, $currentpage, $ite
// Sort the entries of the table according to time or number of votes.
if (!empty($sortinfo = $table->get_sort_columns())) {
- $sortcriterium = pdfannotator_get_first_key_in_array($sortinfo); // Returns the name (e.g. col2) of the column which was clicked for sorting.
+ $sortcriterium = pdfannotator_get_first_key_in_array($sortinfo); // Returns the name (e.g. col2) of the column which was
+ // clicked for sorting.
$sortorder = $sortinfo[$sortcriterium]; // 3 for descending, 4 for ascending.
$data = pdfannotator_sort_answers($data, $sortcriterium, $sortorder);
}
@@ -1720,7 +2106,8 @@ function pdfannotator_print_answers($data, $thiscourse, $url, $currentpage, $ite
// Add data to the table and print the requested table page.
if ($itemsperpage == -1) { // No pagination.
foreach ($data as $answer) {
- pdfannotator_answerstable_add_row($thiscourse, $table, $answer, $cmid, $currentpage, $itemsperpage, $answerfilter, $context);
+ pdfannotator_answerstable_add_row($thiscourse, $table, $answer, $cmid, $currentpage, $itemsperpage, $answerfilter,
+ $context);
}
} else {
$answercount = count($data);
@@ -1732,7 +2119,8 @@ function pdfannotator_print_answers($data, $thiscourse, $url, $currentpage, $ite
if ($rowstoprint === 0) {
break;
}
- pdfannotator_answerstable_add_row($thiscourse, $table, $answer, $cmid, $currentpage, $itemsperpage, $answerfilter, $context);
+ pdfannotator_answerstable_add_row($thiscourse, $table, $answer, $cmid, $currentpage, $itemsperpage, $answerfilter,
+ $context);
$rowstoprint--;
}
}
@@ -1740,10 +2128,14 @@ function pdfannotator_print_answers($data, $thiscourse, $url, $currentpage, $ite
}
/**
+ * Function prints a table view of all posts that the current user
*
- * @param type $posts
- * @param type $url
- * @param type $thiscourse
+ * @param array $posts
+ * @param int $thiscourse
+ * @param moodle_url $url
+ * @param int $currentpage
+ * @param int $itemsperpage
+ * @return void
*/
function pdfannotator_print_this_users_posts($posts, $thiscourse, $url, $currentpage, $itemsperpage) {
@@ -1755,7 +2147,8 @@ function pdfannotator_print_this_users_posts($posts, $thiscourse, $url, $current
// Sort the entries of the table according to time or number of votes.
if (!empty($sortinfo = $table->get_sort_columns())) {
- $sortcriterium = pdfannotator_get_first_key_in_array($sortinfo); // Returns the name (e.g. col2) of the column which was clicked for sorting.
+ $sortcriterium = pdfannotator_get_first_key_in_array($sortinfo); // Returns the name (e.g. col2) of the column which was
+ // clicked for sorting.
$sortorder = $sortinfo[$sortcriterium]; // 3 for descending, 4 for ascending.
$posts = pdfannotator_sort_entries($posts, $sortcriterium, $sortorder);
}
@@ -1784,10 +2177,14 @@ function pdfannotator_print_this_users_posts($posts, $thiscourse, $url, $current
/**
* Function prints a table view of all comments that were reported as inappropriate.
*
- * @param array of objects $reports
+ * @param array $reports array of objects
* @param int $thiscourse
- * @param Moodle url object $url
+ * @param moodle_url $url Moodle url object
* @param int $currentpage
+ * @param int $itemsperpage
+ * @param int $cmid
+ * @param int $reportfilter
+ * @param \context $context the context of the PDF annotator instance
*/
function pdfannotator_print_reports($reports, $thiscourse, $url, $currentpage, $itemsperpage, $cmid, $reportfilter, $context) {
@@ -1798,14 +2195,16 @@ function pdfannotator_print_reports($reports, $thiscourse, $url, $currentpage, $
$table->setup();
// Sort the entries of the table according to time or number of votes.
if (!empty($sortinfo = $table->get_sort_columns())) {
- $sortcriterium = pdfannotator_get_first_key_in_array($sortinfo); // Returns the name (e.g. col2) of the column which was clicked for sorting.
+ $sortcriterium = pdfannotator_get_first_key_in_array($sortinfo); // Returns the name (e.g. col2) of the column which was
+ // clicked for sorting.
$sortorder = $sortinfo[$sortcriterium]; // 3 for descending, 4 for ascending.
$reports = pdfannotator_sort_reports($reports, $sortcriterium, $sortorder);
}
// Add data to the table and print the requested table page.
if ($itemsperpage == -1) {
foreach ($reports as $report) {
- pdfannotator_reportstable_add_row($thiscourse, $table, $report, $cmid, $itemsperpage, $reportfilter, $currentpage, $context);
+ pdfannotator_reportstable_add_row($thiscourse, $table, $report, $cmid, $itemsperpage, $reportfilter, $currentpage,
+ $context);
}
} else {
$reportcount = count($reports);
@@ -1817,7 +2216,8 @@ function pdfannotator_print_reports($reports, $thiscourse, $url, $currentpage, $
if ($rowstoprint === 0) {
break;
}
- pdfannotator_reportstable_add_row($thiscourse, $table, $report, $cmid, $itemsperpage, $reportfilter, $currentpage, $context);
+ pdfannotator_reportstable_add_row($thiscourse, $table, $report, $cmid, $itemsperpage, $reportfilter, $currentpage,
+ $context);
$rowstoprint--;
}
}
@@ -1831,6 +2231,9 @@ function pdfannotator_print_reports($reports, $thiscourse, $url, $currentpage, $
* @param int $thiscourse
* @param questionstable $table
* @param object $question
+ * @param array $urlparams
+ * @param bool $showdropdown
+ * @return void
*/
function pdfannotator_questionstable_add_row($thiscourse, $table, $question, $urlparams, $showdropdown) {
@@ -1838,14 +2241,16 @@ function pdfannotator_questionstable_add_row($thiscourse, $table, $question, $ur
if ($question->visibility == 'anonymous') {
$author = get_string('anonymous', 'pdfannotator');
} else {
- $author = "userid&course=$thiscourse>" . pdfannotator_get_username($question->userid) . "";
+ $author = "userid&course=$thiscourse>" .
+ pdfannotator_get_username($question->userid) . "";
}
$time = pdfannotator_get_user_datetime_shortformat($question->timecreated);
- if (!empty($question->lastanswered)) { // ! ($question->lastanswered != $question->timecreated) {
+ if (!empty($question->lastanswered)) {
if ($question->lastuservisibility == 'anonymous') {
$lastresponder = get_string('anonymous', 'pdfannotator');
} else {
- $lastresponder = "lastuser&course=$thiscourse>" . pdfannotator_get_username($question->lastuser) . "";
+ $lastresponder = "lastuser&course=$thiscourse>" .
+ pdfannotator_get_username($question->lastuser) . "";
}
$answertime = pdfannotator_timeago($question->lastanswered);
$lastanswered = $lastresponder . "
" . $answertime;
@@ -1859,7 +2264,7 @@ function pdfannotator_questionstable_add_row($thiscourse, $table, $question, $ur
$content = "link class='more'>$question->content";
$pdfannotatorname = $question->pdfannotatorname;
- $data = array($content, $author . '
' . $time, $question->votes, $question->answercount, $lastanswered, $pdfannotatorname);
+ $data = [$content, $author . '
' . $time, $question->votes, $question->answercount, $lastanswered, $pdfannotatorname];
if ($showdropdown) {
$myrenderer = $PAGE->get_renderer('mod_pdfannotator');
@@ -1876,8 +2281,15 @@ function pdfannotator_questionstable_add_row($thiscourse, $table, $question, $ur
* @param int $thiscourse
* @param answerstable $table
* @param object $answer
+ * @param int $cmid
+ * @param int $currentpage
+ * @param int $itemsperpage
+ * @param int $answerfilter
+ * @param \context $context the context of the PDF annotator instance
+ * @return void
*/
-function pdfannotator_answerstable_add_row($thiscourse, $table, $answer, $cmid, $currentpage, $itemsperpage, $answerfilter, $context) {
+function pdfannotator_answerstable_add_row($thiscourse, $table, $answer, $cmid, $currentpage, $itemsperpage, $answerfilter,
+ $context) {
global $CFG, $PAGE;
$answer->answer = pdfannotator_get_relativelink($answer->answer, $answer->answerid, $context);
@@ -1901,7 +2313,8 @@ function pdfannotator_answerstable_add_row($thiscourse, $table, $answer, $cmid,
if ($answer->visibility == 'anonymous') {
$answeredby = get_string('anonymous', 'pdfannotator');
} else {
- $answeredby = "userid&course=$thiscourse>" . pdfannotator_get_username($answer->userid) . "";
+ $answeredby = "userid&course=$thiscourse>" .
+ pdfannotator_get_username($answer->userid) . "";
}
$answertime = pdfannotator_get_user_datetime_shortformat($answer->timemodified);
@@ -1917,9 +2330,11 @@ function pdfannotator_answerstable_add_row($thiscourse, $table, $answer, $cmid,
}
$myrenderer = $PAGE->get_renderer('mod_pdfannotator');
- $dropdown = $myrenderer->render_dropdownmenu(new answermenu($answer->annoid, $issubscribed, $cmid, $currentpage, $itemsperpage, $answerfilter));
+ $dropdown = $myrenderer->render_dropdownmenu(new answermenu($answer->annoid, $issubscribed, $cmid, $currentpage, $itemsperpage,
+ $answerfilter));
- $table->add_data(array($answerlink, $checked, $answeredby . '
' . $answertime, $question, $pdfannotatorname, $dropdown), $classname);
+ $table->add_data([$answerlink, $checked, $answeredby . '
' . $answertime, $question, $pdfannotatorname, $dropdown],
+ $classname);
}
/**
@@ -1938,7 +2353,7 @@ function pdfannotator_userspoststable_add_row($table, $post) {
$classname = 'dimmed_text';
}
$pdfannotatorname = $post->pdfannotatorname;
- $table->add_data(array($content, $time, $post->votes, $pdfannotatorname), $classname);
+ $table->add_data([$content, $time, $post->votes, $pdfannotatorname], $classname);
}
/**
@@ -1952,8 +2367,11 @@ function pdfannotator_userspoststable_add_row($table, $post) {
* @param int $itemsperpage
* @param int $reportfilter
* @param int $currentpage
+ * @param \context $context the context of the PDF annotator instance
+ * @return void
*/
-function pdfannotator_reportstable_add_row($thiscourse, $table, $report, $cmid, $itemsperpage, $reportfilter, $currentpage, $context) {
+function pdfannotator_reportstable_add_row($thiscourse, $table, $report, $cmid, $itemsperpage, $reportfilter, $currentpage,
+ $context) {
global $CFG, $PAGE, $DB;
$questionid = $DB->get_record('pdfannotator_comments', ['annotationid' => $report->annotationid, 'isquestion' => 1], 'id');
$report->report = pdfannotator_get_relativelink($report->report, $questionid, $context);
@@ -1962,9 +2380,11 @@ function pdfannotator_reportstable_add_row($thiscourse, $table, $report, $cmid,
// Prepare report data for display.
$reportid = 'report_' . $report->reportid;
$reportedcommmentlink = "link class='more'>$report->reportedcomment";
- $writtenby = "commentauthor&course=$thiscourse>" . pdfannotator_get_username($report->commentauthor) . "";
+ $writtenby = "commentauthor&course=$thiscourse>" .
+ pdfannotator_get_username($report->commentauthor) . "";
$commenttime = pdfannotator_get_user_datetime_shortformat($report->commenttime);
- $reportedby = "reportinguser&course=$thiscourse>" . pdfannotator_get_username($report->reportinguser) . "";
+ $reportedby = "reportinguser&course=$thiscourse>" .
+ pdfannotator_get_username($report->reportinguser) . "";
$reporttime = pdfannotator_get_user_datetime_shortformat($report->timecreated);
$report->report = "
' . $reporttime, $reportedcommmentlink, $writtenby . '
' . $commenttime, $dropdown), $classname);
+ $table->add_data([$report->report, $reportedby . '
' . $reporttime, $reportedcommmentlink, $writtenby . '
' .
+ $commenttime, $dropdown], $classname);
}
@@ -1990,16 +2411,16 @@ function pdfannotator_reportstable_add_row($thiscourse, $table, $report, $cmid,
* @return string
*/
function pdfannotator_timeago($timestamp) {
- $strtime = array(get_string('second', 'pdfannotator'), get_string('minute', 'pdfannotator'), get_string('hour', 'pdfannotator'));
+ $strtime = [get_string('second', 'pdfannotator'), get_string('minute', 'pdfannotator'), get_string('hour', 'pdfannotator')];
$strtime[] = get_string('day', 'pdfannotator');
$strtime[] = get_string('month', 'pdfannotator');
$strtime[] = get_string('year', 'pdfannotator');
- $strtimeplural = array(get_string('seconds', 'pdfannotator'), get_string('minutes', 'pdfannotator'));
+ $strtimeplural = [get_string('seconds', 'pdfannotator'), get_string('minutes', 'pdfannotator')];
$strtimeplural[] = get_string('hours', 'pdfannotator');
$strtimeplural[] = get_string('days', 'pdfannotator');
$strtimeplural[] = get_string('months', 'pdfannotator');
$strtimeplural[] = get_string('years', 'pdfannotator');
- $length = array("60", "60", "24", "30", "12", "10");
+ $length = ["60", "60", "24", "30", "12", "10"];
$currenttime = time();
if ($currenttime >= $timestamp) {
$diff = time() - $timestamp;
@@ -2024,7 +2445,7 @@ function pdfannotator_timeago($timestamp) {
* and returns this information as a string. If the timestamp is older than 2 days,
* the ecaxt datetime is returned. Otherwise, the string looks like '3 days ago'.
*
- * @param type $timestamp
+ * @param int $timestamp
* @return string
*/
function pdfannotator_optional_timeago($timestamp) {
@@ -2037,20 +2458,39 @@ function pdfannotator_optional_timeago($timestamp) {
}
}
+/**
+ * Function checks whether the current user is using a mobile device.
+ *
+ * @return false|int
+ */
function pdfannotator_is_mobile_device() {
$param = filter_input(INPUT_SERVER, 'HTTP_USER_AGENT', FILTER_DEFAULT); // XXX How to filter, here?
- return preg_match("/(android|avantgo|blackberry|bolt|boost|cricket|docomo|fone|hiptop|mini|mobi|palm|phone|pie|tablet|up\.browser|up\.link|webos|wos)/i", $param);
+ return preg_match("/(android|avantgo|blackberry|bolt|boost|cricket|docomo|fone|hiptop|mini|mobi|palm|phone|pie|tablet|".
+ "up\.browser|up\.link|webos|wos)/i", $param);
}
+/**
+ * Function checks whether the current user is using a mobile phone.
+ *
+ * @return false|int
+ */
function pdfannotator_is_phone() {
$param = filter_input(INPUT_SERVER, 'HTTP_USER_AGENT', FILTER_DEFAULT); // XXX How to filter, here?
- return preg_match("/(android|avantgo|blackberry|bolt|boost|cricket|docomo|fone|hiptop|mini|mobi|palm|phone|pie|tablet|up\.browser|up\.link|webos|wos)/i", $param);
+ return preg_match("/(android|avantgo|blackberry|bolt|boost|cricket|docomo|fone|hiptop|mini|mobi|palm|phone|pie|tablet|".
+ "up\.browser|up\.link|webos|wos)/i", $param);
}
-
+/**
+ * Function returns the last answer to a question with $annotationid.
+ *
+ * @param int $annotationid specifies the annotation (usually a highlight) to be commented
+ * @param \context $context the context of the pdfannotator instance
+ * @return mixed|null
+ * @throws dml_exception
+ */
function pdfannotator_get_last_answer($annotationid, $context) {
global $DB;
- $params = array('isquestion' => 0, 'annotationid' => $annotationid);
+ $params = ['isquestion' => 0, 'annotationid' => $annotationid];
$answers = $DB->get_records('pdfannotator_comments', $params, 'timecreated DESC' );
foreach ($answers as $answer) {
@@ -2064,6 +2504,15 @@ function pdfannotator_get_last_answer($annotationid, $context) {
return null;
}
+/**
+ * Function checks whether the current user can see a comment.
+ *
+ * @param stdClass $comment the comment to be checked
+ * @param \context $context the context of the pdfannotator instance
+ * @return bool
+ * @throws coding_exception
+ * @throws dml_exception
+ */
function pdfannotator_can_see_comment($comment, $context) {
global $USER, $DB;
if (is_array($comment)) {
@@ -2072,7 +2521,7 @@ function pdfannotator_can_see_comment($comment, $context) {
// If the comment is an answer, it is always saved as public. So, we check the visibility of the corresponding question.
if (!$comment->isquestion) {
- $question = $DB->get_record('pdfannotator_comments', array('annotationid' => $comment->annotationid, 'isquestion' => '1'));
+ $question = $DB->get_record('pdfannotator_comments', ['annotationid' => $comment->annotationid, 'isquestion' => '1']);
$question = (object)$question;
} else {
$question = $comment;
@@ -2084,7 +2533,8 @@ function pdfannotator_can_see_comment($comment, $context) {
}
// Protected Comments are only displayed for the author and for the managers.
- if ($question->visibility == "protected" && $USER->id != $question->userid && !has_capability('mod/pdfannotator:viewprotectedcomments', $context)) {
+ if ($question->visibility == "protected" && $USER->id != $question->userid &&
+ !has_capability('mod/pdfannotator:viewprotectedcomments', $context)) {
return false;
}
return true;
@@ -2093,10 +2543,14 @@ function pdfannotator_can_see_comment($comment, $context) {
/**
* Count how many answers has a question with $annotationid
* return only answers that the user can see
+ *
+ * @param int $annotationid specifies the annotation (usually a highlight) to be commented
+ * @param \context $context the context of the pdfannotator instance
+ * @return int the number of answers to the question
*/
function pdfannotator_count_answers($annotationid, $context) {
global $DB;
- $params = array('isquestion' => 0, 'annotationid' => $annotationid);
+ $params = ['isquestion' => 0, 'annotationid' => $annotationid];
$answers = $DB->get_records('pdfannotator_comments', $params);
$count = 0;
diff --git a/mod_form.php b/mod_form.php
index 931ac4e..a989434 100644
--- a/mod_form.php
+++ b/mod_form.php
@@ -21,16 +21,25 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*
*/
-if (!defined('MOODLE_INTERNAL')) {
- die('Direct access to this script is forbidden.'); // It must be included from a Moodle page.
-}
+
+defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/course/moodleform_mod.php');
require_once($CFG->dirroot . '/mod/pdfannotator/lib.php');
require_once($CFG->libdir . '/filelib.php');
+/**
+ * Form definition class for the pdfannotator module.
+ */
class mod_pdfannotator_mod_form extends moodleform_mod {
+ /**
+ * Define the form elements.
+ *
+ * @return void
+ * @throws coding_exception
+ * @throws dml_exception
+ */
public function definition() {
global $CFG, $USER, $COURSE;
@@ -39,7 +48,7 @@ public function definition() {
$mform->addElement('header', 'general', get_string('general', 'form'));
$mform->setType('general', PARAM_TEXT);
- $mform->addElement('text', 'name', get_string('setting_alternative_name', 'pdfannotator'), array('size' => '48'));
+ $mform->addElement('text', 'name', get_string('setting_alternative_name', 'pdfannotator'), ['size' => '48']);
$mform->addHelpButton('name', 'setting_alternative_name', 'pdfannotator');
if (!empty($CFG->formatstringstriptags)) {
$mform->setType('name', PARAM_TEXT);
@@ -61,7 +70,7 @@ public function definition() {
// $fileoptions = array('subdirs' => 0, 'maxbytes' => 0, 'areamaxbytes' => 10485760, 'maxfiles' => 1,
// 'accepted_types' => '.pdf', 'return_types' => 1 | 2);
// FILE_INTERNAL | FILE_EXTERNAL was replaced by 1|2, because moodle doesnt't identify FILE_INTERNAL, FILE_EXTERNAL here.
- $filemanageroptions = array();
+ $filemanageroptions = [];
$filemanageroptions['accepted_types'] = '.pdf';
$filemanageroptions['maxbytes'] = 0;
$filemanageroptions['maxfiles'] = 1; // Upload only one file.
@@ -72,52 +81,52 @@ public function definition() {
$mform->addHelpButton('files', 'setting_fileupload', 'pdfannotator');
$mform->addElement('advcheckbox', 'usevotes', get_string('setting_usevotes', 'pdfannotator'),
- get_string('usevotes', 'pdfannotator'), null, array(0, 1));
+ get_string('usevotes', 'pdfannotator'), null, [0, 1]);
$mform->setType('usevotes', PARAM_BOOL);
$mform->setDefault('usevotes', $config->usevotes);
$mform->addHelpButton('usevotes', 'setting_usevotes', 'pdfannotator');
$mform->addElement('advcheckbox', 'use_studenttextbox', get_string('setting_use_studenttextbox', 'pdfannotator'),
- get_string('use_studenttextbox', 'pdfannotator'), null, array(0, 1));
+ get_string('use_studenttextbox', 'pdfannotator'), null, [0, 1]);
$mform->setType('use_studenttextbox', PARAM_BOOL);
$mform->setDefault('use_studenttextbox', $config->use_studenttextbox);
$mform->addHelpButton('use_studenttextbox', 'setting_use_studenttextbox', 'pdfannotator');
$mform->addElement('advcheckbox', 'use_studentdrawing', get_string('setting_use_studentdrawing', 'pdfannotator'),
- get_string('use_studentdrawing', 'pdfannotator'), null, array(0, 1));
+ get_string('use_studentdrawing', 'pdfannotator'), null, [0, 1]);
$mform->setType('use_studentdrawing', PARAM_BOOL);
$mform->setDefault('use_studentdrawing', $config->use_studentdrawing);
$mform->addHelpButton('use_studentdrawing', 'setting_use_studentdrawing', 'pdfannotator');
// XXX second checkbox or change to select.
$mform->addElement('advcheckbox', 'useprint', get_string('setting_useprint_document', 'pdfannotator'),
- get_string('useprint', 'pdfannotator'), null, array(0, 1));
+ get_string('useprint', 'pdfannotator'), null, [0, 1]);
$mform->setType('useprint', PARAM_BOOL);
$mform->setDefault('useprint', $config->useprint);
$mform->addHelpButton('useprint', 'setting_useprint_document', 'pdfannotator');
$mform->addElement('advcheckbox', 'useprintcomments', get_string('setting_useprint_comments', 'pdfannotator'),
- get_string('useprint_comments', 'pdfannotator'), null, array(0, 1));
+ get_string('useprint_comments', 'pdfannotator'), null, [0, 1]);
$mform->setType('useprintcomments', PARAM_BOOL);
$mform->setDefault('useprintcomments', $config->useprintcomments);
$mform->addHelpButton('useprintcomments', 'setting_useprint_comments', 'pdfannotator');
$mform->addElement('advcheckbox', 'useprivatecomments', get_string('setting_use_private_comments', 'pdfannotator'),
- get_string('use_private_comments', 'pdfannotator'), null, array(0, 1));
+ get_string('use_private_comments', 'pdfannotator'), null, [0, 1]);
$mform->setType('useprivatecomments', PARAM_BOOL);
$mform->setDefault('useprivatecomments', $config->use_private_comments);
$mform->addHelpButton('useprivatecomments', 'setting_use_private_comments', 'pdfannotator');
$mform->addElement('advcheckbox', 'useprotectedcomments', get_string('setting_use_protected_comments', 'pdfannotator'),
- get_string('use_protected_comments', 'pdfannotator'), null, array(0, 1));
+ get_string('use_protected_comments', 'pdfannotator'), null, [0, 1]);
$mform->setType('useprotectedcomments', PARAM_BOOL);
$mform->setDefault('useprotectedcomments', $config->use_protected_comments);
$mform->addHelpButton('useprotectedcomments', 'setting_use_protected_comments', 'pdfannotator');
// Add legacy files flag only if used.
if (isset($this->current->legacyfiles) && $this->current->legacyfiles != RESOURCELIB_LEGACYFILES_NO) {
- $options = array(RESOURCELIB_LEGACYFILES_DONE => get_string('legacyfilesdone', 'pdfannotator'),
- RESOURCELIB_LEGACYFILES_ACTIVE => get_string('legacyfilesactive', 'pdfannotator'));
+ $options = [RESOURCELIB_LEGACYFILES_DONE => get_string('legacyfilesdone', 'pdfannotator'),
+ RESOURCELIB_LEGACYFILES_ACTIVE => get_string('legacyfilesactive', 'pdfannotator')];
$mform->addElement('select', 'legacyfiles', get_string('legacyfiles', 'pdfannotator'), $options);
}
@@ -131,16 +140,31 @@ public function definition() {
}
// Loads the old file in the filemanager.
+
+ /**
+ * Preprocesses the form data before displaying it.
+ *
+ * @param array $defaultvalues
+ * @return void
+ */
public function data_preprocessing(&$defaultvalues) {
if ($this->current->instance) {
$contextid = $this->context->id;
$draftitemid = file_get_submitted_draft_itemid('files');
- file_prepare_draft_area($draftitemid, $contextid, 'mod_pdfannotator', 'content', 0, array('subdirs' => true));
+ file_prepare_draft_area($draftitemid, $contextid, 'mod_pdfannotator', 'content', 0, ['subdirs' => true]);
$defaultvalues['files'] = $draftitemid;
$this->_form->disabledIf('files', 'update', 'notchecked', 2);
}
}
+ /**
+ * Validates the form data.
+ *
+ * @param array $data
+ * @param array $files
+ * @return array
+ * @throws coding_exception
+ */
public function validation($data, $files) {
global $USER;
diff --git a/model/annotation.class.php b/model/annotation.class.php
index 0bf002a..157a6d6 100644
--- a/model/annotation.class.php
+++ b/model/annotation.class.php
@@ -27,17 +27,19 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*
*/
-defined('MOODLE_INTERNAL') || die();
+/**
+ * Class pdfannotator_annotation
+ */
class pdfannotator_annotation {
/**
* This method creates a new record in the database table named mdl_pdfannotator_annotations and returns its id
*
- * @param type $documentid specifies the pdf file to which this annotation belongs
- * @param type $pageid specifies the page within that pdf file
- * @param type $type child class (highlight, strikeout, area, textbox, drawing, comment or point)
- * @param type $itemid identifies the record in the respective child class table, e.g. highlights
+ * @param int $documentid specifies the pdf file to which this annotation belongs
+ * @param int $pageid specifies the page within that pdf file
+ * @param string $type child class (highlight, strikeout, area, textbox, drawing, comment or point)
+ * @param int $itemid identifies the record in the respective child class table, e.g. highlights
* @return int (or boolean false)
*/
public static function create_annotation($documentid, $pageid, $type, $itemid) {
@@ -58,9 +60,9 @@ public static function create_annotation($documentid, $pageid, $type, $itemid) {
* Method updates data attribute (consisting of width, color and lines)
* in mdl_pdfannotator_drawings after a drawing was shifted in position
*
- * @param type $annotationid
- * @param type $newdata
- * @return type int 1 for success
+ * @param int $annotationid
+ * @param array $newdata
+ * @return int 1 for success
*/
public static function update($annotationid, $newdata) {
global $DB, $USER;
@@ -77,7 +79,7 @@ public static function update($annotationid, $newdata) {
}
if ($success) {
- $result = array('status' => 'success', 'timemoved' => $time);
+ $result = ['status' => 'success', 'timemoved' => $time];
if ($annotation->userid != $USER->id) {
$result['movedby'] = pdfannotator_get_username($USER->id);
}
@@ -92,16 +94,16 @@ public static function update($annotationid, $newdata) {
* if the user is allowed to do so.
* Teachers are allowed to delete any comment, students may only delete their own comments.
*
- * @param type $annotationId
- * @param type $cmid
- * @param type $deleteanyway Delete annotation in any case. F.e. if right to be forgotten was invoked or
+ * @param int $annotationid
+ * @param id $cmid
+ * @param bool $deleteanyway Delete annotation in any case. F.e. if right to be forgotten was invoked or
* a user without the capability to delete the annotation deletes it implicitly by deleting the last comment of the annotation
* @return boolean
*/
public static function delete($annotationid, $cmid = null, $deleteanyway = null) {
global $DB;
- $annotation = $DB->get_record('pdfannotator_annotations', array('id' => $annotationid), '*', $strictness = IGNORE_MISSING);
+ $annotation = $DB->get_record('pdfannotator_annotations', ['id' => $annotationid], '*', $strictness = IGNORE_MISSING);
if (!$annotation) {
return false;
}
@@ -113,17 +115,17 @@ public static function delete($annotationid, $cmid = null, $deleteanyway = null)
if ($deletionallowed[0] === true || $deleteanyway === true) {
// Delete all comments of this annotation.
- $comments = $DB->get_records('pdfannotator_comments', array("annotationid" => $annotationid));
+ $comments = $DB->get_records('pdfannotator_comments', ["annotationid" => $annotationid]);
foreach ($comments as $commentdata) {
- $DB->delete_records('pdfannotator_votes', array("commentid" => $commentdata->id));
+ $DB->delete_records('pdfannotator_votes', ["commentid" => $commentdata->id]);
}
- $success = $DB->delete_records('pdfannotator_comments', array("annotationid" => $annotationid));
+ $success = $DB->delete_records('pdfannotator_comments', ["annotationid" => $annotationid]);
// Delete subscriptions to the question.
- $DB->delete_records('pdfannotator_subscriptions', array('annotationid' => $annotationid));
+ $DB->delete_records('pdfannotator_subscriptions', ['annotationid' => $annotationid]);
// Delete the annotation itself.
- $success = $DB->delete_records('pdfannotator_annotations', array("id" => $annotationid));
+ $success = $DB->delete_records('pdfannotator_annotations', ["id" => $annotationid]);
if ($deleteanyway) {
return;
@@ -141,8 +143,11 @@ public static function delete($annotationid, $cmid = null, $deleteanyway = null)
/**
* Method checks whether the annotation as well as possible comments attached to it
- * belong to the current user. *
- * @return
+ * belong to the current user.
+ *
+ * @param stdClass $annotation
+ * @param int $cmid
+ * @return array
*/
public static function deletion_allowed($annotation, $cmid) {
@@ -178,7 +183,8 @@ public static function deletion_allowed($annotation, $cmid) {
* It returns true if the annotation was made by the user who is trying to shift it and no other person has answered
* or if that user is an admin.
*
- * @param type $annotationId
+ * @param int $annotationid
+ * @param context $context
* @return boolean
*/
public static function shifting_allowed($annotationid, $context) {
@@ -192,7 +198,7 @@ public static function shifting_allowed($annotationid, $context) {
if (!$editownpost || $USER->id != self::get_author($annotationid)) {
return false;
} else if ($DB->record_exists_select('pdfannotator_comments', "annotationid = ? AND userid != ?",
- array($annotationid, $USER->id))) {
+ [$annotationid, $USER->id])) {
// Annotation was answered by other users.
return false;
}
@@ -201,7 +207,7 @@ public static function shifting_allowed($annotationid, $context) {
/**
* Return information for the dummy-comment of a textbox or drawing
- * @param type $annotationid
+ * @param int $annotationid
*/
public static function get_information($annotationid) {
global $DB;
@@ -227,6 +233,7 @@ public static function get_information($annotationid) {
}
}
$comment->usevotes = 0;
+ // phpcs:disable moodle.Commenting.TodoComment
$comment->uuid = -1; // TODO.
$comment->annotation = $annotationid;
$comment->isdeleted = 0;
@@ -242,31 +249,31 @@ public static function get_information($annotationid) {
/**
* Method takes an annotation's id and returns the user id of its author
*
- * @param type $itemid
- * @return type
+ * @param int $annotationid
+ * @return array
*/
public static function get_author($annotationid) {
global $DB;
- return $DB->get_field('pdfannotator_annotations', 'userid', array('id' => $annotationid), $strictness = MUST_EXIST);
+ return $DB->get_field('pdfannotator_annotations', 'userid', ['id' => $annotationid], $strictness = MUST_EXIST);
}
/**
* Method takes an annotation's id and returns the page it was made on
*
- * @param type $annotationId
- * @return type
+ * @param int $annotationid
+ * @return array
*/
public static function get_pageid($annotationid) {
global $DB;
- return $DB->get_field('pdfannotator_annotations', 'page', array('id' => $annotationid), $strictness = IGNORE_MISSING);
+ return $DB->get_field('pdfannotator_annotations', 'page', ['id' => $annotationid], $strictness = IGNORE_MISSING);
}
/**
* Method takes an annotation's id and returns the content of the underlying question comment
*
- * @param type $annotationId
- * @return type
+ * @param int $annotationid
+ * @return string
*/
public static function get_question($annotationid) {
global $DB;
diff --git a/model/comment.class.php b/model/comment.class.php
index 5b91e80..27f51ad 100644
--- a/model/comment.class.php
+++ b/model/comment.class.php
@@ -29,15 +29,22 @@
require_once($CFG->dirroot . '/mod/pdfannotator/model/annotation.class.php');
require_once($CFG->dirroot . '/mod/pdfannotator/model/pdfannotator.php');
-
+/**
+ *
+ */
class pdfannotator_comment {
/**
* This method inserts a new record into mdl_pdfannotator_comments and returns its id
*
- * @param type $documentid specifies the pdf
- * @param type $annotationid specifies the annotation (usually a highlight) to be commented
- * @param String $content the text or comment itself
+ * @param int $documentid specifies the pdf
+ * @param int $annotationid specifies the annotation (usually a highlight) to be commented
+ * @param string $content the text or comment itself
+ * @param string $visibility the visibility of the comment, can be 'public', 'private', 'protected' or 'anonymous'
+ * @param int $isquestion specifies if the comment is a question (1) or an answer (0)
+ * @param \cm_info $cm the course module information
+ * @param \context $context the context of the pdfannotator instance
+ * @return array|bool returns the comment object if successful, false otherwise
*/
public static function create($documentid, $annotationid, $content, $visibility, $isquestion, $cm, $context) {
global $DB, $USER, $CFG;
@@ -46,7 +53,7 @@ public static function create($documentid, $annotationid, $content, $visibility,
return false;
}
- $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
+ $course = $DB->get_record('course', ['id' => $cm->course], '*', MUST_EXIST);
// Create a new record in 'pdfannotator_comments'.
$datarecord = new stdClass();
@@ -62,19 +69,20 @@ public static function create($documentid, $annotationid, $content, $visibility,
// Create a new record in the table named 'comments' and return its id, which is created by autoincrement.
$commentuuid = $DB->insert_record('pdfannotator_comments', $datarecord, true);
$datarecord->id = $commentuuid;
-
+
// Get the draftitemid and prepare the draft area.
$draftitemid = required_param('pdfannotator_addcomment_editoritemid', PARAM_INT);
$options = pdfannotator_get_editor_options($context);
- $text = file_save_draft_area_files($draftitemid, $context->id, "mod_pdfannotator", "post", $commentuuid, $options, $datarecord->content, true);
+ $text = file_save_draft_area_files($draftitemid, $context->id, "mod_pdfannotator", "post", $commentuuid,
+ $options, $datarecord->content, true);
$datarecord->content = $text;
$DB->update_record('pdfannotator_comments', $datarecord);
$datarecord->uuid = $commentuuid;
self::set_username($datarecord);
-
+
$datarecord->displaycontent = pdfannotator_get_relativelink($datarecord->content, $datarecord->id, $context);
$datarecord->displaycontent = format_text($datarecord->displaycontent, FORMAT_MOODLE, ['para' => false, 'filter' => true]);
$datarecord->timecreated = pdfannotator_optional_timeago($datarecord->timecreated);
@@ -120,7 +128,7 @@ public static function create($documentid, $annotationid, $content, $visibility,
$question->answeruser = $visibility == 'public' ? fullname($USER) : 'Anonymous';
$question->content = $content;
- $page = $DB->get_field('pdfannotator_annotations', 'page', array('id' => $annotationid), MUST_EXIST);
+ $page = $DB->get_field('pdfannotator_annotations', 'page', ['id' => $annotationid], MUST_EXIST);
$question->urltoanswer = $CFG->wwwroot . '/mod/pdfannotator/view.php?id=' . $cm->id . '&page=' . $page .
'&annoid=' . $annotationid . '&commid=' . $commentuuid;
@@ -147,9 +155,9 @@ public static function create($documentid, $annotationid, $content, $visibility,
/**
* This method returns an array of all comment objects belonging to the specified annotation.
*
- * @param type $documentid
- * @param type $highlightid
- * @param $context
+ * @param int $documentid
+ * @param int $annotationid
+ * @param \context $context
* @return \stdClass
*/
public static function read($documentid, $annotationid, $context) {
@@ -164,7 +172,7 @@ public static function read($documentid, $annotationid, $context) {
. " GROUP BY c.id, c.content, c.userid, c.visibility, c.isquestion, c.isdeleted, c.ishidden, c.timecreated, "
. "c.timemodified, c.modifiedby, c.solved, c.annotationid"
. " ORDER BY c.timecreated";
- $a = array();
+ $a = [];
$a[] = $annotationid;
$comments = $DB->get_records_sql($sql, $a); // Records taken from table 'comments' as an array of objects.
$usevotes = pdfannotator_instance::use_votes($documentid);
@@ -172,7 +180,7 @@ public static function read($documentid, $annotationid, $context) {
$annotation = $DB->get_record('pdfannotator_annotations', ['id' => $annotationid],
$fields = 'timecreated, timemodified, modifiedby', $strictness = MUST_EXIST);
- $result = array();
+ $result = [];
foreach ($comments as $data) {
$comment = new stdClass();
@@ -207,7 +215,8 @@ public static function read($documentid, $annotationid, $context) {
} else {
$comment->content = $data->content;
$comment->displaycontent = pdfannotator_get_relativelink($comment->content, $comment->uuid, $context);
- $comment->displaycontent = format_text($comment->displaycontent, FORMAT_MOODLE, ['para' => false, 'filter' => true]);
+ $comment->displaycontent = format_text($comment->displaycontent, FORMAT_MOODLE, ['para' => false,
+ 'filter' => true]);
}
self::set_username($comment);
@@ -225,7 +234,8 @@ public static function read($documentid, $annotationid, $context) {
/**
* Function sets the username to be passed to JavaScript according to comment visibility
*
- * @param type $comment
+ * @param string $comment
+ * @return void
*/
public static function set_username($comment) {
global $USER;
@@ -253,7 +263,9 @@ public static function set_username($comment) {
/**
* Function serves to hide a comment from participants' view while keeping it visibile for managers/teachers/etc.
*
- * @return type
+ * @param int $commentid
+ * @param int $cmid
+ * @return void
*/
public static function hide_comment($commentid, $cmid) {
@@ -261,7 +273,7 @@ public static function hide_comment($commentid, $cmid) {
$success = 0;
// 1. Is there a comment to hide? Retrieve comment from db (return false if it doesn't exist).
- $comment = $DB->get_record('pdfannotator_comments', array('id' => $commentid), '*', $strictness = IGNORE_MISSING);
+ $comment = $DB->get_record('pdfannotator_comments', ['id' => $commentid], '*', $strictness = IGNORE_MISSING);
if (!$comment) {
echo json_encode(['status' => 'error']);
return;
@@ -286,16 +298,16 @@ public static function hide_comment($commentid, $cmid) {
// But first: Check if the predecessor was already marked as deleted, too and if so, delete it completely.
$sql = "SELECT id, isdeleted, isquestion from {pdfannotator_comments} "
. "WHERE annotationid = ? AND timecreated < ? ORDER BY id DESC";
- $params = array($annotationid, $comment->timecreated);
+ $params = [$annotationid, $comment->timecreated];
$predecessors = $DB->get_records_sql($sql, $params);
foreach ($predecessors as $predecessor) {
if ($predecessor->isdeleted != 0) {
- $workingfine = $DB->delete_records('pdfannotator_comments', array("id" => $predecessor->id));
+ $workingfine = $DB->delete_records('pdfannotator_comments', ["id" => $predecessor->id]);
if ($workingfine != 0) {
$tobedeletedaswell[] = $predecessor->id;
if ($predecessor->isquestion) {
- $hideannotation = 1; // ... $annotationid;
+ $hideannotation = 1; // Refers to $annotationid.
}
}
} else {
@@ -305,7 +317,7 @@ public static function hide_comment($commentid, $cmid) {
}
- $success = $DB->update_record('pdfannotator_comments', array("id" => $commentid, "ishidden" => 1), $bulk = false);
+ $success = $DB->update_record('pdfannotator_comments', ["id" => $commentid, "ishidden" => 1], $bulk = false);
if ($success == 1) {
return ['status' => 'success', 'hideannotation' => $hideannotation, 'wasanswered' => $wasanswered,
@@ -326,7 +338,7 @@ public static function redisplay_comment($commentid, $cmid) {
global $DB;
- $success = $DB->update_record('pdfannotator_comments', array("id" => $commentid, "ishidden" => 0), $bulk = false);
+ $success = $DB->update_record('pdfannotator_comments', ["id" => $commentid, "ishidden" => 0], $bulk = false);
if ($success == 1) {
return ['status' => 'success'];
@@ -338,12 +350,15 @@ public static function redisplay_comment($commentid, $cmid) {
/**
* Deletes a comment.
* If the comment is answered, it will be displayed as deleted comment.
+ *
+ * @param int $commentid
+ * @param int $cmid
*/
public static function delete_comment($commentid, $cmid) {
global $DB, $USER;
$success = 0;
// Retrieve comment from db (return false if it doesn't exist).
- $comment = $DB->get_record('pdfannotator_comments', array('id' => $commentid), '*', $strictness = IGNORE_MISSING);
+ $comment = $DB->get_record('pdfannotator_comments', ['id' => $commentid], '*', $strictness = IGNORE_MISSING);
if (!$comment) {
echo json_encode(['status' => 'error']);
@@ -367,18 +382,18 @@ public static function delete_comment($commentid, $cmid) {
$deleteannotation = 0;
if ($wasanswered) { // If the comment was answered, mark it as deleted for a special display.
- $params = array("id" => $commentid, "isdeleted" => 1);
+ $params = ["id" => $commentid, "isdeleted" => 1];
$success = $DB->update_record('pdfannotator_comments', $params, $bulk = false);
} else { // If not, just delete it.
// But first: Check if the predecessor was already marked as deleted, too and if so, delete it completely.
$sql = "SELECT id, isdeleted, isquestion from {pdfannotator_comments} "
. "WHERE annotationid = ? AND timecreated < ? ORDER BY id DESC";
- $params = array($annotationid, $comment->timecreated);
+ $params = [$annotationid, $comment->timecreated];
$predecessors = $DB->get_records_sql($sql, $params);
foreach ($predecessors as $predecessor) {
if ($predecessor->isdeleted != 0) {
- $workingfine = $DB->delete_records('pdfannotator_comments', array("id" => $predecessor->id));
+ $workingfine = $DB->delete_records('pdfannotator_comments', ["id" => $predecessor->id]);
if ($workingfine != 0) {
$tobedeletedaswell[] = $predecessor->id;
if ($predecessor->isquestion) {
@@ -397,10 +412,10 @@ public static function delete_comment($commentid, $cmid) {
$deleteannotation = $annotationid;
}
- $success = $DB->delete_records('pdfannotator_comments', array("id" => $commentid));
+ $success = $DB->delete_records('pdfannotator_comments', ["id" => $commentid]);
}
// Delete votes to the comment.
- $DB->delete_records('pdfannotator_votes', array("commentid" => $commentid));
+ $DB->delete_records('pdfannotator_votes', ["commentid" => $commentid]);
if ($success == 1) {
return ['status' => 'success', 'wasanswered' => $wasanswered, 'followups' => $tobedeletedaswell,
@@ -410,6 +425,17 @@ public static function delete_comment($commentid, $cmid) {
}
}
+ /**
+ * Updates a comment.
+ *
+ * @param int $commentid
+ * @param stdClass $content
+ * @param bool $editanypost
+ * @param \context $context
+ * @return array|string[]
+ * @throws coding_exception
+ * @throws dml_exception
+ */
public static function update($commentid, $content, $editanypost, $context) {
global $DB, $USER;
$comment = $DB->get_record('pdfannotator_comments', ['id' => $commentid]);
@@ -423,7 +449,8 @@ public static function update($commentid, $content, $editanypost, $context) {
$draftitemid = required_param('pdfannotator_editcomment_editoritemid', PARAM_INT);
$options = pdfannotator_get_editor_options($context);
- $text = file_save_draft_area_files($draftitemid, $context->id, "mod_pdfannotator", "post", $commentid, $options, $content, true);
+ $text = file_save_draft_area_files($draftitemid, $context->id, "mod_pdfannotator", "post",
+ $commentid, $options, $content, true);
$comment->content = $text;
$success = $DB->update_record('pdfannotator_comments', $comment);
@@ -434,7 +461,7 @@ public static function update($commentid, $content, $editanypost, $context) {
if ($success) {
$content = pdfannotator_get_relativelink($comment->content, $comment->id, $context);
$content = format_text($content, $format = FORMAT_MOODLE, $options = ['para' => false, 'filter' => true]);
- $result = array('status' => 'success', 'timemodified' => $time, 'newContent' => $content);
+ $result = ['status' => 'success', 'timemodified' => $time, 'newContent' => $content];
if ($comment->userid != $USER->id) {
$result['modifiedby'] = pdfannotator_get_username($USER->id);
}
@@ -446,7 +473,9 @@ public static function update($commentid, $content, $editanypost, $context) {
/**
* Inserts a vote into the db.
- * @param type $commentid
+ *
+ * @param int $documentid
+ * @param int $commentid
* @return boolean
*/
public static function insert_vote($documentid, $commentid) {
@@ -460,7 +489,7 @@ public static function insert_vote($documentid, $commentid) {
}
// Check comment's existence.
- if (!$DB->record_exists('pdfannotator_comments', array('id' => $commentid))) {
+ if (!$DB->record_exists('pdfannotator_comments', ['id' => $commentid])) {
return false;
}
@@ -476,18 +505,20 @@ public static function insert_vote($documentid, $commentid) {
/**
* Inserts a subscription into the DB.
- * @param type $annotationid
- * @return boolean
+ *
+ * @param int $annotationid
+ * @param \context $context
+ * @return bool
*/
public static function insert_subscription($annotationid, $context) {
global $DB, $USER;
// Check if subscription already exists.
- if ($DB->record_exists('pdfannotator_subscriptions', array('annotationid' => $annotationid, 'userid' => $USER->id))) {
+ if ($DB->record_exists('pdfannotator_subscriptions', ['annotationid' => $annotationid, 'userid' => $USER->id])) {
return false;
}
- $comment = $DB->get_record('pdfannotator_comments', array('annotationid' => $annotationid, 'isquestion' => '1'));
+ $comment = $DB->get_record('pdfannotator_comments', ['annotationid' => $annotationid, 'isquestion' => '1']);
if (!pdfannotator_can_see_comment($comment, $context)) {
return false;
}
@@ -502,13 +533,13 @@ public static function insert_subscription($annotationid, $context) {
/**
* Deletes a subscription.
- * @param type $annotationid
+ * @param int $annotationid
* @return string
*/
public static function delete_subscription($annotationid) {
global $DB, $USER;
- $count = $DB->count_records('pdfannotator_comments', array('annotationid' => $annotationid, 'isquestion' => 0));
- $success = $DB->delete_records('pdfannotator_subscriptions', array('annotationid' => $annotationid, 'userid' => $USER->id));
+ $count = $DB->count_records('pdfannotator_comments', ['annotationid' => $annotationid, 'isquestion' => 0]);
+ $success = $DB->delete_records('pdfannotator_subscriptions', ['annotationid' => $annotationid, 'userid' => $USER->id]);
if (!empty($success)) {
return $count;
}
@@ -517,7 +548,9 @@ public static function delete_subscription($annotationid) {
/**
* Marks a comment as solved. A question will be closed (or opened) and a answer will be marked as correct.
- * @param type $commentid
+ *
+ * @param int $commentid
+ * @param \context $context
* @return boolean
*/
public static function mark_solved($commentid, $context) {
@@ -545,6 +578,13 @@ public static function mark_solved($commentid, $context) {
return $success;
}
+ /**
+ * Returns if a comment is solved.
+ *
+ * @param int $commentid
+ * @return bool
+ * @throws dml_exception
+ */
public static function is_solved($commentid) {
global $DB;
return $DB->record_exists('pdfannotator_comments', ['commentid' => $commentid, 'solved' => 1]);
@@ -552,53 +592,66 @@ public static function is_solved($commentid) {
/**
* Returns if the user already voted a comment.
- * @param type $commentid
- * @return type
+ * @param int $commentid
+ * @return bool
*/
public static function is_voted($commentid) {
global $DB, $USER;
- return $DB->record_exists('pdfannotator_votes', array('commentid' => $commentid, 'userid' => $USER->id));
+ return $DB->record_exists('pdfannotator_votes', ['commentid' => $commentid, 'userid' => $USER->id]);
}
/**
* Returns the number of votes a comment got.
- * @param type $commentid
- * @return type
+ *
+ * @param int $commentid
+ * @return int
*/
public static function get_number_of_votes($commentid) {
global $DB;
- return $DB->count_records('pdfannotator_votes', array('commentid' => $commentid));
+ return $DB->count_records('pdfannotator_votes', ['commentid' => $commentid]);
}
/**
* Returns if the user is subscribed to a question.
- * @param type $annotationid
- * @return type
+ *
+ * @param int $annotationid
+ * @return bool
*/
public static function is_subscribed($annotationid) {
global $DB, $USER;
- return $DB->record_exists('pdfannotator_subscriptions', array('annotationid' => $annotationid, 'userid' => $USER->id));
+ return $DB->record_exists('pdfannotator_subscriptions', ['annotationid' => $annotationid, 'userid' => $USER->id]);
}
/**
* Returns all subscribed users to a question.
- * @param type $annotationid
+ *
+ * @param int $annotationid
* @return arry of userids as strings
*/
public static function get_subscribed_users($annotationid) {
global $DB;
$select = 'annotationid = ?';
- $test = $DB->get_fieldset_select('pdfannotator_subscriptions', 'userid', $select, array($annotationid));
+ $test = $DB->get_fieldset_select('pdfannotator_subscriptions', 'userid', $select, [$annotationid]);
return $test;
}
+ /**
+ * Returns all questions of a page.
+ *
+ * @param int $documentid
+ * @param int $pagenumber
+ * @param \context $context
+ * @return array
+ * @throws coding_exception
+ * @throws dml_exception
+ */
public static function get_questions($documentid, $pagenumber, $context) {
global $DB, $USER;
$displayhidden = has_capability('mod/pdfannotator:seehiddencomments', $context);
// Get all questions of a page with a subselect, where all ids of annotations of one page are selected.
$sql = "SELECT c.* FROM {pdfannotator_comments} c WHERE isquestion = 1 AND annotationid IN "
. "(SELECT id FROM {pdfannotator_annotations} a WHERE a.page = :page AND a.pdfannotatorid = :docid)";
- $questions = $DB->get_records_sql($sql, array('page' => $pagenumber, 'docid' => $documentid));
+ $questions = $DB->get_records_sql($sql, ['page' => $pagenumber, 'docid' => $documentid]);
$ret = [];
foreach ($questions as $question) {
// Private Comments are only displayed for the author.
@@ -623,13 +676,22 @@ public static function get_questions($documentid, $pagenumber, $context) {
return $ret;
}
+ /**
+ * Returns all questions of a document.
+ *
+ * @param int $documentid
+ * @param \context $context
+ * @return array
+ * @throws coding_exception
+ * @throws dml_exception
+ */
public static function get_all_questions($documentid, $context) {
global $DB;
// Get all questions of a page with a subselect, where all ids of annotations of one page are selected.
$sql = "SELECT c.*, a.page FROM {pdfannotator_comments} c "
. "JOIN (SELECT * FROM {pdfannotator_annotations} WHERE pdfannotatorid = :docid) a "
. "ON a.id = c.annotationid WHERE isquestion = 1";
- $questions = $DB->get_records_sql($sql, array('docid' => $documentid));
+ $questions = $DB->get_records_sql($sql, ['docid' => $documentid]);
$ret = [];
foreach ($questions as $question) {
@@ -644,8 +706,10 @@ public static function get_all_questions($documentid, $context) {
/**
* Get all questions in an annotator where a comment contains the pattern
- * @param type $documentid
- * @param type $pattern
+ *
+ * @param int $documentid
+ * @param string $pattern
+ * @param \context $context
*/
public static function get_questions_search($documentid, $pattern, $context) {
global $DB;
diff --git a/model/overviewtable.php b/model/overviewtable.php
index 28d6a5e..cf04e48 100644
--- a/model/overviewtable.php
+++ b/model/overviewtable.php
@@ -25,31 +25,43 @@
defined('MOODLE_INTERNAL') || die;
require_once($CFG->libdir.'/tablelib.php');
+
/**
* A base class for several table classes that are to be displayed on the overview page.
*/
class overviewtable extends flexible_table {
+ // phpcs:disable Generic.CodeAnalysis.UselessOverridingMethod
+ /**
+ * Constructor for the overview table.
+ *
+ * @param string $id The table unique id.
+ */
public function __construct($id) {
parent::__construct($id);
}
+ /**
+ * Sets up the control variables for the table.
+ *
+ * @return void
+ */
public function setup() {
- ($this->set_control_variables(array(
+ ($this->set_control_variables([
TABLE_VAR_SORT => 'sort',
TABLE_VAR_HIDE => 'hide',
TABLE_VAR_SHOW => 'show',
TABLE_VAR_PAGE => 'page', // This is used for pagination in the tables.
- TABLE_VAR_RESET => 'treset'
- )));
+ TABLE_VAR_RESET => 'treset',
+ ]));
parent::setup();
}
/**
* Function wraps text elements with a text class for identification by media queries /
* selective display/hiding.
*
- * @param type $string
- * @return type
+ * @param string $string
+ * @return string
*/
public static function wrap($string) {
return "$string";
@@ -61,14 +73,23 @@ public static function wrap($string) {
*/
class questionstable extends overviewtable {
+ /**
+ * @var string
+ */
private $id = 'mod-pdfannotator-questions';
+ /**
+ * Constructor for the question table.
+ *
+ * @param string $url
+ * @param bool $showdropdown
+ * @throws coding_exception
+ */
public function __construct($url, $showdropdown) {
parent::__construct($this->id);
global $OUTPUT;
- // $this->collapsible(true); // Concerns the tables columns.
$this->define_baseurl($url);
- $columns = array('col0', 'col1', 'col2', 'col3', 'col4', 'col5');
+ $columns = ['col0', 'col1', 'col2', 'col3', 'col4', 'col5'];
if ($showdropdown) {
$columns[] = 'col6'; // Action dropdown menu.
$this->no_sorting('col6');
@@ -83,22 +104,14 @@ public function __construct($url, $showdropdown) {
$this->attributes['id'] = $this->id;
$question = get_string('question', 'pdfannotator');
- // $OUTPUT->pix_icon('i/unlock', '') . self::wrap(get_string('question', 'pdfannotator'));
$whoasked = get_string('by', 'pdfannotator') . ' ' . get_string('on', 'pdfannotator');
- // $OUTPUT->pix_icon('i/user', '') . self::wrap(get_string('by', 'pdfannotator')) . ' ' .
- // $OUTPUT->pix_icon('e/insert_time', '') . self::wrap(get_string('on', 'pdfannotator'));
$votes = "" . ' ' .
$OUTPUT->help_icon('voteshelpicon', 'pdfannotator');
- // "" . self::wrap(get_string('votes', 'pdfannotator')) .
- // ' ' . $OUTPUT->help_icon('voteshelpicon', 'pdfannotator');
$answers = $OUTPUT->pix_icon('t/message', '') . ' ' . $OUTPUT->help_icon('answercounthelpicon', 'pdfannotator');
- // $OUTPUT->pix_icon('t/message', '') . ' ' . self::wrap(get_string('answers', 'pdfannotator'));
$lastanswered = get_string('lastanswered', 'pdfannotator');
- // $OUTPUT->pix_icon('e/insert_time', '') . self::wrap(get_string('lastanswered', 'pdfannotator'));
$document = get_string('pdfannotatorcolumn', 'pdfannotator');
- // "" . self::wrap(get_string('pdfannotatorcolumn', 'pdfannotator'));
- $headers = array($question, $whoasked, $votes, $answers, $lastanswered, $document);
+ $headers = [$question, $whoasked, $votes, $answers, $lastanswered, $document];
if ($showdropdown) {
$this->column_style('col6', 'width', '5%'); // Action dropdown menu.
$actionmenu = get_string('overviewactioncolumn', 'pdfannotator');
@@ -121,14 +134,22 @@ public function __construct($url, $showdropdown) {
*/
class answerstable extends overviewtable {
+ /**
+ * @var string
+ */
private $id = 'mod-pdfannotator-answers';
+ /**
+ * Constructor for the answer table.
+ *
+ * @param string $url
+ * @throws coding_exception
+ */
public function __construct($url) {
parent::__construct($this->id);
global $OUTPUT;
- // $this->collapsible(true); // Concerns the tables columns.
$this->define_baseurl($url);
- $this->define_columns(array('col0', 'col1', 'col2', 'col3', 'col4', 'col5'));
+ $this->define_columns(['col0', 'col1', 'col2', 'col3', 'col4', 'col5']);
$this->column_style('col0', 'width', '30%'); // Answer.
$this->column_style('col1', 'width', '5%'); // Marked as correct?
$this->column_style('col2', 'width', '20%'); // Who gave the answer and when.
@@ -137,19 +158,12 @@ public function __construct($url) {
$this->column_style('col5', 'width', '10%'); // Action dropdown menu.
$this->attributes['id'] = $this->id;
$answer = get_string('answer', 'pdfannotator');
- // $OUTPUT->pix_icon('t/message', '') . self::wrap(get_string('answer', 'pdfannotator'));
$iscorrect = $OUTPUT->pix_icon('t/check', '') . ' ' . $OUTPUT->help_icon('iscorrecthelpicon', 'pdfannotator');
- // . get_string('correct', 'pdfannotator');
$whoanswered = get_string('by', 'pdfannotator') . ' ' . get_string('on', 'pdfannotator');
- // $OUTPUT->pix_icon('i/user', '') . self::wrap(get_string('by', 'pdfannotator')) . ' ' .
- // $OUTPUT->pix_icon('e/insert_time', '') . self::wrap(get_string('on', 'pdfannotator'));
$question = get_string('myquestion', 'pdfannotator');
- // $OUTPUT->pix_icon('i/email', '') . self::wrap(get_string('myquestion', 'pdfannotator'));
$document = get_string('pdfannotatorcolumn', 'pdfannotator');
- // "" . self::wrap(get_string('pdfannotatorcolumn', 'pdfannotator'));
$actionmenu = get_string('overviewactioncolumn', 'pdfannotator');
- // $OUTPUT->pix_icon('i/settings', '') . self::wrap(get_string('overviewactioncolumn', 'pdfannotator'));
- $this->define_headers(array($answer, $iscorrect, $whoanswered, $question, $document, $actionmenu));
+ $this->define_headers([$answer, $iscorrect, $whoanswered, $question, $document, $actionmenu]);
$this->no_sorting('col1');
$this->no_sorting('col0');
$this->no_sorting('col5');
@@ -163,30 +177,33 @@ public function __construct($url) {
*/
class userspoststable extends overviewtable {
+ /**
+ * @var string
+ */
private $id = 'mod-pdfannotator-ownposts';
+ /**
+ * Constructor for the user's posts table.
+ *
+ * @param string $url
+ * @throws coding_exception
+ */
public function __construct($url) {
parent::__construct($this->id);
global $OUTPUT;
- // $this->collapsible(true); // Concerns the tables columns.
$this->define_baseurl($url);
- $this->define_columns(array('col0', 'col1', 'col2', 'col3'));
+ $this->define_columns(['col0', 'col1', 'col2', 'col3']);
$this->column_style('col0', 'width', '60%'); // The user's post.
$this->column_style('col1', 'width', '18%'); // Time of last modification.
$this->column_style('col2', 'width', '7%'); // Number of votes for this post.
$this->column_style('col3', 'width', '15%'); // Annotator in which they posted it.
$this->attributes['id'] = $this->id;
$mypost = get_string('mypost', 'pdfannotator');
- // $OUTPUT->pix_icon('t/message', '') . self::wrap(get_string('mypost', 'pdfannotator'));
$lastedited = get_string('lastedited', 'pdfannotator');
- // $OUTPUT->pix_icon('e/insert_time', '') . self::wrap(get_string('lastedited', 'pdfannotator'));
$votes = "" . ' ' .
$OUTPUT->help_icon('voteshelpicontwo', 'pdfannotator');
- // "" . self::wrap(get_string('votes', 'pdfannotator')). ' ' .
- // $OUTPUT->help_icon('voteshelpicon', 'pdfannotator');
$document = get_string('pdfannotatorcolumn', 'pdfannotator');
- // "" . self::wrap(get_string('pdfannotatorcolumn', 'pdfannotator'));
- $this->define_headers(array($mypost, $lastedited, $votes, $document));
+ $this->define_headers([$mypost, $lastedited, $votes, $document]);
$this->no_sorting('col0');
$this->sortable(true, 'col2', SORT_ASC);
$this->sortable(true, 'col3', SORT_DESC);
@@ -198,13 +215,22 @@ public function __construct($url) {
*/
class reportstable extends overviewtable {
+ /**
+ * @var string
+ */
private $id = 'mod-pdfannotator-reports';
+ /**
+ * Constructor for the reports table.
+ *
+ * @param string $url
+ * @throws coding_exception
+ */
public function __construct($url) {
parent::__construct($this->id);
global $OUTPUT;
$this->define_baseurl($url);
- $this->define_columns(array('col0', 'col1', 'col2', 'col3', 'col4'));
+ $this->define_columns(['col0', 'col1', 'col2', 'col3', 'col4']);
$this->column_style('col0', 'width', '25%'); // Reported comment.
$this->column_style('col1', 'width', '20%'); // Who wrote it when.
$this->column_style('col2', 'width', '25%'); // Report.
@@ -212,18 +238,11 @@ public function __construct($url) {
$this->column_style('col4', 'width', '10%'); // Action dropdown menu.
$this->attributes['id'] = $this->id;
$report = get_string('report', 'pdfannotator');
- // $OUTPUT->pix_icon('i/email', '') . self::wrap(get_string('report', 'pdfannotator'));
$reportedby = get_string('by', 'pdfannotator'). ' '. get_string('on', 'pdfannotator');
- // $OUTPUT->pix_icon('i/user', '') . self::wrap(get_string('by', 'pdfannotator')) . ' ' .
- // $OUTPUT->pix_icon('e/insert_time', '') . self::wrap(get_string('on', 'pdfannotator'));
$reportedcomment = get_string('reportedcomment', 'pdfannotator');
- // $OUTPUT->pix_icon('i/flagged', '') . self::wrap(get_string('reportedcomment', 'pdfannotator'));
$writtenby = get_string('by', 'pdfannotator') . ' ' . get_string('on', 'pdfannotator');
- // $OUTPUT->pix_icon('i/user', '') . self::wrap(get_string('by', 'pdfannotator')) . ' ' .
- // $OUTPUT->pix_icon('e/insert_time', '') . self::wrap(get_string('on', 'pdfannotator'));
$actionmenu = get_string('overviewactioncolumn', 'pdfannotator');
- // $OUTPUT->pix_icon('i/settings', '') . self::wrap(get_string('overviewactioncolumn', 'pdfannotator'));
- $this->define_headers(array($report, $reportedby, $reportedcomment, $writtenby, $actionmenu));
+ $this->define_headers([$report, $reportedby, $reportedcomment, $writtenby, $actionmenu]);
$this->no_sorting('col0');
$this->no_sorting('col2');
$this->no_sorting('col4');
diff --git a/model/pdfannotator.php b/model/pdfannotator.php
index 7e75b48..ce1a80c 100644
--- a/model/pdfannotator.php
+++ b/model/pdfannotator.php
@@ -31,26 +31,58 @@
*/
class pdfannotator_instance {
+ /**
+ * @var int
+ */
private $id;
+ /**
+ * @var cm_info
+ */
private $coursemodule;
+ /**
+ * @var string
+ */
private $name;
+ /**
+ * @var array
+ */
private $answers; // Questions asked by the current users.
+ /**
+ * @var array
+ */
private $unsolvedquestions;
+ /**
+ * @var array
+ */
private $reports;
+ /**
+ * @var array
+ */
private $userposts;
+ /**
+ * @var array
+ */
private $hiddenanswers;
+ /**
+ * @var array
+ */
private $hiddenreports;
+ /**
+ * Constructor for the pdfannotator class.
+ *
+ * @param stdClass $dbrecord
+ */
public function __construct($dbrecord) {
$this->id = $dbrecord->id;
$this->coursemodule = $dbrecord->coursemodule;
$this->name = $dbrecord->name;
- $this->answers = array();
- $this->reports = array();
- $this->unsolvedquestions = array();
- $this->userposts = array();
- $this->hiddenanswers = array();
- $this->hiddenreports = array();
+ $this->answers = [];
+ $this->reports = [];
+ $this->unsolvedquestions = [];
+ $this->userposts = [];
+ $this->hiddenanswers = [];
+ $this->hiddenreports = [];
}
/* * **************************** static methods ***************************** */
@@ -59,8 +91,8 @@ public function __construct($dbrecord) {
* This method returns an array containing one pdfannotator_instance object
* for each annotator in the specified course.
*
- * @param type $courseid
- * @param type $beginwith optional parameter that specifies the (current) pdfannotator that should come first in the list
+ * @param int $courseid
+ * @param int $beginwith optional parameter that specifies the (current) pdfannotator that should come first in the list
* @return \pdfannotator_instance: array of pdfannotator_instance objects
*/
public static function get_pdfannotator_instances($courseid, $beginwith = null) {
@@ -70,7 +102,7 @@ public static function get_pdfannotator_instances($courseid, $beginwith = null)
$course = get_course($courseid);
$result = get_all_instances_in_course('pdfannotator', $course);
- $pdfannotatorlist = array();
+ $pdfannotatorlist = [];
foreach ($result as $pdfannotator) {
$pdfannotatorlist[] = new pdfannotator_instance($pdfannotator);
@@ -90,9 +122,17 @@ public static function get_pdfannotator_instances($courseid, $beginwith = null)
return $pdfannotatorlist;
}
+ /**
+ * Returns an array containing information about the course modules
+ *
+ * @param int $courseid
+ * @return array
+ * @throws dml_exception
+ * @throws moodle_exception
+ */
public static function get_cm_info($courseid) {
global $USER;
- $info = array();
+ $info = [];
$userid = $USER->id;
$course = get_course($courseid);
@@ -102,7 +142,7 @@ public static function get_cm_info($courseid) {
foreach ($instances as $instance) {
$cmid = $instance->coursemodule;
$cm = $modinfo->get_cm($cmid);
- $cminfo = array();
+ $cminfo = [];
$cminfo['visible'] = $cm->visible;
$cminfo['availableinfo'] = $cm->availableinfo;
$info[$cmid] = $cminfo;
@@ -110,21 +150,47 @@ public static function get_cm_info($courseid) {
return $info;
}
+ /**
+ * Checks if the pdfannotator instance with the given document ID uses votes.
+ *
+ * @param int $documentid
+ * @return bool
+ * @throws dml_exception
+ */
public static function use_votes($documentid) {
global $DB;
- return $DB->record_exists('pdfannotator', array('id' => $documentid, 'usevotes' => '1'));
+ return $DB->record_exists('pdfannotator', ['id' => $documentid, 'usevotes' => '1']);
}
/* * **************************** (attribute) getter methods ***************************** */
+ /**
+ * Returns the ID of the pdfannotator instance.
+ *
+ * @return mixed
+ */
public function get_id() {
return $this->id;
}
+ /**
+ * Returns the name of the pdfannotator instance.
+ *
+ * @return mixed
+ */
public function get_name() {
return $this->name;
}
+ /**
+ * Returns the conversations of the pdfannotator instance.
+ *
+ * @param int $pdfannotatorid
+ * @param context $context
+ * @return array|int
+ * @throws coding_exception
+ * @throws dml_exception
+ */
public static function get_conversations($pdfannotatorid, $context) {
global $DB;
@@ -137,7 +203,7 @@ public static function get_conversations($pdfannotatorid, $context) {
. "ORDER BY a.page ASC";
try {
- $questions = $DB->get_records_sql($sql, array($pdfannotatorid));
+ $questions = $DB->get_records_sql($sql, [$pdfannotatorid]);
} catch (Exception $ex) {
return -1;
}
@@ -163,7 +229,7 @@ public static function get_conversations($pdfannotatorid, $context) {
. "WHERE c.pdfannotatorid = ? AND c.annotationid = ? AND NOT c.isquestion = 1 AND NOT c.isdeleted = 1";
try {
- $answers = $DB->get_records_sql($sql, array($pdfannotatorid, $question->annoid));
+ $answers = $DB->get_records_sql($sql, [$pdfannotatorid, $question->annoid]);
} catch (Exception $ex) {
return -1;
}
diff --git a/model/statistics.class.php b/model/statistics.class.php
index 7d3ee1e..369a222 100644
--- a/model/statistics.class.php
+++ b/model/statistics.class.php
@@ -16,24 +16,44 @@
/**
* Defining class for statistics tab
+ *
* @package mod_pdfannotator
* @copyright 2018 RWTH Aachen (see README.md)
* @author Friederike Schwager
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*
*/
-defined('MOODLE_INTERNAL') || die();
/**
* This class contains functions returning the data for the statistics-tab
*/
class pdfannotator_statistics {
+ /**
+ * @var int
+ */
private $courseid;
+ /**
+ * @var int
+ */
private $annotatorid;
+ /**
+ * @var int
+ */
private $userid;
+ /**
+ * @var false|mixed
+ */
private $isteacher;
+ /**
+ * Constructor for the statistics class.
+ *
+ * @param int $courseid
+ * @param int $annotatorid
+ * @param int $userid
+ * @param bool $isteacher
+ */
public function __construct($courseid, $annotatorid, $userid, $isteacher = false) {
$this->annotatorid = $annotatorid;
$this->courseid = $courseid;
@@ -43,14 +63,15 @@ public function __construct($courseid, $annotatorid, $userid, $isteacher = false
/**
* Returns the number of questions/answers in one PDF-Annotator by one/all users
- * @param type $isquestion '1' for questions, '0' for answers
- * @param type $user false by default for comments by all users. True for comments by the user
- * @return type
+ *
+ * @param int $isquestion '1' for questions, '0' for answers
+ * @param user $user false by default for comments by all users. True for comments by the user
+ * @return int
*/
public function get_comments_annotator($isquestion, $user = false) {
global $DB;
- $conditions = array('pdfannotatorid' => $this->annotatorid, 'isquestion' => $isquestion, 'isdeleted' => '0');
+ $conditions = ['pdfannotatorid' => $this->annotatorid, 'isquestion' => $isquestion, 'isdeleted' => '0'];
if ($user) {
$conditions['userid'] = $this->userid;
}
@@ -60,9 +81,10 @@ public function get_comments_annotator($isquestion, $user = false) {
/**
* Returns the number of questions/answers in all PDF-Annotators in one course by one/all users
- * @param type $isquestion '1' for questions, '0' for answers
- * @param type $user false by default for comments by all users. userid for comments by a specific user
- * @return type
+ *
+ * @param int $isquestion '1' for questions, '0' for answers
+ * @param user $user false by default for comments by all users. userid for comments by a specific user
+ * @return int
*/
public function get_comments_course($isquestion, $user = false) {
global $DB;
@@ -71,13 +93,14 @@ public function get_comments_course($isquestion, $user = false) {
if ($user) {
$sql .= " AND c.userid = ?";
}
- return $DB->count_records_sql($sql, array($this->courseid, $isquestion, '0', $this->userid));
+ return $DB->count_records_sql($sql, [$this->courseid, $isquestion, '0', $this->userid]);
}
/**
* Returns the average number of questions/answers a user wrote in this pdf-annotator.
* Only users that wrote at least one comment are included.
- * @param type $isquestion '1' for questions, '0' for answers
+ *
+ * @param int $isquestion '1' for questions, '0' for answers
* @return float
*/
public function get_comments_average_annotator($isquestion) {
@@ -87,13 +110,14 @@ public function get_comments_average_annotator($isquestion) {
. "WHERE pdfannotatorid = ? AND isquestion = ? AND isdeleted = ? "
. "GROUP BY userid ) AS counts";
- return (float) key($DB->get_records_sql($sql, array($this->annotatorid, $isquestion, '0')));
+ return (float) key($DB->get_records_sql($sql, [$this->annotatorid, $isquestion, '0']));
}
/**
* Returns the average number of questions/answers a user wrote in this course.
* Only users that wrote at least one comment are included.
- * @param type $isquestion '1' for questions, '0' for answers
+ *
+ * @param int $isquestion '1' for questions, '0' for answers
* @return float
*/
public function get_comments_average_course($isquestion) {
@@ -104,66 +128,69 @@ public function get_comments_average_course($isquestion) {
. "WHERE a.course = ? AND a.id = c.pdfannotatorid AND c.isquestion = ? AND c.isdeleted = ? "
. "GROUP BY c.userid ) AS counts";
- return (float) key($DB->get_records_sql($sql, array($this->courseid, $isquestion, '0')));
+ return (float) key($DB->get_records_sql($sql, [$this->courseid, $isquestion, '0']));
}
/**
* Returns the number of reported comments in this annotator.
- * @return type
+ *
+ * @return int
*/
public function get_reports_annotator() {
global $DB;
- return $DB->count_records('pdfannotator_reports', array('pdfannotatorid' => $this->annotatorid));
+ return $DB->count_records('pdfannotator_reports', ['pdfannotatorid' => $this->annotatorid]);
}
/**
* Returns the number of reported comments in this course.
- * @return type
+ *
+ * @return int
*/
public function get_reports_course() {
global $DB;
- return $DB->count_records('pdfannotator_reports', array('courseid' => $this->courseid));
+ return $DB->count_records('pdfannotator_reports', ['courseid' => $this->courseid]);
}
/**
* Returns the data for the tabl in the statistics-tab
+ *
* @return array
*/
public function get_tabledata() {
$ret = [];
- $ret[] = array('row' => array(get_string('all_questions', 'pdfannotator'),
- $this->get_comments_annotator('1'), $this->get_comments_course('1')));
- $ret[] = array('row' => array(get_string('myquestions', 'pdfannotator'),
- $this->get_comments_annotator('1', true), $this->get_comments_course('1', true)));
- $ret[] = array('row' => array(get_string('average_questions', 'pdfannotator') .
+ $ret[] = ['row' => [get_string('all_questions', 'pdfannotator'),
+ $this->get_comments_annotator('1'), $this->get_comments_course('1')]];
+ $ret[] = ['row' => [get_string('myquestions', 'pdfannotator'),
+ $this->get_comments_annotator('1', true), $this->get_comments_course('1', true)]];
+ $ret[] = ['row' => [get_string('average_questions', 'pdfannotator') .
'' , round($this->get_comments_average_annotator('1'), 2),
- round($this->get_comments_average_course('1'), 2)));
- $ret[] = array('row' => array(get_string('all_answers', 'pdfannotator'),
- $this->get_comments_annotator('0'), $this->get_comments_course('0')));
- $ret[] = array('row' => array(get_string('myanswers', 'pdfannotator'),
- $this->get_comments_annotator('0', true), $this->get_comments_course('0', true)));
- $ret[] = array('row' => array(get_string('average_answers', 'pdfannotator') .
+ round($this->get_comments_average_course('1'), 2)]];
+ $ret[] = ['row' => [get_string('all_answers', 'pdfannotator'),
+ $this->get_comments_annotator('0'), $this->get_comments_course('0')]];
+ $ret[] = ['row' => [get_string('myanswers', 'pdfannotator'),
+ $this->get_comments_annotator('0', true), $this->get_comments_course('0', true)]];
+ $ret[] = ['row' => [get_string('average_answers', 'pdfannotator') .
'', round($this->get_comments_average_annotator('0'), 2),
- round($this->get_comments_average_course('0'), 2)));
- $ret[] = array('row' => array(get_string('private_comments', 'pdfannotator'),
+ round($this->get_comments_average_course('0'), 2)]];
+ $ret[] = ['row' => [get_string('private_comments', 'pdfannotator'),
$this->count_private_comments($this->annotatorid, 0) + $this->count_private_comments($this->annotatorid, 1),
- $this->count_private_comments_in_course()));
- $ret[] = array('row' => array(get_string('protected_comments', 'pdfannotator'),
+ $this->count_private_comments_in_course()]];
+ $ret[] = ['row' => [get_string('protected_comments', 'pdfannotator'),
$this->count_protected_comments($this->annotatorid, 1) + $this->count_protected_comments($this->annotatorid, 0),
- $this->count_protected_comments_in_course()));
+ $this->count_protected_comments_in_course()]];
if ($this->isteacher) {
- $ret[] = array('row' => array(get_string('reports', 'pdfannotator'), $this->get_reports_annotator(),
- $this->get_reports_course()));
+ $ret[] = ['row' => [get_string('reports', 'pdfannotator'), $this->get_reports_annotator(),
+ $this->get_reports_course()]];
}
return $ret;
@@ -171,8 +198,8 @@ public function get_tabledata() {
/**
* Returns the data for the chart in the statistics-tab.
- * @param type $pdfannotators
- * @return type
+ *
+ * @return array
*/
public function get_chartdata() {
@@ -216,22 +243,25 @@ public function get_chartdata() {
$names[] = $pdfannotator->get_name();
}
- $ret = array($names, $otherquestions, $myquestions, $otheranswers, $myanswers, $otherprivate, $myprivate,
- $otherprotectedquestions, $myprotectedquestions, $otherprotectedanswers, $myprotectedanswers);
+ $ret = [$names, $otherquestions, $myquestions, $otheranswers, $myanswers, $otherprivate, $myprivate,
+ $otherprotectedquestions, $myprotectedquestions, $otherprotectedanswers, $myprotectedanswers];
return $ret;
}
/**
+ * Count comments in one PDF-Annotator by one/all users.
+ *
* Returns the number of all questions/answers in one PDF-Annotator by one/all users
- * @param type $annotatorid
- * @param type $isquestion '1' for questions, '0' for answers
- * @param type $userid false by default for comments by all users. Userid for comments by a specific user
+ *
+ * @param int $annotatorid
+ * @param int $isquestion '1' for questions, '0' for answers
+ * @param int $userid false by default for comments by all users. Userid for comments by a specific user
* @return float
*/
public static function count_comments_annotator($annotatorid, $isquestion, $userid = false) {
global $DB;
- $conditions = array('pdfannotatorid' => $annotatorid, 'isquestion' => $isquestion, 'isdeleted' => '0');
+ $conditions = ['pdfannotatorid' => $annotatorid, 'isquestion' => $isquestion, 'isdeleted' => '0'];
if ($userid) {
$conditions['userid'] = $userid;
}
@@ -241,6 +271,10 @@ public static function count_comments_annotator($annotatorid, $isquestion, $user
/**
* Count private comments for annotator.
+ *
+ * @param int $annotatorid
+ * @param bool $isquestion
+ * @param int $userid
*/
public function count_private_comments($annotatorid, $isquestion, $userid=false) {
global $DB;
@@ -267,6 +301,15 @@ public function count_private_comments($annotatorid, $isquestion, $userid=false)
return $count;
}
+ /**
+ * Count protected comments for annotator.
+ *
+ * @param int $annotatorid
+ * @param bool $isquestion
+ * @param int $userid
+ * @return int
+ * @throws dml_exception
+ */
public function count_protected_comments($annotatorid, $isquestion, $userid=false) {
global $DB;
if ($isquestion) {
@@ -293,18 +336,30 @@ public function count_protected_comments($annotatorid, $isquestion, $userid=fals
}
+ /**
+ * Count private comments in course.
+ *
+ * @return int
+ * @throws dml_exception
+ */
public function count_private_comments_in_course() {
global $DB;
$sql = "SELECT COUNT(*) FROM {pdfannotator_comments} c JOIN {pdfannotator} a ON "
. "a.course = ? AND a.id = c.pdfannotatorid WHERE c.visibility = ? AND c.isdeleted = ?";
- return $DB->count_records_sql($sql, array($this->courseid, "private", '0'));
+ return $DB->count_records_sql($sql, [$this->courseid, "private", '0']);
}
+ /**
+ * Count protected comments in course.
+ *
+ * @return int
+ * @throws dml_exception
+ */
public function count_protected_comments_in_course() {
global $DB;
$sql = "SELECT COUNT(*) FROM {pdfannotator_comments} c JOIN {pdfannotator} a ON "
. "a.course = ? AND a.id = c.pdfannotatorid WHERE c.visibility = ? AND c.isdeleted = ?";
- return $DB->count_records_sql($sql, array($this->courseid, "protected", '0'));
+ return $DB->count_records_sql($sql, [$this->courseid, "protected", '0']);
}
}
diff --git a/renderable.php b/renderable.php
index abd08d5..7078308 100644
--- a/renderable.php
+++ b/renderable.php
@@ -28,12 +28,30 @@
require_once('model/comment.class.php');
+/**
+ *
+ */
class pdfannotator_comment_info implements renderable {
+ /**
+ * @var string
+ */
public $pdfname;
+ /**
+ * @var int
+ */
public $page;
+ /**
+ * @var int
+ */
public $datetime;
+ /**
+ * @var string
+ */
public $author;
+ /**
+ * @var string
+ */
public $content;
/**
diff --git a/renderer.php b/renderer.php
index ad4b705..58b4f5a 100644
--- a/renderer.php
+++ b/renderer.php
@@ -16,28 +16,34 @@
/**
* Renderer file
+ *
* @package mod_pdfannotator
* @copyright 2018 RWTH Aachen (see README.md)
* @author Rabea de Groot and Anna Heynkes
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*
*/
-defined('MOODLE_INTERNAL') || die();
+/**
+ * Renderer class for the pdfannotator module.
+ */
class mod_pdfannotator_renderer extends plugin_renderer_base {
/**
+ * Renders the pdfannotator overview page.
*
- * @param type $index
- * @return type
+ * @param stdClass $index
+ * @return bool|string
*/
public function render_index($index) {
return $this->render_from_template('pdfannotator/index', $index->export_for_template($this));
}
+
/**
+ * Renders the statistics of the pdfannotator module.
*
* @param \templatable $statistic
- * @return type
+ * @return bool|string
*/
public function render_statistic(\templatable $statistic) {
$data = $statistic->export_for_template($this);
@@ -45,9 +51,11 @@ public function render_statistic(\templatable $statistic) {
}
/**
- * renders dropdown-actionmenu. Currently used on overview in the categories "answers" and "reports".
- * @param \templatable $dropdownmenu
- * @return type
+ * Renders dropdown-actionmenu. Currently used on overview in the categories "answers" and "reports".
+ *
+ * @param templatable $dropdownmenu
+ * @return bool|string
+ * @throws \core\exception\moodle_exception
*/
public function render_dropdownmenu(\templatable $dropdownmenu) {
$data = $dropdownmenu->export_for_template($this);
@@ -70,19 +78,19 @@ public function render_pdfannotator_comment_info(pdfannotator_comment_info $info
$row = new html_table_row();
$cell1 = new html_table_cell(get_string('slotdatetimelabel', 'pdfannotator'));
$cell2 = $info->datetime;
- $row->cells = array($cell1, $cell2);
+ $row->cells = [$cell1, $cell2];
$t->data[] = $row;
$row = new html_table_row();
$cell1 = new html_table_cell(get_string('author', 'pdfannotator'));
$cell2 = new html_table_cell($info->author);
- $row->cells = array($cell1, $cell2);
+ $row->cells = [$cell1, $cell2];
$t->data[] = $row;
$row = new html_table_row();
$cell1 = new html_table_cell(get_string('comment', 'pdfannotator'));
$cell2 = new html_table_cell($info->content);
- $row->cells = array($cell1, $cell2);
+ $row->cells = [$cell1, $cell2];
$t->data[] = $row;
$o .= html_writer::table($t);
@@ -90,19 +98,22 @@ public function render_pdfannotator_comment_info(pdfannotator_comment_info $info
$o .= $this->output->container_end();
return $o;
}
+
/**
* Construct a tab header.
*
* @param moodle_url $baseurl
- * @param string $what
+ * @param string $action
* @param string $namekey
- * @param string $subpage
+ * @param string $pdfannotatorname
* @param string $nameargs
* @return tabobject
+ * @throws \core\exception\moodle_exception
+ * @throws coding_exception
*/
private function pdfannotator_create_tab(moodle_url $baseurl, $action, $namekey = null, $pdfannotatorname = null,
$nameargs = null) {
- $taburl = new moodle_url($baseurl, array('action' => $action));
+ $taburl = new moodle_url($baseurl, ['action' => $action]);
$tabname = get_string($namekey, 'pdfannotator', $nameargs);
if ($pdfannotatorname) {
strlen($pdfannotatorname) > 20 ? $tabname = substr($pdfannotatorname, 0, 21) . "..." : $tabname = $pdfannotatorname;
@@ -115,21 +126,21 @@ private function pdfannotator_create_tab(moodle_url $baseurl, $action, $namekey
* Render the tab header hierarchy.
*
* @param moodle_url $baseurl
- * @param type $pdfannotatorname
- * @param type $context
- * @param type $selected
- * @param type $inactive
- * @return type
+ * @param string $pdfannotatorname
+ * @param context $context
+ * @param bool $selected
+ * @param bool $inactive
+ * @return array
*/
public function pdfannotator_render_tabs(moodle_url $baseurl, $pdfannotatorname, $context, $selected = null, $inactive = null) {
$overviewtab = $this->pdfannotator_create_tab($baseurl, 'overview', 'overview');
- $level1 = array(
+ $level1 = [
$overviewtab,
$this->pdfannotator_create_tab($baseurl, 'view', 'document', $pdfannotatorname),
$this->pdfannotator_create_tab($baseurl, 'statistic', 'statistic'),
- );
+ ];
return $this->tabtree($level1, $selected, $inactive);
}
diff --git a/reportform.php b/reportform.php
index d492a93..70ffb0e 100644
--- a/reportform.php
+++ b/reportform.php
@@ -33,6 +33,12 @@
*/
class pdfannotator_reportform extends moodleform {
+ /**
+ * Define the form elements.
+ *
+ * @return void
+ * @throws coding_exception
+ */
public function definition() {
global $CFG;
@@ -68,6 +74,11 @@ public function definition() {
$this->add_action_buttons($cancel = true, get_string('reportsendbutton', 'pdfannotator'));
}
+ /**
+ * Display the form.
+ *
+ * @return void
+ */
public function display() {
$this->_form->display();
}
diff --git a/settings.php b/settings.php
index 72421ea..dcb3dd1 100644
--- a/settings.php
+++ b/settings.php
@@ -15,6 +15,8 @@
// along with Moodle. If not, see