Skip to content

Commit

Permalink
Moodle 4.3 code style
Browse files Browse the repository at this point in the history
davidherney committed Oct 5, 2024
1 parent 885bce4 commit df519ef
Showing 22 changed files with 219 additions and 217 deletions.
24 changes: 13 additions & 11 deletions avatar_edit.php
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@

$avatar = null;
if (!empty($id)) {
$avatar = $DB->get_record('block_ludifica_avatars', array('id' => $id), '*', MUST_EXIST);
$avatar = $DB->get_record('block_ludifica_avatars', ['id' => $id], '*', MUST_EXIST);
}

require_login();
@@ -43,10 +43,12 @@
$PAGE->set_heading(get_string('avatars', 'block_ludifica'));
$PAGE->set_title(get_string('avatars', 'block_ludifica'));

$filemanageroptions = array('maxbytes' => $CFG->maxbytes,
'subdirs' => 0,
'maxfiles' => 1,
'accepted_types' => array('.jpg', '.png', '.svg'));
$filemanageroptions = [
'maxbytes' => $CFG->maxbytes,
'subdirs' => 0,
'maxfiles' => 1,
'accepted_types' => ['.jpg', '.png', '.svg'],
];
$draftitemid = file_get_submitted_draft_itemid('attachments_filemanager');
file_prepare_draft_area($draftitemid, $syscontext->id, 'block_ludifica', 'avatarbust', $id, $filemanageroptions);

@@ -55,7 +57,7 @@
}

// First create the form.
$editform = new block_ludifica_avatar_edit(null, array('data' => $avatar, 'filemanageroptions' => $filemanageroptions));
$editform = new block_ludifica_avatar_edit(null, ['data' => $avatar, 'filemanageroptions' => $filemanageroptions]);
if ($editform->is_cancelled()) {
$url = new moodle_url($CFG->wwwroot . '/blocks/ludifica/avatars.php');
redirect($url);
@@ -83,25 +85,25 @@
if (!empty($avatar->id)) {
$DB->update_record('block_ludifica_avatars', $avatar);

$event = \block_ludifica\event\avatar_updated::create(array(
$event = \block_ludifica\event\avatar_updated::create([
'objectid' => $avatar->id,
'context' => $syscontext,
));
]);
$event->trigger();
} else {
$id = $DB->insert_record('block_ludifica_avatars', $avatar, true);

$event = \block_ludifica\event\avatar_created::create(array(
$event = \block_ludifica\event\avatar_created::create([
'objectid' => $id,
'context' => $syscontext,
));
]);
$event->trigger();
}

file_save_draft_area_files($data->attachments_filemanager, $syscontext->id, 'block_ludifica', 'avatarbust',
$id, $filemanageroptions);

$url = new moodle_url($CFG->wwwroot . '/blocks/ludifica/avatars.php', array('msg' => 'changessaved'));
$url = new moodle_url($CFG->wwwroot . '/blocks/ludifica/avatars.php', ['msg' => 'changessaved']);
redirect($url);
}

