From a34036f9d84ed885d11aba5f9d528b6b3b4a377e Mon Sep 17 00:00:00 2001 From: Marina Glancy Date: Mon, 25 Sep 2023 17:02:20 +0100 Subject: [PATCH 1/3] WPOS-56 fix codechecker warnings (fixed with phpcbf) --- certificates.php | 4 +- classes/certificate.php | 30 ++++---- classes/customfield/issue_handler.php | 2 +- classes/edit_element_form.php | 2 +- classes/element_helper.php | 34 ++++----- classes/event/certificate_issued.php | 4 +- classes/event/certificate_revoked.php | 4 +- classes/event/certificate_verified.php | 8 +- classes/event/template_created.php | 6 +- classes/event/template_deleted.php | 4 +- classes/event/template_updated.php | 6 +- classes/external/elements.php | 10 +-- classes/external/issues.php | 8 +- classes/external/templates.php | 12 +-- classes/form/certificate_issues.php | 8 +- classes/form/details.php | 2 +- classes/my_certificates_table.php | 12 +-- classes/output/element.php | 4 +- classes/output/template.php | 2 +- classes/output/verify_certificate_result.php | 12 +-- classes/permission.php | 4 +- classes/persistent/element.php | 74 +++++++++---------- classes/persistent/page.php | 32 ++++---- classes/persistent/template.php | 22 +++--- classes/plugin_manager.php | 20 ++--- classes/privacy/provider.php | 2 +- classes/reportbuilder/datasource/issues.php | 6 +- .../reportbuilder/datasource/templates.php | 6 +- .../reportbuilder/local/entities/template.php | 2 +- .../local/systemreports/issues.php | 2 +- .../local/systemreports/templates.php | 2 +- classes/template.php | 14 ++-- classes/upload_image_form.php | 6 +- db/access.php | 42 +++++------ db/events.php | 2 +- db/services.php | 2 +- element/border/classes/element.php | 10 +-- element/code/classes/element.php | 6 +- element/date/tests/element_test.php | 4 +- element/digitalsignature/classes/element.php | 12 +-- element/image/classes/element.php | 10 +-- element/program/tests/element_test.php | 4 +- element/text/tests/element_test.php | 2 +- element/userfield/classes/element.php | 10 +-- element/userfield/tests/element_test.php | 4 +- includes/colourpicker.php | 12 +-- lib.php | 4 +- manage_templates.php | 2 +- my.php | 6 +- template.php | 4 +- tests/behat/behat_tool_certificate.php | 24 +++--- tests/capabilities_test.php | 10 +-- tests/certificate_test.php | 22 +++--- tests/lib_test.php | 16 ++-- tests/my_certificates_table_test.php | 20 ++--- .../reportbuilder/datasource/issues_test.php | 2 +- .../datasource/templates_test.php | 2 +- tests/template_test.php | 24 +++--- tests/upgradelib_test.php | 16 ++-- 59 files changed, 319 insertions(+), 319 deletions(-) diff --git a/certificates.php b/certificates.php index 0a827fe1..7ccddbfa 100644 --- a/certificates.php +++ b/certificates.php @@ -33,7 +33,7 @@ $page = optional_param('page', 0, PARAM_INT); $perpage = optional_param('perpage', \tool_certificate\certificate::ISSUES_PER_PAGE, PARAM_INT); -$pageurl = $url = new moodle_url('/admin/tool/certificate/certificates.php', array('templateid' => $templateid)); +$pageurl = $url = new moodle_url('/admin/tool/certificate/certificates.php', ['templateid' => $templateid]); $PAGE->set_url($pageurl); $template = \tool_certificate\template::instance($templateid); if ($coursecontext = $template->get_context()->get_course_context(false)) { @@ -67,7 +67,7 @@ if ($template->can_issue_to_anybody()) { $data += ['addbutton' => true, 'addbuttontitle' => get_string('issuecertificates', 'tool_certificate'), 'addbuttonurl' => null, 'addbuttonattrs' => ['name' => 'data-tid', 'value' => $template->get_id()], - 'addbuttonicon' => true]; + 'addbuttonicon' => true, ]; } $PAGE->requires->js_call_amd('tool_certificate/issues-list', 'init'); diff --git a/classes/certificate.php b/classes/certificate.php index c7fc6e51..a585739e 100644 --- a/classes/certificate.php +++ b/classes/certificate.php @@ -190,7 +190,7 @@ public static function count_issues_for_course(int $templateid, int $courseid, s $params = [ 'templateid' => $templateid, 'courseid' => $courseid, - 'component' => $component + 'component' => $component, ]; if ($groupmode) { @@ -323,7 +323,7 @@ public static function get_issues_for_user($userid, $limitfrom, $limitnum, $sort ON t.id = ci.templateid WHERE ci.userid = :userid ORDER BY {$sort}"; - return $DB->get_records_sql($sql, array('userid' => $userid), $limitfrom, $limitnum); + return $DB->get_records_sql($sql, ['userid' => $userid], $limitfrom, $limitnum); } /** @@ -499,81 +499,81 @@ public static function create_demo_template(): void { // Create template elements. $str = get_string('demotmplbackground', 'tool_certificate'); $elementrecord = ['pageid' => $page->get_id(), 'name' => $str, 'element' => 'image', - 'data' => json_encode(['width' => 0, 'height' => 0, 'isbackground' => true]), 'sequence' => 1]; + 'data' => json_encode(['width' => 0, 'height' => 0, 'isbackground' => true]), 'sequence' => 1, ]; $element = new \tool_certificate\persistent\element(0, (object)$elementrecord); $element->save(); self::create_demo_element_file($element->get('id'), "{$CFG->dirroot}/{$CFG->admin}/tool/certificate/pix/background.jpg"); $str = get_string('demotmplawardedto', 'tool_certificate'); $elementrecord = ['pageid' => $page->get_id(), 'name' => $str, 'element' => 'text', 'data' => $str, 'font' => 'freesans', - 'fontsize' => 12, 'colour' => '#fff', 'posx' => 25, 'posy' => 25, 'sequence' => 2, 'refpoint' => 0]; + 'fontsize' => 12, 'colour' => '#fff', 'posx' => 25, 'posy' => 25, 'sequence' => 2, 'refpoint' => 0, ]; $element = new \tool_certificate\persistent\element(0, (object)$elementrecord); $element->save(); $str = get_string('demotmplusername', 'tool_certificate'); $elementrecord = ['pageid' => $page->get_id(), 'name' => $str, 'element' => 'userfield', 'data' => 'fullname', 'font' => 'freesansb', 'fontsize' => 26, 'colour' => '#fff', 'posx' => 25, 'posy' => 30, 'sequence' => 3, - 'refpoint' => 0]; + 'refpoint' => 0, ]; $element = new \tool_certificate\persistent\element(0, (object)$elementrecord); $element->save(); $str = get_string('demotmplforcompleting', 'tool_certificate'); $elementrecord = ['pageid' => $page->get_id(), 'name' => $str, 'element' => 'text', 'data' => $str, 'font' => 'freesans', - 'fontsize' => 12, 'colour' => '#fff', 'posx' => 25, 'posy' => 52, 'sequence' => 4, 'refpoint' => 0]; + 'fontsize' => 12, 'colour' => '#fff', 'posx' => 25, 'posy' => 52, 'sequence' => 4, 'refpoint' => 0, ]; $element = new \tool_certificate\persistent\element(0, (object)$elementrecord); $element->save(); $str = get_string('demotmplcoursefullname', 'tool_certificate'); $elementrecord = ['pageid' => $page->get_id(), 'name' => $str, 'element' => 'program', 'font' => 'freesansb', 'fontsize' => 26, 'data' => json_encode(['display' => 'coursefullname']), 'colour' => '#fff', 'posx' => 25, - 'posy' => 57, 'sequence' => 5, 'refpoint' => 0]; + 'posy' => 57, 'sequence' => 5, 'refpoint' => 0, ]; $element = new \tool_certificate\persistent\element(0, (object)$elementrecord); $element->save(); $str = get_string('demotmplawardedon', 'tool_certificate'); $elementrecord = ['pageid' => $page->get_id(), 'name' => $str, 'element' => 'text', 'data' => $str, 'font' => 'freesans', 'fontsize' => 12, 'colour' => '#fff', 'posx' => 25, 'posy' => 80, 'sequence' => 6, - 'refpoint' => 0]; + 'refpoint' => 0, ]; $element = new \tool_certificate\persistent\element(0, (object)$elementrecord); $element->save(); $str = get_string('demotmplissueddate', 'tool_certificate'); $elementrecord = ['pageid' => $page->get_id(), 'name' => $str, 'element' => 'date', 'font' => 'freesansb', 'fontsize' => 12, 'data' => json_encode(['dateitem' => -1, 'dateformat' => 'strftimedate']), 'colour' => '#fff', - 'posx' => 49, 'posy' => 80, 'sequence' => 7, 'refpoint' => 0]; + 'posx' => 49, 'posy' => 80, 'sequence' => 7, 'refpoint' => 0, ]; $element = new \tool_certificate\persistent\element(0, (object)$elementrecord); $element->save(); $str = get_string('demotmplqrcode', 'tool_certificate'); $elementrecord = ['pageid' => $page->get_id(), 'name' => $str, 'element' => 'code', 'font' => 'freesans', 'fontsize' => 12, 'data' => json_encode(['display' => 4]), 'colour' => '#000000', - 'posx' => 44, 'posy' => 157, 'width' => 35, 'sequence' => 8, 'refpoint' => 1]; + 'posx' => 44, 'posy' => 157, 'width' => 35, 'sequence' => 8, 'refpoint' => 1, ]; $element = new \tool_certificate\persistent\element(0, (object)$elementrecord); $element->save(); $str = get_string('demotmplsignature', 'tool_certificate'); $elementrecord = ['pageid' => $page->get_id(), 'name' => $str, 'element' => 'image', 'posx' => 118, 'posy' => 157, - 'data' => json_encode(['width' => 50, 'height' => 0, 'isbackground' => false]), 'sequence' => 9]; + 'data' => json_encode(['width' => 50, 'height' => 0, 'isbackground' => false]), 'sequence' => 9, ]; $element = new \tool_certificate\persistent\element(0, (object)$elementrecord); $element->save(); self::create_demo_element_file($element->get('id'), "{$CFG->dirroot}/{$CFG->admin}/tool/certificate/pix/signature.png"); $elementrecord = ['pageid' => $page->get_id(), 'name' => 'Mary Jones', 'element' => 'text', 'font' => 'freesansb', 'fontsize' => 12, 'data' => 'Mary Jones', 'colour' => '#000000', 'posx' => 141, 'posy' => 181, 'sequence' => 10, - 'refpoint' => 1]; + 'refpoint' => 1, ]; $element = new \tool_certificate\persistent\element(0, (object)$elementrecord); $element->save(); $str = get_string('demotmpldirector', 'tool_certificate'); $elementrecord = ['pageid' => $page->get_id(), 'name' => $str, 'element' => 'text', 'font' => 'freesans', 'fontsize' => 12, 'data' => $str, 'colour' => '#000000', 'posx' => 141, 'posy' => 187, 'sequence' => 11, - 'refpoint' => 1]; + 'refpoint' => 1, ]; $element = new \tool_certificate\persistent\element(0, (object)$elementrecord); $element->save(); $str = get_string('logo', 'admin'); $elementrecord = ['pageid' => $page->get_id(), 'name' => $str, 'element' => 'image', 'posx' => 223, 'posy' => 179, - 'data' => json_encode(['width' => 50, 'height' => 0, 'isbackground' => false]), 'sequence' => 12]; + 'data' => json_encode(['width' => 50, 'height' => 0, 'isbackground' => false]), 'sequence' => 12, ]; $element = new \tool_certificate\persistent\element(0, (object)$elementrecord); $element->save(); $wplogo = "{$CFG->dirroot}/{$CFG->admin}/tool/wp/pix/workplacelogo.png"; @@ -622,7 +622,7 @@ public static function add_expirydate_to_form(MoodleQuickForm &$mform): void { $group[] =& $mform->createElement('date_time_selector', 'expirydateabsolute', ''); // TODO: Missing here "month" and "year" options. See MDL-61624. $group[] =& $mform->createElement('duration', 'expirydaterelative', '', ['defaulunit' => DAYSECS, - 'units' => [DAYSECS, WEEKSECS]]); + 'units' => [DAYSECS, WEEKSECS], ]); $mform->addGroup($group, 'expirydateformgroup', get_string('expirydate', 'tool_certificate'), ' ', false); $mform->setDefault('expirydatetype', self::DATE_EXPIRATION_NEVER); $mform->hideIf('expirydateabsolute', 'expirydatetype', 'noteq', self::DATE_EXPIRATION_ABSOLUTE); diff --git a/classes/customfield/issue_handler.php b/classes/customfield/issue_handler.php index f48f3213..cbbfee51 100644 --- a/classes/customfield/issue_handler.php +++ b/classes/customfield/issue_handler.php @@ -210,7 +210,7 @@ public function ensure_field_exists(string $shortname, string $type = 'text', st try { $config = ['visible' => $visible, 'previewvalue' => $previewvalue] + $config; $record = (object)['type' => $type, 'shortname' => $shortname, 'name' => $displayname ?: $shortname, - 'descriptionformat' => FORMAT_HTML, 'configdata' => json_encode($config)]; + 'descriptionformat' => FORMAT_HTML, 'configdata' => json_encode($config), ]; $field = \core_customfield\field_controller::create(0, $record, $category); } catch (\moodle_exception $e) { return null; diff --git a/classes/edit_element_form.php b/classes/edit_element_form.php index 88ed5f5b..79ab0bae 100644 --- a/classes/edit_element_form.php +++ b/classes/edit_element_form.php @@ -73,7 +73,7 @@ protected function get_element() : element { $this->element = element::instance($this->_ajaxformdata['id']); } else { $this->element = element::instance(0, (object)['pageid' => $this->_ajaxformdata['pageid'], - 'element' => $this->_ajaxformdata['element']]); + 'element' => $this->_ajaxformdata['element'], ]); } } return $this->element; diff --git a/classes/element_helper.php b/classes/element_helper.php index edbcbdeb..b6e36db6 100644 --- a/classes/element_helper.php +++ b/classes/element_helper.php @@ -115,7 +115,7 @@ public static function render_html_content($element, $content) { } else if ($element->get_refpoint() == self::CUSTOMCERT_REF_POINT_TOPCENTER) { $style .= ' text-align: center;'; } - return \html_writer::div($content, '', array('style' => $style)); + return \html_writer::div($content, '', ['style' => $style]); } /** @@ -291,7 +291,7 @@ public static function render_form_element_height($mform, $stringcomponent = 'ce * @param \MoodleQuickForm $mform the edit_form instance. */ public static function render_form_element_refpoint($mform) { - $refpointoptions = array(); + $refpointoptions = []; $refpointoptions[self::CUSTOMCERT_REF_POINT_TOPLEFT] = get_string('alignleft', 'tool_certificate'); $refpointoptions[self::CUSTOMCERT_REF_POINT_TOPCENTER] = get_string('aligncentre', 'tool_certificate'); $refpointoptions[self::CUSTOMCERT_REF_POINT_TOPRIGHT] = get_string('alignright', 'tool_certificate'); @@ -308,7 +308,7 @@ public static function render_form_element_refpoint($mform) { * @return array the validation errors */ public static function validate_form_element_colour($data) { - $errors = array(); + $errors = []; // Validate the colour. if (!self::validate_colour($data['colour'])) { $errors['colour'] = get_string('invalidcolour', 'tool_certificate'); @@ -323,7 +323,7 @@ public static function validate_form_element_colour($data) { * @return array the validation errors */ public static function validate_form_element_position($data) { - $errors = array(); + $errors = []; // Check if posx is not set, or not numeric or less than 0. if (!empty($data['posx']) && !is_numeric($data['posx'])) { @@ -368,7 +368,7 @@ public static function get_font($element) { $font = substr($font, 0, -1); $attr .= 'B'; } - return array($font, $attr); + return [$font, $attr]; } /** @@ -379,7 +379,7 @@ public static function get_font($element) { */ public static function validate_colour($colour) { // List of valid HTML colour names. - $colournames = array( + $colournames = [ 'aliceblue', 'antiquewhite', 'aqua', 'aquamarine', 'azure', 'beige', 'bisque', 'black', 'blanchedalmond', 'blue', 'blueviolet', 'brown', 'burlywood', 'cadetblue', 'chartreuse', @@ -410,8 +410,8 @@ public static function validate_colour($colour) { 'seagreen', 'seashell', 'sienna', 'silver', 'skyblue', 'slateblue', 'slategray', 'slategrey', 'snow', 'springgreen', 'steelblue', 'tan', 'teal', 'thistle', 'tomato', 'turquoise', 'violet', 'wheat', 'white', - 'whitesmoke', 'yellow', 'yellowgreen' - ); + 'whitesmoke', 'yellow', 'yellowgreen', + ]; if (preg_match('/^#?([[:xdigit:]]{3}){1,2}$/', $colour)) { return true; @@ -439,7 +439,7 @@ public static function get_element_sequence($pageid) { FROM {tool_certificate_elements} WHERE pageid = :id"; // Get the current max sequence on this page and add 1 to get the new sequence. - if ($maxseq = $DB->get_record_sql($sql, array('id' => $pageid))) { + if ($maxseq = $DB->get_record_sql($sql, ['id' => $pageid])) { $sequence = $maxseq->maxsequence + 1; } @@ -455,7 +455,7 @@ public static function get_available_element_types() { global $CFG; // Array to store the element types. - $options = array(); + $options = []; $plugins = self::get_enabled_plugins(); @@ -486,11 +486,11 @@ public static function get_enabled_plugins() { $manager = new plugin_manager(); $plugins = $manager->get_sorted_plugins_list(); if (!$plugins) { - return array(); + return []; } // Check they are enabled using get_config (which is cached and hopefully fast). - $enabled = array(); + $enabled = []; foreach ($plugins as $plugin) { $disabled = get_config('certificateelement_' . $plugin, 'disabled'); if (empty($disabled)) { @@ -553,7 +553,7 @@ private static function get_fonts() { */ private static function get_font_sizes() { // Array to store the sizes. - $sizes = array(); + $sizes = []; for ($i = 1; $i <= 200; $i++) { $sizes[$i] = $i; @@ -660,7 +660,7 @@ public static function get_shared_images_list() { $fs = get_file_storage(); // The array used to store the images. - $arrfiles = array(); + $arrfiles = []; if ($files = get_file_storage()->get_area_files(\context_system::instance()->id, 'tool_certificate', 'image', false, 'filename', false)) { foreach ($files as $hash => $file) { @@ -670,7 +670,7 @@ public static function get_shared_images_list() { if (count($arrfiles)) { \core_collator::asort($arrfiles); - $arrfiles = array('0' => get_string('noimage', 'tool_certificate')) + $arrfiles; + $arrfiles = ['0' => get_string('noimage', 'tool_certificate')] + $arrfiles; } return $arrfiles; @@ -683,7 +683,7 @@ public static function get_shared_images_list() { * @return bool whether the element was added (it would not be added if there are no shared images) */ public static function render_shared_image_picker_element($mform) { - $arrfiles = array(); + $arrfiles = []; if ($files = get_file_storage()->get_area_files(\context_system::instance()->id, 'tool_certificate', 'image', false, 'filename', false)) { foreach ($files as $hash => $file) { @@ -696,7 +696,7 @@ public static function render_shared_image_picker_element($mform) { } \core_collator::asort($arrfiles); - $arrfiles = array('0' => get_string('noimage', 'tool_certificate')) + $arrfiles; + $arrfiles = ['0' => get_string('noimage', 'tool_certificate')] + $arrfiles; $mform->addElement('select', 'fileid', get_string('selectsharedimage', 'certificateelement_image'), $arrfiles); return true; } diff --git a/classes/event/certificate_issued.php b/classes/event/certificate_issued.php index 5831b08a..7af35aea 100644 --- a/classes/event/certificate_issued.php +++ b/classes/event/certificate_issued.php @@ -58,8 +58,8 @@ public static function create_from_issue(\stdClass $issue) { 'objectid' => $issue->id, 'relateduserid' => $issue->userid, 'other' => [ - 'code' => $issue->code - ] + 'code' => $issue->code, + ], ]; $event = self::create($data); $event->add_record_snapshot('tool_certificate_issues', $issue); diff --git a/classes/event/certificate_revoked.php b/classes/event/certificate_revoked.php index 2aaf53e7..4dcb66fb 100644 --- a/classes/event/certificate_revoked.php +++ b/classes/event/certificate_revoked.php @@ -86,8 +86,8 @@ public static function create_from_issue(\stdClass $issue) { 'objectid' => $issue->id, 'relateduserid' => $issue->userid, 'other' => [ - 'code' => $issue->code - ] + 'code' => $issue->code, + ], ]; $event = self::create($data); $event->add_record_snapshot('tool_certificate_issues', $issue); diff --git a/classes/event/certificate_verified.php b/classes/event/certificate_verified.php index ba0042d1..e9a096a7 100644 --- a/classes/event/certificate_verified.php +++ b/classes/event/certificate_verified.php @@ -81,14 +81,14 @@ public function get_url() { * @return certificate_issued */ public static function create_from_issue(\stdClass $issue) { - $data = array( + $data = [ 'context' => \context_system::instance(), 'objectid' => $issue->id, 'relateduserid' => $issue->userid, 'other' => [ - 'code' => $issue->code - ] - ); + 'code' => $issue->code, + ], + ]; $event = self::create($data); $event->add_record_snapshot('tool_certificate_issues', $issue); return $event; diff --git a/classes/event/template_created.php b/classes/event/template_created.php index 25336ced..6269f535 100644 --- a/classes/event/template_created.php +++ b/classes/event/template_created.php @@ -71,10 +71,10 @@ public static function get_name() { * @return template_created */ public static function create_from_template(template $template) : template_created { - $data = array( + $data = [ 'context' => $template->get_context(), 'objectid' => $template->get_id(), - ); + ]; $event = self::create($data); $event->add_record_snapshot('tool_certificate_templates', $template->to_record()); return $event; @@ -86,6 +86,6 @@ public static function create_from_template(template $template) : template_creat * @return \moodle_url */ public function get_url() { - return new \moodle_url('/admin/tool/certificate/template.php', array('id' => $this->objectid)); + return new \moodle_url('/admin/tool/certificate/template.php', ['id' => $this->objectid]); } } diff --git a/classes/event/template_deleted.php b/classes/event/template_deleted.php index 35608380..958dec18 100644 --- a/classes/event/template_deleted.php +++ b/classes/event/template_deleted.php @@ -80,10 +80,10 @@ public function get_url() { * @return template_deleted */ public static function create_from_template(template $template) : template_deleted { - $data = array( + $data = [ 'context' => $template->get_context(), 'objectid' => $template->get_id(), - ); + ]; $event = self::create($data); $event->add_record_snapshot('tool_certificate_templates', $template->to_record()); return $event; diff --git a/classes/event/template_updated.php b/classes/event/template_updated.php index 5a2e22be..1ccc7ce2 100644 --- a/classes/event/template_updated.php +++ b/classes/event/template_updated.php @@ -70,7 +70,7 @@ public static function get_name() { * @return \moodle_url */ public function get_url() { - return new \moodle_url('/admin/tool/certificate/template.php', array('id' => $this->objectid)); + return new \moodle_url('/admin/tool/certificate/template.php', ['id' => $this->objectid]); } /** @@ -80,10 +80,10 @@ public function get_url() { * @return template_updated */ public static function create_from_template(template $template): template_updated { - $data = array( + $data = [ 'context' => $template->get_context(), 'objectid' => $template->get_id(), - ); + ]; $event = self::create($data); $event->add_record_snapshot('tool_certificate_templates', $template->to_record()); return $event; diff --git a/classes/external/elements.php b/classes/external/elements.php index 8804d09e..d4468860 100644 --- a/classes/external/elements.php +++ b/classes/external/elements.php @@ -46,9 +46,9 @@ class elements extends \external_api { */ public static function delete_element_parameters() { return new \external_function_parameters( - array( - 'id' => new \external_value(PARAM_INT, 'Element id') - ) + [ + 'id' => new \external_value(PARAM_INT, 'Element id'), + ] ); } @@ -81,12 +81,12 @@ public static function delete_element_returns() { */ public static function update_element_parameters() { return new \external_function_parameters( - array( + [ 'id' => new \external_value(PARAM_INT, 'Element id'), 'sequence' => new \external_value(PARAM_INT, 'Sequence', VALUE_DEFAULT, null), 'posx' => new \external_value(PARAM_INT, 'X position', VALUE_DEFAULT, null), 'posy' => new \external_value(PARAM_INT, 'Y position', VALUE_DEFAULT, null), - ) + ] ); } diff --git a/classes/external/issues.php b/classes/external/issues.php index 66e03994..6be110fa 100644 --- a/classes/external/issues.php +++ b/classes/external/issues.php @@ -44,9 +44,9 @@ class issues extends \external_api { */ public static function revoke_issue_parameters() { return new \external_function_parameters( - array( + [ 'id' => new \external_value(PARAM_INT, 'The issue id'), - ) + ] ); } @@ -91,9 +91,9 @@ public static function revoke_issue_returns() { */ public static function regenerate_issue_file_parameters() { return new \external_function_parameters( - array( + [ 'id' => new \external_value(PARAM_INT, 'The issue id'), - ) + ] ); } diff --git a/classes/external/templates.php b/classes/external/templates.php index 67eac307..02f2156a 100644 --- a/classes/external/templates.php +++ b/classes/external/templates.php @@ -46,10 +46,10 @@ class templates extends \external_api { */ public static function duplicate_template_parameters() { return new \external_function_parameters( - array( + [ 'id' => new \external_value(PARAM_INT, 'Template id'), - 'categoryid' => new \external_value(PARAM_INT, 'Category id', VALUE_DEFAULT, 0) - ) + 'categoryid' => new \external_value(PARAM_INT, 'Category id', VALUE_DEFAULT, 0), + ] ); } @@ -86,9 +86,9 @@ public static function duplicate_template_returns() { */ public static function delete_template_parameters() { return new \external_function_parameters( - array( - 'id' => new \external_value(PARAM_INT, 'Template id') - ) + [ + 'id' => new \external_value(PARAM_INT, 'Template id'), + ] ); } diff --git a/classes/form/certificate_issues.php b/classes/form/certificate_issues.php index 12ff0261..03235fae 100644 --- a/classes/form/certificate_issues.php +++ b/classes/form/certificate_issues.php @@ -67,13 +67,13 @@ public function definition() { $mform->setType('tid', PARAM_INT); // Users. - $options = array( + $options = [ 'ajax' => 'tool_certificate/form-potential-user-selector', 'multiple' => true, - 'data-itemid' => $this->get_template()->get_id() - ); + 'data-itemid' => $this->get_template()->get_id(), + ]; $selectstr = get_string('selectuserstoissuecertificatefor', 'tool_certificate'); - $mform->addElement('autocomplete', 'users', $selectstr, array(), $options); + $mform->addElement('autocomplete', 'users', $selectstr, [], $options); // Expiry date. certificate_manager::add_expirydate_to_form($mform); diff --git a/classes/form/details.php b/classes/form/details.php index 21e776e1..0ef86170 100644 --- a/classes/form/details.php +++ b/classes/form/details.php @@ -187,7 +187,7 @@ public function set_data_for_dynamic_submission(): void { 'id' => $this->template->get_id(), 'name' => $this->template->get_name(), 'shared' => $this->template->get_shared(), - 'categoryid' => $this->template->get_category_id()]); + 'categoryid' => $this->template->get_category_id(), ]); } else { $data = template::instance()->new_page()->to_record(); unset($data->id, $data->templateid); diff --git a/classes/my_certificates_table.php b/classes/my_certificates_table.php index 59c9afbc..f8913db3 100644 --- a/classes/my_certificates_table.php +++ b/classes/my_certificates_table.php @@ -57,16 +57,16 @@ public function __construct($userid, $download = null) { parent::__construct('tool_certificate_my_certificates_table'); $this->userid = $userid; - $columns = array( + $columns = [ 'name', 'timecreated', 'expires', - ); - $headers = array( + ]; + $headers = [ get_string('name'), get_string('issueddate', 'tool_certificate'), get_string('expirydate', 'tool_certificate'), - ); + ]; if (permission::can_verify()) { $columns[] = 'code'; @@ -217,7 +217,7 @@ public function col_linkedin($issue) { 'issueYear' => date('Y', $issue->timecreated), 'issueMonth' => date('m', $issue->timecreated), 'certId' => $issue->code, - 'certUrl' => template::verification_url($issue->code) + 'certUrl' => template::verification_url($issue->code), ]; if ($issue->expires !== '0') { @@ -235,7 +235,7 @@ public function col_linkedin($issue) { return $OUTPUT->action_link($link, '', null, [ 'target' => '_blank', - 'class' => 'd-flex' + 'class' => 'd-flex', ], $icon); } diff --git a/classes/output/element.php b/classes/output/element.php index c9e5aae7..1f0fe123 100644 --- a/classes/output/element.php +++ b/classes/output/element.php @@ -98,7 +98,7 @@ protected function get_other_values(\renderer_base $output): array { 'icon' => $output->render($this->get_element()->get_element_type_image(true)), 'html' => $this->get_element()->render_html(), 'draggable' => $this->get_element()->is_draggable(), - 'showrefpoint' => $this->persistent->get('refpoint') !== null + 'showrefpoint' => $this->persistent->get('refpoint') !== null, ]; } @@ -110,7 +110,7 @@ protected function get_other_values(\renderer_base $output): array { protected function get_format_parameters_for_name() { return [ 'context' => $this->get_element()->get_template()->get_context(), - 'escape' => false + 'escape' => false, ]; } } diff --git a/classes/output/template.php b/classes/output/template.php index ce42ba8b..95c8d86e 100644 --- a/classes/output/template.php +++ b/classes/output/template.php @@ -124,7 +124,7 @@ protected function get_other_values(\renderer_base $output): array { protected function get_format_parameters_for_name() { return [ 'context' => $this->get_template()->get_context(), - 'escape' => false + 'escape' => false, ]; } } diff --git a/classes/output/verify_certificate_result.php b/classes/output/verify_certificate_result.php index 9ed18ab6..72d80132 100644 --- a/classes/output/verify_certificate_result.php +++ b/classes/output/verify_certificate_result.php @@ -88,7 +88,7 @@ class verify_certificate_result implements templatable, renderable { */ public function __construct($issue) { $this->viewurl = template::view_url($issue->code); - $this->userprofileurl = new \moodle_url('/user/view.php', array('id' => $issue->userid)); + $this->userprofileurl = new \moodle_url('/user/view.php', ['id' => $issue->userid]); $this->userfullname = @json_decode($issue->data, true)['userfullname']; $this->certificatename = $issue->certificatename; $strftimedatetime = get_string("strftimedatetime", "langconfig"); @@ -112,24 +112,24 @@ public function export_for_template(\renderer_base $output) { $table->attributes['class'] = 'admintable generaltable mb-2'; $fullnamerow = new html_table_row([ new html_table_cell(get_string('fullname')), - new html_table_cell($this->userfullname) + new html_table_cell($this->userfullname), ]); $certificaterow = new html_table_row([ new html_table_cell(get_string('certificate', 'tool_certificate')), - new html_table_cell($this->certificatename) + new html_table_cell($this->certificatename), ]); $issuedrow = new html_table_row([ new html_table_cell(get_string('issueddate', 'tool_certificate')), - new html_table_cell($this->timecreated) + new html_table_cell($this->timecreated), ]); $expiresrow = new html_table_row([ new html_table_cell(get_string('expirydate', 'tool_certificate')), - new html_table_cell($this->expires) + new html_table_cell($this->expires), ]); $statusrow = new html_table_row([ new html_table_cell(get_string('status')), new html_table_cell($this->expired ? get_string('expired', 'tool_certificate') : - get_string('valid', 'tool_certificate')) + get_string('valid', 'tool_certificate')), ]); $table->data = [ diff --git a/classes/permission.php b/classes/permission.php index 7af9c6d3..5a77458e 100644 --- a/classes/permission.php +++ b/classes/permission.php @@ -213,7 +213,7 @@ public static function can_view_templates_in_context(\context $context): bool { } return has_any_capability(['tool/certificate:issue', 'tool/certificate:manage', - 'tool/certificate:viewallcertificates'], $context); + 'tool/certificate:viewallcertificates', ], $context); } /** @@ -303,7 +303,7 @@ public static function can_view_issue(template $template, \stdClass $issue, ?\co } return has_any_capability(['tool/certificate:issue', 'tool/certificate:viewallcertificates', - 'tool/certificate:manage'] , $context) && + 'tool/certificate:manage', ] , $context) && !self::is_user_hidden_by_tenancy($issue->userid); } diff --git a/classes/persistent/element.php b/classes/persistent/element.php index 80acdbd7..8386cdde 100644 --- a/classes/persistent/element.php +++ b/classes/persistent/element.php @@ -44,63 +44,63 @@ class element extends persistent { * @return array */ protected static function define_properties() { - return array( - 'pageid' => array( - 'type' => PARAM_INT - ), - 'name' => array( + return [ + 'pageid' => [ + 'type' => PARAM_INT, + ], + 'name' => [ 'type' => PARAM_TEXT, - 'default' => '' - ), - 'element' => array( - 'type' => PARAM_ALPHANUMEXT - ), - 'data' => array( + 'default' => '', + ], + 'element' => [ + 'type' => PARAM_ALPHANUMEXT, + ], + 'data' => [ 'type' => PARAM_RAW, 'null' => NULL_ALLOWED, - 'default' => null - ), - 'font' => array( + 'default' => null, + ], + 'font' => [ 'type' => PARAM_NOTAGS, 'null' => NULL_ALLOWED, 'default' => 'freesans', - ), - 'fontsize' => array( + ], + 'fontsize' => [ 'type' => PARAM_INT, 'null' => NULL_ALLOWED, - 'default' => null - ), - 'colour' => array( + 'default' => null, + ], + 'colour' => [ 'type' => PARAM_NOTAGS, 'null' => NULL_ALLOWED, - 'default' => null - ), - 'posx' => array( + 'default' => null, + ], + 'posx' => [ 'type' => PARAM_INT, 'null' => NULL_ALLOWED, - 'default' => null - ), - 'posy' => array( + 'default' => null, + ], + 'posy' => [ 'type' => PARAM_INT, 'null' => NULL_ALLOWED, - 'default' => null - ), - 'width' => array( + 'default' => null, + ], + 'width' => [ 'type' => PARAM_INT, 'null' => NULL_ALLOWED, - 'default' => null - ), - 'refpoint' => array( + 'default' => null, + ], + 'refpoint' => [ 'type' => PARAM_INT, 'null' => NULL_ALLOWED, - 'default' => null - ), - 'sequence' => array( + 'default' => null, + ], + 'sequence' => [ 'type' => PARAM_INT, 'null' => NULL_ALLOWED, - 'default' => null - ), - ); + 'default' => null, + ], + ]; } /** diff --git a/classes/persistent/page.php b/classes/persistent/page.php index b7ffdce9..c19f4d1d 100644 --- a/classes/persistent/page.php +++ b/classes/persistent/page.php @@ -44,31 +44,31 @@ class page extends persistent { * @return array */ protected static function define_properties() { - return array( - 'templateid' => array( - 'type' => PARAM_INT - ), - 'width' => array( + return [ + 'templateid' => [ + 'type' => PARAM_INT, + ], + 'width' => [ 'type' => PARAM_INT, 'default' => 297, - ), - 'height' => array( + ], + 'height' => [ 'type' => PARAM_INT, 'default' => 210, - ), - 'leftmargin' => array( + ], + 'leftmargin' => [ 'type' => PARAM_INT, 'default' => 0, - ), - 'rightmargin' => array( + ], + 'rightmargin' => [ 'type' => PARAM_INT, 'default' => 0, - ), - 'sequence' => array( + ], + 'sequence' => [ 'type' => PARAM_INT, - 'default' => 0 - ), - ); + 'default' => 0, + ], + ]; } /** diff --git a/classes/persistent/template.php b/classes/persistent/template.php index 9b9bf026..43c1932e 100644 --- a/classes/persistent/template.php +++ b/classes/persistent/template.php @@ -45,17 +45,17 @@ class template extends persistent { * @return array */ protected static function define_properties() { - return array( - 'name' => array( - 'type' => PARAM_TEXT - ), - 'contextid' => array( - 'type' => PARAM_INT - ), - 'shared' => array( - 'type' => PARAM_BOOL - ), - ); + return [ + 'name' => [ + 'type' => PARAM_TEXT, + ], + 'contextid' => [ + 'type' => PARAM_INT, + ], + 'shared' => [ + 'type' => PARAM_BOOL, + ], + ]; } /** diff --git a/classes/plugin_manager.php b/classes/plugin_manager.php index 8bb9437d..a6602b32 100644 --- a/classes/plugin_manager.php +++ b/classes/plugin_manager.php @@ -94,10 +94,10 @@ private function view_plugins_table() { // Set up the table. $table = new \flexible_table('pluginsadminttable'); $table->define_baseurl($this->pageurl); - $table->define_columns(array('pluginname', 'version', 'hideshow', 'order', 'settings', 'uninstall')); - $table->define_headers(array(get_string('name'), + $table->define_columns(['pluginname', 'version', 'hideshow', 'order', 'settings', 'uninstall']); + $table->define_headers([get_string('name'), get_string('version'), get_string('hideshow', 'tool_certificate'), - get_string('order'), get_string('settings'), get_string('uninstallplugin', 'core_admin'))); + get_string('order'), get_string('settings'), get_string('uninstallplugin', 'core_admin'), ]); $table->set_attribute('id', 'plugins'); $table->set_attribute('class', 'admintable generaltable'); $table->setup(); @@ -105,7 +105,7 @@ private function view_plugins_table() { $plugins = $this->get_sorted_plugins_list(); foreach ($plugins as $idx => $plugin) { - $row = array(); + $row = []; $class = ''; $row[] = get_string('pluginname', 'certificateelement_' . $plugin); @@ -124,7 +124,7 @@ private function view_plugins_table() { if (!$idx == 0) { $movelinks .= $this->format_icon_link('moveup', $plugin, 't/up', get_string('up')); } else { - $movelinks .= $OUTPUT->spacer(array('width' => 16)); + $movelinks .= $OUTPUT->spacer(['width' => 16]); } if ($idx != count($plugins) - 1) { $movelinks .= $this->format_icon_link('movedown', $plugin, 't/down', get_string('down')); @@ -134,7 +134,7 @@ private function view_plugins_table() { $exists = file_exists($CFG->dirroot . '/'. $CFG->admin . '/tool/certificate/element/' . $plugin . '/settings.php'); if ($row[1] != '' && $exists) { $row[] = \html_writer::link(new \moodle_url('/admin/settings.php', - array('section' => 'certificateelement_' . $plugin)), get_string('settings')); + ['section' => 'certificateelement_' . $plugin]), get_string('settings')); } else { $row[] = ' '; } @@ -189,7 +189,7 @@ public function show_plugin($plugin) { public function get_sorted_plugins_list() { $names = \core_component::get_plugin_list('certificateelement'); - $result = array(); + $result = []; foreach ($names as $name => $path) { $idx = get_config('certificateelement_' . $name, 'sortorder'); @@ -229,9 +229,9 @@ private function format_icon_link($action, $plugin, $icon, $alt) { } return $OUTPUT->action_icon(new \moodle_url($url, - array('action' => $action, 'plugin' => $plugin, 'sesskey' => \sesskey())), - new \pix_icon($icon, $alt, 'moodle', array('title' => $alt)), - null, array('title' => $alt)) . ' '; + ['action' => $action, 'plugin' => $plugin, 'sesskey' => \sesskey()]), + new \pix_icon($icon, $alt, 'moodle', ['title' => $alt]), + null, ['title' => $alt]) . ' '; } /** diff --git a/classes/privacy/provider.php b/classes/privacy/provider.php index 7f5f7f76..ad540fd9 100644 --- a/classes/privacy/provider.php +++ b/classes/privacy/provider.php @@ -126,7 +126,7 @@ public static function export_user_data(approved_contextlist $contextlist) { ]; writer::with_context($context)->export_data(array_merge($contextpath, [ - clean_param($record->certificatename, PARAM_FILE) + clean_param($record->certificatename, PARAM_FILE), ]), $data); } diff --git a/classes/reportbuilder/datasource/issues.php b/classes/reportbuilder/datasource/issues.php index 42d5a6ba..a28fa6cd 100644 --- a/classes/reportbuilder/datasource/issues.php +++ b/classes/reportbuilder/datasource/issues.php @@ -80,7 +80,7 @@ protected function initialise(): void { $coursecatentityalias = $coursecatentity->get_table_alias('course_categories'); $coursecategoryjoins = [ "JOIN {context} ctx ON ctx.id = {$certificatetempl}.contextid", - "LEFT JOIN {course_categories} {$coursecatentityalias} ON {$coursecatentityalias}.id = ctx.instanceid" + "LEFT JOIN {course_categories} {$coursecatentityalias} ON {$coursecatentityalias}.id = ctx.instanceid", ]; $this->add_entity($coursecatentity ->add_joins($coursecategoryjoins)); @@ -167,7 +167,7 @@ public function get_default_columns(): array { 'issue:timecreated', 'issue:expires', 'issue:codewithlink', - 'user:fullnamewithlink' + 'user:fullnamewithlink', ]; } @@ -181,7 +181,7 @@ public function get_default_filters(): array { 'template:templateselector', 'issue:timecreated', 'issue:expires', - 'user:fullname' + 'user:fullname', ]; } diff --git a/classes/reportbuilder/datasource/templates.php b/classes/reportbuilder/datasource/templates.php index c169c65d..c75f5e1d 100644 --- a/classes/reportbuilder/datasource/templates.php +++ b/classes/reportbuilder/datasource/templates.php @@ -59,7 +59,7 @@ protected function initialise(): void { $coursecategories = $coursecatentity->get_table_alias('course_categories'); $coursecategoryjoins = [ "JOIN {context} ctx ON ctx.id = {$certificatetempl}.contextid", - "LEFT JOIN {course_categories} {$coursecategories} ON {$coursecategories}.id = ctx.instanceid" + "LEFT JOIN {course_categories} {$coursecategories} ON {$coursecategories}.id = ctx.instanceid", ]; $this->add_entity($coursecatentity ->add_joins($coursecategoryjoins)); @@ -107,7 +107,7 @@ public function get_default_columns(): array { return [ 'template:name', 'course_category:name', - 'template:timecreated' + 'template:timecreated', ]; } @@ -120,7 +120,7 @@ public function get_default_filters(): array { return [ 'template:name', 'course_category:name', - 'template:timecreated' + 'template:timecreated', ]; } diff --git a/classes/reportbuilder/local/entities/template.php b/classes/reportbuilder/local/entities/template.php index 6ec843ac..0ee0fc5d 100644 --- a/classes/reportbuilder/local/entities/template.php +++ b/classes/reportbuilder/local/entities/template.php @@ -46,7 +46,7 @@ class template extends base { */ protected function get_default_table_aliases(): array { return [ - 'tool_certificate_templates' => 'tct' + 'tool_certificate_templates' => 'tct', ]; } diff --git a/classes/reportbuilder/local/systemreports/issues.php b/classes/reportbuilder/local/systemreports/issues.php index 2dd12b33..9ca11a7a 100644 --- a/classes/reportbuilder/local/systemreports/issues.php +++ b/classes/reportbuilder/local/systemreports/issues.php @@ -203,7 +203,7 @@ protected function add_actions(): void { new moodle_url('/admin/tool/certificate/view.php', ['code' => ':code']), new pix_icon('i/search', ''), [ - 'target' => '_blank' + 'target' => '_blank', ], false, new lang_string('view') diff --git a/classes/reportbuilder/local/systemreports/templates.php b/classes/reportbuilder/local/systemreports/templates.php index e4a40e3a..68d15823 100644 --- a/classes/reportbuilder/local/systemreports/templates.php +++ b/classes/reportbuilder/local/systemreports/templates.php @@ -163,7 +163,7 @@ protected function add_actions(): void { new moodle_url('/admin/tool/certificate/view.php', ['templateid' => ':id', 'preview' => 1, 'code' => 'previewing']), new pix_icon('i/search', ''), [ - 'target' => '_blank' + 'target' => '_blank', ], false, new lang_string('preview') diff --git a/classes/template.php b/classes/template.php index bcfa364f..de0e99b2 100644 --- a/classes/template.php +++ b/classes/template.php @@ -133,7 +133,7 @@ public function save_page($data) { $time = time(); // Get the existing pages and save the page data. - if ($pages = $DB->get_records('tool_certificate_pages', array('templateid' => $data->tid))) { + if ($pages = $DB->get_records('tool_certificate_pages', ['templateid' => $data->tid])) { // Loop through existing pages. foreach ($pages as $page) { // Get the name of the fields we want from the form. @@ -196,7 +196,7 @@ public function delete_page($pageid) { SET sequence = sequence - 1 WHERE templateid = :templateid AND sequence > :sequence"; - $DB->execute($sql, array('templateid' => $this->get_id(), 'sequence' => $sequence)); + $DB->execute($sql, ['templateid' => $this->get_id(), 'sequence' => $sequence]); $this->pages = null; } @@ -209,7 +209,7 @@ public function delete_element($elementid) { global $DB; // Ensure element exists and delete it. - $element = $DB->get_record('tool_certificate_elements', array('id' => $elementid), '*', MUST_EXIST); + $element = $DB->get_record('tool_certificate_elements', ['id' => $elementid], '*', MUST_EXIST); if (!array_key_exists($element->pageid, $this->get_pages())) { return; } @@ -219,7 +219,7 @@ public function delete_element($elementid) { \tool_certificate\element::instance(0, $element)->delete(); } catch (\moodle_exception $e) { // The plugin files are missing, so just remove the entry from the DB. - $DB->delete_records('tool_certificate_elements', array('id' => $elementid)); + $DB->delete_records('tool_certificate_elements', ['id' => $elementid]); } // Now we want to decrease the sequence numbers of the elements @@ -228,7 +228,7 @@ public function delete_element($elementid) { SET sequence = sequence - 1 WHERE pageid = :pageid AND sequence > :sequence"; - $DB->execute($sql, array('pageid' => $element->pageid, 'sequence' => $element->sequence)); + $DB->execute($sql, ['pageid' => $element->pageid, 'sequence' => $element->sequence]); } /** @@ -278,7 +278,7 @@ public function generate_pdf($preview = false, $issue = null, $return = false) { } else { $orientation = 'P'; } - $pdf->AddPage($orientation, array($pagerecord->width, $pagerecord->height)); + $pdf->AddPage($orientation, [$pagerecord->width, $pagerecord->height]); $pdf->SetMargins($pagerecord->leftmargin, 0, $pagerecord->rightmargin); // Get the elements for the page. if ($elements = $page->get_elements()) { @@ -747,7 +747,7 @@ public function create_issue_file(\stdClass $issue, bool $regenerate = false): \ 'filearea' => 'issues', 'itemid' => $issue->id, 'filepath' => '/', - 'filename' => $issue->code . '.pdf' + 'filename' => $issue->code . '.pdf', ]; $fs = get_file_storage(); diff --git a/classes/upload_image_form.php b/classes/upload_image_form.php index e7651595..26d6de5e 100644 --- a/classes/upload_image_form.php +++ b/classes/upload_image_form.php @@ -38,7 +38,7 @@ class upload_image_form extends \moodleform { /** @var array the filemanager options */ - protected $filemanageroptions = array(); + protected $filemanageroptions = []; /** * Form definition. @@ -47,10 +47,10 @@ public function definition() { global $CFG; $mform = $this->_form; - $this->filemanageroptions = array( + $this->filemanageroptions = [ 'maxbytes' => $CFG->maxbytes, 'subdirs' => 1, - 'accepted_types' => 'web_image'); + 'accepted_types' => 'web_image', ]; $mform->addElement('filemanager', 'certificateimage', get_string('uploadimage', 'tool_certificate'), '', $this->filemanageroptions); diff --git a/db/access.php b/db/access.php index c4f84000..bafee35a 100644 --- a/db/access.php +++ b/db/access.php @@ -24,52 +24,52 @@ defined('MOODLE_INTERNAL') || die(); -$capabilities = array( +$capabilities = [ - 'tool/certificate:manage' => array( + 'tool/certificate:manage' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_COURSE, - 'archetypes' => array( + 'archetypes' => [ 'manager' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW, - ) - ), + ], + ], - 'tool/certificate:image' => array( + 'tool/certificate:image' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_SYSTEM, - 'clonepermissionsfrom' => 'tool/certificate:imageforalltenants' - ), + 'clonepermissionsfrom' => 'tool/certificate:imageforalltenants', + ], - 'tool/certificate:issue' => array( + 'tool/certificate:issue' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_COURSE, - 'archetypes' => array( + 'archetypes' => [ 'manager' => CAP_ALLOW, 'teacher' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW, - ) - ), + ], + ], - 'tool/certificate:viewallcertificates' => array( + 'tool/certificate:viewallcertificates' => [ 'captype' => 'read', 'contextlevel' => CONTEXT_COURSE, - 'archetypes' => array( + 'archetypes' => [ 'manager' => CAP_ALLOW, 'teacher' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW, - ) - ), + ], + ], - 'tool/certificate:verify' => array( + 'tool/certificate:verify' => [ 'captype' => 'read', 'contextlevel' => CONTEXT_SYSTEM, - 'archetypes' => array( + 'archetypes' => [ 'guest' => CAP_ALLOW, 'user' => CAP_ALLOW, - ) - ), -); + ], + ], +]; diff --git a/db/events.php b/db/events.php index 1df2c12d..ff13f72d 100644 --- a/db/events.php +++ b/db/events.php @@ -28,6 +28,6 @@ $observers = [ [ 'eventname' => '\core\event\course_content_deleted', - 'callback' => tool_certificate_observer::class . '::on_course_content_deleted' + 'callback' => tool_certificate_observer::class . '::on_course_content_deleted', ], ]; diff --git a/db/services.php b/db/services.php index 434e75bb..63960d73 100644 --- a/db/services.php +++ b/db/services.php @@ -32,7 +32,7 @@ 'description' => 'Revoke an issue for a certificate', 'type' => 'write', 'ajax' => true, - 'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE) + 'services' => [MOODLE_OFFICIAL_MOBILE_SERVICE], ], 'tool_certificate_regenerate_issue_file' => [ 'classname' => \tool_certificate\external\issues::class, diff --git a/element/border/classes/element.php b/element/border/classes/element.php index 65b747a3..9789f2a9 100644 --- a/element/border/classes/element.php +++ b/element/border/classes/element.php @@ -60,7 +60,7 @@ public function render_form_elements($mform) { public function render($pdf, $preview, $user, $issue) { $colour = \TCPDF_COLORS::convertHTMLColorToDec($this->get_colour(), $colour); // Set double width because half of the width will be outside of the page. - $pdf->SetLineStyle(array('width' => 2 * $this->get_data(), 'color' => $colour)); + $pdf->SetLineStyle(['width' => 2 * $this->get_data(), 'color' => $colour]); $pdf->Line(0, 0, $pdf->getPageWidth(), 0); $pdf->Line($pdf->getPageWidth(), 0, $pdf->getPageWidth(), $pdf->getPageHeight()); $pdf->Line(0, $pdf->getPageHeight(), $pdf->getPageWidth(), $pdf->getPageHeight()); @@ -82,16 +82,16 @@ public function render_html() { $style = 'position: absolute; background-color: ' . $this->get_colour() . ''; $html .= \html_writer::tag('div', '', ['data-width' => $width, 'data-height' => $page->height, 'style' => $style, - 'data-posx' => 0, 'data-posy' => 0]); + 'data-posx' => 0, 'data-posy' => 0, ]); $html .= \html_writer::tag('div', '', ['data-width' => $width, 'data-height' => $page->height, 'style' => $style, - 'data-posx' => $page->width - $width, 'data-posy' => 0]); + 'data-posx' => $page->width - $width, 'data-posy' => 0, ]); $html .= \html_writer::tag('div', '', ['data-width' => $page->width, 'data-height' => $width, 'style' => $style, - 'data-posx' => 0, 'data-posy' => 0]); + 'data-posx' => 0, 'data-posy' => 0, ]); $html .= \html_writer::tag('div', '', ['data-width' => $page->width, 'data-height' => $width, 'style' => $style, - 'data-posx' => 0, 'data-posy' => $page->height - $width]); + 'data-posx' => 0, 'data-posy' => $page->height - $width, ]); return $html; } diff --git a/element/code/classes/element.php b/element/code/classes/element.php index 83a99909..07cd278e 100644 --- a/element/code/classes/element.php +++ b/element/code/classes/element.php @@ -173,10 +173,10 @@ protected function render_qrcode($pdf, $code) { 'border' => 0, 'vpadding' => 'auto', 'hpadding' => 'auto', - 'fgcolor' => array(0, 0, 0), - 'bgcolor' => array(255, 255, 255), + 'fgcolor' => [0, 0, 0], + 'bgcolor' => [255, 255, 255], 'module_width' => 1, - 'module_height' => 1 + 'module_height' => 1, ]; $codeurl = new \moodle_url("/admin/tool/certificate/index.php", ['code' => $code]); diff --git a/element/date/tests/element_test.php b/element/date/tests/element_test.php index aec2a686..63764476 100644 --- a/element/date/tests/element_test.php +++ b/element/date/tests/element_test.php @@ -53,7 +53,7 @@ public function test_render_html() { $certificate1 = $this->get_generator()->create_template((object)['name' => 'Certificate 1']); $pageid = $this->get_generator()->create_page($certificate1)->get_id(); $formdata = ['name' => 'Date element', 'dateitem' => \certificateelement_date\element::CUSTOMCERT_DATE_ISSUE, - 'dateformat' => 'strftimedateshort']; + 'dateformat' => 'strftimedateshort', ]; $e = $this->get_generator()->create_element($pageid, 'date', $formdata); $this->assertNotEmpty($e->render_html()); @@ -83,7 +83,7 @@ public function test_save_unique_data() { $pageid = $this->get_generator()->create_page($certificate1)->get_id(); $e = $this->get_generator()->new_element($pageid, 'date'); $newdata = (object)['dateitem' => \certificateelement_date\element::CUSTOMCERT_DATE_ISSUE, - 'dateformat' => 'strftimedate']; + 'dateformat' => 'strftimedate', ]; $expected = json_encode($newdata); $e->save_form_data($newdata); $el = $DB->get_record('tool_certificate_elements', ['id' => $e->get_id()]); diff --git a/element/digitalsignature/classes/element.php b/element/digitalsignature/classes/element.php index 3cc3f1dd..5cf64cf8 100644 --- a/element/digitalsignature/classes/element.php +++ b/element/digitalsignature/classes/element.php @@ -30,7 +30,7 @@ class element extends \certificateelement_image\element { /** * @var array The file manager options for the certificate. */ - protected $signaturefilemanageroptions = array(); + protected $signaturefilemanageroptions = []; /** * Constructor. @@ -42,7 +42,7 @@ protected function __construct() { 'maxbytes' => $COURSE->maxbytes, 'subdirs' => 0, 'accepted_types' => ['.crt'], - 'maxfiles' => 1 + 'maxfiles' => 1, ]; parent::__construct(); @@ -131,7 +131,7 @@ public function render_html() { $size = element_helper::calculate_image_size('none', ['width' => 140, 'height' => 140], (float)$imageinfo['width'], (float)$imageinfo['height']); return \html_writer::div(' ', 'm-0 p-0', ['style' => 'border: 1px dotted black;', - 'data-width' => $size['width'], 'data-height' => $size['height']]); + 'data-width' => $size['width'], 'data-height' => $size['height'], ]); } else { // Link to the file. $url = \moodle_url::make_pluginfile_url($file->get_contextid(), $file->get_component(), $file->get_filearea(), @@ -178,7 +178,7 @@ private function calculate_additional_data($data) { 'signaturereason' => $data->signaturereason, 'signaturecontactinfo' => $data->signaturecontactinfo, 'width' => !empty($data->width) ? (int) $data->width : 0, - 'height' => !empty($data->height) ? (int) $data->height : 0 + 'height' => !empty($data->height) ? (int) $data->height : 0, ]; // Array of data we will be storing in the database. @@ -203,7 +203,7 @@ private function calculate_additional_data($data) { 'signaturefilearea' => $signaturefile->get_filearea(), 'signatureitemid' => $signaturefile->get_itemid(), 'signaturefilepath' => $signaturefile->get_filepath(), - 'signaturefilename' => $signaturefile->get_filename() + 'signaturefilename' => $signaturefile->get_filename(), ]; } } @@ -234,7 +234,7 @@ public function render($pdf, $preview, $user, $issue) { 'Name' => $imageinfo->signaturename, 'Location' => $imageinfo->signaturelocation, 'Reason' => $imageinfo->signaturereason, - 'ContactInfo' => $imageinfo->signaturecontactinfo + 'ContactInfo' => $imageinfo->signaturecontactinfo, ]; $pdf->setSignature('file://' . $location, '', $imageinfo->signaturepassword, '', 2, $info); $size = element_helper::calculate_image_size($file, [], $imageinfo->width, $imageinfo->height); diff --git a/element/image/classes/element.php b/element/image/classes/element.php index 73d99b8a..7865ce22 100644 --- a/element/image/classes/element.php +++ b/element/image/classes/element.php @@ -38,7 +38,7 @@ class element extends \tool_certificate\element { /** * @var array The file manager options. */ - protected $filemanageroptions = array(); + protected $filemanageroptions = []; /** * Constructor. @@ -46,12 +46,12 @@ class element extends \tool_certificate\element { protected function __construct() { global $COURSE; - $this->filemanageroptions = array( + $this->filemanageroptions = [ 'maxbytes' => $COURSE->maxbytes, 'subdirs' => 0, 'accepted_types' => 'web_image', - 'maxfiles' => 1 - ); + 'maxfiles' => 1, + ]; parent::__construct(); } @@ -129,7 +129,7 @@ public function save_form_data(\stdClass $data) { private function calculate_additional_data($data) { $arrtostore = [ 'width' => !empty($data->width) ? (int) $data->width : 0, - 'height' => !empty($data->height) ? (int) $data->height : 0 + 'height' => !empty($data->height) ? (int) $data->height : 0, ]; if ($this->can_be_used_as_a_background()) { $arrtostore['isbackground'] = !empty($data->isbackground); diff --git a/element/program/tests/element_test.php b/element/program/tests/element_test.php index 98572ade..090c19cc 100644 --- a/element/program/tests/element_test.php +++ b/element/program/tests/element_test.php @@ -115,7 +115,7 @@ public function test_format_issue_data() { $user1 = $this->getDataGenerator()->create_user(); $data = ['certificationname' => 'Certification 1', 'programname' => 'Program 1', 'programcompletiondate' => '1/2/12', - 'programcompletedcourses' => '

Course1,
Course2

']; + 'programcompletedcourses' => '

Course1,
Course2

', ]; $issueid = $certificate1->issue_certificate($user1->id, null, $data, 'tool_program'); $issue = (object)['id' => $issueid]; @@ -175,7 +175,7 @@ public function test_render_content() { // Generate PDF for issue. $issue = $this->get_generator()->issue($certificate1, $this->getDataGenerator()->create_user(), null, ['programname' => 'P', 'certificationname' => 'C', 'programcompletiondate' => '1/1/11', - 'programcompletedcourses' => 'list'], 'tool_certification'); + 'programcompletedcourses' => 'list', ], 'tool_certification'); $filecontents = $this->get_generator()->generate_pdf($certificate1, false, $issue); $filesize = core_text::strlen($filecontents); $this->assertTrue($filesize > 30000 && $filesize < 90000); diff --git a/element/text/tests/element_test.php b/element/text/tests/element_test.php index 76dfd5e5..d746dd02 100644 --- a/element/text/tests/element_test.php +++ b/element/text/tests/element_test.php @@ -63,7 +63,7 @@ public function test_render_html() { $pageid = $this->get_generator()->create_page($certificate1)->get_id(); $e = $this->get_generator()->new_element($pageid, 'text'); $formdata = (object)['name' => 'Text element', 'text' => 'Here is the text', - 'element' => 'text', 'pageid' => $pageid]; + 'element' => 'text', 'pageid' => $pageid, ]; $e->save_form_data($formdata); $html = $e->render_html(); $this->assertStringContainsString('Here is the text', $html); diff --git a/element/userfield/classes/element.php b/element/userfield/classes/element.php index 6c3af37e..a22962b6 100644 --- a/element/userfield/classes/element.php +++ b/element/userfield/classes/element.php @@ -51,7 +51,7 @@ public function render_form_elements($mform) { }; // Get the user profile fields. - $userfields = array( + $userfields = [ 'fullname' => $displayname('fullname'), 'firstname' => $displayname('firstname'), 'lastname' => $displayname('lastname'), @@ -64,11 +64,11 @@ public function render_form_elements($mform) { 'department' => $displayname('department'), 'phone1' => $displayname('phone1'), 'phone2' => $displayname('phone2'), - 'address' => $displayname('address') - ); + 'address' => $displayname('address'), + ]; // Get the user custom fields. $arrcustomfields = \availability_profile\condition::get_custom_profile_fields(); - $customfields = array(); + $customfields = []; foreach ($arrcustomfields as $key => $customfield) { $customfields[$customfield->id] = $key; } @@ -108,7 +108,7 @@ protected function get_user_field_value($user) { if ($field === 'fullname') { return fullname($user); } else if (is_number($field)) { // Must be a custom user profile field. - if ($record = $DB->get_record('user_info_field', array('id' => $field))) { + if ($record = $DB->get_record('user_info_field', ['id' => $field])) { $file = $CFG->dirroot . '/user/profile/field/' . $record->datatype . '/field.class.php'; if (file_exists($file)) { require_once($CFG->dirroot . '/user/profile/lib.php'); diff --git a/element/userfield/tests/element_test.php b/element/userfield/tests/element_test.php index d386839e..ea15d6c3 100644 --- a/element/userfield/tests/element_test.php +++ b/element/userfield/tests/element_test.php @@ -67,9 +67,9 @@ public function test_render_html() { $this->assertTrue(strpos($e->render_html(), '@') !== false); // Add a custom field of textarea type. - $id1 = $DB->insert_record('user_info_field', array( + $id1 = $DB->insert_record('user_info_field', [ 'shortname' => 'frogdesc', 'name' => 'Description of frog', 'categoryid' => 1, - 'datatype' => 'textarea')); + 'datatype' => 'textarea', ]); $formdata = (object)['name' => 'User custom field element', 'userfield' => $id1]; $e = $this->get_generator()->create_element($pageid, 'userfield', $formdata); diff --git a/includes/colourpicker.php b/includes/colourpicker.php index e93dcf13..13ce3f09 100644 --- a/includes/colourpicker.php +++ b/includes/colourpicker.php @@ -41,7 +41,7 @@ class moodlequickform_tool_certificate_colourpicker extends moodlequickform_edit * @param string $value */ public function setvalue($value) { - $this->updateAttributes(array('value' => $value)); + $this->updateAttributes(['value' => $value]); } /** @@ -59,13 +59,13 @@ public function getvalue() { public function tohtml() { global $PAGE, $OUTPUT; - $PAGE->requires->js_init_call('M.util.init_colour_picker', array($this->getAttribute('id'), null)); + $PAGE->requires->js_init_call('M.util.init_colour_picker', [$this->getAttribute('id'), null]); $content = ''; - $content .= html_writer::start_tag('div', array('class' => 'form-colourpicker defaultsnext')); + $content .= html_writer::start_tag('div', ['class' => 'form-colourpicker defaultsnext']); $content .= html_writer::tag('div', $OUTPUT->pix_icon('i/loading', get_string('loading', 'admin'), 'moodle', - array('class' => 'loadingicon')), array('class' => 'admin_colourpicker clearfix')); - $content .= html_writer::empty_tag('input', array('type' => 'text', 'id' => $this->getAttribute('id'), - 'name' => $this->getName(), 'value' => $this->getValue(), 'size' => '12')); + ['class' => 'loadingicon']), ['class' => 'admin_colourpicker clearfix']); + $content .= html_writer::empty_tag('input', ['type' => 'text', 'id' => $this->getAttribute('id'), + 'name' => $this->getName(), 'value' => $this->getValue(), 'size' => '12', ]); $content .= html_writer::end_tag('div'); return $content; diff --git a/lib.php b/lib.php index b7c1917d..36134488 100644 --- a/lib.php +++ b/lib.php @@ -162,7 +162,7 @@ function tool_certificate_inplace_editable($itemtype, $itemid, $newvalue) { function tool_certificate_get_fontawesome_icon_map() { return [ 'tool_certificate:download' => 'fa-download', - 'tool_certificate:linkedin' => 'fa-linkedin-square' + 'tool_certificate:linkedin' => 'fa-linkedin-square', ]; } @@ -277,7 +277,7 @@ function tool_certificate_theme_workplace_menu_items(): array { 'url' => new moodle_url("/admin/tool/certificate/manage_templates.php"), 'name' => get_string('certificates', 'tool_certificate'), 'imageurl' => $OUTPUT->image_url('icon', 'tool_certificate')->out(false), - 'isglobal' => component_class_callback('\tool_tenant\permission', 'can_switch_tenant', [], false) + 'isglobal' => component_class_callback('\tool_tenant\permission', 'can_switch_tenant', [], false), ]; } return $menuitems; diff --git a/manage_templates.php b/manage_templates.php index 4c816095..347361a6 100644 --- a/manage_templates.php +++ b/manage_templates.php @@ -50,7 +50,7 @@ if (\tool_certificate\permission::can_create()) { $data += ['addbutton' => true, 'addbuttontitle' => get_string('createtemplate', 'tool_certificate'), 'addbuttonurl' => null, 'addbuttonattrs' => ['name' => 'data-contextid', 'value' => $context->id], - 'addbuttonicon' => true]; + 'addbuttonicon' => true, ]; } $PAGE->requires->js_call_amd('tool_certificate/templates-list', 'init'); diff --git a/my.php b/my.php index b1888fbb..4d595301 100644 --- a/my.php +++ b/my.php @@ -28,8 +28,8 @@ $download = optional_param('download', null, PARAM_ALPHA); $page = optional_param('page', 0, PARAM_INT); $perpage = optional_param('perpage', \tool_certificate\certificate::ISSUES_PER_PAGE, PARAM_INT); -$pageurl = $url = new moodle_url('/admin/tool/certificate/my.php', array('userid' => $userid, - 'page' => $page, 'perpage' => $perpage)); +$pageurl = $url = new moodle_url('/admin/tool/certificate/my.php', ['userid' => $userid, + 'page' => $page, 'perpage' => $perpage, ]); // Requires a login. require_login(); @@ -56,7 +56,7 @@ $PAGE->set_pagelayout('standard'); -$PAGE->navbar->add(get_string('profile'), new moodle_url('/user/profile.php', array('id' => $user->id))); +$PAGE->navbar->add(get_string('profile'), new moodle_url('/user/profile.php', ['id' => $user->id])); $PAGE->navbar->add(get_string('mycertificates', 'tool_certificate')); echo $OUTPUT->header(); diff --git a/template.php b/template.php index 9bb12688..131f3695 100644 --- a/template.php +++ b/template.php @@ -35,11 +35,11 @@ $template = \tool_certificate\template::instance($templateid); } -$pageurl = new moodle_url('/admin/tool/certificate/template.php', array('id' => $template->get_id())); +$pageurl = new moodle_url('/admin/tool/certificate/template.php', ['id' => $template->get_id()]); if ($template->get_context()->contextlevel == CONTEXT_COURSE) { $courseid = $template->get_context()->instanceid; require_login($courseid); - $manageurl = new moodle_url('/admin/tool/certificate/manage_templates.php', array('courseid' => $courseid)); + $manageurl = new moodle_url('/admin/tool/certificate/manage_templates.php', ['courseid' => $courseid]); $PAGE->navbar->add(get_string('managetemplates', 'tool_certificate'), $manageurl); $PAGE->set_url($pageurl); } else { diff --git a/tests/behat/behat_tool_certificate.php b/tests/behat/behat_tool_certificate.php index be47f8b7..6261a478 100644 --- a/tests/behat/behat_tool_certificate.php +++ b/tests/behat/behat_tool_certificate.php @@ -57,19 +57,19 @@ public function i_add_the_element_to_the_site_certificate_template_page($element // Click on "Add field" button. $this->execute('behat_general::i_click_on_in_the', - array(get_string('addelement', 'tool_certificate'), "button", - "//*[@data-region='page'][{$pagenum}]", "xpath_element")); + [get_string('addelement', 'tool_certificate'), "button", + "//*[@data-region='page'][{$pagenum}]", "xpath_element", ]); // Wait until the respective element type selector has class .show . $xpath = "//*[@data-region='page'][{$pagenum}]". "//*[@data-region='elementtypeslist' and contains(concat(' ', normalize-space(@class), ' '), ' show ')]"; - $this->execute("behat_general::wait_until_exists", array($this->escape($xpath), "xpath_element")); + $this->execute("behat_general::wait_until_exists", [$this->escape($xpath), "xpath_element"]); // Wait for CSS transition to finish. $this->getSession()->wait(200); // Click on the link in the element type selector. $this->execute('behat_general::i_click_on_in_the', - array($elementname, "link", $xpath, "xpath_element")); + [$elementname, "link", $xpath, "xpath_element"]); } /** @@ -82,12 +82,12 @@ public function i_add_the_element_to_the_site_certificate_template_page($element public function i_verify_the_site_certificate_for_user($templatename, $username) { global $DB; - $template = $DB->get_record('tool_certificate_templates', array('name' => $templatename), '*', MUST_EXIST); - $user = $DB->get_record('user', array('username' => $username), '*', MUST_EXIST); - $issue = $DB->get_record('tool_certificate_issues', array('userid' => $user->id, 'templateid' => $template->id), + $template = $DB->get_record('tool_certificate_templates', ['name' => $templatename], '*', MUST_EXIST); + $user = $DB->get_record('user', ['username' => $username], '*', MUST_EXIST); + $issue = $DB->get_record('tool_certificate_issues', ['userid' => $user->id, 'templateid' => $template->id], '*', MUST_EXIST); - $this->execute('behat_forms::i_set_the_field_to', array(get_string('code', 'tool_certificate'), $issue->code)); + $this->execute('behat_forms::i_set_the_field_to', [get_string('code', 'tool_certificate'), $issue->code]); $this->execute('behat_forms::press_button', get_string('verify', 'tool_certificate')); $this->execute('behat_general::assert_page_contains_text', get_string('valid', 'tool_certificate')); $this->execute('behat_general::assert_page_not_contains_text', get_string('expired', 'tool_certificate')); @@ -122,12 +122,12 @@ public function i_verify_the_site_certificate_with_code($code) { public function i_can_not_verify_the_site_certificate_for_user($templatename, $username) { global $DB; - $template = $DB->get_record('tool_certificate_templates', array('name' => $templatename), '*', MUST_EXIST); - $user = $DB->get_record('user', array('username' => $username), '*', MUST_EXIST); - $issue = $DB->get_record('tool_certificate_issues', array('userid' => $user->id, 'templateid' => $template->id), + $template = $DB->get_record('tool_certificate_templates', ['name' => $templatename], '*', MUST_EXIST); + $user = $DB->get_record('user', ['username' => $username], '*', MUST_EXIST); + $issue = $DB->get_record('tool_certificate_issues', ['userid' => $user->id, 'templateid' => $template->id], '*', MUST_EXIST); - $this->execute('behat_forms::i_set_the_field_to', array(get_string('code', 'tool_certificate'), $issue->code)); + $this->execute('behat_forms::i_set_the_field_to', [get_string('code', 'tool_certificate'), $issue->code]); $this->execute('behat_forms::press_button', get_string('verify', 'tool_certificate')); $this->execute('behat_general::assert_page_contains_text', get_string('notverified', 'tool_certificate')); $this->execute('behat_general::assert_page_not_contains_text', get_string('verified', 'tool_certificate')); diff --git a/tests/capabilities_test.php b/tests/capabilities_test.php index d7e63a03..8266c5a0 100644 --- a/tests/capabilities_test.php +++ b/tests/capabilities_test.php @@ -56,7 +56,7 @@ public function test_can_manage() { $certificate2 = $this->certgenerator->create_template((object)['name' => 'Certificate 2', 'categoryid' => $cat2->id]); $certificate3 = $this->certgenerator->create_template((object)['name' => 'Certificate 3']); - $managerrole = $DB->get_record('role', array('shortname' => 'manager')); + $managerrole = $DB->get_record('role', ['shortname' => 'manager']); $manager = $this->getDataGenerator()->create_user(); $this->getDataGenerator()->role_assign($managerrole->id, $manager->id, context_coursecat::instance($cat1->id)); @@ -97,12 +97,12 @@ public function test_can_verify() { public function test_can_view_admin_tree() { global $DB; - $guest = $DB->get_record('user', array('username' => 'guest')); + $guest = $DB->get_record('user', ['username' => 'guest']); $this->setUser($guest); $this->assertFalse(\tool_certificate\permission::can_view_admin_tree()); - $managerrole = $DB->get_record('role', array('shortname' => 'manager')); + $managerrole = $DB->get_record('role', ['shortname' => 'manager']); $manager = $this->getDataGenerator()->create_user(); $this->getDataGenerator()->role_assign($managerrole->id, $manager->id); @@ -125,7 +125,7 @@ public function test_can_issue_same_tenant() { $cat1 = self::getDataGenerator()->create_category(); $cat2 = self::getDataGenerator()->create_category(); - $managerrole = $DB->get_record('role', array('shortname' => 'manager')); + $managerrole = $DB->get_record('role', ['shortname' => 'manager']); $manager1 = $this->getDataGenerator()->create_user(); $user1 = $this->getDataGenerator()->create_user(); $this->getDataGenerator()->role_assign($managerrole->id, $manager1->id, context_coursecat::instance($cat1->id)); @@ -172,7 +172,7 @@ public function test_can_issue_other_tenant() { $cat1 = self::getDataGenerator()->create_category(); $cat2 = self::getDataGenerator()->create_category(); - $managerrole = $DB->get_record('role', array('shortname' => 'manager')); + $managerrole = $DB->get_record('role', ['shortname' => 'manager']); unassign_capability('moodle/site:viewparticipants', $managerrole->id, \context_system::instance()->id); $manager1 = $this->getDataGenerator()->create_user(); $user1 = $this->getDataGenerator()->create_user(); diff --git a/tests/certificate_test.php b/tests/certificate_test.php index 2705eb79..94460077 100644 --- a/tests/certificate_test.php +++ b/tests/certificate_test.php @@ -93,7 +93,7 @@ public function test_count_issues_for_template() { $this->assertEquals(2, \tool_certificate\certificate::count_issues_for_template($certificate3->get_id())); - $managerrole = $DB->get_record('role', array('shortname' => 'manager')); + $managerrole = $DB->get_record('role', ['shortname' => 'manager']); $manager = $this->getDataGenerator()->create_user(); $this->getDataGenerator()->role_assign($managerrole->id, $manager->id); @@ -128,7 +128,7 @@ public function test_get_issues_for_template() { $this->assertEquals('Certificate 1', $issue->name); // Now test with manager with no permission on all tenants. - $managerrole = $DB->get_record('role', array('shortname' => 'manager')); + $managerrole = $DB->get_record('role', ['shortname' => 'manager']); $manager = $this->getDataGenerator()->create_user(); $this->getDataGenerator()->role_assign($managerrole->id, $manager->id); @@ -344,7 +344,7 @@ public function test_verify() { $this->assertEquals($result->issue->id, $issueid1); // Now test with manager with no permission on all tenants. - $managerrole = $DB->get_record('role', array('shortname' => 'manager')); + $managerrole = $DB->get_record('role', ['shortname' => 'manager']); $manager = $this->getDataGenerator()->create_user(); $this->getDataGenerator()->role_assign($managerrole->id, $manager->id); @@ -399,13 +399,13 @@ public function test_count_templates_in_category() { $category4 = $this->getDataGenerator()->create_category(['name' => 'Cat4', 'parent' => $category2->id]); $template1 = $this->get_generator()->create_template((object)['name' => 'Certificate 1', - 'contextid' => $category1->get_context()->id]); + 'contextid' => $category1->get_context()->id, ]); $template2 = $this->get_generator()->create_template((object)['name' => 'Certificate 2', - 'contextid' => $category2->get_context()->id]); + 'contextid' => $category2->get_context()->id, ]); $template3 = $this->get_generator()->create_template((object)['name' => 'Certificate 3', - 'contextid' => $category4->get_context()->id]); + 'contextid' => $category4->get_context()->id, ]); $template4 = $this->get_generator()->create_template((object)['name' => 'Certificate 4', - 'contextid' => $category4->get_context()->id]); + 'contextid' => $category4->get_context()->id, ]); /* * Now we have @@ -503,16 +503,16 @@ public function test_get_user_extra_field_names(): void { public function calculate_expirydate_provider(): array { return [ 'Expires never' => [ - certificate::DATE_EXPIRATION_NEVER, null, null, null + certificate::DATE_EXPIRATION_NEVER, null, null, null, ], 'Expires on 10 September 2022' => [ - certificate::DATE_EXPIRATION_ABSOLUTE, '10 September 2022', null, '10 September 2022' + certificate::DATE_EXPIRATION_ABSOLUTE, '10 September 2022', null, '10 September 2022', ], 'Expires after 2 weeks from now' => [ - certificate::DATE_EXPIRATION_AFTER, null, 2 * WEEKSECS, '+2 week' + certificate::DATE_EXPIRATION_AFTER, null, 2 * WEEKSECS, '+2 week', ], 'Expires after 5 days from now' => [ - certificate::DATE_EXPIRATION_AFTER, null, 5 * DAYSECS, '+5 day' + certificate::DATE_EXPIRATION_AFTER, null, 5 * DAYSECS, '+5 day', ], ]; } diff --git a/tests/lib_test.php b/tests/lib_test.php index 272fe843..09630ea4 100644 --- a/tests/lib_test.php +++ b/tests/lib_test.php @@ -28,9 +28,9 @@ use advanced_testcase; use tool_certificate_generator; use context_coursecat; -use \tool_certificate\persistent\element; -use \tool_certificate\persistent\page; -use \tool_certificate\persistent\template; +use tool_certificate\persistent\element; +use tool_certificate\persistent\page; +use tool_certificate\persistent\template; /** * Tests for functions in lib.php @@ -71,9 +71,9 @@ public function test_can_course_category_delete() { $cat4 = $this->getDataGenerator()->create_category(['name' => 'Cat4', 'parent' => $cat1->id]); $template1 = $this->get_certificate_generator()->create_template((object)['name' => 'Certificate 1', - 'contextid' => $cat1->get_context()->id]); + 'contextid' => $cat1->get_context()->id, ]); $template2 = $this->get_certificate_generator()->create_template((object)['name' => 'Certificate 2', - 'contextid' => $cat3->get_context()->id]); + 'contextid' => $cat3->get_context()->id, ]); /* * Now we have @@ -112,9 +112,9 @@ public function test_can_course_category_delete_move() { $cat4 = $this->getDataGenerator()->create_category(['name' => 'Cat4', 'parent' => $cat1->id]); $template1 = $this->get_certificate_generator()->create_template((object)['name' => 'Certificate 1', - 'contextid' => $cat1->get_context()->id]); + 'contextid' => $cat1->get_context()->id, ]); $template2 = $this->get_certificate_generator()->create_template((object)['name' => 'Certificate 2', - 'contextid' => $cat3->get_context()->id]); + 'contextid' => $cat3->get_context()->id, ]); /* * Now we have @@ -183,7 +183,7 @@ public function test_delete_category_with_certificates() { 'filearea' => 'element', 'itemid' => $certificateelement2->get_id(), 'filepath' => '/', - 'filename' => 'image.png' + 'filename' => 'image.png', ]; $fs->create_file_from_string($filerecord, 'Cat'); diff --git a/tests/my_certificates_table_test.php b/tests/my_certificates_table_test.php index f9473966..2fe35924 100644 --- a/tests/my_certificates_table_test.php +++ b/tests/my_certificates_table_test.php @@ -105,14 +105,14 @@ public function col_linkedin_provider(): array { 'timecreated' => 1634376554, 'templateid' => '1', 'contextid' => '1', - 'name' => 'Certificate demo template' + 'name' => 'Certificate demo template', ], [ 'name' => 'Certificate demo template', 'issueYear' => '2021', 'issueMonth' => '10', 'certId' => '0123456789SS', - 'certUrl' => 'https://www.example.com/moodle/admin/tool/certificate/index.php?code=0123456789SS' - ], null], + 'certUrl' => 'https://www.example.com/moodle/admin/tool/certificate/index.php?code=0123456789SS', + ], null, ], [(object)[ 'id' => '6', 'expires' => '0', @@ -120,7 +120,7 @@ public function col_linkedin_provider(): array { 'timecreated' => 1500370154, 'templateid' => '1', 'contextid' => '1', - 'name' => 'Certificate demo template' + 'name' => 'Certificate demo template', ], [ 'name' => 'Certificate demo template', 'issueYear' => '2017', @@ -128,7 +128,7 @@ public function col_linkedin_provider(): array { 'certId' => '0123456789SS', 'certUrl' => 'https://www.example.com/moodle/admin/tool/certificate/index.php?code=0123456789SS', 'organizationId' => '123', - ], 123], + ], 123, ], [(object)[ 'id' => '6', 'expires' => '123', @@ -136,7 +136,7 @@ public function col_linkedin_provider(): array { 'timecreated' => 1568626154, 'templateid' => '1', 'contextid' => '1', - 'name' => 'Certificate demo template' + 'name' => 'Certificate demo template', ], [ 'name' => 'Certificate demo template', 'issueYear' => '2019', @@ -144,8 +144,8 @@ public function col_linkedin_provider(): array { 'certId' => '0123456789SS', 'certUrl' => 'https://www.example.com/moodle/admin/tool/certificate/index.php?code=0123456789SS', 'expirationYear' => '1970', - 'expirationMonth' => '01' - ], null], + 'expirationMonth' => '01', + ], null, ], [(object)[ 'id' => '6', 'expires' => '123', @@ -153,7 +153,7 @@ public function col_linkedin_provider(): array { 'timecreated' => 1705573754, 'templateid' => '1', 'contextid' => '1', - 'name' => 'Certificate demo template' + 'name' => 'Certificate demo template', ], [ 'name' => 'Certificate demo template', 'issueYear' => '2024', @@ -163,7 +163,7 @@ public function col_linkedin_provider(): array { 'expirationYear' => '1970', 'expirationMonth' => '01', 'organizationId' => '123', - ], 123] + ], 123, ], ]; } diff --git a/tests/reportbuilder/datasource/issues_test.php b/tests/reportbuilder/datasource/issues_test.php index 96ae537b..8dd6967e 100644 --- a/tests/reportbuilder/datasource/issues_test.php +++ b/tests/reportbuilder/datasource/issues_test.php @@ -95,7 +95,7 @@ public function test_certificate_issues_datasource(): void { $issuecode2 = $DB->get_record('tool_certificate_issues', ['id' => $issueid2]); $contentcerts = [ [$cert1['name'], $issuecode1->code, $user1->firstname . ' '.$user1->lastname], - [$cert2['name'], $issuecode2->code, $user2->firstname . ' '.$user2->lastname] + [$cert2['name'], $issuecode2->code, $user2->firstname . ' '.$user2->lastname], ]; $this->assertEqualsCanonicalizing($contentcerts, $content); } diff --git a/tests/reportbuilder/datasource/templates_test.php b/tests/reportbuilder/datasource/templates_test.php index 2757d3dd..620f5f71 100644 --- a/tests/reportbuilder/datasource/templates_test.php +++ b/tests/reportbuilder/datasource/templates_test.php @@ -86,7 +86,7 @@ public function test_certificate_template_datasource(): void { // Set all expected certificate template values. $contentcerts = [ [$cert1['name'], $newcategory->name, 0], - [$cert2['name'], '', 0] + [$cert2['name'], '', 0], ]; $this->assertEqualsCanonicalizing($contentcerts, $content); diff --git a/tests/template_test.php b/tests/template_test.php index cb0dae5c..4049d5de 100644 --- a/tests/template_test.php +++ b/tests/template_test.php @@ -256,10 +256,10 @@ public function test_save_page() { $pageid = $this->get_generator()->create_page($certificate1)->get_id(); $pagedata = (object)['tid' => $certificate1->get_id(), 'pagewidth_'.$pageid => 333, 'pageheight_'.$pageid => 444, - 'pageleftmargin_'.$pageid => 333, 'pagerightmargin_'.$pageid => 444]; + 'pageleftmargin_'.$pageid => 333, 'pagerightmargin_'.$pageid => 444, ]; $certificate1->save_page($pagedata); $this->assertTrue($DB->record_exists('tool_certificate_pages', ['templateid' => $certificate1->get_id(), - 'width' => 333, 'height' => 444])); + 'width' => 333, 'height' => 444, ])); } /** @@ -359,19 +359,19 @@ public function test_issue_certificate() { $this->assertEquals(2, $DB->count_records('tool_certificate_issues', ['templateid' => $certificate1->get_id()])); $this->assertEquals(1, $DB->count_records('tool_certificate_issues', ['templateid' => $certificate1->get_id(), - 'userid' => $user1->id])); + 'userid' => $user1->id, ])); $this->assertEquals(1, $DB->count_records('tool_certificate_issues', ['templateid' => $certificate1->get_id(), - 'userid' => $user2->id])); + 'userid' => $user2->id, ])); $certificate1->issue_certificate($user1->id); $this->assertEquals(2, $DB->count_records('tool_certificate_issues', ['templateid' => $certificate1->get_id(), - 'userid' => $user1->id])); + 'userid' => $user1->id, ])); $certificate1->issue_certificate($user2->id); $certificate1->issue_certificate($user2->id); $this->assertEquals(3, $DB->count_records('tool_certificate_issues', ['templateid' => $certificate1->get_id(), - 'userid' => $user2->id])); + 'userid' => $user2->id, ])); // Test issue_certificate with courseid. $course = $this->getDataGenerator()->create_course(); @@ -383,7 +383,7 @@ public function test_issue_certificate() { $this->assertEquals($course->id, $issue->courseid); $this->assertEquals(4, $DB->count_records('tool_certificate_issues', ['templateid' => $certificate1->get_id(), - 'userid' => $user2->id])); + 'userid' => $user2->id, ])); } /** @@ -498,11 +498,11 @@ public function test_get_visible_categories_contexts_sql() { $cat3 = $this->getDataGenerator()->create_category(); $this->get_generator()->create_template((object)['name' => 'Template 1', - 'contextid' => context_coursecat::instance($cat1->id)->id]); + 'contextid' => context_coursecat::instance($cat1->id)->id, ]); $this->get_generator()->create_template((object)['name' => 'Template 2', - 'contextid' => context_coursecat::instance($cat2->id)->id]); + 'contextid' => context_coursecat::instance($cat2->id)->id, ]); $this->get_generator()->create_template((object)['name' => 'Template 2', - 'contextid' => context_system::instance()->id]); + 'contextid' => context_system::instance()->id, ]); [$sql, $params] = \tool_certificate\template::get_visible_categories_contexts_sql(); @@ -524,7 +524,7 @@ public function test_move_files_to_new_context() { $cat1 = $this->getDataGenerator()->create_category(); $cat1context = context_coursecat::instance($cat1->id); $template1 = $this->get_generator()->create_template((object)['name' => 'Template 1', - 'contextid' => context_coursecat::instance($cat1->id)->id]); + 'contextid' => context_coursecat::instance($cat1->id)->id, ]); $page1 = $this->get_generator()->create_page($template1); $imageelement = $this->get_generator()->create_element($page1->get_id(), 'image'); @@ -536,7 +536,7 @@ public function test_move_files_to_new_context() { 'filearea' => 'element', 'itemid' => $imageelement->get_id(), 'filepath' => '/', - 'filename' => 'image.png' + 'filename' => 'image.png', ]; $file = $fs->create_file_from_string($filerecord, 'Awesome photography'); $filecontent = $file->get_content(); diff --git a/tests/upgradelib_test.php b/tests/upgradelib_test.php index 899a776d..44409d73 100644 --- a/tests/upgradelib_test.php +++ b/tests/upgradelib_test.php @@ -132,15 +132,15 @@ public function test_tool_certificate_upgrade_move_data_to_customfields() { $context = context_system::instance(); $templateid = $DB->insert_record('tool_certificate_templates', (object)['name' => 'Template 01', - 'contextid' => $context->id]); + 'contextid' => $context->id, ]); $id1 = $DB->insert_record($tablename, (object)['component' => 'tool_dynamicrule', 'templateid' => $templateid, - 'data' => '{"certificationname":"","programname":"","completiondate":"","completedcourses":[]}']); + 'data' => '{"certificationname":"","programname":"","completiondate":"","completedcourses":[]}', ]); $id2 = $DB->insert_record($tablename, (object)['component' => 'tool_dynamicrule', 'templateid' => $templateid, 'data' => '{"certificationname":"My cert","programname":"My prog","completiondate":"1546344000",' . - '"completedcourses":["a","b"]}']); + '"completedcourses":["a","b"]}', ]); $id3 = $DB->insert_record($tablename, (object)['component' => 'tool_dynamicrule', 'templateid' => $templateid, - 'data' => json_encode(['coursename' => 'X'])]); + 'data' => json_encode(['coursename' => 'X']), ]); // Create tool_program issue customfields manually if tool_program is not available. if (!class_exists('\\tool_program\\program')) { @@ -309,14 +309,14 @@ public function test_tool_certificate_fix_orphaned_template_element_files() { $cat2context = context_coursecat::instance($cat2->id); // Create a template in category2. $template1 = $this->get_generator()->create_template((object)['name' => 'Template 1', - 'contextid' => context_coursecat::instance($cat2->id)->id]); + 'contextid' => context_coursecat::instance($cat2->id)->id, ]); $page1 = $this->get_generator()->create_page($template1); $imageelement1 = $this->get_generator()->create_element($page1->get_id(), 'image'); // Create a dummy orphaned image file for element1 in a wrong template context (category1). $file1record = ['contextid' => $cat1context->id, 'component' => 'tool_certificate', 'filearea' => 'element', - 'itemid' => $imageelement1->get_id(), 'filepath' => '/', 'filename' => 'image1.png']; + 'itemid' => $imageelement1->get_id(), 'filepath' => '/', 'filename' => 'image1.png', ]; $file1 = $fs->create_file_from_string($file1record, 'Awesome photography'); $file1content = $file1->get_content(); @@ -329,14 +329,14 @@ public function test_tool_certificate_fix_orphaned_template_element_files() { // Create a dummy orphaned image file for element2 in a wrong template context (category1). $file2record = ['contextid' => $cat1context->id, 'component' => 'tool_certificate', 'filearea' => 'element', - 'itemid' => $imageelement2->get_id(), 'filepath' => '/', 'filename' => 'image2.png']; + 'itemid' => $imageelement2->get_id(), 'filepath' => '/', 'filename' => 'image2.png', ]; $file2 = $fs->create_file_from_string($file2record, 'Even more awesome photography'); $file2content = $file2->get_content(); // Create a dummy image file for element2 in the correct template context (category1), so we can check that upgrade script // is just removing the old file, and not trying to move it. $file3record = ['contextid' => $cat2context->id, 'component' => 'tool_certificate', 'filearea' => 'element', - 'itemid' => $imageelement2->get_id(), 'filepath' => '/', 'filename' => 'image2.png']; + 'itemid' => $imageelement2->get_id(), 'filepath' => '/', 'filename' => 'image2.png', ]; $file3 = $fs->create_file_from_string($file3record, 'Even more awesome photography'); $file3content = $file3->get_content(); From 67c43024ea1a680caf239de726482387c322243f Mon Sep 17 00:00:00 2001 From: Marina Glancy Date: Mon, 25 Sep 2023 16:48:30 +0100 Subject: [PATCH 2/3] WPOS-56 addressed new code checker problem reports --- classes/page.php | 2 +- classes/template.php | 4 ++-- templates/form-user-selector-suggestion.mustache | 2 +- tests/certificate_test.php | 2 +- tests/my_certificates_table_test.php | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/classes/page.php b/classes/page.php index 86db4900..0220166f 100644 --- a/classes/page.php +++ b/classes/page.php @@ -64,7 +64,7 @@ protected static function instance_from_persistent(\tool_certificate\persistent\ * New instance of the page * * @param int $id - * @param \stdClass $obj + * @param \stdClass|null $obj * @return page */ public static function instance(int $id = 0, ?\stdClass $obj = null) { diff --git a/classes/template.php b/classes/template.php index de0e99b2..2bc346e6 100644 --- a/classes/template.php +++ b/classes/template.php @@ -306,7 +306,7 @@ public function generate_pdf($preview = false, $issue = null, $return = false) { /** * Duplicates the template into a new one * - * @param \context $context + * @param \context|null $context * @return template */ public function duplicate(?\context $context = null) { @@ -684,7 +684,7 @@ public static function find_by_name($name) { * @param int $expires The timestamp when the certificate will expiry. Null if do not expires. * @param array $data Additional data that will json_encode'd and stored with the issue. * @param string $component The component the certificate was issued by. - * @param null $courseid + * @param int|null $courseid * @param \core\lock\lock|null $lock optional lock to release after a record was inserted into the DB * @return int The ID of the issue */ diff --git a/templates/form-user-selector-suggestion.mustache b/templates/form-user-selector-suggestion.mustache index 215e13ed..02b6375c 100644 --- a/templates/form-user-selector-suggestion.mustache +++ b/templates/form-user-selector-suggestion.mustache @@ -28,7 +28,7 @@ } }} - + {{fullname}} {{#hasidentity}} {{identity}} diff --git a/tests/certificate_test.php b/tests/certificate_test.php index 94460077..95171906 100644 --- a/tests/certificate_test.php +++ b/tests/certificate_test.php @@ -500,7 +500,7 @@ public function test_get_user_extra_field_names(): void { * * @return array */ - public function calculate_expirydate_provider(): array { + public static function calculate_expirydate_provider(): array { return [ 'Expires never' => [ certificate::DATE_EXPIRATION_NEVER, null, null, null, diff --git a/tests/my_certificates_table_test.php b/tests/my_certificates_table_test.php index 2fe35924..34923c20 100644 --- a/tests/my_certificates_table_test.php +++ b/tests/my_certificates_table_test.php @@ -96,7 +96,7 @@ public function test_col_linkedin($issue, $params, $organizationid): void { * * @return array[] */ - public function col_linkedin_provider(): array { + public static function col_linkedin_provider(): array { return [ [(object)[ 'id' => '6', From 834a446a8249f8afe7ed94f75e7105c5d0a6edb0 Mon Sep 17 00:00:00 2001 From: Marina Glancy Date: Mon, 25 Sep 2023 15:12:31 +0100 Subject: [PATCH 3/3] WPOS-56 .gitlabci modification to use latest codechecker --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 584905db..711e4472 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,4 +1,4 @@ -image: moodlehq/moodle-workplace-plugin-ci:8.0 +image: moodlehq/moodle-workplace-plugin-ci:8.0-ci4.1.5 services: - postgres:13