Skip to content

Commit

Permalink
Merge branch 'WPOS-56' into 'master'
Browse files Browse the repository at this point in the history
WPOS-56 WP-4395 fix codechecker warnings

See merge request workplace/moodle-tool_certificate!155
  • Loading branch information
dravek committed Oct 2, 2023
2 parents bdb5f75 + 834a446 commit 33dee6c
Show file tree
Hide file tree
Showing 62 changed files with 326 additions and 326 deletions.
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
image: moodlehq/moodle-workplace-plugin-ci:8.0
image: moodlehq/moodle-workplace-plugin-ci:8.0-ci4.1.5

services:
- postgres:13
Expand Down
4 changes: 2 additions & 2 deletions certificates.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
$page = optional_param('page', 0, PARAM_INT);
$perpage = optional_param('perpage', \tool_certificate\certificate::ISSUES_PER_PAGE, PARAM_INT);

$pageurl = $url = new moodle_url('/admin/tool/certificate/certificates.php', array('templateid' => $templateid));
$pageurl = $url = new moodle_url('/admin/tool/certificate/certificates.php', ['templateid' => $templateid]);
$PAGE->set_url($pageurl);
$template = \tool_certificate\template::instance($templateid);
if ($coursecontext = $template->get_context()->get_course_context(false)) {
Expand Down Expand Up @@ -67,7 +67,7 @@
if ($template->can_issue_to_anybody()) {
$data += ['addbutton' => true, 'addbuttontitle' => get_string('issuecertificates', 'tool_certificate'),
'addbuttonurl' => null, 'addbuttonattrs' => ['name' => 'data-tid', 'value' => $template->get_id()],
'addbuttonicon' => true];
'addbuttonicon' => true, ];
}
$PAGE->requires->js_call_amd('tool_certificate/issues-list', 'init');