15 changes: 10 additions & 5 deletions avatar_edit_form.php
Original file line number Diff line number Diff line change
@@ -51,15 +51,20 @@ public function definition() {
$this->_data = $this->_customdata['data'];

if ($this->_data) {
$this->_data->description = array('text' => $this->_data->description);
$this->_data->description = ['text' => $this->_data->description];
if ($this->_data->description == 'null') {
$this->_data->description = '';
}
}

$editoroptions = array('maxfiles' => 0, 'maxbytes' => 0, 'enable_filemanagement' => false,
'trusttext' => false, 'noclean' => false);
$editorattributes = array ('rows' => 5, 'cols' => 50);
$editoroptions = [
'maxfiles' => 0,
'maxbytes' => 0,
'enable_filemanagement' => false,
'trusttext' => false,
'noclean' => false,
];
$editorattributes = ['rows' => 5, 'cols' => 50];
$filemanageroptions = $this->_customdata['filemanageroptions'];

$mform->addElement('header', 'general', get_string('general'));
@@ -84,7 +89,7 @@ public function definition() {
$mform->setType('sources', PARAM_TEXT);
$mform->addHelpButton('sources', 'avatarsources', 'block_ludifica');

$values = array('1' => get_string('yes'), '0' => get_string('no'));
$values = ['1' => get_string('yes'), '0' => get_string('no')];
$mform->addElement('select', 'enabled', get_string('enabled', 'block_ludifica'), $values);

$mform->addElement('hidden', 'id', null);
2 changes: 1 addition & 1 deletion block_ludifica.php
Original file line number Diff line number Diff line change
@@ -59,7 +59,7 @@ public function has_config() {
* @return array page-type prefix => true/false.
*/
public function applicable_formats() {
return array('all' => true);
return ['all' => true];
}

/**
14 changes: 8 additions & 6 deletions classes/avatar.php
Original file line number Diff line number Diff line change
@@ -51,7 +51,7 @@ public function __construct($avatar = null) {
if (is_object($avatar) && property_exists($avatar, 'id')) {
$this->data = $avatar;
} else {
$this->data = $DB->get_record('block_ludifica_avatars', array('id' => (int)$avatar));
$this->data = $DB->get_record('block_ludifica_avatars', ['id' => (int)$avatar]);
}
}

@@ -112,10 +112,12 @@ public function get_busturi() {
$filename = $file->get_filename();

if (!empty($filename) && $filename != '.') {
$path = '/' . implode('/', array($file->get_contextid(),
'block_ludifica',
'avatarbust',
$file->get_itemid() . $file->get_filepath() . $filename));
$path = '/' . implode('/', [
$file->get_contextid(),
'block_ludifica',
'avatarbust',
$file->get_itemid() . $file->get_filepath() . $filename,
]);

return \moodle_url::make_file_url('/pluginfile.php', $path);

@@ -144,7 +146,7 @@ public static function default_avatar() {
* @return array Avatar types.
*/
public static function get_types() {
return array(self::$defaulttype => get_string('avatartype_normal', 'block_ludifica'));
return [self::$defaulttype => get_string('avatartype_normal', 'block_ludifica')];
// The 'user' type is not avaible yet. The string is 'avatartype_user'.
}

40 changes: 20 additions & 20 deletions classes/controller.php
Original file line number Diff line number Diff line change
@@ -75,7 +75,7 @@ public static function points_completecourse($userid, $courseid, $completionid =
$conditions = [
'userid' => $userid,
'courseid' => $courseid,
'type' => player::POINTS_TYPE_COURSECOMPLETED
'type' => player::POINTS_TYPE_COURSECOMPLETED,
];

$record = $DB->get_record('block_ludifica_userpoints', $conditions);
@@ -141,7 +141,7 @@ public static function points_recurrentlogin($userid) {

$conditions = [
'userid' => $userid,
'type' => player::POINTS_TYPE_RECURRENTLOGIN
'type' => player::POINTS_TYPE_RECURRENTLOGIN,
];

// Only get the newest.
@@ -273,7 +273,7 @@ public static function points_completemodule($userid, $courseid, $completionid,
'userid' => $userid,
'courseid' => $courseid,
'objectid' => $cmid,
'type' => player::POINTS_TYPE_MODULECOMPLETED
'type' => player::POINTS_TYPE_MODULECOMPLETED,
];

$record = $DB->get_record('block_ludifica_userpoints', $conditions);
@@ -342,7 +342,7 @@ public static function points_userupdated($userid) {
$conditions = [
'userid' => $userid,
'courseid' => SITEID,
'type' => player::POINTS_TYPE_EMAILCHANGED
'type' => player::POINTS_TYPE_EMAILCHANGED,
];

// If exists not add points again.
@@ -495,7 +495,7 @@ public static function requirements_compliance($userid, $ticket) {
public static function requirements_text($userid, $ticket) {
global $CFG;

$captions = array();
$captions = [];

$infodata = is_string($ticket->infodata) ? json_decode($ticket->infodata) : $ticket->infodata;

@@ -566,7 +566,7 @@ public static function get_topbycourse($courseid, $includecurrent = true) {
" ORDER BY points DESC, g.nickname ASC";
}

$records = $DB->get_records_sql($sql, array('courseid' => $courseid));
$records = $DB->get_records_sql($sql, ['courseid' => $courseid]);

return self::get_toplist($records, $includecurrent);

@@ -737,7 +737,7 @@ public static function get_customranking($custom, $courseid = null, $includecurr
public static function get_avatar_id($userid) {
global $DB;

$records = $DB->get_record('block_ludifica_general', array('userid' => $userid));
$records = $DB->get_record('block_ludifica_general', ['userid' => $userid]);
if (!empty($records)) {
return $records->avatarid;
} else {
@@ -754,7 +754,7 @@ public static function get_avatar_id($userid) {
public static function user_profile_url($userid) {
global $CFG;

return new \moodle_url($CFG->wwwroot . '/user/view.php', array('id' => $userid));
return new \moodle_url($CFG->wwwroot . '/user/view.php', ['id' => $userid]);
}

/**
@@ -842,7 +842,7 @@ private static function get_toplist($records, $includecurrent = true) {
* @return array Tabs list.
*/
public static function get_storetabs($active) {
$tabs = array();
$tabs = [];

$avatars = new \stdClass();
$avatars->text = get_string('avatars', 'block_ludifica');
@@ -888,7 +888,7 @@ public static function get_uniqueid() {
public static function get_coursemodules() {
global $COURSE;

$coursemodules = array();
$coursemodules = [];

// Points by complete modules not apply in the site level.
if ($COURSE->id > SITEID && $COURSE->enablecompletion) {
@@ -984,7 +984,7 @@ public static function get_modulespoints($courseid, $cmid = null) {
// Use the first instance configuration found. This is the more recently block instance configured.
$cmconfig[$cmid] = (object)[
'instanceid' => $instance->id,
'points' => $instanceconfig->{$fieldkey}
'points' => $instanceconfig->{$fieldkey},
];
break;
} else if (!$fieldkey) {
@@ -998,7 +998,7 @@ public static function get_modulespoints($courseid, $cmid = null) {
if (!isset($cmconfig[$cmid])) {
$cmconfig[$cmid] = (object)[
'instanceid' => $instance->id,
'points' => $cmpoints
'points' => $cmpoints,
];
}
}
@@ -1032,7 +1032,7 @@ public static function include_templatecss() {
*
* @return array The improve criteria list.
*/
public static function badges_improvecriteria() : array {
public static function badges_improvecriteria(): array {
global $CFG;
$criteria = [];

@@ -1063,7 +1063,7 @@ public static function badges_improvecriteria() : array {
* @param string $type
* @return \block_ludifica\improvecriteria\base
*/
public static function get_badges_improvecriteria(string $type) : \block_ludifica\improvecriteria\base {
public static function get_badges_improvecriteria(string $type): \block_ludifica\improvecriteria\base {
global $CFG;

$criteria = null;
@@ -1082,7 +1082,7 @@ public static function get_badges_improvecriteria(string $type) : \block_ludific
* @param string $eventname
* @param \core\event\base $event
*/
public static function trigger(string $eventname, \core\event\base $event) : void {
public static function trigger(string $eventname, \core\event\base $event): void {

// Get available criteria to improve.
$availablecriteria = self::badges_improvecriteria();
@@ -1100,7 +1100,7 @@ public static function trigger(string $eventname, \core\event\base $event) : voi
*
* @return array The icons list.
*/
public static function get_views_icons() : array {
public static function get_views_icons(): array {

$icons = [
'profile' => 'i/completion_self',
@@ -1118,7 +1118,7 @@ public static function get_views_icons() : array {
*
* @return bool If show icons.
*/
public static function show_tabicon() : bool {
public static function show_tabicon(): bool {

if (self::$showicons !== null) {
return self::$showicons;
@@ -1137,7 +1137,7 @@ public static function show_tabicon() : bool {
*
* @return bool If show the text.
*/
public static function show_tabtext() : bool {
public static function show_tabtext(): bool {

if (self::$showtext !== null) {
return self::$showtext;
@@ -1156,7 +1156,7 @@ public static function show_tabtext() : bool {
*
* @return bool If show the text.
*/
public static function show_tabs() : bool {
public static function show_tabs(): bool {

if (self::$showtabs !== null) {
return self::$showtabs;
@@ -1176,7 +1176,7 @@ public static function show_tabs() : bool {
* @param string $name
* @return \stdClass The info: icon and title.
*/
public static function customranking_info(string $name) : ?object {
public static function customranking_info(string $name): ?object {
global $DB, $USER;

if (strpos($name, 'profile_field_') !== false) {
4 changes: 2 additions & 2 deletions classes/entity.php
Original file line number Diff line number Diff line change
@@ -64,7 +64,7 @@ public function __get($name) {
} else if (property_exists($this->data, $name)) {
return $this->data->$name;
} else if (method_exists($this, 'get_' . $name)) {
return call_user_func(array($this, 'get_' . $name));
return call_user_func([$this, 'get_' . $name]);
} else {
throw new \Exception('propertie_or_method_not_found: ' . get_class($this) . '->'. $name);
}
@@ -82,7 +82,7 @@ public function __set($name, $value) {
} else if (property_exists($this->data, $name)) {
$this->data->$name = $value;
} else if (method_exists($this, 'set_' . $name)) {
return call_user_func(array($this, 'set_' . $name), $value);
return call_user_func([$this, 'set_' . $name], $value);
} else {
throw new \Exception('propertie_or_method_not_found: ' . get_class($this) . '->'. $name);
}
Loading

0 comments on commit df519ef

Please sign in to comment.