From e02769ed50e4f3a9b80a5cc6c7c2b65e6bb67837 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Wed, 31 Jan 2024 15:23:21 +0000 Subject: [PATCH] Use phpcbf to convert long array syntax to short --- ajax.php | 2 +- backup/moodle2/backup_customcert_stepslib.php | 30 ++--- ...restore_customcert_activity_task.class.php | 10 +- .../moodle2/restore_customcert_stepslib.php | 2 +- classes/certificate.php | 32 ++--- classes/edit_element_form.php | 4 +- classes/edit_form.php | 60 ++++----- classes/element.php | 6 +- classes/element_helper.php | 44 +++---- classes/event/course_module_viewed.php | 2 +- classes/event/element_created.php | 8 +- classes/event/element_deleted.php | 8 +- classes/event/element_updated.php | 8 +- classes/event/page_created.php | 8 +- classes/event/page_deleted.php | 8 +- classes/event/page_updated.php | 8 +- classes/event/template_created.php | 8 +- classes/event/template_deleted.php | 6 +- classes/event/template_updated.php | 8 +- classes/external.php | 32 ++--- classes/load_template_form.php | 4 +- classes/manage_templates_table.php | 18 +-- classes/my_certificates_table.php | 12 +- classes/output/email_certificate.php | 4 +- classes/output/verify_certificate_result.php | 6 +- classes/output/verify_certificate_results.php | 2 +- classes/task/email_certificate_task.php | 14 +- classes/template.php | 46 +++---- classes/upload_image_form.php | 6 +- classes/verify_certificate_form.php | 2 +- db/access.php | 124 +++++++++--------- db/log.php | 12 +- db/services.php | 18 +-- db/tasks.php | 8 +- edit.php | 36 ++--- edit_element.php | 18 +-- element/bgimage/classes/element.php | 6 +- element/bgimage/db/upgrade.php | 6 +- element/border/classes/element.php | 4 +- element/categoryname/classes/element.php | 2 +- element/code/classes/element.php | 6 +- element/coursefield/classes/element.php | 6 +- element/date/classes/element.php | 26 ++-- element/daterange/classes/element.php | 22 ++-- element/digitalsignature/classes/element.php | 6 +- element/grade/classes/element.php | 10 +- element/gradeitemname/classes/element.php | 4 +- element/image/classes/element.php | 16 +-- element/image/db/upgrade.php | 6 +- element/qrcode/classes/element.php | 2 +- element/teachername/classes/element.php | 6 +- element/userfield/classes/element.php | 8 +- element/userpicture/classes/element.php | 8 +- includes/colourpicker.php | 12 +- index.php | 30 ++--- lib.php | 44 +++---- load_template.php | 16 +-- manage_templates.php | 6 +- mobile/pluginfile.php | 2 +- mod_form.php | 8 +- my_certificates.php | 10 +- rearrange.php | 38 +++--- report.php | 2 +- tests/behat/behat_mod_customcert.php | 38 +++--- tests/element_helper_test.php | 16 +-- tests/email_certificate_task_test.php | 20 +-- tests/generator/lib.php | 4 +- tests/page_test.php | 4 +- tests/privacy_provider_test.php | 12 +- verify_certificate.php | 8 +- view.php | 24 ++-- 71 files changed, 531 insertions(+), 531 deletions(-) diff --git a/ajax.php b/ajax.php index 28a3ac71..d944ce9f 100644 --- a/ajax.php +++ b/ajax.php @@ -33,7 +33,7 @@ $values = json_decode($values); // Make sure the template exists. -$template = $DB->get_record('customcert_templates', array('id' => $tid), '*', MUST_EXIST); +$template = $DB->get_record('customcert_templates', ['id' => $tid], '*', MUST_EXIST); // Set the template. $template = new \mod_customcert\template($template); diff --git a/backup/moodle2/backup_customcert_stepslib.php b/backup/moodle2/backup_customcert_stepslib.php index e1f80fbe..01dc0f75 100644 --- a/backup/moodle2/backup_customcert_stepslib.php +++ b/backup/moodle2/backup_customcert_stepslib.php @@ -39,30 +39,30 @@ class backup_customcert_activity_structure_step extends backup_activity_structur protected function define_structure() { // The instance. - $customcert = new backup_nested_element('customcert', array('id'), array( + $customcert = new backup_nested_element('customcert', ['id'], [ 'templateid', 'name', 'intro', 'introformat', 'requiredtime', 'verifyany', 'emailstudents', - 'emailteachers', 'emailothers', 'protection', 'timecreated', 'timemodified')); + 'emailteachers', 'emailothers', 'protection', 'timecreated', 'timemodified']); // The template. - $template = new backup_nested_element('template', array('id'), array( - 'name', 'contextid', 'timecreated', 'timemodified')); + $template = new backup_nested_element('template', ['id'], [ + 'name', 'contextid', 'timecreated', 'timemodified']); // The pages. $pages = new backup_nested_element('pages'); - $page = new backup_nested_element('page', array('id'), array( + $page = new backup_nested_element('page', ['id'], [ 'templateid', 'width', 'height', 'leftmargin', 'rightmargin', - 'sequence', 'timecreated', 'timemodified')); + 'sequence', 'timecreated', 'timemodified']); // The elements. - $element = new backup_nested_element('element', array('id'), array( + $element = new backup_nested_element('element', ['id'], [ 'pageid', 'name', 'element', 'data', 'font', 'fontsize', 'colour', 'posx', 'posy', 'width', 'refpoint', 'sequence', - 'alignment', 'timecreated', 'timemodified')); + 'alignment', 'timecreated', 'timemodified']); // The issues. $issues = new backup_nested_element('issues'); - $issue = new backup_nested_element('issue', array('id'), array( - 'customcertid', 'userid', 'timecreated', 'emailed', 'code')); + $issue = new backup_nested_element('issue', ['id'], [ + 'customcertid', 'userid', 'timecreated', 'emailed', 'code']); // Build the tree. $customcert->add_child($issues); @@ -73,20 +73,20 @@ protected function define_structure() { $page->add_child($element); // Define sources. - $customcert->set_source_table('customcert', array('id' => backup::VAR_ACTIVITYID)); + $customcert->set_source_table('customcert', ['id' => backup::VAR_ACTIVITYID]); // Define template source. - $template->set_source_table('customcert_templates', array('contextid' => backup::VAR_CONTEXTID)); + $template->set_source_table('customcert_templates', ['contextid' => backup::VAR_CONTEXTID]); // Define page source. - $page->set_source_table('customcert_pages', array('templateid' => backup::VAR_PARENTID)); + $page->set_source_table('customcert_pages', ['templateid' => backup::VAR_PARENTID]); // Define element source, each element belongs to a page. - $element->set_source_table('customcert_elements', array('pageid' => backup::VAR_PARENTID)); + $element->set_source_table('customcert_elements', ['pageid' => backup::VAR_PARENTID]); // If we are including user info then save the issues. if ($this->get_setting_value('userinfo')) { - $issue->set_source_table('customcert_issues', array('customcertid' => backup::VAR_ACTIVITYID)); + $issue->set_source_table('customcert_issues', ['customcertid' => backup::VAR_ACTIVITYID]); } // Annotate the user id's where required. diff --git a/backup/moodle2/restore_customcert_activity_task.class.php b/backup/moodle2/restore_customcert_activity_task.class.php index d21228e6..8aba2bd8 100644 --- a/backup/moodle2/restore_customcert_activity_task.class.php +++ b/backup/moodle2/restore_customcert_activity_task.class.php @@ -54,9 +54,9 @@ protected function define_my_steps() { * Define the contents in the activity that must be processed by the link decoder. */ public static function define_decode_contents() { - $contents = array(); + $contents = []; - $contents[] = new restore_decode_content('customcert', array('intro'), 'customcert'); + $contents[] = new restore_decode_content('customcert', ['intro'], 'customcert'); return $contents; } @@ -65,7 +65,7 @@ public static function define_decode_contents() { * Define the decoding rules for links belonging to the activity to be executed by the link decoder. */ public static function define_decode_rules() { - $rules = array(); + $rules = []; $rules[] = new restore_decode_rule('CUSTOMCERTVIEWBYID', '/mod/customcert/view.php?id=$1', 'course_module'); $rules[] = new restore_decode_rule('CUSTOMCERTINDEX', '/mod/customcert/index.php?id=$1', 'course'); @@ -81,7 +81,7 @@ public static function define_decode_rules() { * @return array the restore log rules */ public static function define_restore_log_rules() { - $rules = array(); + $rules = []; $rules[] = new restore_log_rule('customcert', 'add', 'view.php?id={course_module}', '{customcert}'); $rules[] = new restore_log_rule('customcert', 'update', 'view.php?id={course_module}', '{customcert}'); @@ -108,7 +108,7 @@ public function after_restore() { INNER JOIN {customcert} c ON p.templateid = c.templateid WHERE c.id = :customcertid"; - if ($elements = $DB->get_records_sql($sql, array('customcertid' => $this->get_activityid()))) { + if ($elements = $DB->get_records_sql($sql, ['customcertid' => $this->get_activityid()])) { // Go through the elements for the certificate. foreach ($elements as $e) { // Get an instance of the element class. diff --git a/backup/moodle2/restore_customcert_stepslib.php b/backup/moodle2/restore_customcert_stepslib.php index 53183386..dfeb1d10 100644 --- a/backup/moodle2/restore_customcert_stepslib.php +++ b/backup/moodle2/restore_customcert_stepslib.php @@ -38,7 +38,7 @@ class restore_customcert_activity_structure_step extends restore_activity_struct */ protected function define_structure() { // The array used to store the path to the items we want to restore. - $paths = array(); + $paths = []; // The customcert instance. $paths[] = new restore_path_element('customcert', '/activity/customcert'); diff --git a/classes/certificate.php b/classes/certificate.php index e13cac1a..8e7747d6 100644 --- a/classes/certificate.php +++ b/classes/certificate.php @@ -73,7 +73,7 @@ class certificate { * @return string the value to insert into the protection field */ public static function set_protection($data) { - $protection = array(); + $protection = []; if (!empty($data->protection_print)) { $protection[] = self::PROTECTION_PRINT; @@ -157,7 +157,7 @@ public static function get_fonts() { */ public static function get_font_sizes() { // Array to store the sizes. - $sizes = array(); + $sizes = []; for ($i = 1; $i <= 200; $i++) { $sizes[$i] = $i; @@ -214,7 +214,7 @@ public static function get_course_time(int $courseid, int $userid = 0): int { WHERE userid = :userid AND $coursefield = :courseid ORDER BY $timefield ASC"; - $params = array('userid' => $userid, 'courseid' => $courseid); + $params = ['userid' => $userid, 'courseid' => $courseid]; $totaltime = 0; if ($logs = $DB->get_recordset_sql($sql, $params)) { foreach ($logs as $log) { @@ -261,7 +261,7 @@ public static function get_issues($customcertid, $groupmode, $cm, $limitfrom, $l // If it is empty then return an empty array. if (empty($conditionsparams)) { - return array(); + return []; } // Return the issues. @@ -269,7 +269,7 @@ public static function get_issues($customcertid, $groupmode, $cm, $limitfrom, $l $query = \core_user\fields::for_identity($context)->with_userpic()->get_sql('u', true, '', '', false); // Add the conditional SQL and the customcertid to form all used parameters. - $allparams = $query->params + $conditionsparams + array('customcertid' => $customcertid); + $allparams = $query->params + $conditionsparams + ['customcertid' => $customcertid]; $orderby = $sort ?: $DB->sql_fullname(); @@ -304,7 +304,7 @@ public static function get_number_of_issues($customcertid, $cm, $groupmode) { } // Add the conditional SQL and the customcertid to form all used parameters. - $allparams = $conditionsparams + array('customcertid' => $customcertid); + $allparams = $conditionsparams + ['customcertid' => $customcertid]; // Return the number of issues. $sql = "SELECT COUNT(u.id) as count @@ -330,7 +330,7 @@ public static function get_conditional_issues_sql($cm, $groupmode) { // Get all users that can manage this customcert to exclude them from the report. $context = \context_module::instance($cm->id); $conditionssql = ''; - $conditionsparams = array(); + $conditionsparams = []; // Get all users that can manage this certificate to exclude them from the report. $certmanagers = array_keys(get_users_by_capability($context, 'mod/customcert:manage', 'u.id')); @@ -345,30 +345,30 @@ public static function get_conditional_issues_sql($cm, $groupmode) { // If we are viewing all participants and the user does not have access to all groups then return nothing. if (!$currentgroup && !$canaccessallgroups) { - return array('', array()); + return ['', []]; } if ($currentgroup) { if (!$canaccessallgroups) { // Guest users do not belong to any groups. if (isguestuser()) { - return array('', array()); + return ['', []]; } // Check that the user belongs to the group we are viewing. $usersgroups = groups_get_all_groups($cm->course, $USER->id, $cm->groupingid); if ($usersgroups) { if (!isset($usersgroups[$currentgroup])) { - return array('', array()); + return ['', []]; } } else { // They belong to no group, so return an empty array. - return array('', array()); + return ['', []]; } } $groupusers = array_keys(groups_get_members($currentgroup, 'u.*')); if (empty($groupusers)) { - return array('', array()); + return ['', []]; } list($sql, $params) = $DB->get_in_or_equal($groupusers, SQL_PARAMS_NAMED, 'grp'); @@ -377,7 +377,7 @@ public static function get_conditional_issues_sql($cm, $groupmode) { } } - return array($conditionssql, $conditionsparams); + return [$conditionssql, $conditionsparams]; } /** @@ -394,7 +394,7 @@ public static function get_number_of_certificates_for_user($userid) { INNER JOIN {customcert_issues} ci ON c.id = ci.customcertid WHERE ci.userid = :userid"; - return $DB->count_records_sql($sql, array('userid' => $userid)); + return $DB->count_records_sql($sql, ['userid' => $userid]); } /** @@ -421,7 +421,7 @@ public static function get_certificates_for_user($userid, $limitfrom, $limitnum, ON c.course = co.id 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); } /** @@ -456,7 +456,7 @@ public static function generate_code() { $uniquecodefound = false; $code = random_string(10); while (!$uniquecodefound) { - if (!$DB->record_exists('customcert_issues', array('code' => $code))) { + if (!$DB->record_exists('customcert_issues', ['code' => $code])) { $uniquecodefound = true; } else { $code = random_string(10); diff --git a/classes/edit_element_form.php b/classes/edit_element_form.php index a08497dc..587f9396 100644 --- a/classes/edit_element_form.php +++ b/classes/edit_element_form.php @@ -52,7 +52,7 @@ class edit_element_form extends \moodleform { public function definition() { $mform =& $this->_form; - $mform->updateAttributes(array('id' => 'editelementform')); + $mform->updateAttributes(['id' => 'editelementform']); $element = $this->_customdata['element']; @@ -85,7 +85,7 @@ public function definition_after_data() { * @return array the errors that were found */ public function validation($data, $files) { - $errors = array(); + $errors = []; if (\core_text::strlen($data['name']) > 255) { $errors['name'] = get_string('nametoolong', 'customcert'); diff --git a/classes/edit_form.php b/classes/edit_form.php index f091998a..bbf110ad 100644 --- a/classes/edit_form.php +++ b/classes/edit_form.php @@ -66,7 +66,7 @@ public function definition() { // Get the number of pages for this module. if (isset($this->_customdata['tid'])) { $this->tid = $this->_customdata['tid']; - if ($pages = $DB->get_records('customcert_pages', array('templateid' => $this->tid), 'sequence')) { + if ($pages = $DB->get_records('customcert_pages', ['templateid' => $this->tid], 'sequence')) { $this->numpages = count($pages); foreach ($pages as $p) { $this->add_customcert_page_elements($p); @@ -83,22 +83,22 @@ public function definition() { // Link to add another page, only display it when the template has been created. if (isset($this->_customdata['tid'])) { $addpagelink = new \moodle_url('/mod/customcert/edit.php', - array( + [ 'tid' => $this->tid, 'aid' => 1, 'action' => 'addpage', 'sesskey' => sesskey() - ) + ] ); $icon = $OUTPUT->pix_icon('t/switch_plus', get_string('addcertpage', 'customcert')); $addpagehtml = \html_writer::link($addpagelink, $icon . get_string('addcertpage', 'customcert')); - $mform->addElement('html', \html_writer::tag('div', $addpagehtml, array('class' => 'addpage'))); + $mform->addElement('html', \html_writer::tag('div', $addpagehtml, ['class' => 'addpage'])); } // Add the submit buttons. - $group = array(); + $group = []; $group[] = $mform->createElement('submit', 'submitbtn', get_string('savechanges')); - $group[] = $mform->createElement('submit', 'previewbtn', get_string('savechangespreview', 'customcert'), array(), false); + $group[] = $mform->createElement('submit', 'previewbtn', get_string('savechangespreview', 'customcert'), [], false); $mform->addElement('group', 'submitbtngroup', '', $group, '', false); $mform->addElement('hidden', 'tid'); @@ -117,7 +117,7 @@ public function definition_after_data() { // Check that we are updating a current customcert. if ($this->tid) { // Get the pages for this customcert. - if ($pages = $DB->get_records('customcert_pages', array('templateid' => $this->tid))) { + if ($pages = $DB->get_records('customcert_pages', ['templateid' => $this->tid])) { // Loop through the pages. foreach ($pages as $p) { // Set the width. @@ -202,19 +202,19 @@ protected function add_customcert_page_elements($page) { } $editlink = '/mod/customcert/edit.php'; - $editlinkparams = array('tid' => $this->tid, 'sesskey' => sesskey()); + $editlinkparams = ['tid' => $this->tid, 'sesskey' => sesskey()]; $editelementlink = '/mod/customcert/edit_element.php'; - $editelementlinkparams = array('tid' => $this->tid, 'sesskey' => sesskey()); + $editelementlinkparams = ['tid' => $this->tid, 'sesskey' => sesskey()]; // Place the ordering arrows. // Only display the move up arrow if it is not the first. if ($page->sequence > 1) { - $url = new \moodle_url($editlink, $editlinkparams + array('action' => 'pmoveup', 'aid' => $page->id)); + $url = new \moodle_url($editlink, $editlinkparams + ['action' => 'pmoveup', 'aid' => $page->id]); $mform->addElement('html', $OUTPUT->action_icon($url, new \pix_icon('t/up', get_string('moveup')))); } // Only display the move down arrow if it is not the last. if ($page->sequence < $this->numpages) { - $url = new \moodle_url($editlink, $editlinkparams + array('action' => 'pmovedown', 'aid' => $page->id)); + $url = new \moodle_url($editlink, $editlinkparams + ['action' => 'pmovedown', 'aid' => $page->id]); $mform->addElement('html', $OUTPUT->action_icon($url, new \pix_icon('t/down', get_string('movedown')))); } @@ -241,14 +241,14 @@ protected function add_customcert_page_elements($page) { $mform->addHelpButton('pagerightmargin_' . $page->id, 'rightmargin', 'customcert'); // Check if there are elements to add. - if ($elements = $DB->get_records('customcert_elements', array('pageid' => $page->id), 'sequence ASC')) { + if ($elements = $DB->get_records('customcert_elements', ['pageid' => $page->id], 'sequence ASC')) { // Get the total number of elements. $numelements = count($elements); // Create a table to display these elements. $table = new \html_table(); - $table->attributes = array('class' => 'generaltable elementstable'); - $table->head = array(get_string('name', 'customcert'), get_string('type', 'customcert'), get_string('actions')); - $table->align = array('left', 'left', 'left'); + $table->attributes = ['class' => 'generaltable elementstable']; + $table->head = [get_string('name', 'customcert'), get_string('type', 'customcert'), get_string('actions')]; + $table->align = ['left', 'left', 'left']; // Loop through and add the elements to the table. foreach ($elements as $element) { $elementname = new \core\output\inplace_editable('mod_customcert', 'elementname', $element->id, @@ -258,28 +258,28 @@ protected function add_customcert_page_elements($page) { $row->cells[] = $OUTPUT->render($elementname); $row->cells[] = $element->element; // Link to edit this element. - $link = new \moodle_url($editelementlink, $editelementlinkparams + array('id' => $element->id, - 'action' => 'edit')); + $link = new \moodle_url($editelementlink, $editelementlinkparams + ['id' => $element->id, + 'action' => 'edit']); $icons = $OUTPUT->action_icon($link, new \pix_icon('t/edit', get_string('edit')), null, - array('class' => 'action-icon edit-icon')); + ['class' => 'action-icon edit-icon']); // Link to delete the element. - $link = new \moodle_url($editlink, $editlinkparams + array('action' => 'deleteelement', - 'aid' => $element->id)); + $link = new \moodle_url($editlink, $editlinkparams + ['action' => 'deleteelement', + 'aid' => $element->id]); $icons .= $OUTPUT->action_icon($link, new \pix_icon('t/delete', get_string('delete')), null, - array('class' => 'action-icon delete-icon')); + ['class' => 'action-icon delete-icon']); // Now display any moving arrows if they are needed. if ($numelements > 1) { // Only display the move up arrow if it is not the first. $moveicons = ''; if ($element->sequence > 1) { - $url = new \moodle_url($editlink, $editlinkparams + array('action' => 'emoveup', - 'aid' => $element->id)); + $url = new \moodle_url($editlink, $editlinkparams + ['action' => 'emoveup', + 'aid' => $element->id]); $moveicons .= $OUTPUT->action_icon($url, new \pix_icon('t/up', get_string('moveup'))); } // Only display the move down arrow if it is not the last. if ($element->sequence < $numelements) { - $url = new \moodle_url($editlink, $editlinkparams + array('action' => 'emovedown', - 'aid' => $element->id)); + $url = new \moodle_url($editlink, $editlinkparams + ['action' => 'emovedown', + 'aid' => $element->id]); $moveicons .= $OUTPUT->action_icon($url, new \pix_icon('t/down', get_string('movedown'))); } $icons .= $moveicons; @@ -288,7 +288,7 @@ protected function add_customcert_page_elements($page) { $table->data[] = $row; } // Create link to order the elements. - $link = \html_writer::link(new \moodle_url('/mod/customcert/rearrange.php', array('pid' => $page->id)), + $link = \html_writer::link(new \moodle_url('/mod/customcert/rearrange.php', ['pid' => $page->id]), get_string('rearrangeelements', 'customcert')); // Add the table to the form. $mform->addElement('static', 'elements_' . $page->id, get_string('elements', 'customcert'), \html_writer::table($table) @@ -296,19 +296,19 @@ protected function add_customcert_page_elements($page) { $mform->addHelpButton('elements_' . $page->id, 'elements', 'customcert'); } - $group = array(); + $group = []; $group[] = $mform->createElement('select', 'element_' . $page->id, '', element_helper::get_available_element_types()); $group[] = $mform->createElement('submit', 'addelement_' . $page->id, get_string('addelement', 'customcert'), - array(), false); + [], false); $mform->addElement('group', 'elementgroup', '', $group, '', false); // Add option to delete this page if there is more than one page. if ($this->numpages > 1) { // Link to delete the page. - $deletelink = new \moodle_url($editlink, $editlinkparams + array('action' => 'deletepage', 'aid' => $page->id)); + $deletelink = new \moodle_url($editlink, $editlinkparams + ['action' => 'deletepage', 'aid' => $page->id]); $icon = $OUTPUT->pix_icon('t/delete', get_string('deletecertpage', 'customcert')); $deletepagehtml = \html_writer::link($deletelink, $icon . get_string('deletecertpage', 'customcert')); - $mform->addElement('html', \html_writer::tag('div', $deletepagehtml, array('class' => 'deletebutton'))); + $mform->addElement('html', \html_writer::tag('div', $deletepagehtml, ['class' => 'deletebutton'])); } } } diff --git a/classes/element.php b/classes/element.php index c982f759..d61c4ff8 100644 --- a/classes/element.php +++ b/classes/element.php @@ -267,7 +267,7 @@ public function get_alignment() { * @throws \InvalidArgumentException if the provided new alignment is not valid. */ protected function set_alignment(string $alignment) { - $validvalues = array(self::ALIGN_LEFT, self::ALIGN_CENTER, self::ALIGN_RIGHT); + $validvalues = [self::ALIGN_LEFT, self::ALIGN_CENTER, self::ALIGN_RIGHT]; if (!in_array($alignment, $validvalues)) { throw new \InvalidArgumentException("'$alignment' is not a valid alignment value. It has to be one of " . implode(', ', $validvalues)); @@ -331,7 +331,7 @@ public function definition_after_data($mform) { */ public function validate_form_elements($data, $files) { // Array to return the errors. - $errors = array(); + $errors = []; // Common validation methods. $errors += element_helper::validate_form_element_colour($data); @@ -456,7 +456,7 @@ abstract public function render_html(); public function delete() { global $DB; - $return = $DB->delete_records('customcert_elements', array('id' => $this->id)); + $return = $DB->delete_records('customcert_elements', ['id' => $this->id]); \mod_customcert\event\element_deleted::create_from_element($this)->trigger(); diff --git a/classes/element_helper.php b/classes/element_helper.php index 35b7bf32..f5d4dcc9 100644 --- a/classes/element_helper.php +++ b/classes/element_helper.php @@ -129,7 +129,7 @@ public static function render_html_content($element, $content) { if ($element->get_width()) { $style .= ' width: ' . $element->get_width() . 'mm'; } - return \html_writer::div($content, '', array('style' => $style)); + return \html_writer::div($content, '', ['style' => $style]); } /** @@ -167,11 +167,11 @@ public static function render_form_element_colour($mform) { * @param \MoodleQuickForm $mform the edit_form instance. */ public static function render_form_element_position($mform) { - $mform->addElement('text', 'posx', get_string('posx', 'customcert'), array('size' => 10)); + $mform->addElement('text', 'posx', get_string('posx', 'customcert'), ['size' => 10]); $mform->setType('posx', PARAM_INT); $mform->setDefault('posx', 0); $mform->addHelpButton('posx', 'posx', 'customcert'); - $mform->addElement('text', 'posy', get_string('posy', 'customcert'), array('size' => 10)); + $mform->addElement('text', 'posy', get_string('posy', 'customcert'), ['size' => 10]); $mform->setType('posy', PARAM_INT); $mform->setDefault('posy', 0); $mform->addHelpButton('posy', 'posy', 'customcert'); @@ -183,7 +183,7 @@ public static function render_form_element_position($mform) { * @param \MoodleQuickForm $mform the edit_form instance. */ public static function render_form_element_width($mform) { - $mform->addElement('text', 'width', get_string('elementwidth', 'customcert'), array('size' => 10)); + $mform->addElement('text', 'width', get_string('elementwidth', 'customcert'), ['size' => 10]); $mform->setType('width', PARAM_INT); $mform->setDefault('width', 0); $mform->addHelpButton('width', 'elementwidth', 'customcert'); @@ -195,7 +195,7 @@ public static function render_form_element_width($mform) { * @param \MoodleQuickForm $mform the edit_form instance. */ public static function render_form_element_height($mform) { - $mform->addElement('text', 'height', get_string('elementheight', 'customcert'), array('size' => 10)); + $mform->addElement('text', 'height', get_string('elementheight', 'customcert'), ['size' => 10]); $mform->setType('height', PARAM_INT); $mform->setDefault('height', 0); $mform->addHelpButton('height', 'elementheight', 'customcert'); @@ -207,7 +207,7 @@ public static function render_form_element_height($mform) { * @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('topleft', 'customcert'); $refpointoptions[self::CUSTOMCERT_REF_POINT_TOPCENTER] = get_string('topcenter', 'customcert'); $refpointoptions[self::CUSTOMCERT_REF_POINT_TOPRIGHT] = get_string('topright', 'customcert'); @@ -224,7 +224,7 @@ public static function render_form_element_refpoint($mform) { * @param \MoodleQuickForm $mform the edit_form instance. */ public static function render_form_element_alignment($mform) { - $alignmentoptions = array(); + $alignmentoptions = []; $alignmentoptions[element::ALIGN_LEFT] = get_string('alignleft', 'customcert'); $alignmentoptions[element::ALIGN_CENTER] = get_string('aligncenter', 'customcert'); $alignmentoptions[element::ALIGN_RIGHT] = get_string('alignright', 'customcert'); @@ -242,7 +242,7 @@ public static function render_form_element_alignment($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', 'customcert'); @@ -257,7 +257,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 ((!isset($data['posx'])) || (!is_numeric($data['posx'])) || ($data['posx'] < 0)) { @@ -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', @@ -411,7 +411,7 @@ public static function validate_colour($colour) { 'slategray', 'slategrey', 'snow', 'springgreen', 'steelblue', 'tan', 'teal', 'thistle', 'tomato', 'turquoise', 'violet', 'wheat', 'white', '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 {customcert_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; } @@ -464,7 +464,7 @@ public static function get_courseid($elementid) { WHERE ce.id = :elementid"; // Check if there is a course associated with this element. - if ($course = $DB->get_record_sql($sql, array('elementid' => $elementid))) { + if ($course = $DB->get_record_sql($sql, ['elementid' => $elementid])) { return $course->course; } else { // Must be in a site template. return $SITE->id; @@ -487,7 +487,7 @@ public static function get_context(int $elementid) : \context { INNER JOIN {customcert_elements} ce ON cp.id = ce.pageid WHERE ce.id = :elementid"; - $contextid = $DB->get_field_sql($sql, array('elementid' => $elementid), MUST_EXIST); + $contextid = $DB->get_field_sql($sql, ['elementid' => $elementid], MUST_EXIST); return \context::instance_by_id($contextid); } @@ -501,7 +501,7 @@ public static function get_available_element_types() { global $CFG; // Array to store the element types. - $options = array(); + $options = []; // Check that the directory exists. $elementdir = "$CFG->dirroot/mod/customcert/element"; @@ -542,7 +542,7 @@ public static function get_available_element_types() { */ public static function get_grade_items($course) { // Array to store the grade items. - $arrgradeitems = array(); + $arrgradeitems = []; // Get other non-module related grade items. if ($gradeitems = \grade_item::fetch_all(['courseid' => $course->id])) { @@ -554,7 +554,7 @@ public static function get_grade_items($course) { if ($gi->is_external_item()) { $cm = get_coursemodule_from_instance($gi->itemmodule, $gi->iteminstance, $course->id); $modcontext = \context_module::instance($cm->id); - $modname = format_string($cm->name, true, array('context' => $modcontext)); + $modname = format_string($cm->name, true, ['context' => $modcontext]); } if ($gi->is_external_item() && !$gi->is_outcome_item()) { @@ -592,7 +592,7 @@ public static function get_course_grade_info($courseid, $gradeformat, $userid) { return false; } - $grade = new \grade_grade(array('itemid' => $courseitem->id, 'userid' => $userid)); + $grade = new \grade_grade(['itemid' => $courseitem->id, 'userid' => $userid]); return new grade_information( $courseitem->get_name(), @@ -613,11 +613,11 @@ public static function get_course_grade_info($courseid, $gradeformat, $userid) { public static function get_mod_grade_info($cmid, $gradeformat, $userid) { global $DB; - if (!$cm = $DB->get_record('course_modules', array('id' => $cmid))) { + if (!$cm = $DB->get_record('course_modules', ['id' => $cmid])) { return false; } - if (!$module = $DB->get_record('modules', array('id' => $cm->module))) { + if (!$module = $DB->get_record('modules', ['id' => $cm->module])) { return false; } @@ -676,7 +676,7 @@ public static function get_grade_item_info($gradeitemid, $gradeformat, $userid) return false; } - $grade = new \grade_grade(array('itemid' => $gradeitem->id, 'userid' => $userid)); + $grade = new \grade_grade(['itemid' => $gradeitem->id, 'userid' => $userid]); return new grade_information( $gradeitem->get_name(), diff --git a/classes/event/course_module_viewed.php b/classes/event/course_module_viewed.php index 254c4d70..9481fd58 100644 --- a/classes/event/course_module_viewed.php +++ b/classes/event/course_module_viewed.php @@ -47,7 +47,7 @@ protected function init() { * @return string[] */ public static function get_objectid_mapping() { - return array('db' => 'customcert', 'restore' => 'customcert'); + return ['db' => 'customcert', 'restore' => 'customcert']; } /** diff --git a/classes/event/element_created.php b/classes/event/element_created.php index 212d1d01..8aba7157 100644 --- a/classes/event/element_created.php +++ b/classes/event/element_created.php @@ -79,10 +79,10 @@ public static function create_from_element(\mod_customcert\element $element): el $page = $DB->get_record('customcert_pages', ['id' => $element->get_pageid()]); $template = $DB->get_record('customcert_templates', ['id' => $page->templateid]); - $data = array( + $data = [ 'contextid' => $template->contextid, 'objectid' => $element->get_id(), - ); + ]; return self::create($data); } @@ -96,7 +96,7 @@ public function get_url() { return new \moodle_url('/mod/customcert/manage_templates.php'); } else { return new \moodle_url('/mod/customcert/view.php', - array('id' => $this->contextinstanceid)); + ['id' => $this->contextinstanceid]); } } @@ -106,7 +106,7 @@ public function get_url() { * @return string[] */ public static function get_objectid_mapping() { - return array('db' => 'customcert_elements', 'restore' => 'customcert_elements'); + return ['db' => 'customcert_elements', 'restore' => 'customcert_elements']; } /** diff --git a/classes/event/element_deleted.php b/classes/event/element_deleted.php index 95a1b4b6..eefbe438 100644 --- a/classes/event/element_deleted.php +++ b/classes/event/element_deleted.php @@ -79,10 +79,10 @@ public static function create_from_element(\mod_customcert\element $element): el $page = $DB->get_record('customcert_pages', ['id' => $element->get_pageid()]); $template = $DB->get_record('customcert_templates', ['id' => $page->templateid]); - $data = array( + $data = [ 'contextid' => $template->contextid, 'objectid' => $element->get_id(), - ); + ]; return self::create($data); } @@ -96,7 +96,7 @@ public function get_url() { return new \moodle_url('/mod/customcert/manage_templates.php'); } else { return new \moodle_url('/mod/customcert/view.php', - array('id' => $this->contextinstanceid)); + ['id' => $this->contextinstanceid]); } } @@ -106,7 +106,7 @@ public function get_url() { * @return string[] */ public static function get_objectid_mapping() { - return array('db' => 'customcert_elements', 'restore' => 'customcert_elements'); + return ['db' => 'customcert_elements', 'restore' => 'customcert_elements']; } /** diff --git a/classes/event/element_updated.php b/classes/event/element_updated.php index ae2b58a5..db83be76 100644 --- a/classes/event/element_updated.php +++ b/classes/event/element_updated.php @@ -79,10 +79,10 @@ public static function create_from_element(\mod_customcert\element $element): el $page = $DB->get_record('customcert_pages', ['id' => $element->get_pageid()]); $template = $DB->get_record('customcert_templates', ['id' => $page->templateid]); - $data = array( + $data = [ 'contextid' => $template->contextid, 'objectid' => $element->get_id(), - ); + ]; return self::create($data); } @@ -113,7 +113,7 @@ public function get_url() { return new \moodle_url('/mod/customcert/manage_templates.php'); } else { return new \moodle_url('/mod/customcert/view.php', - array('id' => $this->contextinstanceid)); + ['id' => $this->contextinstanceid]); } } @@ -123,7 +123,7 @@ public function get_url() { * @return string[] */ public static function get_objectid_mapping() { - return array('db' => 'customcert_elements', 'restore' => 'customcert_elements'); + return ['db' => 'customcert_elements', 'restore' => 'customcert_elements']; } /** diff --git a/classes/event/page_created.php b/classes/event/page_created.php index 7f17428e..af69caac 100644 --- a/classes/event/page_created.php +++ b/classes/event/page_created.php @@ -77,10 +77,10 @@ public static function get_name() { * @return page_created */ public static function create_from_page(\stdClass $page, template $template): page_created { - $data = array( + $data = [ 'context' => $template->get_context(), 'objectid' => $page->id, - ); + ]; return self::create($data); } @@ -94,7 +94,7 @@ public function get_url() { return new \moodle_url('/mod/customcert/manage_templates.php'); } else { return new \moodle_url('/mod/customcert/view.php', - array('id' => $this->contextinstanceid)); + ['id' => $this->contextinstanceid]); } } @@ -104,7 +104,7 @@ public function get_url() { * @return string[] */ public static function get_objectid_mapping() { - return array('db' => 'customcert_pages', 'restore' => 'customcert_pages'); + return ['db' => 'customcert_pages', 'restore' => 'customcert_pages']; } /** diff --git a/classes/event/page_deleted.php b/classes/event/page_deleted.php index 783265b2..eeb6d0f1 100644 --- a/classes/event/page_deleted.php +++ b/classes/event/page_deleted.php @@ -77,10 +77,10 @@ public static function get_name() { * @return page_deleted */ public static function create_from_page(\stdClass $page, template $template): page_deleted { - $data = array( + $data = [ 'context' => $template->get_context(), 'objectid' => $page->id, - ); + ]; return self::create($data); } @@ -94,7 +94,7 @@ public function get_url() { return new \moodle_url('/mod/customcert/manage_templates.php'); } else { return new \moodle_url('/mod/customcert/view.php', - array('id' => $this->contextinstanceid)); + ['id' => $this->contextinstanceid]); } } @@ -104,7 +104,7 @@ public function get_url() { * @return string[] */ public static function get_objectid_mapping() { - return array('db' => 'customcert_pages', 'restore' => 'customcert_pages'); + return ['db' => 'customcert_pages', 'restore' => 'customcert_pages']; } /** diff --git a/classes/event/page_updated.php b/classes/event/page_updated.php index 7627b76f..3a4a7e8a 100644 --- a/classes/event/page_updated.php +++ b/classes/event/page_updated.php @@ -77,10 +77,10 @@ public static function get_name() { * @return page_updated */ public static function create_from_page(\stdClass $page, template $template): page_updated { - $data = array( + $data = [ 'context' => $template->get_context(), 'objectid' => $page->id, - ); + ]; return self::create($data); } @@ -94,7 +94,7 @@ public function get_url() { return new \moodle_url('/mod/customcert/manage_templates.php'); } else { return new \moodle_url('/mod/customcert/view.php', - array('id' => $this->contextinstanceid)); + ['id' => $this->contextinstanceid]); } } @@ -104,7 +104,7 @@ public function get_url() { * @return string[] */ public static function get_objectid_mapping() { - return array('db' => 'customcert_pages', 'restore' => 'customcert_pages'); + return ['db' => 'customcert_pages', 'restore' => 'customcert_pages']; } /** diff --git a/classes/event/template_created.php b/classes/event/template_created.php index 63cb5907..8c5e0092 100644 --- a/classes/event/template_created.php +++ b/classes/event/template_created.php @@ -76,10 +76,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(), - ); + ]; return self::create($data); } @@ -93,7 +93,7 @@ public function get_url() { return new \moodle_url('/mod/customcert/manage_templates.php'); } else { return new \moodle_url('/mod/customcert/view.php', - array('id' => $this->contextinstanceid)); + ['id' => $this->contextinstanceid]); } } @@ -103,7 +103,7 @@ public function get_url() { * @return string[] */ public static function get_objectid_mapping() { - return array('db' => 'customcert_templates', 'restore' => 'customcert_templates'); + return ['db' => 'customcert_templates', 'restore' => 'customcert_templates']; } /** diff --git a/classes/event/template_deleted.php b/classes/event/template_deleted.php index ed3e7baf..f718dcb8 100644 --- a/classes/event/template_deleted.php +++ b/classes/event/template_deleted.php @@ -76,10 +76,10 @@ public static function get_name() { * @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); return $event; } @@ -102,7 +102,7 @@ public function get_url() { * @return string[] */ public static function get_objectid_mapping() { - return array('db' => 'customcert_templates', 'restore' => 'customcert_templates'); + return ['db' => 'customcert_templates', 'restore' => 'customcert_templates']; } /** diff --git a/classes/event/template_updated.php b/classes/event/template_updated.php index 60d86332..ba75c6d2 100644 --- a/classes/event/template_updated.php +++ b/classes/event/template_updated.php @@ -76,10 +76,10 @@ public static function get_name() { * @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); return $event; } @@ -93,7 +93,7 @@ public function get_url() { return new \moodle_url('/mod/customcert/manage_templates.php'); } else { return new \moodle_url('/mod/customcert/view.php', - array('id' => $this->contextinstanceid)); + ['id' => $this->contextinstanceid]); } } @@ -103,7 +103,7 @@ public function get_url() { * @return string[] */ public static function get_objectid_mapping() { - return array('db' => 'customcert_templates', 'restore' => 'customcert_templates'); + return ['db' => 'customcert_templates', 'restore' => 'customcert_templates']; } /** diff --git a/classes/external.php b/classes/external.php index b77563bc..c11b1b33 100644 --- a/classes/external.php +++ b/classes/external.php @@ -42,18 +42,18 @@ class external extends \external_api { */ public static function save_element_parameters() { return new \external_function_parameters( - array( + [ 'templateid' => new \external_value(PARAM_INT, 'The template id'), 'elementid' => new \external_value(PARAM_INT, 'The element id'), 'values' => new \external_multiple_structure( new \external_single_structure( - array( + [ 'name' => new \external_value(PARAM_ALPHANUMEXT, 'The field to update'), 'value' => new \external_value(PARAM_RAW, 'The value of the field'), - ) + ] ) ) - ) + ] ); } @@ -68,15 +68,15 @@ public static function save_element_parameters() { public static function save_element($templateid, $elementid, $values) { global $DB; - $params = array( + $params = [ 'templateid' => $templateid, 'elementid' => $elementid, 'values' => $values - ); + ]; self::validate_parameters(self::save_element_parameters(), $params); - $template = $DB->get_record('customcert_templates', array('id' => $templateid), '*', MUST_EXIST); - $element = $DB->get_record('customcert_elements', array('id' => $elementid), '*', MUST_EXIST); + $template = $DB->get_record('customcert_templates', ['id' => $templateid], '*', MUST_EXIST); + $element = $DB->get_record('customcert_elements', ['id' => $elementid], '*', MUST_EXIST); // Set the template. $template = new \mod_customcert\template($template); @@ -123,10 +123,10 @@ public static function save_element_returns() { */ public static function get_element_html_parameters() { return new \external_function_parameters( - array( + [ 'templateid' => new \external_value(PARAM_INT, 'The template id'), 'elementid' => new \external_value(PARAM_INT, 'The element id'), - ) + ] ); } @@ -140,14 +140,14 @@ public static function get_element_html_parameters() { public static function get_element_html($templateid, $elementid) { global $DB; - $params = array( + $params = [ 'templateid' => $templateid, 'elementid' => $elementid - ); + ]; self::validate_parameters(self::get_element_html_parameters(), $params); - $template = $DB->get_record('customcert_templates', array('id' => $templateid), '*', MUST_EXIST); - $element = $DB->get_record('customcert_elements', array('id' => $elementid), '*', MUST_EXIST); + $template = $DB->get_record('customcert_templates', ['id' => $templateid], '*', MUST_EXIST); + $element = $DB->get_record('customcert_elements', ['id' => $elementid], '*', MUST_EXIST); // Set the template. $template = new \mod_customcert\template($template); @@ -183,10 +183,10 @@ public static function get_element_html_returns() { */ public static function delete_issue_parameters() { return new \external_function_parameters( - array( + [ 'certificateid' => new \external_value(PARAM_INT, 'The certificate id'), 'issueid' => new \external_value(PARAM_INT, 'The issue id'), - ) + ] ); } diff --git a/classes/load_template_form.php b/classes/load_template_form.php index ef9a8d74..8f01fde3 100644 --- a/classes/load_template_form.php +++ b/classes/load_template_form.php @@ -64,13 +64,13 @@ public function definition() { foreach ($arrtemplates as $key => $template) { $templates[$key] = format_string($template, true, ['context' => $context]); } - $group = array(); + $group = []; $group[] = $mform->createElement('select', 'ltid', '', $templates); $group[] = $mform->createElement('submit', 'loadtemplatesubmit', get_string('load', 'customcert')); $mform->addElement('group', 'loadtemplategroup', '', $group, '', false); $mform->setType('ltid', PARAM_INT); } else { - $msg = \html_writer::tag('div', get_string('notemplates', 'customcert'), array('class' => 'alert')); + $msg = \html_writer::tag('div', get_string('notemplates', 'customcert'), ['class' => 'alert']); $mform->addElement('static', 'notemplates', '', $msg); } } diff --git a/classes/manage_templates_table.php b/classes/manage_templates_table.php index 58b8acba..0a011d6f 100644 --- a/classes/manage_templates_table.php +++ b/classes/manage_templates_table.php @@ -90,30 +90,30 @@ public function col_actions($template) { global $OUTPUT; // Link to edit the template. - $editlink = new \moodle_url('/mod/customcert/edit.php', array('tid' => $template->id)); + $editlink = new \moodle_url('/mod/customcert/edit.php', ['tid' => $template->id]); $editicon = $OUTPUT->action_icon($editlink, new \pix_icon('t/edit', get_string('edit'))); // Link to duplicate the template. $duplicatelink = new \moodle_url('/mod/customcert/manage_templates.php', - array( + [ 'tid' => $template->id, 'action' => 'duplicate', 'sesskey' => sesskey() - ) + ] ); $duplicateicon = $OUTPUT->action_icon($duplicatelink, new \pix_icon('t/copy', get_string('duplicate')), null, - array('class' => 'action-icon duplicate-icon')); + ['class' => 'action-icon duplicate-icon']); // Link to delete the template. $deletelink = new \moodle_url('/mod/customcert/manage_templates.php', - array( + [ 'tid' => $template->id, 'action' => 'delete', 'sesskey' => sesskey() - ) + ] ); $deleteicon = $OUTPUT->action_icon($deletelink, new \pix_icon('t/delete', get_string('delete')), null, - array('class' => 'action-icon delete-icon')); + ['class' => 'action-icon delete-icon']); return $editicon . $duplicateicon . $deleteicon; } @@ -127,11 +127,11 @@ public function col_actions($template) { public function query_db($pagesize, $useinitialsbar = true) { global $DB; - $total = $DB->count_records('customcert_templates', array('contextid' => $this->context->id)); + $total = $DB->count_records('customcert_templates', ['contextid' => $this->context->id]); $this->pagesize($pagesize, $total); - $this->rawdata = $DB->get_records('customcert_templates', array('contextid' => $this->context->id), + $this->rawdata = $DB->get_records('customcert_templates', ['contextid' => $this->context->id], $this->get_sql_sort(), '*', $this->get_page_start(), $this->get_page_size()); // Set initial bars. diff --git a/classes/my_certificates_table.php b/classes/my_certificates_table.php index 8da14738..a9090cc1 100644 --- a/classes/my_certificates_table.php +++ b/classes/my_certificates_table.php @@ -53,18 +53,18 @@ class my_certificates_table extends \table_sql { public function __construct($userid, $download = null) { parent::__construct('mod_customcert_report_table'); - $columns = array( + $columns = [ 'name', 'coursename', 'timecreated', 'code' - ); - $headers = array( + ]; + $headers = [ get_string('name'), get_string('course'), get_string('receiveddate', 'customcert'), get_string('code', 'customcert') - ); + ]; // Check if we were passed a filename, which means we want to download it. if ($download) { @@ -144,9 +144,9 @@ public function col_download($certificate) { $icon = new \pix_icon('download', get_string('download'), 'customcert'); $link = new \moodle_url('/mod/customcert/my_certificates.php', - array('userid' => $this->userid, + ['userid' => $this->userid, 'certificateid' => $certificate->id, - 'downloadcert' => '1')); + 'downloadcert' => '1']); return $OUTPUT->action_link($link, '', null, null, $icon); } diff --git a/classes/output/email_certificate.php b/classes/output/email_certificate.php index f6393754..fe3a2c64 100644 --- a/classes/output/email_certificate.php +++ b/classes/output/email_certificate.php @@ -101,13 +101,13 @@ public function export_for_template(\renderer_base $renderer) { $data->emailgreeting = get_string('emailstudentgreeting', 'customcert', $this->userfullname); $data->emailbody = get_string('emailstudentbody', 'customcert', $info); $data->emailbodyplaintext = get_string('emailstudentbodyplaintext', 'customcert', $info); - $data->emailcertificatelink = new \moodle_url('/mod/customcert/view.php', array('id' => $this->cmid)); + $data->emailcertificatelink = new \moodle_url('/mod/customcert/view.php', ['id' => $this->cmid]); $data->emailcertificatelinktext = get_string('emailstudentcertificatelinktext', 'customcert'); } else { $data->emailgreeting = get_string('emailnonstudentgreeting', 'customcert'); $data->emailbody = get_string('emailnonstudentbody', 'customcert', $info); $data->emailbodyplaintext = get_string('emailnonstudentbodyplaintext', 'customcert', $info); - $data->emailcertificatelink = new \moodle_url('/mod/customcert/view.php', array('id' => $this->cmid)); + $data->emailcertificatelink = new \moodle_url('/mod/customcert/view.php', ['id' => $this->cmid]); $data->emailcertificatelinktext = get_string('emailnonstudentcertificatelinktext', 'customcert'); } diff --git a/classes/output/verify_certificate_result.php b/classes/output/verify_certificate_result.php index 1d51694d..970bdd3c 100644 --- a/classes/output/verify_certificate_result.php +++ b/classes/output/verify_certificate_result.php @@ -70,10 +70,10 @@ public function __construct($result) { $cm = get_coursemodule_from_instance('customcert', $result->certificateid); $context = \context_module::instance($cm->id); - $this->userprofileurl = new \moodle_url('/user/view.php', array('id' => $result->userid, - 'course' => $result->courseid)); + $this->userprofileurl = new \moodle_url('/user/view.php', ['id' => $result->userid, + 'course' => $result->courseid]); $this->userfullname = fullname($result); - $this->courseurl = new \moodle_url('/course/view.php', array('id' => $result->courseid)); + $this->courseurl = new \moodle_url('/course/view.php', ['id' => $result->courseid]); $this->coursefullname = format_string($result->coursefullname, true, ['context' => $context]); $this->certificatename = format_string($result->certificatename, true, ['context' => $context]); } diff --git a/classes/output/verify_certificate_results.php b/classes/output/verify_certificate_results.php index cffe1c5e..9cbdc664 100644 --- a/classes/output/verify_certificate_results.php +++ b/classes/output/verify_certificate_results.php @@ -76,7 +76,7 @@ public function export_for_template(\renderer_base $output) { $result = new \stdClass(); $result->success = $this->success; $result->message = $this->message; - $result->issues = array(); + $result->issues = []; foreach ($this->issues as $issue) { $resultissue = new verify_certificate_result($issue); $result->issues[] = $resultissue->export_for_template($output); diff --git a/classes/task/email_certificate_task.php b/classes/task/email_certificate_task.php index 403ee501..06781b4a 100644 --- a/classes/task/email_certificate_task.php +++ b/classes/task/email_certificate_task.php @@ -61,7 +61,7 @@ public function execute() { WHERE (c.emailstudents = :emailstudents OR c.emailteachers = :emailteachers OR $emailotherslengthsql >= 3)"; - if (!$customcerts = $DB->get_records_sql($sql, array('emailstudents' => 1, 'emailteachers' => 1))) { + if (!$customcerts = $DB->get_records_sql($sql, ['emailstudents' => 1, 'emailteachers' => 1])) { return; } @@ -94,9 +94,9 @@ public function execute() { // Store teachers for later. $teachers = get_enrolled_users($context, 'moodle/course:update'); - $courseshortname = format_string($customcert->courseshortname, true, array('context' => $context)); - $coursefullname = format_string($customcert->coursefullname, true, array('context' => $context)); - $certificatename = format_string($customcert->name, true, array('context' => $context)); + $courseshortname = format_string($customcert->courseshortname, true, ['context' => $context]); + $coursefullname = format_string($customcert->coursefullname, true, ['context' => $context]); + $certificatename = format_string($customcert->name, true, ['context' => $context]); // Used to create the email subject. $info = new \stdClass; @@ -112,7 +112,7 @@ public function execute() { JOIN {user} u ON ci.userid = u.id WHERE ci.customcertid = :customcertid"; - $issuedusers = $DB->get_records_sql($sql, array('customcertid' => $customcert->id)); + $issuedusers = $DB->get_records_sql($sql, ['customcertid' => $customcert->id]); // Now, get a list of users who can access the certificate but have not yet. $enrolledusers = get_enrolled_users(\context_course::instance($customcert->courseid), 'mod/customcert:view'); @@ -148,7 +148,7 @@ public function execute() { // Ensure the cert hasn't already been issued, e.g via the UI (view.php) - a race condition. $issueid = $DB->get_field('customcert_issues', 'id', - array('userid' => $enroluser->id, 'customcertid' => $customcert->id), IGNORE_MULTIPLE); + ['userid' => $enroluser->id, 'customcertid' => $customcert->id], IGNORE_MULTIPLE); if (empty($issueid)) { // Ok, issue them the certificate. $issueid = \mod_customcert\certificate::issue_certificate($customcert->id, $enroluser->id); @@ -251,7 +251,7 @@ public function execute() { } // Set the field so that it is emailed. - $DB->set_field('customcert_issues', 'emailed', 1, array('id' => $user->issueid)); + $DB->set_field('customcert_issues', 'emailed', 1, ['id' => $user->issueid]); } } } diff --git a/classes/template.php b/classes/template.php index af24bd26..444af034 100644 --- a/classes/template.php +++ b/classes/template.php @@ -95,7 +95,7 @@ public function add_page(bool $triggertemplateupdatedevent = true) { $sql = "SELECT MAX(sequence) as maxpage FROM {customcert_pages} cp WHERE cp.templateid = :templateid"; - if ($maxpage = $DB->get_record_sql($sql, array('templateid' => $this->id))) { + if ($maxpage = $DB->get_record_sql($sql, ['templateid' => $this->id])) { $sequence = $maxpage->maxpage + 1; } @@ -134,7 +134,7 @@ public function save_page($data) { $time = time(); // Get the existing pages and save the page data. - if ($pages = $DB->get_records('customcert_pages', array('templateid' => $data->tid))) { + if ($pages = $DB->get_records('customcert_pages', ['templateid' => $data->tid])) { // Loop through existing pages. foreach ($pages as $page) { // Only update if there is a difference. @@ -172,14 +172,14 @@ public function delete() { global $DB; // Delete the pages. - if ($pages = $DB->get_records('customcert_pages', array('templateid' => $this->id))) { + if ($pages = $DB->get_records('customcert_pages', ['templateid' => $this->id])) { foreach ($pages as $page) { $this->delete_page($page->id, false); } } // Now, finally delete the actual template. - if (!$DB->delete_records('customcert_templates', array('id' => $this->id))) { + if (!$DB->delete_records('customcert_templates', ['id' => $this->id])) { return false; } @@ -199,23 +199,23 @@ public function delete_page(int $pageid, bool $triggertemplateupdatedevent = tru global $DB; // Get the page. - $page = $DB->get_record('customcert_pages', array('id' => $pageid), '*', MUST_EXIST); + $page = $DB->get_record('customcert_pages', ['id' => $pageid], '*', MUST_EXIST); // The element may have some extra tasks it needs to complete to completely delete itself. - if ($elements = $DB->get_records('customcert_elements', array('pageid' => $page->id))) { + if ($elements = $DB->get_records('customcert_elements', ['pageid' => $page->id])) { foreach ($elements as $element) { // Get an instance of the element class. if ($e = \mod_customcert\element_factory::get_element_instance($element)) { $e->delete(); } else { // The plugin files are missing, so just remove the entry from the DB. - $DB->delete_records('customcert_elements', array('id' => $element->id)); + $DB->delete_records('customcert_elements', ['id' => $element->id]); } } } // Delete this page. - $DB->delete_records('customcert_pages', array('id' => $page->id)); + $DB->delete_records('customcert_pages', ['id' => $page->id]); \mod_customcert\event\page_deleted::create_from_page($page, $this)->trigger(); @@ -225,7 +225,7 @@ public function delete_page(int $pageid, bool $triggertemplateupdatedevent = tru SET sequence = sequence - 1 WHERE templateid = :templateid AND sequence > :sequence"; - $DB->execute($sql, array('templateid' => $this->id, 'sequence' => $page->sequence)); + $DB->execute($sql, ['templateid' => $this->id, 'sequence' => $page->sequence]); if ($triggertemplateupdatedevent) { \mod_customcert\event\template_updated::create_from_template($this)->trigger(); @@ -241,14 +241,14 @@ public function delete_element($elementid) { global $DB; // Ensure element exists and delete it. - $element = $DB->get_record('customcert_elements', array('id' => $elementid), '*', MUST_EXIST); + $element = $DB->get_record('customcert_elements', ['id' => $elementid], '*', MUST_EXIST); // Get an instance of the element class. if ($e = \mod_customcert\element_factory::get_element_instance($element)) { $e->delete(); } else { // The plugin files are missing, so just remove the entry from the DB. - $DB->delete_records('customcert_elements', array('id' => $elementid)); + $DB->delete_records('customcert_elements', ['id' => $elementid]); } // Now we want to decrease the sequence numbers of the elements @@ -257,7 +257,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]); \mod_customcert\event\template_updated::create_from_template($this)->trigger(); } @@ -283,7 +283,7 @@ public function generate_pdf(bool $preview = false, int $userid = null, bool $re require_once($CFG->dirroot . '/mod/customcert/lib.php'); // Get the pages for the template, there should always be at least one page for each template. - if ($pages = $DB->get_records('customcert_pages', array('templateid' => $this->id), 'sequence ASC')) { + if ($pages = $DB->get_records('customcert_pages', ['templateid' => $this->id], 'sequence ASC')) { // Create the pdf object. $pdf = new \pdf(); @@ -340,10 +340,10 @@ public function generate_pdf(bool $preview = false, int $userid = null, bool $re } else { $orientation = 'P'; } - $pdf->AddPage($orientation, array($page->width, $page->height)); + $pdf->AddPage($orientation, [$page->width, $page->height]); $pdf->SetMargins($page->leftmargin, 0, $page->rightmargin); // Get the elements for the page. - if ($elements = $DB->get_records('customcert_elements', array('pageid' => $page->id), 'sequence ASC')) { + if ($elements = $DB->get_records('customcert_elements', ['pageid' => $page->id], 'sequence ASC')) { // Loop through and display. foreach ($elements as $element) { // Get an instance of the element class. @@ -381,7 +381,7 @@ public function copy_to_template($copytotemplate) { $copytotemplateid = $copytotemplate->get_id(); // Get the pages for the template, there should always be at least one page for each template. - if ($templatepages = $DB->get_records('customcert_pages', array('templateid' => $this->id))) { + if ($templatepages = $DB->get_records('customcert_pages', ['templateid' => $this->id])) { // Loop through the pages. foreach ($templatepages as $templatepage) { $page = clone($templatepage); @@ -392,7 +392,7 @@ public function copy_to_template($copytotemplate) { $page->id = $DB->insert_record('customcert_pages', $page); \mod_customcert\event\page_created::create_from_page($page, $copytotemplate)->trigger(); // Now go through the elements we want to load. - if ($templateelements = $DB->get_records('customcert_elements', array('pageid' => $templatepage->id))) { + if ($templateelements = $DB->get_records('customcert_elements', ['pageid' => $templatepage->id])) { foreach ($templateelements as $templateelement) { $element = clone($templateelement); $element->pageid = $page->id; @@ -439,7 +439,7 @@ public function move_item($itemname, $itemid, $direction) { $table .= 'elements'; } - if ($moveitem = $DB->get_record($table, array('id' => $itemid))) { + if ($moveitem = $DB->get_record($table, ['id' => $itemid])) { // Check which direction we are going. if ($direction == 'up') { $sequence = $moveitem->sequence - 1; @@ -450,17 +450,17 @@ public function move_item($itemname, $itemid, $direction) { // Get the item we will be swapping with. Make sure it is related to the same template (if it's // a page) or the same page (if it's an element). if ($itemname == 'page') { - $params = array('templateid' => $moveitem->templateid); + $params = ['templateid' => $moveitem->templateid]; } else { // Must be an element. - $params = array('pageid' => $moveitem->pageid); + $params = ['pageid' => $moveitem->pageid]; } - $swapitem = $DB->get_record($table, $params + array('sequence' => $sequence)); + $swapitem = $DB->get_record($table, $params + ['sequence' => $sequence]); } // Check that there is an item to move, and an item to swap it with. if ($moveitem && !empty($swapitem)) { - $DB->set_field($table, 'sequence', $swapitem->sequence, array('id' => $moveitem->id)); - $DB->set_field($table, 'sequence', $moveitem->sequence, array('id' => $swapitem->id)); + $DB->set_field($table, 'sequence', $swapitem->sequence, ['id' => $moveitem->id]); + $DB->set_field($table, 'sequence', $moveitem->sequence, ['id' => $swapitem->id]); \mod_customcert\event\template_updated::create_from_template($this)->trigger(); } diff --git a/classes/upload_image_form.php b/classes/upload_image_form.php index 44228976..320537ea 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' => 'image'); + 'accepted_types' => 'image']; $mform->addElement('filemanager', 'customcertimage', get_string('uploadimage', 'customcert'), '', $this->filemanageroptions); diff --git a/classes/verify_certificate_form.php b/classes/verify_certificate_form.php index 15ce6b8c..0baa779a 100644 --- a/classes/verify_certificate_form.php +++ b/classes/verify_certificate_form.php @@ -57,7 +57,7 @@ public function definition() { * @return array the errors that were found */ public function validation($data, $files) { - $errors = array(); + $errors = []; if ($data['code'] === '') { $errors['code'] = get_string('invalidcode', 'customcert'); diff --git a/db/access.php b/db/access.php index da603457..f3f71555 100644 --- a/db/access.php +++ b/db/access.php @@ -24,153 +24,153 @@ defined('MOODLE_INTERNAL') || die(); -$capabilities = array( +$capabilities = [ - 'mod/customcert:addinstance' => array( + 'mod/customcert:addinstance' => [ 'riskbitmask' => RISK_XSS, 'captype' => 'write', 'contextlevel' => CONTEXT_COURSE, - 'archetypes' => array( + 'archetypes' => [ 'editingteacher' => CAP_ALLOW, 'manager' => CAP_ALLOW - ), + ], 'clonepermissionsfrom' => 'moodle/course:manageactivities' - ), + ], - 'mod/customcert:view' => array( + 'mod/customcert:view' => [ 'captype' => 'read', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'student' => CAP_ALLOW, 'teacher' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW, 'manager' => CAP_ALLOW - ) - ), + ] + ], - 'mod/customcert:manage' => array( + 'mod/customcert:manage' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'editingteacher' => CAP_ALLOW, 'manager' => CAP_ALLOW - ) - ), + ] + ], - 'mod/customcert:receiveissue' => array( + 'mod/customcert:receiveissue' => [ 'captype' => 'read', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'student' => CAP_ALLOW - ) - ), + ] + ], - 'mod/customcert:viewreport' => array( + 'mod/customcert:viewreport' => [ 'captype' => 'read', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'teacher' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW, 'manager' => CAP_ALLOW - ) - ), + ] + ], - 'mod/customcert:viewallcertificates' => array( + 'mod/customcert:viewallcertificates' => [ 'captype' => 'read', 'contextlevel' => CONTEXT_SYSTEM, - 'archetypes' => array( + 'archetypes' => [ 'manager' => CAP_ALLOW - ) - ), + ] + ], - 'mod/customcert:verifycertificate' => array( + 'mod/customcert:verifycertificate' => [ 'captype' => 'read', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'teacher' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW, 'manager' => CAP_ALLOW - ) - ), + ] + ], - 'mod/customcert:verifyallcertificates' => array( + 'mod/customcert:verifyallcertificates' => [ 'captype' => 'read', 'contextlevel' => CONTEXT_SYSTEM, - 'archetypes' => array( + 'archetypes' => [ 'manager' => CAP_ALLOW - ) - ), + ] + ], - 'mod/customcert:manageemailstudents' => array( + 'mod/customcert:manageemailstudents' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_COURSE, - 'archetypes' => array( + 'archetypes' => [ 'editingteacher' => CAP_ALLOW, 'manager' => CAP_ALLOW - ), + ], 'clonepermissionsfrom' => 'moodle/course:manageactivities' - ), + ], - 'mod/customcert:manageemailteachers' => array( + 'mod/customcert:manageemailteachers' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_COURSE, - 'archetypes' => array( + 'archetypes' => [ 'editingteacher' => CAP_ALLOW, 'manager' => CAP_ALLOW - ), + ], 'clonepermissionsfrom' => 'moodle/course:manageactivities' - ), + ], - 'mod/customcert:manageemailothers' => array( + 'mod/customcert:manageemailothers' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_COURSE, - 'archetypes' => array( + 'archetypes' => [ 'editingteacher' => CAP_ALLOW, 'manager' => CAP_ALLOW - ), + ], 'clonepermissionsfrom' => 'moodle/course:manageactivities' - ), + ], - 'mod/customcert:manageverifyany' => array( + 'mod/customcert:manageverifyany' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_COURSE, - 'archetypes' => array( + 'archetypes' => [ 'editingteacher' => CAP_ALLOW, 'manager' => CAP_ALLOW - ), + ], 'clonepermissionsfrom' => 'moodle/course:manageactivities' - ), + ], - 'mod/customcert:managerequiredtime' => array( + 'mod/customcert:managerequiredtime' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_COURSE, - 'archetypes' => array( + 'archetypes' => [ 'editingteacher' => CAP_ALLOW, 'manager' => CAP_ALLOW - ), + ], 'clonepermissionsfrom' => 'moodle/course:manageactivities' - ), + ], - 'mod/customcert:manageprotection' => array( + 'mod/customcert:manageprotection' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_COURSE, - 'archetypes' => array( + 'archetypes' => [ 'editingteacher' => CAP_ALLOW, 'manager' => CAP_ALLOW - ), + ], 'clonepermissionsfrom' => 'moodle/course:manageactivities' - ), + ], - 'mod/customcert:managelanguages' => array( + 'mod/customcert:managelanguages' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_COURSE, - 'archetypes' => array( + 'archetypes' => [ 'editingteacher' => CAP_ALLOW, 'manager' => CAP_ALLOW - ), + ], 'clonepermissionsfrom' => 'moodle/course:manageactivities' - ), -); + ], +]; diff --git a/db/log.php b/db/log.php index 9b3790cb..b2799eb2 100644 --- a/db/log.php +++ b/db/log.php @@ -24,9 +24,9 @@ defined('MOODLE_INTERNAL') || die(); -$logs = array( - array('module' => 'customcert', 'action' => 'view', 'mtable' => 'customcert', 'field' => 'name'), - array('module' => 'customcert', 'action' => 'add', 'mtable' => 'customcert', 'field' => 'name'), - array('module' => 'customcert', 'action' => 'update', 'mtable' => 'customcert', 'field' => 'name'), - array('module' => 'customcert', 'action' => 'received', 'mtable' => 'customcert', 'field' => 'name'), -); +$logs = [ + ['module' => 'customcert', 'action' => 'view', 'mtable' => 'customcert', 'field' => 'name'], + ['module' => 'customcert', 'action' => 'add', 'mtable' => 'customcert', 'field' => 'name'], + ['module' => 'customcert', 'action' => 'update', 'mtable' => 'customcert', 'field' => 'name'], + ['module' => 'customcert', 'action' => 'received', 'mtable' => 'customcert', 'field' => 'name'], +]; diff --git a/db/services.php b/db/services.php index 923d8428..8a481a58 100644 --- a/db/services.php +++ b/db/services.php @@ -24,30 +24,30 @@ defined('MOODLE_INTERNAL') || die(); -$functions = array( - 'mod_customcert_delete_issue' => array( +$functions = [ + 'mod_customcert_delete_issue' => [ 'classname' => 'mod_customcert\external', 'methodname' => 'delete_issue', 'classpath' => '', 'description' => 'Delete an issue for a certificate', 'type' => 'write', 'ajax' => true, - 'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE) - ), - 'mod_customcert_save_element' => array( + 'services' => [MOODLE_OFFICIAL_MOBILE_SERVICE] + ], + 'mod_customcert_save_element' => [ 'classname' => 'mod_customcert\external', 'methodname' => 'save_element', 'classpath' => '', 'description' => 'Saves data for an element', 'type' => 'write', 'ajax' => true - ), - 'mod_customcert_get_element_html' => array( + ], + 'mod_customcert_get_element_html' => [ 'classname' => 'mod_customcert\external', 'methodname' => 'get_element_html', 'classpath' => '', 'description' => 'Returns the HTML to display for an element', 'type' => 'read', 'ajax' => true - ), -); + ], +]; diff --git a/db/tasks.php b/db/tasks.php index 91f6e2a5..fa58805d 100644 --- a/db/tasks.php +++ b/db/tasks.php @@ -25,8 +25,8 @@ defined('MOODLE_INTERNAL') || die(); -$tasks = array( - array( +$tasks = [ + [ 'classname' => 'mod_customcert\task\email_certificate_task', 'blocking' => 0, 'minute' => '*', @@ -34,5 +34,5 @@ 'day' => '*', 'month' => '*', 'dayofweek' => '*' - ) -); + ] +]; diff --git a/edit.php b/edit.php index d9e4540d..bd0218ed 100644 --- a/edit.php +++ b/edit.php @@ -34,17 +34,17 @@ // Edit an existing template. if ($tid) { // Create the template object. - $template = $DB->get_record('customcert_templates', array('id' => $tid), '*', MUST_EXIST); + $template = $DB->get_record('customcert_templates', ['id' => $tid], '*', MUST_EXIST); $template = new \mod_customcert\template($template); // Set the context. $contextid = $template->get_contextid(); // Set the page url. - $pageurl = new moodle_url('/mod/customcert/edit.php', array('tid' => $tid)); + $pageurl = new moodle_url('/mod/customcert/edit.php', ['tid' => $tid]); } else { // Adding a new template. // Need to supply the contextid. $contextid = required_param('contextid', PARAM_INT); // Set the page url. - $pageurl = new moodle_url('/mod/customcert/edit.php', array('contextid' => $contextid)); + $pageurl = new moodle_url('/mod/customcert/edit.php', ['contextid' => $contextid]); } $context = context::instance_by_id($contextid); @@ -98,13 +98,13 @@ break; case 'addpage' : $template->add_page(); - $url = new \moodle_url('/mod/customcert/edit.php', array('tid' => $tid)); + $url = new \moodle_url('/mod/customcert/edit.php', ['tid' => $tid]); redirect($url); break; case 'deletepage' : if (!empty($confirm)) { // Check they have confirmed the deletion. $template->delete_page($actionid); - $url = new \moodle_url('/mod/customcert/edit.php', array('tid' => $tid)); + $url = new \moodle_url('/mod/customcert/edit.php', ['tid' => $tid]); redirect($url); } else { // Set deletion flag to true. @@ -112,15 +112,15 @@ // Create the message. $message = get_string('deletepageconfirm', 'customcert'); // Create the link options. - $nourl = new moodle_url('/mod/customcert/edit.php', array('tid' => $tid)); + $nourl = new moodle_url('/mod/customcert/edit.php', ['tid' => $tid]); $yesurl = new moodle_url('/mod/customcert/edit.php', - array( + [ 'tid' => $tid, 'action' => 'deletepage', 'aid' => $actionid, 'confirm' => 1, 'sesskey' => sesskey() - ) + ] ); } break; @@ -133,15 +133,15 @@ // Create the message. $message = get_string('deleteelementconfirm', 'customcert'); // Create the link options. - $nourl = new moodle_url('/mod/customcert/edit.php', array('tid' => $tid)); + $nourl = new moodle_url('/mod/customcert/edit.php', ['tid' => $tid]); $yesurl = new moodle_url('/mod/customcert/edit.php', - array( + [ 'tid' => $tid, 'action' => 'deleteelement', 'aid' => $actionid, 'confirm' => 1, 'sesskey' => sesskey() - ) + ] ); } break; @@ -160,9 +160,9 @@ } if ($tid) { - $mform = new \mod_customcert\edit_form($pageurl, array('tid' => $tid)); + $mform = new \mod_customcert\edit_form($pageurl, ['tid' => $tid]); // Set the name for the form. - $mform->set_data(array('name' => $template->get_name())); + $mform->set_data(['name' => $template->get_name()]); } else { $mform = new \mod_customcert\edit_form($pageurl); } @@ -219,7 +219,7 @@ $element = "element_" . $pageid; $element = $data->$element; // Create the URL to redirect to to add this element. - $params = array(); + $params = []; $params['tid'] = $template->get_id(); $params['action'] = 'add'; $params['element'] = $element; @@ -236,16 +236,16 @@ } // Redirect to the editing page to show form with recent updates. - $url = new moodle_url('/mod/customcert/edit.php', array('tid' => $template->get_id())); + $url = new moodle_url('/mod/customcert/edit.php', ['tid' => $template->get_id()]); redirect($url); } echo $OUTPUT->header(); $mform->display(); if ($tid && $context->contextlevel == CONTEXT_MODULE) { - $loadtemplateurl = new moodle_url('/mod/customcert/load_template.php', array('tid' => $tid)); - $loadtemplateform = new \mod_customcert\load_template_form($loadtemplateurl, array('context' => $context), 'post', - '', array('id' => 'loadtemplateform')); + $loadtemplateurl = new moodle_url('/mod/customcert/load_template.php', ['tid' => $tid]); + $loadtemplateform = new \mod_customcert\load_template_form($loadtemplateurl, ['context' => $context], 'post', + '', ['id' => 'loadtemplateform']); $loadtemplateform->display(); } echo $OUTPUT->footer(); diff --git a/edit_element.php b/edit_element.php index 126a139a..bcfac711 100644 --- a/edit_element.php +++ b/edit_element.php @@ -27,7 +27,7 @@ $tid = required_param('tid', PARAM_INT); $action = required_param('action', PARAM_ALPHA); -$template = $DB->get_record('customcert_templates', array('id' => $tid), '*', MUST_EXIST); +$template = $DB->get_record('customcert_templates', ['id' => $tid], '*', MUST_EXIST); // Set the template object. $template = new \mod_customcert\template($template); @@ -51,15 +51,15 @@ if ($action == 'edit') { // The id of the element must be supplied if we are currently editing one. $id = required_param('id', PARAM_INT); - $element = $DB->get_record('customcert_elements', array('id' => $id), '*', MUST_EXIST); - $pageurl = new moodle_url('/mod/customcert/edit_element.php', array('id' => $id, 'tid' => $tid, 'action' => $action)); + $element = $DB->get_record('customcert_elements', ['id' => $id], '*', MUST_EXIST); + $pageurl = new moodle_url('/mod/customcert/edit_element.php', ['id' => $id, 'tid' => $tid, 'action' => $action]); } else { // Must be adding an element. // We need to supply what element we want added to what page. $pageid = required_param('pageid', PARAM_INT); $element = new stdClass(); $element->element = required_param('element', PARAM_ALPHA); - $pageurl = new moodle_url('/mod/customcert/edit_element.php', array('tid' => $tid, 'element' => $element->element, - 'pageid' => $pageid, 'action' => $action)); + $pageurl = new moodle_url('/mod/customcert/edit_element.php', ['tid' => $tid, 'element' => $element->element, + 'pageid' => $pageid, 'action' => $action]); } // Set up the page. @@ -73,14 +73,14 @@ new moodle_url('/mod/customcert/manage_templates.php')); } $PAGE->navbar->add(get_string('editcustomcert', 'customcert'), new moodle_url('/mod/customcert/edit.php', - array('tid' => $tid))); + ['tid' => $tid])); $PAGE->navbar->add(get_string('editelement', 'customcert')); -$mform = new \mod_customcert\edit_element_form($pageurl, array('element' => $element)); +$mform = new \mod_customcert\edit_element_form($pageurl, ['element' => $element]); // Check if they cancelled. if ($mform->is_cancelled()) { - $url = new moodle_url('/mod/customcert/edit.php', array('tid' => $tid)); + $url = new moodle_url('/mod/customcert/edit.php', ['tid' => $tid]); redirect($url); } @@ -102,7 +102,7 @@ \mod_customcert\event\template_updated::create_from_template($template)->trigger(); } - $url = new moodle_url('/mod/customcert/edit.php', array('tid' => $tid)); + $url = new moodle_url('/mod/customcert/edit.php', ['tid' => $tid]); redirect($url); } diff --git a/element/bgimage/classes/element.php b/element/bgimage/classes/element.php index 9a1bf271..b50ce224 100644 --- a/element/bgimage/classes/element.php +++ b/element/bgimage/classes/element.php @@ -53,7 +53,7 @@ public function render_form_elements($mform) { */ public function validate_form_elements($data, $files) { // Array to return the errors. - return array(); + return []; } /** @@ -117,11 +117,11 @@ public function render_html() { $url = \moodle_url::make_pluginfile_url($file->get_contextid(), 'mod_customcert', 'image', $file->get_itemid(), $file->get_filepath(), $file->get_filename()); // Get the page we are rendering this on. - $page = $DB->get_record('customcert_pages', array('id' => $this->get_pageid()), '*', MUST_EXIST); + $page = $DB->get_record('customcert_pages', ['id' => $this->get_pageid()], '*', MUST_EXIST); // Set the image to the size of the page. $style = 'width: ' . $page->width . 'mm; height: ' . $page->height . 'mm'; - return \html_writer::tag('img', '', array('src' => $url, 'style' => $style)); + return \html_writer::tag('img', '', ['src' => $url, 'style' => $style]); } } } diff --git a/element/bgimage/db/upgrade.php b/element/bgimage/db/upgrade.php index 364a1b5d..e5712a3f 100644 --- a/element/bgimage/db/upgrade.php +++ b/element/bgimage/db/upgrade.php @@ -41,7 +41,7 @@ function xmldb_customcertelement_bgimage_upgrade($oldversion) { // Get the current data we have stored for this element. $elementinfo = json_decode($image->data); if ($file = $fs->get_file_by_hash($elementinfo->pathnamehash)) { - $arrtostore = array( + $arrtostore = [ 'contextid' => $file->get_contextid(), 'filearea' => $file->get_filearea(), 'itemid' => $file->get_itemid(), @@ -49,9 +49,9 @@ function xmldb_customcertelement_bgimage_upgrade($oldversion) { 'filename' => $file->get_filename(), 'width' => (int) $elementinfo->width, 'height' => (int) $elementinfo->height - ); + ]; $arrtostore = json_encode($arrtostore); - $DB->set_field('customcert_elements', 'data', $arrtostore, array('id' => $image->id)); + $DB->set_field('customcert_elements', 'data', $arrtostore, ['id' => $image->id]); } } } diff --git a/element/border/classes/element.php b/element/border/classes/element.php index 6eda5c76..a5032cb6 100644 --- a/element/border/classes/element.php +++ b/element/border/classes/element.php @@ -55,7 +55,7 @@ public function render_form_elements($mform) { */ public function render($pdf, $preview, $user) { $colour = \TCPDF_COLORS::convertHTMLColorToDec($this->get_colour(), $colour); - $pdf->SetLineStyle(array('width' => $this->get_data(), 'color' => $colour)); + $pdf->SetLineStyle(['width' => $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()); @@ -83,7 +83,7 @@ public function render_html() { */ public function validate_form_elements($data, $files) { // Array to return the errors. - $errors = array(); + $errors = []; // Validate the width. $errors += \mod_customcert\element_helper::validate_form_element_width($data, false); diff --git a/element/categoryname/classes/element.php b/element/categoryname/classes/element.php index a9b304b5..93631450 100644 --- a/element/categoryname/classes/element.php +++ b/element/categoryname/classes/element.php @@ -70,7 +70,7 @@ protected function get_category_name() : string { // Check that there is a course category available. if (!empty($course->category)) { - $categoryname = $DB->get_field('course_categories', 'name', array('id' => $course->category), MUST_EXIST); + $categoryname = $DB->get_field('course_categories', 'name', ['id' => $course->category], MUST_EXIST); } else { // Must be in a site template. $categoryname = $SITE->fullname; } diff --git a/element/code/classes/element.php b/element/code/classes/element.php index 02eed30a..545362b7 100644 --- a/element/code/classes/element.php +++ b/element/code/classes/element.php @@ -47,11 +47,11 @@ public function render($pdf, $preview, $user) { $code = \mod_customcert\certificate::generate_code(); } else { // Get the page. - $page = $DB->get_record('customcert_pages', array('id' => $this->get_pageid()), '*', MUST_EXIST); + $page = $DB->get_record('customcert_pages', ['id' => $this->get_pageid()], '*', MUST_EXIST); // Get the customcert this page belongs to. - $customcert = $DB->get_record('customcert', array('templateid' => $page->templateid), '*', MUST_EXIST); + $customcert = $DB->get_record('customcert', ['templateid' => $page->templateid], '*', MUST_EXIST); // Now we can get the issue for this user. - $issue = $DB->get_record('customcert_issues', array('userid' => $user->id, 'customcertid' => $customcert->id), + $issue = $DB->get_record('customcert_issues', ['userid' => $user->id, 'customcertid' => $customcert->id], '*', IGNORE_MULTIPLE); $code = $issue->code; } diff --git a/element/coursefield/classes/element.php b/element/coursefield/classes/element.php index e4049497..53017db0 100644 --- a/element/coursefield/classes/element.php +++ b/element/coursefield/classes/element.php @@ -41,13 +41,13 @@ class element extends \mod_customcert\element { */ public function render_form_elements($mform) { // Get the user profile fields. - $coursefields = array( + $coursefields = [ 'fullname' => get_string('fullnamecourse'), 'shortname' => get_string('shortnamecourse'), 'idnumber' => get_string('idnumbercourse') - ); + ]; // Get the course custom fields. - $arrcustomfields = array(); + $arrcustomfields = []; $handler = \core_course\customfield\course_handler::create(); $customfields = $handler->get_fields(); diff --git a/element/date/classes/element.php b/element/date/classes/element.php index a0361e72..d241f030 100644 --- a/element/date/classes/element.php +++ b/element/date/classes/element.php @@ -111,7 +111,7 @@ public function render_form_elements($mform) { global $CFG, $COURSE; // Get the possible date options. - $dateoptions = array(); + $dateoptions = []; $dateoptions[CUSTOMCERT_DATE_ISSUE] = get_string('issueddate', 'customcertelement_date'); $dateoptions[CUSTOMCERT_DATE_CURRENT_DATE] = get_string('currentdate', 'customcertelement_date'); $completionenabled = $CFG->enablecompletion && ($COURSE->id == SITEID || $COURSE->enablecompletion); @@ -148,10 +148,10 @@ public function render_form_elements($mform) { */ public function save_unique_data($data) { // Array of data we will be storing in the database. - $arrtostore = array( + $arrtostore = [ 'dateitem' => $data->dateitem, 'dateformat' => $data->dateformat - ); + ]; // Encode these variables before saving into the DB. return json_encode($arrtostore); @@ -184,11 +184,11 @@ public function render($pdf, $preview, $user) { $date = time(); } else { // Get the page. - $page = $DB->get_record('customcert_pages', array('id' => $this->get_pageid()), '*', MUST_EXIST); + $page = $DB->get_record('customcert_pages', ['id' => $this->get_pageid()], '*', MUST_EXIST); // Get the customcert this page belongs to. - $customcert = $DB->get_record('customcert', array('templateid' => $page->templateid), '*', MUST_EXIST); + $customcert = $DB->get_record('customcert', ['templateid' => $page->templateid], '*', MUST_EXIST); // Now we can get the issue for this user. - $issue = $DB->get_record('customcert_issues', array('userid' => $user->id, 'customcertid' => $customcert->id), + $issue = $DB->get_record('customcert_issues', ['userid' => $user->id, 'customcertid' => $customcert->id], '*', IGNORE_MULTIPLE); if ($dateitem == CUSTOMCERT_DATE_ISSUE) { @@ -211,7 +211,7 @@ public function render($pdf, $preview, $user) { FROM {course_completions} c WHERE c.userid = :userid AND c.course = :courseid"; - if ($timecompleted = $DB->get_record_sql($sql, array('userid' => $issue->userid, 'courseid' => $courseid))) { + if ($timecompleted = $DB->get_record_sql($sql, ['userid' => $issue->userid, 'courseid' => $courseid])) { if (!empty($timecompleted->timecompleted)) { $date = $timecompleted->timecompleted; } @@ -221,7 +221,7 @@ public function render($pdf, $preview, $user) { $sql = "SELECT ue.timestart FROM {enrol} e JOIN {user_enrolments} ue ON ue.enrolid = e.id WHERE e.courseid = :courseid AND ue.userid = :userid"; - if ($timestart = $DB->get_record_sql($sql, array('userid' => $issue->userid, 'courseid' => $courseid))) { + if ($timestart = $DB->get_record_sql($sql, ['userid' => $issue->userid, 'courseid' => $courseid])) { if (!empty($timestart->timestart)) { $date = $timestart->timestart; } @@ -231,15 +231,15 @@ public function render($pdf, $preview, $user) { $sql = "SELECT ue.timeend FROM {enrol} e JOIN {user_enrolments} ue ON ue.enrolid = e.id WHERE e.courseid = :courseid AND ue.userid = :userid"; - if ($timeend = $DB->get_record_sql($sql, array('userid' => $issue->userid, 'courseid' => $courseid))) { + if ($timeend = $DB->get_record_sql($sql, ['userid' => $issue->userid, 'courseid' => $courseid])) { if (!empty($timeend->timeend)) { $date = $timeend->timeend; } } } else if ($dateitem == CUSTOMCERT_DATE_COURSE_START) { - $date = $DB->get_field('course', 'startdate', array('id' => $courseid)); + $date = $DB->get_field('course', 'startdate', ['id' => $courseid]); } else if ($dateitem == CUSTOMCERT_DATE_COURSE_END) { - $date = $DB->get_field('course', 'enddate', array('id' => $courseid)); + $date = $DB->get_field('course', 'enddate', ['id' => $courseid]); } else { if ($dateitem == CUSTOMCERT_DATE_COURSE_GRADE) { $grade = \mod_customcert\element_helper::get_course_grade_info( @@ -329,7 +329,7 @@ public function after_restore($restore) { $dateinfo = json_decode($this->get_data()); if ($newitem = \restore_dbops::get_backup_ids_record($restore->get_restoreid(), 'course_module', $dateinfo->dateitem)) { $dateinfo->dateitem = $newitem->newitemid; - $DB->set_field('customcert_elements', 'data', $this->save_unique_data($dateinfo), array('id' => $this->get_id())); + $DB->set_field('customcert_elements', 'data', $this->save_unique_data($dateinfo), ['id' => $this->get_id()]); } } @@ -432,7 +432,7 @@ protected function get_date_format_string($date, $dateformat) { * @return string the suffix. */ protected static function get_ordinal_number_suffix($day) { - if (!in_array(($day % 100), array(11, 12, 13))) { + if (!in_array(($day % 100), [11, 12, 13])) { switch ($day % 10) { // Handle 1st, 2nd, 3rd. case 1: diff --git a/element/daterange/classes/element.php b/element/daterange/classes/element.php index 0e45ca41..506bdf74 100644 --- a/element/daterange/classes/element.php +++ b/element/daterange/classes/element.php @@ -113,7 +113,7 @@ public function render_form_elements($mform) { global $COURSE; // Get the possible date options. - $dateoptions = array(); + $dateoptions = []; $dateoptions[self::DATE_ISSUE] = get_string('issueddate', 'customcertelement_daterange'); $dateoptions[self::DATE_CURRENT_DATE] = get_string('currentdate', 'customcertelement_daterange'); $dateoptions[self::DATE_COMPLETION] = get_string('completiondate', 'customcertelement_daterange'); @@ -180,7 +180,7 @@ public function render_form_elements($mform) { [0, 1] ); - $rangeoptions = array(); + $rangeoptions = []; $rangeoptions['startdate']['type'] = PARAM_INT; $rangeoptions['enddate']['type'] = PARAM_INT; $rangeoptions['recurring']['type'] = PARAM_INT; @@ -296,11 +296,11 @@ public function validate_form_elements($data, $files) { * @return string the json encoded array */ public function save_unique_data($data) { - $arrtostore = array( + $arrtostore = [ 'dateitem' => $data->dateitem, 'fallbackstring' => $data->fallbackstring, 'dateranges' => [], - ); + ]; for ($i = 0; $i < $data->repeats; $i++) { if (empty($data->rangedelete[$i])) { @@ -340,11 +340,11 @@ public function render($pdf, $preview, $user) { $date = time(); } else { // Get the page. - $page = $DB->get_record('customcert_pages', array('id' => $this->get_pageid()), '*', MUST_EXIST); + $page = $DB->get_record('customcert_pages', ['id' => $this->get_pageid()], '*', MUST_EXIST); // Get the customcert this page belongs to. - $customcert = $DB->get_record('customcert', array('templateid' => $page->templateid), '*', MUST_EXIST); + $customcert = $DB->get_record('customcert', ['templateid' => $page->templateid], '*', MUST_EXIST); // Now we can get the issue for this user. - $issue = $DB->get_record('customcert_issues', array('userid' => $user->id, 'customcertid' => $customcert->id), + $issue = $DB->get_record('customcert_issues', ['userid' => $user->id, 'customcertid' => $customcert->id], '*', MUST_EXIST); switch ($dateitem) { @@ -362,7 +362,7 @@ public function render($pdf, $preview, $user) { FROM {course_completions} c WHERE c.userid = :userid AND c.course = :courseid"; - if ($timecompleted = $DB->get_record_sql($sql, array('userid' => $issue->userid, 'courseid' => $courseid))) { + if ($timecompleted = $DB->get_record_sql($sql, ['userid' => $issue->userid, 'courseid' => $courseid])) { if (!empty($timecompleted->timecompleted)) { $date = $timecompleted->timecompleted; } @@ -370,11 +370,11 @@ public function render($pdf, $preview, $user) { break; case self::DATE_COURSE_START: - $date = $DB->get_field('course', 'startdate', array('id' => $courseid)); + $date = $DB->get_field('course', 'startdate', ['id' => $courseid]); break; case self::DATE_COURSE_END: - $date = $DB->get_field('course', 'enddate', array('id' => $courseid)); + $date = $DB->get_field('course', 'enddate', ['id' => $courseid]); break; case self::DATE_COURSE_GRADE: @@ -724,7 +724,7 @@ public function after_restore($restore) { $data = $this->get_decoded_data(); if ($newitem = \restore_dbops::get_backup_ids_record($restore->get_restoreid(), 'course_module', $data->dateitem)) { $data->dateitem = $newitem->newitemid; - $DB->set_field('customcert_elements', 'data', $this->save_unique_data($data), array('id' => $this->get_id())); + $DB->set_field('customcert_elements', 'data', $this->save_unique_data($data), ['id' => $this->get_id()]); } } diff --git a/element/digitalsignature/classes/element.php b/element/digitalsignature/classes/element.php index 4b1451d3..07a4ce4a 100644 --- a/element/digitalsignature/classes/element.php +++ b/element/digitalsignature/classes/element.php @@ -36,7 +36,7 @@ class element extends \customcertelement_image\element { /** * @var array The file manager options for the certificate. */ - protected $signaturefilemanageroptions = array(); + protected $signaturefilemanageroptions = []; /** * Constructor. @@ -292,7 +292,7 @@ public static function get_signatures() { $fs = get_file_storage(); // The array used to store the digital signatures. - $arrfiles = array(); + $arrfiles = []; // Loop through the files uploaded in the system context. if ($files = $fs->get_area_files(\context_system::instance()->id, 'mod_customcert', 'signature', false, 'filename', false)) { @@ -309,7 +309,7 @@ public static function get_signatures() { } \core_collator::asort($arrfiles); - $arrfiles = array('0' => get_string('nosignature', 'customcertelement_digitalsignature')) + $arrfiles; + $arrfiles = ['0' => get_string('nosignature', 'customcertelement_digitalsignature')] + $arrfiles; return $arrfiles; } diff --git a/element/grade/classes/element.php b/element/grade/classes/element.php index f100a98c..7b4e6cbf 100644 --- a/element/grade/classes/element.php +++ b/element/grade/classes/element.php @@ -47,7 +47,7 @@ public function render_form_elements($mform) { global $COURSE; // Get the grade items we can display. - $gradeitems = array(); + $gradeitems = []; $gradeitems[CUSTOMCERT_GRADE_COURSE] = get_string('coursegrade', 'customcertelement_grade'); $gradeitems = $gradeitems + \mod_customcert\element_helper::get_grade_items($COURSE); @@ -73,10 +73,10 @@ public function render_form_elements($mform) { */ public function save_unique_data($data) { // Array of data we will be storing in the database. - $arrtostore = array( + $arrtostore = [ 'gradeitem' => $data->gradeitem, 'gradeformat' => $data->gradeformat - ); + ]; // Encode these variables before saving into the DB. return json_encode($arrtostore); @@ -196,7 +196,7 @@ public function after_restore($restore) { $gradeinfo = json_decode($this->get_data()); if ($newitem = \restore_dbops::get_backup_ids_record($restore->get_restoreid(), 'course_module', $gradeinfo->gradeitem)) { $gradeinfo->gradeitem = $newitem->newitemid; - $DB->set_field('customcert_elements', 'data', $this->save_unique_data($gradeinfo), array('id' => $this->get_id())); + $DB->set_field('customcert_elements', 'data', $this->save_unique_data($gradeinfo), ['id' => $this->get_id()]); } } @@ -206,7 +206,7 @@ public function after_restore($restore) { * @return array returns an array of grade formats */ public static function get_grade_format_options() { - $gradeformat = array(); + $gradeformat = []; $gradeformat[GRADE_DISPLAY_TYPE_REAL] = get_string('gradepoints', 'customcertelement_grade'); $gradeformat[GRADE_DISPLAY_TYPE_PERCENTAGE] = get_string('gradepercent', 'customcertelement_grade'); $gradeformat[GRADE_DISPLAY_TYPE_LETTER] = get_string('gradeletter', 'customcertelement_grade'); diff --git a/element/gradeitemname/classes/element.php b/element/gradeitemname/classes/element.php index b529ca8d..837adaf5 100644 --- a/element/gradeitemname/classes/element.php +++ b/element/gradeitemname/classes/element.php @@ -125,11 +125,11 @@ protected function get_grade_item_name() : string { // This will effectively prevent the element from rendering. return $gradeitem ? $gradeitem->get_name() : ''; } else { - if (!$cm = $DB->get_record('course_modules', array('id' => $gradeitem))) { + if (!$cm = $DB->get_record('course_modules', ['id' => $gradeitem])) { return ''; } - if (!$module = $DB->get_record('modules', array('id' => $cm->module))) { + if (!$module = $DB->get_record('modules', ['id' => $cm->module])) { return ''; } diff --git a/element/image/classes/element.php b/element/image/classes/element.php index 6b8cb746..f1ab3e26 100644 --- a/element/image/classes/element.php +++ b/element/image/classes/element.php @@ -36,7 +36,7 @@ class element extends \mod_customcert\element { /** * @var array The file manager options. */ - protected $filemanageroptions = array(); + protected $filemanageroptions = []; /** * Constructor. @@ -46,11 +46,11 @@ class element extends \mod_customcert\element { public function __construct($element) { global $COURSE; - $this->filemanageroptions = array( + $this->filemanageroptions = [ 'maxbytes' => $COURSE->maxbytes, 'subdirs' => 1, 'accepted_types' => 'image' - ); + ]; parent::__construct($element); } @@ -102,7 +102,7 @@ public function render_form_elements($mform) { */ public function validate_form_elements($data, $files) { // Array to return the errors. - $errors = array(); + $errors = []; // Validate the width. $errors += \mod_customcert\element_helper::validate_form_element_width($data); @@ -263,7 +263,7 @@ public function render_html() { $style .= 'height: ' . $imageinfo->height . 'mm'; } - return \html_writer::tag('img', '', array('src' => $url, 'style' => $style)); + return \html_writer::tag('img', '', ['src' => $url, 'style' => $style]); } } @@ -337,7 +337,7 @@ public function after_restore($restore) { $elementinfo = json_encode($elementinfo); // Perform the update. - $DB->set_field('customcert_elements', 'data', $elementinfo, array('id' => $this->get_id())); + $DB->set_field('customcert_elements', 'data', $elementinfo, ['id' => $this->get_id()]); } /** @@ -366,7 +366,7 @@ public static function get_images() { $fs = get_file_storage(); // The array used to store the images. - $arrfiles = array(); + $arrfiles = []; // Loop through the files uploaded in the system context. if ($files = $fs->get_area_files(\context_system::instance()->id, 'mod_customcert', 'image', false, 'filename', false)) { foreach ($files as $hash => $file) { @@ -382,7 +382,7 @@ public static function get_images() { } \core_collator::asort($arrfiles); - $arrfiles = array('0' => get_string('noimage', 'customcert')) + $arrfiles; + $arrfiles = ['0' => get_string('noimage', 'customcert')] + $arrfiles; return $arrfiles; } diff --git a/element/image/db/upgrade.php b/element/image/db/upgrade.php index c70fd25c..ba791ff4 100644 --- a/element/image/db/upgrade.php +++ b/element/image/db/upgrade.php @@ -41,7 +41,7 @@ function xmldb_customcertelement_image_upgrade($oldversion) { // Get the current data we have stored for this element. $elementinfo = json_decode($image->data); if ($file = $fs->get_file_by_hash($elementinfo->pathnamehash)) { - $arrtostore = array( + $arrtostore = [ 'contextid' => $file->get_contextid(), 'filearea' => $file->get_filearea(), 'itemid' => $file->get_itemid(), @@ -49,9 +49,9 @@ function xmldb_customcertelement_image_upgrade($oldversion) { 'filename' => $file->get_filename(), 'width' => (int) $elementinfo->width, 'height' => (int) $elementinfo->height - ); + ]; $arrtostore = json_encode($arrtostore); - $DB->set_field('customcert_elements', 'data', $arrtostore, array('id' => $image->id)); + $DB->set_field('customcert_elements', 'data', $arrtostore, ['id' => $image->id]); } } } diff --git a/element/qrcode/classes/element.php b/element/qrcode/classes/element.php index 04320ab3..0171b46b 100644 --- a/element/qrcode/classes/element.php +++ b/element/qrcode/classes/element.php @@ -151,7 +151,7 @@ public function render($pdf, $preview, $user) { AND cp.id = :pageid"; // Now we can get the issue for this user. - $issue = $DB->get_record_sql($sql, array('userid' => $user->id, 'pageid' => $this->get_pageid()), + $issue = $DB->get_record_sql($sql, ['userid' => $user->id, 'pageid' => $this->get_pageid()], '*', MUST_EXIST); $code = $issue->code; diff --git a/element/teachername/classes/element.php b/element/teachername/classes/element.php index 086a9e50..bbe01e91 100644 --- a/element/teachername/classes/element.php +++ b/element/teachername/classes/element.php @@ -69,7 +69,7 @@ public function save_unique_data($data) { public function render($pdf, $preview, $user) { global $DB; - $teacher = $DB->get_record('user', array('id' => $this->get_data())); + $teacher = $DB->get_record('user', ['id' => $this->get_data()]); $teachername = fullname($teacher); \mod_customcert\element_helper::render_content($pdf, $this, $teachername); @@ -86,7 +86,7 @@ public function render($pdf, $preview, $user) { public function render_html() { global $DB; - $teacher = $DB->get_record('user', array('id' => $this->get_data())); + $teacher = $DB->get_record('user', ['id' => $this->get_data()]); $teachername = fullname($teacher); return \mod_customcert\element_helper::render_html_content($this, $teachername); @@ -106,7 +106,7 @@ protected function get_list_of_teachers() { } // The list of teachers to return. - $teachers = array(); + $teachers = []; // Now return all users who can manage the customcert in this context. if ($users = get_enrolled_users($PAGE->context, 'mod/customcert:manage')) { diff --git a/element/userfield/classes/element.php b/element/userfield/classes/element.php index 5d8cf902..c92384ac 100644 --- a/element/userfield/classes/element.php +++ b/element/userfield/classes/element.php @@ -42,7 +42,7 @@ class element extends \mod_customcert\element { */ public function render_form_elements($mform) { // Get the user profile fields. - $userfields = array( + $userfields = [ 'firstname' => fields::get_display_name('firstname'), 'lastname' => fields::get_display_name('lastname'), 'username' => fields::get_display_name('username'), @@ -56,10 +56,10 @@ public function render_form_elements($mform) { 'phone1' => fields::get_display_name('phone1'), 'phone2' => fields::get_display_name('phone2'), 'address' => fields::get_display_name('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] = $customfield->name; } @@ -141,7 +141,7 @@ protected function get_user_field_value(\stdClass $user, bool $preview) : string $value = ''; } if (is_number($field)) { // Must be a custom user profile field. - if ($field = $DB->get_record('user_info_field', array('id' => $field))) { + if ($field = $DB->get_record('user_info_field', ['id' => $field])) { // Found the field name, let's update the value to display. $value = $field->name; $file = $CFG->dirroot . '/user/profile/field/' . $field->datatype . '/field.class.php'; diff --git a/element/userpicture/classes/element.php b/element/userpicture/classes/element.php index cc5ab99f..58aab610 100644 --- a/element/userpicture/classes/element.php +++ b/element/userpicture/classes/element.php @@ -57,7 +57,7 @@ public function render_form_elements($mform) { */ public function validate_form_elements($data, $files) { // Array to return the errors. - $errors = array(); + $errors = []; // Validate the width. $errors += \mod_customcert\element_helper::validate_form_element_width($data); @@ -82,10 +82,10 @@ public function validate_form_elements($data, $files) { */ public function save_unique_data($data) { // Array of data we will be storing in the database. - $arrtostore = array( + $arrtostore = [ 'width' => (int) $data->width, 'height' => (int) $data->height - ); + ]; return json_encode($arrtostore); } @@ -172,7 +172,7 @@ public function render_html() { $style .= 'height: ' . $imageinfo->height . 'mm'; } - return \html_writer::tag('img', '', array('src' => $url, 'style' => $style)); + return \html_writer::tag('img', '', ['src' => $url, 'style' => $style]); } /** diff --git a/includes/colourpicker.php b/includes/colourpicker.php index cad6e2c0..f52086c4 100644 --- a/includes/colourpicker.php +++ b/includes/colourpicker.php @@ -41,7 +41,7 @@ class moodlequickform_customcert_colourpicker extends moodlequickform_editor { * @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/index.php b/index.php index 1ab05ed9..65a41685 100644 --- a/index.php +++ b/index.php @@ -26,13 +26,13 @@ $id = required_param('id', PARAM_INT); // Course ID. -$course = $DB->get_record('course', array('id' => $id), '*', MUST_EXIST); +$course = $DB->get_record('course', ['id' => $id], '*', MUST_EXIST); // Requires a login. require_login($course); // Set up the page variables. -$pageurl = new moodle_url('/mod/customcert/index.php', array('id' => $course->id)); +$pageurl = new moodle_url('/mod/customcert/index.php', ['id' => $course->id]); \mod_customcert\page_helper::page_setup($pageurl, context_course::instance($id), get_string('modulenameplural', 'customcert')); @@ -41,16 +41,16 @@ $PAGE->navbar->add(get_string('modulenameplural', 'customcert')); // Add the page view to the Moodle log. -$event = \mod_customcert\event\course_module_instance_list_viewed::create(array( +$event = \mod_customcert\event\course_module_instance_list_viewed::create([ 'context' => context_course::instance($course->id) -)); +]); $event->add_record_snapshot('course', $course); $event->trigger(); // Get the customcerts, if there are none display a notice. if (!$customcerts = get_all_instances_in_course('customcert', $course)) { echo $OUTPUT->header(); - notice(get_string('nocustomcerts', 'customcert'), new moodle_url('/course/view.php', array('id' => $course->id))); + notice(get_string('nocustomcerts', 'customcert'), new moodle_url('/course/view.php', ['id' => $course->id])); echo $OUTPUT->footer(); exit(); } @@ -59,21 +59,21 @@ $table = new html_table(); if ($usesections = course_format_uses_sections($course->format)) { - $table->head = array(get_string('sectionname', 'format_'.$course->format), get_string('name'), - get_string('receiveddate', 'customcert')); + $table->head = [get_string('sectionname', 'format_'.$course->format), get_string('name'), + get_string('receiveddate', 'customcert')]; } else { - $table->head = array(get_string('name'), get_string('receiveddate', 'customcert')); + $table->head = [get_string('name'), get_string('receiveddate', 'customcert')]; } $currentsection = ''; foreach ($customcerts as $customcert) { // Check if the customcert is visible, if so show text as normal, else show it as dimmed. if ($customcert->visible) { - $link = html_writer::tag('a', $customcert->name, array('href' => new moodle_url('/mod/customcert/view.php', - array('id' => $customcert->coursemodule)))); + $link = html_writer::tag('a', $customcert->name, ['href' => new moodle_url('/mod/customcert/view.php', + ['id' => $customcert->coursemodule])]); } else { - $link = html_writer::tag('a', $customcert->name, array('class' => 'dimmed', - 'href' => new moodle_url('/mod/customcert/view.php', array('id' => $customcert->coursemodule)))); + $link = html_writer::tag('a', $customcert->name, ['class' => 'dimmed', + 'href' => new moodle_url('/mod/customcert/view.php', ['id' => $customcert->coursemodule])]); } // If we are at a different section then print a horizontal rule. if ($customcert->section !== $currentsection) { @@ -83,16 +83,16 @@ $currentsection = $customcert->section; } // Check if there is was an issue provided for this user. - if ($certrecord = $DB->get_record('customcert_issues', array('userid' => $USER->id, 'customcertid' => $customcert->id))) { + if ($certrecord = $DB->get_record('customcert_issues', ['userid' => $USER->id, 'customcertid' => $customcert->id])) { $issued = userdate($certrecord->timecreated); } else { $issued = get_string('notissued', 'customcert'); } // Only display the section column if the course format uses sections. if ($usesections) { - $table->data[] = array($customcert->section, $link, $issued); + $table->data[] = [$customcert->section, $link, $issued]; } else { - $table->data[] = array($link, $issued); + $table->data[] = [$link, $issued]; } } diff --git a/lib.php b/lib.php index dcd7c150..819aec3f 100644 --- a/lib.php +++ b/lib.php @@ -78,7 +78,7 @@ function customcert_delete_instance($id) { global $CFG, $DB; // Ensure the customcert exists. - if (!$customcert = $DB->get_record('customcert', array('id' => $id))) { + if (!$customcert = $DB->get_record('customcert', ['id' => $id])) { return false; } @@ -88,18 +88,18 @@ function customcert_delete_instance($id) { } // Delete the customcert instance. - if (!$DB->delete_records('customcert', array('id' => $id))) { + if (!$DB->delete_records('customcert', ['id' => $id])) { return false; } // Now, delete the template associated with this certificate. - if ($template = $DB->get_record('customcert_templates', array('id' => $customcert->templateid))) { + if ($template = $DB->get_record('customcert_templates', ['id' => $customcert->templateid])) { $template = new \mod_customcert\template($template); $template->delete(); } // Delete the customcert issues. - if (!$DB->delete_records('customcert_issues', array('customcertid' => $id))) { + if (!$DB->delete_records('customcert_issues', ['customcertid' => $id])) { return false; } @@ -123,15 +123,15 @@ function customcert_reset_userdata($data) { global $DB; $componentstr = get_string('modulenameplural', 'customcert'); - $status = array(); + $status = []; if (!empty($data->reset_customcert)) { $sql = "SELECT cert.id FROM {customcert} cert WHERE cert.course = :courseid"; - $DB->delete_records_select('customcert_issues', "customcertid IN ($sql)", array('courseid' => $data->courseid)); - $status[] = array('component' => $componentstr, 'item' => get_string('deleteissuedcertificates', 'customcert'), - 'error' => false); + $DB->delete_records_select('customcert_issues', "customcertid IN ($sql)", ['courseid' => $data->courseid]); + $status[] = ['component' => $componentstr, 'item' => get_string('deleteissuedcertificates', 'customcert'), + 'error' => false]; } return $status; @@ -155,7 +155,7 @@ function customcert_reset_course_form_definition(&$mform) { * @return array */ function customcert_reset_course_form_defaults($course) { - return array('reset_customcert' => 1); + return ['reset_customcert' => 1]; } /** @@ -172,7 +172,7 @@ function customcert_user_outline($course, $user, $mod, $customcert) { global $DB; $result = new stdClass(); - if ($issue = $DB->get_record('customcert_issues', array('customcertid' => $customcert->id, 'userid' => $user->id))) { + if ($issue = $DB->get_record('customcert_issues', ['customcertid' => $customcert->id, 'userid' => $user->id])) { $result->info = get_string('receiveddate', 'customcert'); $result->time = $issue->timecreated; } else { @@ -195,7 +195,7 @@ function customcert_user_outline($course, $user, $mod, $customcert) { function customcert_user_complete($course, $user, $mod, $customcert) { global $DB, $OUTPUT; - if ($issue = $DB->get_record('customcert_issues', array('customcertid' => $customcert->id, 'userid' => $user->id))) { + if ($issue = $DB->get_record('customcert_issues', ['customcertid' => $customcert->id, 'userid' => $user->id])) { echo $OUTPUT->box_start(); echo get_string('receiveddate', 'customcert') . ": "; echo userdate($issue->timecreated); @@ -275,7 +275,7 @@ function customcert_supports($feature) { * @return array */ function customcert_get_view_actions() { - return array('view', 'view all', 'view report'); + return ['view', 'view all', 'view report']; } /** @@ -284,7 +284,7 @@ function customcert_get_view_actions() { * @return array */ function customcert_get_post_actions() { - return array('received'); + return ['received']; } /** @@ -304,10 +304,10 @@ function mod_customcert_output_fragment_editelement($args) { global $DB; // Get the element. - $element = $DB->get_record('customcert_elements', array('id' => $args['elementid']), '*', MUST_EXIST); + $element = $DB->get_record('customcert_elements', ['id' => $args['elementid']], '*', MUST_EXIST); - $pageurl = new moodle_url('/mod/customcert/rearrange.php', array('pid' => $element->pageid)); - $form = new \mod_customcert\edit_element_form($pageurl, array('element' => $element)); + $pageurl = new moodle_url('/mod/customcert/rearrange.php', ['pid' => $element->pageid]); + $form = new \mod_customcert\edit_element_form($pageurl, ['element' => $element]); return $form->render(); } @@ -335,9 +335,9 @@ function customcert_extend_settings_navigation(settings_navigation $settings, na if (has_capability('mod/customcert:manage', $settings->get_page()->cm->context)) { // Get the template id. - $templateid = $DB->get_field('customcert', 'templateid', array('id' => $settings->get_page()->cm->instance)); + $templateid = $DB->get_field('customcert', 'templateid', ['id' => $settings->get_page()->cm->instance]); $node = navigation_node::create(get_string('editcustomcert', 'customcert'), - new moodle_url('/mod/customcert/edit.php', array('tid' => $templateid)), + new moodle_url('/mod/customcert/edit.php', ['tid' => $templateid]), navigation_node::TYPE_SETTING, null, 'mod_customcert_edit', new pix_icon('t/edit', '')); $customcertnode->add_node($node, $beforekey); @@ -345,7 +345,7 @@ function customcert_extend_settings_navigation(settings_navigation $settings, na if (has_capability('mod/customcert:verifycertificate', $settings->get_page()->cm->context)) { $node = navigation_node::create(get_string('verifycertificate', 'customcert'), - new moodle_url('/mod/customcert/verify_certificate.php', array('contextid' => $settings->get_page()->cm->context->id)), + new moodle_url('/mod/customcert/verify_certificate.php', ['contextid' => $settings->get_page()->cm->context->id]), navigation_node::TYPE_SETTING, null, 'mod_customcert_verify_certificate', new pix_icon('t/check', '')); $customcertnode->add_node($node, $beforekey); @@ -395,9 +395,9 @@ function mod_customcert_inplace_editable($itemtype, $itemid, $newvalue) { global $DB, $PAGE; if ($itemtype === 'elementname') { - $element = $DB->get_record('customcert_elements', array('id' => $itemid), '*', MUST_EXIST); - $page = $DB->get_record('customcert_pages', array('id' => $element->pageid), '*', MUST_EXIST); - $template = $DB->get_record('customcert_templates', array('id' => $page->templateid), '*', MUST_EXIST); + $element = $DB->get_record('customcert_elements', ['id' => $itemid], '*', MUST_EXIST); + $page = $DB->get_record('customcert_pages', ['id' => $element->pageid], '*', MUST_EXIST); + $template = $DB->get_record('customcert_templates', ['id' => $page->templateid], '*', MUST_EXIST); // Set the template object. $template = new \mod_customcert\template($template); diff --git a/load_template.php b/load_template.php index f74e514e..a7dfe7ad 100644 --- a/load_template.php +++ b/load_template.php @@ -28,10 +28,10 @@ $ltid = required_param('ltid', PARAM_INT); // The template to load. $confirm = optional_param('confirm', 0, PARAM_INT); -$template = $DB->get_record('customcert_templates', array('id' => $tid), '*', MUST_EXIST); +$template = $DB->get_record('customcert_templates', ['id' => $tid], '*', MUST_EXIST); $template = new \mod_customcert\template($template); -$loadtemplate = $DB->get_record('customcert_templates', array('id' => $ltid), '*', MUST_EXIST); +$loadtemplate = $DB->get_record('customcert_templates', ['id' => $ltid], '*', MUST_EXIST); $loadtemplate = new \mod_customcert\template($loadtemplate); if ($cm = $template->get_cm()) { @@ -61,24 +61,24 @@ $loadtemplate->copy_to_template($template); // Redirect. - $url = new moodle_url('/mod/customcert/edit.php', array('tid' => $tid)); + $url = new moodle_url('/mod/customcert/edit.php', ['tid' => $tid]); redirect($url); } // Create the link options. -$nourl = new moodle_url('/mod/customcert/edit.php', array('tid' => $tid)); -$yesurl = new moodle_url('/mod/customcert/load_template.php', array('tid' => $tid, +$nourl = new moodle_url('/mod/customcert/edit.php', ['tid' => $tid]); +$yesurl = new moodle_url('/mod/customcert/load_template.php', ['tid' => $tid, 'ltid' => $ltid, 'confirm' => 1, - 'sesskey' => sesskey())); + 'sesskey' => sesskey()]); -$pageurl = new moodle_url('/mod/customcert/load_template.php', array('tid' => $tid, 'ltid' => $ltid)); +$pageurl = new moodle_url('/mod/customcert/load_template.php', ['tid' => $tid, 'ltid' => $ltid]); \mod_customcert\page_helper::page_setup($pageurl, $template->get_context(), $title); $PAGE->activityheader->set_attrs(['hidecompletion' => true, 'description' => '']); $str = get_string('editcustomcert', 'customcert'); -$link = new moodle_url('/mod/customcert/edit.php', array('tid' => $template->get_id())); +$link = new moodle_url('/mod/customcert/edit.php', ['tid' => $template->get_id()]); $PAGE->navbar->add($str, new \action_link($link, $str)); $PAGE->navbar->add(get_string('loadtemplate', 'customcert')); diff --git a/manage_templates.php b/manage_templates.php index 50b8e66f..bb94ff12 100644 --- a/manage_templates.php +++ b/manage_templates.php @@ -37,7 +37,7 @@ } if ($tid) { - $template = $DB->get_record('customcert_templates', array('id' => $tid), '*', MUST_EXIST); + $template = $DB->get_record('customcert_templates', ['id' => $tid], '*', MUST_EXIST); $template = new \mod_customcert\template($template); } @@ -64,12 +64,12 @@ if ($action && confirm_sesskey()) { $nourl = new moodle_url('/mod/customcert/manage_templates.php'); $yesurl = new moodle_url('/mod/customcert/manage_templates.php', - array( + [ 'tid' => $tid, 'action' => $action, 'confirm' => 1, 'sesskey' => sesskey() - ) + ] ); // Check if we are deleting a template. diff --git a/mobile/pluginfile.php b/mobile/pluginfile.php index 20485f1e..0baad6b0 100644 --- a/mobile/pluginfile.php +++ b/mobile/pluginfile.php @@ -56,7 +56,7 @@ } $cm = get_coursemodule_from_instance('customcert', $certificateid, 0, false, MUST_EXIST); -$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); +$course = $DB->get_record('course', ['id' => $cm->course], '*', MUST_EXIST); $certificate = $DB->get_record('customcert', ['id' => $certificateid], '*', MUST_EXIST); $template = $DB->get_record('customcert_templates', ['id' => $certificate->templateid], '*', MUST_EXIST); diff --git a/mod_form.php b/mod_form.php index 00bb5b5c..917deec2 100644 --- a/mod_form.php +++ b/mod_form.php @@ -47,7 +47,7 @@ public function definition() { $mform->addElement('header', 'general', get_string('general', 'form')); - $mform->addElement('text', 'name', get_string('name', 'customcert'), array('size' => '64')); + $mform->addElement('text', 'name', get_string('name', 'customcert'), ['size' => '64']); if (!empty($CFG->formatstringstriptags)) { $mform->setType('name', PARAM_TEXT); } else { @@ -81,7 +81,7 @@ public function definition() { } if (has_capability('mod/customcert:manageemailothers', $this->get_context())) { - $mform->addElement('text', 'emailothers', get_string('emailothers', 'customcert'), array('size' => '40')); + $mform->addElement('text', 'emailothers', get_string('emailothers', 'customcert'), ['size' => '40']); $mform->addHelpButton('emailothers', 'emailothers', 'customcert'); $mform->setDefault('emailothers', get_config('customcert', 'emailothers')); $mform->setType('emailothers', PARAM_TEXT); @@ -95,7 +95,7 @@ public function definition() { } if (has_capability('mod/customcert:managerequiredtime', $this->get_context())) { - $mform->addElement('text', 'requiredtime', get_string('coursetimereq', 'customcert'), array('size' => '3')); + $mform->addElement('text', 'requiredtime', get_string('coursetimereq', 'customcert'), ['size' => '3']); $mform->addHelpButton('requiredtime', 'coursetimereq', 'customcert'); $mform->setDefault('requiredtime', get_config('customcert', 'requiredtime')); $mform->setType('requiredtime', PARAM_INT); @@ -170,7 +170,7 @@ public function data_postprocessing($data) { } else { // If updating, but a user can't manage protection, then get data from database. if (!has_capability('mod/customcert:manageprotection', $this->get_context())) { - $customcert = $DB->get_record('customcert', array('id' => $data->instance)); + $customcert = $DB->get_record('customcert', ['id' => $data->instance]); $protection = $this->build_protection_data($customcert->protection); $data->protection_print = $protection->protection_print; diff --git a/my_certificates.php b/my_certificates.php index f7077075..906c2b4c 100644 --- a/my_certificates.php +++ b/my_certificates.php @@ -30,7 +30,7 @@ $downloadcert = optional_param('downloadcert', '', PARAM_BOOL); if ($downloadcert) { $certificateid = required_param('certificateid', PARAM_INT); - $customcert = $DB->get_record('customcert', array('id' => $certificateid), '*', MUST_EXIST); + $customcert = $DB->get_record('customcert', ['id' => $certificateid], '*', MUST_EXIST); // Check there exists an issued certificate for this user. if (!$issue = $DB->get_record('customcert_issues', ['userid' => $userid, 'customcertid' => $customcert->id])) { @@ -39,8 +39,8 @@ } $page = optional_param('page', 0, PARAM_INT); $perpage = optional_param('perpage', \mod_customcert\certificate::CUSTOMCERT_PER_PAGE, PARAM_INT); -$pageurl = $url = new moodle_url('/mod/customcert/my_certificates.php', array('userid' => $userid, - 'page' => $page, 'perpage' => $perpage)); +$pageurl = $url = new moodle_url('/mod/customcert/my_certificates.php', ['userid' => $userid, + 'page' => $page, 'perpage' => $perpage]); // Requires a login. if ($courseid) { @@ -65,7 +65,7 @@ // Check if we requested to download a certificate. if ($downloadcert) { - $template = $DB->get_record('customcert_templates', array('id' => $customcert->templateid), '*', MUST_EXIST); + $template = $DB->get_record('customcert_templates', ['id' => $customcert->templateid], '*', MUST_EXIST); $template = new \mod_customcert\template($template); $template->generate_pdf(false, $userid); exit(); @@ -80,7 +80,7 @@ } // Additional page setup. -$PAGE->navbar->add(get_string('profile'), new moodle_url('/user/profile.php', array('id' => $userid))); +$PAGE->navbar->add(get_string('profile'), new moodle_url('/user/profile.php', ['id' => $userid])); $PAGE->navbar->add(get_string('mycertificates', 'customcert')); echo $OUTPUT->header(); diff --git a/rearrange.php b/rearrange.php index 81ce0cd0..1b9cafda 100644 --- a/rearrange.php +++ b/rearrange.php @@ -27,9 +27,9 @@ // The page of the customcert we are editing. $pid = required_param('pid', PARAM_INT); -$page = $DB->get_record('customcert_pages', array('id' => $pid), '*', MUST_EXIST); -$template = $DB->get_record('customcert_templates', array('id' => $page->templateid), '*', MUST_EXIST); -$elements = $DB->get_records('customcert_elements', array('pageid' => $pid), 'sequence'); +$page = $DB->get_record('customcert_pages', ['id' => $pid], '*', MUST_EXIST); +$template = $DB->get_record('customcert_templates', ['id' => $page->templateid], '*', MUST_EXIST); +$elements = $DB->get_records('customcert_elements', ['pageid' => $pid], 'sequence'); // Set the template. $template = new \mod_customcert\template($template); @@ -52,7 +52,7 @@ } // Set the $PAGE settings. -$pageurl = new moodle_url('/mod/customcert/rearrange.php', array('pid' => $pid)); +$pageurl = new moodle_url('/mod/customcert/rearrange.php', ['pid' => $pid]); \mod_customcert\page_helper::page_setup($pageurl, $template->get_context(), $title); $PAGE->activityheader->set_attrs(['hidecompletion' => true, 'description' => '']); @@ -65,35 +65,35 @@ } $str = get_string('editcustomcert', 'customcert'); -$link = new moodle_url('/mod/customcert/edit.php', array('tid' => $template->get_id())); +$link = new moodle_url('/mod/customcert/edit.php', ['tid' => $template->get_id()]); $PAGE->navbar->add($str, new \action_link($link, $str)); $PAGE->navbar->add(get_string('rearrangeelements', 'customcert')); // Include the JS we need. $PAGE->requires->yui_module('moodle-mod_customcert-rearrange', 'Y.M.mod_customcert.rearrange.init', - array($template->get_id(), + [$template->get_id(), $page, - $elements)); + $elements]); // Create the buttons to save the position of the elements. -$html = html_writer::start_tag('div', array('class' => 'buttons')); -$html .= $OUTPUT->single_button(new moodle_url('/mod/customcert/edit.php', array('tid' => $template->get_id())), - get_string('saveandclose', 'customcert'), 'get', array('class' => 'savepositionsbtn')); -$html .= $OUTPUT->single_button(new moodle_url('/mod/customcert/rearrange.php', array('pid' => $pid)), - get_string('saveandcontinue', 'customcert'), 'get', array('class' => 'applypositionsbtn')); -$html .= $OUTPUT->single_button(new moodle_url('/mod/customcert/edit.php', array('tid' => $template->get_id())), - get_string('cancel'), 'get', array('class' => 'cancelbtn')); +$html = html_writer::start_tag('div', ['class' => 'buttons']); +$html .= $OUTPUT->single_button(new moodle_url('/mod/customcert/edit.php', ['tid' => $template->get_id()]), + get_string('saveandclose', 'customcert'), 'get', ['class' => 'savepositionsbtn']); +$html .= $OUTPUT->single_button(new moodle_url('/mod/customcert/rearrange.php', ['pid' => $pid]), + get_string('saveandcontinue', 'customcert'), 'get', ['class' => 'applypositionsbtn']); +$html .= $OUTPUT->single_button(new moodle_url('/mod/customcert/edit.php', ['tid' => $template->get_id()]), + get_string('cancel'), 'get', ['class' => 'cancelbtn']); $html .= html_writer::end_tag('div'); // Create the div that represents the PDF. $style = 'height: ' . $page->height . 'mm; line-height: normal; width: ' . $page->width . 'mm;'; $marginstyle = 'height: ' . $page->height . 'mm; width:1px; float:left; position:relative;'; -$html .= html_writer::start_tag('div', array( +$html .= html_writer::start_tag('div', [ 'data-templateid' => $template->get_id(), 'data-contextid' => $template->get_contextid(), 'id' => 'pdf', - 'style' => $style) + 'style' => $style] ); if ($page->leftmargin) { $position = 'left:' . $page->leftmargin . 'mm;'; @@ -126,8 +126,8 @@ $class .= ' align-left'; break; } - $html .= html_writer::tag('div', $e->render_html(), array('class' => $class, - 'data-refpoint' => $element->refpoint, 'id' => 'element-' . $element->id)); + $html .= html_writer::tag('div', $e->render_html(), ['class' => $class, + 'data-refpoint' => $element->refpoint, 'id' => 'element-' . $element->id]); } } } @@ -141,5 +141,5 @@ echo $OUTPUT->heading(get_string('rearrangeelementsheading', 'customcert'), 3); echo $OUTPUT->notification(get_string('exampledatawarning', 'customcert'), \core\output\notification::NOTIFY_WARNING); echo $html; -$PAGE->requires->js_call_amd('mod_customcert/rearrange-area', 'init', array('#pdf')); +$PAGE->requires->js_call_amd('mod_customcert/rearrange-area', 'init', ['#pdf']); echo $OUTPUT->footer(); diff --git a/report.php b/report.php index fde4f269..c6010978 100644 --- a/report.php +++ b/report.php @@ -29,7 +29,7 @@ $id = required_param('id', PARAM_INT); $cm = get_coursemodule_from_id('customcert', $id, 0, false, MUST_EXIST); -$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); +$course = $DB->get_record('course', ['id' => $cm->course], '*', MUST_EXIST); require_login($course, false, $cm); diff --git a/tests/behat/behat_mod_customcert.php b/tests/behat/behat_mod_customcert.php index f210962e..58fc1f5e 100644 --- a/tests/behat/behat_mod_customcert.php +++ b/tests/behat/behat_mod_customcert.php @@ -49,12 +49,12 @@ class behat_mod_customcert extends behat_base { public function i_add_the_element_to_the_certificate_template_page($elementname, $pagenum, $templatename) { global $DB; - $template = $DB->get_record('customcert_templates', array('name' => $templatename), '*', MUST_EXIST); - $page = $DB->get_record('customcert_pages', array('templateid' => $template->id, 'sequence' => $pagenum), + $template = $DB->get_record('customcert_templates', ['name' => $templatename], '*', MUST_EXIST); + $page = $DB->get_record('customcert_pages', ['templateid' => $template->id, 'sequence' => $pagenum], '*', MUST_EXIST); - $this->execute('behat_forms::i_set_the_field_to', array($this->escape('element_' . $page->id), - $this->escape($elementname))); + $this->execute('behat_forms::i_set_the_field_to', [$this->escape('element_' . $page->id), + $this->escape($elementname)]); $this->execute('behat_forms::press_button', get_string('addelement', 'customcert')); } @@ -68,12 +68,12 @@ public function i_add_the_element_to_the_certificate_template_page($elementname, public function i_delete_the_certificate_page($pagenum, $templatename) { global $DB; - $template = $DB->get_record('customcert_templates', array('name' => $templatename), '*', MUST_EXIST); - $page = $DB->get_record('customcert_pages', array('templateid' => $template->id, 'sequence' => $pagenum), + $template = $DB->get_record('customcert_templates', ['name' => $templatename], '*', MUST_EXIST); + $page = $DB->get_record('customcert_pages', ['templateid' => $template->id, 'sequence' => $pagenum], '*', MUST_EXIST); - $this->execute('behat_general::i_click_on_in_the', array('Delete page', 'link', - $this->escape('#id_page_' . $page->id), 'css_element')); + $this->execute('behat_general::i_click_on_in_the', ['Delete page', 'link', + $this->escape('#id_page_' . $page->id), 'css_element']); $this->execute('behat_forms::press_button', get_string('continue')); } @@ -87,12 +87,12 @@ public function i_delete_the_certificate_page($pagenum, $templatename) { public function i_verify_the_custom_certificate_for_user($certificatename, $username) { global $DB; - $certificate = $DB->get_record('customcert', array('name' => $certificatename), '*', MUST_EXIST); - $user = $DB->get_record('user', array('username' => $username), '*', MUST_EXIST); - $issue = $DB->get_record('customcert_issues', array('userid' => $user->id, 'customcertid' => $certificate->id), + $certificate = $DB->get_record('customcert', ['name' => $certificatename], '*', MUST_EXIST); + $user = $DB->get_record('user', ['username' => $username], '*', MUST_EXIST); + $issue = $DB->get_record('customcert_issues', ['userid' => $user->id, 'customcertid' => $certificate->id], '*', MUST_EXIST); - $this->execute('behat_forms::i_set_the_field_to', array(get_string('code', 'customcert'), $issue->code)); + $this->execute('behat_forms::i_set_the_field_to', [get_string('code', 'customcert'), $issue->code]); $this->execute('behat_forms::press_button', get_string('verify', 'customcert')); $this->execute('behat_general::assert_page_contains_text', get_string('verified', 'customcert')); $this->execute('behat_general::assert_page_not_contains_text', get_string('notverified', 'customcert')); @@ -108,12 +108,12 @@ public function i_verify_the_custom_certificate_for_user($certificatename, $user public function i_can_not_verify_the_custom_certificate_for_user($certificatename, $username) { global $DB; - $certificate = $DB->get_record('customcert', array('name' => $certificatename), '*', MUST_EXIST); - $user = $DB->get_record('user', array('username' => $username), '*', MUST_EXIST); - $issue = $DB->get_record('customcert_issues', array('userid' => $user->id, 'customcertid' => $certificate->id), + $certificate = $DB->get_record('customcert', ['name' => $certificatename], '*', MUST_EXIST); + $user = $DB->get_record('user', ['username' => $username], '*', MUST_EXIST); + $issue = $DB->get_record('customcert_issues', ['userid' => $user->id, 'customcertid' => $certificate->id], '*', MUST_EXIST); - $this->execute('behat_forms::i_set_the_field_to', array(get_string('code', 'customcert'), $issue->code)); + $this->execute('behat_forms::i_set_the_field_to', [get_string('code', 'customcert'), $issue->code]); $this->execute('behat_forms::press_button', get_string('verify', 'customcert')); $this->execute('behat_general::assert_page_contains_text', get_string('notverified', 'customcert')); $this->execute('behat_general::assert_page_not_contains_text', get_string('verified', 'customcert')); @@ -131,10 +131,10 @@ public function i_can_not_verify_the_custom_certificate_for_user($certificatenam public function i_visit_the_verification_url_for_custom_certificate($certificatename) { global $DB; - $certificate = $DB->get_record('customcert', array('name' => $certificatename), '*', MUST_EXIST); - $template = $DB->get_record('customcert_templates', array('id' => $certificate->templateid), '*', MUST_EXIST); + $certificate = $DB->get_record('customcert', ['name' => $certificatename], '*', MUST_EXIST); + $template = $DB->get_record('customcert_templates', ['id' => $certificate->templateid], '*', MUST_EXIST); - $url = new moodle_url('/mod/customcert/verify_certificate.php', array('contextid' => $template->contextid)); + $url = new moodle_url('/mod/customcert/verify_certificate.php', ['contextid' => $template->contextid]); $this->getSession()->visit($this->locate_path($url->out_as_local_url())); } diff --git a/tests/element_helper_test.php b/tests/element_helper_test.php index 4edbb793..940bd635 100644 --- a/tests/element_helper_test.php +++ b/tests/element_helper_test.php @@ -60,10 +60,10 @@ public function test_get_courseid_element_in_course_certificate() { $course = $this->getDataGenerator()->create_course(); // Create a custom certificate in the course. - $customcert = $this->getDataGenerator()->create_module('customcert', array('course' => $course->id)); + $customcert = $this->getDataGenerator()->create_module('customcert', ['course' => $course->id]); // Get the template to add elements to. - $template = $DB->get_record('customcert_templates', array('contextid' => context_module::instance($customcert->cmid)->id)); + $template = $DB->get_record('customcert_templates', ['contextid' => context_module::instance($customcert->cmid)->id]); $template = new template($template); // Add a page to the template. @@ -121,10 +121,10 @@ public function test_get_context_element_in_course_certificate() { $course = $this->getDataGenerator()->create_course(); // Create a custom certificate in the course. - $customcert = $this->getDataGenerator()->create_module('customcert', array('course' => $course->id)); + $customcert = $this->getDataGenerator()->create_module('customcert', ['course' => $course->id]); // Get the template to add elements to. - $template = $DB->get_record('customcert_templates', array('contextid' => context_module::instance($customcert->cmid)->id)); + $template = $DB->get_record('customcert_templates', ['contextid' => context_module::instance($customcert->cmid)->id]); $template = new template($template); // Add a page to the template. @@ -183,9 +183,9 @@ public function test_get_grade_items() { $course = $this->getDataGenerator()->create_course(); // Create a few gradeable items. - $assign1 = $this->getDataGenerator()->create_module('assign', array('course' => $course->id)); - $assign2 = $this->getDataGenerator()->create_module('assign', array('course' => $course->id)); - $assign3 = $this->getDataGenerator()->create_module('assign', array('course' => $course->id)); + $assign1 = $this->getDataGenerator()->create_module('assign', ['course' => $course->id]); + $assign2 = $this->getDataGenerator()->create_module('assign', ['course' => $course->id]); + $assign3 = $this->getDataGenerator()->create_module('assign', ['course' => $course->id]); // Create a manual grade item. $gi = $this->getDataGenerator()->create_grade_item(['courseid' => $course->id]); @@ -235,7 +235,7 @@ public function test_get_mod_grade_info() { $this->getDataGenerator()->enrol_user($student2->id, $course->id); // Create a gradeable item. - $assign = $this->getDataGenerator()->create_module('assign', array('course' => $course->id)); + $assign = $this->getDataGenerator()->create_module('assign', ['course' => $course->id]); // Give a grade to the student. $gi = grade_item::fetch( diff --git a/tests/email_certificate_task_test.php b/tests/email_certificate_task_test.php index 6ddc4a2c..93910d8b 100644 --- a/tests/email_certificate_task_test.php +++ b/tests/email_certificate_task_test.php @@ -141,7 +141,7 @@ public function test_email_certificates_students() { // Create some users. $user1 = $this->getDataGenerator()->create_user(); $user2 = $this->getDataGenerator()->create_user(); - $user3 = $this->getDataGenerator()->create_user(array('firstname' => 'Teacher', 'lastname' => 'One')); + $user3 = $this->getDataGenerator()->create_user(['firstname' => 'Teacher', 'lastname' => 'One']); // Enrol two of them in the course as students. $roleids = $DB->get_records_menu('role', null, '', 'shortname, id'); @@ -152,8 +152,8 @@ public function test_email_certificates_students() { $this->getDataGenerator()->enrol_user($user3->id, $course->id, $roleids['editingteacher']); // Create a custom certificate. - $customcert = $this->getDataGenerator()->create_module('customcert', array('course' => $course->id, - 'emailstudents' => 1)); + $customcert = $this->getDataGenerator()->create_module('customcert', ['course' => $course->id, + 'emailstudents' => 1]); // Create template object. $template = new stdClass(); @@ -228,7 +228,7 @@ public function test_email_certificates_teachers() { // Create some users. $user1 = $this->getDataGenerator()->create_user(); $user2 = $this->getDataGenerator()->create_user(); - $user3 = $this->getDataGenerator()->create_user(array('firstname' => 'Teacher', 'lastname' => 'One')); + $user3 = $this->getDataGenerator()->create_user(['firstname' => 'Teacher', 'lastname' => 'One']); // Enrol two of them in the course as students. $roleids = $DB->get_records_menu('role', null, '', 'shortname, id'); @@ -239,8 +239,8 @@ public function test_email_certificates_teachers() { $this->getDataGenerator()->enrol_user($user3->id, $course->id, $roleids['editingteacher']); // Create a custom certificate. - $customcert = $this->getDataGenerator()->create_module('customcert', array('course' => $course->id, - 'emailteachers' => 1)); + $customcert = $this->getDataGenerator()->create_module('customcert', ['course' => $course->id, + 'emailteachers' => 1]); // Create template object. $template = new stdClass(); @@ -294,8 +294,8 @@ public function test_email_certificates_others() { $this->getDataGenerator()->enrol_user($user2->id, $course->id); // Create a custom certificate. - $customcert = $this->getDataGenerator()->create_module('customcert', array('course' => $course->id, - 'emailothers' => 'testcustomcert@example.com, doo@dah')); + $customcert = $this->getDataGenerator()->create_module('customcert', ['course' => $course->id, + 'emailothers' => 'testcustomcert@example.com, doo@dah']); // Create template object. $template = new stdClass(); @@ -404,8 +404,8 @@ public function test_email_certificates_students_havent_met_required_time() { $this->getDataGenerator()->enrol_user($user1->id, $course->id); // Create a custom certificate. - $customcert = $this->getDataGenerator()->create_module('customcert', array('course' => $course->id, 'emailstudents' => 1, - 'requiredtime' => '60')); + $customcert = $this->getDataGenerator()->create_module('customcert', ['course' => $course->id, 'emailstudents' => 1, + 'requiredtime' => '60']); // Create template object. $template = new stdClass(); diff --git a/tests/generator/lib.php b/tests/generator/lib.php index 7b6e3426..22d69718 100644 --- a/tests/generator/lib.php +++ b/tests/generator/lib.php @@ -43,13 +43,13 @@ class mod_customcert_generator extends testing_module_generator { public function create_instance($record = null, array $options = null) { $record = (object)(array)$record; - $defaultsettings = array( + $defaultsettings = [ 'requiredtime' => 0, 'emailstudents' => 0, 'emailteachers' => 0, 'emailothers' => '', 'protection' => '' - ); + ]; foreach ($defaultsettings as $name => $value) { if (!isset($record->{$name})) { diff --git a/tests/page_test.php b/tests/page_test.php index 3642e741..06b0a8df 100644 --- a/tests/page_test.php +++ b/tests/page_test.php @@ -67,10 +67,10 @@ public function test_delete_non_empty_page(): void { $template->delete_page($page2id); - $records = $DB->count_records('customcert_elements', array('pageid' => $page2id)); + $records = $DB->count_records('customcert_elements', ['pageid' => $page2id]); $this->assertEquals(0, $records); - $records = $DB->count_records('customcert_pages', array('id' => $page2id)); + $records = $DB->count_records('customcert_pages', ['id' => $page2id]); $this->assertEquals(0, $records); } } diff --git a/tests/privacy_provider_test.php b/tests/privacy_provider_test.php index 2a424840..e954f3d5 100644 --- a/tests/privacy_provider_test.php +++ b/tests/privacy_provider_test.php @@ -134,7 +134,7 @@ public function test_export_for_context() { $course = $this->getDataGenerator()->create_course(); - $customcert = $this->getDataGenerator()->create_module('customcert', array('course' => $course->id)); + $customcert = $this->getDataGenerator()->create_module('customcert', ['course' => $course->id]); // Create users who will be issued a certificate. $user1 = $this->getDataGenerator()->create_user(); @@ -173,8 +173,8 @@ public function test_delete_data_for_all_users_in_context() { $course = $this->getDataGenerator()->create_course(); - $customcert = $this->getDataGenerator()->create_module('customcert', array('course' => $course->id)); - $customcert2 = $this->getDataGenerator()->create_module('customcert', array('course' => $course->id)); + $customcert = $this->getDataGenerator()->create_module('customcert', ['course' => $course->id]); + $customcert2 = $this->getDataGenerator()->create_module('customcert', ['course' => $course->id]); // Create users who will be issued a certificate. $user1 = $this->getDataGenerator()->create_user(); @@ -215,7 +215,7 @@ public function test_delete_data_for_user() { $course = $this->getDataGenerator()->create_course(); - $customcert = $this->getDataGenerator()->create_module('customcert', array('course' => $course->id)); + $customcert = $this->getDataGenerator()->create_module('customcert', ['course' => $course->id]); // Create users who will be issued a certificate. $user1 = $this->getDataGenerator()->create_user(); @@ -256,8 +256,8 @@ public function test_delete_data_for_users() { // Create course, customcert and users who will be issued a certificate. $course = $this->getDataGenerator()->create_course(); - $customcert1 = $this->getDataGenerator()->create_module('customcert', array('course' => $course->id)); - $customcert2 = $this->getDataGenerator()->create_module('customcert', array('course' => $course->id)); + $customcert1 = $this->getDataGenerator()->create_module('customcert', ['course' => $course->id]); + $customcert2 = $this->getDataGenerator()->create_module('customcert', ['course' => $course->id]); $cm1 = get_coursemodule_from_instance('customcert', $customcert1->id); $cm2 = get_coursemodule_from_instance('customcert', $customcert2->id); $user1 = $this->getDataGenerator()->create_user(); diff --git a/verify_certificate.php b/verify_certificate.php index f8cdb339..acd60f71 100644 --- a/verify_certificate.php +++ b/verify_certificate.php @@ -33,7 +33,7 @@ $context = context::instance_by_id($contextid); // Set up the page. -$pageurl = new moodle_url('/mod/customcert/verify_certificate.php', array('contextid' => $contextid)); +$pageurl = new moodle_url('/mod/customcert/verify_certificate.php', ['contextid' => $contextid]); if ($code) { $pageurl->param('code', $code); @@ -42,8 +42,8 @@ // Ok, a certificate was specified. if ($context->contextlevel != CONTEXT_SYSTEM) { $cm = get_coursemodule_from_id('customcert', $context->instanceid, 0, false, MUST_EXIST); - $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); - $customcert = $DB->get_record('customcert', array('id' => $cm->instance), '*', MUST_EXIST); + $course = $DB->get_record('course', ['id' => $cm->course], '*', MUST_EXIST); + $customcert = $DB->get_record('customcert', ['id' => $cm->instance], '*', MUST_EXIST); // Check if we are allowing anyone to verify, if so, no need to check login, or permissions. if (!$customcert->verifyany) { @@ -89,7 +89,7 @@ if ($code) { $result = new stdClass(); - $result->issues = array(); + $result->issues = []; // Ok, now check if the code is valid. $userfields = \mod_customcert\helper::get_all_user_name_fields('u'); diff --git a/view.php b/view.php index 2c904e78..f8f149d7 100644 --- a/view.php +++ b/view.php @@ -34,9 +34,9 @@ $perpage = optional_param('perpage', \mod_customcert\certificate::CUSTOMCERT_PER_PAGE, PARAM_INT); $cm = get_coursemodule_from_id('customcert', $id, 0, false, MUST_EXIST); -$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); -$customcert = $DB->get_record('customcert', array('id' => $cm->instance), '*', MUST_EXIST); -$template = $DB->get_record('customcert_templates', array('id' => $customcert->templateid), '*', MUST_EXIST); +$course = $DB->get_record('course', ['id' => $cm->course], '*', MUST_EXIST); +$customcert = $DB->get_record('customcert', ['id' => $cm->instance], '*', MUST_EXIST); +$template = $DB->get_record('customcert_templates', ['id' => $customcert->templateid], '*', MUST_EXIST); // Ensure the user is allowed to view this page. require_login($course, false, $cm); @@ -48,7 +48,7 @@ $canviewreport = has_capability('mod/customcert:viewreport', $context); // Initialise $PAGE. -$pageurl = new moodle_url('/mod/customcert/view.php', array('id' => $cm->id)); +$pageurl = new moodle_url('/mod/customcert/view.php', ['id' => $cm->id]); \mod_customcert\page_helper::page_setup($pageurl, $context, format_string($customcert->name)); // Check if the user can view the certificate based on time spent in course. @@ -86,16 +86,16 @@ } // Delete the issue. - $DB->delete_records('customcert_issues', array('id' => $deleteissue, 'customcertid' => $customcert->id)); + $DB->delete_records('customcert_issues', ['id' => $deleteissue, 'customcertid' => $customcert->id]); // Redirect back to the manage templates page. - redirect(new moodle_url('/mod/customcert/view.php', array('id' => $id))); + redirect(new moodle_url('/mod/customcert/view.php', ['id' => $id])); } -$event = \mod_customcert\event\course_module_viewed::create(array( +$event = \mod_customcert\event\course_module_viewed::create([ 'objectid' => $customcert->id, 'context' => $context, -)); +]); $event->add_record_snapshot('course', $course); $event->add_record_snapshot('customcert', $customcert); $event->trigger(); @@ -121,7 +121,7 @@ // If the current user has been issued a customcert generate HTML to display the details. $issuehtml = ''; - $issues = $DB->get_records('customcert_issues', array('userid' => $USER->id, 'customcertid' => $customcert->id)); + $issues = $DB->get_records('customcert_issues', ['userid' => $USER->id, 'customcertid' => $customcert->id]); if ($issues && !$canmanage) { // Get the most recent issue (there should only be one). $issue = reset($issues); @@ -133,7 +133,7 @@ $downloadbutton = ''; if ($canreceive) { $linkname = get_string('getcustomcert', 'customcert'); - $link = new moodle_url('/mod/customcert/view.php', array('id' => $cm->id, 'downloadown' => true)); + $link = new moodle_url('/mod/customcert/view.php', ['id' => $cm->id, 'downloadown' => true]); $downloadbutton = new single_button($link, $linkname, 'get', true); $downloadbutton->class .= ' m-b-1'; // Seems a bit hackish, ahem. $downloadbutton = $OUTPUT->render($downloadbutton); @@ -156,7 +156,7 @@ $userid = $USER->id; if ($downloadown) { // Create new customcert issue record if one does not already exist. - if (!$DB->record_exists('customcert_issues', array('userid' => $USER->id, 'customcertid' => $customcert->id))) { + if (!$DB->record_exists('customcert_issues', ['userid' => $USER->id, 'customcertid' => $customcert->id])) { \mod_customcert\certificate::issue_certificate($customcert->id, $USER->id); } @@ -169,7 +169,7 @@ // Hack alert - don't initiate the download when running Behat. if (defined('BEHAT_SITE_RUNNING')) { - redirect(new moodle_url('/mod/customcert/view.php', array('id' => $cm->id))); + redirect(new moodle_url('/mod/customcert/view.php', ['id' => $cm->id])); } \core\session\manager::write_close();