Expand Down
30 changes: 15 additions & 15 deletions classes/certificate.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public static function count_issues_for_course(int $templateid, int $courseid, s
$params = [
'templateid' => $templateid,
'courseid' => $courseid,
'component' => $component
'component' => $component,
];

if ($groupmode) {
Expand Down Expand Up @@ -323,7 +323,7 @@ public static function get_issues_for_user($userid, $limitfrom, $limitnum, $sort
ON t.id = ci.templateid
WHERE ci.userid = :userid
ORDER BY {$sort}";
return $DB->get_records_sql($sql, array('userid' => $userid), $limitfrom, $limitnum);
return $DB->get_records_sql($sql, ['userid' => $userid], $limitfrom, $limitnum);
}

/**
Expand Down Expand Up @@ -499,81 +499,81 @@ public static function create_demo_template(): void {
// Create template elements.
$str = get_string('demotmplbackground', 'tool_certificate');
$elementrecord = ['pageid' => $page->get_id(), 'name' => $str, 'element' => 'image',
'data' => json_encode(['width' => 0, 'height' => 0, 'isbackground' => true]), 'sequence' => 1];
'data' => json_encode(['width' => 0, 'height' => 0, 'isbackground' => true]), 'sequence' => 1, ];
$element = new \tool_certificate\persistent\element(0, (object)$elementrecord);
$element->save();
self::create_demo_element_file($element->get('id'), "{$CFG->dirroot}/{$CFG->admin}/tool/certificate/pix/background.jpg");

$str = get_string('demotmplawardedto', 'tool_certificate');
$elementrecord = ['pageid' => $page->get_id(), 'name' => $str, 'element' => 'text', 'data' => $str, 'font' => 'freesans',
'fontsize' => 12, 'colour' => '#fff', 'posx' => 25, 'posy' => 25, 'sequence' => 2, 'refpoint' => 0];
'fontsize' => 12, 'colour' => '#fff', 'posx' => 25, 'posy' => 25, 'sequence' => 2, 'refpoint' => 0, ];
$element = new \tool_certificate\persistent\element(0, (object)$elementrecord);
$element->save();

$str = get_string('demotmplusername', 'tool_certificate');
$elementrecord = ['pageid' => $page->get_id(), 'name' => $str, 'element' => 'userfield', 'data' => 'fullname',
'font' => 'freesansb', 'fontsize' => 26, 'colour' => '#fff', 'posx' => 25, 'posy' => 30, 'sequence' => 3,
'refpoint' => 0];
'refpoint' => 0, ];
$element = new \tool_certificate\persistent\element(0, (object)$elementrecord);
$element->save();

$str = get_string('demotmplforcompleting', 'tool_certificate');
$elementrecord = ['pageid' => $page->get_id(), 'name' => $str, 'element' => 'text', 'data' => $str, 'font' => 'freesans',
'fontsize' => 12, 'colour' => '#fff', 'posx' => 25, 'posy' => 52, 'sequence' => 4, 'refpoint' => 0];
'fontsize' => 12, 'colour' => '#fff', 'posx' => 25, 'posy' => 52, 'sequence' => 4, 'refpoint' => 0, ];
$element = new \tool_certificate\persistent\element(0, (object)$elementrecord);
$element->save();

$str = get_string('demotmplcoursefullname', 'tool_certificate');
$elementrecord = ['pageid' => $page->get_id(), 'name' => $str, 'element' => 'program', 'font' => 'freesansb',
'fontsize' => 26, 'data' => json_encode(['display' => 'coursefullname']), 'colour' => '#fff', 'posx' => 25,
'posy' => 57, 'sequence' => 5, 'refpoint' => 0];
'posy' => 57, 'sequence' => 5, 'refpoint' => 0, ];
$element = new \tool_certificate\persistent\element(0, (object)$elementrecord);
$element->save();

$str = get_string('demotmplawardedon', 'tool_certificate');
$elementrecord = ['pageid' => $page->get_id(), 'name' => $str, 'element' => 'text', 'data' => $str,
'font' => 'freesans', 'fontsize' => 12, 'colour' => '#fff', 'posx' => 25, 'posy' => 80, 'sequence' => 6,
'refpoint' => 0];
'refpoint' => 0, ];
$element = new \tool_certificate\persistent\element(0, (object)$elementrecord);
$element->save();

$str = get_string('demotmplissueddate', 'tool_certificate');
$elementrecord = ['pageid' => $page->get_id(), 'name' => $str, 'element' => 'date', 'font' => 'freesansb',
'fontsize' => 12, 'data' => json_encode(['dateitem' => -1, 'dateformat' => 'strftimedate']), 'colour' => '#fff',
'posx' => 49, 'posy' => 80, 'sequence' => 7, 'refpoint' => 0];
'posx' => 49, 'posy' => 80, 'sequence' => 7, 'refpoint' => 0, ];
$element = new \tool_certificate\persistent\element(0, (object)$elementrecord);
$element->save();

$str = get_string('demotmplqrcode', 'tool_certificate');
$elementrecord = ['pageid' => $page->get_id(), 'name' => $str, 'element' => 'code', 'font' => 'freesans',
'fontsize' => 12, 'data' => json_encode(['display' => 4]), 'colour' => '#000000',
'posx' => 44, 'posy' => 157, 'width' => 35, 'sequence' => 8, 'refpoint' => 1];
'posx' => 44, 'posy' => 157, 'width' => 35, 'sequence' => 8, 'refpoint' => 1, ];
$element = new \tool_certificate\persistent\element(0, (object)$elementrecord);
$element->save();

$str = get_string('demotmplsignature', 'tool_certificate');
$elementrecord = ['pageid' => $page->get_id(), 'name' => $str, 'element' => 'image', 'posx' => 118, 'posy' => 157,
'data' => json_encode(['width' => 50, 'height' => 0, 'isbackground' => false]), 'sequence' => 9];
'data' => json_encode(['width' => 50, 'height' => 0, 'isbackground' => false]), 'sequence' => 9, ];
$element = new \tool_certificate\persistent\element(0, (object)$elementrecord);
$element->save();
self::create_demo_element_file($element->get('id'), "{$CFG->dirroot}/{$CFG->admin}/tool/certificate/pix/signature.png");

$elementrecord = ['pageid' => $page->get_id(), 'name' => 'Mary Jones', 'element' => 'text', 'font' => 'freesansb',
'fontsize' => 12, 'data' => 'Mary Jones', 'colour' => '#000000', 'posx' => 141, 'posy' => 181, 'sequence' => 10,
'refpoint' => 1];
'refpoint' => 1, ];
$element = new \tool_certificate\persistent\element(0, (object)$elementrecord);
$element->save();

$str = get_string('demotmpldirector', 'tool_certificate');
$elementrecord = ['pageid' => $page->get_id(), 'name' => $str, 'element' => 'text', 'font' => 'freesans',
'fontsize' => 12, 'data' => $str, 'colour' => '#000000', 'posx' => 141, 'posy' => 187, 'sequence' => 11,
'refpoint' => 1];
'refpoint' => 1, ];
$element = new \tool_certificate\persistent\element(0, (object)$elementrecord);
$element->save();

$str = get_string('logo', 'admin');
$elementrecord = ['pageid' => $page->get_id(), 'name' => $str, 'element' => 'image', 'posx' => 223, 'posy' => 179,
'data' => json_encode(['width' => 50, 'height' => 0, 'isbackground' => false]), 'sequence' => 12];
'data' => json_encode(['width' => 50, 'height' => 0, 'isbackground' => false]), 'sequence' => 12, ];
$element = new \tool_certificate\persistent\element(0, (object)$elementrecord);
$element->save();
$wplogo = "{$CFG->dirroot}/{$CFG->admin}/tool/wp/pix/workplacelogo.png";
Expand Down Expand Up @@ -622,7 +622,7 @@ public static function add_expirydate_to_form(MoodleQuickForm &$mform): void {
$group[] =& $mform->createElement('date_time_selector', 'expirydateabsolute', '');
// TODO: Missing here "month" and "year" options. See MDL-61624.
$group[] =& $mform->createElement('duration', 'expirydaterelative', '', ['defaulunit' => DAYSECS,
'units' => [DAYSECS, WEEKSECS]]);
'units' => [DAYSECS, WEEKSECS], ]);
$mform->addGroup($group, 'expirydateformgroup', get_string('expirydate', 'tool_certificate'), ' ', false);
$mform->setDefault('expirydatetype', self::DATE_EXPIRATION_NEVER);
$mform->hideIf('expirydateabsolute', 'expirydatetype', 'noteq', self::DATE_EXPIRATION_ABSOLUTE);
Expand Down
2 changes: 1 addition & 1 deletion classes/customfield/issue_handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public function ensure_field_exists(string $shortname, string $type = 'text', st
try {
$config = ['visible' => $visible, 'previewvalue' => $previewvalue] + $config;
$record = (object)['type' => $type, 'shortname' => $shortname, 'name' => $displayname ?: $shortname,
'descriptionformat' => FORMAT_HTML, 'configdata' => json_encode($config)];
'descriptionformat' => FORMAT_HTML, 'configdata' => json_encode($config), ];
$field = \core_customfield\field_controller::create(0, $record, $category);
} catch (\moodle_exception $e) {
return null;
Expand Down
2 changes: 1 addition & 1 deletion classes/edit_element_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ protected function get_element() : element {
$this->element = element::instance($this->_ajaxformdata['id']);
} else {
$this->element = element::instance(0, (object)['pageid' => $this->_ajaxformdata['pageid'],
'element' => $this->_ajaxformdata['element']]);
'element' => $this->_ajaxformdata['element'], ]);
}
}
return $this->element;
Expand Down
34 changes: 17 additions & 17 deletions classes/element_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public static function render_html_content($element, $content) {
} else if ($element->get_refpoint() == self::CUSTOMCERT_REF_POINT_TOPCENTER) {
$style .= ' text-align: center;';
}
return \html_writer::div($content, '', array('style' => $style));
return \html_writer::div($content, '', ['style' => $style]);
}

/**
Expand Down Expand Up @@ -291,7 +291,7 @@ public static function render_form_element_height($mform, $stringcomponent = 'ce
* @param \MoodleQuickForm $mform the edit_form instance.
*/
public static function render_form_element_refpoint($mform) {
$refpointoptions = array();
$refpointoptions = [];
$refpointoptions[self::CUSTOMCERT_REF_POINT_TOPLEFT] = get_string('alignleft', 'tool_certificate');
$refpointoptions[self::CUSTOMCERT_REF_POINT_TOPCENTER] = get_string('aligncentre', 'tool_certificate');
$refpointoptions[self::CUSTOMCERT_REF_POINT_TOPRIGHT] = get_string('alignright', 'tool_certificate');
Expand All @@ -308,7 +308,7 @@ public static function render_form_element_refpoint($mform) {
* @return array the validation errors
*/
public static function validate_form_element_colour($data) {
$errors = array();
$errors = [];
// Validate the colour.
if (!self::validate_colour($data['colour'])) {
$errors['colour'] = get_string('invalidcolour', 'tool_certificate');
Expand All @@ -323,7 +323,7 @@ public static function validate_form_element_colour($data) {
* @return array the validation errors
*/
public static function validate_form_element_position($data) {
$errors = array();
$errors = [];

// Check if posx is not set, or not numeric or less than 0.
if (!empty($data['posx']) && !is_numeric($data['posx'])) {
Expand Down Expand Up @@ -368,7 +368,7 @@ public static function get_font($element) {
$font = substr($font, 0, -1);
$attr .= 'B';
}
return array($font, $attr);
return [$font, $attr];
}

/**
Expand All @@ -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',
Expand Down Expand Up @@ -410,8 +410,8 @@ public static function validate_colour($colour) {
'seagreen', 'seashell', 'sienna', 'silver', 'skyblue', 'slateblue',
'slategray', 'slategrey', 'snow', 'springgreen', 'steelblue', 'tan',
'teal', 'thistle', 'tomato', 'turquoise', 'violet', 'wheat', 'white',
'whitesmoke', 'yellow', 'yellowgreen'
);
'whitesmoke', 'yellow', 'yellowgreen',
];

if (preg_match('/^#?([[:xdigit:]]{3}){1,2}$/', $colour)) {
return true;
Expand Down Expand Up @@ -439,7 +439,7 @@ public static function get_element_sequence($pageid) {
FROM {tool_certificate_elements}
WHERE pageid = :id";
// Get the current max sequence on this page and add 1 to get the new sequence.
if ($maxseq = $DB->get_record_sql($sql, array('id' => $pageid))) {
if ($maxseq = $DB->get_record_sql($sql, ['id' => $pageid])) {
$sequence = $maxseq->maxsequence + 1;
}

Expand All @@ -455,7 +455,7 @@ public static function get_available_element_types() {
global $CFG;

// Array to store the element types.
$options = array();
$options = [];

$plugins = self::get_enabled_plugins();

Expand Down Expand Up @@ -486,11 +486,11 @@ public static function get_enabled_plugins() {
$manager = new plugin_manager();
$plugins = $manager->get_sorted_plugins_list();
if (!$plugins) {
return array();
return [];
}

// Check they are enabled using get_config (which is cached and hopefully fast).
$enabled = array();
$enabled = [];
foreach ($plugins as $plugin) {
$disabled = get_config('certificateelement_' . $plugin, 'disabled');
if (empty($disabled)) {
Expand Down Expand Up @@ -553,7 +553,7 @@ private static function get_fonts() {
*/
private static function get_font_sizes() {
// Array to store the sizes.
$sizes = array();
$sizes = [];

for ($i = 1; $i <= 200; $i++) {
$sizes[$i] = $i;
Expand Down Expand Up @@ -660,7 +660,7 @@ public static function get_shared_images_list() {
$fs = get_file_storage();

// The array used to store the images.
$arrfiles = array();
$arrfiles = [];
if ($files = get_file_storage()->get_area_files(\context_system::instance()->id, 'tool_certificate',
'image', false, 'filename', false)) {
foreach ($files as $hash => $file) {
Expand All @@ -670,7 +670,7 @@ public static function get_shared_images_list() {

if (count($arrfiles)) {
\core_collator::asort($arrfiles);
$arrfiles = array('0' => get_string('noimage', 'tool_certificate')) + $arrfiles;
$arrfiles = ['0' => get_string('noimage', 'tool_certificate')] + $arrfiles;
}

return $arrfiles;
Expand All @@ -683,7 +683,7 @@ public static function get_shared_images_list() {
* @return bool whether the element was added (it would not be added if there are no shared images)
*/
public static function render_shared_image_picker_element($mform) {
$arrfiles = array();
$arrfiles = [];
if ($files = get_file_storage()->get_area_files(\context_system::instance()->id, 'tool_certificate',
'image', false, 'filename', false)) {
foreach ($files as $hash => $file) {
Expand All @@ -696,7 +696,7 @@ public static function render_shared_image_picker_element($mform) {
}

\core_collator::asort($arrfiles);
$arrfiles = array('0' => get_string('noimage', 'tool_certificate')) + $arrfiles;
$arrfiles = ['0' => get_string('noimage', 'tool_certificate')] + $arrfiles;
$mform->addElement('select', 'fileid', get_string('selectsharedimage', 'certificateelement_image'), $arrfiles);
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions classes/event/certificate_issued.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ public static function create_from_issue(\stdClass $issue) {
'objectid' => $issue->id,
'relateduserid' => $issue->userid,
'other' => [
'code' => $issue->code
]
'code' => $issue->code,
],
];
$event = self::create($data);
$event->add_record_snapshot('tool_certificate_issues', $issue);
Expand Down
4 changes: 2 additions & 2 deletions classes/event/certificate_revoked.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ public static function create_from_issue(\stdClass $issue) {
'objectid' => $issue->id,
'relateduserid' => $issue->userid,
'other' => [
'code' => $issue->code
]
'code' => $issue->code,
],
];
$event = self::create($data);
$event->add_record_snapshot('tool_certificate_issues', $issue);
Expand Down
8 changes: 4 additions & 4 deletions classes/event/certificate_verified.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,14 @@ public function get_url() {
* @return certificate_issued
*/
public static function create_from_issue(\stdClass $issue) {
$data = array(
$data = [
'context' => \context_system::instance(),
'objectid' => $issue->id,
'relateduserid' => $issue->userid,
'other' => [
'code' => $issue->code
]
);
'code' => $issue->code,
],
];
$event = self::create($data);
$event->add_record_snapshot('tool_certificate_issues', $issue);
return $event;
Expand Down
6 changes: 3 additions & 3 deletions classes/event/template_created.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ public static function get_name() {
* @return template_created
*/
public static function create_from_template(template $template) : template_created {
$data = array(
$data = [
'context' => $template->get_context(),
'objectid' => $template->get_id(),
);
];
$event = self::create($data);
$event->add_record_snapshot('tool_certificate_templates', $template->to_record());
return $event;
Expand All @@ -86,6 +86,6 @@ public static function create_from_template(template $template) : template_creat
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/admin/tool/certificate/template.php', array('id' => $this->objectid));
return new \moodle_url('/admin/tool/certificate/template.php', ['id' => $this->objectid]);
}
}
4 changes: 2 additions & 2 deletions classes/event/template_deleted.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ public function get_url() {
* @return template_deleted
*/
public static function create_from_template(template $template) : template_deleted {
$data = array(
$data = [
'context' => $template->get_context(),
'objectid' => $template->get_id(),
);
];
$event = self::create($data);
$event->add_record_snapshot('tool_certificate_templates', $template->to_record());
return $event;
Expand Down
Loading

0 comments on commit 33dee6c

Please sign in to comment.