From 217c542191b433d9021856c063cca397d371a4bc Mon Sep 17 00:00:00 2001 From: Matthias Opitz Date: Thu, 23 Nov 2023 17:32:26 +0000 Subject: [PATCH 1/3] replaced deprecated function print_error() --- index.php | 2 +- lib.php | 32 ++++++++++++++++---------------- mod_form.php | 2 +- report.php | 6 +++--- view.php | 8 ++++---- 5 files changed, 25 insertions(+), 25 deletions(-) diff --git a/index.php b/index.php index f2d2f89..ad428b5 100644 --- a/index.php +++ b/index.php @@ -33,7 +33,7 @@ $PAGE->set_url('/mod/choicegroup/index.php', array('id' => $id)); if (!$course = $DB->get_record('course', array('id' => $id))) { - print_error('invalidcourseid'); + throw new moodle_exception('invalidcourseid'); } require_course_login($course); diff --git a/lib.php b/lib.php index 1eccefc..0b99fee 100644 --- a/lib.php +++ b/lib.php @@ -198,12 +198,12 @@ function choicegroup_add_instance($choicegroup) { //insert answers $choicegroup->id = $DB->insert_record("choicegroup", $choicegroup); - + // deserialize the selected groups - + $groupIDs = explode(';', $choicegroup->serializedselectedgroups); $groupIDs = array_diff( $groupIDs, array( '' ) ); - + foreach ($groupIDs as $groupID) { $groupID = trim($groupID); if (isset($groupID) && $groupID != '') { @@ -216,7 +216,7 @@ function choicegroup_add_instance($choicegroup) { } $option->timemodified = time(); $DB->insert_record("choicegroup_options", $option); - } + } } if (class_exists('\core_completion\api')) { @@ -252,10 +252,10 @@ function choicegroup_update_instance($choicegroup) { if (empty($choicegroup->multipleenrollmentspossible)) { $choicegroup->multipleenrollmentspossible = 0; } - - + + // deserialize the selected groups - + $groupIDs = explode(';', $choicegroup->serializedselectedgroups); $groupIDs = array_diff( $groupIDs, array( '' ) ); @@ -285,9 +285,9 @@ function choicegroup_update_instance($choicegroup) { continue 2; // continue the big loop } } - $DB->insert_record("choicegroup_options", $option); + $DB->insert_record("choicegroup_options", $option); } - + } // remove all remaining pre-existing groups which did not appear in the form (and are thus assumed to have been deleted) foreach ($preExistingGroups as $preExistingGroup) { @@ -413,13 +413,13 @@ function choicegroup_user_submit_response($formanswer, $choicegroup, $userid, $c $countanswers=0; groups_add_member($selected_option->groupid, $userid); - $groupmember_added = true; + $groupmember_added = true; if ($choicegroup->limitanswers) { $groupmember = $DB->get_record('groups_members', array('groupid' => $selected_option->groupid, 'userid'=>$userid)); $select_count = 'groupid='.$selected_option->groupid.' and id<='.$groupmember->id; $countanswers = $DB->count_records_select('groups_members', $select_count); $maxans = $choicegroup->maxanswers[$formanswer]; - if ($countanswers > $maxans) { + if ($countanswers > $maxans) { groups_remove_member($selected_option->groupid, $userid); $groupmember_added = false; } @@ -454,7 +454,7 @@ function choicegroup_user_submit_response($formanswer, $choicegroup, $userid, $c } } else { if (!$current || !($current->id==$selected_option->groupid)) { //check to see if current choicegroup already selected - if not display error - print_error('choicegroupfull', 'choicegroup', $CFG->wwwroot.'/mod/choicegroup/view.php?id='.$cm->id); + throw new moodle_exception('choicegroupfull', 'choicegroup', $CFG->wwwroot.'/mod/choicegroup/view.php?id='.$cm->id); } } } @@ -960,13 +960,13 @@ function choicegroup_get_response_data($choicegroup, $cm, $groupmode, $onlyactiv return $allresponses; } -/* Return an array with the options selected of users of the $choicegroup - * +/* Return an array with the options selected of users of the $choicegroup + * * @param object $choicegroup choicegroup record * @param context_module $ctx Context instance * @param int $currentgroup Current group * @param bool $onlyactive Whether to get responses for active users only - * @return array of selected options by all users + * @return array of selected options by all users */ function choicegroup_get_responses($choicegroup, $ctx, $currentgroup, $onlyactive) { @@ -1044,7 +1044,7 @@ function choicegroup_extend_settings_navigation(settings_navigation $settings, n groups_get_activity_group($cm, true); } if (!$choicegroup = choicegroup_get_choicegroup($cm->instance)) { - print_error('invalidcoursemodule'); + throw new moodle_exception('invalidcoursemodule'); return false; } diff --git a/mod_form.php b/mod_form.php index c0558c6..b410d8f 100644 --- a/mod_form.php +++ b/mod_form.php @@ -75,7 +75,7 @@ function definition() $a->linkcourse = $CFG->wwwroot . '//course/view.php?id=' . $COURSE->id; $message = get_string('pleasesetonegroupor', 'choicegroup', $a); \core\notification::add($message, \core\notification::WARNING); - print_error('nogroupincourse', 'choicegroup', new moodle_url('/course/view.php?id=' . $COURSE->id), $a); + throw new moodle_exception('nogroupincourse', 'choicegroup', new moodle_url('/course/view.php?id=' . $COURSE->id), $a); } $db_groupings = $DB->get_records('groupings', array('courseid' => $COURSE->id)); diff --git a/report.php b/report.php index 28d7e3f..3e67b41 100644 --- a/report.php +++ b/report.php @@ -46,11 +46,11 @@ $PAGE->set_url($url); if (! $cm = get_coursemodule_from_id('choicegroup', $id)) { - print_error("invalidcoursemodule"); + throw new moodle_exception("invalidcoursemodule"); } if (! $course = $DB->get_record("course", array("id" => $cm->course))) { - print_error("coursemisconf"); + throw new moodle_exception("coursemisconf"); } require_login($course->id, false, $cm); @@ -60,7 +60,7 @@ require_capability('mod/choicegroup:readresponses', $context); if (!$choicegroup = choicegroup_get_choicegroup($cm->instance)) { - print_error('invalidcoursemodule'); + throw new moodle_exception('invalidcoursemodule'); } $strchoicegroup = get_string("modulename", "choicegroup"); diff --git a/view.php b/view.php index 30a269c..a9d50fb 100644 --- a/view.php +++ b/view.php @@ -41,17 +41,17 @@ $PAGE->set_url($url); if (! $cm = get_coursemodule_from_id('choicegroup', $id)) { - print_error('invalidcoursemodule'); + throw new moodle_exception('invalidcoursemodule'); } if (! $course = $DB->get_record("course", array("id" => $cm->course))) { - print_error('coursemisconf'); + throw new moodle_exception('coursemisconf'); } require_login($course, false, $cm); $PAGE->requires->js_call_amd('mod_choicegroup/choicegroupdatadisplay', 'init'); if (!$choicegroup = choicegroup_get_choicegroup($cm->instance)) { - print_error('invalidcoursemodule'); + throw new moodle_exception('invalidcoursemodule'); } $choicegroup_groups = choicegroup_get_groups($choicegroup); $choicegroup_users = array(); @@ -60,7 +60,7 @@ $strchoicegroups = get_string('modulenameplural', 'choicegroup'); if (!$context = context_module::instance($cm->id)) { - print_error('badcontext'); + throw new moodle_exception('badcontext'); } $eventparams = array( From cc71083368caa999ccd5175defe3d4d0e9aa9b8b Mon Sep 17 00:00:00 2001 From: Matthias Opitz Date: Mon, 4 Dec 2023 18:33:28 +0000 Subject: [PATCH 2/3] added suffix to completion rules --- mod_form.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/mod_form.php b/mod_form.php index b410d8f..1934712 100644 --- a/mod_form.php +++ b/mod_form.php @@ -335,10 +335,19 @@ function get_data() function add_completion_rules() { + global $CFG; + $mform =& $this->_form; - $mform->addElement('checkbox', 'completionsubmit', '', get_string('completionsubmit', 'choicegroup')); - return array('completionsubmit'); + // Changes for Moodle 4.3 - MDL-78516. + if ($CFG->branch < 403) { + $suffix = ''; + } else { + $suffix = $this->get_suffix(); + } + + $mform->addElement('checkbox', 'completionsubmit' . $suffix, '', get_string('completionsubmit', 'choicegroup')); + return ['completionsubmit' . $suffix]; } function completion_rule_enabled($data) From 449277eb4ccd9c820f3666a1e378f55b5eb036e0 Mon Sep 17 00:00:00 2001 From: Matthias Opitz Date: Tue, 5 Dec 2023 09:52:02 +0000 Subject: [PATCH 3/3] removed moodle_exception when $db_groups < 1 --- mod_form.php | 1 - 1 file changed, 1 deletion(-) diff --git a/mod_form.php b/mod_form.php index 1934712..26dfda6 100644 --- a/mod_form.php +++ b/mod_form.php @@ -75,7 +75,6 @@ function definition() $a->linkcourse = $CFG->wwwroot . '//course/view.php?id=' . $COURSE->id; $message = get_string('pleasesetonegroupor', 'choicegroup', $a); \core\notification::add($message, \core\notification::WARNING); - throw new moodle_exception('nogroupincourse', 'choicegroup', new moodle_url('/course/view.php?id=' . $COURSE->id), $a); } $db_groupings = $DB->get_records('groupings', array('courseid' => $COURSE->id));