From 5e78c2b4f3b37bd02147b70f4e732b3dcdf439eb Mon Sep 17 00:00:00 2001 From: Irina Hoppe Date: Wed, 20 Dec 2023 11:39:34 +0100 Subject: [PATCH 01/33] WIP: added custom completion rules --- classes/completion/custom_completion.php | 105 +++++++++++++++++++++++ db/install.xml | 2 + db/upgrade.php | 19 ++++ lib.php | 48 ++++++++++- locallib.php | 51 ++++++++++- mod_form.php | 38 ++++++++ 6 files changed, 257 insertions(+), 6 deletions(-) create mode 100644 classes/completion/custom_completion.php diff --git a/classes/completion/custom_completion.php b/classes/completion/custom_completion.php new file mode 100644 index 00000000..c08af3c2 --- /dev/null +++ b/classes/completion/custom_completion.php @@ -0,0 +1,105 @@ +. + +declare(strict_types=1); + +namespace mod_ratingallocate\completion; + +use core_completion\activity_custom_completion; + +/** + * Activity custom completion subclass for the ratingallocate activity. + * + * Class for defining the custom completion rules of ratingallocate and fetching the completion statuses + * of the custom completion rules for a given ratingallocate instance and a user. + * + * @package mod_ratingallocate + * @copyright Irina Hoppe Uni Münster + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class custom_completion extends activity_custom_completion { + + /** + * Fetches the completion state for a given completion rule. + * + * @param string $rule The completion rule. + * @return int The completion state. + * @throws \moodle_exception + */ + public function get_state(string $rule): int { + global $DB; + + $this->validate_rule($rule); + + $userid = $this->userid; + $ratingallocateid = $this->cm->instance; + + if (!$DB->get_record('ratingallocate', ['id' => $ratingallocateid])) { + throw new \moodle_exception('Unable to find ratingallocate instance with id ' . $ratingallocateid); + } + + if ($rule == 'completionvote') { + $sql = "SELECT * FROM {ratingallocate_ratings} r INNER JOIN {ratingallocate_choices} c on r.choiceid=c.id " . + "WHERE r.userid= :userid AND c.ratingallocateid= :ratingallocateid"; + $votesofuser = $DB->get_records_sql($sql, ['userid' => $userid, 'ratingallocateid' => $ratingallocateid]); + $status = count($votesofuser) > 0; + } else if ($rule == 'completionallocation') { + $sql = "SELECT * FROM {ratingallocate_allocations} WHERE userid= :userid AND ratingallocateid= :ratingallocateid"; + $allocationsofuser = $DB->get_records_sql($sql, ['userid' => $userid, 'ratingallocateid' => $ratingallocateid]); + $status = count($allocationsofuser) > 0; + } + + return $status ? COMPLETION_COMPLETE : COMPLETION_INCOMPLETE; + } + + /** + * Fetch the list of custom completion rules that this module defines. + * + * @return array + */ + public static function get_defined_custom_rules(): array { + return [ + 'completionvote', + 'completionallocation' + ]; + } + + /** + * Returns an associative array of the descriptions of custom completion rules. + * + * @return array + */ + public function get_custom_rule_descriptions(): array { + return [ + 'completionvote' => get_string('comletionvote_desc', RATINGALLOCATE_MOD_NAME), + 'completionallocation' => get_string('completionallocation_desc', RATINGALLOCATE_MOD_NAME) + ]; + } + + /** + * Returns an array of all completion rules, in the order they should be displayed to users. + * + * @return array + */ + public function get_sort_order(): array { + return [ + 'completionview', + 'completionvote', + 'completionallocation' + ]; + } +} + diff --git a/db/install.xml b/db/install.xml index 5433f236..3ca1d6f0 100644 --- a/db/install.xml +++ b/db/install.xml @@ -23,6 +23,8 @@ + + diff --git a/db/upgrade.php b/db/upgrade.php index c6885680..ed21d858 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -218,5 +218,24 @@ function xmldb_ratingallocate_upgrade($oldversion) { upgrade_mod_savepoint(true, 2023050900, 'ratingallocate'); } + if ($oldversion < 2023122000) { + + // Define completionrules fields to be added to ratingallocate. + $table = new xmldb_table('ratingallocate'); + $votefield = new xmldb_field('completionvote', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, false, '0'); + $allocationfield = new xmldb_field('completionallocation', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, false, '0'); + + // Conditionally launch add field notification_send. + if (!$dbman->field_exists($table, $votefield)) { + $dbman->add_field($table, $votefield); + } + if (!$dbman->field_exists($table, $allocationfield)) { + $dbman->add_field($table, $allocationfield); + } + + // Ratingallocate savepoint reached. + upgrade_mod_savepoint(true, 2023121300, 'ratingallocate'); + } + return true; } diff --git a/lib.php b/lib.php index 8008cb25..c9685569 100644 --- a/lib.php +++ b/lib.php @@ -70,6 +70,8 @@ function ratingallocate_supports($feature) { return true; case FEATURE_COMPLETION_TRACKS_VIEWS: return true; + case FEATURE_COMPLETION_HAS_RULES: + return true; default : return null; } @@ -765,7 +767,8 @@ function ratingallocate_get_coursemodule_info($coursemodule) { global $DB; $dbparams = ['id' => $coursemodule->instance]; - if (! $ratingallocate = $DB->get_record('ratingallocate', $dbparams)) { + $fields = 'id, name, intro, introformat, accesstimestart, accesstimestop, completionvote, completionallocation'; + if (!$ratingallocate = $DB->get_record(RATINGALLOCATE_MOD_NAME, $dbparams, $fields)) { return false; } @@ -774,7 +777,13 @@ function ratingallocate_get_coursemodule_info($coursemodule) { if ($coursemodule->showdescription) { // Convert intro to html. Do not filter cached version, filters run at display time. - $result->content = format_module_intro('ratingallocate', $ratingallocate, $coursemodule->id, false); + $result->content = format_module_intro(RATINGALLOCATE_MOD_NAME, $ratingallocate, $coursemodule->id, false); + } + + // Populate the custom completion rules as key => value pairs, but only if the completion mode is 'automatic'. + if ($ratingallocate->completion == COMPLETION_TRACKING_AUTOMATIC) { + $result->customdata['customcompletionrules']['completionvote'] = $ratingallocate->completionvote; + $result->customdata['customcompletionrules']['completionallocation'] = $ratingallocate->completionallocation; } // Populate some other values that can be used in calendar or on dashboard. @@ -787,3 +796,38 @@ function ratingallocate_get_coursemodule_info($coursemodule) { return $result; } + +/** + * Callback which returns human-readable strings describing the active completion custom rules for the module instance. + * + * @param cm_info|stdClass $cm object with fields ->completion and ->customdata['customcompletionrules'] + * @return array $descriptions the array of descriptions for the custom rules. + */ +function mod_ratingallocate_get_completion_active_rule_descriptions($cm) +{ + // Values will be present in cm_info, and we assume these are up to date. + if (empty($cm->customdata['customcompletionrules']) || $cm->completion != COMPLETION_TRACKING_AUTOMATIC) { + return []; + } + + $descriptions = []; + + foreach ($cm->customdata['customcompletionrules'] as $key => $val) { + switch ($key) { + case 'completionvote': + if ($val == 1) { + $descriptions[] = get_string('copletionvotedesc', RATINGALLOCATE_MOD_NAME); + } + break; + case 'completionallocation': + if ($val == 1) { + $descriptions[] = get_string('copletionallocationdesc', RATINGALLOCATE_MOD_NAME); + } + break; + default: + break; + } + } + + return $descriptions; +} diff --git a/locallib.php b/locallib.php index fc9f82fe..7353bbf9 100644 --- a/locallib.php +++ b/locallib.php @@ -187,6 +187,7 @@ class ratingallocate { /** * Returns all users enrolled in the course the ratingallocate is in, who were able to access the activity + * @returns Array of user records * @throws moodle_exception */ public function get_raters_in_course(): array { @@ -1402,6 +1403,15 @@ public function distrubute_choices() { $distributor = new solver_edmonds_karp(); $timestart = microtime(true); $distributor->distribute_users($this); + + $completion = new completion_info($this->course); + $raters = $this->get_raters_in_course(); + if ($completion->is_enabled($this->coursemodule)) { + foreach ($raters as $rater) { + $completion->update_state($this->coursemodule, COMPLETION_COMPLETE, $rater->id); + } + + } $timeneeded = (microtime(true) - $timestart); // Set algorithm status to finished. @@ -1611,8 +1621,16 @@ public function get_allocations() { * Removes all allocations for choices in $ratingallocateid */ public function clear_all_allocations() { - $this->db->delete_records('ratingallocate_allocations', ['ratingallocateid' => intval - ($this->ratingallocateid)]); + $this->db->delete_records('ratingallocate_allocations', ['ratingallocateid' => intval($this->ratingallocateid)]); + $raters = $this->get_raters_in_course(); + + $completion = new completion_info($this->course); + if ($completion->is_enabled($this->coursemodule)) { + foreach ($raters as $rater) { + $completion->update_state($this->coursemodule, COMPLETION_INCOMPLETE, $rater->id); + } + } + } /** @@ -1751,7 +1769,7 @@ public function get_users_with_ratings() { * Deletes all ratings in this ratingallocate */ public function delete_all_ratings() { - global $DB; + global $DB, $USER; $transaction = $DB->start_delegated_transaction(); @@ -1772,6 +1790,11 @@ public function delete_all_ratings() { $transaction->allow_commit(); + $completion = new completion_info($this->course); + if ($completion->is_enabled($this->coursemodule)) { + $completion->update_state($this->coursemodule, COMPLETION_INCOMPLETE, $USER->id); + } + // Logging. $event = \mod_ratingallocate\event\all_ratings_deleted::create_simple( context_module::instance($this->coursemodule->id), $this->ratingallocateid); @@ -1806,6 +1829,11 @@ public function delete_ratings_of_user($userid) { $transaction->allow_commit(); + $completion = new completion_info($this->course); + if ($completion->is_enabled($this->coursemodule)) { + $completion->update_state($this->coursemodule, COMPLETION_INCOMPLETE, $userid); + } + // Logging. $event = \mod_ratingallocate\event\rating_deleted::create_simple( context_module::instance($this->coursemodule->id), $this->ratingallocateid); @@ -1862,7 +1890,10 @@ public function save_ratings_to_db($userid, array $data) { $transaction->allow_commit(); $completion = new completion_info($this->course); - $completion->set_module_viewed($this->coursemodule); + if ($completion->is_enabled()) { + $completion->set_module_viewed($this->coursemodule, $userid); + $completion->update_state($this->coursemodule, COMPLETION_UNKNOWN, $userid); + } // Logging. $event = \mod_ratingallocate\event\rating_saved::create_simple( @@ -2054,6 +2085,10 @@ public function remove_allocation($choiceid, $userid) { 'choiceid' => $choiceid, 'userid' => $userid, ]); + $completion = new completion_info($this->course); + if ($completion->is_enabled($this->coursemodule)) { + $completion->update_state($this->coursemodule, COMPLETION_INCOMPLETE, $userid); + } return true; } @@ -2067,6 +2102,10 @@ public function remove_allocations($userid) { 'userid' => $userid, 'ratingallocateid' => $this->ratingallocateid, ]); + $completion = new completion_info($this->course); + if ($completion->is_enabled($this->coursemodule)) { + $completion->update_state($this->coursemodule, COMPLETION_INCOMPLETE, $userid); + } } /** @@ -2081,6 +2120,10 @@ public function add_allocation($choiceid, $userid) { 'userid' => $userid, 'ratingallocateid' => $this->ratingallocateid, ]); + $completion = new completion_info($this->course); + if ($completion->is_enabled($this->coursemodule)) { + $completion->update_state($this->coursemodule, COMPLETION_COMPLETE, $userid); + } return true; } diff --git a/mod_form.php b/mod_form.php index 0879f737..9b4bdc68 100644 --- a/mod_form.php +++ b/mod_form.php @@ -324,4 +324,42 @@ public function validation($data, $files) { private function get_settingsfield_identifier($strategy, $key) { return self::STRATEGY_OPTIONS . '[' . $strategy . '][' . $key . ']'; } + + /** + * Add elements for setting the custom completion rules. + * + * @return array List of added element names. + */ + public function add_completion_rules() { + $mform = $this->_form; + $suffix = $this->get_suffix(); + + $mform->addElement('checkbox', $this->get_suffixed_name('vote'), ' ', get_string('completionvote', RATINGALLOCATE_MOD_NAME)); + $mform->addElement('checkbox', $this->get_suffixed_name('allocation'), ' ', get_string('completionallocation', RATINGALLOCATE_MOD_NAME)); + + //Set default to not checked. + $mform->setDefault($this->get_suffixed_name('vote'), 0); + $mform->setDefault($this->get_suffixed_name('allocation'), 0); + + //Add help buttons. + $mform->addHelpButton($this->get_suffixed_name('vote'), 'completionvote', RATINGALLOCATE_MOD_NAME); + $mform->addHelpButton($this->get_suffixed_name('allocation'), 'completionallocation', RATINGALLOCATE_MOD_NAME); + + return [$this->get_suffixed_name('vote'), $this->get_suffixed_name('allocation')]; + } + + protected function get_suffixed_name(string $fieldname): string { + return $fieldname . $this->get_suffix(); + } + + /** + * Called during validaiton to see wether some activitiy-specific completion rules are selected. + * + * @param array $data Input data not yet validated. + * @return bool True if one or more rules are enabled, false if none are. + */ + public function completion_rule_enabled($data) { + return ($data[$this->get_suffixed_name('vote')] == 1 || $data[$this->get_suffixed_name('allocation')] == 1); + } + } From a377ad3b3f525fcc747cb0fd4ba17a0ed94bff1d Mon Sep 17 00:00:00 2001 From: Irina Hoppe Date: Wed, 17 Jan 2024 10:32:26 +0100 Subject: [PATCH 02/33] added language strings and fixed some syntax errors --- classes/completion/custom_completion.php | 2 +- db/upgrade.php | 4 ++-- lang/en/ratingallocate.php | 7 +++++++ lib.php | 2 +- mod_form.php | 6 +++--- 5 files changed, 14 insertions(+), 7 deletions(-) diff --git a/classes/completion/custom_completion.php b/classes/completion/custom_completion.php index c08af3c2..9e2a35d2 100644 --- a/classes/completion/custom_completion.php +++ b/classes/completion/custom_completion.php @@ -84,7 +84,7 @@ public static function get_defined_custom_rules(): array { */ public function get_custom_rule_descriptions(): array { return [ - 'completionvote' => get_string('comletionvote_desc', RATINGALLOCATE_MOD_NAME), + 'completionvote' => get_string('completionvote_desc', RATINGALLOCATE_MOD_NAME), 'completionallocation' => get_string('completionallocation_desc', RATINGALLOCATE_MOD_NAME) ]; } diff --git a/db/upgrade.php b/db/upgrade.php index ed21d858..e70e240e 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -218,7 +218,7 @@ function xmldb_ratingallocate_upgrade($oldversion) { upgrade_mod_savepoint(true, 2023050900, 'ratingallocate'); } - if ($oldversion < 2023122000) { + if ($oldversion < 2024011700) { // Define completionrules fields to be added to ratingallocate. $table = new xmldb_table('ratingallocate'); @@ -234,7 +234,7 @@ function xmldb_ratingallocate_upgrade($oldversion) { } // Ratingallocate savepoint reached. - upgrade_mod_savepoint(true, 2023121300, 'ratingallocate'); + upgrade_mod_savepoint(true, 2024011700, 'ratingallocate'); } return true; diff --git a/lang/en/ratingallocate.php b/lang/en/ratingallocate.php index 24cbddf5..a9551325 100644 --- a/lang/en/ratingallocate.php +++ b/lang/en/ratingallocate.php @@ -304,6 +304,13 @@ $string['err_required'] = 'You need to provide a value for this field.'; $string['err_minimum'] = 'The minimum value for this field is {$a}.'; $string['err_maximum'] = 'The maximum value for this field is {$a}.'; + +$string['completionvote'] = "Vote in the activity"; +$string['completionallocation'] = "Been allocated to a choice"; +$string['completionvote_help'] = "To complete this activity, users have to submit a vote."; +$string['completionallocation_help'] = "To complete this activity, users have to be allocated to a choice."; +$string['completionvote_desc'] = "Vote"; +$string['completionallocation_desc'] = "Be allocated"; // // $string['show_choices_header'] = 'List of all choices'; diff --git a/lib.php b/lib.php index c9685569..2f44283e 100644 --- a/lib.php +++ b/lib.php @@ -781,7 +781,7 @@ function ratingallocate_get_coursemodule_info($coursemodule) { } // Populate the custom completion rules as key => value pairs, but only if the completion mode is 'automatic'. - if ($ratingallocate->completion == COMPLETION_TRACKING_AUTOMATIC) { + if ($coursemodule->completion == COMPLETION_TRACKING_AUTOMATIC) { $result->customdata['customcompletionrules']['completionvote'] = $ratingallocate->completionvote; $result->customdata['customcompletionrules']['completionallocation'] = $ratingallocate->completionallocation; } diff --git a/mod_form.php b/mod_form.php index 9b4bdc68..62711030 100644 --- a/mod_form.php +++ b/mod_form.php @@ -334,8 +334,8 @@ public function add_completion_rules() { $mform = $this->_form; $suffix = $this->get_suffix(); - $mform->addElement('checkbox', $this->get_suffixed_name('vote'), ' ', get_string('completionvote', RATINGALLOCATE_MOD_NAME)); - $mform->addElement('checkbox', $this->get_suffixed_name('allocation'), ' ', get_string('completionallocation', RATINGALLOCATE_MOD_NAME)); + $mform->addElement('advcheckbox', $this->get_suffixed_name('vote'), ' ', get_string('completionvote', RATINGALLOCATE_MOD_NAME)); + $mform->addElement('advcheckbox', $this->get_suffixed_name('allocation'), ' ', get_string('completionallocation', RATINGALLOCATE_MOD_NAME)); //Set default to not checked. $mform->setDefault($this->get_suffixed_name('vote'), 0); @@ -349,7 +349,7 @@ public function add_completion_rules() { } protected function get_suffixed_name(string $fieldname): string { - return $fieldname . $this->get_suffix(); + return 'completion' . $fieldname; } /** From 9448309b4a5163e5e132168b257468e4a47f8c8a Mon Sep 17 00:00:00 2001 From: Irina Hoppe Date: Wed, 17 Jan 2024 13:52:58 +0100 Subject: [PATCH 03/33] some codestyle fixes and added behat tests for custom completion rules --- lib.php | 3 +- mod_form.php | 4 +- .../completion_condition_allocation.feature | 43 ++++++++++++++++++ tests/behat/completion_condition_vote.feature | 44 +++++++++++++++++++ tests/behat/completion_manual.feature | 39 ++++++++++++++++ 5 files changed, 129 insertions(+), 4 deletions(-) create mode 100644 tests/behat/completion_condition_allocation.feature create mode 100644 tests/behat/completion_condition_vote.feature create mode 100644 tests/behat/completion_manual.feature diff --git a/lib.php b/lib.php index 2f44283e..1209b99c 100644 --- a/lib.php +++ b/lib.php @@ -803,8 +803,7 @@ function ratingallocate_get_coursemodule_info($coursemodule) { * @param cm_info|stdClass $cm object with fields ->completion and ->customdata['customcompletionrules'] * @return array $descriptions the array of descriptions for the custom rules. */ -function mod_ratingallocate_get_completion_active_rule_descriptions($cm) -{ +function mod_ratingallocate_get_completion_active_rule_descriptions($cm) { // Values will be present in cm_info, and we assume these are up to date. if (empty($cm->customdata['customcompletionrules']) || $cm->completion != COMPLETION_TRACKING_AUTOMATIC) { return []; diff --git a/mod_form.php b/mod_form.php index 62711030..8683e64d 100644 --- a/mod_form.php +++ b/mod_form.php @@ -337,11 +337,11 @@ public function add_completion_rules() { $mform->addElement('advcheckbox', $this->get_suffixed_name('vote'), ' ', get_string('completionvote', RATINGALLOCATE_MOD_NAME)); $mform->addElement('advcheckbox', $this->get_suffixed_name('allocation'), ' ', get_string('completionallocation', RATINGALLOCATE_MOD_NAME)); - //Set default to not checked. + // Set default to not checked. $mform->setDefault($this->get_suffixed_name('vote'), 0); $mform->setDefault($this->get_suffixed_name('allocation'), 0); - //Add help buttons. + // Add help buttons. $mform->addHelpButton($this->get_suffixed_name('vote'), 'completionvote', RATINGALLOCATE_MOD_NAME); $mform->addHelpButton($this->get_suffixed_name('allocation'), 'completionallocation', RATINGALLOCATE_MOD_NAME); diff --git a/tests/behat/completion_condition_allocation.feature b/tests/behat/completion_condition_allocation.feature new file mode 100644 index 00000000..b03cebf0 --- /dev/null +++ b/tests/behat/completion_condition_allocation.feature @@ -0,0 +1,43 @@ +@mod @mod_ratingallocate @core_completion +Feature: Set a ratingallocate activity marked as completed when a user has been allocated + In order to ensure a student has been allocated + As a teacher + I need to set the ratingallocate to complete when the student has an allocation + + Background: + Given the following "users" exist: + | username | firstname | lastname | email | + | student1 | Student | 1 | student1@example.com | + | student2 | Student | 2 | student2@example.com | + | teacher1 | Teacher | 1 | teacher1@example.com | + And the following "courses" exist: + | fullname | shortname | category | enablecompletion | + | Course 1 | C1 | 0 | 1 | + And the following "course enrolments" exist: + | user | course | role | + | teacher1 | C1 | editingteacher | + | student1 | C1 | student | + | student2 | C1 | student | + And the following "activities" exist: + | activity | course | idnumber | name | completion | + | ratingallocate | C1 | ra1 | My Fair Allocation | 3 | + And the following choices exist: + | title | explanation | maxsize | ratingallocate | + | C1 | Test | 1 | My Fair Allocation | + | C2 | Test | 0 | My Fair Allocation | + And the following ratings exist: + | choice | user | rating | + | C1 | student1 | 1 | + | C1 | student2 | 0 | + | C2 | student1 | 0 | + | C2 | student2 | 0 | + And I run the scheduled task "mod_ratingallocate\task\cron_task" + + @javascript + Scenario: User completes ratingallocate only if they have been allocated + When I log in as "teacher1" + And I am on "Course 1" course homepage + And I navigate to "Reports" in current page administration + And I click on "Activity completion" "link" + Then "Completed" "icon" should exist in the "Student 1" "table_row" + And "Completed" "icon" should not exist in the "Student 2" "table_row" diff --git a/tests/behat/completion_condition_vote.feature b/tests/behat/completion_condition_vote.feature new file mode 100644 index 00000000..24e9ba33 --- /dev/null +++ b/tests/behat/completion_condition_vote.feature @@ -0,0 +1,44 @@ +@mod @mod_ratingallocate @core_completion +Feature: Set a ratingallocate activity marked as completed when a user submits a vote + In order to ensure a student has voted in the activity + As a teacher + I need to set the ratingallocate to complete when the student has voted + + Background: + Given the following "users" exist: + | username | firstname | lastname | email | + | student1 | Student | 1 | student1@example.com | + | student2 | Student | 2 | student2@example.com | + | teacher1 | Teacher | 1 | teacher1@example.com | + And the following "courses" exist: + | fullname | shortname | category | enablecompletion | + | Course 1 | C1 | 0 | 1 | + And the following "course enrolments" exist: + | user | course | role | + | teacher1 | C1 | editingteacher | + | student1 | C1 | student | + | student2 | C1 | student | + And the following "activities" exist: + | activity | course | idnumber | name | completion | + | ratingallocate | C1 | ra1 | My Fair Allocation | 2 | + And I log in as "teacher1" + And I am on the "My Fair Allocation" "ratingallocate activity" page + And I press "Edit Choices" + And I add a new choice with the values: + | title | My first choice | + | Description (optional) | Test 1 | + | maxsize | 2 | + + @javascript + Scenario: User completes ratingallocate only if they voted + When I log in as "student1" + And I am on the "My Fair Allocation" "ratingallocate activity" page + And I press "Edit Rating" + And I press "Save changes" + And I log out + And I log in as "teacher1" + And I am on "Course 1" course homepage + And I navigate to "Reports" in current page administration + And I click on "Activity completion" "link" + Then "Completed" "icon" should exist in the "Student 1" "table_row" + And "Completed" "icon" should not exist in the "Student 2" "table_row" diff --git a/tests/behat/completion_manual.feature b/tests/behat/completion_manual.feature new file mode 100644 index 00000000..057ecd60 --- /dev/null +++ b/tests/behat/completion_manual.feature @@ -0,0 +1,39 @@ +@mod @mod_ratingallocate @core_completion +Feature: Manually mark a ratingallocate activity as completed + In order to meet manual ratingallocate completion requirements + As a student + I need to be able to view and modify my ratingallocate manual completion status + + Background: + Given the following "users" exist: + | username | firstname | lastname | email | + | student1 | Student | 1 | student1@example.com | + | teacher1 | Teacher | 1 | teacher1@example.com | + And the following "courses" exist: + | fullname | shortname | category | enablecompletion | + | Course 1 | C1 | 0 | 1 | + And the following "course enrolments" exist: + | user | course | role | + | teacher1 | C1 | editingteacher | + | student1 | C1 | student | + And the following "activities" exist: + | activity | course | idnumber | name | completion | + | ratingallocate | C1 | ra1 | My Fair Allocation | 1 | + And I log in as "teacher1" + And I am on the "My Fair Allocation" "ratingallocate activity" page + And I press "Edit Choices" + And I add a new choice with the values: + | title | My first choice | + | Description (optional) | Test 1 | + | maxsize | 2 | + + @javascript + Scenario: Use manual completion + Given I am on the "My Fair Allocation" "ratingallocate activity" page logged in as teacher1 + And the manual completion button for "My Fair Allocation" should be disabled + And I log out + # Student view. + When I am on the "My Fair Allocation" "ratingallocate activity" page logged in as student1 + Then the manual completion button of "My Fair Allocation" is displayed as "Mark as done" + And I toggle the manual completion state of "My Fair Allocation" + And the manual completion button of "My Fair Allocation" is displayed as "Done" From 42d871521bfbf14b50e9ed12e423b91474c2076a Mon Sep 17 00:00:00 2001 From: Irina Hoppe Date: Mon, 22 Jan 2024 10:00:08 +0100 Subject: [PATCH 04/33] modified behat backgrounds according to ratingallocate settings form --- tests/behat/completion_condition_allocation.feature | 9 +++++++-- tests/behat/completion_condition_vote.feature | 9 +++++++-- tests/behat/completion_manual.feature | 8 ++++++-- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/tests/behat/completion_condition_allocation.feature b/tests/behat/completion_condition_allocation.feature index b03cebf0..b389e6a6 100644 --- a/tests/behat/completion_condition_allocation.feature +++ b/tests/behat/completion_condition_allocation.feature @@ -19,8 +19,13 @@ Feature: Set a ratingallocate activity marked as completed when a user has been | student1 | C1 | student | | student2 | C1 | student | And the following "activities" exist: - | activity | course | idnumber | name | completion | - | ratingallocate | C1 | ra1 | My Fair Allocation | 3 | + | activity | course | idnumber | name | + | ratingallocate | C1 | ra1 | My Fair Allocation | + And I am on the "My Fair Allocation" "ratingallocate activity editing" page + And I expand "Completion conditions" node + And I select the radio "id_completion_2" + And I check "id_completionallocation" + And I press "id_submitbutton" And the following choices exist: | title | explanation | maxsize | ratingallocate | | C1 | Test | 1 | My Fair Allocation | diff --git a/tests/behat/completion_condition_vote.feature b/tests/behat/completion_condition_vote.feature index 24e9ba33..af1b27fb 100644 --- a/tests/behat/completion_condition_vote.feature +++ b/tests/behat/completion_condition_vote.feature @@ -19,8 +19,8 @@ Feature: Set a ratingallocate activity marked as completed when a user submits a | student1 | C1 | student | | student2 | C1 | student | And the following "activities" exist: - | activity | course | idnumber | name | completion | - | ratingallocate | C1 | ra1 | My Fair Allocation | 2 | + | activity | course | idnumber | name | + | ratingallocate | C1 | ra1 | My Fair Allocation | And I log in as "teacher1" And I am on the "My Fair Allocation" "ratingallocate activity" page And I press "Edit Choices" @@ -28,6 +28,11 @@ Feature: Set a ratingallocate activity marked as completed when a user submits a | title | My first choice | | Description (optional) | Test 1 | | maxsize | 2 | + And I am on the "My Fair Allocation" "ratingallocate activity editing" page + And I expand "Completion conditions" node + And I select the radio "id_completion_2" + And I check "id_completionvote" + And I press "id_submitbutton" @javascript Scenario: User completes ratingallocate only if they voted diff --git a/tests/behat/completion_manual.feature b/tests/behat/completion_manual.feature index 057ecd60..7698507d 100644 --- a/tests/behat/completion_manual.feature +++ b/tests/behat/completion_manual.feature @@ -17,8 +17,8 @@ Feature: Manually mark a ratingallocate activity as completed | teacher1 | C1 | editingteacher | | student1 | C1 | student | And the following "activities" exist: - | activity | course | idnumber | name | completion | - | ratingallocate | C1 | ra1 | My Fair Allocation | 1 | + | activity | course | idnumber | name | + | ratingallocate | C1 | ra1 | My Fair Allocation | And I log in as "teacher1" And I am on the "My Fair Allocation" "ratingallocate activity" page And I press "Edit Choices" @@ -26,6 +26,10 @@ Feature: Manually mark a ratingallocate activity as completed | title | My first choice | | Description (optional) | Test 1 | | maxsize | 2 | + And I am on the "My Fair Allocation" "ratingallocate activity editing" page + And I expand "Completion conditions" node + And I select the radio "id_completion_1" + And I press "id_submitbutton" @javascript Scenario: Use manual completion From c4e6082febb330a87a2458b2fcaa69d50b96521d Mon Sep 17 00:00:00 2001 From: Irina Hoppe Date: Fri, 2 Feb 2024 09:48:14 +0100 Subject: [PATCH 05/33] modified behat and phpunit tests --- mod_form.php | 1 - tests/behat/completion_condition_allocation.feature | 9 ++------- tests/behat/completion_condition_vote.feature | 9 ++------- tests/behat/completion_manual.feature | 8 ++------ tests/mod_generator_test.php | 4 +++- 5 files changed, 9 insertions(+), 22 deletions(-) diff --git a/mod_form.php b/mod_form.php index 8683e64d..14b98915 100644 --- a/mod_form.php +++ b/mod_form.php @@ -332,7 +332,6 @@ private function get_settingsfield_identifier($strategy, $key) { */ public function add_completion_rules() { $mform = $this->_form; - $suffix = $this->get_suffix(); $mform->addElement('advcheckbox', $this->get_suffixed_name('vote'), ' ', get_string('completionvote', RATINGALLOCATE_MOD_NAME)); $mform->addElement('advcheckbox', $this->get_suffixed_name('allocation'), ' ', get_string('completionallocation', RATINGALLOCATE_MOD_NAME)); diff --git a/tests/behat/completion_condition_allocation.feature b/tests/behat/completion_condition_allocation.feature index b389e6a6..75f90bd7 100644 --- a/tests/behat/completion_condition_allocation.feature +++ b/tests/behat/completion_condition_allocation.feature @@ -19,13 +19,8 @@ Feature: Set a ratingallocate activity marked as completed when a user has been | student1 | C1 | student | | student2 | C1 | student | And the following "activities" exist: - | activity | course | idnumber | name | - | ratingallocate | C1 | ra1 | My Fair Allocation | - And I am on the "My Fair Allocation" "ratingallocate activity editing" page - And I expand "Completion conditions" node - And I select the radio "id_completion_2" - And I check "id_completionallocation" - And I press "id_submitbutton" + | activity | course | idnumber | name | completion | completionallocation | + | ratingallocate | C1 | ra1 | My Fair Allocation | 2 | 1 | And the following choices exist: | title | explanation | maxsize | ratingallocate | | C1 | Test | 1 | My Fair Allocation | diff --git a/tests/behat/completion_condition_vote.feature b/tests/behat/completion_condition_vote.feature index af1b27fb..82a376b8 100644 --- a/tests/behat/completion_condition_vote.feature +++ b/tests/behat/completion_condition_vote.feature @@ -19,8 +19,8 @@ Feature: Set a ratingallocate activity marked as completed when a user submits a | student1 | C1 | student | | student2 | C1 | student | And the following "activities" exist: - | activity | course | idnumber | name | - | ratingallocate | C1 | ra1 | My Fair Allocation | + | activity | course | idnumber | name | completion | completionvote | + | ratingallocate | C1 | ra1 | My Fair Allocation | 2 | 1 | And I log in as "teacher1" And I am on the "My Fair Allocation" "ratingallocate activity" page And I press "Edit Choices" @@ -28,11 +28,6 @@ Feature: Set a ratingallocate activity marked as completed when a user submits a | title | My first choice | | Description (optional) | Test 1 | | maxsize | 2 | - And I am on the "My Fair Allocation" "ratingallocate activity editing" page - And I expand "Completion conditions" node - And I select the radio "id_completion_2" - And I check "id_completionvote" - And I press "id_submitbutton" @javascript Scenario: User completes ratingallocate only if they voted diff --git a/tests/behat/completion_manual.feature b/tests/behat/completion_manual.feature index 7698507d..057ecd60 100644 --- a/tests/behat/completion_manual.feature +++ b/tests/behat/completion_manual.feature @@ -17,8 +17,8 @@ Feature: Manually mark a ratingallocate activity as completed | teacher1 | C1 | editingteacher | | student1 | C1 | student | And the following "activities" exist: - | activity | course | idnumber | name | - | ratingallocate | C1 | ra1 | My Fair Allocation | + | activity | course | idnumber | name | completion | + | ratingallocate | C1 | ra1 | My Fair Allocation | 1 | And I log in as "teacher1" And I am on the "My Fair Allocation" "ratingallocate activity" page And I press "Edit Choices" @@ -26,10 +26,6 @@ Feature: Manually mark a ratingallocate activity as completed | title | My first choice | | Description (optional) | Test 1 | | maxsize | 2 | - And I am on the "My Fair Allocation" "ratingallocate activity editing" page - And I expand "Completion conditions" node - And I select the radio "id_completion_1" - And I press "id_submitbutton" @javascript Scenario: Use manual completion diff --git a/tests/mod_generator_test.php b/tests/mod_generator_test.php index f3c2d233..767246de 100644 --- a/tests/mod_generator_test.php +++ b/tests/mod_generator_test.php @@ -73,7 +73,9 @@ public function test_create_instance(): void { 'algorithmstarttime' => null, 'algorithmstatus' => '0', 'runalgorithmbycron' => '1', - ]; + 'completionvote' => '0', + 'completionallocation' => '0', + ); $this->assertEquals(json_decode(json_encode($expectedvaluesdb, false)), reset($records)); // Must have two choices. From f3916c0629ed6d5f516d0aadff1cb46323d7a2c6 Mon Sep 17 00:00:00 2001 From: Irina Hoppe Date: Fri, 2 Feb 2024 10:19:53 +0100 Subject: [PATCH 06/33] fixed behat test for completionallocation --- tests/behat/completion_condition_allocation.feature | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/behat/completion_condition_allocation.feature b/tests/behat/completion_condition_allocation.feature index 75f90bd7..e083291f 100644 --- a/tests/behat/completion_condition_allocation.feature +++ b/tests/behat/completion_condition_allocation.feature @@ -31,7 +31,12 @@ Feature: Set a ratingallocate activity marked as completed when a user has been | C1 | student2 | 0 | | C2 | student1 | 0 | | C2 | student2 | 0 | + And I log in as "teacher1" + And I am on the "My Fair Allocation" "ratingallocate activity editing" page And I run the scheduled task "mod_ratingallocate\task\cron_task" + And I am on the "My Fair Allocation" "ratingallocate activity" page + And I press "Publish Allocation" + And I log out @javascript Scenario: User completes ratingallocate only if they have been allocated From 73d16ab3cb070eaa6c49e9f4fd39540577ea3ade Mon Sep 17 00:00:00 2001 From: Irina Hoppe Date: Fri, 2 Feb 2024 10:37:45 +0100 Subject: [PATCH 07/33] fixed change of completion status for manual allocation and allocation by cron --- locallib.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/locallib.php b/locallib.php index 7353bbf9..2c89b406 100644 --- a/locallib.php +++ b/locallib.php @@ -304,6 +304,13 @@ private function process_action_start_distribution() { \core\output\notification::NOTIFY_SUCCESS); } } + $raters = $this->get_raters_in_course(); + $completion = new completion_info($this->course); + if ($completion->is_enabled($this->coursemodule)) { + foreach ($raters as $rater) { + $completion->update_state($this->coursemodule, COMPLETION_UNKNOWN, $rater->id); + } + } redirect(new moodle_url('/mod/ratingallocate/view.php', ['id' => $this->coursemodule->id])); return; @@ -728,6 +735,13 @@ private function process_action_manual_allocation() { ['id' => $this->coursemodule->id, 'action' => ACTION_MANUAL_ALLOCATION])); } } + $raters = $this->get_raters_in_course(); + $completion = new completion_info($this->course); + if ($completion->is_enabled($this->coursemodule)) { + foreach ($raters as $rater) { + $completion->update_state($this->coursemodule, COMPLETION_UNKNOWN, $rater->id); + } + } } $output .= $OUTPUT->heading(get_string('manual_allocation', RATINGALLOCATE_MOD_NAME), 2); From 4176b98e8ddb39f3d6590368fb79af51a10d8757 Mon Sep 17 00:00:00 2001 From: Irina Hoppe Date: Fri, 2 Feb 2024 13:39:23 +0100 Subject: [PATCH 08/33] changed behat test for completionallocation --- tests/behat/completion_condition_allocation.feature | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/behat/completion_condition_allocation.feature b/tests/behat/completion_condition_allocation.feature index e083291f..66a5eb8e 100644 --- a/tests/behat/completion_condition_allocation.feature +++ b/tests/behat/completion_condition_allocation.feature @@ -32,9 +32,8 @@ Feature: Set a ratingallocate activity marked as completed when a user has been | C2 | student1 | 0 | | C2 | student2 | 0 | And I log in as "teacher1" - And I am on the "My Fair Allocation" "ratingallocate activity editing" page - And I run the scheduled task "mod_ratingallocate\task\cron_task" And I am on the "My Fair Allocation" "ratingallocate activity" page + And I run the scheduled task "mod_ratingallocate\task\cron_task" And I press "Publish Allocation" And I log out From 2ec59727e224555bd8eca5f7b5e9ab355e58ade8 Mon Sep 17 00:00:00 2001 From: Irina Hoppe Date: Wed, 20 Dec 2023 11:39:34 +0100 Subject: [PATCH 09/33] WIP: added custom completion rules --- lib.php | 2 ++ mod_form.php | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib.php b/lib.php index 1209b99c..226f1a5f 100644 --- a/lib.php +++ b/lib.php @@ -72,6 +72,8 @@ function ratingallocate_supports($feature) { return true; case FEATURE_COMPLETION_HAS_RULES: return true; + case FEATURE_COMPLETION_HAS_RULES: + return true; default : return null; } diff --git a/mod_form.php b/mod_form.php index 14b98915..4831ce69 100644 --- a/mod_form.php +++ b/mod_form.php @@ -332,9 +332,10 @@ private function get_settingsfield_identifier($strategy, $key) { */ public function add_completion_rules() { $mform = $this->_form; + $suffix = $this->get_suffix(); - $mform->addElement('advcheckbox', $this->get_suffixed_name('vote'), ' ', get_string('completionvote', RATINGALLOCATE_MOD_NAME)); - $mform->addElement('advcheckbox', $this->get_suffixed_name('allocation'), ' ', get_string('completionallocation', RATINGALLOCATE_MOD_NAME)); + $mform->addElement('checkbox', $this->get_suffixed_name('vote'), ' ', get_string('completionvote', RATINGALLOCATE_MOD_NAME)); + $mform->addElement('checkbox', $this->get_suffixed_name('allocation'), ' ', get_string('completionallocation', RATINGALLOCATE_MOD_NAME)); // Set default to not checked. $mform->setDefault($this->get_suffixed_name('vote'), 0); From e2520d3a0d3b9588df779234752db72963e57659 Mon Sep 17 00:00:00 2001 From: Irina Hoppe Date: Wed, 17 Jan 2024 10:32:26 +0100 Subject: [PATCH 10/33] added language strings and fixed some syntax errors --- mod_form.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mod_form.php b/mod_form.php index 4831ce69..8683e64d 100644 --- a/mod_form.php +++ b/mod_form.php @@ -334,8 +334,8 @@ public function add_completion_rules() { $mform = $this->_form; $suffix = $this->get_suffix(); - $mform->addElement('checkbox', $this->get_suffixed_name('vote'), ' ', get_string('completionvote', RATINGALLOCATE_MOD_NAME)); - $mform->addElement('checkbox', $this->get_suffixed_name('allocation'), ' ', get_string('completionallocation', RATINGALLOCATE_MOD_NAME)); + $mform->addElement('advcheckbox', $this->get_suffixed_name('vote'), ' ', get_string('completionvote', RATINGALLOCATE_MOD_NAME)); + $mform->addElement('advcheckbox', $this->get_suffixed_name('allocation'), ' ', get_string('completionallocation', RATINGALLOCATE_MOD_NAME)); // Set default to not checked. $mform->setDefault($this->get_suffixed_name('vote'), 0); From 59c3d9f4c077d381036bc88384a469f9dd2037fc Mon Sep 17 00:00:00 2001 From: Irina Hoppe Date: Mon, 22 Jan 2024 10:00:08 +0100 Subject: [PATCH 11/33] modified behat backgrounds according to ratingallocate settings form --- tests/behat/completion_manual.feature | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/behat/completion_manual.feature b/tests/behat/completion_manual.feature index 057ecd60..7698507d 100644 --- a/tests/behat/completion_manual.feature +++ b/tests/behat/completion_manual.feature @@ -17,8 +17,8 @@ Feature: Manually mark a ratingallocate activity as completed | teacher1 | C1 | editingteacher | | student1 | C1 | student | And the following "activities" exist: - | activity | course | idnumber | name | completion | - | ratingallocate | C1 | ra1 | My Fair Allocation | 1 | + | activity | course | idnumber | name | + | ratingallocate | C1 | ra1 | My Fair Allocation | And I log in as "teacher1" And I am on the "My Fair Allocation" "ratingallocate activity" page And I press "Edit Choices" @@ -26,6 +26,10 @@ Feature: Manually mark a ratingallocate activity as completed | title | My first choice | | Description (optional) | Test 1 | | maxsize | 2 | + And I am on the "My Fair Allocation" "ratingallocate activity editing" page + And I expand "Completion conditions" node + And I select the radio "id_completion_1" + And I press "id_submitbutton" @javascript Scenario: Use manual completion From 71974f61407e07542ad2b33906da2e3d3ea203ec Mon Sep 17 00:00:00 2001 From: Irina Hoppe Date: Fri, 2 Feb 2024 09:48:14 +0100 Subject: [PATCH 12/33] modified behat and phpunit tests --- mod_form.php | 1 - tests/behat/completion_manual.feature | 8 ++------ 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/mod_form.php b/mod_form.php index 8683e64d..14b98915 100644 --- a/mod_form.php +++ b/mod_form.php @@ -332,7 +332,6 @@ private function get_settingsfield_identifier($strategy, $key) { */ public function add_completion_rules() { $mform = $this->_form; - $suffix = $this->get_suffix(); $mform->addElement('advcheckbox', $this->get_suffixed_name('vote'), ' ', get_string('completionvote', RATINGALLOCATE_MOD_NAME)); $mform->addElement('advcheckbox', $this->get_suffixed_name('allocation'), ' ', get_string('completionallocation', RATINGALLOCATE_MOD_NAME)); diff --git a/tests/behat/completion_manual.feature b/tests/behat/completion_manual.feature index 7698507d..057ecd60 100644 --- a/tests/behat/completion_manual.feature +++ b/tests/behat/completion_manual.feature @@ -17,8 +17,8 @@ Feature: Manually mark a ratingallocate activity as completed | teacher1 | C1 | editingteacher | | student1 | C1 | student | And the following "activities" exist: - | activity | course | idnumber | name | - | ratingallocate | C1 | ra1 | My Fair Allocation | + | activity | course | idnumber | name | completion | + | ratingallocate | C1 | ra1 | My Fair Allocation | 1 | And I log in as "teacher1" And I am on the "My Fair Allocation" "ratingallocate activity" page And I press "Edit Choices" @@ -26,10 +26,6 @@ Feature: Manually mark a ratingallocate activity as completed | title | My first choice | | Description (optional) | Test 1 | | maxsize | 2 | - And I am on the "My Fair Allocation" "ratingallocate activity editing" page - And I expand "Completion conditions" node - And I select the radio "id_completion_1" - And I press "id_submitbutton" @javascript Scenario: Use manual completion From 84bfd46fc264da68587828216983ffaf3b2bbfa8 Mon Sep 17 00:00:00 2001 From: Irina Hoppe Date: Fri, 2 Feb 2024 10:19:53 +0100 Subject: [PATCH 13/33] fixed behat test for completionallocation --- tests/behat/completion_condition_allocation.feature | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/behat/completion_condition_allocation.feature b/tests/behat/completion_condition_allocation.feature index 66a5eb8e..e083291f 100644 --- a/tests/behat/completion_condition_allocation.feature +++ b/tests/behat/completion_condition_allocation.feature @@ -32,8 +32,9 @@ Feature: Set a ratingallocate activity marked as completed when a user has been | C2 | student1 | 0 | | C2 | student2 | 0 | And I log in as "teacher1" - And I am on the "My Fair Allocation" "ratingallocate activity" page + And I am on the "My Fair Allocation" "ratingallocate activity editing" page And I run the scheduled task "mod_ratingallocate\task\cron_task" + And I am on the "My Fair Allocation" "ratingallocate activity" page And I press "Publish Allocation" And I log out From e8d8df02fc4cdac3f35d76321b2119a355a8be49 Mon Sep 17 00:00:00 2001 From: Irina Hoppe Date: Fri, 2 Feb 2024 10:37:45 +0100 Subject: [PATCH 14/33] fixed change of completion status for manual allocation and allocation by cron --- locallib.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/locallib.php b/locallib.php index 2c89b406..4a8d912d 100644 --- a/locallib.php +++ b/locallib.php @@ -742,6 +742,13 @@ private function process_action_manual_allocation() { $completion->update_state($this->coursemodule, COMPLETION_UNKNOWN, $rater->id); } } + $raters = $this->get_raters_in_course(); + $completion = new completion_info($this->course); + if ($completion->is_enabled($this->coursemodule)) { + foreach ($raters as $rater) { + $completion->update_state($this->coursemodule, COMPLETION_UNKNOWN, $rater->id); + } + } } $output .= $OUTPUT->heading(get_string('manual_allocation', RATINGALLOCATE_MOD_NAME), 2); From 169a3bb24a2f0c0ed6fa5deceafc0bcd3542adde Mon Sep 17 00:00:00 2001 From: Irina Hoppe Date: Fri, 2 Feb 2024 13:39:23 +0100 Subject: [PATCH 15/33] changed behat test for completionallocation --- tests/behat/completion_condition_allocation.feature | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/behat/completion_condition_allocation.feature b/tests/behat/completion_condition_allocation.feature index e083291f..66a5eb8e 100644 --- a/tests/behat/completion_condition_allocation.feature +++ b/tests/behat/completion_condition_allocation.feature @@ -32,9 +32,8 @@ Feature: Set a ratingallocate activity marked as completed when a user has been | C2 | student1 | 0 | | C2 | student2 | 0 | And I log in as "teacher1" - And I am on the "My Fair Allocation" "ratingallocate activity editing" page - And I run the scheduled task "mod_ratingallocate\task\cron_task" And I am on the "My Fair Allocation" "ratingallocate activity" page + And I run the scheduled task "mod_ratingallocate\task\cron_task" And I press "Publish Allocation" And I log out From 960b3db0a7ce6d6ec55f40153a9abbab7b0148ba Mon Sep 17 00:00:00 2001 From: Irina Hoppe Date: Thu, 23 May 2024 10:30:39 +0200 Subject: [PATCH 16/33] modify behat tests for new ratingallocate navigation, check completion status after db queries --- locallib.php | 25 ++++++++++++++++++- .../completion_condition_allocation.feature | 2 +- tests/behat/completion_condition_vote.feature | 5 ++-- tests/behat/completion_manual.feature | 17 +++++++------ 4 files changed, 36 insertions(+), 13 deletions(-) diff --git a/locallib.php b/locallib.php index 4a8d912d..f6408dd2 100644 --- a/locallib.php +++ b/locallib.php @@ -653,6 +653,14 @@ private function process_action_delete_choice() { $DB->delete_records(this_db\ratingallocate_ch_gengroups::TABLE, ['choiceid' => $choiceid]); $DB->delete_records(this_db\ratingallocate_choices::TABLE, ['id' => $choiceid]); + $raters = $this->get_raters_in_course(); + $completion = new completion_info($this->course); + if ($completion->is_enabled($this->coursemodule)) { + foreach ($raters as $rater) { + $completion->update_state($this->coursemodule, COMPLETION_INCOMPLETE, $rater->id); + } + } + redirect(new moodle_url('/mod/ratingallocate/view.php', ['id' => $this->coursemodule->id, 'action' => ACTION_SHOW_CHOICES]), get_string('choice_deleted_notification', RATINGALLOCATE_MOD_NAME, @@ -1042,6 +1050,13 @@ public function distribute_users_without_choice(string $distributionalgorithm): // At this point we tried to assign all the users. It is possible that users remain undistributed, though. $transaction->allow_commit(); + + $completion = new completion_info($this->course); + if ($completion->is_enabled($this->coursemodule)) { + foreach ($possibleusers as $userid) { + $completion->update_state($this->coursemodule, COMPLETION_UNKNOWN, $userid); + } + } } /** @@ -1429,7 +1444,7 @@ public function distrubute_choices() { $raters = $this->get_raters_in_course(); if ($completion->is_enabled($this->coursemodule)) { foreach ($raters as $rater) { - $completion->update_state($this->coursemodule, COMPLETION_COMPLETE, $rater->id); + $completion->update_state($this->coursemodule, COMPLETION_UNKNOWN, $rater->id); } } @@ -2052,6 +2067,14 @@ public function save_manual_allocation_form($allocdata, $userdata) { $event->trigger(); $transaction->allow_commit(); + + $completion = new completion_info($this->course); + if ($completion->is_enabled($this->coursemodule)) { + foreach ($allusers as $rater) { + $completion->update_state($this->coursemodule, COMPLETION_UNKNOWN, $rater->id); + } + } + } catch (Exception $e) { if (isset($transaction)) { $transaction->rollback($e); diff --git a/tests/behat/completion_condition_allocation.feature b/tests/behat/completion_condition_allocation.feature index 66a5eb8e..532b9cec 100644 --- a/tests/behat/completion_condition_allocation.feature +++ b/tests/behat/completion_condition_allocation.feature @@ -32,7 +32,7 @@ Feature: Set a ratingallocate activity marked as completed when a user has been | C2 | student1 | 0 | | C2 | student2 | 0 | And I log in as "teacher1" - And I am on the "My Fair Allocation" "ratingallocate activity" page + And I am on the "My Fair Allocation" "mod_ratingallocate > View" page And I run the scheduled task "mod_ratingallocate\task\cron_task" And I press "Publish Allocation" And I log out diff --git a/tests/behat/completion_condition_vote.feature b/tests/behat/completion_condition_vote.feature index 82a376b8..b904d29f 100644 --- a/tests/behat/completion_condition_vote.feature +++ b/tests/behat/completion_condition_vote.feature @@ -22,8 +22,7 @@ Feature: Set a ratingallocate activity marked as completed when a user submits a | activity | course | idnumber | name | completion | completionvote | | ratingallocate | C1 | ra1 | My Fair Allocation | 2 | 1 | And I log in as "teacher1" - And I am on the "My Fair Allocation" "ratingallocate activity" page - And I press "Edit Choices" + And I am on the "My Fair Allocation" "mod_ratingallocate > Choices" page And I add a new choice with the values: | title | My first choice | | Description (optional) | Test 1 | @@ -32,7 +31,7 @@ Feature: Set a ratingallocate activity marked as completed when a user submits a @javascript Scenario: User completes ratingallocate only if they voted When I log in as "student1" - And I am on the "My Fair Allocation" "ratingallocate activity" page + And I am on the "My Fair Allocation" "mod_ratingallocate > View" page And I press "Edit Rating" And I press "Save changes" And I log out diff --git a/tests/behat/completion_manual.feature b/tests/behat/completion_manual.feature index 057ecd60..31a66cdd 100644 --- a/tests/behat/completion_manual.feature +++ b/tests/behat/completion_manual.feature @@ -20,20 +20,21 @@ Feature: Manually mark a ratingallocate activity as completed | activity | course | idnumber | name | completion | | ratingallocate | C1 | ra1 | My Fair Allocation | 1 | And I log in as "teacher1" - And I am on the "My Fair Allocation" "ratingallocate activity" page - And I press "Edit Choices" + And I am on the "My Fair Allocation" "mod_ratingallocate > Choices" page And I add a new choice with the values: | title | My first choice | | Description (optional) | Test 1 | | maxsize | 2 | @javascript - Scenario: Use manual completion - Given I am on the "My Fair Allocation" "ratingallocate activity" page logged in as teacher1 - And the manual completion button for "My Fair Allocation" should be disabled - And I log out - # Student view. - When I am on the "My Fair Allocation" "ratingallocate activity" page logged in as student1 + Scenario: Use manual completion as teacher + When I log in as "teacher1" + And I am on the "My Fair Allocation" "mod_ratingallocate > View" page + Then the manual completion button for "My Fair Allocation" should be disabled + + Scenario: Use manual completion student view + When I log in as "student1" + And I am on the "My Fair Allocation" "mod_ratingallocate > View" page Then the manual completion button of "My Fair Allocation" is displayed as "Mark as done" And I toggle the manual completion state of "My Fair Allocation" And the manual completion button of "My Fair Allocation" is displayed as "Done" From e151376e9f52d0d6e0675c5b12c5b319755d1481 Mon Sep 17 00:00:00 2001 From: Irina Hoppe Date: Thu, 13 Jun 2024 11:17:05 +0200 Subject: [PATCH 17/33] fix changing completionsettings after users already completing the activity --- locallib.php | 3 +++ mod_form.php | 50 +++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/locallib.php b/locallib.php index f6408dd2..da5a4942 100644 --- a/locallib.php +++ b/locallib.php @@ -1232,6 +1232,9 @@ private function process_default() { } + $completion = new completion_info($this->course); + $completion->set_module_viewed($this->coursemodule); + // Logging. $event = \mod_ratingallocate\event\ratingallocate_viewed::create_simple( context_module::instance($this->coursemodule->id), $this->ratingallocateid); diff --git a/mod_form.php b/mod_form.php index 14b98915..8a8cf122 100644 --- a/mod_form.php +++ b/mod_form.php @@ -231,13 +231,13 @@ private function add_settings_field($stratfieldid, array $value, $strategyid, Mo * @throws coding_exception */ public function definition_after_data() { - parent::definition_after_data(); + $mform = &$this->_form; $data = $this->current; if ($this->is_submitted()) { - $subdata = $this->get_submitted_data(); + $subdata = $this->get_data(); $allstrategyoptions = $subdata->{self::STRATEGY_OPTIONS}; } else if (isset($data->setting)) { $allstrategyoptions = json_decode($data->setting, true); @@ -272,8 +272,12 @@ public function definition_after_data() { } $mform->removeElement($strategyplaceholder); } + + // Call parent function after, in order to have completiontracking working properly. + parent::definition_after_data(); } + /** * Checks that accesstimestart is before accesstimestop */ @@ -348,7 +352,7 @@ public function add_completion_rules() { } protected function get_suffixed_name(string $fieldname): string { - return 'completion' . $fieldname; + return 'completion' . $fieldname . $this->get_suffix(); } /** @@ -361,4 +365,44 @@ public function completion_rule_enabled($data) { return ($data[$this->get_suffixed_name('vote')] == 1 || $data[$this->get_suffixed_name('allocation')] == 1); } + /** + * Allows module to modify data returned by get_moduleinfo_data() or prepare_new_moduleinfo_data() before calling set_data(). + * This method is also called in the bulk activity completion form. + * Only available on moodleform_mod. + * + * @param $default_values + * @return void + */ + function data_preprocessing(&$default_values){ + if(empty($default_values[$this->get_suffixed_name('vote')])) { + $default_values[$this->get_suffixed_name('vote')] = 0; + } + if(empty($default_values[$this->get_suffixed_name('allocation')])) { + $default_values[$this->get_suffixed_name('allocation')] = 0; + } + } + + /** + * Allows module to modify the data returned by form get_data(). + * This method is also called in the bulk activity completion form. + * + * Only available on moodleform_mod. + * + * @param stdClass $data the form data to be modified. + */ + public function data_postprocessing($data) { + parent::data_postprocessing($data); + // Turn off completion settings if the checkboxes aren't ticked. + if (!empty($data->completionunlocked)) { + $completion = $data->{'completion' . $this->get_suffix()}; + $autocompletion = !empty($completion) && $completion == COMPLETION_TRACKING_AUTOMATIC; + if (empty($data->{$this->get_suffixed_name('vote')}) || !$autocompletion) { + $data->{$this->get_suffixed_name('vote')} = 0; + } + if (empty($data->{$this->get_suffixed_name('allocation')}) || !$autocompletion) { + $data->{$this->get_suffixed_name('allocation')} = 0; + } + } + } + } From e3f26be66df636661d136a2731987e35edc9f386 Mon Sep 17 00:00:00 2001 From: Irina Hoppe Date: Thu, 13 Jun 2024 11:22:27 +0200 Subject: [PATCH 18/33] codestyle fixes --- mod_form.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/mod_form.php b/mod_form.php index 8a8cf122..d732f93f 100644 --- a/mod_form.php +++ b/mod_form.php @@ -370,15 +370,15 @@ public function completion_rule_enabled($data) { * This method is also called in the bulk activity completion form. * Only available on moodleform_mod. * - * @param $default_values + * @param $defaultvalues * @return void */ - function data_preprocessing(&$default_values){ - if(empty($default_values[$this->get_suffixed_name('vote')])) { - $default_values[$this->get_suffixed_name('vote')] = 0; + public function data_preprocessing (&$defaultvalues){ + if (empty($defaultvalues[$this->get_suffixed_name('vote')])) { + $defaultvalues[$this->get_suffixed_name('vote')] = 0; } - if(empty($default_values[$this->get_suffixed_name('allocation')])) { - $default_values[$this->get_suffixed_name('allocation')] = 0; + if (empty($defaultvalues[$this->get_suffixed_name('allocation')])) { + $defaultvalues[$this->get_suffixed_name('allocation')] = 0; } } From 089deaf1ec57a003654b7df7c89b18c00d5ca36e Mon Sep 17 00:00:00 2001 From: Irina Hoppe Date: Thu, 13 Jun 2024 11:26:10 +0200 Subject: [PATCH 19/33] codestyle fixes --- mod_form.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mod_form.php b/mod_form.php index d732f93f..18456a8e 100644 --- a/mod_form.php +++ b/mod_form.php @@ -373,7 +373,7 @@ public function completion_rule_enabled($data) { * @param $defaultvalues * @return void */ - public function data_preprocessing (&$defaultvalues){ + public function data_preprocessing(&$defaultvalues) { if (empty($defaultvalues[$this->get_suffixed_name('vote')])) { $defaultvalues[$this->get_suffixed_name('vote')] = 0; } From 5862ec0c81144de434dbdf7995cf39caa2641d62 Mon Sep 17 00:00:00 2001 From: Irina Hoppe Date: Thu, 13 Jun 2024 11:56:48 +0200 Subject: [PATCH 20/33] fix suffix for custom completion fields, fix behat test for completion on allocation --- mod_form.php | 3 ++- tests/behat/completion_condition_allocation.feature | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/mod_form.php b/mod_form.php index 18456a8e..077ab6dc 100644 --- a/mod_form.php +++ b/mod_form.php @@ -352,7 +352,8 @@ public function add_completion_rules() { } protected function get_suffixed_name(string $fieldname): string { - return 'completion' . $fieldname . $this->get_suffix(); + // Replace _ratingallocate with $this->get_suffix() for Moodle 4.3 or later. + return 'completion' . $fieldname . '_ratingallocate'; } /** diff --git a/tests/behat/completion_condition_allocation.feature b/tests/behat/completion_condition_allocation.feature index 532b9cec..634d3af8 100644 --- a/tests/behat/completion_condition_allocation.feature +++ b/tests/behat/completion_condition_allocation.feature @@ -35,6 +35,7 @@ Feature: Set a ratingallocate activity marked as completed when a user has been And I am on the "My Fair Allocation" "mod_ratingallocate > View" page And I run the scheduled task "mod_ratingallocate\task\cron_task" And I press "Publish Allocation" + And I run the scheduled task "core\task\completion_regular_task" And I log out @javascript From a5de1556d9333d413242e24457e7b5aa948e2dee Mon Sep 17 00:00:00 2001 From: Irina Hoppe Date: Thu, 13 Jun 2024 12:53:06 +0200 Subject: [PATCH 21/33] run completion scheduled task in behat test for custom completion --- tests/behat/completion_condition_allocation.feature | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/behat/completion_condition_allocation.feature b/tests/behat/completion_condition_allocation.feature index 634d3af8..becac7fc 100644 --- a/tests/behat/completion_condition_allocation.feature +++ b/tests/behat/completion_condition_allocation.feature @@ -35,7 +35,9 @@ Feature: Set a ratingallocate activity marked as completed when a user has been And I am on the "My Fair Allocation" "mod_ratingallocate > View" page And I run the scheduled task "mod_ratingallocate\task\cron_task" And I press "Publish Allocation" + And I wait "1" seconds And I run the scheduled task "core\task\completion_regular_task" + And I wait "1" seconds And I log out @javascript From 868b46484d7fd7261b1aea1e72061dd4beec5bbf Mon Sep 17 00:00:00 2001 From: Irina Hoppe Date: Mon, 24 Jun 2024 12:20:29 +0200 Subject: [PATCH 22/33] edit ratingtime for behat test to run algorithm --- mod_form.php | 2 +- tests/behat/completion_condition_allocation.feature | 13 +++++++++---- tests/behat/completion_manual.feature | 1 + 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/mod_form.php b/mod_form.php index 077ab6dc..3d0e06b7 100644 --- a/mod_form.php +++ b/mod_form.php @@ -237,7 +237,7 @@ public function definition_after_data() { $data = $this->current; if ($this->is_submitted()) { - $subdata = $this->get_data(); + $subdata = $this->get_submitted_data(); $allstrategyoptions = $subdata->{self::STRATEGY_OPTIONS}; } else if (isset($data->setting)) { $allstrategyoptions = json_decode($data->setting, true); diff --git a/tests/behat/completion_condition_allocation.feature b/tests/behat/completion_condition_allocation.feature index becac7fc..115e2c74 100644 --- a/tests/behat/completion_condition_allocation.feature +++ b/tests/behat/completion_condition_allocation.feature @@ -32,6 +32,13 @@ Feature: Set a ratingallocate activity marked as completed when a user has been | C2 | student1 | 0 | | C2 | student2 | 0 | And I log in as "teacher1" + And I am on the "My Fair Allocation" "mod_ratingallocate > Edit" page + And I set the following fields to these values: + | Rating begins at | ##2 days ago## | + | Rating ends at | ##yesterday## | + | Add requirements | 1 | + | completionallocation_ratingallocate | 1 | + And I press "id_submitbutton" And I am on the "My Fair Allocation" "mod_ratingallocate > View" page And I run the scheduled task "mod_ratingallocate\task\cron_task" And I press "Publish Allocation" @@ -44,7 +51,5 @@ Feature: Set a ratingallocate activity marked as completed when a user has been Scenario: User completes ratingallocate only if they have been allocated When I log in as "teacher1" And I am on "Course 1" course homepage - And I navigate to "Reports" in current page administration - And I click on "Activity completion" "link" - Then "Completed" "icon" should exist in the "Student 1" "table_row" - And "Completed" "icon" should not exist in the "Student 2" "table_row" + Then "Student 1" user has completed "My Fair Allocation" activity + And "Student 2" user has not completed "My Fair Allocation" activity diff --git a/tests/behat/completion_manual.feature b/tests/behat/completion_manual.feature index 31a66cdd..8e14026a 100644 --- a/tests/behat/completion_manual.feature +++ b/tests/behat/completion_manual.feature @@ -32,6 +32,7 @@ Feature: Manually mark a ratingallocate activity as completed And I am on the "My Fair Allocation" "mod_ratingallocate > View" page Then the manual completion button for "My Fair Allocation" should be disabled + @javascript Scenario: Use manual completion student view When I log in as "student1" And I am on the "My Fair Allocation" "mod_ratingallocate > View" page From 1b6008a078633141a09f527ce26c5b3767d138fa Mon Sep 17 00:00:00 2001 From: Irina Hoppe Date: Mon, 24 Jun 2024 12:38:48 +0200 Subject: [PATCH 23/33] change radiobutton name in behattest --- tests/behat/completion_condition_allocation.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/behat/completion_condition_allocation.feature b/tests/behat/completion_condition_allocation.feature index 115e2c74..bc980f2f 100644 --- a/tests/behat/completion_condition_allocation.feature +++ b/tests/behat/completion_condition_allocation.feature @@ -36,7 +36,7 @@ Feature: Set a ratingallocate activity marked as completed when a user has been And I set the following fields to these values: | Rating begins at | ##2 days ago## | | Rating ends at | ##yesterday## | - | Add requirements | 1 | + | id_completion_2 | 2 | | completionallocation_ratingallocate | 1 | And I press "id_submitbutton" And I am on the "My Fair Allocation" "mod_ratingallocate > View" page From e1430a245d9476d4ea47933e8203fb1e25608a92 Mon Sep 17 00:00:00 2001 From: Irina Hoppe Date: Thu, 4 Jul 2024 09:46:13 +0200 Subject: [PATCH 24/33] change fieldnames for ratingtime in behattest --- tests/behat/completion_condition_allocation.feature | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/tests/behat/completion_condition_allocation.feature b/tests/behat/completion_condition_allocation.feature index bc980f2f..ab83b5a1 100644 --- a/tests/behat/completion_condition_allocation.feature +++ b/tests/behat/completion_condition_allocation.feature @@ -19,8 +19,8 @@ Feature: Set a ratingallocate activity marked as completed when a user has been | student1 | C1 | student | | student2 | C1 | student | And the following "activities" exist: - | activity | course | idnumber | name | completion | completionallocation | - | ratingallocate | C1 | ra1 | My Fair Allocation | 2 | 1 | + | activity | course | idnumber | name | completion | completionallocation | accesstimestart | accesstimestop | + | ratingallocate | C1 | ra1 | My Fair Allocation | 2 | 1 | ##2 days ago## | ##yesterday## | And the following choices exist: | title | explanation | maxsize | ratingallocate | | C1 | Test | 1 | My Fair Allocation | @@ -32,13 +32,6 @@ Feature: Set a ratingallocate activity marked as completed when a user has been | C2 | student1 | 0 | | C2 | student2 | 0 | And I log in as "teacher1" - And I am on the "My Fair Allocation" "mod_ratingallocate > Edit" page - And I set the following fields to these values: - | Rating begins at | ##2 days ago## | - | Rating ends at | ##yesterday## | - | id_completion_2 | 2 | - | completionallocation_ratingallocate | 1 | - And I press "id_submitbutton" And I am on the "My Fair Allocation" "mod_ratingallocate > View" page And I run the scheduled task "mod_ratingallocate\task\cron_task" And I press "Publish Allocation" From 8a1cea8c4bf7d7c5f7e19d518e3ea559b3a91ef9 Mon Sep 17 00:00:00 2001 From: Irina Hoppe Date: Tue, 30 Jul 2024 11:16:41 +0200 Subject: [PATCH 25/33] rollback for merging codestyle fixes --- version.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/version.php b/version.php index b122377e..80b1be9d 100644 --- a/version.php +++ b/version.php @@ -25,8 +25,8 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2024060300; // The current module version (Date: YYYYMMDDXX). -$plugin->requires = 2022112800; // Requires Moodle 4.1 and higher. +$plugin->version = 2024011700; // The current module version (Date: YYYYMMDDXX). +$plugin->requires = 2020061500; // Requires Moodle 3.9+. $plugin->maturity = MATURITY_STABLE; $plugin->release = 'v4.4-r1'; $plugin->component = 'mod_ratingallocate'; // To check on upgrade, that module sits in correct place. From 48e2bf495fd102409c5ce341746008a0eb8c0402 Mon Sep 17 00:00:00 2001 From: Irina Hoppe Date: Tue, 30 Jul 2024 11:25:43 +0200 Subject: [PATCH 26/33] codestyle fixes --- classes/completion/custom_completion.php | 6 +++--- lib.php | 1 + locallib.php | 2 +- mod_form.php | 6 ++++++ 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/classes/completion/custom_completion.php b/classes/completion/custom_completion.php index 9e2a35d2..25a129a4 100644 --- a/classes/completion/custom_completion.php +++ b/classes/completion/custom_completion.php @@ -73,7 +73,7 @@ public function get_state(string $rule): int { public static function get_defined_custom_rules(): array { return [ 'completionvote', - 'completionallocation' + 'completionallocation', ]; } @@ -85,7 +85,7 @@ public static function get_defined_custom_rules(): array { public function get_custom_rule_descriptions(): array { return [ 'completionvote' => get_string('completionvote_desc', RATINGALLOCATE_MOD_NAME), - 'completionallocation' => get_string('completionallocation_desc', RATINGALLOCATE_MOD_NAME) + 'completionallocation' => get_string('completionallocation_desc', RATINGALLOCATE_MOD_NAME), ]; } @@ -98,7 +98,7 @@ public function get_sort_order(): array { return [ 'completionview', 'completionvote', - 'completionallocation' + 'completionallocation', ]; } } diff --git a/lib.php b/lib.php index 226f1a5f..dbdcac74 100644 --- a/lib.php +++ b/lib.php @@ -764,6 +764,7 @@ function ratingallocate_reset_course_form_defaults($course) { * @param stdClass $coursemodule The coursemodule object (record). * @return cached_cm_info An object on information that the courses * will know about (most noticeably, an icon). + * @throws dml_exception */ function ratingallocate_get_coursemodule_info($coursemodule) { global $DB; diff --git a/locallib.php b/locallib.php index da5a4942..a7078428 100644 --- a/locallib.php +++ b/locallib.php @@ -187,7 +187,7 @@ class ratingallocate { /** * Returns all users enrolled in the course the ratingallocate is in, who were able to access the activity - * @returns Array of user records + * @return Array of user records * @throws moodle_exception */ public function get_raters_in_course(): array { diff --git a/mod_form.php b/mod_form.php index 3d0e06b7..6c854906 100644 --- a/mod_form.php +++ b/mod_form.php @@ -351,6 +351,12 @@ public function add_completion_rules() { return [$this->get_suffixed_name('vote'), $this->get_suffixed_name('allocation')]; } + /** + * Returns the suffixed name for custom completion elements. + * + * @param string $fieldname + * @return string + */ protected function get_suffixed_name(string $fieldname): string { // Replace _ratingallocate with $this->get_suffix() for Moodle 4.3 or later. return 'completion' . $fieldname . '_ratingallocate'; From 0dc89064156f2924af0978d0ad53a2e99661c2e6 Mon Sep 17 00:00:00 2001 From: Irina Hoppe Date: Tue, 30 Jul 2024 12:02:42 +0200 Subject: [PATCH 27/33] codestyle fixes --- tests/mod_generator_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/mod_generator_test.php b/tests/mod_generator_test.php index 767246de..f3ada301 100644 --- a/tests/mod_generator_test.php +++ b/tests/mod_generator_test.php @@ -75,7 +75,7 @@ public function test_create_instance(): void { 'runalgorithmbycron' => '1', 'completionvote' => '0', 'completionallocation' => '0', - ); + ]; $this->assertEquals(json_decode(json_encode($expectedvaluesdb, false)), reset($records)); // Must have two choices. From f14fc2bd8b52d038c26bac543bcd9da136bbc3e9 Mon Sep 17 00:00:00 2001 From: Irina Hoppe Date: Tue, 30 Jul 2024 13:57:32 +0200 Subject: [PATCH 28/33] replace get_suffix() --- mod_form.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mod_form.php b/mod_form.php index 6c854906..4c854132 100644 --- a/mod_form.php +++ b/mod_form.php @@ -401,7 +401,7 @@ public function data_postprocessing($data) { parent::data_postprocessing($data); // Turn off completion settings if the checkboxes aren't ticked. if (!empty($data->completionunlocked)) { - $completion = $data->{'completion' . $this->get_suffix()}; + $completion = $data->{'completion_ratingallocate'}; $autocompletion = !empty($completion) && $completion == COMPLETION_TRACKING_AUTOMATIC; if (empty($data->{$this->get_suffixed_name('vote')}) || !$autocompletion) { $data->{$this->get_suffixed_name('vote')} = 0; From 5df8598f90b5dcd6cf7a732741841ed74b47d5c4 Mon Sep 17 00:00:00 2001 From: Irina Hoppe Date: Tue, 6 Aug 2024 14:02:50 +0200 Subject: [PATCH 29/33] delete use of _ratingallocate as suffix --- classes/completion/custom_completion.php | 21 +++++++++++++++++---- locallib.php | 7 ------- mod_form.php | 6 +++--- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/classes/completion/custom_completion.php b/classes/completion/custom_completion.php index 25a129a4..6cb164cd 100644 --- a/classes/completion/custom_completion.php +++ b/classes/completion/custom_completion.php @@ -18,6 +18,7 @@ namespace mod_ratingallocate\completion; +use context_module; use core_completion\activity_custom_completion; /** @@ -41,25 +42,37 @@ class custom_completion extends activity_custom_completion { */ public function get_state(string $rule): int { global $DB; - + $status = false; $this->validate_rule($rule); $userid = $this->userid; - $ratingallocateid = $this->cm->instance; + $course = $this->cm->get_course(); + $instance = $this->cm->instance; - if (!$DB->get_record('ratingallocate', ['id' => $ratingallocateid])) { - throw new \moodle_exception('Unable to find ratingallocate instance with id ' . $ratingallocateid); + if (!$ratingallocaterecord= $DB->get_record('ratingallocate', ['id' => $instance])) { + throw new \moodle_exception('Unable to find ratingallocate instance with id ' . $instance); } + $modinfo = get_fast_modinfo($course, $userid)->instances['ratingallocate'][$instance]; + $context = context_module::instance($modinfo->id); + + $ratingallocate = new \ratingallocate($ratingallocaterecord, $course, $this->cm, $context); + if ($rule == 'completionvote') { + $status = count($ratingallocate->get_rating_data_for_user($userid)) > 0; + /* $sql = "SELECT * FROM {ratingallocate_ratings} r INNER JOIN {ratingallocate_choices} c on r.choiceid=c.id " . "WHERE r.userid= :userid AND c.ratingallocateid= :ratingallocateid"; $votesofuser = $DB->get_records_sql($sql, ['userid' => $userid, 'ratingallocateid' => $ratingallocateid]); $status = count($votesofuser) > 0; + */ } else if ($rule == 'completionallocation') { + $status = count($ratingallocate->get_allocations_for_user($userid)) > 0; + /* $sql = "SELECT * FROM {ratingallocate_allocations} WHERE userid= :userid AND ratingallocateid= :ratingallocateid"; $allocationsofuser = $DB->get_records_sql($sql, ['userid' => $userid, 'ratingallocateid' => $ratingallocateid]); $status = count($allocationsofuser) > 0; + */ } return $status ? COMPLETION_COMPLETE : COMPLETION_INCOMPLETE; diff --git a/locallib.php b/locallib.php index a7078428..dea65099 100644 --- a/locallib.php +++ b/locallib.php @@ -750,13 +750,6 @@ private function process_action_manual_allocation() { $completion->update_state($this->coursemodule, COMPLETION_UNKNOWN, $rater->id); } } - $raters = $this->get_raters_in_course(); - $completion = new completion_info($this->course); - if ($completion->is_enabled($this->coursemodule)) { - foreach ($raters as $rater) { - $completion->update_state($this->coursemodule, COMPLETION_UNKNOWN, $rater->id); - } - } } $output .= $OUTPUT->heading(get_string('manual_allocation', RATINGALLOCATE_MOD_NAME), 2); diff --git a/mod_form.php b/mod_form.php index 4c854132..42510f15 100644 --- a/mod_form.php +++ b/mod_form.php @@ -358,8 +358,8 @@ public function add_completion_rules() { * @return string */ protected function get_suffixed_name(string $fieldname): string { - // Replace _ratingallocate with $this->get_suffix() for Moodle 4.3 or later. - return 'completion' . $fieldname . '_ratingallocate'; + // Counterintuitively don't use function get_suffix(), since data isn't saved correctly in DB otherwise. + return 'completion' . $fieldname; } /** @@ -401,7 +401,7 @@ public function data_postprocessing($data) { parent::data_postprocessing($data); // Turn off completion settings if the checkboxes aren't ticked. if (!empty($data->completionunlocked)) { - $completion = $data->{'completion_ratingallocate'}; + $completion = $data->completion; $autocompletion = !empty($completion) && $completion == COMPLETION_TRACKING_AUTOMATIC; if (empty($data->{$this->get_suffixed_name('vote')}) || !$autocompletion) { $data->{$this->get_suffixed_name('vote')} = 0; From e532301f7ef393940fc0382555661992f55d63c1 Mon Sep 17 00:00:00 2001 From: Irina Hoppe Date: Tue, 6 Aug 2024 14:06:39 +0200 Subject: [PATCH 30/33] codestyle fix --- classes/completion/custom_completion.php | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/classes/completion/custom_completion.php b/classes/completion/custom_completion.php index 6cb164cd..554c1210 100644 --- a/classes/completion/custom_completion.php +++ b/classes/completion/custom_completion.php @@ -49,7 +49,7 @@ public function get_state(string $rule): int { $course = $this->cm->get_course(); $instance = $this->cm->instance; - if (!$ratingallocaterecord= $DB->get_record('ratingallocate', ['id' => $instance])) { + if (!$ratingallocaterecord = $DB->get_record('ratingallocate', ['id' => $instance])) { throw new \moodle_exception('Unable to find ratingallocate instance with id ' . $instance); } @@ -60,19 +60,8 @@ public function get_state(string $rule): int { if ($rule == 'completionvote') { $status = count($ratingallocate->get_rating_data_for_user($userid)) > 0; - /* - $sql = "SELECT * FROM {ratingallocate_ratings} r INNER JOIN {ratingallocate_choices} c on r.choiceid=c.id " . - "WHERE r.userid= :userid AND c.ratingallocateid= :ratingallocateid"; - $votesofuser = $DB->get_records_sql($sql, ['userid' => $userid, 'ratingallocateid' => $ratingallocateid]); - $status = count($votesofuser) > 0; - */ } else if ($rule == 'completionallocation') { $status = count($ratingallocate->get_allocations_for_user($userid)) > 0; - /* - $sql = "SELECT * FROM {ratingallocate_allocations} WHERE userid= :userid AND ratingallocateid= :ratingallocateid"; - $allocationsofuser = $DB->get_records_sql($sql, ['userid' => $userid, 'ratingallocateid' => $ratingallocateid]); - $status = count($allocationsofuser) > 0; - */ } return $status ? COMPLETION_COMPLETE : COMPLETION_INCOMPLETE; From 289fb8976c93de621bbcf7296a825d9af4c0d9e2 Mon Sep 17 00:00:00 2001 From: Irina Hoppe Date: Fri, 9 Aug 2024 11:12:13 +0200 Subject: [PATCH 31/33] fix computation of completionstatus for user --- classes/completion/custom_completion.php | 18 +++++++++--------- lib.php | 2 -- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/classes/completion/custom_completion.php b/classes/completion/custom_completion.php index 554c1210..e477c750 100644 --- a/classes/completion/custom_completion.php +++ b/classes/completion/custom_completion.php @@ -46,22 +46,22 @@ public function get_state(string $rule): int { $this->validate_rule($rule); $userid = $this->userid; - $course = $this->cm->get_course(); $instance = $this->cm->instance; - if (!$ratingallocaterecord = $DB->get_record('ratingallocate', ['id' => $instance])) { + if (!$DB->get_record('ratingallocate', ['id' => $instance])) { throw new \moodle_exception('Unable to find ratingallocate instance with id ' . $instance); } - $modinfo = get_fast_modinfo($course, $userid)->instances['ratingallocate'][$instance]; - $context = context_module::instance($modinfo->id); - - $ratingallocate = new \ratingallocate($ratingallocaterecord, $course, $this->cm, $context); - if ($rule == 'completionvote') { - $status = count($ratingallocate->get_rating_data_for_user($userid)) > 0; + $sql = "SELECT * FROM {ratingallocate_ratings} r INNER JOIN {ratingallocate_choices} c on r.choiceid=c.id " . + "WHERE r.userid= :userid AND c.ratingallocateid= :ratingallocateid AND c.active=1"; + $votesofuser = $DB->get_records_sql($sql, ['userid' => $userid, 'ratingallocateid' => $instance]); + $status = count($votesofuser) > 0; } else if ($rule == 'completionallocation') { - $status = count($ratingallocate->get_allocations_for_user($userid)) > 0; + $sql = "SELECT * FROM {ratingallocate_allocations} a INNER JOIN {ratingallocate_choices} c + ON a.choiceid = c.id WHERE userid= :userid AND a.ratingallocateid= :ratingallocateid AND c.active=1"; + $allocationsofuser = $DB->get_records_sql($sql, ['userid' => $userid, 'ratingallocateid' => $instance]); + $status = count($allocationsofuser) > 0; } return $status ? COMPLETION_COMPLETE : COMPLETION_INCOMPLETE; diff --git a/lib.php b/lib.php index dbdcac74..6f8a56ea 100644 --- a/lib.php +++ b/lib.php @@ -72,8 +72,6 @@ function ratingallocate_supports($feature) { return true; case FEATURE_COMPLETION_HAS_RULES: return true; - case FEATURE_COMPLETION_HAS_RULES: - return true; default : return null; } From e2db7f317873aef67c74382b9b119ba3e894f5cc Mon Sep 17 00:00:00 2001 From: Irina Hoppe Date: Fri, 9 Aug 2024 14:39:24 +0200 Subject: [PATCH 32/33] change required moodle version --- db/upgrade.php | 4 ++-- version.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/db/upgrade.php b/db/upgrade.php index e70e240e..777594ca 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -218,7 +218,7 @@ function xmldb_ratingallocate_upgrade($oldversion) { upgrade_mod_savepoint(true, 2023050900, 'ratingallocate'); } - if ($oldversion < 2024011700) { + if ($oldversion < 2024080900) { // Define completionrules fields to be added to ratingallocate. $table = new xmldb_table('ratingallocate'); @@ -234,7 +234,7 @@ function xmldb_ratingallocate_upgrade($oldversion) { } // Ratingallocate savepoint reached. - upgrade_mod_savepoint(true, 2024011700, 'ratingallocate'); + upgrade_mod_savepoint(true, 2024080900, 'ratingallocate'); } return true; diff --git a/version.php b/version.php index 80b1be9d..bf60a6cc 100644 --- a/version.php +++ b/version.php @@ -25,8 +25,8 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2024011700; // The current module version (Date: YYYYMMDDXX). -$plugin->requires = 2020061500; // Requires Moodle 3.9+. +$plugin->version = 2024080900; // The current module version (Date: YYYYMMDDXX). +$plugin->requires = 2022112800; // Requires Moodle 4.1 and higher. $plugin->maturity = MATURITY_STABLE; $plugin->release = 'v4.4-r1'; $plugin->component = 'mod_ratingallocate'; // To check on upgrade, that module sits in correct place. From 0f04901a308371ba67a514887db56ac45a7a6ed4 Mon Sep 17 00:00:00 2001 From: Laur0r Date: Mon, 26 Aug 2024 14:24:21 +0200 Subject: [PATCH 33/33] Use latest version of moodle-plugin-ci to fix Node.js bug --- .github/workflows/moodle-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/moodle-ci.yml b/.github/workflows/moodle-ci.yml index 6903de17..0747b0af 100644 --- a/.github/workflows/moodle-ci.yml +++ b/.github/workflows/moodle-ci.yml @@ -128,7 +128,7 @@ jobs: - name: Initialise moodle-plugin-ci run: | - composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^3 + composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^4 echo $(cd ci/bin; pwd) >> $GITHUB_PATH echo $(cd ci/vendor/bin; pwd) >> $GITHUB_PATH sudo locale-gen en_AU.UTF-8