From 32d2ae1b563936e79ee9d99b3464e0867cd7f7ed Mon Sep 17 00:00:00 2001 From: AL Rachels Date: Mon, 9 Oct 2023 12:12:59 -0500 Subject: [PATCH] Codechecker and PHPDocs recomendations --- .../moodle2/backup_hotquestion_stepslib.php | 144 ++++++----- ...estore_hotquestion_activity_task.class.php | 10 +- .../moodle2/restore_hotquestion_stepslib.php | 2 +- classes/completion/custom_completion.php | 2 +- classes/event/add_question.php | 2 +- classes/event/add_round.php | 2 +- classes/event/comment_created.php | 2 +- classes/event/comment_deleted.php | 2 +- classes/event/comments_viewed.php | 14 +- classes/event/course_module_viewed.php | 2 +- classes/event/download_questions.php | 2 +- classes/event/entries_viewed.php | 2 +- classes/event/entry_updated.php | 2 +- classes/event/remove_question.php | 2 +- classes/event/remove_round.php | 2 +- classes/event/remove_vote.php | 2 +- classes/event/update_vote.php | 2 +- classes/local/results.php | 60 +++-- classes/output/viewgrades.php | 55 +++-- classes/privacy/provider.php | 4 +- db/access.php | 88 +++---- db/upgrade.php | 2 +- grades.php | 6 +- index.php | 12 +- lib.php | 109 +++++---- locallib.php | 230 +++++++++++------- mod_form.php | 133 +++++++--- renderer.php | 72 +++--- settings.php | 12 +- tests/behat/Add Hot Question Activity.feature | 41 ---- tests/behat/questions_post.feature.disable | 121 --------- ...ions_visibility_after_closing_time.feature | 4 +- tests/behat/toolbar_reload.feature | 2 +- upgrade.txt | 8 + version.php | 6 +- view.php | 30 ++- 36 files changed, 621 insertions(+), 570 deletions(-) delete mode 100644 tests/behat/Add Hot Question Activity.feature delete mode 100644 tests/behat/questions_post.feature.disable diff --git a/backup/moodle2/backup_hotquestion_stepslib.php b/backup/moodle2/backup_hotquestion_stepslib.php index 9f9f29b..768054f 100644 --- a/backup/moodle2/backup_hotquestion_stepslib.php +++ b/backup/moodle2/backup_hotquestion_stepslib.php @@ -51,66 +51,96 @@ protected function define_structure() { $userinfo = $this->get_setting_value('userinfo'); // Define each element separated. - $hotquestion = new backup_nested_element('hotquestion', array('id'), - array('name', - 'intro', - 'introformat', - 'submitdirections', - 'timecreated', - 'timemodified', - 'timeopen', - 'timeclose', - 'viewaftertimeclose', - 'questionlabel', - 'teacherpriorityvisibility', - 'teacherprioritylabel', - 'heatvisibility', - 'heatlabel', - 'heatlimit', - 'anonymouspost', - 'authorhide', - 'approval', - 'approvallabel', - 'removelabel', - 'scale', - 'assessed', - 'assesstimestart', - 'assesstimefinish', - 'comments', - 'grade', - 'postmaxgrade', - 'factorheat', - 'factorpriority', - 'factorvote', - 'completionpost', - 'completionvote', - 'completionpass')); + $hotquestion = new backup_nested_element('hotquestion', + [ + 'id', + ], + [ + 'name', + 'intro', + 'introformat', + 'submitdirections', + 'timecreated', + 'timemodified', + 'timeopen', + 'timeclose', + 'viewaftertimeclose', + 'questionlabel', + 'teacherpriorityvisibility', + 'teacherprioritylabel', + 'heatvisibility', + 'heatlabel', + 'heatlimit', + 'anonymouspost', + 'authorhide', + 'approval', + 'approvallabel', + 'removelabel', + 'scale', + 'assessed', + 'assesstimestart', + 'assesstimefinish', + 'comments', + 'grade', + 'postmaxgrade', + 'factorheat', + 'factorpriority', + 'factorvote', + 'completionpost', + 'completionvote', + 'completionpass', + ] + ); $grades = new backup_nested_element('grades'); - $grade = new backup_nested_element('grade', array('id'), - array('userid', - 'rawrating', - 'timemodified')); + $grade = new backup_nested_element('grade', + [ + 'id', + ], + [ + 'userid', + 'rawrating', + 'timemodified', + ] + ); $questions = new backup_nested_element('questions'); - $question = new backup_nested_element('question', array('id'), - array('content', - 'format', - 'userid', - 'time', - 'anonymous', - 'approved', - 'tpriority')); + $question = new backup_nested_element('question', + [ + 'id', + ], + [ + 'content', + 'format', + 'userid', + 'time', + 'anonymous', + 'approved', + 'tpriority', + ] + ); $rounds = new backup_nested_element('rounds'); - $round = new backup_nested_element('round', array('id'), - array('starttime', - 'endtime')); + $round = new backup_nested_element('round', + [ + 'id', + ], + [ + 'starttime', + 'endtime', + ] + ); $votes = new backup_nested_element('votes'); - $vote = new backup_nested_element('vote', array('id'), - array('question', - 'voter')); + $vote = new backup_nested_element('vote', + [ + 'id', + ], + [ + 'question', + 'voter', + ] + ); // Build the tree. $hotquestion->add_child($grades); @@ -126,14 +156,14 @@ protected function define_structure() { $votes->add_child($vote); // Define sources. - $hotquestion->set_source_table('hotquestion', array('id' => backup::VAR_ACTIVITYID)); + $hotquestion->set_source_table('hotquestion', ['id' => backup::VAR_ACTIVITYID]); // All the rest of elements only happen if we are including user info. if ($userinfo) { - $grade->set_source_table('hotquestion_grades', array('hotquestion' => backup::VAR_PARENTID)); - $question->set_source_table('hotquestion_questions', array('hotquestion' => backup::VAR_PARENTID)); - $round->set_source_table('hotquestion_rounds', array('hotquestion' => backup::VAR_PARENTID)); - $vote->set_source_table('hotquestion_votes', array('question' => backup::VAR_PARENTID)); + $grade->set_source_table('hotquestion_grades', ['hotquestion' => backup::VAR_PARENTID]); + $question->set_source_table('hotquestion_questions', ['hotquestion' => backup::VAR_PARENTID]); + $round->set_source_table('hotquestion_rounds', ['hotquestion' => backup::VAR_PARENTID]); + $vote->set_source_table('hotquestion_votes', ['question' => backup::VAR_PARENTID]); } // Define id annotations. diff --git a/backup/moodle2/restore_hotquestion_activity_task.class.php b/backup/moodle2/restore_hotquestion_activity_task.class.php index 445349b..365dddf 100644 --- a/backup/moodle2/restore_hotquestion_activity_task.class.php +++ b/backup/moodle2/restore_hotquestion_activity_task.class.php @@ -55,9 +55,9 @@ protected function define_my_steps() { * processed by the link decoder. */ public static function define_decode_contents() { - $contents = array(); + $contents = []; - $contents[] = new restore_decode_content('hotquestion', array('intro'), 'hotquestion'); + $contents[] = new restore_decode_content('hotquestion', ['intro'], 'hotquestion'); return $contents; } @@ -67,7 +67,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('HOTQUESTIONVIEWBYID', '/mod/hotquestion/view.php?id=$1', 'course_module'); $rules[] = new restore_decode_rule('HOTQUESTIONINDEX', '/mod/hotquestion/index.php?id=$1', 'course'); @@ -83,7 +83,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('hotquestion', 'view', 'view.php?id={course_module}', '{hotquestion}'); $rules[] = new restore_log_rule('hotquestion', 'add question', 'view.php?id={course_module}', '{hotquestion}'); @@ -104,7 +104,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 = []; // Fix old wrong uses (missing extension). $rules[] = new restore_log_rule('hotquestion', 'view all', 'index?id={course}', null, diff --git a/backup/moodle2/restore_hotquestion_stepslib.php b/backup/moodle2/restore_hotquestion_stepslib.php index 2313f6c..020353b 100644 --- a/backup/moodle2/restore_hotquestion_stepslib.php +++ b/backup/moodle2/restore_hotquestion_stepslib.php @@ -44,7 +44,7 @@ class restore_hotquestion_activity_structure_step extends restore_activity_struc */ protected function define_structure() { - $paths = array(); + $paths = []; $userinfo = $this->get_setting_value('userinfo'); $paths[] = new restore_path_element('hotquestion', '/activity/hotquestion'); diff --git a/classes/completion/custom_completion.php b/classes/completion/custom_completion.php index 656e87e..b047d70 100644 --- a/classes/completion/custom_completion.php +++ b/classes/completion/custom_completion.php @@ -72,7 +72,7 @@ public function get_state(string $rule): int { } else if ($rule == 'completionvote') { $status = $hotquestion->completionvote <= - $DB->get_field_sql($questionvotesql , $questionvoteparams); + $DB->get_field_sql($questionvotesql, $questionvoteparams); } else if ($rule == 'completionpass') { $status = $hotquestion->completionpass <= $DB->get_field_sql($questioncountsql. diff --git a/classes/event/add_question.php b/classes/event/add_question.php index bd8f727..30e1e24 100644 --- a/classes/event/add_question.php +++ b/classes/event/add_question.php @@ -68,6 +68,6 @@ public function get_description() { * @return \moodle_url */ public function get_url() { - return new \moodle_url('/mod/hotquestion/edit.php', array('id' => $this->contextinstanceid)); + return new \moodle_url('/mod/hotquestion/edit.php', ['id' => $this->contextinstanceid]); } } diff --git a/classes/event/add_round.php b/classes/event/add_round.php index 9246bb2..0b25d3f 100644 --- a/classes/event/add_round.php +++ b/classes/event/add_round.php @@ -68,6 +68,6 @@ public function get_description() { * @return \moodle_url */ public function get_url() { - return new \moodle_url('/mod/hotquestion/view.php', array('id' => $this->contextinstanceid)); + return new \moodle_url('/mod/hotquestion/view.php', ['id' => $this->contextinstanceid]); } } diff --git a/classes/event/comment_created.php b/classes/event/comment_created.php index 53445cf..3f60cb2 100644 --- a/classes/event/comment_created.php +++ b/classes/event/comment_created.php @@ -40,7 +40,7 @@ class comment_created extends \core\event\comment_created { * @return \moodle_url */ public function get_url() { - return new \moodle_url('/mod/hotquestion/view.php', array('id' => $this->contextinstanceid)); + return new \moodle_url('/mod/hotquestion/view.php', ['id' => $this->contextinstanceid]); } /** diff --git a/classes/event/comment_deleted.php b/classes/event/comment_deleted.php index 5d4cb94..23c7e16 100644 --- a/classes/event/comment_deleted.php +++ b/classes/event/comment_deleted.php @@ -40,7 +40,7 @@ class comment_deleted extends \core\event\comment_deleted { * @return \moodle_url */ public function get_url() { - return new \moodle_url('/mod/hotquestion/view.php', array('id' => $this->contextinstanceid)); + return new \moodle_url('/mod/hotquestion/view.php', ['id' => $this->contextinstanceid]); } /** diff --git a/classes/event/comments_viewed.php b/classes/event/comments_viewed.php index 40b5c5b..ebfcbb3 100644 --- a/classes/event/comments_viewed.php +++ b/classes/event/comments_viewed.php @@ -61,8 +61,15 @@ public function get_description() { * @return array */ protected function get_legacy_logdata() { - return(array($this->courseid, 'hotquestion', 'comments', - 'comments.php?pageid=' . $this->objectid, $this->objectid, $this->contextinstanceid)); + return( + [ + $this->courseid, + 'hotquestion', + 'comments', + 'comments.php?pageid=' . $this->objectid, + $this->objectid, $this->contextinstanceid, + ] + ); } /** @@ -71,7 +78,6 @@ protected function get_legacy_logdata() { * @return \moodle_url */ public function get_url() { - return new \moodle_url("/mod/hotquestion/view.php", - array('eid' => $this->objectid)); + return new \moodle_url("/mod/hotquestion/view.php", ['eid' => $this->objectid]); } } diff --git a/classes/event/course_module_viewed.php b/classes/event/course_module_viewed.php index 0f7019c..5212df4 100644 --- a/classes/event/course_module_viewed.php +++ b/classes/event/course_module_viewed.php @@ -52,6 +52,6 @@ protected function init() { * @return \moodle_url */ public function get_url() { - return new \moodle_url('/mod/hotquestion/view.php', array('f' => $this->objectid)); + return new \moodle_url('/mod/hotquestion/view.php', ['f' => $this->objectid]); } } diff --git a/classes/event/download_questions.php b/classes/event/download_questions.php index a3a9607..e97c4a0 100644 --- a/classes/event/download_questions.php +++ b/classes/event/download_questions.php @@ -74,6 +74,6 @@ public function get_description() { * @return \moodle_url */ public function get_url() { - return new \moodle_url('/mod/hotquestion/view.php', array('id' => $this->contextinstanceid)); + return new \moodle_url('/mod/hotquestion/view.php', ['id' => $this->contextinstanceid]); } } diff --git a/classes/event/entries_viewed.php b/classes/event/entries_viewed.php index c747334..b15eb63 100644 --- a/classes/event/entries_viewed.php +++ b/classes/event/entries_viewed.php @@ -68,6 +68,6 @@ public function get_description() { * @return \moodle_url */ public function get_url() { - return new \moodle_url('/mod/hotquestion/report.php', array('id' => $this->contextinstanceid)); + return new \moodle_url('/mod/hotquestion/report.php', ['id' => $this->contextinstanceid]); } } diff --git a/classes/event/entry_updated.php b/classes/event/entry_updated.php index 4e8b40b..cdda4df 100644 --- a/classes/event/entry_updated.php +++ b/classes/event/entry_updated.php @@ -68,6 +68,6 @@ public function get_description() { * @return \moodle_url */ public function get_url() { - return new \moodle_url('/mod/hotquestion/edit.php', array('id' => $this->contextinstanceid)); + return new \moodle_url('/mod/hotquestion/edit.php', ['id' => $this->contextinstanceid]); } } diff --git a/classes/event/remove_question.php b/classes/event/remove_question.php index 587792b..2ccc2ce 100644 --- a/classes/event/remove_question.php +++ b/classes/event/remove_question.php @@ -68,6 +68,6 @@ public function get_description() { * @return \moodle_url */ public function get_url() { - return new \moodle_url('/mod/hotquestion/view.php', array('id' => $this->contextinstanceid)); + return new \moodle_url('/mod/hotquestion/view.php', ['id' => $this->contextinstanceid]); } } diff --git a/classes/event/remove_round.php b/classes/event/remove_round.php index 611866e..f49f460 100644 --- a/classes/event/remove_round.php +++ b/classes/event/remove_round.php @@ -68,6 +68,6 @@ public function get_description() { * @return \moodle_url */ public function get_url() { - return new \moodle_url('/mod/hotquestion/view.php', array('id' => $this->contextinstanceid)); + return new \moodle_url('/mod/hotquestion/view.php', ['id' => $this->contextinstanceid]); } } diff --git a/classes/event/remove_vote.php b/classes/event/remove_vote.php index c0d3ce3..80513a8 100644 --- a/classes/event/remove_vote.php +++ b/classes/event/remove_vote.php @@ -68,6 +68,6 @@ public function get_description() { * @return \moodle_url */ public function get_url() { - return new \moodle_url('/mod/hotquestion/view.php', array('id' => $this->contextinstanceid)); + return new \moodle_url('/mod/hotquestion/view.php', ['id' => $this->contextinstanceid]); } } diff --git a/classes/event/update_vote.php b/classes/event/update_vote.php index 2f04bff..bd6fb64 100644 --- a/classes/event/update_vote.php +++ b/classes/event/update_vote.php @@ -68,6 +68,6 @@ public function get_description() { * @return \moodle_url */ public function get_url() { - return new \moodle_url('/mod/hotquestion/view.php', array('id' => $this->contextinstanceid)); + return new \moodle_url('/mod/hotquestion/view.php', ['id' => $this->contextinstanceid]); } } diff --git a/classes/local/results.php b/classes/local/results.php index 8df6498..7ad0863 100644 --- a/classes/local/results.php +++ b/classes/local/results.php @@ -35,8 +35,8 @@ use context_module; use calendar_event; use comment; -use \mod_hotquestion\event\comments_viewed; -use \mod_hotquestion\event\add_question; +use mod_hotquestion\event\comments_viewed; +use mod_hotquestion\event\add_question; /** * Utility class for Hot Question results. @@ -69,7 +69,12 @@ public static function hotquestion_update_calendar(stdClass $hotquestion, $cmid) $event->type = empty($hotquestion->timeclose) ? CALENDAR_EVENT_TYPE_ACTION : CALENDAR_EVENT_TYPE_STANDARD; } if ($event->id = $DB->get_field('event', 'id', - array('modulename' => 'hotquestion', 'instance' => $hotquestion->id, 'eventtype' => $event->eventtype))) { + [ + 'modulename' => 'hotquestion', + 'instance' => $hotquestion->id, + 'eventtype' => $event->eventtype, + ] + )) { if ((!empty($hotquestion->timeopen)) && ($hotquestion->timeopen > 0)) { // Calendar event exists so update it. $event->name = get_string('calendarstart', 'hotquestion', $hotquestion->name); @@ -112,7 +117,12 @@ public static function hotquestion_update_calendar(stdClass $hotquestion, $cmid) } $event->eventtype = HOTQUESTION_EVENT_TYPE_CLOSE; if ($event->id = $DB->get_field('event', 'id', - array('modulename' => 'hotquestion', 'instance' => $hotquestion->id, 'eventtype' => $event->eventtype))) { + [ + 'modulename' => 'hotquestion', + 'instance' => $hotquestion->id, + 'eventtype' => $event->eventtype, + ] + )) { if ((!empty($hotquestion->timeclose)) && ($hotquestion->timeclose > 0)) { // Calendar event exists so update it. $event->name = get_string('calendarend', 'hotquestion', $hotquestion->name); @@ -165,7 +175,7 @@ public static function hotquestion_get_coursemodule($hotquestionid) { JOIN {modules} m ON m.id = cm.module WHERE cm.instance = :hqid AND m.name = 'hotquestion'"; - $params = array(); + $params = []; $params = ['hqid' => $hotquestionid]; return $DB->get_record_sql($sql, $params); } @@ -204,7 +214,7 @@ public static function hotquestion_count_entries($hotquestion, $groupid = 0) { AND hr.endtime=0 AND hq.time>=hr.starttime AND hq.userid>0"; - $params = array(); + $params = []; $params = ['hqid' => $hotquestion->id] + ['gidid' => $gid->id]; $hotquestions = $DB->get_records_sql($sql, $params); } @@ -226,7 +236,7 @@ public static function hotquestion_count_entries($hotquestion, $groupid = 0) { AND hq.time >= hr.starttime AND hq.userid = :userid"; - $params = array(); + $params = []; $params = ['hqid' => $hotquestion->id] + ['userid' => $USER->id]; $hotquestions = $DB->get_records_sql($sql, $params); @@ -241,7 +251,7 @@ public static function hotquestion_count_entries($hotquestion, $groupid = 0) { AND hr.endtime = 0 AND hq.time >= hr.starttime AND hq.userid > 0"; - $params = array(); + $params = []; $params = ['hqid' => $hotquestion->id]; $hotquestions = $DB->get_records_sql($sql, $params); } @@ -271,9 +281,13 @@ public static function hotquestion_get_question_comment_count($question, $cm, $c // 20210313 Not in use yet. Part of future development. global $DB; - if ($count = $DB->count_records('comments', array('itemid' => $question->id, - 'commentarea' => 'hotquestion_questions', - 'contextid' => $cm->id))) { + if ($count = $DB->count_records('comments', + [ + 'itemid' => $question->id, + 'commentarea' => 'hotquestion_questions', + 'contextid' => $cm->id, + ] + )) { return $count; } else { return 0; @@ -329,7 +343,7 @@ public static function hotquestion_display_question_comments($question, $cm, $co * @return array */ public static function hotquestion_comment_permissions($commentparam) { - return array('ask' => true, 'view' => true); + return ['ask' => true, 'view' => true]; } /** @@ -343,23 +357,23 @@ public static function hotquestion_get_editor_and_attachment_options($course, $c $maxfiles = 99; // TODO: add some setting. $maxbytes = $course->maxbytes; // TODO: add some setting. - $editoroptions = array( + $editoroptions = [ 'trusttext' => true, 'maxfiles' => $maxfiles, 'maxbytes' => $maxbytes, 'context' => $context, - 'subdirs' => false - ); - $attachmentoptions = array( + 'subdirs' => false, + ]; + $attachmentoptions = [ 'subdirs' => false, 'maxfiles' => $maxfiles, - 'maxbytes' => $maxbytes - ); + 'maxbytes' => $maxbytes, + ]; - return array( + return [ $editoroptions, - $attachmentoptions - ); + $attachmentoptions, + ]; } /** @@ -389,10 +403,10 @@ public static function add_new_question($newentry, $hq) { if (!empty($newentry->content)) { // If there is some actual content, then create a new record. $DB->insert_record('hotquestion_questions', $newentry); - $params = array( + $params = [ 'objectid' => $hq->cm->id, 'context' => $context, - ); + ]; $event = add_question::create($params); $event->trigger(); diff --git a/classes/output/viewgrades.php b/classes/output/viewgrades.php index ee4d154..c5745f1 100644 --- a/classes/output/viewgrades.php +++ b/classes/output/viewgrades.php @@ -25,12 +25,12 @@ namespace mod_hotquestion\output; -use \table_sql; -use \context_module; -use \moodle_url; -use \html_writer; -use \user_picture; -use \grade_item; +use table_sql; +use context_module; +use moodle_url; +use html_writer; +use user_picture; +use grade_item; defined('MOODLE_INTERNAL') || die(); @@ -155,29 +155,30 @@ protected function init($group = 0, $userid = 0) { global $CFG, $DB; // 20220503 Changed votes to heatgiven. Added teacher priority and heatreceived. // 20220504 Added teacherpriority. - $tablecolumns = array('userpic', - 'fullname', - 'questions', - 'teacherpriority', - 'heatgiven', - 'heatreceived', - 'rawrating', - 'finalgrade' - ); + $tablecolumns = [ + 'userpic', + 'fullname', + 'questions', + 'teacherpriority', + 'heatgiven', + 'heatreceived', + 'rawrating', + 'finalgrade', + ]; // 20220716 Get the grade point setting for this Hot Question. $finalgrade = $this->hotquestion->instance->grade; // If HotQuestion is set for None or Points, then skip ahead. // If set for Scale, then figure out the scale index and entry for the maximum score. if ($finalgrade < 0) { - if ($scale = $DB->get_record('scale', array('id' => -($this->hotquestion->instance->grade)))) { + if ($scale = $DB->get_record('scale', ['id' => -($this->hotquestion->instance->grade)])) { $this->cache['scale'] = make_menu_from_list($scale->scale); } $finalgrade = count($this->cache['scale']); $finalgrade .= '='.($this->cache['scale'][$finalgrade]); } - $tableheaders = array( + $tableheaders = [ get_string('userpic'), get_string('fullnameuser'), format_string($this->hotquestion->instance->questionlabel).' ('.($this->hotquestion->instance->postmaxgrade).')', @@ -186,7 +187,7 @@ protected function init($group = 0, $userid = 0) { get_string('heatreceived', 'hotquestion').' ('.($this->hotquestion->instance->factorvote).'%)', get_string('grading', 'hotquestion' ), get_string('finalgrade', 'hotquestion').' ('.($finalgrade).')', - ); + ]; $context = $this->get_context(); @@ -290,7 +291,7 @@ public function other_cols($column, $row) { public function col_userpic($row) { global $OUTPUT; $user = user_picture::unalias($row, [], $this->useridfield); - return $OUTPUT->user_picture($user, array('courseid' => $this->hotquestion->cm->course)); + return $OUTPUT->user_picture($user, ['courseid' => $this->hotquestion->cm->course]); } /** @@ -598,11 +599,13 @@ public function get_grade_item() { if ($this->gradeitem) { return $this->gradeitem; } - $params = array('itemtype' => 'mod', - 'itemmodule' => 'hotquestion', - 'iteminstance' => $this->hotquestion->instance->id, - 'courseid' => $this->hotquestion->instance->course, - 'itemnumber' => 0); + $params = [ + 'itemtype' => 'mod', + 'itemmodule' => 'hotquestion', + 'iteminstance' => $this->hotquestion->instance->id, + 'courseid' => $this->hotquestion->instance->course, + 'itemnumber' => 0, + ]; $this->gradeitem = grade_item::fetch($params); if (!$this->gradeitem) { throw new coding_exception(get_string('improperuseviewgradesclass', 'hotquestion')); @@ -619,7 +622,7 @@ public function get_grade_item() { public function display_grade($grade) { global $DB; - static $scalegrades = array(); + static $scalegrades = []; $o = ''; @@ -640,7 +643,7 @@ public function display_grade($grade) { } else { // If using scale and the Scale is missing go here. if (empty($this->cache['scale'])) { - if ($scale = $DB->get_record('scale', array('id' => -($this->hotquestion->instance->grade)))) { + if ($scale = $DB->get_record('scale', ['id' => -($this->hotquestion->instance->grade)])) { $this->cache['scale'] = make_menu_from_list($scale->scale); } else { $o .= '-'; diff --git a/classes/privacy/provider.php b/classes/privacy/provider.php index 063af6f..be8be7d 100644 --- a/classes/privacy/provider.php +++ b/classes/privacy/provider.php @@ -118,7 +118,7 @@ public static function get_contexts_for_userid(int $userid) : contextlist { 'modid' => $modid, 'contextlevel' => CONTEXT_MODULE, 'userid1' => $userid, - 'userid2' => $userid + 'userid2' => $userid, ]; // User-created hotquestion entries. @@ -280,7 +280,7 @@ public static function export_user_data(approved_contextlist $contextlist) { 'time' => transform::datetime($question->time), 'anonymous' => transform::yesno($question->anonymous), 'approved' => transform::yesno($question->approved), - 'tpriority' => $question->tpriority + 'tpriority' => $question->tpriority, ]; } $questions->close(); diff --git a/db/access.php b/db/access.php index 91daf60..da6ceb3 100644 --- a/db/access.php +++ b/db/access.php @@ -48,90 +48,90 @@ defined('MOODLE_INTERNAL') || die(); -$capabilities = array( - - 'mod/hotquestion:manageentries' => array( +$capabilities = [ + 'mod/hotquestion:manageentries' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'editingteacher' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ) - ), + 'manager' => CAP_ALLOW, + ], + ], - 'mod/hotquestion:addinstance' => array( + 'mod/hotquestion:addinstance' => [ 'riskbitmask' => RISK_XSS, 'captype' => 'write', 'contextlevel' => CONTEXT_COURSE, - 'archetypes' => array( + 'archetypes' => [ 'editingteacher' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ), - 'clonepermissionsfrom' => 'moodle/course:manageactivities' - ), + 'manager' => CAP_ALLOW, + ], + 'clonepermissionsfrom' => 'moodle/course:manageactivities', + ], - 'mod/hotquestion:view' => array( + 'mod/hotquestion:view' => [ 'captype' => 'read', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'guest' => CAP_ALLOW, 'student' => CAP_ALLOW, 'teacher' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ) - ), + 'manager' => CAP_ALLOW, + ], + ], - 'mod/hotquestion:vote' => array( + 'mod/hotquestion:vote' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'student' => CAP_ALLOW, 'teacher' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ) - ), + 'manager' => CAP_ALLOW, + ], + ], - 'mod/hotquestion:ask' => array( + 'mod/hotquestion:ask' => [ '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/hotquestion:manage' => array( + 'mod/hotquestion:manage' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'editingteacher' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ) - ), - 'mod/hotquestion:rate' => array( + 'manager' => CAP_ALLOW, + ], + ], + + 'mod/hotquestion:rate' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'teacher' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ) - ), - 'mod/hotquestion:comment' => array( + 'manager' => CAP_ALLOW, + ], + ], + 'mod/hotquestion:comment' => [ '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, + ], + ], +]; diff --git a/db/upgrade.php b/db/upgrade.php index d49e527..f4f701c 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -75,7 +75,7 @@ function xmldb_hotquestion_upgrade($oldversion=0) { $result = $result && $table->add_field($table, $field); // Define index course (not unique) to be added to hotquestion. - $result = $result && $table->add_index('course', XMLDB_INDEX_NOTUNIQUE, array('course')); + $result = $result && $table->add_index('course', XMLDB_INDEX_NOTUNIQUE, ['course']); } if ($result && $oldversion < 2007040200) { diff --git a/grades.php b/grades.php index 6eb6a1e..3c62a12 100644 --- a/grades.php +++ b/grades.php @@ -26,7 +26,7 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later$this->hotquestion->instance->questionlabel */ -use \mod_hotquestion\event\course_module_viewed; +use mod_hotquestion\event\course_module_viewed; require_once("../../config.php"); require_once("lib.php"); @@ -39,7 +39,7 @@ throw new moodle_exception(get_string('incorrectmodule', 'hotquestion')); } -$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); +$course = $DB->get_record('course', ['id' => $cm->course, '*', MUST_EXIST); // Construct hotquestion instance. @@ -80,7 +80,7 @@ } // Start print page. -$hotquestionname = format_string($hq->instance->name, true, array('context' => $context)); +$hotquestionname = format_string($hq->instance->name, true, ['context' => $context]); echo $output->header(); echo $output->heading($hotquestionname); diff --git a/index.php b/index.php index 43d2831..947d267 100644 --- a/index.php +++ b/index.php @@ -24,20 +24,20 @@ */ use mod_hotquestion\local\results; -use \mod_hotquestion\event\course_module_instance_list_viewed; +use mod_hotquestion\event\course_module_instance_list_viewed; require(__DIR__ . "/../../config.php"); require_once(__DIR__ . '/locallib.php'); $id = required_param('id', PARAM_INT); // Course. -$course = $DB->get_record('course', array('id' => $id), '*', MUST_EXIST); +$course = $DB->get_record('course', ['id' => $id], '*', MUST_EXIST); require_course_login($course); // Header. $strhotquestions = get_string("modulenameplural", "hotquestion"); $PAGE->set_pagelayout('incourse'); -$PAGE->set_url('/mod/hotquestion/index.php', array('id' => $id)); +$PAGE->set_url('/mod/hotquestion/index.php', ['id' => $id]); $PAGE->navbar->add($strhotquestions); $PAGE->set_title($strhotquestions); $PAGE->set_heading($course->fullname); @@ -64,8 +64,8 @@ // Table data. $table = new html_table(); -$table->head = array(); -$table->align = array(); +$table->head = []; +$table->align = []; if ($usesections) { $table->head[] = get_string('sectionname', 'format_'.$course->format); @@ -148,7 +148,7 @@ echo html_writer::table($table); // Trigger course module instance list event. -$params = array('context' => context_course::instance($course->id)); +$params = ['context' => context_course::instance($course->id)]; $event = course_module_instance_list_viewed::create($params); $event->add_record_snapshot('course', $course); $event->trigger(); diff --git a/lib.php b/lib.php index 33f324f..df8cf62 100644 --- a/lib.php +++ b/lib.php @@ -132,7 +132,7 @@ function hotquestion_update_instance($hotquestion) { function hotquestion_delete_instance($id) { global $DB; - if (! $hotquestion = $DB->get_record('hotquestion', array('id' => $id))) { + if (! $hotquestion = $DB->get_record('hotquestion', ['id' => $id])) { return false; } @@ -148,7 +148,7 @@ function hotquestion_delete_instance($id) { } \core_completion\api::update_completion_date_event($cm->id, 'hotquestion', $hotquestion->id, null); // Contrib by ecastro ULPGC. - if (! $DB->delete_records('hotquestion', array('id' => $hotquestion->id))) { + if (! $DB->delete_records('hotquestion', ['id' => $hotquestion->id])) { return false; } @@ -164,24 +164,24 @@ function hotquestion_delete_instance($id) { function reset_instance($hotquestionid) { global $DB; // 20220810 Added to fix git hub issue #65. - $hotquestion = $DB->get_record('hotquestion', array('id' => $hotquestionid)); - $questions = $DB->get_records('hotquestion_questions', array('hotquestion' => $hotquestionid)); + $hotquestion = $DB->get_record('hotquestion', ['id' => $hotquestionid]); + $questions = $DB->get_records('hotquestion_questions', ['hotquestion' => $hotquestionid]); foreach ($questions as $question) { - if (! $DB->delete_records('hotquestion_votes', array('question' => $question->id))) { + if (! $DB->delete_records('hotquestion_votes', ['question' => $question->id])) { return false; } } - if (! $DB->delete_records('hotquestion_questions', array('hotquestion' => $hotquestionid))) { + if (! $DB->delete_records('hotquestion_questions', ['hotquestion' => $hotquestionid])) { return false; } - if (! $DB->delete_records('hotquestion_rounds', array('hotquestion' => $hotquestionid))) { + if (! $DB->delete_records('hotquestion_rounds', ['hotquestion' => $hotquestionid])) { return false; } // Contrib by ecastro ULPGC. - if (! $DB->delete_records('hotquestion_grades', array('hotquestion' => $hotquestionid))) { + if (! $DB->delete_records('hotquestion_grades', ['hotquestion' => $hotquestionid])) { return false; } @@ -198,12 +198,12 @@ function reset_instance($hotquestionid) { */ function get_question_list($hotquestionid) { global $CFG, $USER, $DB; - $params = array(); - $toreturn = array(); + $params = []; + $toreturn = []; $questionstblname = $CFG->prefix."hotquestion_questions"; $userstblname = $CFG->prefix."user"; $sql = 'SELECT COUNT(*) FROM {hotquestion_questions} WHERE userid>0'; - return $DB->get_records_sql($sql, array($USER->id)); + return $DB->get_records_sql($sql, [$USER->id]); } /** @@ -253,7 +253,7 @@ function hotquestion_user_complete($course, $user, $mod, $hotquestion) { function hotquestion_print_recent_activity($course, $viewfullnames, $timestart) { global $CFG, $USER, $DB, $OUTPUT; - $dbparams = array($timestart, $course->id, 'hotquestion'); + $dbparams = [$timestart, $course->id, 'hotquestion']; $userfieldsapi = \core_user\fields::for_userpic(); $namefields = $userfieldsapi->get_sql('u', false, '', 'userid', false)->selects; @@ -279,8 +279,8 @@ function hotquestion_print_recent_activity($course, $viewfullnames, $timestart) $newentries = $DB->get_records_sql($sql, $dbparams); $modinfo = get_fast_modinfo($course); - $show = array(); - $grader = array(); + $show = []; + $grader = []; $showrecententries = get_config('hotquestion', 'showrecentactivity'); foreach ($newentries as $anentry) { @@ -391,14 +391,16 @@ function hotquestion_get_participants($hotquestionid) { function hotquestion_reset_userdata($data) { global $DB; - $status = array(); + $status = []; if (!empty($data->reset_hotquestion)) { - $instances = $DB->get_records('hotquestion', array('course' => $data->courseid)); + $instances = $DB->get_records('hotquestion', ['course' => $data->courseid]); foreach ($instances as $instance) { if (reset_instance($instance->id)) { - $status[] = array('component' => get_string('modulenameplural', 'hotquestion') - , 'item' => get_string('resethotquestion', 'hotquestion') - .': '.$instance->name, 'error' => false); + $status[] = [ + 'component' => get_string('modulenameplural', 'hotquestion'), + 'item' => get_string('resethotquestion', 'hotquestion').': '.$instance->name, + 'error' => false, + ]; } } } @@ -490,13 +492,13 @@ function hotquestion_comment_validate($commentparam) { if ($commentparam->commentarea != 'hotquestion_questions') { throw new comment_exception('invalidcommentarea'); } - if (!$record = $DB->get_record('hotquestion_questions', array('id' => $commentparam->itemid))) { + if (!$record = $DB->get_record('hotquestion_questions', ['id' => $commentparam->itemid])) { throw new comment_exception('invalidcommentitemid'); } - if (!$hotquestion = $DB->get_record('hotquestion', array('id' => $record->hotquestion))) { + if (!$hotquestion = $DB->get_record('hotquestion', ['id' => $record->hotquestion])) { throw new comment_exception('invalidid', 'data'); } - if (!$course = $DB->get_record('course', array('id' => $hotquestion->course))) { + if (!$course = $DB->get_record('course', ['id' => $hotquestion->course])) { throw new comment_exception('coursemisconf'); } if (!$cm = get_coursemodule_from_instance('hotquestion', $hotquestion->id, $course->id)) { @@ -513,7 +515,7 @@ function hotquestion_comment_validate($commentparam) { } // Validation for comment deletion. if (!empty($commentparam->commentid)) { - if ($comment = $DB->get_record('comments', array('id' => $commentparam->commentid))) { + if ($comment = $DB->get_record('comments', ['id' => $commentparam->commentid])) { if ($comment->commentarea != 'hotquestion_questions') { throw new comment_exception('invalidcommentarea'); } @@ -548,7 +550,7 @@ function hotquestion_comment_validate($commentparam) { * @return array */ function hotquestion_comment_permissions($commentparam) { - return array('post' => true, 'view' => true); + return ['post' => true, 'view' => true]; } /** @@ -556,11 +558,13 @@ function hotquestion_comment_permissions($commentparam) { * @return array */ function hotquestion_get_extra_capabilities() { - return array('moodle/comment:post', - 'moodle/comment:view', - 'moodle/site:viewfullnames', - 'moodle/site:trustcontent', - 'moodle/site:accessallgroups'); + return [ + 'moodle/comment:post', + 'moodle/comment:view', + 'moodle/site:viewfullnames', + 'moodle/site:trustcontent', + 'moodle/site:accessallgroups', + ]; } // Contrib by ecastro ULPGC. @@ -573,15 +577,13 @@ function hotquestion_get_extra_capabilities() { * @param stdClass $cm Course-module * @param int $userid User ID * @param bool $type Type of comparison (or/and; can be used as return value if no conditions) - * @author 2022 Enrique Castro * @return bool True if completed, false if not. (If no conditions, then return * value depends on comparison type) */ function hotquestion_get_completion_state($course, $cm, $userid, $type) { - global $DB; - global $CFG; + global $DB, $CFG; - $hotquestion = $DB->get_record('hotquestion', array('id' => $cm->instance), '*', MUST_EXIST); + $hotquestion = $DB->get_record('hotquestion', ['id' => $cm->instance], '*', MUST_EXIST); if (!$hotquestion->completionpost && !$hotquestion->completionvote && !$hotquestion->completionpass) { return $type; } @@ -591,7 +593,11 @@ function hotquestion_get_completion_state($course, $cm, $userid, $type) { // Check if the user has used up all attempts. if ($hotquestion->completionpost) { $value = $hotquestion->completionpost <= - $DB->count_records('hotquestion_questions', array('hotquestion' => $hotquestion->id, 'userid' => $userid)); + $DB->count_records('hotquestion_questions', [ + 'hotquestion' => $hotquestion->id, + 'userid' => $userid, + ] + ); if ($type == COMPLETION_AND) { $result = $result && $value; } else { @@ -605,7 +611,10 @@ function hotquestion_get_completion_state($course, $cm, $userid, $type) { FROM {hotquestion_votes} v JOIN {hotquestion_questions} q ON q.id = v.question WHERE q.hotquestion = :hotquestion AND v.voter = :userid "; - $params = array('hotquestion' => $hotquestion->id, 'userid' => $userid); + $params = [ + 'hotquestion' => $hotquestion->id, + 'userid' => $userid, + ]; $value = $hotquestion->completionvote <= $DB->count_records_sql($sql, $params); if ($type == COMPLETION_AND) { $result = $result && $value; @@ -617,10 +626,15 @@ function hotquestion_get_completion_state($course, $cm, $userid, $type) { // Check for passing grade. if ($hotquestion->completionpass) { require_once($CFG->libdir . '/gradelib.php'); - $item = grade_item::fetch(array('courseid' => $course->id, 'itemtype' => 'mod', - 'itemmodule' => 'hotquestion', 'iteminstance' => $cm->instance, 'outcomeid' => null)); + $item = grade_item::fetch([ + 'courseid' => $course->id, + 'itemtype' => 'mod', + 'itemmodule' => 'hotquestion', + 'iteminstance' => $cm->instance, + 'outcomeid' => null, + ]); if ($item) { - $grades = grade_grade::fetch_users_grades($item, array($userid), false); + $grades = grade_grade::fetch_users_grades($item, [$userid], false); if (!empty($grades[$userid])) { return $grades[$userid]->is_passed($item); } @@ -755,7 +769,7 @@ function hotquestion_grade_item_update($hotquestion, $grades=null) { require_once($CFG->libdir.'/gradelib.php'); // Hot Question does not use the Moodle rating, only the whole Hot Question grade. - $item = array(); + $item = []; $item['itemname'] = clean_param($hotquestion->name, PARAM_NOTAGS); $item['gradetype'] = GRADE_TYPE_VALUE; @@ -857,13 +871,14 @@ function hotquestion_grade_item_delete($hotquestion) { require_once($CFG->libdir.'/gradelib.php'); return grade_update('mod/hotquestion', - $hotquestion->course, - 'mod', - 'hotquestion', - $hotquestion->id, - 1, - null, - array('deleted' => 1)); + $hotquestion->course, + 'mod', + 'hotquestion', + $hotquestion->id, + 1, + null, + ['deleted' => 1] + ); } @@ -881,7 +896,7 @@ function hotquestion_rescale_activity_grades(stdClass $course, stdClass $cm, flo float $oldmax, float $newmin, float $newmax): bool { global $DB; - $dbparams = array('id' => $cm->instance); + $dbparams = ['id' => $cm->instance]; $hotquestion = $DB->get_record('hotquestion', $dbparams); $hotquestion->cmid = $cm->id; $hotquestion->cmidnumber = $cm->idnumber; diff --git a/locallib.php b/locallib.php index d3c5832..e3e195a 100644 --- a/locallib.php +++ b/locallib.php @@ -27,14 +27,14 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -use \mod_hotquestion\event\remove_vote; -use \mod_hotquestion\event\update_vote; -use \mod_hotquestion\event\add_question; -use \mod_hotquestion\event\add_round; -use \mod_hotquestion\event\remove_question; -use \mod_hotquestion\event\remove_round; -use \mod_hotquestion\event\download_questions; -use \mod_hotquestion\local\results; +use mod_hotquestion\event\remove_vote; +use mod_hotquestion\event\update_vote; +use mod_hotquestion\event\add_question; +use mod_hotquestion\event\add_round; +use mod_hotquestion\event\remove_question; +use mod_hotquestion\event\remove_round; +use mod_hotquestion\event\download_questions; +use mod_hotquestion\local\results; defined('MOODLE_INTERNAL') || die(); // @codingStandardsIgnoreLine define('HOTQUESTION_EVENT_TYPE_OPEN', 'open'); @@ -79,8 +79,8 @@ class mod_hotquestion { public function __construct($cmid, $roundid = -1) { global $DB; $this->cm = get_coursemodule_from_id('hotquestion', $cmid, 0, false, MUST_EXIST); - $this->course = $DB->get_record('course', array('id' => $this->cm->course), '*', MUST_EXIST); - $this->instance = $DB->get_record('hotquestion', array('id' => $this->cm->instance), '*', MUST_EXIST); + $this->course = $DB->get_record('course', ['id' => $this->cm->course], '*', MUST_EXIST); + $this->instance = $DB->get_record('hotquestion', ['id' => $this->cm->instance], '*', MUST_EXIST); $this->set_currentround($roundid); // Contrib by ecastro ULPGC, for grades callbacks. @@ -101,7 +101,7 @@ public function has_voted($question, $user = -1) { if ($user == -1) { $user = $USER->id; } - return $DB->record_exists('hotquestion_votes', array('question' => $question, 'voter' => $user)); + return $DB->record_exists('hotquestion_votes', ['question' => $question, 'voter' => $user]); } /** @@ -114,14 +114,14 @@ public function vote_on($question) { global $CFG, $DB, $USER; $votes = new StdClass(); $context = context_module::instance($this->cm->id); - $question = $DB->get_record('hotquestion_questions', array('id' => $question)); + $question = $DB->get_record('hotquestion_questions', ['id' => $question]); if ($question && $this->can_vote_on($question)) { // Trigger and log a vote event. - $params = array( + $params = [ 'objectid' => $this->cm->id, 'context' => $context, - ); + ]; $event = update_vote::create($params); $event->trigger(); @@ -130,7 +130,7 @@ public function vote_on($question) { $votes->voter = $USER->id; $DB->insert_record('hotquestion_votes', $votes); } else { - $DB->delete_records('hotquestion_votes', array('question' => $question->id, 'voter' => $USER->id)); + $DB->delete_records('hotquestion_votes', ['question' => $question->id, 'voter' => $USER->id]); } // Update viewed completion state for current user. $this->update_completion_state(); @@ -150,14 +150,14 @@ public function remove_vote($question) { global $CFG, $DB, $USER; $votes = new StdClass(); $context = context_module::instance($this->cm->id); - $question = $DB->get_record('hotquestion_questions', array('id' => $question)); + $question = $DB->get_record('hotquestion_questions', ['id' => $question]); if ($question && $this->can_vote_on($question)) { // Trigger and log a remove_vote event. - $params = array( + $params = [ 'objectid' => $this->cm->id, 'context' => $context, - ); + ]; $event = remove_vote::create($params); $event->trigger(); @@ -166,7 +166,7 @@ public function remove_vote($question) { $votes->voter = $USER->id; $DB->insert_record('hotquestion_votes', $votes); } else { - $DB->delete_records('hotquestion_votes', array('question' => $question->id, 'voter' => $USER->id)); + $DB->delete_records('hotquestion_votes', ['question' => $question->id, 'voter' => $USER->id]); } // Update viewed completion state for current user. $this->update_completion_state(); @@ -185,14 +185,14 @@ public function can_vote_on($question, $user = null) { global $USER, $DB; if (is_int($question)) { - $question = $DB->get_record('hotquestion_questions', array('id' => $question)); + $question = $DB->get_record('hotquestion_questions', ['id' => $question]); } if (empty($user)) { $user = $USER; } // Is this question in last round? - $rounds = $DB->get_records('hotquestion_rounds', array('hotquestion' => $this->instance->id), 'id DESC', '*', 0, 1); + $rounds = $DB->get_records('hotquestion_rounds', ['hotquestion' => $this->instance->id], 'id DESC', '*', 0, 1); $lastround = reset($rounds); $inlastround = $question->time >= $lastround->starttime; @@ -209,7 +209,11 @@ public function can_vote_on($question, $user = null) { public function heat_tally($hq, $user = null) { global $USER, $CFG, $DB; - $params = array($hq->currentround->id, $hq->currentround->hotquestion, $USER->id); + $params = [ + $hq->currentround->id, + $hq->currentround->hotquestion, + $USER->id, + ]; $sql = "SELECT hqq.id AS questionid, COUNT(hqv.voter) AS heat, @@ -249,7 +253,7 @@ public function add_new_round() { global $USER, $CFG, $DB; // Close the latest round. - $rounds = $DB->get_records('hotquestion_rounds', array('hotquestion' => $this->instance->id), 'id DESC', '*', 0, 1); + $rounds = $DB->get_records('hotquestion_rounds', ['hotquestion' => $this->instance->id], 'id DESC', '*', 0, 1); $old = array_pop($rounds); $old->endtime = time(); $DB->update_record('hotquestion_rounds', $old); @@ -263,10 +267,10 @@ public function add_new_round() { $rid = $DB->insert_record('hotquestion_rounds', $new); // Trigger add new round event. - $params = array( + $params = [ 'objectid' => $this->cm->id, 'context' => $context, - ); + ]; $event = add_round::create($params); $event->trigger(); } @@ -279,7 +283,7 @@ public function set_currentround($roundid = -1) { global $DB; // Get all the rounds for this Hot Question. - $rounds = $DB->get_records('hotquestion_rounds', array('hotquestion' => $this->instance->id), 'id ASC'); + $rounds = $DB->get_records('hotquestion_rounds', ['hotquestion' => $this->instance->id], 'id ASC'); // 20210214 Get total number of rounds for the current Hot Question activity. $this->roundcount = (count($rounds)); @@ -382,7 +386,11 @@ public function get_questions() { if ($this->currentround->endtime == 0) { $this->currentround->endtime = 0xFFFFFFFF; // Hack. } - $params = array($this->instance->id, $this->currentround->starttime, $this->currentround->endtime); + $params = [ + $this->instance->id, + $this->currentround->starttime, + $this->currentround->endtime, + ]; // 20210306 Added format to the selection. return $DB->get_records_sql('SELECT q.id, q.hotquestion, q.content, q.format, q.userid, q.time, q.anonymous, q.approved, q.tpriority, count(v.voter) as votecount @@ -409,28 +417,28 @@ public function remove_question() { $data->hotquestion = $this->instance->id; $context = context_module::instance($this->cm->id); // Trigger remove_question event. - $params = array( + $params = [ 'objectid' => $this->cm->id, 'context' => $context, - ); + ]; $event = remove_question::create($params); $event->trigger(); if (null !== (required_param('q', PARAM_INT))) { $questionid = required_param('q', PARAM_INT); $itemid = required_param('q', PARAM_INT); - $dbquestion = $DB->get_record('hotquestion_questions', array('id' => $questionid)); + $dbquestion = $DB->get_record('hotquestion_questions', ['id' => $questionid]); // Contrib by ecastro ULPGC. $users = $this->get_question_voters($questionid); $users[] = $dbquestion->userid; // Contrib by ecastro ULPGC. - $DB->delete_records('hotquestion_questions', array('id' => $dbquestion->id)); + $DB->delete_records('hotquestion_questions', ['id' => $dbquestion->id]); // 20220510 Deleted $dbvote line of code. // Delete all votes on the question that was just deleted. - $DB->delete_records('hotquestion_votes', array('question' => $dbquestion->id)); + $DB->delete_records('hotquestion_votes', ['question' => $dbquestion->id]); // 20220510 Delete all comments on the question that was just deleted. - $DB->delete_records('comments', array('itemid' => $itemid, 'component' => 'mod_hotquestion')); + $DB->delete_records('comments', ['itemid' => $itemid, 'component' => 'mod_hotquestion']); // Update completion state for question creator. $this->update_completion_state($dbquestion->userid); @@ -458,10 +466,10 @@ public function remove_round() { $data->hotquestion = $this->instance->id; $context = context_module::instance($this->cm->id); // Trigger remove_question event. - $params = array( + $params = [ 'objectid' => $this->cm->id, 'context' => $context, - ); + ]; $event = remove_round::create($params); $event->trigger(); @@ -469,7 +477,11 @@ public function remove_round() { if ($this->currentround->endtime == 0) { $this->currentround->endtime = 0xFFFFFFFF; // Hack. } - $params = array($this->instance->id, $this->currentround->starttime, $this->currentround->endtime); + $params = [ + $this->instance->id, + $this->currentround->starttime, + $this->currentround->endtime, + ]; $questions = $DB->get_records_sql('SELECT q.id, q.hotquestion, q.content, q.userid, q.time, q.anonymous, q.approved, q.tpriority, count(v.voter) as votecount FROM {hotquestion_questions} q @@ -485,15 +497,15 @@ public function remove_round() { if ($questions) { foreach ($questions as $q) { $questionid = $q->id; // Get id of first question on the page to delete. - $dbquestion = $DB->get_record('hotquestion_questions', array('id' => $questionid)); + $dbquestion = $DB->get_record('hotquestion_questions', ['id' => $questionid]); // Contrib by ecastro ULPGC. $users = $this->get_question_voters($questionid); $users[] = $dbquestion->userid; // Contrib by ecastro ULPGC. - $DB->delete_records('hotquestion_questions', array('id' => $dbquestion->id)); + $DB->delete_records('hotquestion_questions', ['id' => $dbquestion->id]); // Get an array of all votes on the question that was just deleted, then delete them. - $dbvote = $DB->get_records('hotquestion_votes', array('question' => $questionid)); - $DB->delete_records('hotquestion_votes', array('question' => $dbquestion->id)); + $dbvote = $DB->get_records('hotquestion_votes', ['question' => $questionid]); + $DB->delete_records('hotquestion_votes', ['question' => $dbquestion->id]); // Update completion state for question creator. $this->update_completion_state($dbquestion->userid); @@ -505,15 +517,15 @@ public function remove_round() { $this->update_users_grades($users); } // Now that all questions and votes are gone, remove the round. - $dbround = $DB->get_record('hotquestion_rounds', array('id' => $roundid)); - $DB->delete_records('hotquestion_rounds', array('id' => $dbround->id)); + $dbround = $DB->get_record('hotquestion_rounds', ['id' => $roundid]); + $DB->delete_records('hotquestion_rounds', ['id' => $dbround->id]); } else { // This round is empty so delete without having to remove questions and votes. - $dbround = $DB->get_record('hotquestion_rounds', array('id' => $roundid)); - $DB->delete_records('hotquestion_rounds', array('id' => $dbround->id)); + $dbround = $DB->get_record('hotquestion_rounds', ['id' => $roundid]); + $DB->delete_records('hotquestion_rounds', ['id' => $dbround->id]); } // Now we need to see if we need a new round or have one we can still use. - $rounds = $DB->get_records('hotquestion_rounds', array('hotquestion' => $this->instance->id), 'id DESC'); + $rounds = $DB->get_records('hotquestion_rounds', ['hotquestion' => $this->instance->id], 'id DESC'); foreach ($rounds as $rnd) { if ($rnd->endtime == 0) { @@ -547,10 +559,10 @@ public function download_questions($chq, $filename = "export.csv", $delimiter="; $context = context_module::instance($this->cm->id); // Trigger download_questions event. - $params = array( + $params = [ 'objectid' => $this->cm->id, 'context' => $context, - ); + ]; $event = download_questions::create($params); $event->trigger(); @@ -558,7 +570,7 @@ public function download_questions($chq, $filename = "export.csv", $delimiter="; // Add filename details based on course and HQ activity name. $csv = new csv_export_writer(); $strhotquestion = get_string('hotquestion', 'hotquestion'); - $fields = array(); + $fields = []; if (is_siteadmin($USER->id)) { // For an admin, we want every hotquestion activity. @@ -573,23 +585,24 @@ public function download_questions($chq, $filename = "export.csv", $delimiter="; $csv->filename .= clean_filename(($this->instance->name)); } // Add fields with the column labels for ONLY the current HQ activity. - $fields = array(get_string('firstname'), - get_string('lastname'), - get_string('userid', 'hotquestion'), - get_string('hotquestion', 'hotquestion').' ID', - get_string('question', 'hotquestion').' ID', - get_string('time', 'hotquestion'), - get_string('anonymous', 'hotquestion'), - $this->instance->teacherprioritylabel, - $this->instance->heatlabel, - $this->instance->approvallabel, - $this->instance->questionlabel, - get_string('comments') - ); + $fields = [ + get_string('firstname'), + get_string('lastname'), + get_string('userid', 'hotquestion'), + get_string('hotquestion', 'hotquestion').' ID', + get_string('question', 'hotquestion').' ID', + get_string('time', 'hotquestion'), + get_string('anonymous', 'hotquestion'), + $this->instance->teacherprioritylabel, + $this->instance->heatlabel, + $this->instance->approvallabel, + $this->instance->questionlabel, + get_string('comments'), + ]; $csv->filename .= clean_filename(get_string('exportfilenamep2', 'hotquestion').gmdate("Ymd_Hi").'GMT.csv'); // Now add this instance id that's needed in the sql for teachers and managers downloads. - $fields = array($fields, 'thisinstid' => $this->instance->id); + $fields = [$fields, 'thisinstid' => $this->instance->id]; if ($CFG->dbtype == 'pgsql') { $sql = "SELECT hq.id AS question, @@ -660,26 +673,34 @@ public function download_questions($chq, $filename = "export.csv", $delimiter="; $currenthqhotquestion = ''; } foreach ($hqs as $q) { - $fields2 = array(get_string('firstname'), - get_string('lastname'), - get_string('userid', 'hotquestion'), - get_string('hotquestion', 'hotquestion').' ID', - get_string('question', 'hotquestion').' ID', - get_string('time', 'hotquestion'), - get_string('anonymous', 'hotquestion'), - $q->teacherprioritylabel, - $q->heatlabel, - $q->approvallabel, - $q->questionlabel, - get_string('comments') - ); + $fields2 = [ + get_string('firstname'), + get_string('lastname'), + get_string('userid', 'hotquestion'), + get_string('hotquestion', 'hotquestion').' ID', + get_string('question', 'hotquestion').' ID', + get_string('time', 'hotquestion'), + get_string('anonymous', 'hotquestion'), + $q->teacherprioritylabel, + $q->heatlabel, + $q->approvallabel, + $q->questionlabel, + get_string('comments'), + ]; + // 20220818 Initialize variable for any comments for the next question. $comment = ''; // 20220818 If there are any, get the comments for each question to add in the export file. // 20221124 Modified to include the component. - if ($cmts = $DB->get_records('comments', ['itemid' => $q->question, - 'component' => 'mod_hotquestion'], - 'userid, content, timecreated')) { + if ($cmts = $DB->get_records('comments', [ + 'itemid' => $q->question, + 'component' => 'mod_hotquestion', + ], + 'userid, + content, + timecreated' + )) { + $temp = count($cmts); $comment .= '('.$temp.' '.get_string('comments').') '; foreach ($cmts as $cmt) { @@ -692,22 +713,37 @@ public function download_questions($chq, $filename = "export.csv", $delimiter="; // 20220819 Add the course shortname and the HQ activity name to our data array. $currentcrsname = $DB->get_record('course', ['id' => $q->course], 'shortname'); $currenthqname = $DB->get_record('hotquestion', ['id' => $q->hotquestion], 'name'); - $blankrow = array(' ', null); + $blankrow = [' ', null]; // 20220820 Only include filename, date, and URL only on the first row of the export. // 20220820 Add a blank line before each HQ activity output, except for the first HQ activity. if (!$firstrowflag) { $csv->add_data($blankrow); - $activityinfo = array(get_string('course').': '.$currentcrsname->shortname, - get_string('activity').': '.$currenthqname->name); + $activityinfo = [ + get_string('course').': '.$currentcrsname->shortname, + get_string('activity').': '.$currenthqname->name, + ]; } else { - $activityinfo = array(null, null, null, null, null, null, null, null, null, null, - get_string('exportfilenamep2', 'hotquestion'). - gmdate("Ymd_Hi").get_string('for', 'hotquestion'). - $CFG->wwwroot); + $activityinfo = [ + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + get_string('exportfilenamep2', 'hotquestion'). + gmdate("Ymd_Hi").get_string('for', 'hotquestion'). + $CFG->wwwroot, + ]; $csv->add_data($activityinfo); - $activityinfo = array(get_string('course').': '.$currentcrsname->shortname, - get_string('activity').': '.$currenthqname->name); + $activityinfo = [ + get_string('course').': '.$currentcrsname->shortname, + get_string('activity').': '.$currenthqname->name, + ]; } $csv->add_data($activityinfo); $csv->add_data($fields2); @@ -717,8 +753,20 @@ public function download_questions($chq, $filename = "export.csv", $delimiter="; $cleanedcontent = format_string($q->content, $striplinks = true, $options = null); - $output = array($q->firstname, $q->lastname, $q->userid, $q->hotquestion, $q->question, $q->time, - $q->anonymous, $q->tpriority, $q->heat, $q->approved, $cleanedcontent, $comment); + $output = [ + $q->firstname, + $q->lastname, + $q->userid, + $q->hotquestion, + $q->question, + $q->time, + $q->anonymous, + $q->tpriority, + $q->heat, + $q->approved, + $cleanedcontent, + $comment, + ]; $csv->add_data($output); } } @@ -736,7 +784,7 @@ public function download_questions($chq, $filename = "export.csv", $delimiter="; public function approve_question($question) { global $CFG, $DB, $USER; $context = context_module::instance($this->cm->id); - $question = $DB->get_record('hotquestion_questions', array('id' => $question)); + $question = $DB->get_record('hotquestion_questions', ['id' => $question]); if ($question->approved) { // If currently approved, toggle to disapproved. @@ -761,7 +809,7 @@ public function tpriority_change($u, $question) { global $CFG, $DB, $USER; $context = context_module::instance($this->cm->id); - $question = $DB->get_record('hotquestion_questions', array('id' => $question)); + $question = $DB->get_record('hotquestion_questions', ['id' => $question]); if ($u) { // If priority flag is 1, increase priority by 1. diff --git a/mod_form.php b/mod_form.php index 40ad65f..8d531b8 100644 --- a/mod_form.php +++ b/mod_form.php @@ -51,14 +51,14 @@ class mod_hotquestion_mod_form extends moodleform_mod { public function definition() { global $COURSE, $CFG; - $mform =& $this->_form; + $mform = $this->_form; $hotquestionconfig = get_config('mod_hotquestion'); // Adding the "general" fieldset, where all the common settings are shown. $mform->addElement('header', 'general', get_string('general', 'form')); // Adding the standard "name" field. - $mform->addElement('text', 'name', get_string('hotquestionname', 'hotquestion'), array('size' => '64')); + $mform->addElement('text', 'name', get_string('hotquestionname', 'hotquestion'), ['size' => '64']); if (!empty($CFG->formatstringstriptags)) { $mform->setType('name', PARAM_TEXT); } else { @@ -81,7 +81,7 @@ public function definition() { $mform->addElement('header', 'entrieshdr', get_string('entries', 'hotquestion')); // Add submit instruction text field here. - $mform->addElement('text', 'submitdirections', get_string('inputquestion', 'hotquestion'), array('size' => '64')); + $mform->addElement('text', 'submitdirections', get_string('inputquestion', 'hotquestion'), ['size' => '64']); if (!empty($CFG->formatstringstriptags)) { $mform->setType('submitdirections', PARAM_TEXT); } else { @@ -93,7 +93,7 @@ public function definition() { $mform->addRule('submitdirections', get_string('maximumchars', '', 255), 'maxlength', 255, 'client'); // Add Questions label text field here. - $mform->addElement('text', 'questionlabel', get_string('questionlabel', 'hotquestion'), array('size' => '20')); + $mform->addElement('text', 'questionlabel', get_string('questionlabel', 'hotquestion'), ['size' => '20']); if (!empty($CFG->formatstringstriptags)) { $mform->setType('questionlabel', PARAM_TEXT); } else { @@ -110,11 +110,12 @@ public function definition() { $mform->setDefault('teacherpriorityvisibility', '1'); // Add Priority label text field here. - $mform->addElement('text', - 'teacherprioritylabel', - get_string('teacherprioritylabel', 'hotquestion'), - array('size' => '20') - ); + $mform->addElement( + 'text', + 'teacherprioritylabel', + get_string('teacherprioritylabel', 'hotquestion'), + ['size' => '20'] + ); if (!empty($CFG->formatstringstriptags)) { $mform->setType('teacherprioritylabel', PARAM_TEXT); } else { @@ -131,7 +132,7 @@ public function definition() { $mform->setDefault('heatvisibility', '1'); // Add Heat label text field here. - $mform->addElement('text', 'heatlabel', get_string('heatlabel', 'hotquestion'), array('size' => '20')); + $mform->addElement('text', 'heatlabel', get_string('heatlabel', 'hotquestion'), ['size' => '20']); if (!empty($CFG->formatstringstriptags)) { $mform->setType('heatlabel', PARAM_TEXT); } else { @@ -144,7 +145,7 @@ public function definition() { // Add Heat limit select field here. // Add a dropdown slector for heatlimit. 05/25/2020. - $tlimit = array(); + $tlimit = []; for ($i = 0; $i <= 10; $i++) { $tlimit[] = $i; } @@ -168,7 +169,7 @@ public function definition() { $mform->setDefault('approval', '0'); // Add Approval label text field here. - $mform->addElement('text', 'approvallabel', get_string('approvallabel', 'hotquestion'), array('size' => '20')); + $mform->addElement('text', 'approvallabel', get_string('approvallabel', 'hotquestion'), ['size' => '20']); if (!empty($CFG->formatstringstriptags)) { $mform->setType('approvallabel', PARAM_TEXT); } else { @@ -180,7 +181,7 @@ public function definition() { $mform->addRule('approvallabel', get_string('maximumchars', '', 20), 'maxlength', 20, 'client'); // Add Remove label text field here. - $mform->addElement('text', 'removelabel', get_string('removelabel', 'hotquestion'), array('size' => '20')); + $mform->addElement('text', 'removelabel', get_string('removelabel', 'hotquestion'), ['size' => '20']); if (!empty($CFG->formatstringstriptags)) { $mform->setType('removelabel', PARAM_TEXT); } else { @@ -203,10 +204,10 @@ public function definition() { $mform->addElement('date_time_selector', 'timeopen', get_string('hotquestionopentime', 'hotquestion'), - array('optional' => true, 'step' => 1)); + ['optional' => true, 'step' => 1]); $mform->addElement('date_time_selector', 'timeclose', get_string('hotquestionclosetime', 'hotquestion'), - array('optional' => true, 'step' => 1)); + ['optional' => true, 'step' => 1]); // Contrib by Kemmotar83. $mform->addElement('selectyesno', 'viewaftertimeclose', get_string('viewaftertimeclose', 'hotquestion')); @@ -256,23 +257,67 @@ public function definition() { * @return array Array of string IDs of added items, empty array if none. */ public function add_completion_rules() { - $mform =& $this->_form; + global $CFG; - $group = array(); - $group[] =& $mform->createElement('checkbox', 'completionpostenabled', '', get_string('completionpost', 'hotquestion')); - $group[] =& $mform->createElement('text', 'completionpost', '', array('size' => 3)); + $mform = $this->_form; + + // 20230926 Changed code for Moodle 4.3. + if ($CFG->branch < 403) { + $suffix = ''; + } else { + $suffix = $this->get_suffix(); + } + $completionpostgroup = 'completionpostgroup' . $suffix; + $completionpostenabled = 'completionpostenabled' . $suffix; + $completionpostel = 'completionpost' . $suffix; + $group = []; + $group[] = $mform->createElement('checkbox', $completionpostenabled, '', get_string('completionpost', 'hotquestion')); + $group[] = $mform->createElement('text', $completionpostel, '', ['size' => 3]); + $mform->setType($completionpostel, PARAM_INT); + $mform->addGroup($group, $completionpostgroup, get_string('completionpostgroup', 'hotquestion'), [' '], false); + $mform->disabledIf($completionpostel, $completionpostenabled, 'notchecked'); + + // @codingStandardsIgnoreLine + /* + $group = []; + $group[] = $mform->createElement('checkbox', 'completionpostenabled', '', get_string('completionpost', 'hotquestion')); + $group[] = $mform->createElement('text', 'completionpost', '', ['size' => 3]); $mform->setType('completionpost', PARAM_INT); - $mform->addGroup($group, 'completionpostgroup', get_string('completionpostgroup', 'hotquestion'), array(' '), false); + $mform->addGroup($group, 'completionpostgroup', get_string('completionpostgroup', 'hotquestion'), [' '], false); $mform->disabledIf('completionpost', 'completionpostenabled', 'notchecked'); - - $group = array(); - $group[] =& $mform->createElement('checkbox', 'completionvoteenabled', '', get_string('completionvote', 'hotquestion')); - $group[] =& $mform->createElement('text', 'completionvote', '', array('size' => 3)); + */ + + // Duplicte if and is not needed. + // 20230926 Changed code for Moodle 4.3. + // @codingStandardsIgnoreLine + /* + if ($CFG->branch < 403) { + $suffix = ''; + } else { + $suffix = $this->get_suffix(); + } + */ + $completionvotegroup = 'completionvotegroup' . $suffix; + $completionvoteenabled = 'completionvoteenabled' . $suffix; + $completionvoteel = 'completionvoteel' . $suffix; + $group = []; + $group[] = $mform->createElement('checkbox', $completionvoteenabled, '', get_string('completionvote', 'hotquestion')); + $group[] = $mform->createElement('text', $completionvoteel, '', ['size' => 3]); + $mform->setType($completionvoteel, PARAM_INT); + $mform->addGroup($group, $completionvotegroup, get_string('completionvotegroup', 'hotquestion'), [' '], false); + $mform->disabledIf($completionvoteel, $completionvoteenabled, 'notchecked'); + + // @codingStandardsIgnoreLine + /* + $group = []; + $group[] = $mform->createElement('checkbox', 'completionvoteenabled', '', get_string('completionvote', 'hotquestion')); + $group[] = $mform->createElement('text', 'completionvote', '', ['size' => 3]); $mform->setType('completionvote', PARAM_INT); - $mform->addGroup($group, 'completionvotegroup', get_string('completionvotegroup', 'hotquestion'), array(' '), false); + $mform->addGroup($group, 'completionvotegroup', get_string('completionvotegroup', 'hotquestion'), [' '], false); $mform->disabledIf('completionvote', 'completionvoteenabled', 'notchecked'); + */ - return array('completionpostgroup', 'completionvotegroup'); + return [$completionpostgroup, $completionvotegroup]; } /** @@ -282,8 +327,34 @@ public function add_completion_rules() { * @return bool True if one or more rules is enabled, false if none are. */ public function completion_rule_enabled($data) { + global $CFG; + + // 20230926 Changed code for Moodle 4.3. + if ($CFG->branch < 403) { + $suffix = ''; + } else { + $suffix = $this->get_suffix(); + } + $completionpostenabled = 'completionpostenabled' . $suffix; + $completionpostel = 'completionpost' . $suffix; + + // 20230926 Changed code for Moodle 4.3. + if ($CFG->branch < 403) { + $suffix = ''; + } else { + $suffix = $this->get_suffix(); + } + $completionvoteenabled = 'completionvoteenabled' . $suffix; + $completionvoteel = 'completionvoteel' . $suffix; + + return (!empty($data[$completionpostenabled]) && $data[$completionpostel] != 0) + || (!empty($data[$completionvoteenabled]) && $data[$completionvoteel] != 0); + + // @codingStandardsIgnoreLine + /* return (!empty($data['completionpostenabled']) && $data['completionpost'] != 0) || (!empty($data['completionvoteenabled']) && $data['completionvote'] != 0); + */ } /** @@ -347,9 +418,9 @@ public function definition() { list($allowanonymous, $cm) = $this->_customdata; - $temp = $DB->get_record('hotquestion', array('id' => $cm->instance)); + $temp = $DB->get_record('hotquestion', ['id' => $cm->instance]); - $mform =& $this->_form; + $mform = $this->_form; // 20210218 Changed using a text editor instead of textarea. // $mform->addElement('editor', 'text_editor', $temp->submitdirections, 'wrap="virtual" rows="5"'); @@ -365,10 +436,10 @@ public function definition() { $mform->addElement('hidden', 'id', $cm->id, 'id="hotquestion_courseid"'); $mform->setType('id', PARAM_INT); - $submitgroup = array(); - $submitgroup[] =& $mform->createElement('submit', 'submitbutton', get_string('postbutton', 'hotquestion')); + $submitgroup = []; + $submitgroup[] = $mform->createElement('submit', 'submitbutton', get_string('postbutton', 'hotquestion')); if ($allowanonymous) { - $submitgroup[] =& $mform->createElement('checkbox', 'anonymous', '', get_string('displayasanonymous', 'hotquestion')); + $submitgroup[] = $mform->createElement('checkbox', 'anonymous', '', get_string('displayasanonymous', 'hotquestion')); $mform->setType('anonymous', PARAM_BOOL); } $mform->addGroup($submitgroup); diff --git a/renderer.php b/renderer.php index 2553efd..1dd4c66 100644 --- a/renderer.php +++ b/renderer.php @@ -80,7 +80,7 @@ public function toolbar($shownew = true) { global $DB, $CFG, $USER; $output = ''; - $toolbuttons = array(); + $toolbuttons = []; $roundp = new stdClass(); $round = ''; // Initialize current round. $roundn = ''; // Initialize next round. @@ -89,26 +89,29 @@ public function toolbar($shownew = true) { // Print export to .csv file toolbutton. if ($shownew) { - $options = array(); + $options = []; $options['id'] = $this->hotquestion->cm->id; $options['action'] = 'download'; $url = new moodle_url('/mod/hotquestion/view.php', $options); $toolbuttons[] = html_writer::link($url, $this->pix_icon('a/download_all' , get_string('csvexport', 'hotquestion')) - , array('class' => 'toolbutton')); + , ['class' => 'toolbutton']); } // Print prev/next round toolbuttons. if ($this->hotquestion->get_prevround() != null) { $roundp = $this->hotquestion->get_prevround()->id; $roundn = ''; - $url = new moodle_url('/mod/hotquestion/view.php', array('id' => $this->hotquestion->cm->id, 'round' => $roundp)); - $toolbuttons[] = html_writer::link($url, $this->pix_icon('t/collapsed_rtl' - , get_string('previousround', 'hotquestion')) - , array('class' => 'toolbutton')); + $url = new moodle_url('/mod/hotquestion/view.php', ['id' => $this->hotquestion->cm->id, 'round' => $roundp]); + $toolbuttons[] = html_writer::link($url, $this->pix_icon('t/collapsed_rtl', + get_string('previousround', 'hotquestion')), + ['class' => 'toolbutton'] + ); } else { - $toolbuttons[] = html_writer::tag('span', $this->pix_icon('t/collapsed_empty_rtl', '') - , array('class' => 'dis_toolbutton')); + $toolbuttons[] = html_writer::tag('span', + $this->pix_icon('t/collapsed_empty_rtl', ''), + ['class' => 'dis_toolbutton'] + ); } // 20200215 Text added to show x of n display in toolbar. @@ -124,17 +127,17 @@ public function toolbar($shownew = true) { if ($this->hotquestion->get_nextround() != null) { $roundn = $this->hotquestion->get_nextround()->id; $roundp = ''; - $url = new moodle_url('/mod/hotquestion/view.php', array('id' => $this->hotquestion->cm->id, 'round' => $roundn)); + $url = new moodle_url('/mod/hotquestion/view.php', ['id' => $this->hotquestion->cm->id, 'round' => $roundn]); $toolbuttons[] = html_writer::link($url, $this->pix_icon('t/collapsed' - , get_string('nextround', 'hotquestion')), array('class' => 'toolbutton')); + , get_string('nextround', 'hotquestion')), ['class' => 'toolbutton']); } else { - $toolbuttons[] = html_writer::tag('span', $this->pix_icon('t/collapsed_empty', ''), array('class' => 'dis_toolbutton')); + $toolbuttons[] = html_writer::tag('span', $this->pix_icon('t/collapsed_empty', ''), ['class' => 'dis_toolbutton']); } // Print new round toolbutton. // Added new round confirm 6/24/19. if ($shownew) { - $options = array(); + $options = []; $options['id'] = $this->hotquestion->cm->id; $options['action'] = 'newround'; if ($CFG->branch > 32) { @@ -154,7 +157,7 @@ public function toolbar($shownew = true) { // Print remove round toolbutton. // Added remove round confirm 2/10/19. if ($shownew) { - $options = array(); + $options = []; $options['id'] = $this->hotquestion->cm->id; $options['action'] = 'removeround'; $options['round'] = $this->hotquestion->get_currentround()->id; @@ -175,11 +178,11 @@ public function toolbar($shownew = true) { } // Print refresh toolbutton. - $url = new moodle_url('/mod/hotquestion/view.php', array('id' => $this->hotquestion->cm->id)); - $toolbuttons[] = html_writer::link($url, $this->pix_icon('t/reload', get_string('reload')), array('class' => 'toolbutton')); + $url = new moodle_url('/mod/hotquestion/view.php', ['id' => $this->hotquestion->cm->id]); + $toolbuttons[] = html_writer::link($url, $this->pix_icon('t/reload', get_string('reload')), ['class' => 'toolbutton']); // Return all available toolbuttons. - $output .= html_writer::alist($toolbuttons, array('id' => 'toolbar')); + $output .= html_writer::alist($toolbuttons, ['id' => 'toolbar']); return $output; } @@ -226,7 +229,7 @@ public function questions($allowvote = true) { $table->cellpadding = 10; $table->class = 'generaltable'; $table->width = '100%'; - $table->align = array ('left', 'center', 'center', 'center', 'center'); + $table->align = ['left', 'center', 'center', 'center', 'center']; // 20200611 If teacher changes heat setting to lower than the number of heat // votes already applied by a user, those users will see an error message. @@ -239,9 +242,11 @@ public function questions($allowvote = true) { // Admin, manager and teachers headings for questions, priority, heat, remove and approved headings. if (has_capability('mod/hotquestion:manageentries', $context)) { // 20210924 Changed to format_text questionlabel column setting. - $table->head = array(format_text($this->hotquestion->instance->questionlabel, - $format = FORMAT_MOODLE, $options = null, - $courseiddonotuse = null)); + $table->head = [ + format_text($this->hotquestion->instance->questionlabel, + $format = FORMAT_MOODLE, $options = null, + $courseiddonotuse = null), + ]; // Check teacher priority column visibilty settings. if ($teacherpriorityvisibility) { // Priority column is visible, so show the label. @@ -281,10 +286,14 @@ public function questions($allowvote = true) { } else { // Students only see headings for questions, priority, and heat columns. // 20210924 Changed to format_text questionlabel column setting. - $table->head = array(format_text($this->hotquestion->instance->questionlabel, - $format = FORMAT_MOODLE, - $options = null, - $courseiddonotuse = null)); + $table->head = [ + format_text( + $this->hotquestion->instance->questionlabel, + $format = FORMAT_MOODLE, + $options = null, + $courseiddonotuse = null + ), + ]; // Check teacher priority column visibilty settings. if ($teacherpriorityvisibility) { // 20210924 Changed to format_text prioritylabel column setting. @@ -340,10 +349,10 @@ public function questions($allowvote = true) { // 20230519 Process all questions based on new seeunapproved question preference. foreach ($questions as $question) { - $line = array(); + $line = []; $formatoptions->para = false; $content = format_text($question->content, FORMAT_MOODLE, $formatoptions); - $user = $DB->get_record('user', array('id' => $question->userid)); + $user = $DB->get_record('user', ['id' => $question->userid]); // If groups is set to all participants or matches current group, show the question. if ((! $groups) || (groups_is_member($groups, $user->id))) { // Process the question part of the row entry. @@ -578,9 +587,12 @@ public function hotquestion_inaccessible($message) { public function hotquestion_get_question_comment_count($question, $cm) { global $DB; $context = context_module::instance($cm->id); - if ($count = $DB->count_records('comments', array('itemid' => $question->id, - 'commentarea' => 'hotquestion_question', - 'contextid' => $context->id))) { + if ($count = $DB->count_records('comments', [ + 'itemid' => $question->id, + 'commentarea' => 'hotquestion_question', + 'contextid' => $context->id, + ] + )) { return $count; } else { return 0; diff --git a/settings.php b/settings.php index e2a49e4..b41ed0b 100644 --- a/settings.php +++ b/settings.php @@ -56,7 +56,7 @@ $settings->add(new admin_setting_configcheckbox_with_advanced('mod_hotquestion/teacherpriorityvisibility', get_string('teacherpriorityvisibility', 'hotquestion'), get_string('teacherpriorityvisibility_descr', 'hotquestion'), - array('value' => 1, 'adv' => false))); + ['value' => 1, 'adv' => false])); // Default heading prioritylabel setting. $settings->add(new admin_setting_configtext('mod_hotquestion/teacherprioritylabel', @@ -68,7 +68,7 @@ $settings->add(new admin_setting_configcheckbox_with_advanced('mod_hotquestion/heatvisibility', get_string('heatvisibility', 'hotquestion'), get_string('heatvisibility_descr', 'hotquestion'), - array('value' => 1, 'adv' => false))); + ['value' => 1, 'adv' => false])); // Default heading heatlabel setting. $settings->add(new admin_setting_configtext('mod_hotquestion/heatlabel', @@ -77,7 +77,7 @@ 'Heat', PARAM_TEXT, 20)); // Default heading heatlimit setting. - $tl = array(); + $tl = []; for ($i = 0; $i <= 10; $i++) { $tl[] = $i; } @@ -88,13 +88,13 @@ $settings->add(new admin_setting_configcheckbox_with_advanced('mod_hotquestion/anonymouspost', get_string('allowanonymouspost', 'hotquestion'), get_string('allowanonymouspost_descr', 'hotquestion'), - array('value' => 0, 'adv' => false))); + ['value' => 0, 'adv' => false])); // Default allow hide author info from students. $settings->add(new admin_setting_configcheckbox_with_advanced('mod_hotquestion/allowauthorinfohide', get_string('allowauthorinfohide', 'hotquestion'), get_string('allowauthorinfohide_descr', 'hotquestion'), - array('value' => 0, 'adv' => false))); + ['value' => 0, 'adv' => false])); // Default heading removelabel setting. $settings->add(new admin_setting_configtext('mod_hotquestion/removelabel', @@ -106,7 +106,7 @@ $settings->add(new admin_setting_configcheckbox_with_advanced('mod_hotquestion/requireapproval', get_string('requireapproval', 'hotquestion'), get_string('requireapproval_descr', 'hotquestion'), - array('value' => 0, 'adv' => false))); + ['value' => 0, 'adv' => false])); // Default heading approvallabel setting. $settings->add(new admin_setting_configtext('mod_hotquestion/approvallabel', diff --git a/tests/behat/Add Hot Question Activity.feature b/tests/behat/Add Hot Question Activity.feature deleted file mode 100644 index b38e54e..0000000 --- a/tests/behat/Add Hot Question Activity.feature +++ /dev/null @@ -1,41 +0,0 @@ -@mod @mod_hotquestion -Feature: Add HotQuestion activity - In order to allow work effectively - As a teacher - I need to be able to create HotQuestion activities - - Scenario: Add a hotquestion activity and complete the activity as a student - Given the following "users" exist: - | username | firstname | lastname | email | - | teacher1 | Teacher | 1 | teacher1@example.com | - | student1 | Student | 1 | student1@example.com | - And the following "courses" exist: - | fullname | shortname | category | - | Course 1 | C1 | 0 | - And the following "course enrolments" exist: - | user | course | role | - | teacher1 | C1 | editingteacher | - | student1 | C1 | student | - And I log in as "teacher1" - And I am on "Course 1" course homepage with editing mode on - And I add a "Hot Question" to section "1" and I fill the form with: - | Activity Name | Test Hot Question name | - | Description | Test Hot Question Description | - And I log out - When I log in as "student1" - And I am on "Course 1" course homepage - And I follow "Test hotquestion name" - And I set the following fields to these values: - | Submit your question here: | First question | - And I press "Click to post" - And I set the following fields to these values: - | Submit your question here: | Second question | - And I set the field "Display as anonymous" to "1" - And I press "Click to post" - # Admin User verifies his posts are logged. - And I navigate to "Logs" in current page administration - Then I should see "Admin User" in the "#report_log_r1_c1" "css_element" - And I should see "Added a question" in the "#report_log_r1_c5" "css_element" - And I should see "Admin User" in the "#report_log_r4_c1" "css_element" - And I should see "Added a question" in the "#report_log_r4_c5" "css_element" - Then I log out diff --git a/tests/behat/questions_post.feature.disable b/tests/behat/questions_post.feature.disable deleted file mode 100644 index 0a30bd0..0000000 --- a/tests/behat/questions_post.feature.disable +++ /dev/null @@ -1,121 +0,0 @@ -@mod @mod_hotquestion -Feature: Users can post anonymous or named entries to hotquestion - In order to use HotQuestion - As a user - I need to be able to post a hotquestion entry. - - Background: - Given the following "courses" exist: - | fullname | shortname | category | groupmode | - | Course 1 | C1 | 0 | 1 | - And the following "users" exist: - | username | firstname | lastname | email | - | teacher1 | Teacher | 1 | teacher1@asd.com | - | teacher2 | Teacher | 2 | teacher2@asd.com | - | student1 | Student | 1 | student1@asd.com | - | student2 | Student | 2 | student2@asd.com | - And the following "course enrolments" exist: - | user | course | role | - | teacher1 | C1 | editingteacher | - | teacher2 | C1 | teacher | - | student1 | C1 | student | - | student2 | C1 | student | - And the following "activities" exist: - | activity | name | intro | course | idnumber | submitdirections | - | hotquestion | Test hotquestion name | Hotquestion intro | C1 | hotquestion1 | Submit your question here: | - Scenario: A user posts named and anonymous entries - # Admin User adds posts. - Given I log in as "admin" - When I am on "Course 1" course homepage - And I follow "Test hotquestion name" - And I set the following fields to these values: - | Submit your question here: | First question | - And I press "Click to post" - And I set the following fields to these values: - | Submit your question here: | Second question | - And I set the field "Display as anonymous" to "1" - And I press "Click to post" - # Admin User verifies his posts are logged. - And I navigate to "Logs" in current page administration - Then I should see "Admin User" in the "#report_log_r1_c1" "css_element" - And I should see "Added a question" in the "#report_log_r1_c5" "css_element" - And I should see "Admin User" in the "#report_log_r4_c1" "css_element" - And I should see "Added a question" in the "#report_log_r4_c5" "css_element" - Then I log out - #Teacher 1 posts an entry - Given I log in as "teacher1" - When I am on "Course 1" course homepage - And I follow "Test hotquestion name" - And I set the following fields to these values: - | Submit your question here: | Third question | - And I press "Click to post" - And I set the following fields to these values: - | Submit your question here: | Fourth question | - And I set the field "Display as anonymous" to "1" - And I press "Click to post" - # Teacher 1 verifies his posts are logged. - And I navigate to "Logs" in current page administration - Then I should see "Teacher 1" in the "#report_log_r1_c1" "css_element" - And I should see "Added a question" in the "#report_log_r1_c5" "css_element" - And I should see "Teacher 1" in the "#report_log_r4_c1" "css_element" - And I should see "Added a question" in the "#report_log_r4_c5" "css_element" - Then I log out - #Non-editing teacher 2 posts an entry - Given I log in as "teacher2" - When I am on "Course 1" course homepage - And I follow "Test hotquestion name" - And I set the following fields to these values: - | Submit your question here: | Fifth question | - And I press "Click to post" - And I set the following fields to these values: - | Submit your question here: | Sixth question | - And I set the field "Display as anonymous" to "1" - And I press "Click to post" - # Teacher 2 verifies his posts are logged. - And I navigate to "Logs" in current page administration - Then I should see "Teacher 2" in the "#report_log_r1_c1" "css_element" - And I should see "Added a question" in the "#report_log_r1_c5" "css_element" - And I should see "Teacher 2" in the "#report_log_r4_c1" "css_element" - And I should see "Added a question" in the "#report_log_r4_c5" "css_element" - Then I log out - #Student 1 posts an entry - Given I log in as "student1" - When I am on "Course 1" course homepage - And I follow "Test hotquestion name" - And I set the following fields to these values: - | Submit your question here: | Seventh question | - And I press "Click to post" - Then I should see "Seventh question" - And I set the following fields to these values: - | Submit your question here: | Eighth question | - And I set the field "Display as anonymous" to "1" - And I press "Click to post" - Then I should see "Eighth question" - And I should see "Posted by Anonymous" - And I should see "Seventh question" - And I should see "Posted by Student 1" - And I should see "Sixth question" - And I should see "Posted by Anonymous" - And I should see "Fifth question" - And I should see "Posted by Teacher 2" - And I should see "Fourth question" - And I should see "Posted by Anonymous" - And I should see "Third question" - And I should see "Posted by Teacher 1" - And I should see "Second question" - And I should see "Posted by Anonymous" - And I should see "First question" - And I should see "Posted by Admin User" - Then I log out - # Teacher 1 verifies posts are logged for student. - Given I log in as "teacher1" - When I am on "Course 1" course homepage - And I follow "Test hotquestion name" - And I navigate to "Logs" in current page administration - Then I should see "Teacher 1" in the "#report_log_r0_c1" "css_element" - And I should see "Course module viewed" in the "#report_log_r0_c5" "css_element" - Then I should see "Student 1" in the "#report_log_r2_c1" "css_element" - And I should see "Added a question" in the "#report_log_r2_c5" "css_element" - And I should see "Student 1" in the "#report_log_r5_c1" "css_element" - And I should see "Added a question" in the "#report_log_r5_c5" "css_element" - Then I log out diff --git a/tests/behat/questions_visibility_after_closing_time.feature b/tests/behat/questions_visibility_after_closing_time.feature index a2ca6c0..8f77044 100644 --- a/tests/behat/questions_visibility_after_closing_time.feature +++ b/tests/behat/questions_visibility_after_closing_time.feature @@ -1,6 +1,6 @@ @mod @mod_hotquestion Feature: Set entry visibility after close time for HotQuestion - In order to control if a student can HotQuestion entries after closing time + In order to control if a student can see HotQuestion entries after closing time As a teacher I need to be able to set availability dates and viewaftertimeclose flag for a hotquestion. @@ -86,4 +86,4 @@ Feature: Set entry visibility after close time for HotQuestion And I follow "Test hotquestion name" And I should see "First question" And I should not see "Submit your question here" - Then I log out \ No newline at end of file + Then I log out diff --git a/tests/behat/toolbar_reload.feature b/tests/behat/toolbar_reload.feature index 8f8fdea..b2baaba 100644 --- a/tests/behat/toolbar_reload.feature +++ b/tests/behat/toolbar_reload.feature @@ -1,4 +1,4 @@ -@mod @mod_hotquestion +67@mod @mod_hotquestion Feature: When viewing pevious rounds users can follow reload to go to current round In order to ensure I am on current round As a user diff --git a/upgrade.txt b/upgrade.txt index 59bbec9..5a6b0ef 100644 --- a/upgrade.txt +++ b/upgrade.txt @@ -9,6 +9,14 @@ This files describes changes in the Hot Question code. 20220821 HotQuestion_911 - Need to see about including grades in the Export tool. 20230120 HotQuestion_995 - The grade table needs more info included in the download. +=== 4.1.8 === 2023100900 +20230926 HotQuestion_1076 - Need to implement suffix on mod_for.php for Moodle 4.3. + Added needed code to the mod_form.php file for both add_completion_rules and for + completion_rule_enabled. +20231008 HotQuestion_1091 - Latest codechecker says "Import statements must not begin + with a leading backslash". +20231008 HotQuestion_1092 - Latest codechecker requires convert from long array(), + to short array []. === 4.1.7 === 2023052500 Only for M3.11 and above. === 4.1.7+ === diff --git a/version.php b/version.php index 88ac881..4c950a3 100644 --- a/version.php +++ b/version.php @@ -29,10 +29,10 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2023052502; // The current module version (Date: YYYYMMDDXX). +$plugin->version = 2023100900; // The current module version (Date: YYYYMMDDXX). $plugin->requires = 2021051700; // Requires Moodle 3.11 version. $plugin->cron = 0; // Period for cron to check this module (secs). $plugin->component = 'mod_hotquestion'; $plugin->maturity = MATURITY_STABLE; -$plugin->release = "4.1.7+ (Build: 2023061100)"; // User-friendly version number. -$plugin->supported = [311, 402]; +$plugin->release = "4.1.8 (Build: 2023100900)"; // User-friendly version number. +$plugin->supported = [311, 403]; diff --git a/view.php b/view.php index eabcf7e..d602350 100644 --- a/view.php +++ b/view.php @@ -27,7 +27,7 @@ */ use mod_hotquestion\local\results; use mod_hotquestion\local\hqavailable; -use \mod_hotquestion\event\course_module_viewed; +use mod_hotquestion\event\course_module_viewed; require_once("../../config.php"); require_once("lib.php"); @@ -46,7 +46,7 @@ throw new moodle_exception(get_string('incorrectmodule', 'hotquestion')); } -$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); +$course = $DB->get_record('course', ['id' => $cm->course], '*', MUST_EXIST); // Construct hotquestion instance. $hq = new mod_hotquestion($id, $roundid); @@ -63,11 +63,11 @@ throw new moodle_exception(get_string('accessdenied', 'hotquestion')); } -if (! $hotquestion = $DB->get_record("hotquestion", array("id" => $cm->instance))) { +if (! $hotquestion = $DB->get_record("hotquestion", ["id" => $cm->instance])) { throw new moodle_exception(get_string('incorrectmodule', 'hotquestion')); } -if (! $cw = $DB->get_record("course_sections", array("id" => $cm->section))) { +if (! $cw = $DB->get_record("course_sections", ["id" => $cm->section])) { throw new moodle_exception(get_string('incorrectmodule', 'hotquestion')); } @@ -84,7 +84,11 @@ } // Trigger module viewed event. -$params = array('objectid' => $hq->cm->id, 'context' => $context); +$params = [ + 'objectid' => $hq->cm->id, + 'context' => $context, +]; + $event = course_module_viewed::create($params); $event->trigger(); @@ -94,7 +98,7 @@ // Set page. if (!$ajax) { - $PAGE->set_url('/mod/hotquestion/view.php', array('id' => $hq->cm->id)); + $PAGE->set_url('/mod/hotquestion/view.php', ['id' => $hq->cm->id]); $PAGE->set_title($hq->instance->name); $PAGE->set_heading($hq->course->shortname); $PAGE->set_context($context); @@ -110,7 +114,7 @@ // 20230522 Changed to $canask. Process submitted question. if ($canask) { - $mform = new hotquestion_form(null, array($hq->instance->anonymouspost, $hq->cm)); + $mform = new hotquestion_form(null, [$hq->instance->anonymouspost, $hq->cm]); // 20230520 Needed isset so changing unapproved question views do not cause an error. if (($fromform = $mform->get_data()) && (isset($fromform->submitbutton))) { // If there is a post, $fromform will contain text, format, id, and submitbutton. @@ -224,7 +228,7 @@ // Start print page. if (!$ajax) { // Added code to include the activity name, 10/05/16. - $hotquestionname = format_string($hotquestion->name, true, array('context' => $context)); + $hotquestionname = format_string($hotquestion->name, true, ['context' => $context]); echo $output->header(); // 20220716 HQ_882 Skip heading for Moodle 4.0 and higher as it seems to be automatic. if ($CFG->branch < 400) { @@ -292,9 +296,11 @@ echo '
'; // Add a selector for unapproved question visibility preference. - $listoptions = array(get_string('unapprovedquestionnotset', 'hotquestion'), - get_string('unapprovedquestionsee', 'hotquestion'), - get_string('unapprovedquestionhide', 'hotquestion')); + $listoptions = [ + get_string('unapprovedquestionnotset', 'hotquestion'), + get_string('unapprovedquestionsee', 'hotquestion'), + get_string('unapprovedquestionhide', 'hotquestion'), + ]; $htmlout = ''; $htmlout .= ' '.get_string('unapprovedquestionvisibility', 'hotquestion') .'