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 . /** + * Controller script for the pdfannotator module. + * * @package mod_pdfannotator * @copyright 2018 RWTH Aachen (see README.md) * @author Anna Heynkes, Friederike Schwager @@ -27,7 +29,7 @@ $action = optional_param('action', 'view', PARAM_ALPHA); // The default action is 'view'. -$taburl = new moodle_url('/mod/pdfannotator/view.php', array('id' => $id)); +$taburl = new moodle_url('/mod/pdfannotator/view.php', ['id' => $id]); $myrenderer = $PAGE->get_renderer('mod_pdfannotator'); @@ -119,8 +121,8 @@ $action = 'view'; } } else if ($data = $mform->get_data()) { // Process validated data. $mform->get_data() returns data posted in form. - $url = (new moodle_url('/mod/pdfannotator/view.php', array('id' => $comment->cmid, - 'page' => $comment->page, 'annoid' => $comment->annotationid, 'commid' => $comment->id)))->out(); + $url = (new moodle_url('/mod/pdfannotator/view.php', ['id' => $comment->cmid, + 'page' => $comment->page, 'annoid' => $comment->annotationid, 'commid' => $comment->id]))->out(); $params = new stdClass(); $params->sender = $USER->firstname . ' ' . $USER->lastname; @@ -182,8 +184,8 @@ } echo ""; } else { - $urlparams = array('action' => 'overviewquestions', 'id' => $cmid, 'page' => $currentpage, 'itemsperpage' => $itemsperpage, - 'questionfilter' => $questionfilter); + $urlparams = ['action' => 'overviewquestions', 'id' => $cmid, 'page' => $currentpage, 'itemsperpage' => $itemsperpage, + 'questionfilter' => $questionfilter]; pdfannotator_print_questions($questions, $thiscourse, $urlparams, $currentpage, $itemsperpage, $context); } } @@ -279,8 +281,8 @@ } echo ""; } else { - $urlparams = array('action' => 'overviewanswers', 'id' => $cmid, 'page' => $currentpage, 'itemsperpage' => $itemsperpage, - 'answerfilter' => $answerfilter); + $urlparams = ['action' => 'overviewanswers', 'id' => $cmid, 'page' => $currentpage, 'itemsperpage' => $itemsperpage, + 'answerfilter' => $answerfilter]; $url = new moodle_url($CFG->wwwroot . '/mod/pdfannotator/view.php', $urlparams); pdfannotator_print_answers($data, $thiscourse, $url, $currentpage, $itemsperpage, $cmid, $answerfilter, $context); } @@ -313,7 +315,7 @@ $info = get_string('nomyposts', 'pdfannotator'); echo ""; } else { - $urlparams = array('action' => 'overviewownposts', 'id' => $cmid, 'page' => $currentpage, 'itemsperpage' => $itemsperpage); + $urlparams = ['action' => 'overviewownposts', 'id' => $cmid, 'page' => $currentpage, 'itemsperpage' => $itemsperpage]; $url = new moodle_url($CFG->wwwroot . '/mod/pdfannotator/view.php', $urlparams); pdfannotator_print_this_users_posts($posts, $thiscourse, $url, $currentpage, $itemsperpage); } @@ -332,7 +334,7 @@ $itemsperpage = optional_param('itemsperpage', 5, PARAM_INT); $reportfilter = optional_param('reportfilter', 0, PARAM_INT); - $success = $DB->update_record('pdfannotator_reports', array("id" => $reportid, "seen" => 1), $bulk = false); + $success = $DB->update_record('pdfannotator_reports', ["id" => $reportid, "seen" => 1], $bulk = false); // Give feedback to the user. if ($success) { @@ -370,7 +372,7 @@ $itemsperpage = optional_param('itemsperpage', 5, PARAM_INT); $reportfilter = optional_param('reportfilter', 2, PARAM_INT); - $success = $DB->update_record('pdfannotator_reports', array("id" => $reportid, "seen" => 0), $bulk = false); + $success = $DB->update_record('pdfannotator_reports', ["id" => $reportid, "seen" => 0], $bulk = false); // Give feedback to the user. if ($success) { @@ -433,8 +435,8 @@ } echo ""; } else { - $urlparams = array('action' => 'overviewreports', 'id' => $cmid, 'page' => $currentpage, 'itemsperpage' => $itemsperpage, - 'reportfilter' => $reportfilter); + $urlparams = ['action' => 'overviewreports', 'id' => $cmid, 'page' => $currentpage, 'itemsperpage' => $itemsperpage, + 'reportfilter' => $reportfilter]; $url = new moodle_url($CFG->wwwroot . '/mod/pdfannotator/view.php', $urlparams); pdfannotator_print_reports($reports, $thiscourse, $url, $currentpage, $itemsperpage, $cmid, $reportfilter, $context); } diff --git a/db/access.php b/db/access.php index 5a4571e..40b0229 100644 --- a/db/access.php +++ b/db/access.php @@ -16,6 +16,7 @@ /** * File containing DB access rules + * * @package mod_pdfannotator * @copyright 2018 RWTH Aachen (see README.md) * @author Rabea de Groot and Anna Heynkes @@ -23,352 +24,352 @@ */ defined('MOODLE_INTERNAL') || die(); -$capabilities = array( - 'mod/pdfannotator:view' => array( // The following archetypes are recommended for the view capability (to maintain consistancy). +$capabilities = [ + 'mod/pdfannotator:view' => [ // The following archetypes are recommended for the view capability (to maintain consistancy). 'captype' => 'read', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'guest' => CAP_ALLOW, 'student' => CAP_ALLOW, 'teacher' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW, 'manager' => CAP_ALLOW, - ), - ), + ], + ], - 'mod/pdfannotator:addinstance' => array( + 'mod/pdfannotator:addinstance' => [ 'riskbitmask' => RISK_XSS, 'captype' => 'write', 'contextlevel' => CONTEXT_COURSE, - 'archetypes' => array( + 'archetypes' => [ 'editingteacher' => CAP_ALLOW, 'manager' => CAP_ALLOW, - ), + ], 'clonepermissionsfrom' => 'moodle/course:manageactivities', - ), + ], - 'mod/pdfannotator:administrateuserinput' => array ( + 'mod/pdfannotator:administrateuserinput' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'editingteacher' => CAP_ALLOW, 'manager' => CAP_ALLOW, - ), - ), + ], + ], - 'mod/pdfannotator:create' => array ( // Create annotation or comment. + 'mod/pdfannotator:create' => [ // Create annotation or comment. 'riskbitmask' => RISK_SPAM, 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'student' => CAP_ALLOW, 'teacher' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW, 'manager' => CAP_ALLOW, - ), - ), + ], + ], - 'mod/pdfannotator:deleteown' => array ( // Delete own comments or annotations. + 'mod/pdfannotator:deleteown' => [ // Delete own comments or annotations. 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'student' => CAP_ALLOW, 'teacher' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW, 'manager' => CAP_ALLOW, - ), - ), + ], + ], - 'mod/pdfannotator:deleteany' => array ( // Delete all comments or annotations (including comments/annotations by other users). + 'mod/pdfannotator:deleteany' => [ // Delete all comments or annotations (including comments/annotations by other users). 'riskbitmask' => RISK_DATALOSS, 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'editingteacher' => CAP_ALLOW, 'manager' => CAP_ALLOW, - ), - ), + ], + ], - 'mod/pdfannotator:hidecomments' => array ( + 'mod/pdfannotator:hidecomments' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'teacher' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW, 'manager' => CAP_ALLOW, - ), - ), + ], + ], - 'mod/pdfannotator:seehiddencomments' => array ( + 'mod/pdfannotator:seehiddencomments' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'teacher' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW, 'manager' => CAP_ALLOW, - ), - ), + ], + ], - 'mod/pdfannotator:edit' => array ( // Update/Edit own annotations or comments. + 'mod/pdfannotator:edit' => [ // Update/Edit own annotations or comments. 'riskbitmask' => RISK_SPAM, 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'student' => CAP_ALLOW, 'teacher' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW, 'manager' => CAP_ALLOW, - ), - ), + ], + ], - 'mod/pdfannotator:editanypost' => array( // Update/Edit all annotations or comments. + 'mod/pdfannotator:editanypost' => [ // Update/Edit all annotations or comments. 'riskbitmask' => RISK_SPAM, 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'editingteacher' => CAP_ALLOW, 'manager' => CAP_ALLOW, - ), - ), + ], + ], - 'mod/pdfannotator:report' => array ( // Report comments. + 'mod/pdfannotator:report' => [ // Report comments. 'riskbitmask' => RISK_SPAM, 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'student' => CAP_ALLOW, 'teacher' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW, - ), - ), + ], + ], - 'mod/pdfannotator:vote' => array ( // Give an interesting question or a helpful comment your vote. + 'mod/pdfannotator:vote' => [ // Give an interesting question or a helpful comment your vote. 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'student' => CAP_ALLOW, 'teacher' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW, 'manager' => CAP_ALLOW, - ), - ), + ], + ], - 'mod/pdfannotator:subscribe' => array ( // Subscribe to a question for notifications about new answers. + 'mod/pdfannotator:subscribe' => [ // Subscribe to a question for notifications about new answers. 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'student' => CAP_ALLOW, 'teacher' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW, 'manager' => CAP_ALLOW, - ), - ), + ], + ], - 'mod/pdfannotator:closequestion' => array ( // Close/Open own questions. + 'mod/pdfannotator:closequestion' => [ // Close/Open own questions. 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'student' => CAP_ALLOW, 'teacher' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW, 'manager' => CAP_ALLOW, - ), - ), + ], + ], - 'mod/pdfannotator:closeanyquestion' => array( // Close/Open all questions. + 'mod/pdfannotator:closeanyquestion' => [ // Close/Open all questions. 'riskbitmask' => RISK_SPAM, 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'editingteacher' => CAP_ALLOW, 'manager' => CAP_ALLOW, - ), - ), + ], + ], - 'mod/pdfannotator:markcorrectanswer' => array( // Mark answers as correct. + 'mod/pdfannotator:markcorrectanswer' => [ // Mark answers as correct. 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'teacher' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW, 'manager' => CAP_ALLOW, - ), - ), + ], + ], - 'mod/pdfannotator:usetextbox' => array ( // Always use textbox (even if using textbox (for students) is disabled in settings). + 'mod/pdfannotator:usetextbox' => [ // Always use textbox (even if using textbox (for students) is disabled in settings). 'riskbitmask' => RISK_SPAM, 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'teacher' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW, 'manager' => CAP_ALLOW, - ), - ), + ], + ], - 'mod/pdfannotator:usedrawing' => array ( // Always use drawing (even if using textbox (for students) is disabled in settings). + 'mod/pdfannotator:usedrawing' => [ // Always use drawing (even if using textbox (for students) is disabled in settings). 'riskbitmask' => RISK_SPAM, 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'teacher' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW, 'manager' => CAP_ALLOW, - ), - ), + ], + ], - 'mod/pdfannotator:printdocument' => array ( // Download the pdf document. + 'mod/pdfannotator:printdocument' => [ // Download the pdf document. 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'teacher' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW, 'manager' => CAP_ALLOW, - ), - ), + ], + ], - 'mod/pdfannotator:printcomments' => array ( // Download a pdf with all comments in this document. + 'mod/pdfannotator:printcomments' => [ // Download a pdf with all comments in this document. 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'teacher' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW, 'manager' => CAP_ALLOW, - ), - ), + ], + ], - 'mod/pdfannotator:forwardquestions' => array ( // Forward a question (to an other teacher/manager). + 'mod/pdfannotator:forwardquestions' => [ // Forward a question (to an other teacher/manager). 'riskbitmask' => RISK_SPAM, 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'teacher' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW, 'manager' => CAP_ALLOW, - ), - ), + ], + ], - 'mod/pdfannotator:getforwardedquestions' => array ( // Receive forwarded questions. + 'mod/pdfannotator:getforwardedquestions' => [ // Receive forwarded questions. 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'teacher' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW, 'manager' => CAP_ALLOW, - ), - ), + ], + ], // Get a notification about new questions. - 'mod/pdfannotator:recievenewquestionnotifications' => array ( + 'mod/pdfannotator:recievenewquestionnotifications' => [ 'captype' => 'read', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'student' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW, 'teacher' => CAP_ALLOW, 'manager' => CAP_ALLOW, - ), - ), + ], + ], - 'mod/pdfannotator:viewstatistics' => array ( // View statistics page. + 'mod/pdfannotator:viewstatistics' => [ // View statistics page. 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'student' => CAP_ALLOW, 'manager' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW, 'teacher' => CAP_ALLOW, - ), - ), + ], + ], - 'mod/pdfannotator:viewteacherstatistics' => array ( // See additional information on statistics page. + 'mod/pdfannotator:viewteacherstatistics' => [ // See additional information on statistics page. 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'manager' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW, 'teacher' => CAP_ALLOW, - ), - ), + ], + ], /* ********************** capabilities for viewing the overview page **********************/ // View reports of comments. - 'mod/pdfannotator:viewreports' => array ( + 'mod/pdfannotator:viewreports' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'manager' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW, 'teacher' => CAP_ALLOW, - ), - ), + ], + ], // View answers to questions you wrote or subscribed to. - 'mod/pdfannotator:viewanswers' => array ( + 'mod/pdfannotator:viewanswers' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'student' => CAP_ALLOW, - ), - ), + ], + ], // View all questions that are new in this course. - 'mod/pdfannotator:viewquestions' => array ( + 'mod/pdfannotator:viewquestions' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'student' => CAP_ALLOW, 'manager' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW, 'teacher' => CAP_ALLOW, - ), - ), + ], + ], // View all self-written posts, be it questions or comments. - 'mod/pdfannotator:viewposts' => array ( + 'mod/pdfannotator:viewposts' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'student' => CAP_ALLOW, 'manager' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW, 'teacher' => CAP_ALLOW, - ), - ), + ], + ], - 'mod/pdfannotator:viewprotectedcomments' => array ( + 'mod/pdfannotator:viewprotectedcomments' => [ 'captype' => 'read', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'manager' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW, 'teacher' => CAP_ALLOW, - ), - ), + ], + ], - 'mod/pdfannotator:writeprivatecomments' => array ( + 'mod/pdfannotator:writeprivatecomments' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'manager' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW, 'teacher' => CAP_ALLOW, 'student' => CAP_ALLOW, - ), - ), + ], + ], - 'mod/pdfannotator:writeprotectedcomments' => array ( + 'mod/pdfannotator:writeprotectedcomments' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'manager' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW, 'teacher' => CAP_ALLOW, 'student' => CAP_ALLOW, - ), - ), + ], + ], -); +]; diff --git a/db/events.php b/db/events.php index 72330f6..6ed2f8f 100644 --- a/db/events.php +++ b/db/events.php @@ -14,4 +14,11 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -defined('MOODLE_INTERNAL') || die(); +/** + * File containing the events of the pdfannotator module. + * + * @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 + */ diff --git a/db/install.php b/db/install.php index b2f004f..53e3308 100644 --- a/db/install.php +++ b/db/install.php @@ -21,12 +21,11 @@ * @author Anna Heynkes * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ + /** * Function initialises the pdfannotator_annotationtypes table with its 6 standard records. * */ -defined('MOODLE_INTERNAL') || die(); - function xmldb_pdfannotator_install() { global $DB; @@ -34,12 +33,12 @@ function xmldb_pdfannotator_install() { $condition = []; $types = $DB->record_exists($table, $condition); if (!$types) { - $DB->insert_record($table, array("name" => 'area'), false, false); - $DB->insert_record($table, array("name" => 'drawing'), false, false); - $DB->insert_record($table, array("name" => 'highlight'), false, false); - $DB->insert_record($table, array("name" => 'pin'), false, false); - $DB->insert_record($table, array("name" => 'strikeout'), false, false); - $DB->insert_record($table, array("name" => 'textbox'), false, false); + $DB->insert_record($table, ["name" => 'area'], false, false); + $DB->insert_record($table, ["name" => 'drawing'], false, false); + $DB->insert_record($table, ["name" => 'highlight'], false, false); + $DB->insert_record($table, ["name" => 'pin'], false, false); + $DB->insert_record($table, ["name" => 'strikeout'], false, false); + $DB->insert_record($table, ["name" => 'textbox'], false, false); } } diff --git a/db/messages.php b/db/messages.php index 2ce6545..1759f48 100644 --- a/db/messages.php +++ b/db/messages.php @@ -26,29 +26,29 @@ */ defined('MOODLE_INTERNAL') || die(); -$messageproviders = array ( +$messageproviders = [ - 'newquestion' => array ( + 'newquestion' => [ 'capability' => 'mod/pdfannotator:recievenewquestionnotifications', // All capabilities. - 'defaults' => array( + 'defaults' => [ 'popup' => MESSAGE_PERMITTED + MESSAGE_DEFAULT_ENABLED, 'email' => MESSAGE_PERMITTED, - ), - ), + ], + ], // Concerns answers to questions the student subscribed to. - 'newanswer' => array ( + 'newanswer' => [ 'capability' => 'mod/pdfannotator:viewanswers', // Student capability. - ), + ], // Notify teacher about a newly reported comment. - 'newreport' => array ( + 'newreport' => [ 'capability' => 'mod/pdfannotator:viewreports', // Teacher capability. - ), + ], // Notify when receiving a forwarded question. - 'forwardedquestion' => array ( + 'forwardedquestion' => [ 'capability' => 'mod/pdfannotator:getforwardedquestions', // Teacher capability. - ), + ], -); +]; diff --git a/db/upgrade.php b/db/upgrade.php index c8e1013..6f10df8 100755 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -22,9 +22,19 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * */ -defined('MOODLE_INTERNAL') || die; -function xmldb_pdfannotator_upgrade($oldversion) { +/** + * Upgrade function for the pdfannotator module. + * + * @param int $oldversion + * @return true + * @throws ddl_change_structure_exception + * @throws ddl_exception + * @throws ddl_field_missing_exception + * @throws ddl_table_missing_exception + * @throws dml_exception + */ +function xmldb_pdfannotator_upgrade(int $oldversion) { global $CFG, $DB; $dbman = $DB->get_manager(); @@ -41,7 +51,7 @@ function xmldb_pdfannotator_upgrade($oldversion) { $table->add_field('vote', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, '1'); // Adding keys to table pdfannotator_votes. - $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); + $table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']); // Conditionally launch create table for pdfannotator_votes. if (!$dbman->table_exists($table)) { @@ -70,7 +80,7 @@ function xmldb_pdfannotator_upgrade($oldversion) { $table->add_field('seen', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, '0'); // Adding keys to table pdfannotator_comments_archiv. - $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); + $table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']); // Conditionally launch create table for pdfannotator_comments_archiv. if (!$dbman->table_exists($table)) { @@ -109,13 +119,13 @@ function xmldb_pdfannotator_upgrade($oldversion) { // Define key commentid (foreign) to be added to pdfannotator_votes. $table1 = new xmldb_table('pdfannotator_votes'); - $key1 = new xmldb_key('commentid', XMLDB_KEY_FOREIGN, array('commentid'), 'comments', array('id')); + $key1 = new xmldb_key('commentid', XMLDB_KEY_FOREIGN, ['commentid'], 'comments', ['id']); // Launch add key commentid. $dbman->add_key($table1, $key1); // Define index userid (not unique) to be added to pdfannotator_votes. - $index1 = new xmldb_index('userid', XMLDB_INDEX_NOTUNIQUE, array('userid')); + $index1 = new xmldb_index('userid', XMLDB_INDEX_NOTUNIQUE, ['userid']); // Conditionally launch add index userid. if (!$dbman->index_exists($table1, $index1)) { @@ -124,13 +134,13 @@ function xmldb_pdfannotator_upgrade($oldversion) { // Define key annotationid (foreign) to be added to pdfannotator_comments. $table2 = new xmldb_table('pdfannotator_comments'); - $key2 = new xmldb_key('annotationid', XMLDB_KEY_FOREIGN, array('annotationid'), 'annotations', array('id')); + $key2 = new xmldb_key('annotationid', XMLDB_KEY_FOREIGN, ['annotationid'], 'annotations', ['id']); // Launch add key annotationid. $dbman->add_key($table2, $key2); // Define index userid (not unique) to be added to pdfannotator_comments. - $index2 = new xmldb_index('userid', XMLDB_INDEX_NOTUNIQUE, array('userid')); + $index2 = new xmldb_index('userid', XMLDB_INDEX_NOTUNIQUE, ['userid']); // Conditionally launch add index userid. if (!$dbman->index_exists($table2, $index2)) { @@ -139,7 +149,7 @@ function xmldb_pdfannotator_upgrade($oldversion) { // Define key commentid (foreign) to be added to pdfannotator_reports. $table3 = new xmldb_table('pdfannotator_reports'); - $key3 = new xmldb_key('commentid', XMLDB_KEY_FOREIGN, array('commentid'), 'comments', array('id')); + $key3 = new xmldb_key('commentid', XMLDB_KEY_FOREIGN, ['commentid'], 'comments', ['id']); // Launch add key commentid. $dbman->add_key($table3, $key3); @@ -212,8 +222,8 @@ function xmldb_pdfannotator_upgrade($oldversion) { $table->add_field('commentid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); // Adding keys to table pdfannotator_subscriptions. - $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); - $table->add_key('commentid', XMLDB_KEY_FOREIGN, array('commentid'), 'comments', array('id')); + $table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']); + $table->add_key('commentid', XMLDB_KEY_FOREIGN, ['commentid'], 'comments', ['id']); // Conditionally launch create table for pdfannotator_subscriptions. if (!$dbman->table_exists($table)) { @@ -228,7 +238,7 @@ function xmldb_pdfannotator_upgrade($oldversion) { // Define key commentid (foreign) to be dropped form pdfannotator_subscriptions. $table = new xmldb_table('pdfannotator_subscriptions'); - $key = new xmldb_key('commentid', XMLDB_KEY_FOREIGN, array('commentid'), 'comments', array('id')); + $key = new xmldb_key('commentid', XMLDB_KEY_FOREIGN, ['commentid'], 'comments', ['id']); // Launch drop key commentid. $dbman->drop_key($table, $key); @@ -242,7 +252,7 @@ function xmldb_pdfannotator_upgrade($oldversion) { // Define key annotationid (foreign) to be added to pdfannotator_subscriptions. $table = new xmldb_table('pdfannotator_subscriptions'); - $key = new xmldb_key('annotationid', XMLDB_KEY_FOREIGN, array('annotationid'), 'annotationsneu', array('id')); + $key = new xmldb_key('annotationid', XMLDB_KEY_FOREIGN, ['annotationid'], 'annotationsneu', ['id']); // Launch add key annotationid. $dbman->add_key($table, $key); @@ -250,7 +260,7 @@ function xmldb_pdfannotator_upgrade($oldversion) { // Update existing records. $rs = $DB->get_recordset('pdfannotator_subscriptions'); foreach ($rs as $record) { - $annotationid = $DB->get_field('pdfannotator_comments', 'annotationid', array('id' => $record->annotationid)); + $annotationid = $DB->get_field('pdfannotator_comments', 'annotationid', ['id' => $record->annotationid]); $record->annotationid = $annotationid; $DB->update_record('pdfannotator_subscriptions', $record); } @@ -272,7 +282,7 @@ function xmldb_pdfannotator_upgrade($oldversion) { // Define key pdfannotatorid (foreign) to be added to pdfannotator_comments. $table = new xmldb_table('pdfannotator_comments'); - $key = new xmldb_key('pdfannotatorid', XMLDB_KEY_FOREIGN, array('pdfannotatorid'), 'pdfannotator', array('id')); + $key = new xmldb_key('pdfannotatorid', XMLDB_KEY_FOREIGN, ['pdfannotatorid'], 'pdfannotator', ['id']); // Launch add key pdfannotatorid. $dbman->add_key($table, $key); @@ -289,7 +299,7 @@ function xmldb_pdfannotator_upgrade($oldversion) { // Add pdfannotatorid to old records in comments-table. $rs = $DB->get_recordset('pdfannotator_comments'); foreach ($rs as $record) { - $pdfannotatorid = $DB->get_field('pdfannotator_annotationsneu', 'pdfannotatorid', array('id' => $record->annotationid)); + $pdfannotatorid = $DB->get_field('pdfannotator_annotationsneu', 'pdfannotatorid', ['id' => $record->annotationid]); $record->pdfannotatorid = $pdfannotatorid; $DB->update_record('pdfannotator_comments', $record); } @@ -297,7 +307,7 @@ function xmldb_pdfannotator_upgrade($oldversion) { $rs = $DB->get_recordset('pdfannotator_comments_archiv'); foreach ($rs as $record) { - $pdfannotatorid = $DB->get_field('pdfannotator_annotationsneu', 'pdfannotatorid', array('id' => $record->annotationid)); + $pdfannotatorid = $DB->get_field('pdfannotator_annotationsneu', 'pdfannotatorid', ['id' => $record->annotationid]); $record->pdfannotatorid = $pdfannotatorid; $DB->update_record('pdfannotator_comments_archiv', $record); } @@ -310,7 +320,7 @@ function xmldb_pdfannotator_upgrade($oldversion) { // Define key pdfannotatorid (foreign) to be added to pdfannotator_comments_archiv. $table = new xmldb_table('pdfannotator_comments_archiv'); - $key = new xmldb_key('pdfannotatorid', XMLDB_KEY_FOREIGN, array('pdfannotatorid'), 'pdfannotator', array('id')); + $key = new xmldb_key('pdfannotatorid', XMLDB_KEY_FOREIGN, ['pdfannotatorid'], 'pdfannotator', ['id']); // Launch add key pdfannotatorid. $dbman->add_key($table, $key); @@ -337,15 +347,15 @@ function xmldb_pdfannotator_upgrade($oldversion) { // Define key pdfannotatorid (foreign) to be added to pdfannotator_annotations. $table = new xmldb_table('pdfannotator_annotations'); - $key = new xmldb_key('pdfannotatorid', XMLDB_KEY_FOREIGN, array('pdfannotatorid'), 'pdfannotator', array('id')); + $key = new xmldb_key('pdfannotatorid', XMLDB_KEY_FOREIGN, ['pdfannotatorid'], 'pdfannotator', ['id']); // Launch add key pdfannotatorid. $dbman->add_key($table, $key); // Define key annotationtypeid (foreign) to be added to pdfannotator_annotations. $table = new xmldb_table('pdfannotator_annotations'); - $key = new xmldb_key('annotationtypeid', XMLDB_KEY_FOREIGN, array('annotationtypeid'), 'pdfannotator_annotationtypes', - array('id')); + $key = new xmldb_key('annotationtypeid', XMLDB_KEY_FOREIGN, ['annotationtypeid'], 'pdfannotator_annotationtypes', + ['id']); // Launch add key annotationtypeid. $dbman->add_key($table, $key); diff --git a/forward_form.php b/forward_form.php index 4a249b0..90d1eef 100644 --- a/forward_form.php +++ b/forward_form.php @@ -33,6 +33,12 @@ */ class pdfannotator_forward_form extends moodleform { + /** + * Define the form elements. + * + * @return void + * @throws coding_exception + */ public function definition() { global $CFG; @@ -81,6 +87,11 @@ public function definition() { $this->add_action_buttons($cancel = true, get_string('send', 'pdfannotator')); } + /** + * Display the form. + * + * @return void + */ public function display() { $this->_form->display(); } diff --git a/index.php b/index.php index a9733b5..9bdd419 100644 --- a/index.php +++ b/index.php @@ -15,27 +15,31 @@ // along with Moodle. If not, see . /** + * View script for the pdfannotator module. + * * @package mod_pdfannotator * @copyright 2018 RWTH Aachen (see README.md) * @author Ahmad Obeid * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -//require_once('../../config.php'); + +defined('MOODLE_INTERNAL') || die(); + require_once('locallib.php'); $id = required_param('id', PARAM_INT); // Course ID. // Ensure that the course specified is valid. -if (!$course = $DB->get_record('course', array('id' => $id))) { +if (!$course = $DB->get_record('course', ['id' => $id])) { throw new moodle_exception('Course ID is incorrect'); } -// $course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST); + require_course_login($course, true); $PAGE->set_pagelayout('incourse'); -$params = array( +$params = [ 'context' => context_course::instance($course->id), -); +]; $context = $params['context']; $event = \mod_pdfannotator\event\course_module_instance_list_viewed::create($params); $event->add_record_snapshot('course', $course); @@ -53,7 +57,7 @@ $stryes = get_string('yes'); $strno = get_string('no'); -$PAGE->set_url('/mod/pdfannotator/index.php', array('id' => $course->id)); +$PAGE->set_url('/mod/pdfannotator/index.php', ['id' => $course->id]); $PAGE->set_title($course->shortname.': '.$strpdfannotators); $PAGE->set_heading($course->fullname); $PAGE->navbar->add($strpdfannotators); @@ -71,11 +75,11 @@ $table->attributes['class'] = 'generaltable mod_index'; if ($usesections) { - $table->head = array ($strsectionname, $strname, $strlastmodified, $strintro); - $table->align = array ('center', '', 'left', 'left'); + $table->head = [$strsectionname, $strname, $strlastmodified, $strintro]; + $table->align = ['center', '', 'left', 'left']; } else { - $table->head = array ($strlastmodified, $strname, $strintro); - $table->align = array ('left', 'left', 'left'); + $table->head = [$strlastmodified, $strname, $strintro]; + $table->align = ['left', 'left', 'left']; } $modinfo = get_fast_modinfo($course); @@ -105,30 +109,30 @@ $visible = $pdfannotator->visible; $class = $visible ? '' : 'class="dimmed"'; // Hidden modules are dimmed. $newinfo = " "; - $actions = array(); + $actions = []; // Settings if user have capabilty. - $manageurl = new \moodle_url('/course/mod.php', array('sesskey' => \sesskey())); + $manageurl = new \moodle_url('/course/mod.php', ['sesskey' => \sesskey()]); // Edit. $hascapability = has_capability('mod/pdfannotator:administrateuserinput', $context); if ($hascapability) { - $actions['edit'] = array( - 'url' => new \moodle_url('/course/modedit.php', array('update' => $cm->id)), + $actions['edit'] = [ + 'url' => new \moodle_url('/course/modedit.php', ['update' => $cm->id]), 'icon' => new \pix_icon('t/edit', new \lang_string('edit')), 'string' => new \lang_string('edit'), - ); + ]; // Show/Hide. if ($visible) { - $actions['hide'] = array( - 'url' => new \moodle_url($manageurl, array('hide' => $cm->id)), + $actions['hide'] = [ + 'url' => new \moodle_url($manageurl, ['hide' => $cm->id]), 'icon' => new \pix_icon('t/hide', new \lang_string('hide')), 'string' => new \lang_string('hide'), - ); + ]; } else { - $actions['show'] = array( - 'url' => new \moodle_url($manageurl, array('show' => $cm->id)), + $actions['show'] = [ + 'url' => new \moodle_url($manageurl, ['show' => $cm->id]), 'icon' => new \pix_icon('t/show', new \lang_string('show')), 'string' => new \lang_string('show'), - ); + ]; } } $setting = pdfannotator_render_listitem_actions($actions); @@ -138,11 +142,11 @@ } else if ($lastmodified >= strtotime("-1 day")) { $newinfo = ""; } - $table->data[] = array ( + $table->data[] = [ $printsection, "
id\">".$icon.format_string($pdfannotator->name) .$newinfo."
".$setting."
" , userdate($lastmodified), - format_module_intro('pdfannotator', $pdfannotator, $cm->id)); + format_module_intro('pdfannotator', $pdfannotator, $cm->id)]; } echo html_writer::table($table); diff --git a/lang/en/pdfannotator.php b/lang/en/pdfannotator.php index caf15f6..ad2185a 100644 --- a/lang/en/pdfannotator.php +++ b/lang/en/pdfannotator.php @@ -26,14 +26,14 @@ $string['actiondropdown'] = "Options"; $string['activities'] = 'Activities'; $string['addAComment'] = 'Add a comment'; -$string['add_protected_comment'] = 'Add a comment to private question'; $string['add_private_comment'] = 'Add a comment to personal note'; +$string['add_protected_comment'] = 'Add a comment to private question'; $string['ago'] = '{$a} ago'; $string['all'] = 'all'; -$string['allanswers'] = 'all'; $string['all_answers'] = 'All answers'; -$string['allquestions'] = 'all'; $string['all_questions'] = 'All questions'; +$string['allanswers'] = 'all'; +$string['allquestions'] = 'all'; $string['allquestionsimgtitle'] = "Show all questions in this document"; $string['allquestionstitle'] = 'All questions in'; $string['allreports'] = 'all reports'; @@ -41,10 +41,10 @@ $string['anonymous'] = 'Anonymous'; $string['answer'] = 'Answer'; $string['answerButton'] = 'Answer'; +$string['answerSolved'] = 'This answer was marked as correct by the manager.'; $string['answercounthelpicon'] = 'Number of answers'; $string['answercounthelpicon_help'] = 'This column tells you how many answers a question has received.'; $string['answers'] = 'answers'; -$string['answerSolved'] = 'This answer was marked as correct by the manager.'; $string['answerstab'] = 'Answers'; $string['answerstabicon'] = 'Answers'; $string['answerstabicon_help'] = "This page can show you all answers or only answers to questions you subscribed* to. The list covers all annotators in this course.
*When you post a question yourself, you are automatically subscribed to it as long as you don't unsubscribe."; @@ -66,7 +66,6 @@ $string['comment'] = 'Comment'; $string['commentDeleted'] = 'Comment has been deleted'; $string['comments'] = 'Comments'; -// Annotation separation. $string['comments_icon_private'] = 'This comment is private'; $string['comments_icon_public'] = 'This comment is public'; $string['comments_text_all'] = 'Show all comments'; @@ -80,8 +79,8 @@ $string['day'] = 'day'; $string['days'] = 'days'; -$string['decision:overlappingAnnotation'] = 'You clicked an area, in which is more than one annotation. Decide which one you wanted to click.'; $string['decision'] = 'Make a decision'; +$string['decision:overlappingAnnotation'] = 'You clicked an area, in which is more than one annotation. Decide which one you wanted to click.'; $string['delete'] = 'Delete'; $string['deleteComment'] = 'Delete comment'; $string['deletedComment'] = 'deleted comment'; @@ -102,11 +101,12 @@ $string['editAnnotation'] = 'The annotation will be moved.
This might change the context of the question.'; $string['editAnnotationTitle'] = 'Are you sure?'; $string['editButton'] = 'Save'; -$string['editedComment'] = 'last edited'; $string['editNotAllowed'] = 'Panning not allowed!'; +$string['editedComment'] = 'last edited'; $string['emptypdf'] = 'There are no comments in this annotator at present.'; $string['enterText'] = 'Enter text'; $string['entity_helptitle'] = 'Help for'; +$string['error'] = 'Error!'; $string['error:addAnnotation'] = 'An error has occurred while adding an annotation.'; $string['error:addComment'] = 'An error has occurred while adding the comment.'; $string['error:closequestion'] = 'An error has occurred while closing/opening the question.'; @@ -120,9 +120,9 @@ $string['error:getAnnotation'] = 'An error has occurred while getting the annotation.'; $string['error:getAnnotations'] = 'An error has occurred while getting all annotations.'; $string['error:getComments'] = 'An error has occurred while getting the comments.'; +$string['error:getQuestions'] = 'An error has occurred while getting the questions for this page.'; $string['error:getimageheight'] = 'An error has occurred while getting image height of {$a}.'; $string['error:getimagewidth'] = 'An error has occurred while getting image width of {$a}.'; -$string['error:getQuestions'] = 'An error has occurred while getting the questions for this page.'; $string['error:hideComment'] = "An error has occurred while trying to hide the comment from participants' view."; $string['error:markasread'] = 'The item could not be marked as read.'; $string['error:markasunread'] = 'The item could not be marked as unread.'; @@ -134,15 +134,14 @@ $string['error:printcomments'] = 'An error has occurred while trying to open the comments in a pdf.'; $string['error:printcommentsdata'] = 'Error with data from server.'; $string['error:printlatex'] = 'An error has occurred while trying to add a LaTeX formula to the pdf.'; +$string['error:redihideCommentsplayComment'] = 'An error occurred while re-inserting the comment for attendees.'; $string['error:redisplayComment'] = 'An error has occurred while redisplaying the comment.'; $string['error:renderPage'] = 'An error has occurred while rendering the page.'; $string['error:reportComment'] = 'An error has occurred while saving the report.'; $string['error:subscribe'] = 'An error has occurred while subscribing to the question.'; $string['error:unsubscribe'] = 'An error has occurred while unsubscribing to the question.'; $string['error:unsupportedextension'] = 'The extension of submitted data is not supported. Please select other extension.'; -$string['error:redihideCommentsplayComment'] = 'An error occurred while re-inserting the comment for attendees.'; $string['error:voteComment'] = 'An error has occurred while saving the vote.'; -$string['error'] = 'Error!'; $string['eventreport_added'] = 'A comment was reported'; $string['export_comments_csv'] = 'Export as CSV'; $string['export_comments_csv_tooltip'] = 'Download comments as CSV file'; @@ -176,8 +175,12 @@ Note: If you use the Google Chart API, Google will get all formulas in the document if someone chooses to use LaTeX
If you use the Moodle API, you need a latex, dvips and convert binary installed on your server. (See Moodle Documentation)'; -$string['global_setting_latexusemoodle'] = 'Internal Moodle API'; $string['global_setting_latexusegoogle'] = 'Google Chart API'; +$string['global_setting_latexusemoodle'] = 'Internal Moodle API'; +$string['global_setting_use_private_comments'] = 'Allow personal notes?'; +$string['global_setting_use_private_comments_desc'] = 'Allow participants to write personal annotations and personal notes'; +$string['global_setting_use_protected_comments'] = 'Allow private comments?'; +$string['global_setting_use_protected_comments_desc'] = 'Allow participants to write private annotations and private comments. Only author and manager can see this comment.'; $string['global_setting_use_studentdrawing'] = 'Allow drawings for participants?'; $string['global_setting_use_studentdrawing_desc'] = 'Please note that drawings are anonymous and can neither be commented nor reported.'; $string['global_setting_use_studenttextbox'] = 'Allow textboxes for participants?'; @@ -185,10 +188,6 @@ $string['global_setting_useprint'] = 'Allow save and print?'; $string['global_setting_useprint_comments'] = 'Allow saving/printing comments?'; $string['global_setting_useprint_comments_desc'] = 'Allow participants to save and print the annotations and comments'; -$string['global_setting_use_private_comments'] = 'Allow personal notes?'; -$string['global_setting_use_private_comments_desc'] = 'Allow participants to write personal annotations and personal notes'; -$string['global_setting_use_protected_comments'] = 'Allow private comments?'; -$string['global_setting_use_protected_comments_desc'] = 'Allow participants to write private annotations and private comments. Only author and manager can see this comment.'; $string['global_setting_useprint_desc'] = 'Allow participants to save and print the pdf document and its comments'; $string['global_setting_useprint_document'] = 'Allow saving/printing document?'; $string['global_setting_useprint_document_desc'] = 'Allow participants to save and print the pdf document'; @@ -227,12 +226,12 @@ $string['likeQuestionForbidden'] = 'already marked as helpful'; $string['loading'] = 'Loading!'; -$string['markasread'] = 'Mark as read'; -$string['markasunread'] = 'Mark as unread'; $string['markCorrect'] = 'Mark as correct'; -$string['markhidden'] = 'Hide'; $string['markSolved'] = 'Close question'; $string['markUnsolved'] = 'Reopen question'; +$string['markasread'] = 'Mark as read'; +$string['markasunread'] = 'Mark as unread'; +$string['markhidden'] = 'Hide'; $string['maximumfilesize'] = 'Maximum file size'; $string['maximumfilesize_help'] = 'Files uploaded by users may be up to this size.'; $string['me'] = 'me'; @@ -278,9 +277,9 @@ The question is available under: {$a->urltoanswer}'; $string['nextPage'] = 'Next page'; +$string['noCommentsupported'] = 'This kind of annotation does not support comments.'; $string['noanswers'] = 'There are no answers in this course at present.'; $string['noanswerssubscribed'] = 'There are no answers to subscribed questions in this course at present.'; -$string['noCommentsupported'] = 'This kind of annotation does not support comments.'; $string['nomyposts'] = 'You have posted no question or answer in this course yet.'; $string['noquestions'] = 'No questions on this page!'; $string['noquestions_overview'] = 'There are no questions in this course at present.'; @@ -307,6 +306,8 @@ $string['ownpoststabicon_help'] = 'This page displays all comments that you posted in this course.'; $string['page'] = 'page'; +$string['pdfButton'] = 'Document'; +$string['pdfannotator'] = 'Document'; $string['pdfannotator:addinstance'] = 'add instance'; $string['pdfannotator:administrateuserinput'] = 'Administrate comments'; $string['pdfannotator:closeanyquestion'] = 'Close any question'; @@ -339,12 +340,10 @@ $string['pdfannotator:vote'] = "Vote for an interesting question or helpful answer"; $string['pdfannotator:writeprivatecomments'] = 'Make personal notes'; $string['pdfannotator:writeprotectedcomments'] = 'Write private comments'; -$string['pdfannotator'] = 'Document'; $string['pdfannotatorcolumn'] = 'Document'; $string['pdfannotatorcontent'] = 'Files and subfolders'; $string['pdfannotatorname'] = 'PDF Annotation Tool'; $string['pdfannotatorpost'] = 'Comments and questions'; -$string['pdfButton'] = 'Document'; $string['pluginadministration'] = 'PDF Annotation administration'; $string['pluginname'] = 'PDF Annotation'; $string['point'] = 'Add a pin in the document and write a comment.'; @@ -354,36 +353,36 @@ $string['printviewtitle'] = 'Comments'; $string['printwithannotations'] = 'download comments'; $string['privacy:metadata:core_files'] = 'The Pdfannotator stores files which have been uploaded by the user as a basis for annotation and discussion.'; +$string['privacy:metadata:pdfannotator_annotations'] = "Information about the annotations a user made. This includes the type of annotation (e.g. highlight or drawing), its position within a specific file, as well as the time of creation."; $string['privacy:metadata:pdfannotator_annotations:annotationid'] = 'The ID of the annotation that was made. It refers to the data listed above.'; $string['privacy:metadata:pdfannotator_annotations:userid'] = 'The ID of the user who made this annotation.'; -$string['privacy:metadata:pdfannotator_annotations'] = "Information about the annotations a user made. This includes the type of annotation (e.g. highlight or drawing), its position within a specific file, as well as the time of creation."; +$string['privacy:metadata:pdfannotator_comments'] = "Information about a user's comments. This includes the content and time of creation of the comment, as well as the underlying annotation."; $string['privacy:metadata:pdfannotator_comments:annotationid'] = 'The ID of the underlying annotation.'; $string['privacy:metadata:pdfannotator_comments:content'] = 'The literal comment.'; $string['privacy:metadata:pdfannotator_comments:userid'] = "The ID of the comment's author."; -$string['privacy:metadata:pdfannotator_comments'] = "Information about a user's comments. This includes the content and time of creation of the comment, as well as the underlying annotation."; +$string['privacy:metadata:pdfannotator_reports'] = "Users can report other users' comments as inappropriate. These reports stored. This includes the ID of the reported comment as well as the author, content and time of the report."; $string['privacy:metadata:pdfannotator_reports:commentid'] = 'The ID of the reported comment.'; $string['privacy:metadata:pdfannotator_reports:message'] = 'The text content of the report.'; $string['privacy:metadata:pdfannotator_reports:userid'] = 'The author of the report.'; -$string['privacy:metadata:pdfannotator_reports'] = "Users can report other users' comments as inappropriate. These reports stored. This includes the ID of the reported comment as well as the author, content and time of the report."; +$string['privacy:metadata:pdfannotator_subscriptions'] = "Information about the subscriptions to individual questions/discussions."; $string['privacy:metadata:pdfannotator_subscriptions:annotationid'] = 'The ID of the question/discussion that was subscribed to.'; $string['privacy:metadata:pdfannotator_subscriptions:userid'] = 'The ID of the user with this subscription.'; -$string['privacy:metadata:pdfannotator_subscriptions'] = "Information about the subscriptions to individual questions/discussions."; +$string['privacy:metadata:pdfannotator_votes'] = "Information about questions and comments that were marked as interesting or helpful."; $string['privacy:metadata:pdfannotator_votes:commentid'] = "The ID of the comment."; $string['privacy:metadata:pdfannotator_votes:userid'] = "The ID of the user who marked the comment as interesting or helpful. It is saved in order to prevent users from voting for the same comment repeatedly."; -$string['privacy:metadata:pdfannotator_votes'] = "Information about questions and comments that were marked as interesting or helpful."; $string['private_comments'] = "Personal notes"; $string['private_comments_help'] = 'Visible only for you.'; $string['protected_answers'] = 'Private answers'; $string['protected_comments'] = "Private comments"; $string['protected_comments_help'] = 'Visible only for you and teachers.'; $string['protected_questions'] = 'Private questions'; -$string['publicanswers'] = 'Public answers'; $string['public_comments'] = 'Public comments'; +$string['publicanswers'] = 'Public answers'; $string['publicquestions'] = 'Public questions'; $string['question'] = 'Question'; -$string['questionsimgtitle'] = "Show all questions on this page"; $string['questionSolved'] = 'Questions is closed. However, you can still create new comments.'; +$string['questionsimgtitle'] = "Show all questions on this page"; $string['questionstab'] = 'Questions'; $string['questionstabicon'] = 'Questions'; $string['questionstabicon_help'] = 'This page displays all unsolved questions that were asked in this course. You can also choose to see all or all solved questions in this course.'; @@ -432,6 +431,10 @@ $string['setting_anonymous'] = 'Allow anonymous posting?'; $string['setting_fileupload'] = 'Select a pdf-file'; $string['setting_fileupload_help'] = "You can only change the selected file until the annotator has been created by a click on 'Save'."; +$string['setting_use_private_comments'] = "Allow personal notes"; +$string['setting_use_private_comments_help'] = "Allow participants to write personal notes. Other person cannot see this comment."; +$string['setting_use_protected_comments'] = "Allow private comments"; +$string['setting_use_protected_comments_help'] = "Allow participants to write private comments. Only the author and teachers can see this comment."; $string['setting_use_studentdrawing'] = "Drawing"; $string['setting_use_studentdrawing_help'] = "Allow participants to save and print the pdf document without annotations or comments"; $string['setting_use_studenttextbox'] = "Textbox"; @@ -442,10 +445,6 @@ $string['setting_useprint_document'] = 'Save and print pdf document'; $string['setting_useprint_document_help'] = 'Allow participants to save and print the pdf document'; $string['setting_useprint_help'] = "Please note that drawings are not anonymous and can neither be commented nor reported."; -$string['setting_use_private_comments'] = "Allow personal notes"; -$string['setting_use_private_comments_help'] = "Allow participants to write personal notes. Other person cannot see this comment."; -$string['setting_use_protected_comments'] = "Allow private comments"; -$string['setting_use_protected_comments_help'] = "Allow participants to write private comments. Only the author and teachers can see this comment."; $string['setting_usevotes'] = "Votes/Likes"; $string['setting_usevotes_help'] = "With this option enabled, users can like / vote for posts other than their own."; $string['show'] = 'Show'; @@ -460,16 +459,12 @@ $string['studentdrawingforbidden'] = 'This annotator does not support drawings for your user role.'; $string['studenttextboxforbidden'] = 'This annotator does not support textboxes for your user role.'; $string['subscribe'] = 'Subscribe to this Annotations'; +$string['subscribeQuestion'] = 'Subscribe'; $string['subscribed'] = 'Subscribed'; $string['subscribedanswers'] = 'to my subscribed questions'; -$string['subscribeQuestion'] = 'Subscribe'; $string['subtitleforreportcommentform'] = 'Your message for the course manager'; $string['successfullyEdited'] = 'Changes saved'; $string['successfullyHidden'] = 'Participants now see this comment as hidden.'; -$string['successfullymarkedasread'] = 'The report was marked as read.'; -$string['successfullymarkedasreadandnolongerdisplayed'] = 'The report was marked as read and removed from the table.'; -$string['successfullymarkedasunread'] = 'The report was marked as unread.'; -$string['successfullymarkedasunreadandnolongerdisplayed'] = 'The report was marked as unread and removed from the table.'; $string['successfullyRedisplayed'] = 'The comment is visible to participants once more'; $string['successfullySubscribed'] = 'Subscribed to question.'; $string['successfullySubscribednotify'] = 'Your subscription to the question was registered.'; @@ -477,6 +472,10 @@ $string['successfullyUnsubscribedPlural'] = 'Your subscribtion was cancelled. All {$a} answers to the question were removed from this table.'; $string['successfullyUnsubscribedSingular'] = 'Your subscribtion to the question was cancelled and the only answer removed from this table.'; $string['successfullyUnsubscribedTwo'] = 'Your subscribtion was cancelled. Both answers to the question were removed from this table.'; +$string['successfullymarkedasread'] = 'The report was marked as read.'; +$string['successfullymarkedasreadandnolongerdisplayed'] = 'The report was marked as read and removed from the table.'; +$string['successfullymarkedasunread'] = 'The report was marked as unread.'; +$string['successfullymarkedasunreadandnolongerdisplayed'] = 'The report was marked as unread and removed from the table.'; $string['sumPages'] = 'Number of pages'; $string['text'] = 'Add a text in the document.'; @@ -488,15 +487,15 @@ $string['unsolvedquestionstitle'] = 'Unsolved Questions'; $string['unsolvedquestionstitle_help'] = 'All unsolved questions in this course are listed.'; $string['unsubscribe'] = 'Unsubscribe from this Annotations'; -$string['unsubscribe_notification'] = 'To unsubscribe from notification, please click here.'; $string['unsubscribeQuestion'] = 'Unsubscribe'; +$string['unsubscribe_notification'] = 'To unsubscribe from notification, please click here.'; $string['unsubscribingDidNotWork'] = 'The subscription could not be cancelled.'; +$string['use_private_comments'] = "Allow participants to write personal notes?"; +$string['use_protected_comments'] = "Allow participants to write private comments?"; $string['use_studentdrawing'] = "Enable drawing for participants?"; $string['use_studenttextbox'] = "Enable textbox tool for participants?"; $string['useprint'] = "Give participants access to the PDF?"; $string['useprint_comments'] = "Give participants access to the PDF and its comments?"; -$string['use_private_comments'] = "Allow participants to write personal notes?"; -$string['use_protected_comments'] = "Allow participants to write private comments?"; $string['useprint_document'] = "Give participants access to the PDF?"; $string['usevotes'] = "Allow users to like comments."; diff --git a/lib.php b/lib.php index f8364bf..0079ce3 100644 --- a/lib.php +++ b/lib.php @@ -75,15 +75,16 @@ function pdfannotator_supports($feature) { * @return array */ function pdfannotator_get_extra_capabilities() { - return array('moodle/site:accessallgroups'); + return ['moodle/site:accessallgroups']; } /** * This function is used by the reset_course_userdata function in moodlelib. - * @param $data the data submitted from the reset course. + * + * @param array $data the data submitted from the reset course. * @return array status array */ function pdfannotator_reset_userdata($data) { - return array(); + return []; } /** @@ -97,7 +98,7 @@ function pdfannotator_reset_userdata($data) { * @return array */ function pdfannotator_get_view_actions() { - return array('view', 'view all'); + return ['view', 'view all']; } /** @@ -111,7 +112,7 @@ function pdfannotator_get_view_actions() { * @return array */ function pdfannotator_get_post_actions() { - return array('update', 'add'); + return ['update', 'add']; } /** @@ -131,7 +132,7 @@ function pdfannotator_add_instance($data, $mform) { $data->id = $DB->insert_record('pdfannotator', $data); // We need to use context now, so we need to make sure all needed info is already in db. - $DB->set_field('course_modules', 'instance', $data->id, array('id' => $cmid)); + $DB->set_field('course_modules', 'instance', $data->id, ['id' => $cmid]); pdfannotator_set_mainfile($data); $completiontimeexpected = !empty($data->completionexpected) ? $data->completionexpected : null; @@ -173,7 +174,7 @@ function pdfannotator_update_instance($data, $mform) { * @param object $data Data object */ function pdfannotator_set_display_options($data) { - $displayoptions = array(); + $displayoptions = []; $displayoptions['printintro'] = (int) !empty($data->printintro); $data->displayoptions = serialize($displayoptions); } @@ -187,7 +188,7 @@ function pdfannotator_delete_instance($id) { global $DB; - if (!$pdfannotator = $DB->get_record('pdfannotator', array('id' => $id))) { + if (!$pdfannotator = $DB->get_record('pdfannotator', ['id' => $id])) { return false; } @@ -229,7 +230,7 @@ function pdfannotator_delete_instance($id) { } // 4. Delete the annotator itself. - if (!$DB->delete_records('pdfannotator', array('id' => $id)) == 1) { + if (!$DB->delete_records('pdfannotator', ['id' => $id]) == 1) { return false; } @@ -254,7 +255,7 @@ function pdfannotator_get_coursemodule_info($coursemodule) { $context = context_module::instance($coursemodule->id); - if (!$pdfannotator = $DB->get_record('pdfannotator', array('id' => $coursemodule->instance), 'id, name, course, + if (!$pdfannotator = $DB->get_record('pdfannotator', ['id' => $coursemodule->instance], 'id, name, course, timemodified, timecreated, intro, introformat')) { return null; } @@ -271,7 +272,8 @@ function pdfannotator_get_coursemodule_info($coursemodule) { $files = $fs->get_area_files($context->id, 'mod_pdfannotator', 'content', 0, 'sortorder DESC, id ASC', false, 0, 0, 1); if (count($files) >= 1) { $mainfile = reset($files); - // $info->icon = file_file_icon($mainfile, 24); // Uncomment to use pdf icon. + // phpcs:disable Squiz.PHP.CommentedOutCode + // Uncomment $info->icon = file_file_icon($mainfile, 24); // Uncomment to use pdf icon. $pdfannotator->mainfile = $mainfile->get_filename(); } // If any optional extra details are turned on, store in custom data, @@ -292,7 +294,7 @@ function pdfannotator_get_coursemodule_info($coursemodule) { * @return array */ function pdfannotator_get_file_areas($course, $cm, $context) { - $areas = array(); + $areas = []; $areas['content'] = get_string('pdfannotatorcontent', 'pdfannotator'); $areas['post'] = get_string('pdfannotatorpost', 'pdfannotator'); return $areas; @@ -338,7 +340,8 @@ function pdfannotator_get_file_info($browser, $areas, $course, $cm, $context, $f } } require_once("$CFG->dirroot/mod/pdfannotator/locallib.php"); - return new pdfannotator_content_file_info($browser, $context, $storedfile, $urlbase, $areas[$filearea], true, true, true, false); + return new pdfannotator_content_file_info($browser, $context, $storedfile, $urlbase, $areas[$filearea], true, + true, true, false); } // Note: pdfannotator_intro handled in file_browser automatically. @@ -360,7 +363,7 @@ function pdfannotator_get_file_info($browser, $areas, $course, $cm, $context, $f * @param array $options additional options affecting the file serving * @return bool false if file not found, does not return if found - just send the file */ -function pdfannotator_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options = array()) { +function pdfannotator_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options = []) { global $CFG, $DB; require_once("$CFG->libdir/resourcelib.php"); @@ -395,11 +398,12 @@ function pdfannotator_pluginfile($course, $cm, $context, $filearea, $args, $forc break; } } - $pdfannotator = $DB->get_record('pdfannotator', array('id' => $cm->instance), 'id, legacyfiles', MUST_EXIST); + $pdfannotator = $DB->get_record('pdfannotator', ['id' => $cm->instance], 'id, legacyfiles', MUST_EXIST); if ($pdfannotator->legacyfiles != RESOURCELIB_LEGACYFILES_ACTIVE) { return false; } - if (!$file = resourcelib_try_file_migration('/' . $relativepath, $cm->id, $cm->course, 'mod_pdfannotator', 'content', 0)) { + if (!$file = resourcelib_try_file_migration('/' . $relativepath, $cm->id, $cm->course, + 'mod_pdfannotator', 'content', 0)) { return false; } // File migrate - update flag. @@ -409,7 +413,6 @@ function pdfannotator_pluginfile($course, $cm, $context, $filearea, $args, $forc } while (false); // Should we apply filters? - // $mimetype = $file->get_mimetype(); $filter = 0; // Finally send the file. send_stored_file($file, null, $filter, $forcedownload, $options); @@ -432,7 +435,8 @@ function pdfannotator_pluginfile($course, $cm, $context, $filearea, $args, $forc $pdfid = $DB->get_record('pdfannotator_comments', ['id' => $commentid], 'pdfannotatorid'); if ($pdfid) { $pdfannotator = $DB->get_record('pdfannotator', ['id' => $pdfid->pdfannotatorid], '*', MUST_EXIST); - $cm = get_coursemodule_from_instance('pdfannotator', $pdfid->pdfannotatorid, $pdfannotator->course, false, MUST_EXIST); + $cm = get_coursemodule_from_instance('pdfannotator', $pdfid->pdfannotatorid, $pdfannotator->course, + false, MUST_EXIST); $context2 = context_module::instance($cm->id); $fullpath = rtrim("/$context2->id/mod_pdfannotator/$filearea/$commentid/$relativepath", '/'); if (!$file = $fs->get_file_by_hash(sha1($fullpath)) || $file->is_directory()) { @@ -452,32 +456,35 @@ function pdfannotator_pluginfile($course, $cm, $context, $filearea, $args, $forc * @param stdClass $currentcontext Current context of block */ function pdfannotator_page_type_list($pagetype, $parentcontext, $currentcontext) { - $modulepagetype = array('mod-pdfannotator-*' => get_string('page-mod-pdfannotator-x', 'pdfannotator')); + $modulepagetype = ['mod-pdfannotator-*' => get_string('page-mod-pdfannotator-x', 'pdfannotator')]; return $modulepagetype; } /** * Export file pdfannotator contents * + * @param stdClass $cm course module object + * @param string $baseurl base URL for the file * @return array of file content */ function pdfannotator_export_contents($cm, $baseurl) { global $CFG, $DB; - $contents = array(); + $contents = []; $context = context_module::instance($cm->id); - $pdfannotator = $DB->get_record('pdfannotator', array('id' => $cm->instance), '*', MUST_EXIST); + $pdfannotator = $DB->get_record('pdfannotator', ['id' => $cm->instance], '*', MUST_EXIST); if ($pdfannotator->useprint == 1) { $fs = get_file_storage(); $files = $fs->get_area_files($context->id, 'mod_pdfannotator', 'content', 0, 'sortorder DESC, id ASC', false); $fileinfo = reset($files); - $file = array(); + $file = []; $file['type'] = 'file'; $file['filename'] = $fileinfo->get_filename(); $file['filepath'] = $fileinfo->get_filepath(); $file['filesize'] = $fileinfo->get_filesize(); $file['mimetype'] = 'pdf'; $file['fileurl'] = moodle_url::make_webservice_pluginfile_url( - $context->id, 'mod_pdfannotator', 'content', '1', $fileinfo->get_filepath(), $fileinfo->get_filename())->out(false); + $context->id, 'mod_pdfannotator', 'content', '1', $fileinfo->get_filepath(), + $fileinfo->get_filename())->out(false); $file['timecreated'] = $fileinfo->get_timecreated(); $file['timemodified'] = $fileinfo->get_timemodified(); $file['sortorder'] = $fileinfo->get_sortorder(); @@ -494,37 +501,6 @@ function pdfannotator_export_contents($cm, $baseurl) { return $contents; } -/** - * Register the ability to handle drag and drop file uploads - * @return array containing details of the files / types the mod can handle - */ -// function pdfannotator_dndupload_register() { - // return array('files' => array( - // array('extension' => 'pdf', 'message' => get_string('dnduploadpdfannotator', 'mod_pdfannotator')) - // )); -// } - -/** - * Handle a file that has been uploaded - * @param object $uploadinfo details of the file / content that has been uploaded - * @return int instance id of the newly created mod - */ -// function pdfannotator_dndupload_handle($uploadinfo) { -// // Gather the required info. -// $data = new stdClass(); -// $data->course = $uploadinfo->course->id; -// $data->name = $uploadinfo->displayname; -// $data->intro = ''; -// $data->introformat = FORMAT_HTML; -// $data->coursemodule = $uploadinfo->coursemodule; -// $data->files = $uploadinfo->draftitemid; -// -// // Set the display options to the site defaults. -// $config = get_config('pdfannotator');// -// -// return pdfannotator_add_instance($data, null); -// } - /** * Mark the activity completed (if required) and trigger the course_module_viewed event. * @@ -537,10 +513,10 @@ function pdfannotator_export_contents($cm, $baseurl) { function pdfannotator_view($pdfannotator, $course, $cm, $context) { // Trigger course_module_viewed event. - $params = array( + $params = [ 'context' => $context, 'objectid' => $pdfannotator->id, - ); + ]; $event = \mod_pdfannotator\event\course_module_viewed::create($params); $event->add_record_snapshot('course_modules', $cm); @@ -562,8 +538,8 @@ function pdfannotator_view($pdfannotator, $course, $cm, $context) { * @return stdClass an object with the different type of areas indicating if they were updated or not * @since Moodle 3.2 */ -function pdfannotator_check_updates_since(cm_info $cm, $from, $filter = array()) { - $updates = course_check_module_updates_since($cm, $from, array('content'), $filter); +function pdfannotator_check_updates_since(cm_info $cm, $from, $filter = []) { + $updates = course_check_module_updates_since($cm, $from, ['content'], $filter); return $updates; } @@ -593,15 +569,16 @@ function mod_pdfannotator_core_calendar_provide_event_action(calendar_event $eve ); } +// phpcs:disable moodle.Commenting.TodoComment /** * Returns all annotations comments since a given time in specified annotator. * * @todo Document this functions args - * @param $activities - * @param $index - * @param $timestart - * @param $courseid - * @param $cmid + * @param array $activities + * @param int $index + * @param int $timestart + * @param int $courseid + * @param int $cmid * @param int $userid * @param int $groupid * @throws dml_exception @@ -613,13 +590,13 @@ function pdfannotator_get_recent_mod_activity(&$activities, &$index, $timestart, if ($COURSE->id == $courseid) { $course = $COURSE; } else { - $course = $DB->get_record('course', array('id' => $courseid)); + $course = $DB->get_record('course', ['id' => $courseid]); } $modinfo = get_fast_modinfo($course); $cm = $modinfo->cms[$cmid]; - $params = array($timestart, $cm->instance); + $params = [$timestart, $cm->instance]; if ($userid) { $userselect = "AND u.id = ? AND c.visibility='public'"; @@ -640,8 +617,9 @@ function pdfannotator_get_recent_mod_activity(&$activities, &$index, $timestart, $allnames = get_all_user_name_fields(true, 'u'); } - if (!$posts = $DB->get_records_sql("SELECT p.*,c.id, c.userid AS userid, c.visibility, c.content, c.timecreated, c.annotationid, c.isquestion, - $allnames, u.email, u.picture, u.imagealt, u.email, a.page + if (!$posts = $DB->get_records_sql("SELECT p.*,c.id, c.userid AS userid, c.visibility, c.content, c.timecreated, + c.annotationid, c.isquestion, $allnames, u.email, u.picture, u.imagealt, u.email, + a.page FROM {pdfannotator} p JOIN {pdfannotator_annotations} a ON a.pdfannotatorid=p.id JOIN {pdfannotator_comments} c ON c.annotationid = a.id @@ -651,7 +629,7 @@ function pdfannotator_get_recent_mod_activity(&$activities, &$index, $timestart, ORDER BY p.id ASC ", $params)) { // Order by initial posting date. return; } - $printposts = array(); + $printposts = []; $context = context_course::instance($courseid); foreach ($posts as $post) { if (!pdfannotator_can_see_comment($post, $context)) { @@ -682,7 +660,6 @@ function pdfannotator_get_recent_mod_activity(&$activities, &$index, $timestart, $tmpactivity->visible = $post->visibility; $tmpactivity->user = new stdClass(); - // $additionalfields = array('id' => 'userid', 'picture', 'imagealt', 'email'); $additionalfields = explode(',', user_picture::fields()); $tmpactivity->user = username_load_fields_from_object($tmpactivity->user, $post, null, $additionalfields); $tmpactivity->user->id = $post->userid; @@ -727,9 +704,9 @@ function pdfannotator_print_recent_mod_activity($activity, $courseid, $detail, $ if (!$authorhidden) { $picture = $OUTPUT->user_picture($activity->user, $pictureoptions); } else { - // $pictureoptions = [ 'courseid' => $courseid, 'link' => $authorhidden, 'alttext' => $authorhidden, ]; $pic = $OUTPUT->image_url('/u/f2'); - $picture = '' . get_string('anonymous', 'pdfannotator') . ''; + $picture = '' . get_string('anonymous', 'pdfannotator') .
+            ''; } $output .= html_writer::tag('td', $picture, ['class' => 'userpicture', 'valign' => 'top']); @@ -743,10 +720,10 @@ function pdfannotator_print_recent_mod_activity($activity, $courseid, $detail, $ $aname = s($activity->name); $output .= $OUTPUT->image_icon('icon', $aname, $activity->type); } - $isquestion = ($content->isquestion) ? '' . get_string('question', 'pdfannotator')
-            . ' ' : ''; - $discussionurl = new moodle_url('/mod/pdfannotator/view.php', ['id' => $activity->cmid, 'page' => $content->page, 'annoid' => $content->id, 'commid' => $content->commid]); - // $discussionurl->set_anchor('p' . $activity->content->id); + $isquestion = ($content->isquestion) ? '' .
+        get_string('question', 'pdfannotator') . ' ' : ''; + $discussionurl = new moodle_url('/mod/pdfannotator/view.php', ['id' => $activity->cmid, 'page' => $content->page, + 'annoid' => $content->id, 'commid' => $content->commid]); $output .= html_writer::link($discussionurl, ($isquestion . $content->discussion)); $output .= html_writer::end_div(); @@ -775,7 +752,7 @@ function pdfannotator_print_recent_mod_activity($activity, $courseid, $detail, $ /** * Initialize the editor for editing a comment. - * @param type $args + * @param array $args * @return string */ function mod_pdfannotator_output_fragment_open_edit_comment_editor($args) { @@ -804,14 +781,15 @@ function mod_pdfannotator_output_fragment_open_edit_comment_editor($args) { /** * Initialize the editor for adding a comment. - * @param type $args + * @param array $args * @return string */ function mod_pdfannotator_output_fragment_open_add_comment_editor($args) { $context = context_module::instance($args['cmid']); $data = pdfannotator_data_preprocessing($context, 'id_pdfannotator_content', 0); - $text = file_prepare_draft_area($data['draftItemId'], $context->id, 'mod_pdfannotator', 'post', 0, pdfannotator_get_editor_options($context)); + $text = file_prepare_draft_area($data['draftItemId'], $context->id, 'mod_pdfannotator', 'post', + 0, pdfannotator_get_editor_options($context)); $out = ''; $out = html_writer::empty_tag('input', ['type' => 'hidden', 'class' => 'pdfannotator_' . $args['action'] . 'comment' . '_editoritemid', diff --git a/locallib.php b/locallib.php index 0745e75..f2b67c6 100644 --- a/locallib.php +++ b/locallib.php @@ -37,21 +37,28 @@ /** * Display embedded pdfannotator file. - * @param object $pdfannotator + * + * @param stdClass $pdfannotator * @param object $cm * @param object $course - * @param stored_file $file main file - * @return does not return + * @param object $file + * @param int $page + * @param int $annoid + * @param int $commid + * @return void + * @throws coding_exception */ function pdfannotator_display_embed($pdfannotator, $cm, $course, $file, $page = 1, $annoid = null, $commid = null) { global $CFG, $PAGE, $OUTPUT, $USER; - // The revision attribute's existance is demanded by moodle for versioning and could be saved in the pdfannotator table in the future. + // The revision attribute's existance is demanded by moodle for versioning and could be saved in the pdfannotator table in the + // future. // Note, however, that we forbid file replacement in order to prevent a change of meaning in other people's comments. $pdfannotator->revision = 1; $context = context_module::instance($cm->id); - $path = '/' . $context->id . '/mod_pdfannotator/content/' . $pdfannotator->revision . $file->get_filepath() . $file->get_filename(); + $path = '/' . $context->id . '/mod_pdfannotator/content/' . $pdfannotator->revision . $file->get_filepath() . + $file->get_filename(); $fullurl = file_encode_url($CFG->wwwroot . '/pluginfile.php', $path, false); $documentobject = new stdClass(); @@ -94,7 +101,8 @@ function pdfannotator_display_embed($pdfannotator, $cm, $course, $file, $page = $editorsettings = new stdClass(); $editorsettings->active_editor = get_class(editors_get_preferred_editor(FORMAT_HTML)); - $params = [$cm, $documentobject, $context->id, $USER->id, $capabilities, $toolbarsettings, $page, $annoid, $commid, $editorsettings]; + $params = [$cm, $documentobject, $context->id, $USER->id, $capabilities, $toolbarsettings, $page, $annoid, $commid, + $editorsettings]; $PAGE->requires->js_init_call('adjustPdfannotatorNavbar', null, true); $PAGE->requires->js_init_call('startIndex', $params, true); // The renderer renders the original index.php / takes the template and renders it. @@ -109,6 +117,13 @@ function pdfannotator_display_embed($pdfannotator, $cm, $course, $file, $page = die; } +/** + * Function to get the image options of the editor. + * + * @return stdClass + * @throws dml_exception + * @throws moodle_exception + */ function pdfannotator_get_image_options_editor() { $imageoptions = new \stdClass(); $imageoptions->maxbytes = get_config('mod_pdfannotator', 'maxbytes'); @@ -120,6 +135,13 @@ function pdfannotator_get_image_options_editor() { return $imageoptions; } +/** + * Function to get the editor options. + * + * @param \context $context the context of the pdfannotator instance + * @return array + * @throws dml_exception + */ function pdfannotator_get_editor_options($context) { $options = []; $options = [ @@ -139,15 +161,33 @@ function pdfannotator_get_editor_options($context) { return $options; } +/** + * Function to rewrite the relative link in the content of a comment. + * + * @param stdClass $content + * @param int $commentid + * @param \context $context the context of the pdfannotator instance + * @return array|mixed|string|string[] + */ function pdfannotator_get_relativelink($content, $commentid, $context) { preg_match('/@@PLUGINFILE@@/', $content, $matches); if ($matches) { - $relativelink = file_rewrite_pluginfile_urls($content, 'pluginfile.php', $context->id, 'mod_pdfannotator', 'post', $commentid); + $relativelink = file_rewrite_pluginfile_urls($content, 'pluginfile.php', $context->id, 'mod_pdfannotator', + 'post', $commentid); return $relativelink; } return $content; } +/** + * Function to extract images from the content of a comment. + * + * @param array $contentarr + * @param int $itemid + * @param \context $context the context of the pdfannotator instance + * @return array + * @throws moodle_exception + */ function pdfannotator_extract_images($contentarr, $itemid, $context=null) { // Remove quotes here, in case if there is no math form. if (gettype($contentarr) === 'string') { @@ -167,6 +207,17 @@ function pdfannotator_extract_images($contentarr, $itemid, $context=null) { return $res; } +/** + * Function to split the content of a comment into parts, where each part is either an image or text. + * + * @param stdClass $content + * @param array $res + * @param int $itemid + * @param \context $context the context of the pdfannotator instance + * @return mixed + * @throws coding_exception + * @throws moodle_exception + */ function pdfannotator_split_content_image($content, $res, $itemid, $context=null) { global $CFG; // Gets all files in the comment with id itemid. @@ -274,6 +325,16 @@ function pdfannotator_split_content_image($content, $res, $itemid, $context=null return $res; } +/** + * Function to preprocess data for the editor. + * + * @param \context $context the context of the pdfannotator instance + * @param textarea_texteditor $textarea + * @param int $draftitemid + * @return array + * @throws dml_exception + * @throws moodle_exception + */ function pdfannotator_data_preprocessing($context, $textarea, $draftitemid = 0) { global $PAGE; @@ -297,14 +358,14 @@ function pdfannotator_data_preprocessing($context, $textarea, $draftitemid = 0) if (!$imagebtn) { $editor->use_editor($textarea, $options); } else { - // initialize Filepicker if image button is active. + // Initialize Filepicker if image button is active. $args = new \stdClass(); - // need these three to filter repositories list. + // Need these three to filter repositories list. $args->accepted_types = ['web_image']; $args->return_types = 15; $args->context = $context; $args->env = 'filepicker'; - // advimage plugin + // Advimage plugin. $imageoptions = (object)initialise_filepicker($args); $imageoptions->context = $context; $imageoptions->client_id = uniqid(); @@ -327,8 +388,22 @@ function pdfannotator_data_preprocessing($context, $textarea, $draftitemid = 0) /** * Same function as core, however we need to add files into the existing draft area! * Copied from hsuforum. + * + * @param int $draftitemid + * @param int $contextid + * @param string $component + * @param object $filearea + * @param int $itemid + * @param array|null $options + * @param string|null $text + * @return array|string|string[]|null + * @throws coding_exception + * @throws dml_exception + * @throws file_exception + * @throws stored_file_creation_exception */ -function pdfannotator_file_prepare_draft_area(&$draftitemid, $contextid, $component, $filearea, $itemid, ?array $options=null, ?string $text=null) { +function pdfannotator_file_prepare_draft_area(&$draftitemid, $contextid, $component, $filearea, $itemid, ?array $options=null, + ?string $text=null) { global $CFG, $USER, $CFG, $DB; $options = (array)$options; @@ -346,8 +421,8 @@ function pdfannotator_file_prepare_draft_area(&$draftitemid, $contextid, $compon if (!is_null($itemid) && $files = $fs->get_area_files($contextid, $component, $filearea, $itemid)) { foreach ($files as $file) { if ($file->is_directory() && $file->get_filepath() === '/') { - // we need a way to mark the age of each draft area, - // by not copying the root dir we force it to be created automatically with current timestamp + // We need a way to mark the age of each draft area, + // by not copying the root dir we force it to be created automatically with current timestamp. continue; } if (!$options['subdirs'] && ($file->is_directory() || $file->get_filepath() !== '/')) { @@ -364,8 +439,8 @@ function pdfannotator_file_prepare_draft_area(&$draftitemid, $contextid, $compon // XXX: This is a hack for file manager (MDL-28666) // File manager needs to know the original file information before copying // to draft area, so we append these information in mdl_files.source field - // {@link file_storage::search_references()} - // {@link file_storage::search_references_count()} + // {@see file_storage::search_references()} + // {@see file_storage::search_references_count()}. $sourcefield = $file->get_source(); $newsourcefield = new \stdClass; $newsourcefield->source = $sourcefield; @@ -378,70 +453,114 @@ function pdfannotator_file_prepare_draft_area(&$draftitemid, $contextid, $compon $original->filepath = $file->get_filepath(); $newsourcefield->original = \file_storage::pack_reference($original); $draftfile->set_source(serialize($newsourcefield)); - // End of file manager hack + // End of file manager hack. } } if (!is_null($text)) { - // at this point there should not be any draftfile links yet, + // At this point there should not be any draftfile links yet, // because this is a new text from database that should still contain the @@pluginfile@@ links - // this happens when developers forget to post process the text + // this happens when developers forget to post process the text. $text = str_replace("\"$CFG->httpswwwroot/draftfile.php", "\"$CFG->httpswwwroot/brokenfile.php#", $text); } if (is_null($text)) { return null; } - // relink embedded files - editor can not handle @@PLUGINFILE@@ ! + // Relink embedded files - editor can not handle @@PLUGINFILE@@ ! return file_rewrite_pluginfile_urls($text, 'draftfile.php', $usercontext->id, 'user', 'draft', $draftitemid, $options); } +/** + * Function to get the name of a pdfannotator instance by its id. + * + * @param int $id + * @return false|mixed + * @throws dml_exception + */ function pdfannotator_get_instance_name($id) { global $DB; - return $DB->get_field('pdfannotator', 'name', array('id' => $id), $strictness = MUST_EXIST); + return $DB->get_field('pdfannotator', 'name', ['id' => $id], $strictness = MUST_EXIST); } +/** + * Function to get the course name by course id. + * + * @param int $courseid + * @return false|mixed + * @throws dml_exception + */ function pdfannotator_get_course_name_by_id($courseid) { global $DB; - return $DB->get_field('course', 'fullname', array('id' => $courseid), $strictness = MUST_EXIST); + return $DB->get_field('course', 'fullname', ['id' => $courseid], $strictness = MUST_EXIST); } +/** + * Function to get the username by user id. + * + * @param int $userid + * @return string + * @throws dml_exception + */ function pdfannotator_get_username($userid) { global $DB; - $user = $DB->get_record('user', array('id' => $userid)); + $user = $DB->get_record('user', ['id' => $userid]); return fullname($user); } +/** + * Function to get the id of an annotation type by its name. + * + * @param string $typename + * @return void + * @throws dml_exception + */ function pdfannotator_get_annotationtype_id($typename) { global $DB; if ($typename == 'point') { $typename = 'pin'; } - $result = $DB->get_records('pdfannotator_annotationtypes', array('name' => $typename)); + $result = $DB->get_records('pdfannotator_annotationtypes', ['name' => $typename]); foreach ($result as $r) { return $r->id; } } +/** + * Function to get the name of an annotation type by its id. + * + * @param int $typeid + * @return void + * @throws dml_exception + */ function pdfannotator_get_annotationtype_name($typeid) { global $DB; - $result = $DB->get_records('pdfannotator_annotationtypes', array('id' => $typeid)); + $result = $DB->get_records('pdfannotator_annotationtypes', ['id' => $typeid]); foreach ($result as $r) { return $r->name; } } +/** + * Function to handle LaTeX formulae in the text. + * + * @param \context $context the context of the pdfannotator instance + * @param string $subject + * @return array|string + * @throws dml_exception + */ function pdfannotator_handle_latex($context, string $subject) { global $CFG; $latexapi = get_config('mod_pdfannotator', 'latexapi'); - // Look for these formulae: $$ ... $$, \( ... \) and \[ ... \] + // phpcs:disable Squiz.PHP.CommentedOutCode + // Look for these formulae: $$ ... $$, \( ... \) and \[ ... \]. // !!! keep indentation! $pattern = <<<'SIGN' ~(?:\$\$.*?\$\$)|(?:\\\(.*?\\\))|(?:\\\[.*?\\\])~ SIGN; - $matches = array(); + $matches = []; $hits = preg_match_all($pattern, $subject, $matches, PREG_OFFSET_CAPTURE); if ($hits == 0) { @@ -480,7 +599,7 @@ function pdfannotator_handle_latex($context, string $subject) { $string = str_replace('\begin{align*}', '', $string); $string = str_replace('\end{align*}', '', $string); - // Find any backslash preceding a ( or [ and replace it with \backslash + // Find any backslash preceding a ( or [ and replace it with \backslash. $pattern = '~\\\\(?=[\\\(\\\[])~'; $string = preg_replace($pattern, '\\backslash', $string); $match[0] = $string; @@ -499,12 +618,19 @@ function pdfannotator_handle_latex($context, string $subject) { return $result; } +/** + * Function takes a latex code string, processes it with Moodle's latex filter, + * + * @param \context $context the context of the pdfannotator instance + * @param string $string + * @return array|false + */ function pdfannotator_process_latex_moodle($context, $string) { global $CFG; require_once($CFG->libdir . '/moodlelib.php'); require_once($CFG->dirroot . '/filter/tex/latex.php'); require_once($CFG->dirroot . '/filter/tex/lib.php'); - $result = array(); + $result = []; $tex = new latex(); $md5 = md5($string); $image = $tex->render($string, $md5 . 'png'); @@ -524,8 +650,8 @@ function pdfannotator_process_latex_moodle($context, $string) { * Function takes a latex code string, modifies and url encodes it for the Google Api to process, * and returns the resulting image along with its height * - * @param type $string - * @return type + * @param string $string + * @return string */ function pdfannotator_process_latex_google(string $string) { @@ -534,13 +660,14 @@ function pdfannotator_process_latex_google(string $string) { if ($length <= 200) { // Google API constraint XXX find better alternative if possible. $latexdata = urlencode($string); $requesturl = LATEX_TO_PNG_REQUEST . $latexdata; - $im = @file_get_contents($requesturl); // '@' suppresses warnings so that one failed google request doesn't prevent the pdf from being printed, - // but just the one formula from being presented as a picture. + $im = @file_get_contents($requesturl); // Char '@' suppresses warnings so that one failed google request doesn't prevent the + // pdf from being printed, but just the one formula from being presented as a picture. } if ($im != null) { $array = []; try { - list($width, $height) = getimagesize($requesturl); // XXX alternative: acess height by decoding the string (saving the extra server request)? + // XXX alternative: access height by decoding the string (saving the extra server request)? + list($width, $height) = getimagesize($requesturl); if ($height != null) { $imagedata = IMAGE_PREFIX . base64_encode($im); // Image. $array['image'] = $imagedata; @@ -555,20 +682,45 @@ function pdfannotator_process_latex_google(string $string) { } } +/** + * Send a notification message to the manager when a question is forwarded. + * + * @param array $recipients + * @param array $messageparams + * @param object $course + * @param object $cm + * @param \context $context the context of the pdfannotator instance + * @return void + * @throws coding_exception + */ function pdfannotator_send_forward_message($recipients, $messageparams, $course, $cm, $context) { $name = 'forwardedquestion'; $text = new stdClass(); $module = get_string('modulename', 'pdfannotator'); $modulename = format_string($cm->name, true); - $text->text = pdfannotator_format_notification_message_text($course, $cm, $context, $module, $modulename, $messageparams, $name); + $text->text = pdfannotator_format_notification_message_text($course, $cm, $context, $module, $modulename, $messageparams, + $name); $text->url = $messageparams->urltoquestion; foreach ($recipients as $recipient) { - $text->html = pdfannotator_format_notification_message_html($course, $cm, $context, $module, $modulename, $messageparams, $name, $recipient); + $text->html = pdfannotator_format_notification_message_html($course, $cm, $context, $module, $modulename, $messageparams, + $name, $recipient); pdfannotator_notify_manager($recipient, $course, $cm, $name, $text); } } +/** + * Send a notification message to the manager. + * + * @param stdClass $recipient + * @param object $course + * @param object $cm + * @param string $name + * @param string $messagetext + * @param bool $anonymous + * @return false|int|mixed + * @throws coding_exception + */ function pdfannotator_notify_manager($recipient, $course, $cm, $name, $messagetext, $anonymous = false) { global $USER; @@ -593,16 +745,30 @@ function pdfannotator_notify_manager($recipient, $course, $cm, $name, $messagete $message->notification = 1; // For personal messages '0'. Important: the 1 without '' and 0 with ''. $message->contexturl = $messagetext->url; $message->contexturlname = 'Context name'; - $content = array('*' => array('header' => ' test ', 'footer' => ' test ')); // Extra content for specific processor. + $content = ['*' => ['header' => ' test ', 'footer' => ' test ']]; // Extra content for specific processor. $messageid = message_send($message); return $messageid; } -function pdfannotator_format_notification_message_text($course, $cm, $context, $modulename, $pdfannotatorname, $paramsforlanguagestring, $messagetype) { +/** + * Format a notification message for text. + * + * @param object $course + * @param object $cm + * @param \context $context the context of the pdfannotator instance + * @param string $modulename + * @param string $pdfannotatorname + * @param string $paramsforlanguagestring + * @param string $messagetype + * @return string + * @throws coding_exception + */ +function pdfannotator_format_notification_message_text($course, $cm, $context, $modulename, $pdfannotatorname, + $paramsforlanguagestring, $messagetype) { global $CFG; - $formatparams = array('context' => $context->get_course_context()); + $formatparams = ['context' => $context->get_course_context()]; $posttext = format_string($course->shortname, true, $formatparams) . ' -> ' . $modulename . @@ -610,24 +776,28 @@ function pdfannotator_format_notification_message_text($course, $cm, $context, $ format_string($pdfannotatorname, true, $formatparams) . "\n"; $posttext .= '---------------------------------------------------------------------' . "\n"; $posttext .= "\n"; - $posttext .= get_string($messagetype . 'text', 'pdfannotator', $paramsforlanguagestring) . "\n---------------------------------------------------------------------\n"; + $posttext .= get_string($messagetype . 'text', 'pdfannotator', $paramsforlanguagestring) . + "\n---------------------------------------------------------------------\n"; return $posttext; } /** * Format a notification for HTML. * - * @param string $messagetype - * @param stdClass $info * @param stdClass $course + * @param stdClass $cm * @param stdClass $context * @param string $modulename - * @param stdClass $coursemodule - * @param string $assignmentname + * @param string $pdfannotatorname + * @param stdClass $report + * @param string $messagetype + * @param int $recipientid + * @return string */ -function pdfannotator_format_notification_message_html($course, $cm, $context, $modulename, $pdfannotatorname, $report, $messagetype, $recipientid) { +function pdfannotator_format_notification_message_html($course, $cm, $context, $modulename, $pdfannotatorname, $report, + $messagetype, $recipientid) { global $CFG, $USER; - $formatparams = array('context' => $context->get_course_context()); + $formatparams = ['context' => $context->get_course_context()]; $posthtml = '

' . '' . format_string($course->shortname, true, $formatparams) . @@ -641,15 +811,22 @@ function pdfannotator_format_notification_message_html($course, $cm, $context, $ $posthtml .= '


'; $report->urltoreport = $CFG->wwwroot . '/mod/pdfannotator/view.php?id=' . $cm->id . '&action=overviewreports'; $posthtml .= '

' . get_string($messagetype . 'html', 'pdfannotator', $report) . '

'; - $linktonotificationsettingspage = new moodle_url('/message/notificationpreferences.php', array('userid' => $recipientid)); + $linktonotificationsettingspage = new moodle_url('/message/notificationpreferences.php', ['userid' => $recipientid]); $linktonotificationsettingspage = $linktonotificationsettingspage->__toString(); $posthtml .= '

'; - $posthtml .= '

' . get_string('unsubscribe_notification', 'pdfannotator', $linktonotificationsettingspage) . '

'; + $posthtml .= '

' . get_string('unsubscribe_notification', 'pdfannotator', + $linktonotificationsettingspage) . '

'; return $posthtml; } /** * Internal function - create click to open text with link. + * + * @param stdClass $file + * @param string $revision + * @param string $extra + * @return lang_string|string + * @throws coding_exception */ function pdfannotator_get_clicktoopen($file, $revision, $extra = '') { global $CFG; @@ -665,6 +842,10 @@ function pdfannotator_get_clicktoopen($file, $revision, $extra = '') { /** * Internal function - create click to open text with link. + * + * @param stdClass $file + * @param string $revision + * @return string */ function pdfannotator_get_clicktodownload($file, $revision) { global $CFG; @@ -701,7 +882,7 @@ function pdfannotator_print_header($pdfannotator, $cm, $course) { * @return string Size and type or empty string if show options are not enabled */ function pdfannotator_get_file_details($pdfannotator, $cm) { - $filedetails = array(); + $filedetails = []; $context = context_module::instance($cm->id); $fs = get_file_storage(); @@ -748,6 +929,7 @@ function pdfannotator_print_intro($pdfannotator, $cm, $course, $ignoresettings = /** * Print warning that file can not be found. + * * @param object $pdfannotator * @param object $cm * @param object $course @@ -757,7 +939,9 @@ function pdfannotator_print_filenotfound($pdfannotator, $cm, $course) { global $DB, $OUTPUT; pdfannotator_print_header($pdfannotator, $cm, $course); - // pdfannotator_print_heading($pdfannotator, $cm, $course);//TODO Method is not defined. + // phpcs:disable Squiz.PHP.CommentedOutCode + // phpcs:disable moodle.Commenting.TodoComment + // Pdfannotator_print_heading($pdfannotator, $cm, $course);//TODO Method is not defined. pdfannotator_print_intro($pdfannotator, $cm, $course); echo $OUTPUT->notification(get_string('filenotfound', 'pdfannotator')); @@ -772,12 +956,14 @@ function pdfannotator_print_filenotfound($pdfannotator, $cm, $course) { * *Drawings and textboxes cannot be commented. In their case (only), * therefore, annotations are counted. * + * @param int $annotatorid + * @return int */ function pdfannotator_get_number_of_new_activities($annotatorid) { global $DB; - $parameters = array(); + $parameters = []; $parameters[] = $annotatorid; $parameters[] = strtotime("-1 day"); @@ -804,24 +990,26 @@ function pdfannotator_get_datetime_of_last_modification($annotatorid) { global $DB; // 1. When was the last time the annotator itself (i.e. its title, description or pdf) was modified? - $timemodified = $DB->get_record('pdfannotator', array('id' => $annotatorid), 'timemodified', MUST_EXIST); + $timemodified = $DB->get_record('pdfannotator', ['id' => $annotatorid], 'timemodified', MUST_EXIST); $timemodified = $timemodified->timemodified; // 2. When was the last time an annotation or a comment was added in the specified annotator? $sql = "SELECT max(a.timecreated) AS last_annotation, max(c.timemodified) AS last_comment " . "FROM {pdfannotator_annotations} a LEFT OUTER JOIN {pdfannotator_comments} c ON a.id = c.annotationid " . "WHERE a.pdfannotatorid = ?"; - $newposts = $DB->get_records_sql($sql, array($annotatorid)); + $newposts = $DB->get_records_sql($sql, [$annotatorid]); if (!empty($newposts)) { foreach ($newposts as $entry) { - // 2.a) If there is an annotation younger than the creation/modification of the annotator, set timemodified to the annotation time. + // 2.a) If there is an annotation younger than the creation/modification of the annotator, + // set timemodified to the annotation time. if (!empty($entry->last_annotation) && ($entry->last_annotation > $timemodified)) { $timemodified = $entry->last_annotation; } - // 2.b) If there is a comment younger than the creation/modification of the annotator or its newest annotation, set timemodified to the comment time. + // 2.b) If there is a comment younger than the creation/modification of the annotator or its newest annotation, + // set timemodified to the comment time. if (!empty($entry->last_comment) && ($entry->last_comment > $timemodified)) { $timemodified = $entry->last_comment; } @@ -835,6 +1023,11 @@ function pdfannotator_get_datetime_of_last_modification($annotatorid) { */ class pdfannotator_content_file_info extends file_info_stored { + /** + * Returns the parent file info object. + * + * @return file_info|null + */ public function get_parent() { if ($this->lf->get_filepath() === '/' && $this->lf->get_filename() === '.') { return $this->browser->get_file_info($this->context); @@ -842,6 +1035,11 @@ public function get_parent() { return parent::get_parent(); } + /** + * Returns the visible name of the file. + * + * @return string + */ public function get_visible_name() { if ($this->lf->get_filepath() === '/' && $this->lf->get_filename() === '.') { return $this->topvisiblename; @@ -851,6 +1049,13 @@ public function get_visible_name() { } +/** + * Sets the main file for the PDF annotator. + * + * @param stdClass $data + * @return void + * @throws coding_exception + */ function pdfannotator_set_mainfile($data) { global $DB; $fs = get_file_storage(); @@ -859,7 +1064,7 @@ function pdfannotator_set_mainfile($data) { $context = context_module::instance($cmid); if ($draftitemid) { - file_save_draft_area_files($draftitemid, $context->id, 'mod_pdfannotator', 'content', 0, array('subdirs' => true)); + file_save_draft_area_files($draftitemid, $context->id, 'mod_pdfannotator', 'content', 0, ['subdirs' => true]); } $files = $fs->get_area_files($context->id, 'mod_pdfannotator', 'content', 0, 'sortorder', false); if (count($files) == 1) { @@ -869,6 +1074,12 @@ function pdfannotator_set_mainfile($data) { } } +/** + * Renders the list item actions for the PDF annotator. + * + * @param array|null $actions + * @return bool|string + */ function pdfannotator_render_listitem_actions(?array $actions = null) { $menu = new action_menu(); $menu->attributes['class'] .= ' course-item-actions item-actions'; @@ -876,7 +1087,8 @@ function pdfannotator_render_listitem_actions(?array $actions = null) { foreach ($actions as $key => $action) { $hasitems = true; $menu->add(new action_menu_link( - $action['url'], $action['icon'], $action['string'], in_array($key, []), ['data-action' => $key, 'class' => 'action-' . $key] + $action['url'], $action['icon'], $action['string'], in_array($key, []), ['data-action' => $key, + 'class' => 'action-' . $key] )); } if (!$hasitems) { @@ -885,11 +1097,26 @@ function pdfannotator_render_listitem_actions(?array $actions = null) { return pdfannotator_render_action_menu($menu); } +/** + * Renders the action menu for the list item actions. + * + * @param action_menu $menu + * @return bool|string + * @throws \core\exception\coding_exception + */ function pdfannotator_render_action_menu($menu) { global $OUTPUT; return $OUTPUT->render($menu); } +/** + * Subscribes all annotations of a user in a specific annotator. + * + * @param int $annotatorid + * @param \context $context the context of the pdfannotator instance + * @return void + * @throws dml_exception + */ function pdfannotator_subscribe_all($annotatorid, $context) { global $DB; $sql = "SELECT id FROM {pdfannotator_annotations} " @@ -902,6 +1129,13 @@ function pdfannotator_subscribe_all($annotatorid, $context) { } } +/** + * Unsubscribes all annotations of a user in a specific annotator. + * + * @param int $annotatorid + * @return void + * @throws dml_exception + */ function pdfannotator_unsubscribe_all($annotatorid) { global $DB, $USER; $sql = "SELECT a.id FROM {pdfannotator_annotations} a JOIN {pdfannotator_subscriptions} s " @@ -913,9 +1147,12 @@ function pdfannotator_unsubscribe_all($annotatorid) { } /** - * Checks wether a user has subscribed to all questions in an annotator. - * Returns 1 if all questions are subscribed, 0 if no questions are subscribed and -1 if at least one but not all questions are subscribed. - * @param type $annotatorid + * Checks whether a user has subscribed to all questions in an annotator. + * + * Returns 1 if all questions are subscribed, 0 if no questions are subscribed and -1 if at least one but not all questions are + * subscribed. + * @param int $annotatorid + * @return int */ function pdfannotator_subscribed($annotatorid) { global $DB, $USER; @@ -938,23 +1175,28 @@ function pdfannotator_subscribed($annotatorid) { } /** + * Function returns a string with the date and time of the user. * - * @param type $timestamp + * @param int $timestamp * @return string Day, D Month Y, Time */ function pdfannotator_get_user_datetime($timestamp) { - $userdatetime = userdate($timestamp, $format = '', $timezone = 99, $fixday = true, $fixhour = true); // Method in lib/moodlelib.php + // Method in lib/moodlelib.php. + $userdatetime = userdate($timestamp, $format = '', $timezone = 99, $fixday = true, $fixhour = true); return $userdatetime; } /** + * Function returns a short format of the date and time for the user. * - * @param type $timestamp + * @param int $timestamp * @return string */ function pdfannotator_get_user_datetime_shortformat($timestamp) { - $shortformat = get_string('strftimedatetime', 'pdfannotator'); // Format strings in moodle\lang\en\langconfig.php. - $userdatetime = userdate($timestamp, $shortformat, $timezone = 99, $fixday = true, $fixhour = true); // Method in lib/moodlelib.php + // Format strings in moodle\lang\en\langconfig.php. + $shortformat = get_string('strftimedatetime', 'pdfannotator'); + // Method in lib/moodlelib.php. + $userdatetime = userdate($timestamp, $shortformat, $timezone = 99, $fixday = true, $fixhour = true); return $userdatetime; } @@ -962,13 +1204,13 @@ function pdfannotator_get_user_datetime_shortformat($timestamp) { * Function is executed each time one of the overview categories is accessed. * It creates the tab navigation and makes javascript accessible. * - * @param type $CFG - * @param type $PAGE - * @param type $myrenderer - * @param type $taburl - * @param type $action - * @param type $pdfannotator - * @param type $context + * @param int $cmid + * @param renderable $myrenderer + * @param string $taburl + * @param string $action + * @param stdClass $pdfannotator + * @param \context $context the context of the PDF annotator instance + * @return void */ function pdfannotator_prepare_overviewpage($cmid, $myrenderer, $taburl, $action, $pdfannotator, $context) { @@ -995,7 +1237,7 @@ function pdfannotator_prepare_overviewpage($cmid, $myrenderer, $taburl, $action, $capabilities->viewposts = has_capability('mod/pdfannotator:viewposts', $context); $capabilities->viewreports = has_capability('mod/pdfannotator:viewreports', $context); - $params = array($pdfannotator->id, $cmid, $capabilities, $action['action']); + $params = [$pdfannotator->id, $cmid, $capabilities, $action['action']]; $PAGE->requires->js_init_call('startOverview', $params, true); // 1. name of JS function, 2. parameters. } @@ -1003,10 +1245,10 @@ function pdfannotator_prepare_overviewpage($cmid, $myrenderer, $taburl, $action, * Function serves as subcontroller that tells the annotator model to collect * all or all unsolved/solved questions asked in this course. * - * @param int $openannotator * @param int $courseid - * @param type $questionfilter - * @return type + * @param \context $context the context of the PDF annotator instance + * @param int $questionfilter + * @return array */ function pdfannotator_get_questions($courseid, $context, $questionfilter) { @@ -1037,7 +1279,8 @@ function pdfannotator_get_questions($courseid, $context, $questionfilter) { $questions = $DB->get_records_sql($sql, $params); $seehidden = has_capability('mod/pdfannotator:seehiddencomments', $context); - $labelhidden = "
" . 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 = "
$report->report
"; @@ -1978,7 +2398,8 @@ function pdfannotator_reportstable_add_row($thiscourse, $table, $report, $cmid, $dropdown = $myrenderer->render_dropdownmenu(new reportmenu($report, $cmid, $currentpage, $itemsperpage, $reportfilter)); // Add a new row to the reports table. - $table->add_data(array($report->report, $reportedby . '
' . $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 . /** + * Settings script for the pdfannotator module. + * * @package mod_pdfannotator * @copyright 2018 RWTH Aachen (see README.md) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later @@ -51,13 +53,13 @@ get_string('global_setting_use_protected_comments_desc', 'pdfannotator'), 0)); // Define what API to use for converting latex formulas into png. - $options = array(); + $options = []; $options[LATEX_TO_PNG_MOODLE] = get_string("global_setting_latexusemoodle", "pdfannotator"); $options[LATEX_TO_PNG_GOOGLE_API] = get_string("global_setting_latexusegoogle", "pdfannotator"); $settings->add(new admin_setting_configselect('mod_pdfannotator/latexapi', get_string('global_setting_latexapisetting', 'pdfannotator'), get_string('global_setting_latexapisetting_desc', 'pdfannotator'), LATEX_TO_PNG_MOODLE, $options)); - + $name = new lang_string('global_setting_attobuttons', 'pdfannotator'); $desc = new lang_string('global_setting_attobuttons_desc', 'pdfannotator'); $default = 'collapse = collapse @@ -78,7 +80,7 @@ $name = new lang_string('maximumfilesize', 'pdfannotator'); $description = new lang_string('configmaxbytes', 'pdfannotator'); - + $maxbytes = get_config('pdfannotator', 'maxbytes'); $element = new admin_setting_configselect('mod_pdfannotator/maxbytes', $name, diff --git a/tests/generator/lib.php b/tests/generator/lib.php index 5d7f869..38947d9 100644 --- a/tests/generator/lib.php +++ b/tests/generator/lib.php @@ -27,11 +27,12 @@ class mod_pdfannotator_generator extends testing_module_generator { /** * Create a new instance of the PDF Annotation activity. * - * @param array|stdClass|null $record + * @param array|null $record * @param array|null $options * @return stdClass + * @throws coding_exception */ - public function create_instance($record = null, array $options = null) { + public function create_instance(?array $record = null, ?array $options = null) { if (!isset($record['files'])) { $record['files'] = 0; } diff --git a/tests/privacy/provider_test.php b/tests/privacy/provider_test.php index 3189559..18011d0 100644 --- a/tests/privacy/provider_test.php +++ b/tests/privacy/provider_test.php @@ -16,6 +16,7 @@ namespace mod_pdfannotator\privacy; +use core\param; use mod_pdfannotator\privacy\provider; use core_privacy\local\request\approved_contextlist; use core_privacy\local\request\approved_userlist; @@ -29,19 +30,48 @@ * @copyright IT Center RWTH Aachen University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class provider_test extends provider_testcase { +final class provider_test extends provider_testcase { + /** + * @var stdClass + */ protected $course; + /** + * @var \core\context\module|false + */ protected $cmcontext; + /** + * @var stdClass + */ protected $user; + /** + * @var stdClass + */ protected $pdffile; + /** + * @var stdClass + */ protected $annotations; + /** + * @var stdClass + */ protected $questions; + /** + * @var stdClass + */ protected $answers; + /** + * Set up the test environment. + * + * @return void + * @throws \dml_exception + */ public function setUp(): void { global $DB; + parent::setUp(); + $this->resetAfterTest(); // Create a course. @@ -115,7 +145,15 @@ public function setUp(): void { $this->answers[] = $answer; } - public function test_delete_data_for_users() { + /** + * Test the get_users_in_context method. + * + * @covers \mod_pdfannotator\privacy\provider::get_users_in_context + * @return void + * @throws \coding_exception + * @throws \dml_exception + */ + public function test_delete_data_for_users(): void { global $DB; $this->resetAfterTest(); diff --git a/version.php b/version.php index 1b859b3..0038487 100644 --- a/version.php +++ b/version.php @@ -25,7 +25,7 @@ defined('MOODLE_INTERNAL') || die(); $plugin->component = 'mod_pdfannotator'; -$plugin->version = 2025071000; +$plugin->version = 2025071100; $plugin->release = 'PDF Annotator v1.5 release 9'; $plugin->requires = 2021051700; $plugin->maturity = MATURITY_RC; diff --git a/view.php b/view.php index 765837c..b71d9c5 100644 --- a/view.php +++ b/view.php @@ -15,11 +15,14 @@ // along with Moodle. If not, see . /** + * View script for the pdfannotator module. + * * @package mod_pdfannotator * @copyright 2018 RWTH Aachen (see README.md) * @author Ahmad Obeid, Anna Heynkes * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ + require('../../config.php'); require_once($CFG->dirroot . '/mod/pdfannotator/locallib.php'); // Requires lib.php in turn. require_once($CFG->libdir . '/completionlib.php'); @@ -35,7 +38,7 @@ $commid = optional_param('commid', null, PARAM_INT); if ($r) { - if (!$pdfannotator = $DB->get_record('pdfannotator', array('id' => $r))) { + if (!$pdfannotator = $DB->get_record('pdfannotator', ['id' => $r])) { throw new moodle_exception('invalidaccessparameter'); } $cm = get_coursemodule_from_instance('pdfannotator', $pdfannotator->id, $pdfannotator->course, false, MUST_EXIST); @@ -43,7 +46,7 @@ if (!$cm = get_coursemodule_from_id('pdfannotator', $id)) { throw new moodle_exception('invalidcoursemodule'); } - $pdfannotator = $DB->get_record('pdfannotator', array('id' => $cm->instance), '*', MUST_EXIST); + $pdfannotator = $DB->get_record('pdfannotator', ['id' => $cm->instance], '*', MUST_EXIST); } $course = get_course($cm->course); // Get course by id. @@ -58,9 +61,10 @@ // Completion and trigger events. pdfannotator_view($pdfannotator, $course, $cm, $context); -$PAGE->set_url('/mod/pdfannotator/view.php', array('id' => $cm->id)); +$PAGE->set_url('/mod/pdfannotator/view.php', ['id' => $cm->id]); $fs = get_file_storage(); +// phpcs:disable moodle.Commenting.TodoComment $files = $fs->get_area_files($context->id, 'mod_pdfannotator', 'content', 0, 'sortorder DESC, id ASC', false);// TODO Not efficient! if (count($files) < 1) { pdfannotator_print_filenotfound($pdfannotator, $cm, $course);