diff --git a/amd/src/rating.js b/amd/src/rating.js index 0f44f3ba77..f1cce7a268 100644 --- a/amd/src/rating.js +++ b/amd/src/rating.js @@ -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 */ diff --git a/backup/moodle2/backup_moodleoverflow_stepslib.php b/backup/moodle2/backup_moodleoverflow_stepslib.php index ed5d83f729..24286e4ff9 100644 --- a/backup/moodle2/backup_moodleoverflow_stepslib.php +++ b/backup/moodle2/backup_moodleoverflow_stepslib.php @@ -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); @@ -111,7 +108,7 @@ 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) { @@ -119,15 +116,15 @@ protected function define_structure() { 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. diff --git a/backup/moodle2/restore_moodleoverflow_activity_task.class.php b/backup/moodle2/restore_moodleoverflow_activity_task.class.php index a02b4483a5..69b3703f34 100644 --- a/backup/moodle2/restore_moodleoverflow_activity_task.class.php +++ b/backup/moodle2/restore_moodleoverflow_activity_task.class.php @@ -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; } @@ -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'); @@ -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; @@ -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}'); @@ -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); diff --git a/backup/moodle2/restore_moodleoverflow_stepslib.php b/backup/moodle2/restore_moodleoverflow_stepslib.php index fabc49a080..590a37f886 100644 --- a/backup/moodle2/restore_moodleoverflow_stepslib.php +++ b/backup/moodle2/restore_moodleoverflow_stepslib.php @@ -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'); @@ -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]); } } diff --git a/classes/anonymous.php b/classes/anonymous.php index c098dc8bce..cbb3188da3 100644 --- a/classes/anonymous.php +++ b/classes/anonymous.php @@ -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'), ]; } diff --git a/classes/discussion/discussion.php b/classes/discussion/discussion.php index 2115bae1e7..bdc887eeac 100644 --- a/classes/discussion/discussion.php +++ b/classes/discussion/discussion.php @@ -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; } @@ -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(); @@ -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(); @@ -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; diff --git a/classes/event/readtracking_disabled.php b/classes/event/readtracking_disabled.php index 3ff1a02f12..360321ca81 100644 --- a/classes/event/readtracking_disabled.php +++ b/classes/event/readtracking_disabled.php @@ -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']]); } } diff --git a/classes/event/readtracking_enabled.php b/classes/event/readtracking_enabled.php index c6d7f146d2..afe4f16449 100644 --- a/classes/event/readtracking_enabled.php +++ b/classes/event/readtracking_enabled.php @@ -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']]); } } diff --git a/classes/observer.php b/classes/observer.php index ade917acec..6055ca99f4 100644 --- a/classes/observer.php +++ b/classes/observer.php @@ -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) { @@ -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. @@ -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); diff --git a/classes/output/moodleoverflow_email.php b/classes/output/moodleoverflow_email.php index b52d653be9..47f2651b9f 100644 --- a/classes/output/moodleoverflow_email.php +++ b/classes/output/moodleoverflow_email.php @@ -102,9 +102,9 @@ class moodleoverflow_email implements \renderable, \templatable { * * @var array $writablekeys */ - protected $writablekeys = array( + protected $writablekeys = [ 'viewfullnames' => true, - ); + ]; /** * Builds a renderable moodleoverflow mail. @@ -154,7 +154,7 @@ public function export_for_template(\renderer_base $renderer, $plaintext = false */ protected function export_for_template_text(\mod_moodleoverflow_renderer $renderer) { - return array( + return [ 'id' => html_entity_decode($this->post->id, ENT_COMPAT), 'coursename' => html_entity_decode($this->get_coursename(), ENT_COMPAT), 'courselink' => html_entity_decode($this->get_courselink(), ENT_COMPAT), @@ -180,7 +180,7 @@ protected function export_for_template_text(\mod_moodleoverflow_renderer $render // Format some components according to the renderer. 'message' => html_entity_decode($renderer->format_message_text($this->cm, $this->post), ENT_COMPAT), - ); + ]; } /** @@ -188,10 +188,10 @@ protected function export_for_template_text(\mod_moodleoverflow_renderer $render * * @param \mod_moodleoverflow_renderer $renderer The render to be used for formatting the message and attachments * - * @return stdClass Data ready for use in a mustache template + * @return array Data ready for use in a mustache template */ protected function export_for_template_html(\mod_moodleoverflow_renderer $renderer) { - return array( + return [ 'id' => $this->post->id, 'coursename' => $this->get_coursename(), 'courselink' => $this->get_courselink(), @@ -217,7 +217,7 @@ protected function export_for_template_html(\mod_moodleoverflow_renderer $render // Format some components according to the renderer. 'message' => $renderer->format_message_text($this->cm, $this->post), - ); + ]; } /** @@ -263,7 +263,7 @@ public function get_unsubscribediscussionlink() { $url = '/mod/moodleoverflow/subscribe.php'; // Generate a link to unsubscribe from the discussion. - $link = new \moodle_url($url, array('id' => $id, 'd' => $d)); + $link = new \moodle_url($url, ['id' => $id, 'd' => $d]); return $link->out(false); } @@ -292,9 +292,9 @@ public function get_courseidnumber() { * @return string */ public function get_coursefullname() { - return format_string($this->course->fullname, true, array( + return format_string($this->course->fullname, true, [ 'context' => \context_course::instance($this->course->id), - )); + ]); } /** @@ -303,9 +303,9 @@ public function get_coursefullname() { * @return string */ public function get_coursename() { - return format_string($this->course->shortname, true, array( + return format_string($this->course->shortname, true, [ 'context' => \context_course::instance($this->course->id), - )); + ]); } /** @@ -316,9 +316,9 @@ public function get_coursename() { public function get_courselink() { $link = new \moodle_url( // Posts are viewed on the topic. - '/course/view.php', array( + '/course/view.php', [ 'id' => $this->course->id, - ) + ] ); return $link->out(false); @@ -420,9 +420,9 @@ public function is_firstpost() { */ public function get_replylink() { return new \moodle_url( - '/mod/moodleoverflow/post.php', array( + '/mod/moodleoverflow/post.php', [ 'reply' => $this->post->id, - ) + ] ); } @@ -437,9 +437,9 @@ public function get_unsubscribemoodleoverflowlink() { return null; } $link = new \moodle_url( - '/mod/moodleoverflow/subscribe.php', array( + '/mod/moodleoverflow/subscribe.php', [ 'id' => $this->moodleoverflow->id, - ) + ] ); return $link->out(false); @@ -465,10 +465,10 @@ public function get_parentpostlink() { protected function get_discussionurl() { return new \moodle_url( // Posts are viewed on the topic. - '/mod/moodleoverflow/discussion.php', array( + '/mod/moodleoverflow/discussion.php', [ // Within a discussion. 'd' => $this->discussion->id, - ) + ] ); } @@ -491,9 +491,9 @@ public function get_discussionlink() { public function get_moodleoverflowindexlink() { $link = new \moodle_url( // Posts are viewed on the topic. - '/mod/moodleoverflow/index.php', array( + '/mod/moodleoverflow/index.php', [ 'id' => $this->course->id, - ) + ] ); return $link->out(false); @@ -507,9 +507,9 @@ public function get_moodleoverflowindexlink() { public function get_moodleoverflowviewlink() { $link = new \moodle_url( // Posts are viewed on the topic. - '/mod/moodleoverflow/view.php', array( + '/mod/moodleoverflow/view.php', [ 'm' => $this->moodleoverflow->id, - ) + ] ); return $link->out(false); @@ -526,10 +526,10 @@ public function get_authorlink() { } $link = new \moodle_url( - '/user/view.php', array( + '/user/view.php', [ 'id' => $this->post->userid, 'course' => $this->course->id, - ) + ] ); return $link->out(false); @@ -546,7 +546,7 @@ public function get_author_picture() { return ''; } - return $OUTPUT->user_picture($this->author, array('courseid' => $this->course->id)); + return $OUTPUT->user_picture($this->author, ['courseid' => $this->course->id]); } /** diff --git a/classes/post/post.php b/classes/post/post.php index 0046967637..b054a55595 100644 --- a/classes/post/post.php +++ b/classes/post/post.php @@ -262,8 +262,8 @@ public function moodleoverflow_add_new_post() { if ($this->reviewed) { // Update the discussion. - $DB->set_field('moodleoverflow_discussions', 'timemodified', $this->modified, array('id' => $this->discussion)); - $DB->set_field('moodleoverflow_discussions', 'usermodified', $this->userid, array('id' => $this->discussion)); + $DB->set_field('moodleoverflow_discussions', 'timemodified', $this->modified, ['id' => $this->discussion]); + $DB->set_field('moodleoverflow_discussions', 'usermodified', $this->userid, ['id' => $this->discussion]); } // Mark the created post as read if the user is tracking the discussion. @@ -307,10 +307,10 @@ public function moodleoverflow_delete_post($deletechildren) { } // Delete the ratings. - $DB->delete_records('moodleoverflow_ratings', array('postid' => $this->id)); + $DB->delete_records('moodleoverflow_ratings', ['postid' => $this->id]); // Delete the post. - if ($DB->delete_records('moodleoverflow_posts', array('id' => $this->id))) { + if ($DB->delete_records('moodleoverflow_posts', ['id' => $this->id])) { // Delete the read records. readtracking::moodleoverflow_delete_read_records(-1, $this->id); @@ -330,14 +330,14 @@ public function moodleoverflow_delete_post($deletechildren) { } // Trigger the post deletion event. - $params = array( + $params = [ 'context' => $context, 'objectid' => $this->id, - 'other' => array( + 'other' => [ 'discussionid' => $this->discussion, - 'moodleoverflowid' => $this->get_moodleoverflow()->id - ) - ); + 'moodleoverflowid' => $this->get_moodleoverflow()->id, + ], + ]; if ($this->userid !== $USER->id) { $params['relateduserid'] = $this->userid; } @@ -439,7 +439,7 @@ public function moodleoverflow_add_attachment() { $present = ($info['filecount'] > 0) ? '1' : ''; file_save_draft_area_files($this->formattachments, $context->id, 'mod_moodleoverflow', 'attachment', $this->id, \mod_moodleoverflow_post_form::attachment_options($this->get_moodleoverflow())); - $DB->set_field('moodleoverflow_posts', 'attachment', $present, array('id' => $this->id)); + $DB->set_field('moodleoverflow_posts', 'attachment', $present, ['id' => $this->id]); } /** @@ -453,10 +453,10 @@ public function moodleoverflow_get_attachments() { $this->existence_check(); if (empty($this->attachment) || (!$context = \context_module::instance($this->get_coursemodule()->id))) { - return array(); + return []; } - $attachments = array(); + $attachments = []; $fs = get_file_storage(); // We retrieve all files according to the time that they were created. In the case that several files were uploaded @@ -465,18 +465,18 @@ public function moodleoverflow_get_attachments() { if ($files) { $i = 0; foreach ($files as $file) { - $attachments[$i] = array(); + $attachments[$i] = []; $attachments[$i]['filename'] = $file->get_filename(); $mimetype = $file->get_mimetype(); $iconimage = $OUTPUT->pix_icon(file_file_icon($file), get_mimetype_description($file), 'moodle', - array('class' => 'icon')); + ['class' => 'icon']); $path = moodle_url::make_pluginfile_url($file->get_contextid(), $file->get_component(), $file->get_filearea(), $file->get_itemid(), $file->get_filepath(), $file->get_filename()); $attachments[$i]['icon'] = $iconimage; $attachments[$i]['filepath'] = $path; - if (in_array($mimetype, array('image/gif', 'image/jpeg', 'image/png'))) { + if (in_array($mimetype, ['image/gif', 'image/jpeg', 'image/png'])) { // Image attachments don't get printed as links. $attachments[$i]['image'] = true; } else { @@ -536,7 +536,7 @@ public function get_moodleoverflow() { if (empty($this->moodleoverflowobject)) { $discussion = $this->get_discussion(); - $this->moodleoverflowobject = $DB->get_record('moodleoverflow', array('id' => $discussion->get_moodleoverflowid())); + $this->moodleoverflowobject = $DB->get_record('moodleoverflow', ['id' => $discussion->get_moodleoverflowid()]); } return $this->moodleoverflowobject; @@ -552,7 +552,7 @@ public function get_discussion() { $this->existence_check(); if (empty($this->discussionobject)) { - $record = $DB->get_record('moodleoverflow_discussions', array('id' => $this->discussion)); + $record = $DB->get_record('moodleoverflow_discussions', ['id' => $this->discussion]); $this->discussionobject = discussion::from_record($record); } return $this->discussionobject; @@ -588,7 +588,7 @@ public function moodleoverflow_get_parentpost() { } if (empty($this->parentpost)) { - $parentpostrecord = $DB->get_record('moodleoverflow_post', array('id' => $this->parent)); + $parentpostrecord = $DB->get_record('moodleoverflow_post', ['id' => $this->parent]); $this->parentpost = $this->from_record($parentpostrecord); } return $this->parentpost; @@ -603,7 +603,7 @@ public function moodleoverflow_get_childposts() { global $DB; $this->existence_check(); - if ($childposts = $DB->get_records('moodleoverflow_posts', array('parent' => $this->id))) { + if ($childposts = $DB->get_records('moodleoverflow_posts', ['parent' => $this->id])) { return $childposts; } diff --git a/classes/post/post_control.php b/classes/post/post_control.php index 6e3331578d..91da39cff8 100644 --- a/classes/post/post_control.php +++ b/classes/post/post_control.php @@ -31,6 +31,7 @@ use mod_moodleoverflow\post\post; use mod_moodleoverflow\discussion\discussion; +use moodle_exception; defined('MOODLE_INTERNAL') || die(); global $CFG; @@ -121,7 +122,7 @@ public function detect_interaction($urlparameter) { $this->info->deletepostid = $urlparameter->delete; $this->build_prepost_delete($this->info->deletepostid); } else { - throw new \moodle_exception('unknownaction'); + throw new moodle_exception('unknownaction'); } } @@ -155,7 +156,7 @@ public function execute_interaction($form) { } else if ($this->interaction == 'edit' && $form->edit == $this->prepost->postid) { $this->execute_edit($form, $errordestination); } else { - throw new \moodle_exception('unexpectedinteractionerror', 'moodleoverflow', $errordestination); + throw new moodle_exception('unexpectedinteractionerror', 'moodleoverflow', $errordestination); } } @@ -169,7 +170,7 @@ public function execute_interaction($form) { public function catch_guest($postid = false, $moodleoverflowid = false) { global $PAGE; if ((!$postid && !$moodleoverflowid) || ($postid && $moodleoverflowid)) { - throw new \moodle_exception('inaccurateparameter', 'moodleoverflow'); + throw new moodle_exception('inaccurateparameter', 'moodleoverflow'); } if ($postid) { $this->collect_information($postid, false); @@ -208,15 +209,13 @@ private function build_prepost_create($moodleoverflowid) { if (enrol_selfenrol_available($this->info->course->id)) { $SESSION->wantsurl = qualified_me(); $SESSION->enrolcancel = get_local_referer(false); - redirect(new \moodle_url('/enrol/index.php', - array('id' => $this->info->course->id, - 'returnurl' => '/mod/moodleoverflow/view.php?m=' . - $this->info->moodleoverflow->id)), - get_string('youneedtoenrol')); + redirect(new \moodle_url('/enrol/index.php', ['id' => $this->info->course->id, + 'returnurl' => '/mod/moodleoverflow/view.php?m=' . $this->info->moodleoverflow->id, ]), + get_string('youneedtoenrol')); } } // Notify the user, that he can not post a new discussion. - throw new \moodle_exception('nopostmoodleoverflow', 'moodleoverflow'); + throw new moodle_exception('nopostmoodleoverflow', 'moodleoverflow'); } // Where is the user coming from? @@ -265,17 +264,16 @@ private function build_prepost_reply($replypostid) { $SESSION->wantsurl = qualified_me(); $SESSION->enrolcancel = get_local_referer(false); redirect(new \moodle_url('/enrol/index.php', - array('id' => $this->info->course->id, - 'returnurl' => '/mod/moodleoverflow/view.php?m=' . - $this->info->moodleoverflow->id)), - get_string('youneedtoenrol')); + ['id' => $this->info->course->id, + 'returnurl' => '/mod/moodleoverflow/view.php?m=' . $this->info->moodleoverflow->id, + ]), get_string('youneedtoenrol')); } // Print the error message. - throw new \moodle_exception('nopostmoodleoverflow', 'moodleoverflow'); + throw new moodle_exception('nopostmoodleoverflow', 'moodleoverflow'); } // Make sure the user can post here. if (!$this->info->cm->visible && !has_capability('moodle/course:viewhiddenactivities', $this->info->modulecontext)) { - throw new \moodle_exception('activityiscurrentlyhidden'); + throw new moodle_exception('activityiscurrentlyhidden'); } // Append 'RE: ' to the discussions subject. @@ -319,7 +317,7 @@ private function build_prepost_edit($editpostid) { && $this->info->relatedpost->reviewed; if (($beyondtime || $alreadyreviewed) && !has_capability('mod/moodleoverflow:editanypost', $this->info->modulecontext)) { - throw new \moodle_exception('maxtimehaspassed', 'moodleoverflow', '', + throw new moodle_exception('maxtimehaspassed', 'moodleoverflow', '', format_time(get_config('moodleoverflow', 'maxeditingtime'))); } @@ -330,7 +328,7 @@ private function build_prepost_edit($editpostid) { if (!has_capability('mod/moodleoverflow:editanypost', $this->info->modulecontext)) { // Display the error. Capabilities are missing. - throw new \moodle_exception('cannoteditposts', 'moodleoverflow'); + throw new moodle_exception('cannoteditposts', 'moodleoverflow'); } } @@ -393,14 +391,14 @@ private function execute_create($form, $errordestination) { $this->prepost->subject, 0, $this->prepost->userid, $this->prepost->timenow, $this->prepost->timenow, $this->prepost->userid); if (!$discussion->moodleoverflow_add_discussion($this->prepost)) { - throw new \moodle_exception('couldnotadd', 'moodleoverflow', $errordestination); + throw new moodle_exception('couldnotadd', 'moodleoverflow', $errordestination); } // The creation was successful. $redirectmessage = \html_writer::tag('p', get_string("postaddedsuccess", "moodleoverflow")); // Trigger the discussion created event. - $params = array( 'context' => $this->info->modulecontext, 'objectid' => $discussion->get_id()); + $params = ['context' => $this->info->modulecontext, 'objectid' => $discussion->get_id()]; $event = \mod_moodleoverflow\event\discussion_created::create($params); $event->trigger(); @@ -412,7 +410,7 @@ private function execute_create($form, $errordestination) { $this->info->modulecontext); // Define the location to redirect the user after successfully posting. - $redirectto = new \moodle_url('/mod/moodleoverflow/view.php', array('m' => $form->moodleoverflow)); + $redirectto = new \moodle_url('/mod/moodleoverflow/view.php', ['m' => $form->moodleoverflow]); redirect(moodleoverflow_go_back_to($redirectto->out()), $redirectmessage, null, \core\output\notification::NOTIFY_SUCCESS); } @@ -430,7 +428,7 @@ private function execute_reply($form, $errordestination) { // Create the new post. if (!$newpostid = $this->info->discussion->moodleoverflow_add_post_to_discussion($this->prepost)) { - throw new \moodle_exception('couldnotadd', 'moodleoverflow', $errordestination); + throw new moodle_exception('couldnotadd', 'moodleoverflow', $errordestination); } // The creation was successful. @@ -439,10 +437,11 @@ private function execute_reply($form, $errordestination) { format_time(get_config('moodleoverflow', 'maxeditingtime')))); // Trigger the post created event. - $params = array('context' => $this->info->modulecontext, 'objectid' => $newpostid, - 'other' => array('discussionid' => $this->prepost->discussionid, - 'moodleoverflowid' => $this->prepost->moodleoverflowid) - ); + $params = ['context' => $this->info->modulecontext, 'objectid' => $newpostid, + 'other' => ['discussionid' => $this->prepost->discussionid, + 'moodleoverflowid' => $this->prepost->moodleoverflowid, + ], + ]; $event = \mod_moodleoverflow\event\post_created::create($params); $event->trigger(); @@ -455,7 +454,7 @@ private function execute_reply($form, $errordestination) { // Define the location to redirect the user after successfully posting. $redirectto = new \moodle_url('/mod/moodleoverflow/discussion.php', - array('d' => $this->prepost->discussionid, 'p' => $newpostid)); + ['d' => $this->prepost->discussionid, 'p' => $newpostid]); redirect(\moodleoverflow_go_back_to($redirectto->out()), $redirectmessage, null, \core\output\notification::NOTIFY_SUCCESS); } @@ -472,7 +471,7 @@ private function execute_edit($form, $errordestination) { // Update the post. if (!$this->info->discussion->moodleoverflow_edit_post_from_discussion($this->prepost)) { - throw new \moodle_exception('couldnotupdate', 'moodleoverflow', $errordestination); + throw new moodle_exception('couldnotupdate', 'moodleoverflow', $errordestination); } // The edit was successful. @@ -484,24 +483,25 @@ private function execute_edit($form, $errordestination) { $this->prepost->userid)) { $name = get_string('anonymous', 'moodleoverflow'); } else { - $realuser = $DB->get_record('user', array('id' => $this->prepost->userid)); + $realuser = $DB->get_record('user', ['id' => $this->prepost->userid]); $name = fullname($realuser); } $redirectmessage = get_string('editedpostupdated', 'moodleoverflow', $name); } // Trigger the post updated event. - $params = array('context' => $this->info->modulecontext, 'objectid' => $form->edit, - 'other' => array('discussionid' => $this->prepost->discussionid, - 'moodleoverflowid' => $this->prepost->moodleoverflowid), - 'relateduserid' => $this->prepost->userid == $USER->id ? $this->prepost->userid : null - ); + $params = ['context' => $this->info->modulecontext, 'objectid' => $form->edit, + 'other' => ['discussionid' => $this->prepost->discussionid, + 'moodleoverflowid' => $this->prepost->moodleoverflowid, + ], + 'relateduserid' => $this->prepost->userid == $USER->id ? $this->prepost->userid : null, + ]; $event = \mod_moodleoverflow\event\post_updated::create($params); $event->trigger(); // Define the location to redirect the user after successfully editing. $redirectto = new \moodle_url('/mod/moodleoverflow/discussion.php', - array('d' => $this->prepost->discussionid, 'p' => $form->edit)); + ['d' => $this->prepost->discussionid, 'p' => $form->edit]); redirect(moodleoverflow_go_back_to($redirectto->out()), $redirectmessage, null, \core\output\notification::NOTIFY_SUCCESS); } @@ -510,14 +510,14 @@ public function execute_delete() { // Check if the user has the capability to delete the post. $timepassed = time() - $this->info->relatedpost->created; - $url = new \moodle_url('/mod/moodleoverflow/discussion.php', array('d' => $this->info->discussion->get_id())); + $url = new \moodle_url('/mod/moodleoverflow/discussion.php', ['d' => $this->info->discussion->get_id()]); if (($timepassed > get_config('moodleoverflow', 'maxeditingtime')) && !$this->info->deleteanypost) { - throw new \moodle_exception('cannotdeletepost', 'moodleoverflow', moodleoverflow_go_back_to($url)); + throw new moodle_exception('cannotdeletepost', 'moodleoverflow', moodleoverflow_go_back_to($url)); } // A normal user cannot delete his post if there are direct replies. if ($this->info->replycount && !$this->info->deleteanypost) { - throw new \moodle_exception('cannotdeletereplies', 'moodleoverflow', moodleoverflow_go_back_to($url)); + throw new moodle_exception('cannotdeletereplies', 'moodleoverflow', moodleoverflow_go_back_to($url)); } // Check if the post is a parent post or not. @@ -530,7 +530,7 @@ public function execute_delete() { redirect('view.php?m=' . $moodleoverflowid); } else { $this->info->discussion->moodleoverflow_delete_post_from_discussion($this->prepost); - $discussionurl = new \moodle_url('/mod/moodleoverflow/discussion.php', array('d' => $this->info->discussion->get_id())); + $discussionurl = new \moodle_url('/mod/moodleoverflow/discussion.php', ['d' => $this->info->discussion->get_id()]); redirect(moodleoverflow_go_back_to($discussionurl)); } } @@ -569,12 +569,13 @@ public function build_postform($pageparams) { // Prepare the form. $edit = $this->interaction == 'edit'; - $formarray = array( 'course' => $this->info->course, 'cm' => $this->info->cm, 'coursecontext' => $this->info->coursecontext, - 'modulecontext' => $this->info->modulecontext, 'moodleoverflow' => $this->info->moodleoverflow, - 'post' => $this->prepost, 'edit' => $edit); + $formarray = ['course' => $this->info->course, 'cm' => $this->info->cm, 'coursecontext' => $this->info->coursecontext, + 'modulecontext' => $this->info->modulecontext, 'moodleoverflow' => $this->info->moodleoverflow, + 'post' => $this->prepost, 'edit' => $edit, + ]; // Declare the post_form. - $mformpost = new \mod_moodleoverflow_post_form('post.php', $formarray, 'post', '', array('id' => 'mformmoodleoverflow')); + $mformpost = new \mod_moodleoverflow_post_form('post.php', $formarray, 'post', '', ['id' => 'mformmoodleoverflow']); // If the user is not the original author append an extra message to the message. (Happens when interaction = 'edit'). if ($USER->id != $this->prepost->userid) { @@ -586,7 +587,7 @@ public function build_postform($pageparams) { $data->name = \html_writer::tag('a', $CFG->wwwroot . '/user/view.php?id' . $USER->id . '&course=' . $this->prepost->courseid . '">' . fullname($USER)); $this->prepost->message .= \html_writer::tag('p', \html_writer::tag('span', - get_string('editedby', 'moodleoverflow', $data), array("class" => "edited"))); + get_string('editedby', 'moodleoverflow', $data), ["class" => "edited"])); } else { $data->name = fullname($USER); $this->prepost->message .= "\n\n(" . get_string('editedby', 'moodleoverflow', $data) . ')'; @@ -605,13 +606,18 @@ public function build_postform($pageparams) { } // Set data for the form. - $mformpost->set_data(array( - 'attachments' => $draftitemid, 'general' => $heading, 'subject' => $this->prepost->subject, - 'message' => array('text' => $this->prepost->message, - 'format' => editors_get_preferred_format(), - 'itemid' => $this->prepost->postid), - 'userid' => $this->prepost->userid, 'parent' => $this->prepost->parentid, 'discussion' => $this->prepost->discussionid, - 'course' => $this->prepost->courseid) + $mformpost->set_data([ + 'attachments' => $draftitemid, + 'general' => $heading, + 'subject' => $this->prepost->subject, + 'message' => ['text' => $this->prepost->message, + 'format' => editors_get_preferred_format(), + 'itemid' => $this->prepost->postid, ], + 'userid' => $this->prepost->userid, + 'parent' => $this->prepost->parentid, + 'discussion' => $this->prepost->discussionid, + 'course' => $this->prepost->courseid, + ] + $pageparams ); @@ -703,7 +709,7 @@ private function assemble_prepost() { */ private function check_interaction($interaction) { if ($this->interaction != $interaction) { - throw new \moodle_exception('wronginteraction' , 'moodleoverflow'); + throw new moodle_exception('wronginteraction' , 'moodleoverflow'); } return true; } @@ -717,8 +723,8 @@ private function check_interaction($interaction) { */ private function check_course_exists($courseid) { global $DB; - if (!$course = $DB->get_record('course', array('id' => $courseid))) { - throw new \moodle_exception('invalidcourseid'); + if (!$course = $DB->get_record('course', ['id' => $courseid])) { + throw new moodle_exception('invalidcourseid'); } return $course; } @@ -732,7 +738,7 @@ private function check_course_exists($courseid) { private function check_coursemodule_exists($moodleoverflowid, $courseid) { if (!$cm = get_coursemodule_from_instance('moodleoverflow', $moodleoverflowid, $courseid)) { - throw new \moodle_exception('invalidcoursemodule'); + throw new moodle_exception('invalidcoursemodule'); } return $cm; } @@ -745,8 +751,8 @@ private function check_coursemodule_exists($moodleoverflowid, $courseid) { private function check_moodleoverflow_exists($moodleoverflowid) { // Get the related moodleoverflow instance. global $DB; - if (!$moodleoverflow = $DB->get_record('moodleoverflow', array('id' => $moodleoverflowid))) { - throw new \moodle_exception('invalidmoodleoverflowid', 'moodleoverflow'); + if (!$moodleoverflow = $DB->get_record('moodleoverflow', ['id' => $moodleoverflowid])) { + throw new moodle_exception('invalidmoodleoverflowid', 'moodleoverflow'); } return $moodleoverflow; } @@ -758,8 +764,8 @@ private function check_moodleoverflow_exists($moodleoverflowid) { */ private function check_discussion_exists($discussionid) { global $DB; - if (!$discussionrecord = $DB->get_record('moodleoverflow_discussions', array('id' => $discussionid))) { - throw new \moodle_exception('invaliddiscussionid', 'moodleoverflow'); + if (!$discussionrecord = $DB->get_record('moodleoverflow_discussions', ['id' => $discussionid])) { + throw new moodle_exception('invaliddiscussionid', 'moodleoverflow'); } return discussion::from_record($discussionrecord); } @@ -771,8 +777,8 @@ private function check_discussion_exists($discussionid) { */ private function check_post_exists($postid) { global $DB; - if (!$postrecord = $DB->get_record('moodleoverflow_posts', array('id' => $postid))) { - throw new \moodle_exception('invalidpostid', 'moodleoverflow'); + if (!$postrecord = $DB->get_record('moodleoverflow_posts', ['id' => $postid])) { + throw new moodle_exception('invalidpostid', 'moodleoverflow'); } return post::from_record($postrecord); } @@ -786,7 +792,7 @@ private function check_post_exists($postid) { */ private function check_user_can_create_discussion() { if (!has_capability('mod/moodleoverflow:startdiscussion', $this->info->modulecontext)) { - throw new \moodle_exception('cannotcreatediscussion', 'moodleoverflow'); + throw new moodle_exception('cannotcreatediscussion', 'moodleoverflow'); } return true; } @@ -798,7 +804,7 @@ private function check_user_can_create_discussion() { */ private function check_user_can_create_reply() { if (!has_capability('mod/moodleoverflow:replypost', $this->info->modulecontext, $this->prepost->userid)) { - throw new \moodle_exception('cannotreply', 'moodleoverflow'); + throw new moodle_exception('cannotreply', 'moodleoverflow'); } return true; } @@ -818,7 +824,7 @@ private function check_user_can_edit_post() { $startdiscussion = has_capability('mod/moodleoverflow:startdiscussion', $this->info->modulecontext); $ownpost = ($this->prepost->userid == $USER->id); if (!(($ownpost && ($replypost || $startdiscussion)) || $editanypost)) { - throw new \moodle_exception('cannotupdatepost', 'moodleoverflow'); + throw new moodle_exception('cannotupdatepost', 'moodleoverflow'); } return true; } @@ -834,7 +840,7 @@ private function check_user_can_delete_post() { $this->info->deleteanypost = has_capability('mod/moodleoverflow:deleteanypost', $this->info->modulecontext); if (!(($this->info->relatedpost->get_userid() == $USER->id && $this->info->deleteownpost) || $this->info->deleteanypost)) { - throw new \moodle_exception('cannotdeletepost', 'moodleoverflow'); + throw new moodle_exception('cannotdeletepost', 'moodleoverflow'); } return true; } diff --git a/classes/post_form.php b/classes/post_form.php index 6631f326e6..97e49d5716 100644 --- a/classes/post_form.php +++ b/classes/post_form.php @@ -134,12 +134,12 @@ public static function attachment_options($moodleoverflow) { global $COURSE, $PAGE, $CFG; $maxbytes = get_user_max_upload_file_size($PAGE->context, $CFG->maxbytes, $COURSE->maxbytes, $moodleoverflow->maxbytes); - return array( + return [ 'subdirs' => 0, 'maxbytes' => $maxbytes, 'maxfiles' => $moodleoverflow->maxattachments, 'accepted_types' => '*', - 'return_types' => FILE_INTERNAL | FILE_CONTROLLED_LINK - ); + 'return_types' => FILE_INTERNAL | FILE_CONTROLLED_LINK, + ]; } } diff --git a/classes/privacy/data_export_helper.php b/classes/privacy/data_export_helper.php index 750903a5ac..858ae859f0 100644 --- a/classes/privacy/data_export_helper.php +++ b/classes/privacy/data_export_helper.php @@ -22,7 +22,7 @@ */ namespace mod_moodleoverflow\privacy; use core_privacy\local\request\transform; -use \core_privacy\local\request\writer; +use core_privacy\local\request\writer; use mod_moodleoverflow\ratings; /** @@ -51,7 +51,7 @@ public static function export_discussion_data($userid, array $mappings) { FROM {moodleoverflow} mof INNER JOIN {moodleoverflow_discussions} d ON d.moodleoverflow = mof.id LEFT JOIN {moodleoverflow_discuss_subs} dsub ON dsub.discussion = d.id - WHERE mof.id ${foruminsql} + WHERE mof.id {$foruminsql} AND ( d.userid = :discussionuserid OR d.usermodified = :dmuserid OR @@ -78,7 +78,7 @@ public static function export_discussion_data($userid, array $mappings) { 'name' => format_string($discussion->name, true), 'timemodified' => transform::datetime($discussion->timemodified), 'creator_was_you' => transform::yesno($discussion->userid == $userid), - 'last_modifier_was_you' => transform::yesno($discussion->usermodified == $userid) + 'last_modifier_was_you' => transform::yesno($discussion->usermodified == $userid), ]; // Store the discussion content. writer::with_context($context)->export_data( @@ -113,7 +113,7 @@ public static function export_all_posts($userid, array $mappings) { INNER JOIN {moodleoverflow_posts} p ON p.discussion = d.id LEFT JOIN {moodleoverflow_read} fr ON fr.postid = p.id LEFT JOIN {moodleoverflow_ratings} rat ON rat.postid = p.id - WHERE mof.id ${foruminsql} AND + WHERE mof.id {$foruminsql} AND ( p.userid = :postuserid OR fr.userid = :readuserid OR @@ -164,7 +164,7 @@ protected static function export_all_posts_in_discussion($userid, \context $cont $params = [ 'discussionid' => $discussionid, 'readuserid' => $userid, - 'ratinguserid' => $userid + 'ratinguserid' => $userid, ]; // Keep track of the forums which have data. @@ -237,7 +237,7 @@ protected static function export_post_data($userid, \context $context, $postarea $postdata = (object) [ 'created' => transform::datetime($post->created), 'modified' => transform::datetime($post->modified), - 'author_was_you' => transform::yesno($post->userid == $userid) + 'author_was_you' => transform::yesno($post->userid == $userid), ]; $postdata->message = writer::with_context($context)->rewrite_pluginfile_urls( $postarea, 'mod_moodleoverflow', 'attachment', $post->id, $post->message); @@ -285,11 +285,11 @@ protected static function export_rating_data($postid, $onlyuser, $userid) { 'userid' => $userid, 'postid' => $postid, ]); - $userratings = array(); + $userratings = []; foreach ($ownratings as $rating) { $userratings[] = (object) [ 'firstrated' => $rating->firstrated, - 'rating' => $rating->rating + 'rating' => $rating->rating, ]; } @@ -298,7 +298,7 @@ protected static function export_rating_data($postid, $onlyuser, $userid) { 'downvotes' => $ratingpost->downvotes, 'upvotes' => $ratingpost->upvotes, 'was_rated_as_helpful' => transform::yesno($ratingpost->ishelpful), - 'was_rated_as_solved' => transform::yesno($ratingpost->issolved) + 'was_rated_as_solved' => transform::yesno($ratingpost->issolved), ]; } $ratingdata['your_rating'] = (object) $userratings; diff --git a/classes/privacy/provider.php b/classes/privacy/provider.php index 139ec513c4..d1bf9e7644 100644 --- a/classes/privacy/provider.php +++ b/classes/privacy/provider.php @@ -25,12 +25,12 @@ namespace mod_moodleoverflow\privacy; use core_privacy\local\request\approved_userlist; -use \core_privacy\local\request\userlist; +use core_privacy\local\request\userlist; use core_privacy\local\metadata\collection; use core_privacy\local\request\approved_contextlist; use core_privacy\local\request\contextlist; use core_privacy\local\request\writer; -use \core_privacy\local\request\helper as request_helper; +use core_privacy\local\request\helper as request_helper; /** * Privacy Subsystem for mod_moodleoverflow implementing provider. @@ -56,7 +56,7 @@ public static function get_metadata(collection $collection) : collection { 'name' => 'privacy:metadata:moodleoverflow_discussions:name', 'userid' => 'privacy:metadata:moodleoverflow_discussions:userid', 'timemodified' => 'privacy:metadata:moodleoverflow_discussions:timemodified', - 'usermodified' => 'privacy:metadata:moodleoverflow_discussions:usermodified' + 'usermodified' => 'privacy:metadata:moodleoverflow_discussions:usermodified', ], 'privacy:metadata:moodleoverflow_discussions'); @@ -67,7 +67,7 @@ public static function get_metadata(collection $collection) : collection { 'userid' => 'privacy:metadata:moodleoverflow_posts:userid', 'created' => 'privacy:metadata:moodleoverflow_posts:created', 'modified' => 'privacy:metadata:moodleoverflow_posts:modified', - 'message' => 'privacy:metadata:moodleoverflow_posts:message' + 'message' => 'privacy:metadata:moodleoverflow_posts:message', ], 'privacy:metadata:moodleoverflow_posts'); @@ -77,14 +77,14 @@ public static function get_metadata(collection $collection) : collection { 'discussionid' => 'privacy:metadata:moodleoverflow_read:discussionid', 'postid' => 'privacy:metadata:moodleoverflow_read:postid', 'firstread' => 'privacy:metadata:moodleoverflow_read:firstread', - 'lastread' => 'privacy:metadata:moodleoverflow_read:lastread' + 'lastread' => 'privacy:metadata:moodleoverflow_read:lastread', ], 'privacy:metadata:moodleoverflow_read'); $collection->add_database_table('moodleoverflow_subscriptions', [ 'userid' => 'privacy:metadata:moodleoverflow_subscriptions:userid', - 'moodleoverflow' => 'privacy:metadata:moodleoverflow_subscriptions:moodleoverflow' + 'moodleoverflow' => 'privacy:metadata:moodleoverflow_subscriptions:moodleoverflow', ], 'privacy:metadata:moodleoverflow_subscriptions'); @@ -92,7 +92,7 @@ public static function get_metadata(collection $collection) : collection { [ 'userid' => 'privacy:metadata:moodleoverflow_discuss_subs:userid', 'discussion' => 'privacy:metadata:moodleoverflow_discuss_subs:discussion', - 'preference' => 'privacy:metadata:moodleoverflow_discuss_subs:preference' + 'preference' => 'privacy:metadata:moodleoverflow_discuss_subs:preference', ], 'privacy:metadata:moodleoverflow_discuss_subs'); @@ -102,14 +102,14 @@ public static function get_metadata(collection $collection) : collection { 'postid' => 'privacy:metadata:moodleoverflow_ratings:postid', 'rating' => 'privacy:metadata:moodleoverflow_ratings:rating', 'firstrated' => 'privacy:metadata:moodleoverflow_ratings:firstrated', - 'lastchanged' => 'privacy:metadata:moodleoverflow_ratings:lastchanged' + 'lastchanged' => 'privacy:metadata:moodleoverflow_ratings:lastchanged', ], 'privacy:metadata:moodleoverflow_ratings'); $collection->add_database_table('moodleoverflow_tracking', [ 'userid' => 'privacy:metadata:moodleoverflow_tracking:userid', - 'moodleoverflowid' => 'privacy:metadata:moodleoverflow_tracking:moodleoverflowid' + 'moodleoverflowid' => 'privacy:metadata:moodleoverflow_tracking:moodleoverflowid', ], 'privacy:metadata:moodleoverflow_tracking'); @@ -177,7 +177,7 @@ public static function get_contexts_for_userid(int $userid) : contextlist { 'dsuserid' => $userid, 'rauserid' => $userid, 'tuserid' => $userid, - 'guserid' => $userid + 'guserid' => $userid, ]; $contextlist = new \core_privacy\local\request\contextlist(); @@ -225,7 +225,7 @@ public static function export_user_data(approved_contextlist $contextlist) { $params = [ 'suserid' => $userid, 'userid' => $userid, - 'guserid' => $userid + 'guserid' => $userid, ]; $params += $contextparams; @@ -324,29 +324,29 @@ public static function delete_data_for_user(approved_contextlist $contextlist) { $DB->delete_records('moodleoverflow_read', [ 'moodleoverflowid' => $forum->id, - 'userid' => $userid]); + 'userid' => $userid, ]); $DB->delete_records('moodleoverflow_subscriptions', [ 'moodleoverflow' => $forum->id, - 'userid' => $userid]); + 'userid' => $userid, ]); $DB->delete_records('moodleoverflow_discuss_subs', [ 'moodleoverflow' => $forum->id, - 'userid' => $userid]); + 'userid' => $userid, ]); $DB->delete_records('moodleoverflow_tracking', [ 'moodleoverflowid' => $forum->id, - 'userid' => $userid]); + 'userid' => $userid, ]); $DB->delete_records('moodleoverflow_grades', [ 'moodleoverflowid' => $forum->id, - 'userid' => $userid]); + 'userid' => $userid, ]); // Do not delete ratings but reset userid. $ratingsql = "userid = :userid AND discussionid IN (SELECT id FROM {moodleoverflow_discussions} WHERE moodleoverflow = :forum)"; $ratingparams = [ 'forum' => $forum->id, - 'userid' => $userid + 'userid' => $userid, ]; $DB->set_field_select('moodleoverflow_ratings', 'userid', 0, $ratingsql, $ratingparams); @@ -355,7 +355,7 @@ public static function delete_data_for_user(approved_contextlist $contextlist) { $postidsql = "SELECT p.id FROM {moodleoverflow_posts} p WHERE {$postsql}"; $postparams = [ 'forum' => $forum->id, - 'userid' => $userid + 'userid' => $userid, ]; // Delete all files from the posts. diff --git a/classes/ratings.php b/classes/ratings.php index 6db3641bf7..056dd64f87 100644 --- a/classes/ratings.php +++ b/classes/ratings.php @@ -55,30 +55,30 @@ public static function moodleoverflow_add_rating($moodleoverflow, $postid, $rati } // Is the submitted rating valid? - $possibleratings = array(RATING_NEUTRAL, RATING_DOWNVOTE, RATING_UPVOTE, RATING_SOLVED, + $possibleratings = [RATING_NEUTRAL, RATING_DOWNVOTE, RATING_UPVOTE, RATING_SOLVED, RATING_HELPFUL, RATING_REMOVE_DOWNVOTE, RATING_REMOVE_UPVOTE, - RATING_REMOVE_SOLVED, RATING_REMOVE_HELPFUL); + RATING_REMOVE_SOLVED, RATING_REMOVE_HELPFUL, ]; if (!in_array($rating, $possibleratings)) { throw new moodle_exception('invalidratingid', 'moodleoverflow'); } // Get the related discussion. - if (!$post = $DB->get_record('moodleoverflow_posts', array('id' => $postid))) { + if (!$post = $DB->get_record('moodleoverflow_posts', ['id' => $postid])) { throw new moodle_exception('invalidparentpostid', 'moodleoverflow'); } // Check if the post belongs to a discussion. - if (!$discussion = $DB->get_record('moodleoverflow_discussions', array('id' => $post->discussion))) { + if (!$discussion = $DB->get_record('moodleoverflow_discussions', ['id' => $post->discussion])) { throw new moodle_exception('notpartofdiscussion', 'moodleoverflow'); } // Get the related course. - if (!$course = $DB->get_record('course', array('id' => $moodleoverflow->course))) { + if (!$course = $DB->get_record('course', ['id' => $moodleoverflow->course])) { throw new moodle_exception('invalidcourseid'); } // Are multiple marks allowed? - $markssetting = $DB->get_record('moodleoverflow', array('id' => $moodleoverflow->id), 'allowmultiplemarks'); + $markssetting = $DB->get_record('moodleoverflow', ['id' => $moodleoverflow->id], 'allowmultiplemarks'); $multiplemarks = (bool) $markssetting->allowmultiplemarks; // Retrieve the contexts. @@ -93,10 +93,10 @@ public static function moodleoverflow_add_rating($moodleoverflow, $postid, $rati if (!isguestuser() && !is_enrolled($coursecontext)) { $SESSION->wantsurl = qualified_me(); $SESSION->enrolcancel = get_local_referer(false); - redirect(new \moodle_url('/enrol/index.php', array( + redirect(new \moodle_url('/enrol/index.php', [ 'id' => $course->id, - 'returnurl' => '/mod/moodleoverflow/view.php?m' . $moodleoverflow->id - )), get_string('youneedtoenrol')); + 'returnurl' => '/mod/moodleoverflow/view.php?m' . $moodleoverflow->id, + ]), get_string('youneedtoenrol')); } // Notify the user, that he can not post a new discussion. @@ -212,7 +212,7 @@ public static function moodleoverflow_get_reputation($moodleoverflowid, $userid } // Check the moodleoverflow instance. - if (!$moodleoverflow = $DB->get_record('moodleoverflow', array('id' => $moodleoverflowid))) { + if (!$moodleoverflow = $DB->get_record('moodleoverflow', ['id' => $moodleoverflowid])) { throw new moodle_exception('invalidmoodleoverflowid', 'moodleoverflow'); } @@ -236,7 +236,7 @@ public static function moodleoverflow_sort_answers_by_ratings($posts) { $parentpost = array_shift($answerposts); // Create an empty array for the sorted posts and add the parent post. - $sortedposts = array(); + $sortedposts = []; $sortedposts[0] = $parentpost; // Check if solved posts are preferred over helpful posts. @@ -343,7 +343,7 @@ public static function moodleoverflow_sort_answers_by_ratings($posts) { // Rearrange the indices and return the sorted posts. - $neworder = array(); + $neworder = []; foreach ($sortedposts as $post) { $neworder[$post->id] = $post; } @@ -387,7 +387,7 @@ public static function moodleoverflow_get_rating($postid) { global $DB; // Retrieve the full post. - if (!$post = $DB->get_record('moodleoverflow_posts', array('id' => $postid))) { + if (!$post = $DB->get_record('moodleoverflow_posts', ['id' => $postid])) { throw new moodle_exception('postnotexist', 'moodleoverflow'); } @@ -448,10 +448,10 @@ public static function moodleoverflow_discussion_is_solved($discussionid, $teach if ($teacher) { // Check if a teacher marked a solution as solved. - if ($DB->record_exists('moodleoverflow_ratings', array('discussionid' => $discussionid, 'rating' => 3))) { + if ($DB->record_exists('moodleoverflow_ratings', ['discussionid' => $discussionid, 'rating' => 3])) { // Return the rating records. - return $DB->get_records('moodleoverflow_ratings', array('discussionid' => $discussionid, 'rating' => 3)); + return $DB->get_records('moodleoverflow_ratings', ['discussionid' => $discussionid, 'rating' => 3]); } // The teacher has not marked the discussion as solved. @@ -459,10 +459,10 @@ public static function moodleoverflow_discussion_is_solved($discussionid, $teach } // Check if the topic starter marked a solution as helpful. - if ($DB->record_exists('moodleoverflow_ratings', array('discussionid' => $discussionid, 'rating' => 4))) { + if ($DB->record_exists('moodleoverflow_ratings', ['discussionid' => $discussionid, 'rating' => 4])) { // Return the rating records. - return $DB->get_records('moodleoverflow_ratings', array('discussionid' => $discussionid, 'rating' => 4)); + return $DB->get_records('moodleoverflow_ratings', ['discussionid' => $discussionid, 'rating' => 4]); } // The topic starter has not marked a solution as helpful. @@ -486,7 +486,7 @@ public static function moodleoverflow_get_reputation_instance($moodleoverflowid, } // Check the moodleoverflow instance. - if (!$moodleoverflow = $DB->get_record('moodleoverflow', array('id' => $moodleoverflowid))) { + if (!$moodleoverflow = $DB->get_record('moodleoverflow', ['id' => $moodleoverflowid])) { throw new moodle_exception('invalidmoodleoverflowid', 'moodleoverflow'); } @@ -508,11 +508,11 @@ public static function moodleoverflow_get_reputation_instance($moodleoverflowid, $sql .= "ORDER BY r.postid ASC"; - $params = array($userid, $userid, $moodleoverflowid); + $params = [$userid, $userid, $moodleoverflowid]; $records = $DB->get_records_sql($sql, $params); // Check if there are results. - $records = (isset($records)) ? $records : array(); + $records = (isset($records)) ? $records : []; // Iterate through all ratings. foreach ($records as $record) { @@ -551,7 +551,7 @@ public static function moodleoverflow_get_reputation_instance($moodleoverflowid, $sql = "SELECT COUNT(id) as amount FROM {moodleoverflow_ratings} WHERE userid = ? AND moodleoverflowid = ? AND (rating = 1 OR rating = 2)"; - $params = array($userid, $moodleoverflowid); + $params = [$userid, $moodleoverflowid]; $votes = $DB->get_record_sql($sql, $params); // Add reputation for the votes. @@ -586,7 +586,7 @@ public static function moodleoverflow_get_reputation_course($courseid, $userid = $reputation = 0; // Check if the course exists. - if (!$course = $DB->get_record('course', array('id' => $courseid))) { + if (!$course = $DB->get_record('course', ['id' => $courseid])) { throw new moodle_exception('invalidcourseid'); } @@ -595,11 +595,11 @@ public static function moodleoverflow_get_reputation_course($courseid, $userid = FROM {moodleoverflow} WHERE course = ? AND coursewidereputation = 1"; - $params = array($course->id); + $params = [$course->id]; $instances = $DB->get_records_sql($sql, $params); // Check if there are instances in this course. - $instances = (isset($instances)) ? $instances : array(); + $instances = (isset($instances)) ? $instances : []; // Sum the reputation of each individual instance. foreach ($instances as $instance) { @@ -623,7 +623,7 @@ private static function moodleoverflow_check_old_rating($postid, $userid, $oldra global $DB; // Initiate the array. - $rating = array(); + $rating = []; // Get the normal rating. $sql = "SELECT * @@ -705,16 +705,16 @@ private static function moodleoverflow_remove_rating($postid, $rating, $userid, $oldrecord = self::moodleoverflow_check_old_rating($postid, $userid, $rating); // Trigger an event. - $params = array( + $params = [ 'objectid' => $oldrecord->id, 'context' => $modulecontext, - ); + ]; $event = \mod_moodleoverflow\event\rating_deleted::create($params); $event->add_record_snapshot('moodleoverflow_ratings', $oldrecord); $event->trigger(); // Remove the rating record. - return $DB->delete_records('moodleoverflow_ratings', array('id' => $oldrecord->id)); + return $DB->delete_records('moodleoverflow_ratings', ['id' => $oldrecord->id]); } /** @@ -746,10 +746,10 @@ private static function moodleoverflow_add_rating_record($moodleoverflowid, $dis $recordid = $DB->insert_record('moodleoverflow_ratings', $record); // Trigger an event. - $params = array( + $params = [ 'objectid' => $recordid, 'context' => $mod, - ); + ]; $event = \mod_moodleoverflow\event\rating_created::create($params); $event->trigger(); @@ -777,14 +777,14 @@ private static function moodleoverflow_update_rating_record($postid, $rating, $u WHERE id = ?"; // Trigger an event. - $params = array( + $params = [ 'objectid' => $ratingid, 'context' => $modulecontext, - ); + ]; $event = \mod_moodleoverflow\event\rating_updated::create($params); $event->trigger(); - return $DB->execute($sql, array($postid, $userid, $rating, time(), $ratingid)); + return $DB->execute($sql, [$postid, $userid, $rating, time(), $ratingid]); } /** diff --git a/classes/readtracking.php b/classes/readtracking.php index 54a5e57e65..24d4530498 100644 --- a/classes/readtracking.php +++ b/classes/readtracking.php @@ -106,7 +106,7 @@ public static function moodleoverflow_is_tracked($moodleoverflow, $user = null) // Check the preferences of the user. $userpreference = $DB->get_record('moodleoverflow_tracking', - array('userid' => $user->id, 'moodleoverflowid' => $moodleoverflow->id)); + ['userid' => $user->id, 'moodleoverflowid' => $moodleoverflow->id]); // Return the boolean. if (get_config('moodleoverflow', 'allowforcedreadtracking')) { @@ -242,7 +242,7 @@ public static function moodleoverflow_add_read_record($userid, $postid) { $cutoffdate = $now - (get_config('moodleoverflow', 'oldpostdays') * 24 * 3600); // Check for read records for this user an this post. - $oldrecord = $DB->get_record('moodleoverflow_read', array('postid' => $postid, 'userid' => $userid)); + $oldrecord = $DB->get_record('moodleoverflow_read', ['postid' => $postid, 'userid' => $userid]); if (!$oldrecord) { // If there are no old records, create a new one. @@ -252,7 +252,7 @@ public static function moodleoverflow_add_read_record($userid, $postid) { JOIN {moodleoverflow_discussions} d ON d.id = p.discussion WHERE p.id = ? AND p.modified >= ?"; - return $DB->execute($sql, array($userid, $now, $now, $postid, $cutoffdate)); + return $DB->execute($sql, [$userid, $now, $now, $postid, $cutoffdate]); } // Else update the existing one. @@ -260,7 +260,7 @@ public static function moodleoverflow_add_read_record($userid, $postid) { SET lastread = ? WHERE userid = ? AND postid = ?"; - return $DB->execute($sql, array($now, $userid, $userid)); + return $DB->execute($sql, [$now, $userid, $userid]); } /** @@ -278,7 +278,7 @@ public static function moodleoverflow_delete_read_records($userid = -1, $postid global $DB; // Initiate variables. - $params = array(); + $params = []; $select = ''; // Create the sql-Statement depending on the submitted parameters. @@ -351,7 +351,7 @@ public static function moodleoverflow_clean_read_records() { WHERE postid IN (SELECT p.id FROM {moodleoverflow_posts} p WHERE p.modified >= ? AND p.modified < ?)"; - $DB->execute($sql, array($first, $cutoffdate)); + $DB->execute($sql, [$first, $cutoffdate]); } /** @@ -371,7 +371,7 @@ public static function moodleoverflow_stop_tracking($moodleoverflowid, $userid = } // Check if the user already stopped to track the moodleoverflow. - $params = array('userid' => $userid, 'moodleoverflowid' => $moodleoverflowid); + $params = ['userid' => $userid, 'moodleoverflowid' => $moodleoverflowid]; $isstopped = $DB->record_exists('moodleoverflow_tracking', $params); // Stop tracking the moodleoverflow if not already stopped. @@ -410,7 +410,7 @@ public static function moodleoverflow_start_tracking($moodleoverflowid, $userid } // Delete the tracking setting of this user for this moodleoverflow. - return $DB->delete_records('moodleoverflow_tracking', array('userid' => $userid, 'moodleoverflowid' => $moodleoverflowid)); + return $DB->delete_records('moodleoverflow_tracking', ['userid' => $userid, 'moodleoverflowid' => $moodleoverflowid]); } /** @@ -446,11 +446,11 @@ public static function get_untracked_moodleoverflows($userid, $courseid) { WHERE m.course = ? $trackingsql"; // Get all untracked moodleoverflows from the database. - $moodleoverflows = $DB->get_records_sql($sql, array($userid, $courseid, $userid)); + $moodleoverflows = $DB->get_records_sql($sql, [$userid, $courseid, $userid]); // Check whether there are no untracked moodleoverflows. if (!$moodleoverflows) { - return array(); + return []; } // Loop through all moodleoverflows. @@ -491,7 +491,7 @@ public static function moodleoverflow_count_unread_posts_moodleoverflow($cm) { $cutoffdate = $now - (get_config('moodleoverflow', 'oldpostdays') * 24 * 60 * 60); // Define a sql-query. - $params = array($USER->id, $cm->instance, $cutoffdate); + $params = [$USER->id, $cm->instance, $cutoffdate]; $sql = "SELECT COUNT(p.id) FROM {moodleoverflow_posts} p JOIN {moodleoverflow_discussions} d ON p.discussion = d.id diff --git a/classes/review.php b/classes/review.php index 30b92eb71e..833969f960 100644 --- a/classes/review.php +++ b/classes/review.php @@ -72,7 +72,7 @@ public static function get_short_review_info_for_discussion(int $discussionid) { 'FROM {moodleoverflow_posts} ' . 'WHERE discussion = :discussionid AND reviewed = 0 AND created < :cutofftime', [ 'discussionid' => $discussionid, - 'cutofftime' => time() - get_config('moodleoverflow', 'reviewpossibleaftertime') + 'cutofftime' => time() - get_config('moodleoverflow', 'reviewpossibleaftertime'), ] ); } @@ -89,7 +89,7 @@ public static function get_first_review_post($moodleoverflowid, $afterpostid = n $params = [ 'moodleoverflowid' => $moodleoverflowid, - 'reviewtime' => time() - get_config('moodleoverflow', 'reviewpossibleaftertime') + 'reviewtime' => time() - get_config('moodleoverflow', 'reviewpossibleaftertime'), ]; $orderby = ''; $addwhere = ''; @@ -117,7 +117,7 @@ public static function get_first_review_post($moodleoverflowid, $afterpostid = n ); if ($record) { return (new \moodle_url('/mod/moodleoverflow/discussion.php', [ - 'd' => $record->discussionid + 'd' => $record->discussionid, ], 'p' . $record->postid))->out(false); } else { return null; @@ -162,7 +162,7 @@ public static function count_outstanding_reviews_in_moodleoverflow($moodleoverfl 'JOIN {moodleoverflow_discussions} d ON d.id = p.discussion ' . 'WHERE d.moodleoverflow = :moodleoverflowid AND p.created < :cutofftime AND reviewed = 0', [ 'moodleoverflowid' => $moodleoverflowid, - 'cutofftime' => time() - get_config('moodleoverflow', 'reviewpossibleaftertime') + 'cutofftime' => time() - get_config('moodleoverflow', 'reviewpossibleaftertime'), ] ); } diff --git a/classes/subscriptions.php b/classes/subscriptions.php index 8ea2981846..8799d30f5e 100644 --- a/classes/subscriptions.php +++ b/classes/subscriptions.php @@ -26,6 +26,9 @@ namespace mod_moodleoverflow; +use context_module; +use stdClass; + /** * Moodleoverflow subscription manager. * @@ -51,7 +54,7 @@ class subscriptions { * * @var array[] An array of arrays. */ - protected static $moodleoverflowcache = array(); + protected static $moodleoverflowcache = []; /** * The list of moodleoverflows which have been wholly retrieved for the subscription cache. @@ -61,7 +64,7 @@ class subscriptions { * * @var bool[] */ - protected static $fetchedmoodleoverflows = array(); + protected static $fetchedmoodleoverflows = []; /** * The subscription cache for moodleoverflow discussions. @@ -73,7 +76,7 @@ class subscriptions { * * @var array[] */ - protected static $discussioncache = array(); + protected static $discussioncache = []; /** * The list of moodleoverflows which have been wholly retrieved for the discussion subscription cache. @@ -83,7 +86,7 @@ class subscriptions { * * @var bool[] */ - protected static $fetcheddiscussions = array(); + protected static $fetcheddiscussions = []; /** * Returns whether a user is subscribed to this moodleoverflow or a specific discussion within the moodleoverflow. @@ -194,14 +197,14 @@ public static function fill_subscription_cache($moodleoverflowid, $userid = null // Create the cache for the user. if (!isset(self::$moodleoverflowcache[$userid])) { - self::$moodleoverflowcache[$userid] = array(); + self::$moodleoverflowcache[$userid] = []; } // Check if the user is subscribed to the moodleoverflow. if (!isset(self::$moodleoverflowcache[$userid][$moodleoverflowid])) { // Request to the database. - $params = array('userid' => $userid, 'moodleoverflow' => $moodleoverflowid); + $params = ['userid' => $userid, 'moodleoverflow' => $moodleoverflowid]; if ($DB->record_exists('moodleoverflow_subscriptions', $params)) { self::$moodleoverflowcache[$userid][$moodleoverflowid] = true; } else { @@ -212,7 +215,7 @@ public static function fill_subscription_cache($moodleoverflowid, $userid = null } else { // The request is not connected to a specific user. // Request all records. - $params = array('moodleoverflow' => $moodleoverflowid); + $params = ['moodleoverflow' => $moodleoverflowid]; $subscriptions = $DB->get_recordset('moodleoverflow_subscriptions', $params, '', 'id, userid'); // Loop through the records. @@ -220,7 +223,7 @@ public static function fill_subscription_cache($moodleoverflowid, $userid = null // Create a new record if necessary. if (!isset(self::$moodleoverflowcache[$data->userid])) { - self::$moodleoverflowcache[$data->userid] = array(); + self::$moodleoverflowcache[$data->userid] = []; } // Mark the subscription state. @@ -250,7 +253,7 @@ public static function fetch_discussion_subscription($moodleoverflowid, $userid // Create an array, if there is no record. if (!isset(self::$discussioncache[$userid]) || !isset(self::$discussioncache[$userid][$moodleoverflowid])) { - return array(); + return []; } // Return the cached subscription state. @@ -277,14 +280,14 @@ public static function fill_discussion_subscription_cache($moodleoverflowid, $us // Create a new record if necessary. if (!isset(self::$discussioncache[$userid])) { - self::$discussioncache[$userid] = array(); + self::$discussioncache[$userid] = []; } // Check if the moodleoverflow instance is already cached. if (!isset(self::$discussioncache[$userid][$moodleoverflowid])) { // Get all records. - $params = array('userid' => $userid, 'moodleoverflow' => $moodleoverflowid); + $params = ['userid' => $userid, 'moodleoverflow' => $moodleoverflowid]; $subscriptions = $DB->get_recordset('moodleoverflow_discuss_subs', $params, null, 'id, discussion, preference'); @@ -301,7 +304,7 @@ public static function fill_discussion_subscription_cache($moodleoverflowid, $us // No user ID is submitted. // Get all records. - $params = array('moodleoverflow' => $moodleoverflowid); + $params = ['moodleoverflow' => $moodleoverflowid]; $subscriptions = $DB->get_recordset('moodleoverflow_discuss_subs', $params, null, 'id, userid, discussion, preference'); @@ -329,12 +332,12 @@ private static function add_to_discussion_cache($moodleoverflowid, $userid, $dis // Create a new array for the user if necessary. if (!isset(self::$discussioncache[$userid])) { - self::$discussioncache[$userid] = array(); + self::$discussioncache[$userid] = []; } // Create a new array for the moodleoverflow if necessary. if (!isset(self::$discussioncache[$userid][$moodleoverflowid])) { - self::$discussioncache[$userid][$moodleoverflowid] = array(); + self::$discussioncache[$userid][$moodleoverflowid] = []; } // Save the users preference for that discussion in this array. @@ -356,7 +359,7 @@ public static function subscription_disabled($moodleoverflow) { * Checks wheter the specified moodleoverflow can be subscribed to. * * @param object $moodleoverflow The moodleoverflow ID - * @param \context_module $context The module context. + * @param context_module $context The module context. * * @return boolean */ @@ -390,7 +393,7 @@ public static function set_subscription_mode($moodleoverflowid, $status = 1) { global $DB; // Change the value in the database. - return $DB->set_field('moodleoverflow', 'forcesubscribe', $status, array('id' => $moodleoverflowid)); + return $DB->set_field('moodleoverflow', 'forcesubscribe', $status, ['id' => $moodleoverflowid]); } /** @@ -415,11 +418,11 @@ public static function get_unsubscribable_moodleoverflows() { // Get courses that the current user is enrolled to. $courses = enrol_get_my_courses(); if (empty($courses)) { - return array(); + return []; } // Get the IDs of all that courses. - $courseids = array(); + $courseids = []; foreach ($courses as $course) { $courseids[] = $course->id; } @@ -436,14 +439,15 @@ public static function get_unsubscribable_moodleoverflows() { JOIN {modules} mo ON mo.name = :modulename AND mo.id = cm.module LEFT JOIN {moodleoverflow_subscriptions} ms ON (ms.moodleoverflow = m.id AND ms.userid = :userid) WHERE m.forcesubscribe <> :forcesubscribe AND ms.id IS NOT NULL AND cm.course $coursesql"; - $params = array('modulename' => 'moodleoverflow', - 'userid' => $USER->id, - 'forcesubscribe' => MOODLEOVERFLOW_FORCESUBSCRIBE); + $params = ['modulename' => 'moodleoverflow', + 'userid' => $USER->id, + 'forcesubscribe' => MOODLEOVERFLOW_FORCESUBSCRIBE, + ]; $mergedparams = array_merge($courseparams, $params); $moodleoverflows = $DB->get_recordset_sql($sql, $mergedparams); // Loop through all of the results and add them to an array. - $unsubscribablemoodleoverflows = array(); + $unsubscribablemoodleoverflows = []; foreach ($moodleoverflows as $moodleoverflow) { $unsubscribablemoodleoverflows[] = $moodleoverflow; } @@ -456,7 +460,7 @@ public static function get_unsubscribable_moodleoverflows() { /** * Get the list of potential subscribers to a moodleoverflow. * - * @param \context_module $context The moodleoverflow context. + * @param context_module $context The moodleoverflow context. * @param string $fields The list of fields to return for each user. * @param string $sort Sort order. * @@ -494,7 +498,7 @@ public static function fill_subscription_cache_for_course($courseid, $userid) { // Create an array for the user if necessary. if (!isset(self::$moodleoverflowcache[$userid])) { - self::$moodleoverflowcache[$userid] = array(); + self::$moodleoverflowcache[$userid] = []; } // Fetch a record set for all moodleoverflowids and their subscription id. @@ -502,11 +506,11 @@ public static function fill_subscription_cache_for_course($courseid, $userid) { FROM {moodleoverflow} m LEFT JOIN {moodleoverflow_subscriptions} s ON (s.moodleoverflow = m.id AND s.userid = :userid) WHERE m.course = :course AND m.forcesubscribe <> :subscriptionforced"; - $params = array( + $params = [ 'userid' => $userid, 'course' => $courseid, 'subscriptionforced' => MOODLEOVERFLOW_FORCESUBSCRIBE, - ); + ]; $subscriptions = $DB->get_recordset_sql($sql, $params); // Loop through all records. @@ -522,7 +526,7 @@ public static function fill_subscription_cache_for_course($courseid, $userid) { * Returns a list of user object who are subscribed to this moodleoverflow. * * @param stdClass $moodleoverflow The moodleoverflow record - * @param \context_module $context The moodleoverflow context + * @param context_module $context The moodleoverflow context * @param string $fields Requested user fields * @param boolean $includediscussions Whether to take discussion subscriptions into consideration * @@ -616,10 +620,10 @@ public static function get_subscribed_users($moodleoverflow, $context, $fields = public static function reset_discussion_cache() { // Reset the discussion cache. - self::$discussioncache = array(); + self::$discussioncache = []; // Reset the fetched discussions. - self::$fetcheddiscussions = array(); + self::$fetcheddiscussions = []; } /** @@ -631,18 +635,18 @@ public static function reset_discussion_cache() { public static function reset_moodleoverflow_cache() { // Reset the cache. - self::$moodleoverflowcache = array(); + self::$moodleoverflowcache = []; // Reset the fetched moodleoverflows. - self::$fetchedmoodleoverflows = array(); + self::$fetchedmoodleoverflows = []; } /** * Adds user to the subscriber list. * * @param int $userid The user ID - * @param \stdClass $moodleoverflow The moodleoverflow record - * @param \context_module $context The module context + * @param stdClass $moodleoverflow The moodleoverflow record + * @param context_module $context The module context * @param bool $userrequest Whether the user requested this change themselves. * * @return bool|int Returns true if the user is already subscribed or the subscription id if successfully subscribed. @@ -656,7 +660,7 @@ public static function subscribe_user($userid, $moodleoverflow, $context, $userr } // Create a new subscription object. - $sub = new \stdClass(); + $sub = new stdClass(); $sub->userid = $userid; $sub->moodleoverflow = $moodleoverflow->id; @@ -667,10 +671,10 @@ public static function subscribe_user($userid, $moodleoverflow, $context, $userr if ($userrequest) { // Delete all those discussion subscriptions. - $params = array( - 'userid' => $userid, - 'moodleoverflowid' => $moodleoverflow->id, - 'preference' => self::MOODLEOVERFLOW_DISCUSSION_UNSUBSCRIBED); + $params = ['userid' => $userid, + 'moodleoverflowid' => $moodleoverflow->id, + 'preference' => self::MOODLEOVERFLOW_DISCUSSION_UNSUBSCRIBED, + ]; $where = 'userid = :userid AND moodleoverflow = :moodleoverflowid AND preference <> :preference'; $DB->delete_records_select('moodleoverflow_discuss_subs', $where, $params); @@ -689,12 +693,12 @@ public static function subscribe_user($userid, $moodleoverflow, $context, $userr self::$moodleoverflowcache[$userid][$moodleoverflow->id] = true; // Trigger an subscription created event. - $params = array( + $params = [ 'context' => $context, 'objectid' => $result, 'relateduserid' => $userid, - 'other' => array('moodleoverflowid' => $moodleoverflow->id), - ); + 'other' => ['moodleoverflowid' => $moodleoverflow->id], + ]; $event = event\subscription_created::create($params); $event->trigger(); @@ -706,8 +710,8 @@ public static function subscribe_user($userid, $moodleoverflow, $context, $userr * Removes user from the subscriber list. * * @param int $userid The user ID. - * @param \stdClass $moodleoverflow The moodleoverflow record - * @param \context_module $context The module context + * @param stdClass $moodleoverflow The moodleoverflow record + * @param context_module $context The module context * @param boolean $userrequest Whether the user requested this change themselves. * * @return bool Always returns true @@ -716,26 +720,26 @@ public static function unsubscribe_user($userid, $moodleoverflow, $context, $use global $DB; // Check if there is a subscription record. - $params = array('userid' => $userid, 'moodleoverflow' => $moodleoverflow->id); + $params = ['userid' => $userid, 'moodleoverflow' => $moodleoverflow->id]; if ($subscription = $DB->get_record('moodleoverflow_subscriptions', $params)) { // Delete this record. - $DB->delete_records('moodleoverflow_subscriptions', array('id' => $subscription->id)); + $DB->delete_records('moodleoverflow_subscriptions', ['id' => $subscription->id]); // Was the unsubscription requested by the user? if ($userrequest) { // Delete the discussion subscriptions as well. - $params = array( + $params = [ 'userid' => $userid, 'moodleoverflow' => $moodleoverflow->id, 'preference' => self::MOODLEOVERFLOW_DISCUSSION_UNSUBSCRIBED, - ); + ]; $DB->delete_records('moodleoverflow_discuss_subs', $params); // Update the discussion cache. if (isset(self::$discussioncache[$userid]) && isset(self::$discussioncache[$userid][$moodleoverflow->id])) { - self::$discussioncache[$userid][$moodleoverflow->id] = array(); + self::$discussioncache[$userid][$moodleoverflow->id] = []; } } @@ -743,12 +747,12 @@ public static function unsubscribe_user($userid, $moodleoverflow, $context, $use self::$moodleoverflowcache[$userid][$moodleoverflow->id] = false; // Trigger an subscription deletion event. - $params = array( + $params = [ 'context' => $context, 'objectid' => $subscription->id, 'relateduserid' => $userid, - 'other' => array('moodleoverflowid' => $moodleoverflow->id), - ); + 'other' => ['moodleoverflowid' => $moodleoverflow->id], + ]; $event = event\subscription_deleted::create($params); $event->add_record_snapshot('moodleoverflow_subscriptions', $subscription); $event->trigger(); @@ -763,8 +767,8 @@ public static function unsubscribe_user($userid, $moodleoverflow, $context, $use * * TODO: Refactor this function to the new way of working with discussion and posts. * @param int $userid The user ID - * @param \stdClass $discussion The discussion record - * @param \context_module $context The module context + * @param stdClass $discussion The discussion record + * @param context_module $context The module context * * @return bool Whether a change was made */ @@ -772,7 +776,7 @@ public static function subscribe_user_to_discussion($userid, $discussion, $conte global $DB; // Check if the user is already subscribed to the discussion. - $params = array('userid' => $userid, 'discussion' => $discussion->id); + $params = ['userid' => $userid, 'discussion' => $discussion->id]; $subscription = $DB->get_record('moodleoverflow_discuss_subs', $params); // Dont continue if the user is already subscribed. @@ -781,14 +785,14 @@ public static function subscribe_user_to_discussion($userid, $discussion, $conte } // Check if the user is already subscribed to the moodleoverflow. - $params = array('userid' => $userid, 'moodleoverflow' => $discussion->moodleoverflow); + $params = ['userid' => $userid, 'moodleoverflow' => $discussion->moodleoverflow]; if ($DB->record_exists('moodleoverflow_subscriptions', $params)) { // Check if the user is unsubscribed from the discussion. if ($subscription && $subscription->preference == self::MOODLEOVERFLOW_DISCUSSION_UNSUBSCRIBED) { // Delete the discussion preference. - $DB->delete_records('moodleoverflow_discuss_subs', array('id' => $subscription->id)); + $DB->delete_records('moodleoverflow_discuss_subs', ['id' => $subscription->id]); unset(self::$discussioncache[$userid][$discussion->moodleoverflow][$discussion->id]); } else { @@ -808,7 +812,7 @@ public static function subscribe_user_to_discussion($userid, $discussion, $conte } else { // Else a new record needs to be created. - $subscription = new \stdClass(); + $subscription = new stdClass(); $subscription->userid = $userid; $subscription->moodleoverflow = $discussion->moodleoverflow; $subscription->discussion = $discussion->id; @@ -821,12 +825,12 @@ public static function subscribe_user_to_discussion($userid, $discussion, $conte } // Create a discussion subscription created event. - $params = array( + $params = [ 'context' => $context, 'objectid' => $subscription->id, 'relateduserid' => $userid, - 'other' => array('moodleoverflowid' => $discussion->moodleoverflow, 'discussion' => $discussion->id), - ); + 'other' => ['moodleoverflowid' => $discussion->moodleoverflow, 'discussion' => $discussion->id], + ]; $event = event\discussion_subscription_created::create($params); $event->trigger(); @@ -837,9 +841,9 @@ public static function subscribe_user_to_discussion($userid, $discussion, $conte /** * Unsubscribes the user from the specified discussion. * - * @param int $userid The user ID - * @param \stdClass $discussion The discussion record - * @param \context_module $context The context module + * @param int $userid The user ID + * @param stdClass $discussion The discussion record + * @param context_module $context The context module * * @return bool Whether a change was made */ @@ -847,7 +851,7 @@ public static function unsubscribe_user_from_discussion($userid, $discussion, $c global $DB; // Check the users subscription preference for this discussion. - $params = array('userid' => $userid, 'discussion' => $discussion->id); + $params = ['userid' => $userid, 'discussion' => $discussion->id]; $subscription = $DB->get_record('moodleoverflow_discuss_subs', $params); // If the user not already subscribed to the discussion, do not continue. @@ -856,14 +860,14 @@ public static function unsubscribe_user_from_discussion($userid, $discussion, $c } // Check if the user is subscribed to the moodleoverflow. - $params = array('userid' => $userid, 'moodleoverflow' => $discussion->moodleoverflow); + $params = ['userid' => $userid, 'moodleoverflow' => $discussion->moodleoverflow]; if (!$DB->record_exists('moodleoverflow_subscriptions', $params)) { // Check if the user isn't subscribed to the moodleoverflow. if ($subscription && $subscription->preference != self::MOODLEOVERFLOW_DISCUSSION_UNSUBSCRIBED) { // Delete the discussion subscription. - $DB->delete_records('moodleoverflow_discuss_subs', array('id' => $subscription->id)); + $DB->delete_records('moodleoverflow_discuss_subs', ['id' => $subscription->id]); unset(self::$discussioncache[$userid][$discussion->moodleoverflow][$discussion->id]); } else { @@ -887,7 +891,7 @@ public static function unsubscribe_user_from_discussion($userid, $discussion, $c // There is no record. // Create a new discussion subscription record. - $subscription = new \stdClass(); + $subscription = new stdClass(); $subscription->userid = $userid; $subscription->moodleoverflow = $discussion->moodleoverflow; $subscription->discussion = $discussion->id; @@ -902,12 +906,12 @@ public static function unsubscribe_user_from_discussion($userid, $discussion, $c } // Trigger an discussion subscription deletetion event. - $params = array( + $params = [ 'context' => $context, 'objectid' => $subscription->id, 'relateduserid' => $userid, - 'other' => array('moodleoverflowid' => $discussion->moodleoverflow, 'discussion' => $discussion->id), - ); + 'other' => ['moodleoverflowid' => $discussion->moodleoverflow, 'discussion' => $discussion->id], + ]; $event = event\discussion_subscription_deleted::create($params); $event->trigger(); @@ -927,16 +931,16 @@ public static function unsubscribe_user_from_discussion($userid, $discussion, $c * * @return string */ - public static function moodleoverflow_get_subscribe_link($moodleoverflow, $context, $messages = array()) { + public static function moodleoverflow_get_subscribe_link($moodleoverflow, $context, $messages = []) { global $USER, $OUTPUT; // Define strings. - $defaultmessages = array( + $defaultmessages = [ 'subscribed' => get_string('unsubscribe', 'moodleoverflow'), 'unsubscribed' => get_string('subscribe', 'moodleoverflow'), 'forcesubscribed' => get_string('everyoneissubscribed', 'moodleoverflow'), 'cantsubscribe' => get_string('disallowsubscribe', 'moodleoverflow'), - ); + ]; // Combine strings the submitted messages. $messages = $messages + $defaultmessages; @@ -970,7 +974,7 @@ public static function moodleoverflow_get_subscribe_link($moodleoverflow, $conte } // Create an options array. - $options = array(); + $options = []; $options['id'] = $moodleoverflow->id; $options['sesskey'] = sesskey(); $options['returnurl'] = 0; @@ -979,7 +983,7 @@ public static function moodleoverflow_get_subscribe_link($moodleoverflow, $conte // Return the link to subscribe the user. $url = new \moodle_url('/mod/moodleoverflow/subscribe.php', $options); - return $OUTPUT->single_button($url, $linktext, 'get', array('title' => $linktitle)); + return $OUTPUT->single_button($url, $linktext, 'get', ['title' => $linktitle]); } } @@ -988,9 +992,9 @@ public static function moodleoverflow_get_subscribe_link($moodleoverflow, $conte * * TODO: Refactor this function to the new way of working with discussion and posts. * @param object $fromform The submitted form - * @param \stdClass $moodleoverflow The moodleoverflow record - * @param \stdClass $discussion The discussion record - * @param \context_module $modulecontext The context of the module + * @param stdClass $moodleoverflow The moodleoverflow record + * @param stdClass $discussion The discussion record + * @param context_module $modulecontext The context of the module * * @return bool */ @@ -1046,12 +1050,12 @@ public static function get_discussion_subscription_icon($moodleoverflow, $contex $status = self::is_subscribed($USER->id, $moodleoverflow, $context, $discussionid); // Create a link to subscribe or unsubscribe to the discussion. - $array = array( + $array = [ 'sesskey' => sesskey(), 'id' => $moodleoverflow->id, 'd' => $discussionid, 'returnurl' => $returnurl, - ); + ]; $subscriptionlink = new \moodle_url('/mod/moodleoverflow/subscribe.php', $array); // Create an icon to unsubscribe. @@ -1062,13 +1066,13 @@ public static function get_discussion_subscription_icon($moodleoverflow, $contex $output = $OUTPUT->pix_icon('i/subscribed', $string, 'mod_moodleoverflow'); // Return the link. - $array = array( + $array = [ 'title' => get_string('clicktounsubscribe', 'moodleoverflow'), 'class' => 'discussiontoggle text-muted', 'data-moodleoverflowid' => $moodleoverflow->id, 'data-discussionid' => $discussionid, 'data-includetext' => false, - ); + ]; return \html_writer::link($subscriptionlink, $output, $array); } @@ -1078,13 +1082,13 @@ public static function get_discussion_subscription_icon($moodleoverflow, $contex $output = $OUTPUT->pix_icon('i/unsubscribed', $string, 'mod_moodleoverflow'); // Return the link. - $array = array( + $array = [ 'title' => get_string('clicktosubscribe', 'moodleoverflow'), 'class' => 'discussiontoggle text-muted', 'data-moodleoverflowid' => $moodleoverflow->id, 'data-discussionid' => $discussionid, 'data-includetext' => false, - ); + ]; return \html_writer::link($subscriptionlink, $output, $array); } diff --git a/classes/tables/userstats_table.php b/classes/tables/userstats_table.php index 1c1e9a24a4..5b439420d4 100644 --- a/classes/tables/userstats_table.php +++ b/classes/tables/userstats_table.php @@ -45,7 +45,7 @@ class userstats_table extends \flexible_table { private $moodleoverflowid; /** @var array table that will have objects with every user and his statistics. */ - private $userstatsdata = array(); + private $userstatsdata = []; /** @var \stdClass Help icon for amountofactivity-column.*/ private $helpactivity; @@ -75,7 +75,7 @@ public function __construct($uniqueid, $courseid, $moodleoverflow, $url) { 'forumactivity', 'courseactivity', 'forumreputation', - 'coursereputation']); + 'coursereputation', ]); $this->define_baseurl($url); $this->define_headers([get_string('fullnameuser'), get_string('userstatsupvotes', 'moodleoverflow'), @@ -83,7 +83,7 @@ public function __construct($uniqueid, $courseid, $moodleoverflow, $url) { (get_string('userstatsforumactivity', 'moodleoverflow') . $this->helpactivity->object), (get_string('userstatscourseactivity', 'moodleoverflow') . $this->helpactivity->object), get_string('userstatsforumreputation', 'moodleoverflow'), - get_string('userstatscoursereputation', 'moodleoverflow')]); + get_string('userstatscoursereputation', 'moodleoverflow'), ]); $this->get_table_data(); $this->sortable(true, 'coursereputation', SORT_DESC); $this->no_sorting('username'); @@ -267,17 +267,17 @@ public function set_helpactivity() { $this->helpactivity->icon = \html_writer::img($this->helpactivity->iconurl, get_string('helpamountofactivity', 'moodleoverflow')); $this->helpactivity->class = 'helpactivityclass btn btn-link'; - $this->helpactivity->iconattributes = array('role' => 'button', - 'data-container' => 'body', - 'data-toggle' => 'popover', - 'data-placement' => 'right', - 'data-action' => 'showhelpicon', - 'data-html' => 'true', - 'data-trigger' => 'focus', - 'tabindex' => '0', - 'data-content' => '

' . - get_string('helpamountofactivity', 'moodleoverflow') . - '

'); + $this->helpactivity->iconattributes = ['role' => 'button', + 'data-container' => 'body', + 'data-toggle' => 'popover', + 'data-placement' => 'right', + 'data-action' => 'showhelpicon', + 'data-html' => 'true', + 'data-trigger' => 'focus', + 'tabindex' => '0', + 'data-content' => '

' . + get_string('helpamountofactivity', 'moodleoverflow') . + '

', ]; $this->helpactivity->object = \html_writer::span($this->helpactivity->icon, $this->helpactivity->class, @@ -381,10 +381,10 @@ private function createstudent($user) { $student = new \stdClass(); $student->id = $user->id; $student->name = $user->firstname . ' ' . $user->lastname; - $linktostudent = new \moodle_url('/user/view.php', array('id' => $student->id, 'course' => $this->courseid)); + $linktostudent = new \moodle_url('/user/view.php', ['id' => $student->id, 'course' => $this->courseid]); $student->link = \html_writer::link($linktostudent->out(), $student->name); - $student->submittedposts = array(); // Posts written by the student. Key = postid, Value = postid. - $student->ratedposts = array(); // Posts that the student rated. Key = rateid, Value = rateid. + $student->submittedposts = []; // Posts written by the student. Key = postid, Value = postid. + $student->ratedposts = []; // Posts that the student rated. Key = rateid, Value = rateid. $student->receivedupvotes = 0; $student->receiveddownvotes = 0; $student->forumactivity = 0; // Number of written posts and submitted ratings in the current moodleoverflow. diff --git a/classes/task/send_daily_mail.php b/classes/task/send_daily_mail.php index 7c2fa1cda9..48ac7a67b2 100644 --- a/classes/task/send_daily_mail.php +++ b/classes/task/send_daily_mail.php @@ -52,20 +52,20 @@ public function execute() { // Go through each user that has unread posts. foreach ($users as $user) { // Sorts the records with "Order by courseid". - $userdata = $DB->get_records('moodleoverflow_mail_info', array('userid' => $user->userid), 'courseid, forumid'); - $mail = array(); + $userdata = $DB->get_records('moodleoverflow_mail_info', ['userid' => $user->userid], 'courseid, forumid'); + $mail = []; // Fill the $mail array. foreach ($userdata as $row) { - $currentcourse = $DB->get_record('course', array('id' => $row->courseid), 'fullname, id'); - $currentforum = $DB->get_record('moodleoverflow', array('id' => $row->forumid), 'name, id'); + $currentcourse = $DB->get_record('course', ['id' => $row->courseid], 'fullname, id'); + $currentforum = $DB->get_record('moodleoverflow', ['id' => $row->forumid], 'name, id'); $coursemoduleid = get_coursemodule_from_instance('moodleoverflow', $row->forumid); - $discussion = $DB->get_record('moodleoverflow_discussions', array('id' => $row->forumdiscussionid), 'name, id'); + $discussion = $DB->get_record('moodleoverflow_discussions', ['id' => $row->forumdiscussionid], 'name, id'); $unreadposts = $row->numberofposts; // Build url to the course, forum, and discussion. - $linktocourse = new \moodle_url('/course/view.php', array('id' => $currentcourse->id)); - $linktoforum = new \moodle_url('/mod/moodleoverflow/view.php', array('id' => $coursemoduleid->id)); - $linktodiscussion = new \moodle_url('/mod/moodleoverflow/discussion.php', array('d' => $discussion->id)); + $linktocourse = new \moodle_url('/course/view.php', ['id' => $currentcourse->id]); + $linktoforum = new \moodle_url('/mod/moodleoverflow/view.php', ['id' => $coursemoduleid->id]); + $linktodiscussion = new \moodle_url('/mod/moodleoverflow/discussion.php', ['d' => $discussion->id]); // Now change the url to a clickable html link. $linktocourse = \html_writer::link($linktocourse->out(), $currentcourse->fullname); @@ -73,19 +73,19 @@ public function execute() { $linktodiscussion = \html_writer::link($linktodiscussion->out(), $discussion->name); // Build a single line string with the digest information and add it to the mailarray. - $string = get_string('digestunreadpost', 'mod_moodleoverflow', array('linktocourse' => $linktocourse, + $string = get_string('digestunreadpost', 'mod_moodleoverflow', ['linktocourse' => $linktocourse, 'linktoforum' => $linktoforum, 'linktodiscussion' => $linktodiscussion, - 'unreadposts' => $unreadposts)); + 'unreadposts' => $unreadposts, ]); array_push($mail, $string); } // Build the final message and send it to user. Then remove the sent records. $message = implode('
', $mail); - $userto = $DB->get_record('user', array('id' => $user->userid)); + $userto = $DB->get_record('user', ['id' => $user->userid]); $from = \core_user::get_noreply_user(); $subject = get_string('tasksenddailymail', 'mod_moodleoverflow'); email_to_user($userto, $from, $subject, $message); - $DB->delete_records('moodleoverflow_mail_info', array('userid' => $user->userid)); + $DB->delete_records('moodleoverflow_mail_info', ['userid' => $user->userid]); } } } diff --git a/classes/task/send_mails.php b/classes/task/send_mails.php index 268774bc29..310bbc5f88 100644 --- a/classes/task/send_mails.php +++ b/classes/task/send_mails.php @@ -79,7 +79,7 @@ public function send_review_notifications() { "ORDER BY d.course, d.moodleoverflow, d.id", [ 'mailpending' => MOODLEOVERFLOW_MAILED_PENDING, - 'timecutoff' => time() - get_config('moodleoverflow', 'reviewpossibleaftertime') + 'timecutoff' => time() - get_config('moodleoverflow', 'reviewpossibleaftertime'), ] ); @@ -109,7 +109,7 @@ public function send_review_notifications() { $userswithcapability = get_users_by_capability($modulecontext, 'mod/moodleoverflow:reviewpost'); $coursecontext = \context_course::instance($course->id); $usersenrolled = get_enrolled_users($coursecontext); - $usersto = array(); + $usersto = []; foreach ($userswithcapability as $user) { if (in_array($user, $usersenrolled)) { array_push($usersto, $user); diff --git a/db/access.php b/db/access.php index bf56c9400f..1ea6074738 100644 --- a/db/access.php +++ b/db/access.php @@ -22,7 +22,7 @@ * the module version number should be bumped up. * * The system has four possible values for a capability: - * CAP_ALLOW, CAP_PREVENT, CAP_PROHIBIT, and inherit (not set). + * CAP_ALLOW, CAP_PREVENT, CAP_PROHIBIT, and inherit (not set]. * * It is important that capability names are unique. The naming convention * for capabilities that are specific to modules and blocks is as follows: @@ -47,181 +47,181 @@ defined('MOODLE_INTERNAL') || die(); // Modify capabilities as needed and remove this comment. -$capabilities = array( - 'mod/moodleoverflow:addinstance' => array( +$capabilities = [ + 'mod/moodleoverflow:addinstance' => [ 'riskbitmask' => RISK_XSS, 'captype' => 'write', 'contextlevel' => CONTEXT_COURSE, - 'archetypes' => array( + 'archetypes' => [ 'editingteacher' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ), - 'clonepermissionsfrom' => 'moodle/course:manageactivities' - ), - 'mod/moodleoverflow:viewdiscussion' => array( + 'manager' => CAP_ALLOW, + ], + 'clonepermissionsfrom' => 'moodle/course:manageactivities', + ], + 'mod/moodleoverflow:viewdiscussion' => [ 'captype' => 'read', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'frontpage' => CAP_ALLOW, 'guest' => CAP_ALLOW, 'student' => CAP_ALLOW, 'teacher' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ), - 'clonepermissionsfrom' => 'mod/forum:viewdiscussion' - ), + 'manager' => CAP_ALLOW, + ], + 'clonepermissionsfrom' => 'mod/forum:viewdiscussion', + ], - 'mod/moodleoverflow:replypost' => array( + 'mod/moodleoverflow:replypost' => [ 'riskbitmask' => RISK_SPAM, 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'student' => CAP_ALLOW, 'teacher' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ), - 'clonepermissionsfrom' => 'mod/forum:replypost' - ), + 'manager' => CAP_ALLOW, + ], + 'clonepermissionsfrom' => 'mod/forum:replypost', + ], - 'mod/moodleoverflow:startdiscussion' => array( + 'mod/moodleoverflow:startdiscussion' => [ 'riskbitmask' => RISK_SPAM, 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'student' => CAP_ALLOW, 'teacher' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ), - 'clonepermissionsfrom' => 'mod/forum:startdiscussion' - ), + 'manager' => CAP_ALLOW, + ], + 'clonepermissionsfrom' => 'mod/forum:startdiscussion', + ], - 'mod/moodleoverflow:editanypost' => array( + 'mod/moodleoverflow:editanypost' => [ 'riskbitmask' => RISK_SPAM, 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'teacher' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ), - 'clonepermissionsfrom' => 'mod/forum:editanypost' - ), + 'manager' => CAP_ALLOW, + ], + 'clonepermissionsfrom' => 'mod/forum:editanypost', + ], - 'mod/moodleoverflow:deleteownpost' => array( + 'mod/moodleoverflow:deleteownpost' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'student' => CAP_ALLOW, 'teacher' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ), - 'clonepermissionsfrom' => 'mod/forum:deleteownpost' - ), + 'manager' => CAP_ALLOW, + ], + 'clonepermissionsfrom' => 'mod/forum:deleteownpost', + ], - 'mod/moodleoverflow:deleteanypost' => array( + 'mod/moodleoverflow:deleteanypost' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'teacher' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ), - 'clonepermissionsfrom' => 'mod/forum:deleteanypost' - ), - 'mod/moodleoverflow:ratepost' => array( + 'manager' => CAP_ALLOW, + ], + 'clonepermissionsfrom' => 'mod/forum:deleteanypost', + ], + 'mod/moodleoverflow:ratepost' => [ 'riskbitmask' => RISK_SPAM, 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'student' => CAP_ALLOW, 'teacher' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ) - ), + 'manager' => CAP_ALLOW, + ], + ], - 'mod/moodleoverflow:marksolved' => array( + 'mod/moodleoverflow:marksolved' => [ 'riskbitmask' => RISK_SPAM, 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'student' => CAP_PROHIBIT, 'teacher' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ) - ), + 'manager' => CAP_ALLOW, + ], + ], - 'mod/moodleoverflow:managesubscriptions' => array( + 'mod/moodleoverflow:managesubscriptions' => [ 'riskbitmask' => RISK_SPAM, 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'teacher' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ), - 'clonepermissionsfrom' => 'mod/forum:managesubscriptions' - ), + 'manager' => CAP_ALLOW, + ], + 'clonepermissionsfrom' => 'mod/forum:managesubscriptions', + ], - 'mod/moodleoverflow:allowforcesubscribe' => array( + 'mod/moodleoverflow:allowforcesubscribe' => [ 'captype' => 'read', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'student' => CAP_ALLOW, 'teacher' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW, - 'frontpage' => CAP_ALLOW - ), - 'clonepermissionsfrom' => 'mod/forum:allowforcesubscribe' - ), + 'frontpage' => CAP_ALLOW, + ], + 'clonepermissionsfrom' => 'mod/forum:allowforcesubscribe', + ], - 'mod/moodleoverflow:createattachment' => array( + 'mod/moodleoverflow:createattachment' => [ 'riskbitmask' => RISK_SPAM, 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'student' => CAP_ALLOW, 'teacher' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ), - 'clonepermissionsfrom' => 'mod/forum:createattachment' - ), + 'manager' => CAP_ALLOW, + ], + 'clonepermissionsfrom' => 'mod/forum:createattachment', + ], - 'mod/moodleoverflow:reviewpost' => array( + 'mod/moodleoverflow:reviewpost' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'teacher' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW, - ), - ), + ], + ], - 'mod/moodleoverflow:movetopic' => array( + 'mod/moodleoverflow:movetopic' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'teacher' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ), - ), + 'manager' => CAP_ALLOW, + ], + ], - 'mod/moodleoverflow:viewanyrating' => array( + 'mod/moodleoverflow:viewanyrating' => [ 'riskbitmask' => RISK_PERSONAL, 'captype' => 'read', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'teacher' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ), - 'clonepermissionsfrom' => 'mod/forum:viewanyrating' - ), + 'manager' => CAP_ALLOW, + ], + 'clonepermissionsfrom' => 'mod/forum:viewanyrating', + ], -); +]; diff --git a/db/events.php b/db/events.php index 77c3f0c3ec..73679479db 100644 --- a/db/events.php +++ b/db/events.php @@ -24,24 +24,24 @@ defined('MOODLE_INTERNAL') || die(); -$observers = array( +$observers = [ // Delete read records and subscriptions if the user is not anymore enrolled. - array( + [ 'eventname' => '\core\event\user_enrolment_deleted', 'callback' => 'mod_moodleoverflow_observer::user_enrolment_deleted', - ), + ], // Subscribe the user to moodleoverflows which force him to when enroling a user. - array( + [ 'eventname' => '\core\event\role_assigned', 'callback' => 'mod_moodleoverflow_observer::role_assigned', - ), + ], // Subscribe the user to moodleoverflows which force him to when creating an instance. - array( + [ 'eventname' => '\core\event\course_module_created', 'callback' => 'mod_moodleoverflow_observer::course_module_created', - ), + ], -); +]; diff --git a/db/messages.php b/db/messages.php index c03df6a673..ee2af9a367 100644 --- a/db/messages.php +++ b/db/messages.php @@ -24,8 +24,7 @@ defined('MOODLE_INTERNAL') || die(); -$messageproviders = array( - +$messageproviders = [ // Ordinary single moodleoverflow posts. - 'posts' => array(), -); + 'posts' => [], +]; diff --git a/db/services.php b/db/services.php index 1069519912..d2737001d5 100644 --- a/db/services.php +++ b/db/services.php @@ -24,30 +24,30 @@ */ defined('MOODLE_INTERNAL') || die; -$functions = array( - 'mod_moodleoverflow_record_vote' => array( +$functions = [ + 'mod_moodleoverflow_record_vote' => [ 'classname' => 'mod_moodleoverflow_external', 'methodname' => 'record_vote', 'classpath' => 'mod/moodleoverflow/externallib.php', 'description' => 'Records a vote and updates the reputation of a user', 'type' => 'write', 'ajax' => true, - 'capabilities' => 'mod/moodleoverflow:ratepost' - ), - 'mod_moodleoverflow_review_approve_post' => array( + 'capabilities' => 'mod/moodleoverflow:ratepost', + ], + 'mod_moodleoverflow_review_approve_post' => [ 'classname' => 'mod_moodleoverflow_external', 'methodname' => 'review_approve_post', 'classpath' => 'mod/moodleoverflow/externallib.php', 'description' => 'Approves a post', 'type' => 'write', 'ajax' => true, - ), - 'mod_moodleoverflow_review_reject_post' => array( + ], + 'mod_moodleoverflow_review_reject_post' => [ 'classname' => 'mod_moodleoverflow_external', 'methodname' => 'review_reject_post', 'classpath' => 'mod/moodleoverflow/externallib.php', 'description' => 'Rejects a post', 'type' => 'write', 'ajax' => true, - ), -); + ], +]; diff --git a/db/tasks.php b/db/tasks.php index d7ecba65b4..0a688b84f5 100644 --- a/db/tasks.php +++ b/db/tasks.php @@ -24,38 +24,38 @@ defined('MOODLE_INTERNAL') || die(); -$tasks = array( +$tasks = [ // Deliver mail notification about new posts. - array( + [ 'classname' => 'mod_moodleoverflow\task\send_mails', 'blocking' => 0, 'minute' => '*', 'hour' => '*', 'day' => '*', 'month' => '*', - 'dayofweek' => '*' - ), + 'dayofweek' => '*', + ], // Clean old read records. - array( + [ 'classname' => 'mod_moodleoverflow\task\clean_readrecords', 'blocking' => 0, 'minute' => '*', 'hour' => '*', 'day' => '*', 'month' => '*', - 'dayofweek' => '*' - ), + 'dayofweek' => '*', + ], // Clean old read records. - array( + [ 'classname' => 'mod_moodleoverflow\task\send_daily_mail', 'blocking' => 0, 'minute' => '0', 'hour' => '17', 'day' => '*', 'month' => '*', - 'dayofweek' => '*' - ) -); + 'dayofweek' => '*', + ], +]; diff --git a/db/upgrade.php b/db/upgrade.php index eb31018162..71c9471433 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -94,8 +94,8 @@ function xmldb_moodleoverflow_upgrade($oldversion) { $table->add_field('grade', XMLDB_TYPE_FLOAT, '10', null, XMLDB_NOTNULL, null, '0'); // Adding keys to table moodleoverflow_grades. - $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); - $table->add_key('moodleoverflowid', XMLDB_KEY_FOREIGN, array('moodleoverflowid'), 'moodleoverflow', array('id')); + $table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']); + $table->add_key('moodleoverflowid', XMLDB_KEY_FOREIGN, ['moodleoverflowid'], 'moodleoverflow', ['id']); // Conditionally launch create table for moodleoverflow_grades. if (!$dbman->table_exists($table)) { @@ -260,12 +260,11 @@ function xmldb_moodleoverflow_upgrade($oldversion) { $table->add_field('forumdiscussionid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); $table->add_field('numberofposts', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); - $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); - $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id')); - $table->add_key('courseid', XMLDB_KEY_FOREIGN, array('courseid'), 'course', array('id')); - $table->add_key('forumid', XMLDB_KEY_FOREIGN, array('forumid'), 'moodleoverflow', array('id')); - $table->add_key('forumdiscussionid', XMLDB_KEY_FOREIGN, - array('forumdiscussionid'), 'moodleoverflow_discussions', array('id')); + $table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']); + $table->add_key('userid', XMLDB_KEY_FOREIGN, ['userid'], 'user', ['id']); + $table->add_key('courseid', XMLDB_KEY_FOREIGN, ['courseid'], 'course', ['id']); + $table->add_key('forumid', XMLDB_KEY_FOREIGN, ['forumid'], 'moodleoverflow', ['id']); + $table->add_key('forumdiscussionid', XMLDB_KEY_FOREIGN, ['forumdiscussionid'], 'moodleoverflow_discussions', ['id']); // Conditionally launch create table for moodleoverflow_mail_info. if (!$dbman->table_exists($table)) { diff --git a/discussion.php b/discussion.php index ed07cff8b5..135504a390 100644 --- a/discussion.php +++ b/discussion.php @@ -33,28 +33,28 @@ $ratedpost = optional_param('rp', 0, PARAM_INT); // Set the URL that should be used to return to this page. -$PAGE->set_url('/mod/moodleoverflow/discussion.php', array('d' => $d)); +$PAGE->set_url('/mod/moodleoverflow/discussion.php', ['d' => $d]); // The page should not be large, only pages containing broad tables are usually. $PAGE->add_body_class('limitedwidth'); // Check if the discussion is valid. -if (!$discussion = $DB->get_record('moodleoverflow_discussions', array('id' => $d))) { +if (!$discussion = $DB->get_record('moodleoverflow_discussions', ['id' => $d])) { throw new moodle_exception('invaliddiscussionid', 'moodleoverflow'); } // Check if the related moodleoverflow instance is valid. -if (!$moodleoverflow = $DB->get_record('moodleoverflow', array('id' => $discussion->moodleoverflow))) { +if (!$moodleoverflow = $DB->get_record('moodleoverflow', ['id' => $discussion->moodleoverflow])) { throw new moodle_exception('invalidmoodleoverflowid', 'moodleoverflow'); } // Check if the related moodleoverflow instance is valid. -if (!$course = $DB->get_record('course', array('id' => $discussion->course))) { +if (!$course = $DB->get_record('course', ['id' => $discussion->course])) { throw new moodle_exception('invalidcourseid'); } // Save the allowmultiplemarks setting. -$marksetting = $DB->get_record('moodleoverflow', array('id' => $moodleoverflow->id), 'allowmultiplemarks'); +$marksetting = $DB->get_record('moodleoverflow', ['id' => $moodleoverflow->id], 'allowmultiplemarks'); $multiplemarks = false; if ($marksetting->allowmultiplemarks == 1) { $multiplemarks = true; @@ -81,7 +81,7 @@ if ($ratingid) { require_sesskey(); - if (in_array($ratingid, array(RATING_SOLVED, RATING_REMOVE_SOLVED, RATING_HELPFUL, RATING_REMOVE_HELPFUL))) { + if (in_array($ratingid, [RATING_SOLVED, RATING_REMOVE_SOLVED, RATING_HELPFUL, RATING_REMOVE_HELPFUL])) { // Rate the post. if (!\mod_moodleoverflow\ratings::moodleoverflow_add_rating($moodleoverflow, $ratedpost, $ratingid, $cm)) { throw new moodle_exception('ratingfailed', 'moodleoverflow'); @@ -94,10 +94,10 @@ } // Trigger the discussion viewed event. -$params = array( +$params = [ 'context' => $modulecontext, 'objectid' => $discussion->id, -); +]; $event = \mod_moodleoverflow\event\discussion_viewed::create($params); $event->trigger(); @@ -130,7 +130,7 @@ } $node = $forumnode->add(format_string($discussion->name), - new moodle_url('/mod/moodleoverflow/discussion.php', array('d' => $discussion->id))); + new moodle_url('/mod/moodleoverflow/discussion.php', ['d' => $discussion->id])); $node->display = false; if ($node && ($post->id != $discussion->firstpost)) { $node->add(format_string($post->subject), $PAGE->url); diff --git a/externallib.php b/externallib.php index 22255637cd..c56375b6ed 100644 --- a/externallib.php +++ b/externallib.php @@ -46,25 +46,25 @@ class mod_moodleoverflow_external extends external_api { */ public static function record_vote_parameters() { return new external_function_parameters( - array( + [ 'postid' => new external_value(PARAM_INT, 'id of post'), - 'ratingid' => new external_value(PARAM_INT, 'rating') - ) + 'ratingid' => new external_value(PARAM_INT, 'rating'), + ] ); } /** * Returns the result of the vote (new rating and reputations). - * @return external_multiple_structure + * @return external_single_structure */ public static function record_vote_returns() { return new external_single_structure( - array( + [ 'postrating' => new external_value(PARAM_INT, 'new post rating'), 'ownerreputation' => new external_value(PARAM_INT, 'new reputation of post owner'), 'raterreputation' => new external_value(PARAM_INT, 'new reputation of rater'), 'ownerid' => new external_value(PARAM_INT, 'user id of post owner'), - ) + ] ); } @@ -79,27 +79,27 @@ public static function record_vote($postid, $ratingid) { global $DB, $USER; // Parameter validation. - $params = self::validate_parameters(self::record_vote_parameters(), array( + $params = self::validate_parameters(self::record_vote_parameters(), [ 'postid' => $postid, 'ratingid' => $ratingid, - )); + ]); $transaction = $DB->start_delegated_transaction(); - $post = $DB->get_record('moodleoverflow_posts', array('id' => $params['postid']), '*', MUST_EXIST); + $post = $DB->get_record('moodleoverflow_posts', ['id' => $params['postid']], '*', MUST_EXIST); // Check if the discussion is valid. - if (!$discussion = $DB->get_record('moodleoverflow_discussions', array('id' => $post->discussion))) { + if (!$discussion = $DB->get_record('moodleoverflow_discussions', ['id' => $post->discussion])) { throw new moodle_exception('invaliddiscussionid', 'moodleoverflow'); } // Check if the related moodleoverflow instance is valid. - if (!$moodleoverflow = $DB->get_record('moodleoverflow', array('id' => $discussion->moodleoverflow))) { + if (!$moodleoverflow = $DB->get_record('moodleoverflow', ['id' => $discussion->moodleoverflow])) { throw new moodle_exception('invalidmoodleoverflowid', 'moodleoverflow'); } // Check if the related moodleoverflow instance is valid. - if (!$course = $DB->get_record('course', array('id' => $discussion->course))) { + if (!$course = $DB->get_record('course', ['id' => $discussion->course])) { throw new moodle_exception('invalidcourseid'); } @@ -148,7 +148,7 @@ public static function record_vote($postid, $ratingid) { */ public static function review_approve_post_parameters() { return new external_function_parameters([ - 'postid' => new external_value(PARAM_INT, 'id of post') + 'postid' => new external_value(PARAM_INT, 'id of post'), ]); } @@ -210,7 +210,7 @@ public static function review_approve_post($postid) { public static function review_reject_post_parameters() { return new external_function_parameters([ 'postid' => new external_value(PARAM_INT, 'id of post'), - 'reason' => new external_value(PARAM_RAW, 'reason of rejection') + 'reason' => new external_value(PARAM_RAW, 'reason of rejection'), ]); } diff --git a/index.php b/index.php index 49e454e495..7f5bc9ff7e 100644 --- a/index.php +++ b/index.php @@ -25,6 +25,8 @@ // Require needed files. require_once(dirname(dirname(dirname(__FILE__))) . '/config.php'); require_once(dirname(__FILE__) . '/locallib.php'); + +global $CFG, $USER, $DB, $PAGE, $SESSION, $OUTPUT; require_once($CFG->dirroot . '/course/lib.php'); // Fetch submitted parameters. @@ -32,7 +34,7 @@ $subscribe = optional_param('subscribe', null, PARAM_INT); // Set an url to go back to the page. -$url = new moodle_url('/mod/moodleoverflow/index.php', array('id' => $id)); +$url = new moodle_url('/mod/moodleoverflow/index.php', ['id' => $id]); // Check whether the subscription parameter was set. if ($subscribe !== null) { @@ -44,7 +46,7 @@ $PAGE->set_url($url); // Check if the id is related to a valid course. -if (!$course = $DB->get_record('course', array('id' => $id))) { +if (!$course = $DB->get_record('course', ['id' => $id])) { throw new moodle_exception('invalidcourseid'); } @@ -55,15 +57,13 @@ unset($SESSION->fromdiscussion); // Trigger the course module instace lise viewed evewnt. -$params = array( - 'context' => context_course::instance($course->id) -); +$params = ['context' => context_course::instance($course->id)]; $event = \mod_moodleoverflow\event\course_module_instance_list_viewed::create($params); $event->add_record_snapshot('course', $course); $event->trigger(); // Cache some strings. -$string = array(); +$string = []; $string['moodleoverflow'] = get_string('moodleoverflow', 'moodleoverflow'); $string['moodleoverflows'] = get_string('moodleoverflows', 'moodleoverflow'); $string['modulenameplural'] = get_string('modulenameplural', 'moodleoverflow'); @@ -86,8 +86,8 @@ // Begin to print a table for the general area. $generaltable = new html_table(); -$generaltable->head = array($string['moodleoverflow'], $string['description'], $string['discussions']); -$generaltable->align = array('left', 'left', 'center'); +$generaltable->head = [$string['moodleoverflow'], $string['description'], $string['discussions']]; +$generaltable->align = ['left', 'left', 'center']; // Check whether moodleoverflows can be tracked. $cantrack = \mod_moodleoverflow\readtracking::moodleoverflow_can_track_moodleoverflows(); @@ -111,7 +111,7 @@ // Initiate tables and variables. $table = new html_table(); -$generalmoodleoverflows = array(); +$generalmoodleoverflows = []; $modinfo = get_fast_modinfo($course); $showsubscriptioncolumns = false; @@ -119,7 +119,7 @@ $sql = "SELECT m.* FROM {moodleoverflow} m WHERE m.course = ?"; -$moodleoverflows = $DB->get_records_sql($sql, array($course->id)); +$moodleoverflows = $DB->get_records_sql($sql, [$course->id]); // Loop through allmoodleoverflows. foreach ($modinfo->get_instances_of('moodleoverflow') as $moodleoverflowid => $cm) { @@ -163,7 +163,7 @@ if (isguestuser() || !$showsubscriptioncolumns) { // Redirect the user back. - $url = new moodle_url('/mod/moodleoverflow/index.php', array('id' => $id)); + $url = new moodle_url('/mod/moodleoverflow/index.php', ['id' => $id]); $notification = \core\output\notification::NOTIFY_ERROR; redirect($url, $string['subscribeenrolledonly'], null, $notification); } @@ -210,11 +210,11 @@ } // Create an url to return the user back to. - $url = new moodle_url('/mod/moodleoverflow/index.php', array('id' => $id)); + $url = new moodle_url('/mod/moodleoverflow/index.php', ['id' => $id]); $returnto = moodleoverflow_go_back_to($url); // Prepare the message to be displayed. - $shortname = format_string($course->shortname, true, array('context' => context_course::instance($course->id))); + $shortname = format_string($course->shortname, true, ['context' => context_course::instance($course->id)]); $notification = \core\output\notification::NOTIFY_SUCCESS; // Redirect the user depending on the subscription state. @@ -291,15 +291,15 @@ // Tracking is optional. // Define the url the button is linked to. - $trackingurlparams = array('id' => $moodleoverflow->id, 'sesskey' => sesskey()); + $trackingurlparams = ['id' => $moodleoverflow->id, 'sesskey' => sesskey()]; $trackingurl = new moodle_url('/mod/moodleoverflow/tracking.php', $trackingurlparams); // Check whether the moodleoverflow instance is tracked. if (!isset($untracked[$moodleoverflow->id])) { - $trackingparam = array('title' => $string['notrackmoodleoverflow']); + $trackingparam = ['title' => $string['notrackmoodleoverflow']]; $trackedlink = $OUTPUT->single_button($trackingurl, $string['yes'], 'post', $trackingparam); } else { - $trackingparam = array('title' => $string['trackmoodleoverflow']); + $trackingparam = ['title' => $string['trackmoodleoverflow']]; $trackedlink = $OUTPUT->single_button($trackingurl, $string['no'], 'post', $trackingparam); } } @@ -323,7 +323,7 @@ $discussionlink = "id\" $style>" . $count . ""; // Create rows. - $row = array($moodleoverflowlink, $moodleoverflow->intro, $discussionlink); + $row = [$moodleoverflowlink, $moodleoverflow->intro, $discussionlink]; // Add the tracking information to the rows. if ($cantrack) { @@ -335,12 +335,12 @@ if ($showsubscriptioncolumns) { // Set options to create the subscription link. - $suboptions = array( + $suboptions = [ 'subscribed' => $string['yes'], 'unsubscribed' => $string['no'], 'forcesubscribed' => $string['yes'], 'cantsubscribe' => '-', - ); + ]; // Add the subscription link to the row. $row[] = \mod_moodleoverflow\subscriptions::moodleoverflow_get_subscribe_link($moodleoverflow, @@ -369,7 +369,7 @@ echo $OUTPUT->box_start('subscription'); // Create the subscription link. - $urlparams = array('id' => $course->id, 'sesskey' => sesskey()); + $urlparams = ['id' => $course->id, 'sesskey' => sesskey()]; $subscriptionlink = new moodle_url('/mod/moodleoverflow/index.php', $urlparams); // Give the option to subscribe to all. diff --git a/lib.php b/lib.php index 28eb3fa794..790ee26170 100644 --- a/lib.php +++ b/lib.php @@ -184,7 +184,7 @@ function moodleoverflow_update_instance(stdClass $moodleoverflow, mod_moodleover $moodleoverflow->id = $moodleoverflow->instance; // Get the old record. - $oldmoodleoverflow = $DB->get_record('moodleoverflow', array('id' => $moodleoverflow->id)); + $oldmoodleoverflow = $DB->get_record('moodleoverflow', ['id' => $moodleoverflow->id]); // Find the context of the module. $modulecontext = context_module::instance($moodleoverflow->coursemodule); @@ -235,7 +235,7 @@ function moodleoverflow_refresh_events($courseid = 0) { return true; } } else { - if (!$moodleoverflows = $DB->get_records('moodleoverflow', array('course' => $courseid))) { + if (!$moodleoverflows = $DB->get_records('moodleoverflow', ['course' => $courseid])) { return true; } } @@ -261,13 +261,13 @@ function moodleoverflow_delete_instance($id) { $result = true; // Get the needed objects. - if (!$moodleoverflow = $DB->get_record('moodleoverflow', array('id' => $id))) { + if (!$moodleoverflow = $DB->get_record('moodleoverflow', ['id' => $id])) { return false; } if (!$cm = get_coursemodule_from_instance('moodleoverflow', $moodleoverflow->id)) { return false; } - if (!$course = $DB->get_record('course', array('id' => $cm->course))) { + if (!$course = $DB->get_record('course', ['id' => $cm->course])) { return false; } @@ -279,12 +279,12 @@ function moodleoverflow_delete_instance($id) { $fs->delete_area_files($context->id); // Delete the subscription elements. - $DB->delete_records('moodleoverflow_subscriptions', array('moodleoverflow' => $moodleoverflow->id)); - $DB->delete_records('moodleoverflow_discuss_subs', array('moodleoverflow' => $moodleoverflow->id)); - $DB->delete_records('moodleoverflow_grades', array('moodleoverflowid' => $moodleoverflow->id)); + $DB->delete_records('moodleoverflow_subscriptions', ['moodleoverflow' => $moodleoverflow->id]); + $DB->delete_records('moodleoverflow_discuss_subs', ['moodleoverflow' => $moodleoverflow->id]); + $DB->delete_records('moodleoverflow_grades', ['moodleoverflowid' => $moodleoverflow->id]); // Delete the discussion recursivly. - if ($discussions = $DB->get_records('moodleoverflow_discussions', array('moodleoverflow' => $moodleoverflow->id))) { + if ($discussions = $DB->get_records('moodleoverflow_discussions', ['moodleoverflow' => $moodleoverflow->id])) { require_once('locallib.php'); foreach ($discussions as $discussion) { if (!moodleoverflow_delete_discussion($discussion, $course, $cm, $moodleoverflow)) { @@ -297,7 +297,7 @@ function moodleoverflow_delete_instance($id) { \mod_moodleoverflow\readtracking::moodleoverflow_delete_read_records(-1, -1, -1, $moodleoverflow->id); // Delete the moodleoverflow instance. - if (!$DB->delete_records('moodleoverflow', array('id' => $moodleoverflow->id))) { + if (!$DB->delete_records('moodleoverflow', ['id' => $moodleoverflow->id])) { $result = false; } @@ -345,13 +345,13 @@ function moodleoverflow_print_recent_activity($course, $viewfullnames, $timestar /** * Returns all other caps used in the module. * - * For example, this could be array('moodle/site:accessallgroups') if the + * For example, this could be ['moodle/site:accessallgroups'] if the * module uses that capability. * * @return array */ function moodleoverflow_get_extra_capabilities() { - return array(); + return []; } /* File API */ @@ -369,10 +369,10 @@ function moodleoverflow_get_extra_capabilities() { * @return array of [(string)filearea] => (string)description */ function moodleoverflow_get_file_areas($course, $cm, $context) { - return array( + return [ 'attachment' => get_string('areaattachment', 'mod_moodleoverflow'), 'post' => get_string('areapost', 'mod_moodleoverflow'), - ); + ]; } /** @@ -411,7 +411,7 @@ function moodleoverflow_get_file_info($browser, $areas, $course, $cm, $context, * @param bool $forcedownload whether or not force download * @param array $options additional options affecting the file serving */ -function moodleoverflow_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options = array()) { +function moodleoverflow_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options = []) { global $DB, $CFG; if ($context->contextlevel != CONTEXT_MODULE) { return false; @@ -428,13 +428,13 @@ function moodleoverflow_pluginfile($course, $cm, $context, $filearea, $args, $fo $itemid = array_pop($args); // Check if post, discussion or moodleoverflow still exists. - if (!$post = $DB->get_record('moodleoverflow_posts', array('id' => $itemid))) { + if (!$post = $DB->get_record('moodleoverflow_posts', ['id' => $itemid])) { return false; } - if (!$discussion = $DB->get_record('moodleoverflow_discussions', array('id' => $post->discussion))) { + if (!$discussion = $DB->get_record('moodleoverflow_discussions', ['id' => $post->discussion])) { return false; } - if (!$moodleoverflow = $DB->get_record('moodleoverflow', array('id' => $cm->instance))) { + if (!$moodleoverflow = $DB->get_record('moodleoverflow', ['id' => $cm->instance])) { return false; } @@ -484,7 +484,7 @@ function moodleoverflow_extend_settings_navigation(settings_navigation $settings global $CFG, $DB, $PAGE, $USER; // Retrieve the current moodle record. - $moodleoverflow = $DB->get_record('moodleoverflow', array('id' => $PAGE->cm->instance)); + $moodleoverflow = $DB->get_record('moodleoverflow', ['id' => $PAGE->cm->instance]); // Check if the user can subscribe to the instance. $enrolled = is_enrolled($PAGE->cm->context, $USER, '', false); @@ -504,7 +504,7 @@ function moodleoverflow_extend_settings_navigation(settings_navigation $settings // Generate the link. $url = '/mod/moodleoverflow/index.php'; - $params = array('id' => $moodleoverflow->course); + $params = ['id' => $moodleoverflow->course]; $link = new moodle_url($url, $params); // Add the link to the menu. @@ -523,7 +523,7 @@ function moodleoverflow_extend_settings_navigation(settings_navigation $settings } // Add the link to the menu. - $url = new moodle_url('/mod/moodleoverflow/subscribe.php', array('id' => $moodleoverflow->id, 'sesskey' => sesskey())); + $url = new moodle_url('/mod/moodleoverflow/subscribe.php', ['id' => $moodleoverflow->id, 'sesskey' => sesskey()]); $moodleoverflownode->add($linktext, $url, navigation_node::TYPE_SETTING); } @@ -548,7 +548,7 @@ function moodleoverflow_extend_settings_navigation(settings_navigation $settings // Generate the link. $url = '/mod/moodleoverflow/tracking.php'; - $params = array('id' => $moodleoverflow->id, 'sesskey' => sesskey()); + $params = ['id' => $moodleoverflow->id, 'sesskey' => sesskey()]; $link = new moodle_url($url, $params); // Add the link to the menu. @@ -607,19 +607,19 @@ function moodleoverflow_send_mails() { $textout = $PAGE->get_renderer('mod_moodleoverflow', 'email', 'textemail'); // Initiate the arrays that are saving the users that are subscribed to posts that needs sending. - $users = array(); + $users = []; $userscount = 0; // Count($users) is slow. This avoids using this. // Status arrays. - $mailcount = array(); - $errorcount = array(); + $mailcount = []; + $errorcount = []; // Cache arrays. - $discussions = array(); - $moodleoverflows = array(); - $courses = array(); - $coursemodules = array(); - $subscribedusers = array(); + $discussions = []; + $moodleoverflows = []; + $courses = []; + $coursemodules = []; + $subscribedusers = []; // Posts older than x days will not be mailed. // This will avoid problems with the cron not beeing ran for a long time. @@ -646,7 +646,7 @@ function moodleoverflow_send_mails() { if (!isset($discussions[$discussionid])) { // Retrieve the discussion from the database. - $discussion = $DB->get_record('moodleoverflow_discussions', array('id' => $post->discussion)); + $discussion = $DB->get_record('moodleoverflow_discussions', ['id' => $post->discussion]); // If there is a record, update the cache. Else ignore the post. if ($discussion) { @@ -665,7 +665,7 @@ function moodleoverflow_send_mails() { if (!isset($moodleoverflows[$moodleoverflowid])) { // Retrieve the record from the database and update the cache. - $moodleoverflow = $DB->get_record('moodleoverflow', array('id' => $moodleoverflowid)); + $moodleoverflow = $DB->get_record('moodleoverflow', ['id' => $moodleoverflowid]); if ($moodleoverflow) { $moodleoverflows[$moodleoverflowid] = $moodleoverflow; } else { @@ -680,7 +680,7 @@ function moodleoverflow_send_mails() { if (!isset($courses[$courseid])) { // Retrieve the record from the database and update the cache. - $course = $DB->get_record('course', array('id' => $courseid)); + $course = $DB->get_record('course', ['id' => $courseid]); if ($course) { $courses[$courseid] = $course; } else { @@ -748,9 +748,9 @@ function moodleoverflow_send_mails() { mtrace('Processing user ' . $userto->id); // Initiate the user caches to save memory. $userto = clone($userto); - $userto->ciewfullnames = array(); - $userto->canpost = array(); - $userto->markposts = array(); + $userto->ciewfullnames = []; + $userto->canpost = []; + $userto->markposts = []; // Cache the capabilities of the user. // Check for moodle version. Version 401 supported until 8 December 2025. @@ -763,7 +763,7 @@ function moodleoverflow_send_mails() { // Reset the caches. foreach ($coursemodules as $moodleoverflowid => $unused) { $coursemodules[$moodleoverflowid]->cache = new stdClass(); - $coursemodules[$moodleoverflowid]->cache->caps = array(); + $coursemodules[$moodleoverflowid]->cache->caps = []; unset($coursemodules[$moodleoverflowid]->uservisible); } @@ -787,10 +787,10 @@ function moodleoverflow_send_mails() { $dataobject->forumid = $moodleoverflow->id; $dataobject->forumdiscussionid = $discussion->id; $record = $DB->get_record('moodleoverflow_mail_info', - array('userid' => $dataobject->userid, + ['userid' => $dataobject->userid, 'courseid' => $dataobject->courseid, 'forumid' => $dataobject->forumid, - 'forumdiscussionid' => $dataobject->forumdiscussionid), + 'forumdiscussionid' => $dataobject->forumdiscussionid, ], 'numberofposts, id'); if (is_object($record)) { $dataset = $record; @@ -834,7 +834,7 @@ function moodleoverflow_send_mails() { // We dont know the the user yet. // Retrieve the user from the database. - $userfrom = $DB->get_record('user', array('id' => $post->userid)); + $userfrom = $DB->get_record('user', ['id' => $post->userid]); if ($userfrom) { moodleoverflow_minimise_user_record($userfrom); } else { @@ -886,11 +886,11 @@ function moodleoverflow_send_mails() { // Preapare to actually send the post now. Build up the content. $cleanname = str_replace('"', "'", strip_tags(format_string($moodleoverflow->name))); $coursecontext = context_course::instance($course->id); - $shortname = format_string($course->shortname, true, array('context' => $coursecontext)); + $shortname = format_string($course->shortname, true, ['context' => $coursecontext]); // Define a header to make mails easier to track. $emailmessageid = generate_email_messageid('moodlemoodleoverflow' . $moodleoverflow->id); - $userfrom->customheaders = array( + $userfrom->customheaders = [ 'List-Id: "' . $cleanname . '" ' . $emailmessageid, 'List-Help: ' . $CFG->wwwroot . '/mod/moodleoverflow/view.php?m=' . $moodleoverflow->id, 'Message-ID: ' . generate_email_messageid(hash('sha256', $post->id . 'to' . $userto->id)), @@ -901,7 +901,7 @@ function moodleoverflow_send_mails() { 'Precedence: Bulk', 'X-Auto-Response-Suppress: All', 'Auto-Submitted: auto-generated', - ); + ]; // Cache the users capabilities. if (!isset($userto->canpost[$discussion->id])) { @@ -988,7 +988,7 @@ function moodleoverflow_send_mails() { // Generate the url to view the post. $url = '/mod/moodleoverflow/discussion.php'; - $params = array('d' => $discussion->id); + $params = ['d' => $discussion->id]; $contexturl = new moodle_url($url, $params, 'p' . $post->id); $eventdata->contexturl = $contexturl->out(); $eventdata->contexturlname = $discussion->name; @@ -1025,7 +1025,7 @@ function moodleoverflow_send_mails() { // Mark the posts with errors in the database. if ($errorcount[$post->id]) { - $DB->set_field('moodleoverflow_posts', 'mailed', MOODLEOVERFLOW_MAILED_ERROR, array('id' => $post->id)); + $DB->set_field('moodleoverflow_posts', 'mailed', MOODLEOVERFLOW_MAILED_ERROR, ['id' => $post->id]); } } } @@ -1046,7 +1046,7 @@ function moodleoverflow_get_unmailed_posts($starttime, $endtime) { global $DB; // Set params for the sql query. - $params = array(); + $params = []; $params['ptimestart'] = $starttime; $params['ptimeend'] = $endtime; @@ -1078,7 +1078,7 @@ function moodleoverflow_mark_old_posts_as_mailed($endtime) { $now = time(); // Define variables for the sql query. - $params = array(); + $params = []; $params['mailedsuccess'] = MOODLEOVERFLOW_MAILED_SUCCESS; $params['mailedreviewsent'] = MOODLEOVERFLOW_MAILED_REVIEW_SUCCESS; $params['now'] = $now; @@ -1178,7 +1178,7 @@ function moodleoverflow_can_create_attachment($moodleoverflow, $context) { function moodleoverflow_get_user_grades($moodleoverflow, $userid=0) { global $CFG, $DB; - $params = array("moodleoverflowid" => $moodleoverflow->id); + $params = ["moodleoverflowid" => $moodleoverflow->id]; $sql = "SELECT u.id AS userid, g.grade AS rawgrade FROM {user} u, {moodleoverflow_grades} g @@ -1238,7 +1238,7 @@ function moodleoverflow_grade_item_update($moodleoverflow, $grades=null) { require_once($CFG->libdir.'/gradelib.php'); } - $params = array('itemname' => $moodleoverflow->name, 'idnumber' => $moodleoverflow->id); + $params = ['itemname' => $moodleoverflow->name, 'idnumber' => $moodleoverflow->id]; if ($moodleoverflow->grademaxgrade <= 0) { $params['gradetype'] = GRADE_TYPE_NONE; @@ -1280,6 +1280,6 @@ function moodleoverflow_get_fontawesome_icon_map() { 'mod_moodleoverflow:i/subscribed' => 'fa-bell moodleoverflow-icon-1_5x', 'mod_moodleoverflow:i/unsubscribed' => 'fa-bell-slash-o moodleoverflow-icon-1_5x', 'mod_moodleoverflow:i/vote-up' => 'fa-chevron-up moodleoverflow-icon-2x moodleoverflow-icon-no-margin', - 'mod_moodleoverflow:i/vote-down' => 'fa-chevron-down moodleoverflow-icon-2x moodleoverflow-icon-no-margin' + 'mod_moodleoverflow:i/vote-down' => 'fa-chevron-down moodleoverflow-icon-2x moodleoverflow-icon-no-margin', ]; } diff --git a/locallib.php b/locallib.php index 98b4451ba9..d6eb0d64d1 100644 --- a/locallib.php +++ b/locallib.php @@ -52,7 +52,7 @@ function moodleoverflow_get_discussions($cm, $page = -1, $perpage = 0) { // User must have the permission to view the discussions. $modcontext = context_module::instance($cm->id); if (!capabilities::has(capabilities::VIEW_DISCUSSION, $modcontext)) { - return array(); + return []; } // Filter some defaults. @@ -157,7 +157,7 @@ function moodleoverflow_print_latest_discussions($moodleoverflow, $cm, $page = - $userstatsbuttontext = get_string('seeuserstats', 'moodleoverflow'); $userstatsbuttonurl = new moodle_url('/mod/moodleoverflow/userstats.php', ['id' => $cm->id, 'courseid' => $moodleoverflow->course, - 'mid' => $moodleoverflow->id]); + 'mid' => $moodleoverflow->id, ]); $userstatsbutton = new single_button($userstatsbuttonurl, $userstatsbuttontext, 'get'); $userstatsbutton->class = 'singlebutton align-middle m-2'; echo $OUTPUT->render($userstatsbutton); @@ -191,7 +191,7 @@ function moodleoverflow_print_latest_discussions($moodleoverflow, $cm, $page = - $unreads = moodleoverflow_get_discussions_unread($cm); $markallread = $CFG->wwwroot . '/mod/moodleoverflow/markposts.php?m=' . $moodleoverflow->id; } else { - $unreads = array(); + $unreads = []; $markallread = null; } @@ -233,9 +233,9 @@ function moodleoverflow_print_latest_discussions($moodleoverflow, $cm, $page = - // Iterate through every visible discussion. $i = 0; - $preparedarray = array(); + $preparedarray = []; foreach ($discussions as $discussion) { - $preparedarray[$i] = array(); + $preparedarray[$i] = []; // Handle anonymized discussions. if ($discussion->userid == 0) { @@ -334,8 +334,8 @@ function moodleoverflow_print_latest_discussions($moodleoverflow, $cm, $page = - } } else { // Get his picture, his name and the link to his profile. - $preparedarray[$i]['picture'] = $OUTPUT->user_picture($startuser, array('courseid' => $moodleoverflow->course, - 'link' => false)); + $preparedarray[$i]['picture'] = $OUTPUT->user_picture($startuser, ['courseid' => $moodleoverflow->course, + 'link' => false, ]); $preparedarray[$i]['username'] = fullname($startuser, has_capability('moodle/site:viewfullnames', $context)); $preparedarray[$i]['userlink'] = $CFG->wwwroot . '/user/view.php?id=' . $discussion->userid . '&course=' . $moodleoverflow->course; @@ -394,7 +394,7 @@ function moodleoverflow_print_latest_discussions($moodleoverflow, $cm, $page = - $reviewinfo = review::get_short_review_info_for_discussion($discussion->discussion); $preparedarray[$i]['needreview'] = $reviewinfo->count; $preparedarray[$i]['reviewlink'] = (new moodle_url('/mod/moodleoverflow/discussion.php', [ - 'd' => $discussion->discussion + 'd' => $discussion->discussion, ], 'p' . $reviewinfo->first))->out(false); } @@ -457,10 +457,10 @@ function moodleoverflow_print_latest_discussions($moodleoverflow, $cm, $page = - */ function moodleoverflow_print_forum_list($course, $cm, $movetopopup) { global $CFG, $DB, $PAGE; - $forumarray = array(array()); - $currentforum = $DB->get_record('moodleoverflow_discussions', array('id' => $movetopopup), 'moodleoverflow'); - $currentdiscussion = $DB->get_record('moodleoverflow_discussions', array('id' => $movetopopup), 'name'); - $forums = $DB->get_records('moodleoverflow', array('course' => $course->id)); + $forumarray = [[]]; + $currentforum = $DB->get_record('moodleoverflow_discussions', ['id' => $movetopopup], 'moodleoverflow'); + $currentdiscussion = $DB->get_record('moodleoverflow_discussions', ['id' => $movetopopup], 'name'); + $forums = $DB->get_records('moodleoverflow', ['course' => $course->id]); $amountforums = count($forums); if ($amountforums > 1) { @@ -609,7 +609,7 @@ function moodleoverflow_get_discussions_unread($cm) { $params = [ 'userid' => $USER->id, 'instance' => $cm->instance, - 'cutoffdate' => $cutoffdate + 'cutoffdate' => $cutoffdate, ]; if (!has_capability('mod/moodleoverflow:reviewpost', $modcontext)) { @@ -637,7 +637,7 @@ function moodleoverflow_get_discussions_unread($cm) { } else { // If there are no unread messages, return an empty array. - return array(); + return []; } } @@ -666,7 +666,7 @@ function moodleoverflow_get_post_full($postid) { JOIN {moodleoverflow_discussions} d ON p.discussion = d.id LEFT JOIN {user} u ON p.userid = u.id WHERE p.id = :postid"; - $params = array(); + $params = []; $params['postid'] = $postid; $post = $DB->get_record_sql($sql, $params); @@ -696,7 +696,7 @@ function moodleoverflow_user_can_see_post($moodleoverflow, $discussion, $post, $ // Fetch the moodleoverflow instance object. if (is_numeric($moodleoverflow)) { debugging('missing full moodleoverflow', DEBUG_DEVELOPER); - if (!$moodleoverflow = $DB->get_record('moodleoverflow', array('id' => $moodleoverflow))) { + if (!$moodleoverflow = $DB->get_record('moodleoverflow', ['id' => $moodleoverflow])) { return false; } } @@ -704,7 +704,7 @@ function moodleoverflow_user_can_see_post($moodleoverflow, $discussion, $post, $ // Fetch the discussion object. if (is_numeric($discussion)) { debugging('missing full discussion', DEBUG_DEVELOPER); - if (!$discussion = $DB->get_record('moodleoverflow_discussions', array('id' => $discussion))) { + if (!$discussion = $DB->get_record('moodleoverflow_discussions', ['id' => $discussion])) { return false; } } @@ -712,7 +712,7 @@ function moodleoverflow_user_can_see_post($moodleoverflow, $discussion, $post, $ // Fetch the post object. if (is_numeric($post)) { debugging('missing full post', DEBUG_DEVELOPER); - if (!$post = $DB->get_record('moodleoverflow_posts', array('id' => $post))) { + if (!$post = $DB->get_record('moodleoverflow_posts', ['id' => $post])) { return false; } } @@ -760,7 +760,7 @@ function moodleoverflow_user_can_see_discussion($moodleoverflow, $discussion, $c // Retrieve the moodleoverflow object. if (is_numeric($moodleoverflow)) { debugging('missing full moodleoverflow', DEBUG_DEVELOPER); - if (!$moodleoverflow = $DB->get_record('moodleoverflow', array('id' => $moodleoverflow))) { + if (!$moodleoverflow = $DB->get_record('moodleoverflow', ['id' => $moodleoverflow])) { return false; } } @@ -768,7 +768,7 @@ function moodleoverflow_user_can_see_discussion($moodleoverflow, $discussion, $c // Retrieve the discussion object. if (is_numeric($discussion)) { debugging('missing full discussion', DEBUG_DEVELOPER); - if (!$discussion = $DB->get_record('moodleoverflow_discussions', array('id' => $discussion))) { + if (!$discussion = $DB->get_record('moodleoverflow_discussions', ['id' => $discussion])) { return false; } } @@ -805,7 +805,7 @@ function moodleoverflow_add_discussion($discussion, $modulecontext, $userid = nu // as a real post. The discussion links to it. // Retrieve the module instance. - if (!$moodleoverflow = $DB->get_record('moodleoverflow', array('id' => $discussion->moodleoverflow))) { + if (!$moodleoverflow = $DB->get_record('moodleoverflow', ['id' => $discussion->moodleoverflow])) { return false; } @@ -850,7 +850,7 @@ function moodleoverflow_add_discussion($discussion, $modulecontext, $userid = nu $post->discussion = $DB->insert_record('moodleoverflow_discussions', $discussionobject); // Link the post to the discussion. - $DB->set_field('moodleoverflow_posts', 'discussion', $post->discussion, array('id' => $post->id)); + $DB->set_field('moodleoverflow_posts', 'discussion', $post->discussion, ['id' => $post->id]); moodleoverflow_add_attachment($post, $moodleoverflow, $cm); @@ -862,10 +862,10 @@ function moodleoverflow_add_discussion($discussion, $modulecontext, $userid = nu } // Trigger event. - $params = array( + $params = [ 'context' => $modulecontext, 'objectid' => $post->discussion, - ); + ]; $event = \mod_moodleoverflow\event\discussion_viewed::create($params); $event->trigger(); @@ -1017,10 +1017,10 @@ function moodleoverflow_get_all_discussion_posts($discussionid, $tracking, $modc global $DB, $USER, $CFG; // Initiate tracking settings. - $params = array(); + $params = []; $trackingselector = ""; $trackingjoin = ""; - $params = array(); + $params = []; // If tracking is enabled, another join is needed. if ($tracking) { @@ -1056,7 +1056,7 @@ function moodleoverflow_get_all_discussion_posts($discussionid, $tracking, $modc // Return an empty array, if there are no posts. if (!$posts = $DB->get_records_sql($sql, $params)) { - return array(); + return []; } // Load all ratings. @@ -1099,7 +1099,7 @@ function moodleoverflow_get_all_discussion_posts($discussionid, $tracking, $modc // Create the children array. if (!isset($posts[$post->parent]->children)) { - $posts[$post->parent]->children = array(); + $posts[$post->parent]->children = []; } // Increase the level of the current post. @@ -1205,7 +1205,7 @@ function moodleoverflow_print_post($post, $discussion, $moodleoverflow, $cm, $co } // Get the current link without unnecessary parameters. - $discussionlink = new moodle_url('/mod/moodleoverflow/discussion.php', array('d' => $post->discussion)); + $discussionlink = new moodle_url('/mod/moodleoverflow/discussion.php', ['d' => $post->discussion]); // Build the object that represents the posting user. $postinguser = new stdClass(); @@ -1221,19 +1221,19 @@ function moodleoverflow_print_post($post, $discussion, $moodleoverflow, $cm, $co $postinguser->id = null; if ($post->userid == $USER->id) { $postinguser->fullname = get_string('anonym_you', 'mod_moodleoverflow'); - $postinguser->profilelink = new moodle_url('/user/view.php', array('id' => $post->userid, 'course' => $course->id)); + $postinguser->profilelink = new moodle_url('/user/view.php', ['id' => $post->userid, 'course' => $course->id]); } else { $postinguser->fullname = $usermapping[(int) $post->userid]; $postinguser->profilelink = null; } } else { $postinguser->fullname = fullname($postinguser, capabilities::has('moodle/site:viewfullnames', $modulecontext)); - $postinguser->profilelink = new moodle_url('/user/view.php', array('id' => $post->userid, 'course' => $course->id)); + $postinguser->profilelink = new moodle_url('/user/view.php', ['id' => $post->userid, 'course' => $course->id]); $postinguser->id = $post->userid; } // Prepare an array of commands. - $commands = array(); + $commands = []; // Create a permalink. $permalink = new moodle_url($discussionlink); @@ -1255,15 +1255,15 @@ function moodleoverflow_print_post($post, $discussion, $moodleoverflow, $cm, $co $link = '/mod/moodleoverflow/discussion.php'; if ($post->markedhelpful) { $commands[] = html_writer::tag('a', $str->marknothelpful, - array('class' => 'markhelpful onlyifreviewed', 'role' => 'button', 'data-moodleoverflow-action' => 'helpful')); + ['class' => 'markhelpful onlyifreviewed', 'role' => 'button', 'data-moodleoverflow-action' => 'helpful']); } else { // If there are already marked posts, change the string of the button. if ($helpfulposts) { $commands[] = html_writer::tag('a', $str->alsomarkhelpful, - array('class' => 'markhelpful onlyifreviewed', 'role' => 'button', 'data-moodleoverflow-action' => 'helpful')); + ['class' => 'markhelpful onlyifreviewed', 'role' => 'button', 'data-moodleoverflow-action' => 'helpful']); } else { $commands[] = html_writer::tag('a', $str->markhelpful, - array('class' => 'markhelpful onlyifreviewed', 'role' => 'button', 'data-moodleoverflow-action' => 'helpful')); + ['class' => 'markhelpful onlyifreviewed', 'role' => 'button', 'data-moodleoverflow-action' => 'helpful']); } } } @@ -1277,15 +1277,15 @@ function moodleoverflow_print_post($post, $discussion, $moodleoverflow, $cm, $co $link = '/mod/moodleoverflow/discussion.php'; if ($post->markedsolution) { $commands[] = html_writer::tag('a', $str->marknotsolved, - array('class' => 'marksolved onlyifreviewed', 'role' => 'button', 'data-moodleoverflow-action' => 'solved')); + ['class' => 'marksolved onlyifreviewed', 'role' => 'button', 'data-moodleoverflow-action' => 'solved']); } else { // If there are already marked posts, change the string of the button. if ($solvedposts) { $commands[] = html_writer::tag('a', $str->alsomarksolved, - array('class' => 'marksolved onlyifreviewed', 'role' => 'button', 'data-moodleoverflow-action' => 'solved')); + ['class' => 'marksolved onlyifreviewed', 'role' => 'button', 'data-moodleoverflow-action' => 'solved']); } else { $commands[] = html_writer::tag('a', $str->marksolved, - array('class' => 'marksolved onlyifreviewed', 'role' => 'button', 'data-moodleoverflow-action' => 'solved')); + ['class' => 'marksolved onlyifreviewed', 'role' => 'button', 'data-moodleoverflow-action' => 'solved']); } } } @@ -1298,8 +1298,8 @@ function moodleoverflow_print_post($post, $discussion, $moodleoverflow, $cm, $co (!review::should_post_be_reviewed($post, $moodleoverflow) || !$post->reviewed)) || capabilities::has(capabilities::EDIT_ANY_POST, $modulecontext) ) { - $editurl = new moodle_url('/mod/moodleoverflow/post.php', array('edit' => $post->id)); - $commands[] = array('url' => $editurl, 'text' => $str->edit); + $editurl = new moodle_url('/mod/moodleoverflow/post.php', ['edit' => $post->id]); + $commands[] = ['url' => $editurl, 'text' => $str->edit]; } // Give the option to delete a post. @@ -1308,30 +1308,30 @@ function moodleoverflow_print_post($post, $discussion, $moodleoverflow, $cm, $co capabilities::has(capabilities::DELETE_ANY_POST, $modulecontext)) { $link = '/mod/moodleoverflow/post.php'; - $commands[] = array('url' => new moodle_url($link, array('delete' => $post->id)), 'text' => $str->delete); + $commands[] = ['url' => new moodle_url($link, ['delete' => $post->id]), 'text' => $str->delete]; } // Give the option to reply to a post. if (moodleoverflow_user_can_post($modulecontext, $post, false)) { $attributes = [ - 'class' => 'onlyifreviewed' + 'class' => 'onlyifreviewed', ]; // Answer to the parent post. if (empty($post->parent)) { - $replyurl = new moodle_url('/mod/moodleoverflow/post.php#mformmoodleoverflow', array('reply' => $post->id)); - $commands[] = array('url' => $replyurl, 'text' => $str->replyfirst, 'attributes' => $attributes); + $replyurl = new moodle_url('/mod/moodleoverflow/post.php#mformmoodleoverflow', ['reply' => $post->id]); + $commands[] = ['url' => $replyurl, 'text' => $str->replyfirst, 'attributes' => $attributes]; // If the post is a comment, answer to the parent post. } else if (!$iscomment) { - $replyurl = new moodle_url('/mod/moodleoverflow/post.php#mformmoodleoverflow', array('reply' => $post->id)); - $commands[] = array('url' => $replyurl, 'text' => $str->reply, 'attributes' => $attributes); + $replyurl = new moodle_url('/mod/moodleoverflow/post.php#mformmoodleoverflow', ['reply' => $post->id]); + $commands[] = ['url' => $replyurl, 'text' => $str->reply, 'attributes' => $attributes]; // Else simple respond to the answer. } else { - $replyurl = new moodle_url('/mod/moodleoverflow/post.php#mformmoodleoverflow', array('reply' => $iscomment)); - $commands[] = array('url' => $replyurl, 'text' => $str->reply, 'attributes' => $attributes); + $replyurl = new moodle_url('/mod/moodleoverflow/post.php#mformmoodleoverflow', ['reply' => $iscomment]); + $commands[] = ['url' => $replyurl, 'text' => $str->reply, 'attributes' => $attributes]; } } @@ -1467,7 +1467,7 @@ function moodleoverflow_print_post($post, $discussion, $moodleoverflow, $cm, $co $mustachedata->attachments = get_attachments($post, $cm); // Output the commands. - $commandhtml = array(); + $commandhtml = []; foreach ($commands as $command) { if (is_array($command)) { $commandhtml[] = html_writer::link($command['url'], $command['text'], $command['attributes'] ?? null); @@ -1582,14 +1582,14 @@ function moodleoverflow_print_posts_nested($course, &$cm, $moodleoverflow, $disc */ function get_attachments($post, $cm) { global $CFG, $OUTPUT; - $attachments = array(); + $attachments = []; if (empty($post->attachment)) { - return array(); + return []; } if (!$context = context_module::instance($cm->id)) { - return array(); + return []; } $fs = get_file_storage(); @@ -1600,20 +1600,20 @@ function get_attachments($post, $cm) { if ($files) { $i = 0; foreach ($files as $file) { - $attachments[$i] = array(); + $attachments[$i] = []; $attachments[$i]['filename'] = $file->get_filename(); $mimetype = $file->get_mimetype(); $iconimage = $OUTPUT->pix_icon(file_file_icon($file), get_mimetype_description($file), 'moodle', - array('class' => 'icon')); + ['class' => 'icon']); $path = moodle_url::make_pluginfile_url($file->get_contextid(), $file->get_component(), $file->get_filearea(), $file->get_itemid(), $file->get_filepath(), $file->get_filename()); $attachments[$i]['icon'] = $iconimage; $attachments[$i]['filepath'] = $path; - if (in_array($mimetype, array('image/gif', 'image/jpeg', 'image/png'))) { + if (in_array($mimetype, ['image/gif', 'image/jpeg', 'image/png'])) { // Image attachments don't get printed as links. $attachments[$i]['image'] = true; } else { @@ -1648,7 +1648,7 @@ function moodleoverflow_add_attachment($post, $forum, $cm) { file_save_draft_area_files($post->attachments, $context->id, 'mod_moodleoverflow', 'attachment', $post->id, mod_moodleoverflow_post_form::attachment_options($forum)); - $DB->set_field('moodleoverflow_posts', 'attachment', $present, array('id' => $post->id)); + $DB->set_field('moodleoverflow_posts', 'attachment', $present, ['id' => $post->id]); return true; } @@ -1666,8 +1666,8 @@ function moodleoverflow_add_new_post($post) { // We do not check if these variables exist because this function // is just called from one function which checks all these variables. - $discussion = $DB->get_record('moodleoverflow_discussions', array('id' => $post->discussion)); - $moodleoverflow = $DB->get_record('moodleoverflow', array('id' => $discussion->moodleoverflow)); + $discussion = $DB->get_record('moodleoverflow_discussions', ['id' => $post->discussion]); + $moodleoverflow = $DB->get_record('moodleoverflow', ['id' => $discussion->moodleoverflow]); $cm = get_coursemodule_from_instance('moodleoverflow', $moodleoverflow->id); // Add some variables to the post. @@ -1687,13 +1687,13 @@ function moodleoverflow_add_new_post($post) { // Add the post to the database. $post->id = $DB->insert_record('moodleoverflow_posts', $post); - $DB->set_field('moodleoverflow_posts', 'message', $post->message, array('id' => $post->id)); + $DB->set_field('moodleoverflow_posts', 'message', $post->message, ['id' => $post->id]); moodleoverflow_add_attachment($post, $moodleoverflow, $cm); if ($post->reviewed) { // Update the discussion. - $DB->set_field('moodleoverflow_discussions', 'timemodified', $post->modified, array('id' => $post->discussion)); - $DB->set_field('moodleoverflow_discussions', 'usermodified', $post->userid, array('id' => $post->discussion)); + $DB->set_field('moodleoverflow_discussions', 'timemodified', $post->modified, ['id' => $post->discussion]); + $DB->set_field('moodleoverflow_discussions', 'usermodified', $post->userid, ['id' => $post->discussion]); } // Mark the created post as read if the user is tracking the discussion. @@ -1724,7 +1724,7 @@ function moodleoverflow_delete_discussion($discussion, $course, $cm, $moodleover $result = true; // Get all posts related to the discussion. - if ($posts = $DB->get_records('moodleoverflow_posts', array('discussion' => $discussion->id))) { + if ($posts = $DB->get_records('moodleoverflow_posts', ['discussion' => $discussion->id])) { // Iterate through them and delete each one. foreach ($posts as $post) { @@ -1742,8 +1742,8 @@ function moodleoverflow_delete_discussion($discussion, $course, $cm, $moodleover readtracking::moodleoverflow_delete_read_records(-1, -1, $discussion->id); // Remove the subscriptions for this discussion. - $DB->delete_records('moodleoverflow_discuss_subs', array('discussion' => $discussion->id)); - if (!$DB->delete_records('moodleoverflow_discussions', array('id' => $discussion->id))) { + $DB->delete_records('moodleoverflow_discuss_subs', ['discussion' => $discussion->id]); + if (!$DB->delete_records('moodleoverflow_discussions', ['id' => $discussion->id])) { $result = false; } @@ -1770,7 +1770,7 @@ function moodleoverflow_delete_post($post, $deletechildren, $cm, $moodleoverflow try { $transaction = $DB->start_delegated_transaction(); - $childposts = $DB->get_records('moodleoverflow_posts', array('parent' => $post->id)); + $childposts = $DB->get_records('moodleoverflow_posts', ['parent' => $post->id]); if ($deletechildren && $childposts) { foreach ($childposts as $childpost) { moodleoverflow_delete_post($childpost, true, $cm, $moodleoverflow); @@ -1778,10 +1778,10 @@ function moodleoverflow_delete_post($post, $deletechildren, $cm, $moodleoverflow } // Delete the ratings. - $DB->delete_records('moodleoverflow_ratings', array('postid' => $post->id)); + $DB->delete_records('moodleoverflow_ratings', ['postid' => $post->id]); // Delete the post. - if ($DB->delete_records('moodleoverflow_posts', array('id' => $post->id))) { + if ($DB->delete_records('moodleoverflow_posts', ['id' => $post->id])) { // Delete the read records. readtracking::moodleoverflow_delete_read_records(-1, $post->id); @@ -1808,14 +1808,14 @@ function moodleoverflow_delete_post($post, $deletechildren, $cm, $moodleoverflow $modulecontext = context_module::instance($cm->id); // Trigger the post deletion event. - $params = array( + $params = [ 'context' => $modulecontext, 'objectid' => $post->id, - 'other' => array( + 'other' => [ 'discussionid' => $post->discussion, - 'moodleoverflowid' => $moodleoverflow->id - ) - ); + 'moodleoverflowid' => $moodleoverflow->id, + ], + ]; if ($post->userid !== $USER->id) { $params['relateduserid'] = $post->userid; } @@ -1846,7 +1846,7 @@ function moodleoverflow_discussion_update_last_post($discussionid) { global $DB; // Check if the given discussion exists. - if (!$DB->record_exists('moodleoverflow_discussions', array('id' => $discussionid))) { + if (!$DB->record_exists('moodleoverflow_discussions', ['id' => $discussionid])) { return false; } @@ -1858,7 +1858,7 @@ function moodleoverflow_discussion_update_last_post($discussionid) { ORDER BY modified DESC"; // Find the new last post of the discussion. - if (($lastposts = $DB->get_records_sql($sql, array($discussionid), 0, 1))) { + if (($lastposts = $DB->get_records_sql($sql, [$discussionid], 0, 1))) { $lastpost = reset($lastposts); // Create an discussion object. @@ -1906,10 +1906,10 @@ function moodleoverflow_count_discussions($moodleoverflow, $course) { global $CFG, $DB; // Create a cache. - static $cache = array(); + static $cache = []; // Initiate variables. - $params = array($course->id); + $params = [$course->id]; // Check whether the cache for the moodleoverflow is set. if (!isset($cache[$course->id])) { @@ -1937,7 +1937,7 @@ function moodleoverflow_count_discussions($moodleoverflow, $course) { // There are no records. // Save the result into the cache. - $cache[$course->id] = array(); + $cache[$course->id] = []; } } @@ -1953,7 +1953,7 @@ function moodleoverflow_count_discussions($moodleoverflow, $course) { $sql = "SELECT COUNT(d.id) FROM {moodleoverflow_discussions} d WHERE d.moodleoverflow = ?"; - $amount = $DB->get_field_sql($sql, array($moodleoverflow->id)); + $amount = $DB->get_field_sql($sql, [$moodleoverflow->id]); // Return the amount. return $amount; @@ -1995,10 +1995,10 @@ function moodleoverflow_update_user_grade_on_db($moodleoverflow, $postuserrating } // Save updated grade on local table. - if ($DB->record_exists('moodleoverflow_grades', array('userid' => $userid, 'moodleoverflowid' => $moodleoverflow->id))) { + if ($DB->record_exists('moodleoverflow_grades', ['userid' => $userid, 'moodleoverflowid' => $moodleoverflow->id])) { - $DB->set_field('moodleoverflow_grades', 'grade', $grade, array('userid' => $userid, - 'moodleoverflowid' => $moodleoverflow->id)); + $DB->set_field('moodleoverflow_grades', 'grade', $grade, ['userid' => $userid, + 'moodleoverflowid' => $moodleoverflow->id, ]); } else { @@ -2022,7 +2022,7 @@ function moodleoverflow_update_user_grade_on_db($moodleoverflow, $postuserrating function moodleoverflow_update_all_grades_for_cm($moodleoverflowid) { global $DB; - $moodleoverflow = $DB->get_record('moodleoverflow', array('id' => $moodleoverflowid)); + $moodleoverflow = $DB->get_record('moodleoverflow', ['id' => $moodleoverflowid]); // Check whether moodleoverflow object has the added params. if ($moodleoverflow->grademaxgrade > 0 && $moodleoverflow->gradescalefactor > 0) { diff --git a/markposts.php b/markposts.php index abae184223..9354f62912 100644 --- a/markposts.php +++ b/markposts.php @@ -32,7 +32,7 @@ $returndiscussion = optional_param('return', 0, PARAM_INT); // The page to return to. // Prepare the array that should be used to return to this page. -$url = new moodle_url('/mod/moodleoverflow/markposts.php', array('m' => $moodleoverflowid)); +$url = new moodle_url('/mod/moodleoverflow/markposts.php', ['m' => $moodleoverflowid]); // Check the optional params. if ($discussionid !== 0) { @@ -46,12 +46,12 @@ $PAGE->set_url($url); // Retrieve the connected moodleoverflow instance. -if (!$moodleoverflow = $DB->get_record('moodleoverflow', array('id' => $moodleoverflowid))) { +if (!$moodleoverflow = $DB->get_record('moodleoverflow', ['id' => $moodleoverflowid])) { throw new moodle_exception('invalidmoodleoverflowid', 'moodleoverflow'); } // Retrieve the connected course. -if (!$course = $DB->get_record('course', array('id' => $moodleoverflow->course))) { +if (!$course = $DB->get_record('course', ['id' => $moodleoverflow->course])) { throw new moodle_exception('invalidcourseid'); } @@ -70,12 +70,12 @@ if ($returndiscussion === 0) { // If no parameter is set, relink to the view. - $returnto = new moodle_url("/mod/moodleoverflow/view.php", array('m' => $moodleoverflow->id)); + $returnto = new moodle_url("/mod/moodleoverflow/view.php", ['m' => $moodleoverflow->id]); } else { // Else relink back to the discussion we are coming from. - $returnto = new moodle_url("/mod/moodleoverflow/discussion.php", array('d' => $returndiscussion)); + $returnto = new moodle_url("/mod/moodleoverflow/discussion.php", ['d' => $returndiscussion]); } // Guests can't mark posts as read. @@ -99,7 +99,7 @@ if (!empty($discussionid)) { // Check if the discussion exists. - $options = array('id' => $discussionid, 'moodleoverflow' => $moodleoverflow->id); + $options = ['id' => $discussionid, 'moodleoverflow' => $moodleoverflow->id]; $discussion = $DB->get_record('moodleoverflow_discussions', $options); if (!$discussion) { throw new moodle_exception('invaliddiscussionid', 'moodleoverflow'); diff --git a/mod_form.php b/mod_form.php index 4df07d8537..30cdef4367 100644 --- a/mod_form.php +++ b/mod_form.php @@ -59,7 +59,7 @@ public function definition() { $mform->addElement('header', 'general', get_string('general', 'form')); // Adding the standard "name" field. - $mform->addElement('text', 'name', get_string('moodleoverflowname', 'moodleoverflow'), array('size' => '64')); + $mform->addElement('text', 'name', get_string('moodleoverflowname', 'moodleoverflow'), ['size' => '64']); if (!empty(get_config('moodleoverflow', 'formatstringstriptags'))) { $mform->setType('name', PARAM_TEXT); } else { @@ -77,7 +77,7 @@ public function definition() { $currentsetting = $this->current && property_exists($this->current, 'anonymous') ? $this->current->anonymous : 0; $possiblesettings = [ - anonymous::EVERYTHING_ANONYMOUS => get_string('anonymous:everything', 'moodleoverflow') + anonymous::EVERYTHING_ANONYMOUS => get_string('anonymous:everything', 'moodleoverflow'), ]; if ($currentsetting <= anonymous::QUESTION_ANONYMOUS) { @@ -98,7 +98,7 @@ public function definition() { $possiblesettings = [ review::NOTHING => get_string('nothing', 'moodleoverflow'), review::QUESTIONS => get_string('questions', 'moodleoverflow'), - review::EVERYTHING => get_string('questions_and_posts', 'moodleoverflow') + review::EVERYTHING => get_string('questions_and_posts', 'moodleoverflow'), ]; $mform->addElement('select', 'needsreview', get_string('review', 'moodleoverflow'), $possiblesettings); @@ -115,7 +115,7 @@ public function definition() { $mform->addHelpButton('maxbytes', 'maxattachmentsize', 'moodleoverflow'); $mform->setDefault('maxbytes', get_config('moodleoverflow', 'maxbytes')); - $choices = array( + $choices = [ 0 => 0, 1 => 1, 2 => 2, @@ -129,8 +129,8 @@ public function definition() { 10 => 10, 20 => 20, 50 => 50, - 100 => 100 - ); + 100 => 100, + ]; $mform->addElement('select', 'maxattachments', get_string('maxattachments', 'moodleoverflow'), $choices); $mform->addHelpButton('maxattachments', 'maxattachments', 'moodleoverflow'); $mform->setDefault('maxattachments', get_config('moodleoverflow', 'maxattachments')); @@ -139,7 +139,7 @@ public function definition() { $mform->addElement('header', 'subscriptiontrackingheader', get_string('subscriptiontrackingheader', 'moodleoverflow')); // Prepare the array with options for the subscription state. - $options = array(); + $options = []; $options[MOODLEOVERFLOW_CHOOSESUBSCRIBE] = get_string('subscriptionoptional', 'moodleoverflow'); $options[MOODLEOVERFLOW_FORCESUBSCRIBE] = get_string('subscriptionforced', 'moodleoverflow'); $options[MOODLEOVERFLOW_INITIALSUBSCRIBE] = get_string('subscriptionauto', 'moodleoverflow'); @@ -150,7 +150,7 @@ public function definition() { $mform->addHelpButton('forcesubscribe', 'subscriptionmode', 'moodleoverflow'); // Set the options for the default readtracking. - $options = array(); + $options = []; $options[MOODLEOVERFLOW_TRACKING_OPTIONAL] = get_string('trackingoptional', 'moodleoverflow'); $options[MOODLEOVERFLOW_TRACKING_OFF] = get_string('trackingoff', 'moodleoverflow'); if (get_config('moodleoverflow', 'allowforcedreadtracking')) { @@ -194,7 +194,7 @@ public function definition() { $mform->addElement('header', 'ratingheading', get_string('ratingheading', 'moodleoverflow')); // Which rating is more important? - $options = array(); + $options = []; $options[MOODLEOVERFLOW_PREFERENCE_STARTER] = get_string('starterrating', 'moodleoverflow'); $options[MOODLEOVERFLOW_PREFERENCE_TEACHER] = get_string('teacherrating', 'moodleoverflow'); $mform->addElement('select', 'ratingpreference', get_string('ratingpreference', 'moodleoverflow'), $options); diff --git a/post.php b/post.php index e204e5ee17..57757b7560 100644 --- a/post.php +++ b/post.php @@ -39,16 +39,11 @@ $confirm = optional_param('confirm', 0, PARAM_INT); // Set the URL that should be used to return to this page. -$PAGE->set_url('/mod/moodleoverflow/post.php', array( - 'moodleoverflow' => $moodleoverflow, - 'reply' => $reply, - 'edit' => $edit, - 'delete' => $delete, - 'confirm' => $confirm, -)); +$PAGE->set_url('/mod/moodleoverflow/post.php', ['moodleoverflow' => $moodleoverflow, 'reply' => $reply, 'edit' => $edit, + 'delete' => $delete, 'confirm' => $confirm, ]); // These params will be passed as hidden variables later in the form. -$pageparams = array('moodleoverflow' => $moodleoverflow, 'reply' => $reply, 'edit' => $edit); +$pageparams = ['moodleoverflow' => $moodleoverflow, 'reply' => $reply, 'edit' => $edit]; // Get the system context instance. $systemcontext = context_system::instance(); @@ -124,9 +119,9 @@ // If the interaction was cancelled, the user needs to be redirected. if ($mformpost->is_cancelled()) { if (!isset($prepost->discussionid)) { - redirect(new moodle_url('/mod/moodleoverflow/view.php', array('m' => $prepost->moodleoverflowid))); + redirect(new moodle_url('/mod/moodleoverflow/view.php', ['m' => $prepost->moodleoverflowid])); } else { - redirect(new moodle_url('/mod/moodleoverflow/discussion.php', array('d' => $prepost->discussionid))); + redirect(new moodle_url('/mod/moodleoverflow/discussion.php', ['d' => $prepost->discussionid])); } exit; } diff --git a/settings.php b/settings.php index 6c1a244fb5..bb2e60dd27 100644 --- a/settings.php +++ b/settings.php @@ -50,7 +50,7 @@ // Default read tracking settings. - $options = array(); + $options = []; $options[MOODLEOVERFLOW_TRACKING_OPTIONAL] = get_string('trackingoptional', 'moodleoverflow'); $options[MOODLEOVERFLOW_TRACKING_OFF] = get_string('trackingoff', 'moodleoverflow'); $options[MOODLEOVERFLOW_TRACKING_FORCED] = get_string('trackingon', 'moodleoverflow'); @@ -70,7 +70,7 @@ get_string('configoldpostdays', 'moodleoverflow'), 14, PARAM_INT)); // Default time (hour) to execute 'clean_read_records' cron. - $options = array(); + $options = []; for ($i = 0; $i < 24; $i++) { $options[$i] = sprintf("%02d", $i); } diff --git a/subscribe.php b/subscribe.php index 71487cec6d..0ea5367b30 100644 --- a/subscribe.php +++ b/subscribe.php @@ -38,7 +38,7 @@ $returnurl = optional_param('returnurl', null, PARAM_RAW); // Set the url to return to the same action. -$url = new moodle_url('/mod/moodleoverflow/subscribe.php', array('id' => $id)); +$url = new moodle_url('/mod/moodleoverflow/subscribe.php', ['id' => $id]); if (!is_null($mode)) { $url->param('mode', $mode); } @@ -50,7 +50,7 @@ } if (!is_null($discussionid)) { $url->param('d', $discussionid); - if (!$discussion = $DB->get_record('moodleoverflow_discussions', array('id' => $discussionid, 'moodleoverflow' => $id))) { + if (!$discussion = $DB->get_record('moodleoverflow_discussions', ['id' => $discussionid, 'moodleoverflow' => $id])) { throw new moodle_exception('invaliddiscussionid', 'moodleoverflow'); } } @@ -59,16 +59,16 @@ $PAGE->set_url($url); // Get all necessary objects. -$moodleoverflow = $DB->get_record('moodleoverflow', array('id' => $id), '*', MUST_EXIST); -$course = $DB->get_record('course', array('id' => $moodleoverflow->course), '*', MUST_EXIST); +$moodleoverflow = $DB->get_record('moodleoverflow', ['id' => $id], '*', MUST_EXIST); +$course = $DB->get_record('course', ['id' => $moodleoverflow->course], '*', MUST_EXIST); $cm = get_coursemodule_from_instance('moodleoverflow', $moodleoverflow->id, $course->id, false, MUST_EXIST); $context = context_module::instance($cm->id); // Define variables. -$notify = array(); +$notify = []; $notify['success'] = \core\output\notification::NOTIFY_SUCCESS; $notify['error'] = \core\output\notification::NOTIFY_ERROR; -$strings = array(); +$strings = []; $strings['subscribeenrolledonly'] = get_string('subscribeenrolledonly', 'moodleoverflow'); $strings['everyonecannowchoose'] = get_string('everyonecannowchoose', 'moodleoverflow'); $strings['everyoneisnowsubscribed'] = get_string('everyoneisnowsubscribed', 'moodleoverflow'); @@ -88,7 +88,7 @@ } // Retrieve the user from the database. - $user = $DB->get_record('user', array('id' => $user), '*', MUST_EXIST); + $user = $DB->get_record('user', ['id' => $user], '*', MUST_EXIST); } else { @@ -114,13 +114,13 @@ if (isguestuser()) { echo $OUTPUT->header(); $message = $strings['subscribeenrolledonly'] . '
' . get_string('liketologin'); - $url = new moodle_url('/mod/moodleoverflow/view.php', array('m' => $id)); + $url = new moodle_url('/mod/moodleoverflow/view.php', ['m' => $id]); echo $OUTPUT->confirm($message, get_login_url(), $url); echo $OUTPUT->footer; exit; } else { // There should not be any links leading to this place. Just redirect. - $url = new moodle_url('/mod/moodleoverflow/view.php', array('m' => $id)); + $url = new moodle_url('/mod/moodleoverflow/view.php', ['m' => $id]); redirect($url, $strings['subscribeenrolledonly'], null, $notify['error']); } } @@ -207,7 +207,7 @@ echo $OUTPUT->header(); // Create an url to get back to the view. - $viewurl = new moodle_url('/mod/moodleoverflow/view.php', array('m' => $id)); + $viewurl = new moodle_url('/mod/moodleoverflow/view.php', ['m' => $id]); // Was a discussion id submitted? if ($discussionid) { @@ -262,7 +262,7 @@ // The user needs to be subscribed. // Check the capabilities. - $capabilities = array(); + $capabilities = []; $capabilities['managesubscriptions'] = has_capability('mod/moodleoverflow:managesubscriptions', $context); $capabilities['viewdiscussion'] = has_capability('mod/moodleoverflow:viewdiscussion', $context); require_sesskey(); @@ -287,7 +287,7 @@ echo $OUTPUT->header(); // Create the url to redirect the user back to. - $viewurl = new moodle_url('/mod/moodleoverflow/view.php', array('m' => $id)); + $viewurl = new moodle_url('/mod/moodleoverflow/view.php', ['m' => $id]); // Check whether a discussion is referenced. if ($discussionid) { diff --git a/tests/behat/behat_mod_moodleoverflow.php b/tests/behat/behat_mod_moodleoverflow.php index 709dae2ef6..4569c1c2ca 100644 --- a/tests/behat/behat_mod_moodleoverflow.php +++ b/tests/behat/behat_mod_moodleoverflow.php @@ -103,7 +103,7 @@ protected function add_new_discussion($moodleoverflowname, TableNode $table, $bu // Navigate to moodleoverflow. $this->execute('behat_navigation::i_am_on_page_instance', [$this->escape($moodleoverflowname), - 'moodleoverflow activity']); + 'moodleoverflow activity', ]); $this->execute('behat_forms::press_button', $buttonstr); // Fill form and post. diff --git a/tests/dailymail_test.php b/tests/dailymail_test.php index 26447424b1..922050e033 100644 --- a/tests/dailymail_test.php +++ b/tests/dailymail_test.php @@ -72,7 +72,7 @@ public function setUp(): void { $this->redirectMessages(); // Create a new course with a moodleoverflow forum. $this->course = $this->getDataGenerator()->create_course(); - $location = array('course' => $this->course->id, 'forcesubscribe' => MOODLEOVERFLOW_FORCESUBSCRIBE); + $location = ['course' => $this->course->id, 'forcesubscribe' => MOODLEOVERFLOW_FORCESUBSCRIBE]; $this->moodleoverflow = $this->getDataGenerator()->create_module('moodleoverflow', $location); $this->coursemodule = get_coursemodule_from_instance('moodleoverflow', $this->moodleoverflow->id); } @@ -94,7 +94,7 @@ public function tearDown(): void { */ public function helper_create_user_and_discussion($maildigest) { // Create a user enrolled in the course as student. - $this->user = $this->getDataGenerator()->create_user(array('firstname' => 'Tamaro', 'maildigest' => $maildigest)); + $this->user = $this->getDataGenerator()->create_user(['firstname' => 'Tamaro', 'maildigest' => $maildigest]); $this->getDataGenerator()->enrol_user($this->user->id, $this->course->id, 'student'); // Create a new discussion and post within the moodleoverflow. @@ -215,7 +215,7 @@ public function test_records_removed() { $this->helper_run_send_daily_mail(); // Now check the database if the records of the users are deleted. - $records = $DB->get_records('moodleoverflow_mail_info', array('userid' => $this->user->id)); + $records = $DB->get_records('moodleoverflow_mail_info', ['userid' => $this->user->id]); $this->assertEmpty($records); } } diff --git a/tests/discussion_test.php b/tests/discussion_test.php index a23af66642..9f1110713e 100644 --- a/tests/discussion_test.php +++ b/tests/discussion_test.php @@ -97,11 +97,11 @@ public function test_create_discussion() { $post = $posts[$discussion->get_firstpostid()]; // The discussion and the firstpost should be in the DB. - $dbdiscussion = $DB->get_record('moodleoverflow_discussions', array('id' => $discussion->get_id())); + $dbdiscussion = $DB->get_record('moodleoverflow_discussions', ['id' => $discussion->get_id()]); $this->assertEquals($dbdiscussion->id, $discussionid); $this->assertEquals('Discussion Topic', $dbdiscussion->name); - $dbpost = $DB->get_record('moodleoverflow_posts', array('id' => $discussion->get_firstpostid())); + $dbpost = $DB->get_record('moodleoverflow_posts', ['id' => $discussion->get_firstpostid()]); $this->assertEquals($dbpost->id, $post->get_id()); $this->assertEquals($dbpost->discussion, $post->get_discussionid()); $this->assertEquals($prepost->message, $dbpost->message); @@ -123,10 +123,10 @@ public function test_delete_discussion() { $this->discussion->moodleoverflow_delete_discussion($prepost); // The discussion and the post should not be in the DB anymore. - $discussion = count($DB->get_records('moodleoverflow_discussions', array('id' => $discussionid))); + $discussion = count($DB->get_records('moodleoverflow_discussions', ['id' => $discussionid])); $this->assertEquals(0, $discussion); - $post = count($DB->get_records('moodleoverflow_posts', array('id' => $postid))); + $post = count($DB->get_records('moodleoverflow_posts', ['id' => $postid])); $this->assertEquals(0, $post); } @@ -139,13 +139,13 @@ private function helper_course_set_up() { global $DB; // Create a new course with a moodleoverflow forum. $this->course = $this->getDataGenerator()->create_course(); - $location = array('course' => $this->course->id); + $location = ['course' => $this->course->id]; $this->moodleoverflow = $this->getDataGenerator()->create_module('moodleoverflow', $location); $this->coursemodule = get_coursemodule_from_instance('moodleoverflow', $this->moodleoverflow->id); $this->modulecontext = \context_module::instance($this->coursemodule->id); // Create a teacher. - $this->teacher = $this->getDataGenerator()->create_user(array('firstname' => 'Tamaro', 'lastname' => 'Walter')); + $this->teacher = $this->getDataGenerator()->create_user(['firstname' => 'Tamaro', 'lastname' => 'Walter']); $this->getDataGenerator()->enrol_user($this->teacher->id, $this->course->id, 'student'); // Create a discussion started from the teacher. @@ -153,8 +153,8 @@ private function helper_course_set_up() { $discussion = $this->generator->post_to_forum($this->moodleoverflow, $this->teacher); // Get the discussion and post object. - $discussionrecord = $DB->get_record('moodleoverflow_discussions', array('id' => $discussion[0]->id)); - $postrecord = $DB->get_record('moodleoverflow_posts', array('id' => $discussion[1]->id)); + $discussionrecord = $DB->get_record('moodleoverflow_discussions', ['id' => $discussion[0]->id]); + $postrecord = $DB->get_record('moodleoverflow_posts', ['id' => $discussion[1]->id]); $this->discussion = discussion::from_record($discussionrecord); $this->post = post::from_record($postrecord); diff --git a/tests/generator/lib.php b/tests/generator/lib.php index ace760b258..a089878295 100644 --- a/tests/generator/lib.php +++ b/tests/generator/lib.php @@ -165,7 +165,7 @@ public function create_discussion($record = null, $forum = null) { $record->id = moodleoverflow_add_discussion($record, $modulecontext, $record->userid); if (isset($timemodified) || isset($mailed)) { - $post = $DB->get_record('moodleoverflow_posts', array('discussion' => $record->id)); + $post = $DB->get_record('moodleoverflow_posts', ['discussion' => $record->id]); if (isset($mailed)) { $post->mailed = $mailed; @@ -180,7 +180,7 @@ public function create_discussion($record = null, $forum = null) { $DB->update_record('moodleoverflow_discussions', $record); } - $discussion = $DB->get_record('moodleoverflow_discussions', array('id' => $record->id)); + $discussion = $DB->get_record('moodleoverflow_discussions', ['id' => $record->id]); // Return the discussion object. return $discussion; @@ -313,9 +313,9 @@ public function post_to_forum($forum, $author, $record = null) { $record->moodleoverflow = $forum->id; $discussion = $this->create_discussion($record, $forum, $record); // Retrieve the post which was created by create_discussion. - $post = $DB->get_record('moodleoverflow_posts', array('discussion' => $discussion->id)); + $post = $DB->get_record('moodleoverflow_posts', ['discussion' => $discussion->id]); - return array($discussion, $post); + return [$discussion, $post]; } /** @@ -327,7 +327,7 @@ public function post_to_forum($forum, $author, $record = null) { public function update_post_time($post, $factor) { global $DB; // Update the post to have a created in the past. - $DB->set_field('moodleoverflow_posts', 'created', $post->created + $factor, array('id' => $post->id)); + $DB->set_field('moodleoverflow_posts', 'created', $post->created + $factor, ['id' => $post->id]); } /** @@ -339,9 +339,9 @@ public function update_post_time($post, $factor) { */ public function update_subscription_time($user, $discussion, $factor) { global $DB; - $sub = $DB->get_record('moodleoverflow_discuss_subs', array('userid' => $user->id, 'discussion' => $discussion->id)); + $sub = $DB->get_record('moodleoverflow_discuss_subs', ['userid' => $user->id, 'discussion' => $discussion->id]); // Update the subscription to have a preference in the past. - $DB->set_field('moodleoverflow_discuss_subs', 'preference', $sub->preference + $factor, array('id' => $sub->id)); + $DB->set_field('moodleoverflow_discuss_subs', 'preference', $sub->preference + $factor, ['id' => $sub->id]); } /** @@ -379,7 +379,7 @@ public function reply_to_post($parent, $author, $straighttodb = true) { $record = (object) [ 'discussion' => $parent->discussion, 'parent' => $parent->id, - 'userid' => $author->id + 'userid' => $author->id, ]; return $this->create_post($record, $straighttodb); } diff --git a/tests/locallib_test.php b/tests/locallib_test.php index 6d03e704c2..cc3fb54265 100644 --- a/tests/locallib_test.php +++ b/tests/locallib_test.php @@ -57,7 +57,7 @@ public function test_moodleoverflow_auto_subscribe_on_create() { $usercount = 5; $course = $this->getDataGenerator()->create_course(); - $users = array(); + $users = []; for ($i = 0; $i < $usercount; $i++) { $user = $this->getDataGenerator()->create_user(); @@ -65,11 +65,11 @@ public function test_moodleoverflow_auto_subscribe_on_create() { $this->getDataGenerator()->enrol_user($user->id, $course->id); } - $options = array('course' => $course->id, 'forcesubscribe' => MOODLEOVERFLOW_INITIALSUBSCRIBE); // Automatic Subscription. + $options = ['course' => $course->id, 'forcesubscribe' => MOODLEOVERFLOW_INITIALSUBSCRIBE]; // Automatic Subscription. $mo = $this->getDataGenerator()->create_module('moodleoverflow', $options); // Get the module context. - $cm = $DB->get_record('course_modules', array('id' => $mo->cmid)); + $cm = $DB->get_record('course_modules', ['id' => $mo->cmid]); $context = \context_module::instance($cm->id); $result = \mod_moodleoverflow\subscriptions::get_subscribed_users($mo, $context); @@ -90,7 +90,7 @@ public function test_moodleoverflow_forced_subscribe_on_create() { $usercount = 5; $course = $this->getDataGenerator()->create_course(); - $users = array(); + $users = []; for ($i = 0; $i < $usercount; $i++) { $user = $this->getDataGenerator()->create_user(); @@ -98,10 +98,10 @@ public function test_moodleoverflow_forced_subscribe_on_create() { $this->getDataGenerator()->enrol_user($user->id, $course->id); } - $options = array('course' => $course->id, 'forcesubscribe' => MOODLEOVERFLOW_FORCESUBSCRIBE); + $options = ['course' => $course->id, 'forcesubscribe' => MOODLEOVERFLOW_FORCESUBSCRIBE]; $mo = $this->getDataGenerator()->create_module('moodleoverflow', $options); - $cm = $DB->get_record('course_modules', array('id' => $mo->cmid)); + $cm = $DB->get_record('course_modules', ['id' => $mo->cmid]); $context = \context_module::instance($cm->id); $result = \mod_moodleoverflow\subscriptions::get_subscribed_users($mo, $context); @@ -122,7 +122,7 @@ public function test_moodleoverflow_optional_subscribe_on_create() { $usercount = 5; $course = $this->getDataGenerator()->create_course(); - $users = array(); + $users = []; for ($i = 0; $i < $usercount; $i++) { $user = $this->getDataGenerator()->create_user(); @@ -130,9 +130,9 @@ public function test_moodleoverflow_optional_subscribe_on_create() { $this->getDataGenerator()->enrol_user($user->id, $course->id); } - $options = array('course' => $course->id, 'forcesubscribe' => MOODLEOVERFLOW_CHOOSESUBSCRIBE); // Subscription optional. + $options = ['course' => $course->id, 'forcesubscribe' => MOODLEOVERFLOW_CHOOSESUBSCRIBE]; // Subscription optional. $mo = $this->getDataGenerator()->create_module('moodleoverflow', $options); - $cm = $DB->get_record('course_modules', array('id' => $mo->cmid)); + $cm = $DB->get_record('course_modules', ['id' => $mo->cmid]); $context = \context_module::instance($cm->id); $result = \mod_moodleoverflow\subscriptions::get_subscribed_users($mo, $context); @@ -153,7 +153,7 @@ public function test_moodleoverflow_disallow_subscribe_on_create() { $usercount = 5; $course = $this->getDataGenerator()->create_course(); - $users = array(); + $users = []; for ($i = 0; $i < $usercount; $i++) { $user = $this->getDataGenerator()->create_user(); @@ -161,9 +161,9 @@ public function test_moodleoverflow_disallow_subscribe_on_create() { $this->getDataGenerator()->enrol_user($user->id, $course->id); } - $options = array('course' => $course->id, 'forcesubscribe' => MOODLEOVERFLOW_DISALLOWSUBSCRIBE); // Subscription prevented. + $options = ['course' => $course->id, 'forcesubscribe' => MOODLEOVERFLOW_DISALLOWSUBSCRIBE]; // Subscription prevented. $mo = $this->getDataGenerator()->create_module('moodleoverflow', $options); - $cm = $DB->get_record('course_modules', array('id' => $mo->cmid)); + $cm = $DB->get_record('course_modules', ['id' => $mo->cmid]); $context = \context_module::instance($cm->id); $result = \mod_moodleoverflow\subscriptions::get_subscribed_users($mo, $context); diff --git a/tests/post_test.php b/tests/post_test.php index 9d7d7fc597..0f9c754f13 100644 --- a/tests/post_test.php +++ b/tests/post_test.php @@ -89,7 +89,7 @@ public function test_create_post() { $post->moodleoverflow_add_new_post(); // The post should be in the database. - $postscount = count($DB->get_records('moodleoverflow_posts', array('id' => $post->get_id()))); + $postscount = count($DB->get_records('moodleoverflow_posts', ['id' => $post->get_id()])); $this->assertEquals(1, $postscount); } @@ -100,9 +100,9 @@ public function test_edit_post() { global $DB; // The post and the attachment should exist. - $numberofattachments = count($DB->get_records('files', array('itemid' => $this->post->get_id()))); + $numberofattachments = count($DB->get_records('files', ['itemid' => $this->post->get_id()])); $this->assertEquals(2, $numberofattachments); // One Attachment is saved twice in 'files'. - $post = count($DB->get_records('moodleoverflow_posts', array('id' => $this->post->get_id()))); + $post = count($DB->get_records('moodleoverflow_posts', ['id' => $this->post->get_id()])); $this->assertEquals(1, $post); // Gather important parameters. @@ -113,7 +113,7 @@ public function test_edit_post() { $this->post->moodleoverflow_edit_post($time, $message, $this->post->messageformat, $this->post->formattachments); // The message and modified time should be changed. - $post = $DB->get_record('moodleoverflow_posts', array('id' => $this->post->get_id())); + $post = $DB->get_record('moodleoverflow_posts', ['id' => $this->post->get_id()]); $this->assertEquals($message, $post->message); $this->assertEquals($time, $post->modified); } @@ -126,9 +126,9 @@ public function test_delete_post() { global $DB; // The post and the attachment should exist. - $numberofattachments = count($DB->get_records('files', array('itemid' => $this->post->get_id()))); + $numberofattachments = count($DB->get_records('files', ['itemid' => $this->post->get_id()])); $this->assertEquals(2, $numberofattachments); // One Attachment is saved twice in 'files'. - $post = count($DB->get_records('moodleoverflow_posts', array('id' => $this->post->get_id()))); + $post = count($DB->get_records('moodleoverflow_posts', ['id' => $this->post->get_id()])); $this->assertEquals(1, $post); // Delete the post with its attachment. @@ -137,11 +137,11 @@ public function test_delete_post() { $this->post->moodleoverflow_delete_post(true); // Now try to get the attachment, it should be deleted from the database. - $numberofattachments = count($DB->get_records('files', array('itemid' => $postid))); + $numberofattachments = count($DB->get_records('files', ['itemid' => $postid])); $this->assertEquals(0, $numberofattachments); // Try to find the post, it should be deleted. - $post = count($DB->get_records('moodleoverflow_posts', array('id' => $postid))); + $post = count($DB->get_records('moodleoverflow_posts', ['id' => $postid])); $this->assertEquals(0, $post); } @@ -154,29 +154,29 @@ private function helper_course_set_up() { global $DB; // Create a new course with a moodleoverflow forum. $this->course = $this->getDataGenerator()->create_course(); - $location = array('course' => $this->course->id); + $location = ['course' => $this->course->id]; $this->moodleoverflow = $this->getDataGenerator()->create_module('moodleoverflow', $location); $this->coursemodule = get_coursemodule_from_instance('moodleoverflow', $this->moodleoverflow->id); $this->modulecontext = \context_module::instance($this->coursemodule->id); // Create a teacher. - $this->teacher = $this->getDataGenerator()->create_user(array('firstname' => 'Tamaro', 'lastname' => 'Walter')); + $this->teacher = $this->getDataGenerator()->create_user(['firstname' => 'Tamaro', 'lastname' => 'Walter']); $this->getDataGenerator()->enrol_user($this->teacher->id, $this->course->id, 'student'); // Create a discussion started from the teacher. $this->generator = $this->getDataGenerator()->get_plugin_generator('mod_moodleoverflow'); $discussion = $this->generator->post_to_forum($this->moodleoverflow, $this->teacher); - $discussionrecord = $DB->get_record('moodleoverflow_discussions', array('id' => $discussion[0]->id)); + $discussionrecord = $DB->get_record('moodleoverflow_discussions', ['id' => $discussion[0]->id]); $this->discussion = discussion::from_record($discussionrecord); // Get a temporary post from the DB to add the attachment. - $temppost = $DB->get_record('moodleoverflow_posts', array('id' => $this->discussion->get_firstpostid())); + $temppost = $DB->get_record('moodleoverflow_posts', ['id' => $this->discussion->get_firstpostid()]); // Create an attachment by inserting it directly in the database and update the post record. $this->add_new_attachment($temppost, $this->modulecontext, 'world.txt', 'hello world'); // Build the real post object now. That is the object that will be tested. - $postrecord = $DB->get_record('moodleoverflow_posts', array('id' => $this->discussion->get_firstpostid())); + $postrecord = $DB->get_record('moodleoverflow_posts', ['id' => $this->discussion->get_firstpostid()]); $this->post = post::from_record($postrecord); } diff --git a/tests/privacy_provider_test.php b/tests/privacy_provider_test.php index c4d10fc712..d8b3c489a2 100644 --- a/tests/privacy_provider_test.php +++ b/tests/privacy_provider_test.php @@ -27,8 +27,8 @@ global $CFG; use core_privacy\local\request\approved_contextlist; -use \core_privacy\local\request\userlist; -use \mod_moodleoverflow\privacy\provider; +use core_privacy\local\request\userlist; +use mod_moodleoverflow\privacy\provider; use mod_moodleoverflow\privacy\data_export_helper; /** @@ -307,7 +307,7 @@ public function test_user_has_rated_others() { $cm = get_coursemodule_from_instance('moodleoverflow', $forum->id); $context = \context_module::instance($cm->id); // Rate the other users content. - $rating = array(); + $rating = []; $rating['moodleoverflowid'] = $forum->id; $rating['discussionid'] = $discussion->id; $rating['userid'] = $user->id; @@ -351,7 +351,7 @@ public function test_user_has_been_rated() { $context = \context_module::instance($cm->id); // Other users rate my content. // Rate the other users content. - $rating = array(); + $rating = []; $rating['moodleoverflowid'] = $forum->id; $rating['discussionid'] = $discussion->id; $rating['userid'] = $otheruser->id; @@ -645,7 +645,7 @@ public function test_all_users_deleted_from_context() { if ($post->userid != $user->id) { $ratedposts[$post->id] = $post; - $rating = array(); + $rating = []; $rating['moodleoverflowid'] = $forum->id; $rating['discussionid'] = $discussion->id; $rating['userid'] = $user->id; @@ -687,7 +687,7 @@ public function test_all_users_deleted_from_context() { } // All ratings should have been deleted. foreach ($postsinforum as $post) { - $ratings = $DB->get_records('moodleoverflow_ratings', array('postid' => $post->id)); + $ratings = $DB->get_records('moodleoverflow_ratings', ['postid' => $post->id]); $this->assertEmpty($ratings); } @@ -716,7 +716,7 @@ public function test_all_users_deleted_from_context() { if (!isset($ratedposts[$post->id])) { continue; } - $ratings = $DB->get_records('moodleoverflow_ratings', array('postid' => $post->id)); + $ratings = $DB->get_records('moodleoverflow_ratings', ['postid' => $post->id]); $this->assertNotEmpty($ratings); } } @@ -797,7 +797,7 @@ public function test_delete_data_for_user() { if ($post->userid != $user->id) { $ratedposts[$post->id] = $post; - $rating = array(); + $rating = []; $rating['moodleoverflowid'] = $forum->id; $rating['discussionid'] = $discussion->id; $rating['userid'] = $user->id; @@ -868,7 +868,7 @@ public function test_delete_data_for_user() { )); // Ratings should have been anonymized. - $this->assertCount(16, $DB->get_records('moodleoverflow_ratings', array('userid' => 0))); + $this->assertCount(16, $DB->get_records('moodleoverflow_ratings', ['userid' => 0])); // File count: (5 users * 2 forums * 1 file) = 10. // Files for the affected posts should be removed. @@ -892,7 +892,7 @@ protected function create_courses_and_modules($count) { $forum = $this->getDataGenerator()->create_module('moodleoverflow', ['course' => $course->id]); } - return array($course, $forum); + return [$course, $forum]; } /** @@ -906,7 +906,7 @@ protected function create_courses_and_modules($count) { * @return array The users created */ protected function create_users($course, $count) { - $users = array(); + $users = []; for ($i = 0; $i < $count; $i++) { $user = $this->getDataGenerator()->create_user(); $this->getDataGenerator()->enrol_user($user->id, $course->id); @@ -925,7 +925,7 @@ protected function create_users($course, $count) { * @return array The users created */ protected function create_and_enrol_users($course, $count) { - $users = array(); + $users = []; for ($i = 0; $i < $count; $i++) { $users[$i] = $this->getDataGenerator()->create_user(); $this->getDataGenerator()->enrol_user($users[$i]->id, $course->id); @@ -1039,7 +1039,7 @@ public function test_delete_data_for_users() { 'moodleoverflowid' => $moodleoverflow->id, 'rating' => 1, 'firstrated' => $time, - 'lastchanged' => $time + 'lastchanged' => $time, ]; // Inserts a rating into the table. $DB->insert_record('moodleoverflow_ratings', $rating); @@ -1213,7 +1213,7 @@ public function test_get_users_in_context_post_ratings() { 'moodleoverflowid' => $moodleoverflow->id, 'rating' => 1, 'firstrated' => $time, - 'lastchanged' => $time + 'lastchanged' => $time, ]; // Inserts a rating into the table. $DB->insert_record('moodleoverflow_ratings', $rating); @@ -1429,7 +1429,7 @@ public function test_grades() { 'course' => $course->id, 'scale' => 100, 'grademaxgrade' => 50, - 'gradescalefactor' => 2 + 'gradescalefactor' => 2, ]); $cm = get_coursemodule_from_instance('moodleoverflow', $forum->id); $context = \context_module::instance($cm->id); @@ -1439,7 +1439,7 @@ public function test_grades() { \mod_moodleoverflow\ratings::moodleoverflow_add_rating($forum, $post->id, RATING_UPVOTE, $cm, $user2->id); moodleoverflow_update_all_grades_for_cm($forum->id); $grades = grade_get_grades($course->id, 'mod', 'moodleoverflow', $forum->id, - array($user->id, $user2->id)); + [$user->id, $user2->id]); self::assertEquals("2.50", $grades->items[0]->grades[$user->id]->str_grade); self::assertEquals("0.50", $grades->items[0]->grades[$user2->id]->str_grade); @@ -1456,16 +1456,14 @@ public function test_grades() { self::assertContains("$context->id", $contextlist->get_contextids()); provider::delete_data_for_user($contextlist); moodleoverflow_update_all_grades_for_cm($forum->id); - $grades = $DB->get_records('moodleoverflow_grades', array('moodleoverflowid' => $forum->id), null, - 'userid, grade'); + $grades = $DB->get_records('moodleoverflow_grades', ['moodleoverflowid' => $forum->id], null, 'userid, grade'); self::assertEquals(2.5, $grades[$user->id]->grade); self::assertArrayNotHasKey($user2->id, $grades); // Test delete context. provider::delete_data_for_all_users_in_context($context); moodleoverflow_update_all_grades_for_cm($forum->id); - $grades = $DB->get_records('moodleoverflow_grades', array('moodleoverflowid' => $forum->id), null, - 'userid, grade'); + $grades = $DB->get_records('moodleoverflow_grades', ['moodleoverflowid' => $forum->id], null, 'userid, grade'); self::assertEmpty($grades); } } diff --git a/tests/ratings_test.php b/tests/ratings_test.php index a74de7e581..0110710dc9 100644 --- a/tests/ratings_test.php +++ b/tests/ratings_test.php @@ -23,6 +23,7 @@ */ namespace mod_moodleoverflow; use mod_moodleoverflow\ratings; +use stdClass; defined('MOODLE_INTERNAL') || die(); @@ -38,46 +39,46 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class ratings_test extends \advanced_testcase { - /** @var \stdClass test course */ + /** @var stdClass test course */ private $course; - /** @var \stdClass coursemodule */ + /** @var stdClass coursemodule */ private $coursemodule; - /** @var \stdClass test moodleoverflow */ + /** @var stdClass test moodleoverflow */ private $moodleoverflow; - /** @var \stdClass test teacher */ + /** @var stdClass test teacher */ private $teacher; - /** @var \stdClass test user */ + /** @var stdClass test user */ private $user1; - /** @var \stdClass another test user */ + /** @var stdClass another test user */ private $user2; - /** @var \stdClass a discussion */ + /** @var stdClass a discussion */ private $discussion; - /** @var \stdClass a post from the teacher*/ + /** @var stdClass a post from the teacher*/ private $post; - /** @var \stdClass answer from user 1 */ + /** @var stdClass answer from user 1 */ private $answer1; - /** @var \stdClass answer from user 1 */ + /** @var stdClass answer from user 1 */ private $answer2; - /** @var \stdClass answer from user 1 */ + /** @var stdClass answer from user 1 */ private $answer3; - /** @var \stdClass answer from user 2 */ + /** @var stdClass answer from user 2 */ private $answer4; - /** @var \stdClass answer from user 2 */ + /** @var stdClass answer from user 2 */ private $answer5; - /** @var \stdClass answer from user 2 */ + /** @var stdClass answer from user 2 */ private $answer6; /** @var \mod_moodleoverflow_generator $generator */ @@ -114,19 +115,19 @@ public function test_answersorting_everygroup() { // Test with every group of rating. // Create a array of the posts, save the sorted post and compare them to the order that they should have. - $posts = array($this->post, $this->answer1, $this->answer2, $this->answer3, $this->answer4, $this->answer5, $this->answer6); + $posts = [$this->post, $this->answer1, $this->answer2, $this->answer3, $this->answer4, $this->answer5, $this->answer6]; $this->set_ratingpreferences(0); $sortedposts = ratings::moodleoverflow_sort_answers_by_ratings($posts); - $rightorderposts = array($this->post, $this->answer1, $this->answer3, $this->answer2, - $this->answer4, $this->answer6, $this->answer5); + $rightorderposts = [$this->post, $this->answer1, $this->answer3, $this->answer2, + $this->answer4, $this->answer6, $this->answer5, ]; $result = $this->postsorderequal($sortedposts, $rightorderposts); $this->assertEquals(1, $result); // Change the rating preference of the teacher and sort again. $this->set_ratingpreferences(1); $sortedposts = ratings::moodleoverflow_sort_answers_by_ratings($posts); - $rightorderposts = array($this->post, $this->answer1, $this->answer2, $this->answer3, - $this->answer4, $this->answer6, $this->answer5); + $rightorderposts = [$this->post, $this->answer1, $this->answer2, $this->answer3, + $this->answer4, $this->answer6, $this->answer5, ]; $result = $this->postsorderequal($sortedposts, $rightorderposts); $this->assertEquals(1, $result); } @@ -141,44 +142,44 @@ public function test_answersorting_threegroups() { $this->create_everygroup(); // Test without posts that are only marked as solved. - $posts = array($this->post, $this->answer1, $this->answer3, $this->answer4, $this->answer5, $this->answer6); + $posts = [$this->post, $this->answer1, $this->answer3, $this->answer4, $this->answer5, $this->answer6]; $this->set_ratingpreferences(0); $sortedposts = ratings::moodleoverflow_sort_answers_by_ratings($posts); - $rightorderposts = array($this->post, $this->answer1, $this->answer3, $this->answer4, $this->answer6, $this->answer5); + $rightorderposts = [$this->post, $this->answer1, $this->answer3, $this->answer4, $this->answer6, $this->answer5]; $result = $this->postsorderequal($sortedposts, $rightorderposts); $this->assertEquals(1, $result); $this->set_ratingpreferences(1); $sortedposts = ratings::moodleoverflow_sort_answers_by_ratings($posts); - $rightorderposts = array($this->post, $this->answer1, $this->answer3, $this->answer4, $this->answer6, $this->answer5); + $rightorderposts = [$this->post, $this->answer1, $this->answer3, $this->answer4, $this->answer6, $this->answer5]; $result = $this->postsorderequal($sortedposts, $rightorderposts); $this->assertEquals(1, $result); // Test without posts that are only marked as helpful. - $posts = array($this->post, $this->answer1, $this->answer2, $this->answer4, $this->answer5, $this->answer6); + $posts = [$this->post, $this->answer1, $this->answer2, $this->answer4, $this->answer5, $this->answer6]; $this->set_ratingpreferences(0); $sortedposts = ratings::moodleoverflow_sort_answers_by_ratings($posts); - $rightorderposts = array($this->post, $this->answer1, $this->answer2, $this->answer4, $this->answer6, $this->answer5); + $rightorderposts = [$this->post, $this->answer1, $this->answer2, $this->answer4, $this->answer6, $this->answer5]; $result = $this->postsorderequal($sortedposts, $rightorderposts); $this->assertEquals(1, $result); $this->set_ratingpreferences(1); $sortedposts = ratings::moodleoverflow_sort_answers_by_ratings($posts); - $rightorderposts = array($this->post, $this->answer1, $this->answer2, $this->answer4, $this->answer6, $this->answer5); + $rightorderposts = [$this->post, $this->answer1, $this->answer2, $this->answer4, $this->answer6, $this->answer5]; $result = $this->postsorderequal($sortedposts, $rightorderposts); $this->assertEquals(1, $result); // Test without posts that are marked as both helpful and solved. - $posts = array($this->post, $this->answer2, $this->answer3, $this->answer4, $this->answer5, $this->answer6); + $posts = [$this->post, $this->answer2, $this->answer3, $this->answer4, $this->answer5, $this->answer6]; $this->set_ratingpreferences(0); $sortedposts = ratings::moodleoverflow_sort_answers_by_ratings($posts); - $rightorderposts = array($this->post, $this->answer3, $this->answer2, $this->answer4, $this->answer6, $this->answer5); + $rightorderposts = [$this->post, $this->answer3, $this->answer2, $this->answer4, $this->answer6, $this->answer5]; $result = $this->postsorderequal($sortedposts, $rightorderposts); $this->assertEquals(1, $result); $this->set_ratingpreferences(1); $sortedposts = ratings::moodleoverflow_sort_answers_by_ratings($posts); - $rightorderposts = array($this->post, $this->answer2, $this->answer3, $this->answer4, $this->answer6, $this->answer5); + $rightorderposts = [$this->post, $this->answer2, $this->answer3, $this->answer4, $this->answer6, $this->answer5]; $result = $this->postsorderequal($sortedposts, $rightorderposts); $this->assertEquals(1, $result); } @@ -208,8 +209,8 @@ public function test_answersorting_twogroups() { $group1 = 's'; $group2 = 'h'; $this->set_ratingpreferences(0); - $rightorderposts = array($this->post, $this->answer6, $this->answer5, $this->answer4, - $this->answer2, $this->answer1, $this->answer3); + $rightorderposts = [$this->post, $this->answer6, $this->answer5, $this->answer4, + $this->answer2, $this->answer1, $this->answer3, ]; $this->process_groups($group1, $group2, $rightorderposts); // Test case 5: only solved posts and only helpful posts with ratingpreferences = 1. @@ -219,10 +220,10 @@ public function test_answersorting_twogroups() { // Test case 6: only solved posts and not-marked posts. $group2 = 'o'; $this->create_twogroups($group1, $group2); - $posts = array($this->post, $this->answer1, $this->answer2, $this->answer3, $this->answer4, $this->answer5, $this->answer6); + $posts = [$this->post, $this->answer1, $this->answer2, $this->answer3, $this->answer4, $this->answer5, $this->answer6]; $sortedposts = ratings::moodleoverflow_sort_answers_by_ratings($posts); - $rightorderposts = array($this->post, $this->answer2, $this->answer1, $this->answer3, - $this->answer6, $this->answer5, $this->answer4); + $rightorderposts = [$this->post, $this->answer2, $this->answer1, $this->answer3, + $this->answer6, $this->answer5, $this->answer4, ]; $result = $this->postsorderequal($sortedposts, $rightorderposts); $this->assertEquals(1, $result); @@ -246,40 +247,40 @@ public function test_answersorting_onegroup() { // Test case 1: only solved and helpful posts. $group = 'sh'; $this->create_onegroup($group); - $posts = array($this->post, $this->answer1, $this->answer2, $this->answer3, $this->answer4, $this->answer5, $this->answer6); + $posts = [$this->post, $this->answer1, $this->answer2, $this->answer3, $this->answer4, $this->answer5, $this->answer6]; $sortedposts = ratings::moodleoverflow_sort_answers_by_ratings($posts); - $rightorderposts = array($this->post, $this->answer4, $this->answer6, $this->answer3, - $this->answer1, $this->answer2, $this->answer5); + $rightorderposts = [$this->post, $this->answer4, $this->answer6, $this->answer3, + $this->answer1, $this->answer2, $this->answer5, ]; $result = $this->postsorderequal($sortedposts, $rightorderposts); $this->assertEquals(1, $result); // Test case 1: only solvedposts. $group = 's'; $this->create_onegroup($group); - $posts = array($this->post, $this->answer1, $this->answer2, $this->answer3, $this->answer4, $this->answer5, $this->answer6); + $posts = [$this->post, $this->answer1, $this->answer2, $this->answer3, $this->answer4, $this->answer5, $this->answer6]; $sortedposts = ratings::moodleoverflow_sort_answers_by_ratings($posts); - $rightorderposts = array($this->post, $this->answer4, $this->answer6, $this->answer3, - $this->answer1, $this->answer2, $this->answer5); + $rightorderposts = [$this->post, $this->answer4, $this->answer6, $this->answer3, + $this->answer1, $this->answer2, $this->answer5, ]; $result = $this->postsorderequal($sortedposts, $rightorderposts); $this->assertEquals(1, $result); // Test case 1: only helpful posts. $group = 'h'; $this->create_onegroup($group); - $posts = array($this->post, $this->answer1, $this->answer2, $this->answer3, $this->answer4, $this->answer5, $this->answer6); + $posts = [$this->post, $this->answer1, $this->answer2, $this->answer3, $this->answer4, $this->answer5, $this->answer6]; $sortedposts = ratings::moodleoverflow_sort_answers_by_ratings($posts); - $rightorderposts = array($this->post, $this->answer4, $this->answer6, $this->answer3, - $this->answer1, $this->answer2, $this->answer5); + $rightorderposts = [$this->post, $this->answer4, $this->answer6, $this->answer3, + $this->answer1, $this->answer2, $this->answer5, ]; $result = $this->postsorderequal($sortedposts, $rightorderposts); $this->assertEquals(1, $result); // Test case 1: only not marked posts. $group = 'o'; $this->create_onegroup($group); - $posts = array($this->post, $this->answer1, $this->answer2, $this->answer3, $this->answer4, $this->answer5, $this->answer6); + $posts = [$this->post, $this->answer1, $this->answer2, $this->answer3, $this->answer4, $this->answer5, $this->answer6]; $sortedposts = ratings::moodleoverflow_sort_answers_by_ratings($posts); - $rightorderposts = array($this->post, $this->answer4, $this->answer6, $this->answer3, - $this->answer1, $this->answer2, $this->answer5); + $rightorderposts = [$this->post, $this->answer4, $this->answer6, $this->answer3, + $this->answer1, $this->answer2, $this->answer5, ]; $result = $this->postsorderequal($sortedposts, $rightorderposts); $this->assertEquals(1, $result); } @@ -296,24 +297,24 @@ private function helper_course_set_up() { global $DB; // Create a new course with a moodleoverflow forum. $this->course = $this->getDataGenerator()->create_course(); - $location = array('course' => $this->course->id); + $location = ['course' => $this->course->id]; $this->moodleoverflow = $this->getDataGenerator()->create_module('moodleoverflow', $location); $this->coursemodule = get_coursemodule_from_instance('moodleoverflow', $this->moodleoverflow->id); // Create a teacher. - $this->teacher = $this->getDataGenerator()->create_user(array('firstname' => 'Tamaro', 'lastname' => 'Walter')); + $this->teacher = $this->getDataGenerator()->create_user(['firstname' => 'Tamaro', 'lastname' => 'Walter']); $this->getDataGenerator()->enrol_user($this->teacher->id, $this->course->id, 'student'); // Create 2 users. - $this->user1 = $this->getDataGenerator()->create_user(array('firstname' => 'Ava', 'lastname' => 'Davis')); + $this->user1 = $this->getDataGenerator()->create_user(['firstname' => 'Ava', 'lastname' => 'Davis']); $this->getDataGenerator()->enrol_user($this->user1->id, $this->course->id, 'student'); - $this->user2 = $this->getDataGenerator()->create_user(array('firstname' => 'Ethan', 'lastname' => 'Brown')); + $this->user2 = $this->getDataGenerator()->create_user(['firstname' => 'Ethan', 'lastname' => 'Brown']); $this->getDataGenerator()->enrol_user($this->user2->id, $this->course->id, 'student'); // Create a discussion, a parent post and six answers. $this->generator = $this->getDataGenerator()->get_plugin_generator('mod_moodleoverflow'); $this->discussion = $this->generator->post_to_forum($this->moodleoverflow, $this->teacher); - $this->post = $DB->get_record('moodleoverflow_posts', array('id' => $this->discussion[0]->firstpost), '*'); + $this->post = $DB->get_record('moodleoverflow_posts', ['id' => $this->discussion[0]->firstpost], '*'); $this->answer1 = $this->generator->reply_to_post($this->discussion[1], $this->user1, true); $this->answer2 = $this->generator->reply_to_post($this->discussion[1], $this->user1, true); $this->answer3 = $this->generator->reply_to_post($this->discussion[1], $this->user1, true); @@ -431,7 +432,7 @@ private function create_everygroup() { * - no mark (o) */ private function create_onegroup($group) { - $answers = array($this->answer1, $this->answer2, $this->answer3, $this->answer4, $this->answer5, $this->answer6); + $answers = [$this->answer1, $this->answer2, $this->answer3, $this->answer4, $this->answer5, $this->answer6]; foreach ($answers as $answer) { switch ($group) { case 'sh': @@ -621,10 +622,10 @@ private function create_twogroups($group1, $group2) { */ private function process_groups(String $group1, string $group2, array $orderposts = null) { $this->create_twogroups($group1, $group2); - $posts = array($this->post, $this->answer1, $this->answer2, $this->answer3, $this->answer4, $this->answer5, $this->answer6); + $posts = [$this->post, $this->answer1, $this->answer2, $this->answer3, $this->answer4, $this->answer5, $this->answer6]; $sortedposts = ratings::moodleoverflow_sort_answers_by_ratings($posts); - $rightorderposts = array($this->post, $this->answer2, $this->answer1, $this->answer3, - $this->answer6, $this->answer5, $this->answer4); + $rightorderposts = [$this->post, $this->answer2, $this->answer1, $this->answer3, + $this->answer6, $this->answer5, $this->answer4, ]; if ($orderposts) { $rightorderposts = $orderposts; } diff --git a/tests/readtracking_test.php b/tests/readtracking_test.php index bb74a59553..a4bfa108d3 100644 --- a/tests/readtracking_test.php +++ b/tests/readtracking_test.php @@ -49,13 +49,13 @@ public function test_moodleoverflow_can_track_moodleoverflows() { $this->resetAfterTest(); $course = $this->getDataGenerator()->create_course(); - $options = array('course' => $course->id, 'trackingtype' => MOODLEOVERFLOW_TRACKING_OFF); // Off. + $options = ['course' => $course->id, 'trackingtype' => MOODLEOVERFLOW_TRACKING_OFF]; // Off. $mooff = $this->getDataGenerator()->create_module('moodleoverflow', $options); - $options = array('course' => $course->id, 'trackingtype' => MOODLEOVERFLOW_TRACKING_FORCED); // On. + $options = ['course' => $course->id, 'trackingtype' => MOODLEOVERFLOW_TRACKING_FORCED]; // On. $moforce = $this->getDataGenerator()->create_module('moodleoverflow', $options); - $options = array('course' => $course->id, 'trackingtype' => MOODLEOVERFLOW_TRACKING_OPTIONAL); // Optional. + $options = ['course' => $course->id, 'trackingtype' => MOODLEOVERFLOW_TRACKING_OPTIONAL]; // Optional. $mooptional = $this->getDataGenerator()->create_module('moodleoverflow', $options); // Allow force. @@ -98,13 +98,13 @@ public function test_moodleoverflow_is_tracked() { $course = $this->getDataGenerator()->create_course(); - $options = array('course' => $course->id, 'trackingtype' => MOODLEOVERFLOW_TRACKING_OPTIONAL); + $options = ['course' => $course->id, 'trackingtype' => MOODLEOVERFLOW_TRACKING_OPTIONAL]; $mooptional = $this->getDataGenerator()->create_module('moodleoverflow', $options); - $options = array('course' => $course->id, 'trackingtype' => MOODLEOVERFLOW_TRACKING_FORCED); + $options = ['course' => $course->id, 'trackingtype' => MOODLEOVERFLOW_TRACKING_FORCED]; $moforce = $this->getDataGenerator()->create_module('moodleoverflow', $options); - $options = array('course' => $course->id, 'trackingtype' => MOODLEOVERFLOW_TRACKING_OFF); + $options = ['course' => $course->id, 'trackingtype' => MOODLEOVERFLOW_TRACKING_OFF]; $mooff = $this->getDataGenerator()->create_module('moodleoverflow', $options); // Allow force. diff --git a/tests/review_test.php b/tests/review_test.php index 52f176c8f7..019f276086 100644 --- a/tests/review_test.php +++ b/tests/review_test.php @@ -112,8 +112,9 @@ public function test_forum_review_everything() { global $DB, $CFG; require_once($CFG->dirroot . '/mod/moodleoverflow/externallib.php'); - $options = array('course' => $this->course->id, 'needsreview' => review::EVERYTHING, - 'forcesubscribe' => MOODLEOVERFLOW_FORCESUBSCRIBE); + $options = ['course' => $this->course->id, + 'needsreview' => review::EVERYTHING, + 'forcesubscribe' => MOODLEOVERFLOW_FORCESUBSCRIBE, ]; $posts = $this->create_post($options); $this->check_mail_records($posts['teacherpost'], $posts['studentpost'], 1, 0, MOODLEOVERFLOW_MAILED_REVIEW_SUCCESS); @@ -177,8 +178,9 @@ public function test_forum_review_only_questions() { global $DB, $CFG; require_once($CFG->dirroot . '/mod/moodleoverflow/externallib.php'); - $options = array('course' => $this->course->id, 'needsreview' => review::QUESTIONS, - 'forcesubscribe' => MOODLEOVERFLOW_FORCESUBSCRIBE); + $options = ['course' => $this->course->id, + 'needsreview' => review::QUESTIONS, + 'forcesubscribe' => MOODLEOVERFLOW_FORCESUBSCRIBE, ]; $posts = $this->create_post($options); $this->check_mail_records($posts['teacherpost'], $posts['studentpost'], 1, 0, MOODLEOVERFLOW_MAILED_REVIEW_SUCCESS); @@ -215,8 +217,9 @@ public function test_forum_review_only_questions() { * Test reviews functionality when reviewing is allowed in admin settings. */ public function test_forum_review_disallowed() { - $options = array('course' => $this->course->id, 'needsreview' => review::EVERYTHING, - 'forcesubscribe' => MOODLEOVERFLOW_FORCESUBSCRIBE); + $options = ['course' => $this->course->id, + 'needsreview' => review::EVERYTHING, + 'forcesubscribe' => MOODLEOVERFLOW_FORCESUBSCRIBE, ]; set_config('allowreview', 0, 'moodleoverflow'); @@ -276,7 +279,7 @@ private function create_post($options) { list(, $teacherpost) = $this->generator->post_to_forum($moodleoverflow, $this->teacher); list(, $studentpost) = $this->generator->post_to_forum($moodleoverflow, $this->student); - return array('teacherpost' => $teacherpost, 'studentpost' => $studentpost); + return ['teacherpost' => $teacherpost, 'studentpost' => $studentpost]; } /** @@ -293,17 +296,17 @@ private function check_mail_records($teacherpost, $studentpost, $review1, $revie global $DB; $this->assert_matches_properties(['mailed' => MOODLEOVERFLOW_MAILED_PENDING, 'reviewed' => $review1, - 'timereviewed' => null], + 'timereviewed' => null, ], $DB->get_record('moodleoverflow_posts', ['id' => $teacherpost->id])); $this->assert_matches_properties(['mailed' => MOODLEOVERFLOW_MAILED_PENDING, 'reviewed' => $review2, - 'timereviewed' => null], + 'timereviewed' => null, ], $DB->get_record('moodleoverflow_posts', ['id' => $studentpost->id])); $this->run_send_mails(); $this->run_send_mails(); // Execute twice to ensure no duplicate mails. $this->assert_matches_properties(['mailed' => MOODLEOVERFLOW_MAILED_SUCCESS, 'reviewed' => $review1, - 'timereviewed' => null], + 'timereviewed' => null, ], $DB->get_record('moodleoverflow_posts', ['id' => $teacherpost->id])); $this->assert_matches_properties(['mailed' => $mailed, 'reviewed' => $review2, 'timereviewed' => null], $DB->get_record('moodleoverflow_posts', ['id' => $studentpost->id])); diff --git a/tests/subscriptions_test.php b/tests/subscriptions_test.php index 110a4f5a63..28f5776a9d 100644 --- a/tests/subscriptions_test.php +++ b/tests/subscriptions_test.php @@ -68,7 +68,7 @@ public function tearDown(): void { * @return array The users created */ protected function helper_create_users($course, $count) { - $users = array(); + $users = []; for ($i = 0; $i < $count; $i++) { $user = $this->getDataGenerator()->create_user(); @@ -101,10 +101,10 @@ protected function helper_post_to_moodleoverflow($moodleoverflow, $author) { $discussion = $generator->create_discussion($record, $moodleoverflow); // Retrieve the post which was created. - $post = $DB->get_record('moodleoverflow_posts', array('discussion' => $discussion->id)); + $post = $DB->get_record('moodleoverflow_posts', ['discussion' => $discussion->id]); // Return the discussion and the post. - return array($discussion->id, $post); + return [$discussion->id, $post]; } /** @@ -118,7 +118,7 @@ public function test_subscription_modes() { // Create a course with a moodleoverflow. $course = $this->getDataGenerator()->create_course(); - $options = array('course' => $course->id); + $options = ['course' => $course->id]; $moodleoverflow = $this->getDataGenerator()->create_module('moodleoverflow', $options); $modulecontext = \context_module::instance($moodleoverflow->cmid); @@ -130,7 +130,7 @@ public function test_subscription_modes() { // Test the forced subscription. \mod_moodleoverflow\subscriptions::set_subscription_mode($moodleoverflow->id, MOODLEOVERFLOW_FORCESUBSCRIBE); - $moodleoverflow = $DB->get_record('moodleoverflow', array('id' => $moodleoverflow->id)); + $moodleoverflow = $DB->get_record('moodleoverflow', ['id' => $moodleoverflow->id]); $this->assertEquals(MOODLEOVERFLOW_FORCESUBSCRIBE, \mod_moodleoverflow\subscriptions::get_subscription_mode($moodleoverflow)); $this->assertTrue(\mod_moodleoverflow\subscriptions::is_forcesubscribed($moodleoverflow)); @@ -139,21 +139,21 @@ public function test_subscription_modes() { // Test the disallowed subscription. \mod_moodleoverflow\subscriptions::set_subscription_mode($moodleoverflow->id, MOODLEOVERFLOW_DISALLOWSUBSCRIBE); - $moodleoverflow = $DB->get_record('moodleoverflow', array('id' => $moodleoverflow->id)); + $moodleoverflow = $DB->get_record('moodleoverflow', ['id' => $moodleoverflow->id]); $this->assertTrue(\mod_moodleoverflow\subscriptions::subscription_disabled($moodleoverflow)); $this->assertFalse(\mod_moodleoverflow\subscriptions::is_subscribable($moodleoverflow, $modulecontext)); $this->assertFalse(\mod_moodleoverflow\subscriptions::is_forcesubscribed($moodleoverflow)); // Test the initial subscription. \mod_moodleoverflow\subscriptions::set_subscription_mode($moodleoverflow->id, MOODLEOVERFLOW_INITIALSUBSCRIBE); - $moodleoverflow = $DB->get_record('moodleoverflow', array('id' => $moodleoverflow->id)); + $moodleoverflow = $DB->get_record('moodleoverflow', ['id' => $moodleoverflow->id]); $this->assertTrue(\mod_moodleoverflow\subscriptions::is_subscribable($moodleoverflow, $modulecontext)); $this->assertFalse(\mod_moodleoverflow\subscriptions::subscription_disabled($moodleoverflow)); $this->assertFalse(\mod_moodleoverflow\subscriptions::is_forcesubscribed($moodleoverflow)); // Test the choose subscription. \mod_moodleoverflow\subscriptions::set_subscription_mode($moodleoverflow->id, MOODLEOVERFLOW_CHOOSESUBSCRIBE); - $moodleoverflow = $DB->get_record('moodleoverflow', array('id' => $moodleoverflow->id)); + $moodleoverflow = $DB->get_record('moodleoverflow', ['id' => $moodleoverflow->id]); $this->assertTrue(\mod_moodleoverflow\subscriptions::is_subscribable($moodleoverflow, $modulecontext)); $this->assertFalse(\mod_moodleoverflow\subscriptions::subscription_disabled($moodleoverflow)); $this->assertFalse(\mod_moodleoverflow\subscriptions::is_forcesubscribed($moodleoverflow)); @@ -168,7 +168,7 @@ public function test_unsubscribable_moodleoverflows() { // Create a course with a moodleoverflow. $course = $this->getDataGenerator()->create_course(); - $options = array('course' => $course->id); + $options = ['course' => $course->id]; $mof = $this->getDataGenerator()->create_module('moodleoverflow', $options); // Get the module context. @@ -186,13 +186,13 @@ public function test_unsubscribable_moodleoverflows() { $this->assertEquals(0, count($result)); // Create the moodleoverflows. - $options = array('course' => $course->id, 'forcesubscribe' => MOODLEOVERFLOW_FORCESUBSCRIBE); + $options = ['course' => $course->id, 'forcesubscribe' => MOODLEOVERFLOW_FORCESUBSCRIBE]; $this->getDataGenerator()->create_module('moodleoverflow', $options); - $options = array('course' => $course->id, 'forcesubscribe' => MOODLEOVERFLOW_DISALLOWSUBSCRIBE); + $options = ['course' => $course->id, 'forcesubscribe' => MOODLEOVERFLOW_DISALLOWSUBSCRIBE]; $disallow = $this->getDataGenerator()->create_module('moodleoverflow', $options); - $options = array('course' => $course->id, 'forcesubscribe' => MOODLEOVERFLOW_CHOOSESUBSCRIBE); + $options = ['course' => $course->id, 'forcesubscribe' => MOODLEOVERFLOW_CHOOSESUBSCRIBE]; $choose = $this->getDataGenerator()->create_module('moodleoverflow', $options); - $options = array('course' => $course->id, 'forcesubscribe' => MOODLEOVERFLOW_INITIALSUBSCRIBE); + $options = ['course' => $course->id, 'forcesubscribe' => MOODLEOVERFLOW_INITIALSUBSCRIBE]; $this->getDataGenerator()->create_module('moodleoverflow', $options); // At present the user is only subscribed to the initial moodleoverflow. @@ -219,7 +219,7 @@ public function test_moodleoverflow_toggle_as_other() { // Create a course with a moodleoverflow. $course = $this->getDataGenerator()->create_course(); - $options = array('course' => $course->id); + $options = ['course' => $course->id]; $moodleoverflow = $this->getDataGenerator()->create_module('moodleoverflow', $options); // Get the module context. @@ -244,139 +244,139 @@ public function test_moodleoverflow_toggle_as_other() { $modulecontext, $discussion->id)); // Check thast we have no records in either on the subscription tables. - $options = array('userid' => $author->id, 'moodleoverflow' => $moodleoverflow->id); + $options = ['userid' => $author->id, 'moodleoverflow' => $moodleoverflow->id]; $count = $DB->count_records('moodleoverflow_subscriptions', $options); $this->assertEquals(0, $count); - $options = array('userid' => $author->id, 'discussion' => $discussion->id); + $options = ['userid' => $author->id, 'discussion' => $discussion->id]; $count = $DB->count_records('moodleoverflow_discuss_subs', $options); $this->assertEquals(0, $count); // Subscribing to the moodleoverflow should create a record in the subscription table, // but the moodleoverflow discussion subscriptions table. \mod_moodleoverflow\subscriptions::subscribe_user($author->id, $moodleoverflow, $modulecontext); - $options = array('userid' => $author->id, 'moodleoverflow' => $moodleoverflow->id); + $options = ['userid' => $author->id, 'moodleoverflow' => $moodleoverflow->id]; $count = $DB->count_records('moodleoverflow_subscriptions', $options); $this->assertEquals(1, $count); - $options = array('userid' => $author->id, 'discussion' => $discussion->id); + $options = ['userid' => $author->id, 'discussion' => $discussion->id]; $count = $DB->count_records('moodleoverflow_discuss_subs', $options); $this->assertEquals(0, $count); // Unsubscribing should remove the record from the moodleoverflow subscription table. // Do not modify the moodleoverflow discussion subscriptions table. \mod_moodleoverflow\subscriptions::unsubscribe_user($author->id, $moodleoverflow, $modulecontext); - $options = array('userid' => $author->id, 'moodleoverflow' => $moodleoverflow->id); + $options = ['userid' => $author->id, 'moodleoverflow' => $moodleoverflow->id]; $count = $DB->count_records('moodleoverflow_subscriptions', $options); $this->assertEquals(0, $count); - $options = array('userid' => $author->id, 'discussion' => $discussion->id); + $options = ['userid' => $author->id, 'discussion' => $discussion->id]; $count = $DB->count_records('moodleoverflow_discuss_subs', $options); $this->assertEquals(0, $count); // Enroling the user in the discussion should add one record to the // moodleoverflow discussion table without modifying the form subscription. \mod_moodleoverflow\subscriptions::subscribe_user_to_discussion($author->id, $discussion, $modulecontext); - $options = array('userid' => $author->id, 'moodleoverflow' => $moodleoverflow->id); + $options = ['userid' => $author->id, 'moodleoverflow' => $moodleoverflow->id]; $count = $DB->count_records('moodleoverflow_subscriptions', $options); $this->assertEquals(0, $count); - $options = array('userid' => $author->id, 'discussion' => $discussion->id); + $options = ['userid' => $author->id, 'discussion' => $discussion->id]; $count = $DB->count_records('moodleoverflow_discuss_subs', $options); $this->assertEquals(1, $count); // Unsubscribing should remove the record from the moodleoverflow subscriptions // table and not modify the moodleoverflow discussion subscription table. \mod_moodleoverflow\subscriptions::unsubscribe_user_from_discussion($author->id, $discussion, $modulecontext); - $options = array('userid' => $author->id, 'discussion' => $discussion->id); + $options = ['userid' => $author->id, 'discussion' => $discussion->id]; $count = $DB->count_records('moodleoverflow_discuss_subs', $options); $this->assertEquals(0, $count); - $options = array('userid' => $author->id, 'moodleoverflow' => $moodleoverflow->id); + $options = ['userid' => $author->id, 'moodleoverflow' => $moodleoverflow->id]; $count = $DB->count_records('moodleoverflow_subscriptions', $options); $this->assertEquals(0, $count); // Resubscribe to the discussion so that we can check the effect of moodleoverflow-level subscriptions. \mod_moodleoverflow\subscriptions::subscribe_user_to_discussion($author->id, $discussion, $modulecontext); - $options = array('userid' => $author->id, 'discussion' => $discussion->id); + $options = ['userid' => $author->id, 'discussion' => $discussion->id]; $count = $DB->count_records('moodleoverflow_discuss_subs', $options); $this->assertEquals(1, $count); - $options = array('userid' => $author->id, 'moodleoverflow' => $moodleoverflow->id); + $options = ['userid' => $author->id, 'moodleoverflow' => $moodleoverflow->id]; $count = $DB->count_records('moodleoverflow_subscriptions', $options); $this->assertEquals(0, $count); // Subscribing to the moodleoverflow should have no effect on the moodleoverflow discussion // subscription table if the user did not request the change himself. \mod_moodleoverflow\subscriptions::subscribe_user($author->id, $moodleoverflow, $modulecontext); - $options = array('userid' => $author->id, 'moodleoverflow' => $moodleoverflow->id); + $options = ['userid' => $author->id, 'moodleoverflow' => $moodleoverflow->id]; $count = $DB->count_records('moodleoverflow_subscriptions', $options); $this->assertEquals(1, $count); - $options = array('userid' => $author->id, 'discussion' => $discussion->id); + $options = ['userid' => $author->id, 'discussion' => $discussion->id]; $count = $DB->count_records('moodleoverflow_discuss_subs', $options); $this->assertEquals(1, $count); // Unsubbing from the moodleoverflow should have no effect on the moodleoverflow // discussion subscription table if the user did not request the change themself. \mod_moodleoverflow\subscriptions::unsubscribe_user($author->id, $moodleoverflow, $modulecontext); - $options = array('userid' => $author->id, 'moodleoverflow' => $moodleoverflow->id); + $options = ['userid' => $author->id, 'moodleoverflow' => $moodleoverflow->id]; $count = $DB->count_records('moodleoverflow_subscriptions', $options); $this->assertEquals(0, $count); - $options = array('userid' => $author->id, 'discussion' => $discussion->id); + $options = ['userid' => $author->id, 'discussion' => $discussion->id]; $count = $DB->count_records('moodleoverflow_discuss_subs', $options); $this->assertEquals(1, $count); // Subscribing to the moodleoverflow should remove the per-discussion // subscription preference if the user requested the change themself. \mod_moodleoverflow\subscriptions::subscribe_user($author->id, $moodleoverflow, $modulecontext, true); - $options = array('userid' => $author->id, 'moodleoverflow' => $moodleoverflow->id); + $options = ['userid' => $author->id, 'moodleoverflow' => $moodleoverflow->id]; $count = $DB->count_records('moodleoverflow_subscriptions', $options); $this->assertEquals(1, $count); - $options = array('userid' => $author->id, 'discussion' => $discussion->id); + $options = ['userid' => $author->id, 'discussion' => $discussion->id]; $count = $DB->count_records('moodleoverflow_discuss_subs', $options); $this->assertEquals(0, $count); // Now unsubscribe from the current discussion whilst being subscribed to the moodleoverflow as a whole. \mod_moodleoverflow\subscriptions::unsubscribe_user_from_discussion($author->id, $discussion, $modulecontext); - $options = array('userid' => $author->id, 'moodleoverflow' => $moodleoverflow->id); + $options = ['userid' => $author->id, 'moodleoverflow' => $moodleoverflow->id]; $count = $DB->count_records('moodleoverflow_subscriptions', $options); $this->assertEquals(1, $count); - $options = array('userid' => $author->id, 'discussion' => $discussion->id); + $options = ['userid' => $author->id, 'discussion' => $discussion->id]; $count = $DB->count_records('moodleoverflow_discuss_subs', $options); $this->assertEquals(1, $count); // Unsubscribing from the moodleoverflow should remove the per-discussion // subscription preference if the user requested the change himself. \mod_moodleoverflow\subscriptions::unsubscribe_user($author->id, $moodleoverflow, $modulecontext, true); - $options = array('userid' => $author->id, 'moodleoverflow' => $moodleoverflow->id); + $options = ['userid' => $author->id, 'moodleoverflow' => $moodleoverflow->id]; $count = $DB->count_records('moodleoverflow_subscriptions', $options); $this->assertEquals(0, $count); - $count = $DB->count_records('moodleoverflow_discuss_subs', array( + $count = $DB->count_records('moodleoverflow_discuss_subs', [ 'userid' => $author->id, 'discussion' => $discussion->id, - )); + ]); $this->assertEquals(0, $count); // Subscribe to the discussion. \mod_moodleoverflow\subscriptions::subscribe_user_to_discussion($author->id, $discussion, $modulecontext); - $options = array('userid' => $author->id, 'moodleoverflow' => $moodleoverflow->id); + $options = ['userid' => $author->id, 'moodleoverflow' => $moodleoverflow->id]; $count = $DB->count_records('moodleoverflow_subscriptions', $options); $this->assertEquals(0, $count); - $count = $DB->count_records('moodleoverflow_discuss_subs', array( + $count = $DB->count_records('moodleoverflow_discuss_subs', [ 'userid' => $author->id, 'discussion' => $discussion->id, - )); + ]); $this->assertEquals(1, $count); // Subscribe to the moodleoverflow without removing the discussion preferences. \mod_moodleoverflow\subscriptions::subscribe_user($author->id, $moodleoverflow, $modulecontext); - $options = array('userid' => $author->id, 'moodleoverflow' => $moodleoverflow->id); + $options = ['userid' => $author->id, 'moodleoverflow' => $moodleoverflow->id]; $count = $DB->count_records('moodleoverflow_subscriptions', $options); $this->assertEquals(1, $count); - $options = array('userid' => $author->id, 'discussion' => $discussion->id); + $options = ['userid' => $author->id, 'discussion' => $discussion->id]; $count = $DB->count_records('moodleoverflow_discuss_subs', $options); $this->assertEquals(1, $count); // Unsubscribe from the discussion should result in a change. \mod_moodleoverflow\subscriptions::unsubscribe_user_from_discussion($author->id, $discussion, $modulecontext); - $options = array('userid' => $author->id, 'moodleoverflow' => $moodleoverflow->id); + $options = ['userid' => $author->id, 'moodleoverflow' => $moodleoverflow->id]; $count = $DB->count_records('moodleoverflow_subscriptions', $options); $this->assertEquals(1, $count); - $options = array('userid' => $author->id, 'discussion' => $discussion->id); + $options = ['userid' => $author->id, 'discussion' => $discussion->id]; $count = $DB->count_records('moodleoverflow_discuss_subs', $options); $this->assertEquals(1, $count); } @@ -390,7 +390,7 @@ public function test_moodleoverflow_discussion_subscription_moodleoverflow_unsub // Create a course with a moodleoverflow. $course = $this->getDataGenerator()->create_course(); - $options = array('course' => $course->id, 'forcesubscribe' => MOODLEOVERFLOW_CHOOSESUBSCRIBE); + $options = ['course' => $course->id, 'forcesubscribe' => MOODLEOVERFLOW_CHOOSESUBSCRIBE]; $moodleoverflow = $this->getDataGenerator()->create_module('moodleoverflow', $options); // Create users enrolled in the course as students. @@ -417,7 +417,7 @@ public function test_moodleoverflow_discussion_subscription_moodleoverflow_subsc // Create a course with a moodleoverflow. $course = $this->getDataGenerator()->create_course(); - $options = array('course' => $course->id, 'forcesubscribe' => MOODLEOVERFLOW_CHOOSESUBSCRIBE); + $options = ['course' => $course->id, 'forcesubscribe' => MOODLEOVERFLOW_CHOOSESUBSCRIBE]; $moodleoverflow = $this->getDataGenerator()->create_module('moodleoverflow', $options); // Get the module context. @@ -456,7 +456,7 @@ public function test_moodleoverflow_discussion_subscription_moodleoverflow_unsub // Create a course and a new moodleoverflow. $course = $this->getDataGenerator()->create_course(); - $options = array('course' => $course->id, 'forcesubscribe' => MOODLEOVERFLOW_CHOOSESUBSCRIBE); + $options = ['course' => $course->id, 'forcesubscribe' => MOODLEOVERFLOW_CHOOSESUBSCRIBE]; $moodleoverflow = $this->getDataGenerator()->create_module('moodleoverflow', $options); // Get the module context. @@ -500,7 +500,7 @@ public function test_moodleoverflow_discussion_subscription_moodleoverflow_subsc // Create a course, with a moodleoverflow. $course = $this->getDataGenerator()->create_course(); - $options = array('course' => $course->id, 'forcesubscribe' => MOODLEOVERFLOW_CHOOSESUBSCRIBE); + $options = ['course' => $course->id, 'forcesubscribe' => MOODLEOVERFLOW_CHOOSESUBSCRIBE]; $moodleoverflow = $this->getDataGenerator()->create_module('moodleoverflow', $options); // Get the module context. @@ -544,7 +544,7 @@ public function test_moodleoverflow_discussion_toggle_moodleoverflow_subscribed( // Create a course with a moodleoverflow. $course = $this->getDataGenerator()->create_course(); - $options = array('course' => $course->id, 'forcesubscribe' => MOODLEOVERFLOW_CHOOSESUBSCRIBE); + $options = ['course' => $course->id, 'forcesubscribe' => MOODLEOVERFLOW_CHOOSESUBSCRIBE]; $moodleoverflow = $this->getDataGenerator()->create_module('moodleoverflow', $options); $cm = get_coursemodule_from_instance('moodleoverflow', $moodleoverflow->id); @@ -574,10 +574,10 @@ public function test_moodleoverflow_discussion_toggle_moodleoverflow_subscribed( $discussion, $modulecontext)); // And there should be no discussion subscriptions (and one moodleoverflow subscription). - $options = array('userid' => $author->id, 'discussion' => $discussion->id); + $options = ['userid' => $author->id, 'discussion' => $discussion->id]; $count = $DB->count_records('moodleoverflow_discuss_subs', $options); $this->assertEquals(0, $count); - $options = array('userid' => $author->id, 'moodleoverflow' => $moodleoverflow->id); + $options = ['userid' => $author->id, 'moodleoverflow' => $moodleoverflow->id]; $count = $DB->count_records('moodleoverflow_subscriptions', $options); $this->assertEquals(1, $count); @@ -592,10 +592,10 @@ public function test_moodleoverflow_discussion_toggle_moodleoverflow_subscribed( $discussion, $modulecontext)); // And there should be a discussion subscriptions (and one moodleoverflow subscription). - $options = array('userid' => $author->id, 'discussion' => $discussion->id); + $options = ['userid' => $author->id, 'discussion' => $discussion->id]; $count = $DB->count_records('moodleoverflow_discuss_subs', $options); $this->assertEquals(1, $count); - $options = array('userid' => $author->id, 'moodleoverflow' => $moodleoverflow->id); + $options = ['userid' => $author->id, 'moodleoverflow' => $moodleoverflow->id]; $count = $DB->count_records('moodleoverflow_subscriptions', $options); $this->assertEquals(1, $count); @@ -604,12 +604,12 @@ public function test_moodleoverflow_discussion_toggle_moodleoverflow_subscribed( $discussion->id)); // There should be a record in the discussion subscription tracking table. - $options = array('userid' => $author->id, 'discussion' => $discussion->id); + $options = ['userid' => $author->id, 'discussion' => $discussion->id]; $count = $DB->count_records('moodleoverflow_discuss_subs', $options); $this->assertEquals(1, $count); // And one in the moodleoverflow subscription tracking table. - $options = array('userid' => $author->id, 'moodleoverflow' => $moodleoverflow->id); + $options = ['userid' => $author->id, 'moodleoverflow' => $moodleoverflow->id]; $count = $DB->count_records('moodleoverflow_subscriptions', $options); $this->assertEquals(1, $count); @@ -624,12 +624,12 @@ public function test_moodleoverflow_discussion_toggle_moodleoverflow_subscribed( $discussion->id)); // And one in the moodleoverflow subscription tracking table. - $options = array('userid' => $author->id, 'moodleoverflow' => $moodleoverflow->id); + $options = ['userid' => $author->id, 'moodleoverflow' => $moodleoverflow->id]; $count = $DB->count_records('moodleoverflow_subscriptions', $options); $this->assertEquals(1, $count); // There should be no record in the discussion subscription tracking table. - $options = array('userid' => $author->id, 'discussion' => $discussion->id); + $options = ['userid' => $author->id, 'discussion' => $discussion->id]; $count = $DB->count_records('moodleoverflow_discuss_subs', $options); $this->assertEquals(0, $count); @@ -644,12 +644,12 @@ public function test_moodleoverflow_discussion_toggle_moodleoverflow_subscribed( $discussion->id)); // And one in the moodleoverflow subscription tracking table. - $options = array('userid' => $author->id, 'moodleoverflow' => $moodleoverflow->id); + $options = ['userid' => $author->id, 'moodleoverflow' => $moodleoverflow->id]; $count = $DB->count_records('moodleoverflow_subscriptions', $options); $this->assertEquals(1, $count); // There should be a record in the discussion subscription tracking table. - $options = array('userid' => $author->id, 'discussion' => $discussion->id); + $options = ['userid' => $author->id, 'discussion' => $discussion->id]; $count = $DB->count_records('moodleoverflow_discuss_subs', $options); $this->assertEquals(1, $count); @@ -665,12 +665,12 @@ public function test_moodleoverflow_discussion_toggle_moodleoverflow_subscribed( $discussion->id)); // There should be no record in the discussion subscription tracking table. - $options = array('userid' => $author->id, 'discussion' => $discussion->id); + $options = ['userid' => $author->id, 'discussion' => $discussion->id]; $count = $DB->count_records('moodleoverflow_discuss_subs', $options); $this->assertEquals(0, $count); // And one in the forum subscription tracking table. - $options = array('userid' => $author->id, 'moodleoverflow' => $moodleoverflow->id); + $options = ['userid' => $author->id, 'moodleoverflow' => $moodleoverflow->id]; $count = $DB->count_records('moodleoverflow_subscriptions', $options); $this->assertEquals(1, $count); @@ -685,12 +685,12 @@ public function test_moodleoverflow_discussion_toggle_moodleoverflow_subscribed( $this->assertTrue(\mod_moodleoverflow\subscriptions::is_subscribed($author->id, $moodleoverflow, $modulecontext)); // There should be a record in the discussion subscription tracking table. - $options = array('userid' => $author->id, 'discussion' => $discussion->id); + $options = ['userid' => $author->id, 'discussion' => $discussion->id]; $count = $DB->count_records('moodleoverflow_discuss_subs', $options); $this->assertEquals(1, $count); // And one in the moodleoverflow subscription tracking table. - $options = array('userid' => $author->id, 'moodleoverflow' => $moodleoverflow->id); + $options = ['userid' => $author->id, 'moodleoverflow' => $moodleoverflow->id]; $count = $DB->count_records('moodleoverflow_subscriptions', $options); $this->assertEquals(1, $count); @@ -699,10 +699,10 @@ public function test_moodleoverflow_discussion_toggle_moodleoverflow_subscribed( true)); // This removes both the moodleoverflow, and the moodleoverflow records. - $options = array('userid' => $author->id, 'discussion' => $discussion->id); + $options = ['userid' => $author->id, 'discussion' => $discussion->id]; $count = $DB->count_records('moodleoverflow_discuss_subs', $options); $this->assertEquals(0, $count); - $options = array('userid' => $author->id, 'moodleoverflow' => $moodleoverflow->id); + $options = ['userid' => $author->id, 'moodleoverflow' => $moodleoverflow->id]; $count = $DB->count_records('moodleoverflow_subscriptions', $options); $this->assertEquals(0, $count); @@ -723,7 +723,7 @@ public function test_moodleoverflow_discussion_toggle_moodleoverflow_unsubscribe // Create a course, with a moodleoverflow. $course = $this->getDataGenerator()->create_course(); - $options = array('course' => $course->id, 'forcesubscribe' => MOODLEOVERFLOW_CHOOSESUBSCRIBE); + $options = ['course' => $course->id, 'forcesubscribe' => MOODLEOVERFLOW_CHOOSESUBSCRIBE]; $moodleoverflow = $this->getDataGenerator()->create_module('moodleoverflow', $options); // Get the module context. @@ -762,7 +762,7 @@ public function test_moodleoverflow_discussion_toggle_moodleoverflow_unsubscribe $discussion->id)); // There should be a record in the discussion subscription tracking table. - $options = array('userid' => $author->id, 'discussion' => $discussion->id); + $options = ['userid' => $author->id, 'discussion' => $discussion->id]; $count = $DB->count_records('moodleoverflow_discuss_subs', $options); $this->assertEquals(1, $count); @@ -777,7 +777,7 @@ public function test_moodleoverflow_discussion_toggle_moodleoverflow_unsubscribe $discussion->id)); // There should be no record in the discussion subscription tracking table. - $options = array('userid' => $author->id, 'discussion' => $discussion->id); + $options = ['userid' => $author->id, 'discussion' => $discussion->id]; $count = $DB->count_records('moodleoverflow_discuss_subs', $options); $this->assertEquals(0, $count); @@ -792,7 +792,7 @@ public function test_moodleoverflow_discussion_toggle_moodleoverflow_unsubscribe $this->assertFalse(\mod_moodleoverflow\subscriptions::is_subscribed($author->id, $moodleoverflow, $modulecontext)); // There should be a record in the discussion subscription tracking table. - $options = array('userid' => $author->id, 'discussion' => $discussion->id); + $options = ['userid' => $author->id, 'discussion' => $discussion->id]; $count = $DB->count_records('moodleoverflow_discuss_subs', $options); $this->assertEquals(1, $count); @@ -807,7 +807,7 @@ public function test_moodleoverflow_discussion_toggle_moodleoverflow_unsubscribe $this->assertFalse(\mod_moodleoverflow\subscriptions::is_subscribed($author->id, $moodleoverflow, $modulecontext)); // There should be no record in the discussion subscription tracking table. - $options = array('userid' => $author->id, 'discussion' => $discussion->id); + $options = ['userid' => $author->id, 'discussion' => $discussion->id]; $count = $DB->count_records('moodleoverflow_discuss_subs', $options); $this->assertEquals(0, $count); } @@ -824,7 +824,7 @@ public function test_fetch_subscribed_users_subscriptions() { // Create a course, with a moodleoverflow. where users are initially subscribed. $course = $this->getDataGenerator()->create_course(); - $options = array('course' => $course->id, 'forcesubscribe' => MOODLEOVERFLOW_INITIALSUBSCRIBE); + $options = ['course' => $course->id, 'forcesubscribe' => MOODLEOVERFLOW_INITIALSUBSCRIBE]; $moodleoverflow = $this->getDataGenerator()->create_module('moodleoverflow', $options); // Get the module context. @@ -865,7 +865,7 @@ public function test_fetch_subscribed_users_forced() { // Create a course, with a moodleoverflow. where users are initially subscribed. $course = $this->getDataGenerator()->create_course(); - $options = array('course' => $course->id, 'forcesubscribe' => MOODLEOVERFLOW_FORCESUBSCRIBE); + $options = ['course' => $course->id, 'forcesubscribe' => MOODLEOVERFLOW_FORCESUBSCRIBE]; $moodleoverflow = $this->getDataGenerator()->create_module('moodleoverflow', $options); // Get the module context. @@ -892,7 +892,7 @@ public function test_fetch_subscribed_users_discussion_subscriptions() { // Create a course, with a moodleoverflow. where users are initially subscribed. $course = $this->getDataGenerator()->create_course(); - $options = array('course' => $course->id, 'forcesubscribe' => MOODLEOVERFLOW_INITIALSUBSCRIBE); + $options = ['course' => $course->id, 'forcesubscribe' => MOODLEOVERFLOW_INITIALSUBSCRIBE]; $moodleoverflow = $this->getDataGenerator()->create_module('moodleoverflow', $options); // Get the module context. @@ -979,7 +979,7 @@ public function test_force_subscribed_to_moodleoverflow() { // Create a course, with a moodleoverflow. $course = $this->getDataGenerator()->create_course(); - $options = array('course' => $course->id, 'forcesubscribe' => MOODLEOVERFLOW_FORCESUBSCRIBE); + $options = ['course' => $course->id, 'forcesubscribe' => MOODLEOVERFLOW_FORCESUBSCRIBE]; $moodleoverflow = $this->getDataGenerator()->create_module('moodleoverflow', $options); // Remove the allowforcesubscribe capability from the user. @@ -1011,7 +1011,7 @@ public function test_subscription_cache_prefill() { // Create a course, with a moodleoverflow. $course = $this->getDataGenerator()->create_course(); - $options = array('course' => $course->id, 'forcesubscribe' => MOODLEOVERFLOW_INITIALSUBSCRIBE); + $options = ['course' => $course->id, 'forcesubscribe' => MOODLEOVERFLOW_INITIALSUBSCRIBE]; $moodleoverflow = $this->getDataGenerator()->create_module('moodleoverflow', $options); // Create some users. @@ -1046,7 +1046,7 @@ public function test_subscription_cache_fill() { // Create a course, with a moodleoverflow. $course = $this->getDataGenerator()->create_course(); - $options = array('course' => $course->id, 'forcesubscribe' => MOODLEOVERFLOW_INITIALSUBSCRIBE); + $options = ['course' => $course->id, 'forcesubscribe' => MOODLEOVERFLOW_INITIALSUBSCRIBE]; $moodleoverflow = $this->getDataGenerator()->create_module('moodleoverflow', $options); // Create some users. @@ -1079,11 +1079,11 @@ public function test_discussion_subscription_cache_fill_for_course() { $course = $this->getDataGenerator()->create_course(); // Create the moodleoverflows. - $options = array('course' => $course->id, 'forcesubscribe' => MOODLEOVERFLOW_DISALLOWSUBSCRIBE); + $options = ['course' => $course->id, 'forcesubscribe' => MOODLEOVERFLOW_DISALLOWSUBSCRIBE]; $disallowmoodleoverflow = $this->getDataGenerator()->create_module('moodleoverflow', $options); - $options = array('course' => $course->id, 'forcesubscribe' => MOODLEOVERFLOW_CHOOSESUBSCRIBE); + $options = ['course' => $course->id, 'forcesubscribe' => MOODLEOVERFLOW_CHOOSESUBSCRIBE]; $choosemoodleoverflow = $this->getDataGenerator()->create_module('moodleoverflow', $options); - $options = array('course' => $course->id, 'forcesubscribe' => MOODLEOVERFLOW_INITIALSUBSCRIBE); + $options = ['course' => $course->id, 'forcesubscribe' => MOODLEOVERFLOW_INITIALSUBSCRIBE]; $initialmoodleoverflow = $this->getDataGenerator()->create_module('moodleoverflow', $options); // Create some users and keep a reference to the first user. @@ -1130,7 +1130,7 @@ public function test_discussion_subscription_cache_prefill() { // Create a course, with a moodleoverflow. $course = $this->getDataGenerator()->create_course(); - $options = array('course' => $course->id, 'forcesubscribe' => MOODLEOVERFLOW_INITIALSUBSCRIBE); + $options = ['course' => $course->id, 'forcesubscribe' => MOODLEOVERFLOW_INITIALSUBSCRIBE]; $moodleoverflow = $this->getDataGenerator()->create_module('moodleoverflow', $options); // Get the module context. @@ -1141,7 +1141,7 @@ public function test_discussion_subscription_cache_prefill() { $users = $this->helper_create_users($course, 20); // Post some discussions to the moodleoverflow. - $discussions = array(); + $discussions = []; $author = $users[0]; for ($i = 0; $i < 20; $i++) { $discussion = new \stdClass(); @@ -1197,14 +1197,14 @@ public function test_discussion_subscription_cache_fill() { // Create a course, with a moodleoverflow. $course = $this->getDataGenerator()->create_course(); - $options = array('course' => $course->id, 'forcesubscribe' => MOODLEOVERFLOW_INITIALSUBSCRIBE); + $options = ['course' => $course->id, 'forcesubscribe' => MOODLEOVERFLOW_INITIALSUBSCRIBE]; $moodleoverflow = $this->getDataGenerator()->create_module('moodleoverflow', $options); // Create some users. $users = $this->helper_create_users($course, 20); // Post some discussions to the moodleoverflow. - $discussions = array(); + $discussions = []; $author = $users[0]; for ($i = 0; $i < 20; $i++) { $discussion = new \stdClass(); @@ -1270,7 +1270,7 @@ public function test_moodleoverflow_subscribe_toggle_as_other_repeat_subscriptio // Create a course, with a moodleoverflow. $course = $this->getDataGenerator()->create_course(); - $options = array('course' => $course->id, 'forcesubscribe' => MOODLEOVERFLOW_CHOOSESUBSCRIBE); + $options = ['course' => $course->id, 'forcesubscribe' => MOODLEOVERFLOW_CHOOSESUBSCRIBE]; $moodleoverflow = $this->getDataGenerator()->create_module('moodleoverflow', $options); // Get the module context. @@ -1294,26 +1294,26 @@ public function test_moodleoverflow_subscribe_toggle_as_other_repeat_subscriptio $discussion->id)); // Confirm that we have no records in either of the subscription tables. - $this->assertEquals(0, $DB->count_records('moodleoverflow_subscriptions', array( + $this->assertEquals(0, $DB->count_records('moodleoverflow_subscriptions', [ 'userid' => $user->id, 'moodleoverflow' => $moodleoverflow->id, - ))); - $this->assertEquals(0, $DB->count_records('moodleoverflow_discuss_subs', array( + ])); + $this->assertEquals(0, $DB->count_records('moodleoverflow_discuss_subs', [ 'userid' => $user->id, 'discussion' => $discussion->id, - ))); + ])); // Subscribing to the moodleoverflow should create a record in the subscriptions table, // but not the moodleoverflow discussion subscriptions table. \mod_moodleoverflow\subscriptions::subscribe_user($user->id, $moodleoverflow, $modulecontext); - $this->assertEquals(1, $DB->count_records('moodleoverflow_subscriptions', array( + $this->assertEquals(1, $DB->count_records('moodleoverflow_subscriptions', [ 'userid' => $user->id, 'moodleoverflow' => $moodleoverflow->id, - ))); - $this->assertEquals(0, $DB->count_records('moodleoverflow_discuss_subs', array( + ])); + $this->assertEquals(0, $DB->count_records('moodleoverflow_discuss_subs', [ 'userid' => $user->id, 'discussion' => $discussion->id, - ))); + ])); // Now unsubscribe from the discussion. This should return true. $uid = $user->id; @@ -1334,25 +1334,25 @@ public function test_moodleoverflow_subscribe_toggle_as_other_repeat_subscriptio // And unsubscribing from the moodleoverflow but not as a request from the user should maintain their preference. \mod_moodleoverflow\subscriptions::unsubscribe_user($user->id, $moodleoverflow, $modulecontext); - $this->assertEquals(0, $DB->count_records('moodleoverflow_subscriptions', array( + $this->assertEquals(0, $DB->count_records('moodleoverflow_subscriptions', [ 'userid' => $user->id, 'moodleoverflow' => $moodleoverflow->id, - ))); - $this->assertEquals(1, $DB->count_records('moodleoverflow_discuss_subs', array( + ])); + $this->assertEquals(1, $DB->count_records('moodleoverflow_discuss_subs', [ 'userid' => $user->id, 'discussion' => $discussion->id, - ))); + ])); // Subscribing to the discussion should return truthfully because a change was made. $this->assertTrue(\mod_moodleoverflow\subscriptions::subscribe_user_to_discussion($user->id, $discussion, $modulecontext)); - $this->assertEquals(0, $DB->count_records('moodleoverflow_subscriptions', array( + $this->assertEquals(0, $DB->count_records('moodleoverflow_subscriptions', [ 'userid' => $user->id, 'moodleoverflow' => $moodleoverflow->id, - ))); - $this->assertEquals(1, $DB->count_records('moodleoverflow_discuss_subs', array( + ])); + $this->assertEquals(1, $DB->count_records('moodleoverflow_discuss_subs', [ 'userid' => $user->id, 'discussion' => $discussion->id, - ))); + ])); } /** @@ -1422,7 +1422,7 @@ public function test_is_subscribable_is_guest($options) { $this->resetAfterTest(true); // Create a guest user. - $guest = $DB->get_record('user', array('username' => 'guest')); + $guest = $DB->get_record('user', ['username' => 'guest']); $this->setUser($guest); // Create a course, with a moodleoverflow. diff --git a/tests/userstats_test.php b/tests/userstats_test.php index 044dd1f8b7..741712320f 100644 --- a/tests/userstats_test.php +++ b/tests/userstats_test.php @@ -183,7 +183,7 @@ public function test_partial_anonymous() { // User1 starts a new discussion, the forum activity shouldn't change. $discussion = $this->generator->post_to_forum($this->moodleoverflow, $this->user1); - $starterpost = $DB->get_record('moodleoverflow_posts', array('id' => $discussion[0]->firstpost), '*'); + $starterpost = $DB->get_record('moodleoverflow_posts', ['id' => $discussion[0]->firstpost], '*'); $newuserstats = $this->create_statstable(); $newactivityuser1 = $this->get_specific_userstats($newuserstats, $this->user1, 'forumactivity'); $this->assertEquals($oldactivityuser1, $newactivityuser1); @@ -276,25 +276,25 @@ private function helper_course_set_up() { global $DB; // Create a new course with a moodleoverflow forum. $this->course = $this->getDataGenerator()->create_course(); - $location = array('course' => $this->course->id); + $location = ['course' => $this->course->id]; $this->moodleoverflow = $this->getDataGenerator()->create_module('moodleoverflow', $location); $this->coursemodule = get_coursemodule_from_instance('moodleoverflow', $this->moodleoverflow->id); // Create a teacher. - $this->teacher = $this->getDataGenerator()->create_user(array('firstname' => 'Tamaro', 'lastname' => 'Walter')); + $this->teacher = $this->getDataGenerator()->create_user(['firstname' => 'Tamaro', 'lastname' => 'Walter']); $this->getDataGenerator()->enrol_user($this->teacher->id, $this->course->id, 'student'); // Create 2 users and their discussions and posts. - $this->user1 = $this->getDataGenerator()->create_user(array('firstname' => 'Ava', 'lastname' => 'Davis')); + $this->user1 = $this->getDataGenerator()->create_user(['firstname' => 'Ava', 'lastname' => 'Davis']); $this->getDataGenerator()->enrol_user($this->user1->id, $this->course->id, 'student'); - $this->user2 = $this->getDataGenerator()->create_user(array('firstname' => 'Ethan', 'lastname' => 'Brown')); + $this->user2 = $this->getDataGenerator()->create_user(['firstname' => 'Ethan', 'lastname' => 'Brown']); $this->getDataGenerator()->enrol_user($this->user2->id, $this->course->id, 'student'); $this->generator = $this->getDataGenerator()->get_plugin_generator('mod_moodleoverflow'); $this->discussion1 = $this->generator->post_to_forum($this->moodleoverflow, $this->user1); $this->discussion2 = $this->generator->post_to_forum($this->moodleoverflow, $this->user2); - $this->post1 = $DB->get_record('moodleoverflow_posts', array('id' => $this->discussion1[0]->firstpost), '*'); - $this->post2 = $DB->get_record('moodleoverflow_posts', array('id' => $this->discussion1[0]->firstpost), '*'); + $this->post1 = $DB->get_record('moodleoverflow_posts', ['id' => $this->discussion1[0]->firstpost], '*'); + $this->post2 = $DB->get_record('moodleoverflow_posts', ['id' => $this->discussion1[0]->firstpost], '*'); $this->answer1 = $this->generator->reply_to_post($this->discussion1[1], $this->user2, true); $this->answer2 = $this->generator->reply_to_post($this->discussion2[1], $this->user1, true); } @@ -323,7 +323,7 @@ private function make_anonymous($anonymoussetting) { private function create_statstable() { $url = new \moodle_url('/mod/moodleoverflow/userstats.php', ['id' => $this->coursemodule->id, 'courseid' => $this->course->id, - 'mid' => $this->moodleoverflow->id]); + 'mid' => $this->moodleoverflow->id, ]); $userstatstable = new userstats_table('testtable', $this->course->id, $this->moodleoverflow->id, $url); $userstatstable->get_table_data(); return $userstatstable->get_usertable(); @@ -346,7 +346,7 @@ private function create_upvote($author, $discussion, $post) { 'postid' => $post->id, 'rating' => 2, 'firstrated' => time(), - 'lastchanged' => time() + 'lastchanged' => time(), ]; return $this->generator->create_rating($record); } @@ -368,7 +368,7 @@ private function create_downvote($author, $discussion, $post) { 'postid' => $post->id, 'rating' => 1, 'firstrated' => time(), - 'lastchanged' => time() + 'lastchanged' => time(), ]; return $this->generator->create_rating($record); } @@ -390,7 +390,7 @@ private function create_helpful($author, $discussion, $post) { 'postid' => $post->id, 'rating' => 4, 'firstrated' => time(), - 'lastchanged' => time() + 'lastchanged' => time(), ]; return $this->generator->create_rating($record); } @@ -412,7 +412,7 @@ private function create_solution($author, $discussion, $post) { 'postid' => $post->id, 'rating' => 3, 'firstrated' => time(), - 'lastchanged' => time() + 'lastchanged' => time(), ]; return $this->generator->create_rating($record); } diff --git a/tracking.php b/tracking.php index 9011bbe3df..b152d5d439 100644 --- a/tracking.php +++ b/tracking.php @@ -34,12 +34,12 @@ require_sesskey(); // Retrieve the moodleoverflow instance to track or untrack. -if (!$moodleoverflow = $DB->get_record("moodleoverflow", array("id" => $id))) { +if (!$moodleoverflow = $DB->get_record("moodleoverflow", ["id" => $id])) { throw new moodle_exception('invalidmoodleoverflowid', 'moodleoverflow'); } // Retrieve the course of the instance. -if (!$course = $DB->get_record("course", array("id" => $moodleoverflow->course))) { +if (!$course = $DB->get_record("course", ["id" => $moodleoverflow->course])) { throw new moodle_exception('invalidcoursemodule'); } @@ -53,7 +53,7 @@ // Set the page to return to. $url = '/mod/moodleoverflow/' . $returnpage; -$params = array('id' => $course->id, 'm' => $moodleoverflow->id); +$params = ['id' => $course->id, 'm' => $moodleoverflow->id]; $returnpageurl = new moodle_url($url, $params); $returnto = moodleoverflow_go_back_to($returnpageurl); @@ -72,11 +72,11 @@ $info->moodleoverflow = format_string($moodleoverflow->name); // Set parameters for an event. -$eventparams = array( +$eventparams = [ 'context' => context_module::instance($cm->id), 'relateduserid' => $USER->id, - 'other' => array('moodleoverflowid' => $moodleoverflow->id), -); + 'other' => ['moodleoverflowid' => $moodleoverflow->id], +]; // Check whether the moodleoverflow is tracked. $istracked = \mod_moodleoverflow\readtracking::moodleoverflow_is_tracked($moodleoverflow); diff --git a/userstats.php b/userstats.php index cab12d15d1..6d61eaec89 100644 --- a/userstats.php +++ b/userstats.php @@ -38,13 +38,13 @@ // Define important variables. if ($courseid) { - $course = $DB->get_record('course', array('id' => $courseid), '*'); + $course = $DB->get_record('course', ['id' => $courseid], '*'); } if ($cmid) { $cm = get_coursemodule_from_id('moodleoverflow', $cmid, $course->id, false, MUST_EXIST); } if ($mid) { - $moodleoverflow = $DB->get_record('moodleoverflow', array('id' => $mid), '*'); + $moodleoverflow = $DB->get_record('moodleoverflow', ['id' => $mid], '*'); } // Require a login. require_login($course, true, $cm); @@ -56,8 +56,8 @@ // Do a capability check, in case a user iserts the userstats-url manually. if (has_capability('mod/moodleoverflow:viewanyrating', $context) && get_config('moodleoverflow', 'showuserstats')) { // Print the page header. - $PAGE->set_url('/mod/moodleoverflow/userstats.php', array('id' => $cm->id, - 'courseid' => $course->id, 'mid' => $moodleoverflow->id)); + $PAGE->set_url('/mod/moodleoverflow/userstats.php', ['id' => $cm->id, 'courseid' => $course->id, + 'mid' => $moodleoverflow->id, ]); $PAGE->set_title(format_string('User statistics')); $PAGE->set_heading(format_string('User statistics of course: ' . $course->fullname)); diff --git a/version.php b/version.php index c5e7541f80..ab72068a1b 100644 --- a/version.php +++ b/version.php @@ -29,7 +29,8 @@ $plugin->component = 'mod_moodleoverflow'; $plugin->version = 2023070300; +$plugin->version = 2023082500; $plugin->release = 'v4.2-r2'; $plugin->requires = 2020061500; // Requires Moodle 3.9+. $plugin->maturity = MATURITY_STABLE; -$plugin->dependencies = array(); +$plugin->dependencies = []; diff --git a/view.php b/view.php index 552292d209..d30c6e6544 100644 --- a/view.php +++ b/view.php @@ -38,7 +38,7 @@ $linktoforum = optional_param('movetoforum', 0, PARAM_INT); // Forum to which it is moved. // Set the parameters. -$params = array(); +$params = []; if ($id) { $params['id'] = $id; } else { @@ -52,18 +52,18 @@ // Check for the course and module. if ($id) { $cm = get_coursemodule_from_id('moodleoverflow', $id, 0, false, MUST_EXIST); - $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); - $moodleoverflow = $DB->get_record('moodleoverflow', array('id' => $cm->instance), '*', MUST_EXIST); + $course = $DB->get_record('course', ['id' => $cm->course], '*', MUST_EXIST); + $moodleoverflow = $DB->get_record('moodleoverflow', ['id' => $cm->instance], '*', MUST_EXIST); } else if ($m) { - $moodleoverflow = $DB->get_record('moodleoverflow', array('id' => $m), '*', MUST_EXIST); - $course = $DB->get_record('course', array('id' => $moodleoverflow->course), '*', MUST_EXIST); + $moodleoverflow = $DB->get_record('moodleoverflow', ['id' => $m], '*', MUST_EXIST); + $course = $DB->get_record('course', ['id' => $moodleoverflow->course], '*', MUST_EXIST); $cm = get_coursemodule_from_instance('moodleoverflow', $moodleoverflow->id, $course->id, false, MUST_EXIST); } else { throw new moodle_exception('missingparameter'); } // Save the allowmultiplemarks setting. -$marksetting = $DB->get_record('moodleoverflow', array('id' => $moodleoverflow->id), 'allowmultiplemarks'); +$marksetting = $DB->get_record('moodleoverflow', ['id' => $moodleoverflow->id], 'allowmultiplemarks'); // Require a login. require_login($course, true, $cm); @@ -78,14 +78,14 @@ } // Mark the activity completed (if required) and trigger the course_module_viewed event. -$event = \mod_moodleoverflow\event\course_module_viewed::create(array( +$event = \mod_moodleoverflow\event\course_module_viewed::create([ 'objectid' => $PAGE->cm->instance, 'context' => $PAGE->context, -)); +]); $event->trigger(); // Print the page header. -$PAGE->set_url('/mod/moodleoverflow/view.php', array('id' => $cm->id)); +$PAGE->set_url('/mod/moodleoverflow/view.php', ['id' => $cm->id]); $PAGE->set_title(format_string($moodleoverflow->name)); $PAGE->set_heading(format_string($course->fullname)); @@ -100,7 +100,7 @@ if ($moodleoverflow->anonymous > 0) { $strkeys = [ \mod_moodleoverflow\anonymous::QUESTION_ANONYMOUS => 'desc:only_questions', - \mod_moodleoverflow\anonymous::EVERYTHING_ANONYMOUS => 'desc:anonymous' + \mod_moodleoverflow\anonymous::EVERYTHING_ANONYMOUS => 'desc:anonymous', ]; echo html_writer::tag('p', get_string($strkeys[$moodleoverflow->anonymous], 'moodleoverflow')); } @@ -109,7 +109,7 @@ if ($reviewlevel > 0) { $strkeys = [ \mod_moodleoverflow\review::QUESTIONS => 'desc:review_questions', - \mod_moodleoverflow\review::EVERYTHING => 'desc:review_everything' + \mod_moodleoverflow\review::EVERYTHING => 'desc:review_everything', ]; echo html_writer::tag('p', get_string($strkeys[$reviewlevel], 'moodleoverflow')); } @@ -131,7 +131,7 @@ if ($linktoforum && $movetopopup && has_capability('mod/moodleoverflow:movetopic', $context)) { // Take the $movetopopup-id and the $linktoforum-id and move the discussion to the forum. - $topic = $DB->get_record('moodleoverflow_discussions', array('id' => $movetopopup)); + $topic = $DB->get_record('moodleoverflow_discussions', ['id' => $movetopopup]); $topic->moodleoverflow = $linktoforum; $DB->update_record('moodleoverflow_discussions', $topic); redirect($CFG->wwwroot . '/mod/moodleoverflow/view.php?id=' . $cm->id);