Skip to content

Commit

Permalink
code cleaning: long array syntax to short array syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
TamaroWalter committed Oct 27, 2023
1 parent 2379466 commit eaa2611
Show file tree
Hide file tree
Showing 54 changed files with 971 additions and 968 deletions.
2 changes: 1 addition & 1 deletion amd/src/rating.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export function init(userid, allowmultiplemarks) {

/**
* Function to change the String of the post data-action button.
* Only used if mulitplemarks are allowed.
* Only used if multiplemarks are allowed.
* @param {string} htmlclass the class where the String is being updated
* @param {string} action helpful or solved mark
*/
Expand Down
47 changes: 22 additions & 25 deletions backup/moodle2/backup_moodleoverflow_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,49 +44,46 @@ protected function define_structure() {
$userinfo = $this->get_setting_value('userinfo');

// Define the root element describing the moodleoverflow instance.
$moodleoverflow = new backup_nested_element('moodleoverflow', array('id'), array(
$moodleoverflow = new backup_nested_element('moodleoverflow', ['id'], [
'name', 'intro', 'introformat', 'maxbytes', 'maxattachments',
'forcesubscribe', 'trackingtype', 'timecreated', 'timemodified',
'ratingpreference', 'coursewidereputation', 'allownegativereputation'));
'ratingpreference', 'coursewidereputation', 'allownegativereputation',
]);

// Define each element separated.
$discussions = new backup_nested_element('discussions');
$discussion = new backup_nested_element('discussion', array('id'), array(
'name', 'firstpost', 'userid', 'timemodified', 'usermodified', 'timestart'));
$discussion = new backup_nested_element('discussion', ['id'], [
'name', 'firstpost', 'userid', 'timemodified', 'usermodified', 'timestart', ]);

$posts = new backup_nested_element('posts');

$post = new backup_nested_element('post', array('id'), array(
$post = new backup_nested_element('post', ['id'], [
'parent', 'userid', 'created', 'modified',
'mailed', 'message', 'messageformat', 'attachment'));
'mailed', 'message', 'messageformat', 'attachment', ]);

$ratings = new backup_nested_element('ratings');

$rating = new backup_nested_element('rating', array('id'), array(
'userid', 'rating', 'firstrated', 'lastchanged'));
$rating = new backup_nested_element('rating', ['id'], [
'userid', 'rating', 'firstrated', 'lastchanged', ]);

$discussionsubs = new backup_nested_element('discuss_subs');

$discussionsub = new backup_nested_element('discuss_sub', array('id'), array(
$discussionsub = new backup_nested_element('discuss_sub', ['id'], [
'userid',
'preference',
));
]);

$subscriptions = new backup_nested_element('subscriptions');

$subscription = new backup_nested_element('subscription', array('id'), array(
'userid'));
$subscription = new backup_nested_element('subscription', ['id'], ['userid']);

$readposts = new backup_nested_element('readposts');

$read = new backup_nested_element('read', array('id'), array(
'userid', 'discussionid', 'postid', 'firstread',
'lastread'));
$read = new backup_nested_element('read', ['id'], ['userid', 'discussionid', 'postid', 'firstread', 'lastread']);

$tracking = new backup_nested_element('tracking');

$track = new backup_nested_element('track', array('id'), array(
'userid'));
$track = new backup_nested_element('track', ['id'], ['userid']);

// Build the tree.
$moodleoverflow->add_child($discussions);
Expand All @@ -111,23 +108,23 @@ protected function define_structure() {
$tracking->add_child($track);

// Define data sources.
$moodleoverflow->set_source_table('moodleoverflow', array('id' => backup::VAR_ACTIVITYID));
$moodleoverflow->set_source_table('moodleoverflow', ['id' => backup::VAR_ACTIVITYID]);

// All these source definitions only happen if we are including user info.
if ($userinfo) {
$discussion->set_source_sql('
SELECT *
FROM {moodleoverflow_discussions}
WHERE moodleoverflow = ?',
array(backup::VAR_PARENTID));
[backup::VAR_PARENTID]);

// Need posts ordered by id so parents are always before childs on restore.
$post->set_source_table('moodleoverflow_posts', array('discussion' => backup::VAR_PARENTID), 'id ASC');
$rating->set_source_table('moodleoverflow_ratings', array('postid' => backup::VAR_PARENTID));
$discussionsub->set_source_table('moodleoverflow_discuss_subs', array('discussion' => backup::VAR_PARENTID));
$subscription->set_source_table('moodleoverflow_subscriptions', array('moodleoverflow' => backup::VAR_PARENTID));
$read->set_source_table('moodleoverflow_read', array('moodleoverflowid' => backup::VAR_PARENTID));
$track->set_source_table('moodleoverflow_tracking', array('moodleoverflowid' => backup::VAR_PARENTID));
$post->set_source_table('moodleoverflow_posts', ['discussion' => backup::VAR_PARENTID], 'id ASC');
$rating->set_source_table('moodleoverflow_ratings', ['postid' => backup::VAR_PARENTID]);
$discussionsub->set_source_table('moodleoverflow_discuss_subs', ['discussion' => backup::VAR_PARENTID]);
$subscription->set_source_table('moodleoverflow_subscriptions', ['moodleoverflow' => backup::VAR_PARENTID]);
$read->set_source_table('moodleoverflow_read', ['moodleoverflowid' => backup::VAR_PARENTID]);
$track->set_source_table('moodleoverflow_tracking', ['moodleoverflowid' => backup::VAR_PARENTID]);
}

// Define id annotations.
Expand Down
16 changes: 8 additions & 8 deletions backup/moodle2/restore_moodleoverflow_activity_task.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ protected function define_my_steps() {
* processed by the link decoder
*/
public static function define_decode_contents() {
$contents = array();
$contents = [];

$contents[] = new restore_decode_content('moodleoverflow', array('intro'), 'moodleoverflow');
$contents[] = new restore_decode_content('moodleoverflow_posts', array('message'), 'moodleoverflow_post');
$contents[] = new restore_decode_content('moodleoverflow', ['intro'], 'moodleoverflow');
$contents[] = new restore_decode_content('moodleoverflow_posts', ['message'], 'moodleoverflow_post');

return $contents;
}
Expand All @@ -72,7 +72,7 @@ public static function define_decode_contents() {
* to the activity to be executed by the link decoder
*/
public static function define_decode_rules() {
$rules = array();
$rules = [];

$rules[] = new restore_decode_rule('MOODLEOVERFLOWVIEWBYID', '/mod/moodleoverflow/view.php?id=$1', 'course_module');
$rules[] = new restore_decode_rule('MOODLEOVERFLOWINDEX', '/mod/moodleoverflow/index.php?id=$1', 'course');
Expand All @@ -85,9 +85,9 @@ public static function define_decode_rules() {
// Link to discussion with parent and with anchor posts.
$rules[] = new restore_decode_rule('MOODLEOVERFLOWDISCUSSIONVIEWPARENT',
'/mod/moodleoverflow/discussion.php?d=$1&parent=$2',
array('moodleoverflow_discussion', 'moodleoverflow_post'));
['moodleoverflow_discussion', 'moodleoverflow_post']);
$rules[] = new restore_decode_rule('MOODLEOVERFLOWDISCUSSIONVIEWINSIDE', '/mod/moodleoverflow/discussion.php?d=$1#$2',
array('moodleoverflow_discussion', 'moodleoverflow_post'));
['moodleoverflow_discussion', 'moodleoverflow_post']);

return $rules;

Expand All @@ -100,7 +100,7 @@ public static function define_decode_rules() {
* of { restore_log_rule} objects
*/
public static function define_restore_log_rules() {
$rules = array();
$rules = [];

$rules[] = new restore_log_rule('moodleoverflow', 'add',
'view.php?id={course_module}', '{moodleoverflow}');
Expand Down Expand Up @@ -160,7 +160,7 @@ public static function define_restore_log_rules() {
* activity level. All them are rules not linked to any module instance (cmid = 0)
*/
public static function define_restore_log_rules_for_course() {
$rules = array();
$rules = [];

$rules[] = new restore_log_rule('moodleoverflow', 'view all', 'index.php?id={course}', null);

Expand Down
4 changes: 2 additions & 2 deletions backup/moodle2/restore_moodleoverflow_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class restore_moodleoverflow_activity_structure_step extends restore_activity_st
*/
protected function define_structure() {

$paths = array();
$paths = [];
$userinfo = $this->get_setting_value('userinfo');

$paths[] = new restore_path_element('moodleoverflow', '/activity/moodleoverflow');
Expand Down Expand Up @@ -138,7 +138,7 @@ protected function process_moodleoverflow_post($data) {

// If !post->parent, it's the 1st post. Set it in discussion.
if (empty($data->parent)) {
$DB->set_field('moodleoverflow_discussions', 'firstpost', $newitemid, array('id' => $data->discussion));
$DB->set_field('moodleoverflow_discussions', 'firstpost', $newitemid, ['id' => $data->discussion]);
}
}

Expand Down
2 changes: 1 addition & 1 deletion classes/anonymous.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public static function get_userid_mapping($moodleoverflow, $discussionid) {
if ($moodleoverflow->anonymous == self::QUESTION_ANONYMOUS) {
return [
$DB->get_field('moodleoverflow_posts', 'userid',
['parent' => 0, 'discussion' => $discussionid]) => get_string('questioner', 'mod_moodleoverflow')
['parent' => 0, 'discussion' => $discussionid]) => get_string('questioner', 'mod_moodleoverflow'),
];
}

Expand Down
18 changes: 9 additions & 9 deletions classes/discussion/discussion.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public function __construct($id, $course, $moodleoverflow, $name, $firstpost,
$this->timemodified = $timemodified;
$this->timestart = $timestart;
$this->usermodified = $usermodified;
$this->posts = array();
$this->posts = [];
$this->postsbuild = false;
}

Expand Down Expand Up @@ -222,17 +222,17 @@ public function moodleoverflow_add_discussion($prepost) {
$this->firstpost = $post->moodleoverflow_add_new_post();

// Save the id of the first/parent post in the DB.
$DB->set_field('moodleoverflow_discussions', 'firstpost', $this->firstpost, array('id' => $this->id));
$DB->set_field('moodleoverflow_discussions', 'firstpost', $this->firstpost, ['id' => $this->id]);

// Add the parent post to the $posts array.
$this->posts[$this->firstpost] = $post;
$this->postsbuild = true;

// Trigger event.
$params = array(
$params = [
'context' => $prepost->modulecontext,
'objectid' => $this->id,
);
];
// TODO: check if the event functions.
$event = \mod_moodleoverflow\event\discussion_viewed::create($params);
$event->trigger();
Expand Down Expand Up @@ -266,16 +266,16 @@ public function moodleoverflow_delete_discussion($prepost) {
readtracking::moodleoverflow_delete_read_records(-1, -1, $this->id);

// Remove the subscriptions for the discussion.
$DB->delete_records('moodleoverflow_discuss_subs', array('discussion' => $this->id));
$DB->delete_records('moodleoverflow_discuss_subs', ['discussion' => $this->id]);

// Delete the discussion from the database.
$DB->delete_records('moodleoverflow_discussions', array('id' => $this->id));
$DB->delete_records('moodleoverflow_discussions', ['id' => $this->id]);

// Trigger the discussion deleted event.
$params = array(
$params = [
'objectid' => $this->id,
'context' => $prepost->modulecontext,
);
];

$event = \mod_moodleoverflow\event\discussion_deleted::create($params);
$event->trigger();
Expand Down Expand Up @@ -521,7 +521,7 @@ public function get_moodleoverflow() {
$this->existence_check();

if (empty($this->moodleoverflowobject)) {
$this->moodleoverflowobject = $DB->get_records('moodleoverflow', array('id' => $this->moodleoverflow));
$this->moodleoverflowobject = $DB->get_records('moodleoverflow', ['id' => $this->moodleoverflow]);
}

return $this->moodleoverflowobject;
Expand Down
2 changes: 1 addition & 1 deletion classes/event/readtracking_disabled.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,6 @@ public static function get_name() {
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/moodleoverflow/view.php', array('m' => $this->other['moodleoverflowid']));
return new \moodle_url('/mod/moodleoverflow/view.php', ['m' => $this->other['moodleoverflowid']]);
}
}
2 changes: 1 addition & 1 deletion classes/event/readtracking_enabled.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,6 @@ public static function get_name() {
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/moodleoverflow/view.php', array('m' => $this->other['moodleoverflowid']));
return new \moodle_url('/mod/moodleoverflow/view.php', ['m' => $this->other['moodleoverflowid']]);
}
}
10 changes: 5 additions & 5 deletions classes/observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static function user_enrolment_deleted(\core\event\user_enrolment_deleted
if ($cp->lastenrol) {

// Get the moodleoverflow instances from which the user was unenrolled from.
$moodleoverflows = $DB->get_records('moodleoverflow', array('course' => $cp->courseid), '', 'id');
$moodleoverflows = $DB->get_records('moodleoverflow', ['course' => $cp->courseid], '', 'id');

// Do not continue if there are no connected moodleoverflow instances.
if (!$moodleoverflows) {
Expand Down Expand Up @@ -93,9 +93,9 @@ public static function role_assigned(\core\event\role_assigned $event) {
JOIN {modules} mo ON (mo.id = cm.module)
LEFT JOIN {moodleoverflow_subscriptions} ms ON (ms.moodleoverflow = m.id AND ms.userid = :userid)
WHERE m.course = :courseid AND m.forcesubscribe = :initial AND mo.name = 'moodleoverflow' AND ms.id IS NULL";
$params = array('courseid' => $context->instanceid,
'userid' => $userid,
'initial' => MOODLEOVERFLOW_INITIALSUBSCRIBE);
$params = ['courseid' => $context->instanceid,
'userid' => $userid,
'initial' => MOODLEOVERFLOW_INITIALSUBSCRIBE, ];
$moodleoverflows = $DB->get_records_sql($sql, $params);

// Loop through all moodleoverflows.
Expand Down Expand Up @@ -133,7 +133,7 @@ public static function course_module_created(\core\event\course_module_created $
require_once($CFG->dirroot . '/mod/moodleoverflow/lib.php');

// Create a snapshot of the created moodleoverflow record.
$moodleoverflow = $DB->get_record('moodleoverflow', array('id' => $event->other['instanceid']));
$moodleoverflow = $DB->get_record('moodleoverflow', ['id' => $event->other['instanceid']]);

// Trigger the function for a created moodleoverflow instance.
moodleoverflow_instance_created($event->get_context(), $moodleoverflow);
Expand Down
Loading

0 comments on commit eaa2611

Please sign in to comment.