diff --git a/backup/moodle2/backup_ratingallocate_activity_stepslib.php b/backup/moodle2/backup_ratingallocate_activity_stepslib.php index 46377498..e8f5440e 100644 --- a/backup/moodle2/backup_ratingallocate_activity_stepslib.php +++ b/backup/moodle2/backup_ratingallocate_activity_stepslib.php @@ -36,7 +36,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class backup_ratingallocate_activity_structure_step extends backup_activity_structure_step { - /** * Define the complete ratingallocate structure for backup. * @return backup_nested_element @@ -51,41 +50,59 @@ protected function define_structure() { // Define each element separated. $class = 'mod_ratingallocate\db\ratingallocate'; - $ratingallocate = new backup_nested_element(get_tablename_for_tableClass($class), get_id_for_tableClass($class), - get_fields_for_tableClass($class)); + $ratingallocate = new backup_nested_element( + get_tablename_for_tableClass($class), + get_id_for_tableClass($class), + get_fields_for_tableClass($class) + ); $class = 'mod_ratingallocate\db\ratingallocate_choices'; $ratingallocatechoices = new backup_nested_element(get_tablename_for_tableClass($class) . 's'); - $ratingallocatechoice = new backup_nested_element(get_tablename_for_tableClass($class), get_id_for_tableClass($class), - get_fields_for_tableClass($class)); + $ratingallocatechoice = new backup_nested_element( + get_tablename_for_tableClass($class), + get_id_for_tableClass($class), + get_fields_for_tableClass($class) + ); $class = 'mod_ratingallocate\db\ratingallocate_ratings'; $ratingallocateratings = new backup_nested_element(get_tablename_for_tableClass($class) . 's'); - $ratingallocaterating = new backup_nested_element(get_tablename_for_tableClass($class), get_id_for_tableClass($class), - get_fields_for_tableClass($class)); + $ratingallocaterating = new backup_nested_element( + get_tablename_for_tableClass($class), + get_id_for_tableClass($class), + get_fields_for_tableClass($class) + ); $class = 'mod_ratingallocate\db\ratingallocate_allocations'; $ratingallocateallocations = new backup_nested_element(get_tablename_for_tableClass($class) . 's'); - $ratingallocateallocation = new backup_nested_element(get_tablename_for_tableClass($class), get_id_for_tableClass($class), - get_fields_for_tableClass($class)); + $ratingallocateallocation = new backup_nested_element( + get_tablename_for_tableClass($class), + get_id_for_tableClass($class), + get_fields_for_tableClass($class) + ); $groupchoiceclass = 'mod_ratingallocate\db\ratingallocate_group_choices'; $groupchoices = new backup_nested_element(get_tablename_for_tableClass($groupchoiceclass) . 's'); - $groupchoice = new backup_nested_element(get_tablename_for_tableClass($groupchoiceclass), + $groupchoice = new backup_nested_element( + get_tablename_for_tableClass($groupchoiceclass), get_id_for_tableClass($groupchoiceclass), - get_fields_for_tableClass($groupchoiceclass)); + get_fields_for_tableClass($groupchoiceclass) + ); $choicegroupclass = 'mod_ratingallocate\db\ratingallocate_ch_gengroups'; $ratingallocatechoicegroups = new backup_nested_element(get_tablename_for_tableClass($choicegroupclass) . 's'); - $ratingallocatechoicegroup = new backup_nested_element(get_tablename_for_tableClass($choicegroupclass), - get_id_for_tableClass($choicegroupclass), - get_fields_for_tableClass($choicegroupclass)); + $ratingallocatechoicegroup = new backup_nested_element( + get_tablename_for_tableClass($choicegroupclass), + get_id_for_tableClass($choicegroupclass), + get_fields_for_tableClass($choicegroupclass) + ); $groupingclass = 'mod_ratingallocate\db\ratingallocate_groupings'; $ratingallocategroupings = new backup_nested_element(get_tablename_for_tableClass($groupingclass) . 's'); - $ratingallocategrouping = new backup_nested_element(get_tablename_for_tableClass($groupingclass), - get_id_for_tableClass($groupingclass), - get_fields_for_tableClass($groupingclass)); + $ratingallocategrouping = new backup_nested_element( + get_tablename_for_tableClass($groupingclass), + get_id_for_tableClass($groupingclass), + get_fields_for_tableClass($groupingclass) + ); // Build the tree. $ratingallocate->add_child($ratingallocatechoices); @@ -107,29 +124,41 @@ protected function define_structure() { $ratingallocatechoicegroups->add_child($ratingallocatechoicegroup); // Define sources. - $ratingallocate->set_source_table(get_tablename_for_tableClass('mod_ratingallocate\db\ratingallocate'), - [this_db\ratingallocate::ID => backup::VAR_ACTIVITYID], this_db\ratingallocate_choices::ID . ' ASC'); - $ratingallocatechoice->set_source_table(get_tablename_for_tableClass('mod_ratingallocate\db\ratingallocate_choices'), - [this_db\ratingallocate_choices::RATINGALLOCATEID => backup::VAR_PARENTID], - this_db\ratingallocate_choices::ID . ' ASC'); + $ratingallocate->set_source_table( + get_tablename_for_tableClass('mod_ratingallocate\db\ratingallocate'), + [this_db\ratingallocate::ID => backup::VAR_ACTIVITYID], + this_db\ratingallocate_choices::ID . ' ASC' + ); + $ratingallocatechoice->set_source_table( + get_tablename_for_tableClass('mod_ratingallocate\db\ratingallocate_choices'), + [this_db\ratingallocate_choices::RATINGALLOCATEID => backup::VAR_PARENTID], + this_db\ratingallocate_choices::ID . ' ASC' + ); $groupchoice->set_source_table(get_tablename_for_tableClass($groupchoiceclass), ['choiceid' => backup::VAR_PARENTID]); $ratingallocatechoicegroup->set_source_table( - get_tablename_for_tableClass($choicegroupclass), ['choiceid' => backup::VAR_PARENTID]); + get_tablename_for_tableClass($choicegroupclass), + ['choiceid' => backup::VAR_PARENTID] + ); $ratingallocategrouping->set_source_table( - get_tablename_for_tableClass($groupingclass), ['ratingallocateid' => backup::VAR_PARENTID]); + get_tablename_for_tableClass($groupingclass), + ['ratingallocateid' => backup::VAR_PARENTID] + ); if ($userinfo) { - $ratingallocaterating->set_source_table(get_tablename_for_tableClass( - 'mod_ratingallocate\db\ratingallocate_ratings'), - [this_db\ratingallocate_ratings::CHOICEID => backup::VAR_PARENTID], - this_db\ratingallocate_ratings::ID . ' ASC'); + $ratingallocaterating->set_source_table( + get_tablename_for_tableClass( + 'mod_ratingallocate\db\ratingallocate_ratings' + ), + [this_db\ratingallocate_ratings::CHOICEID => backup::VAR_PARENTID], + this_db\ratingallocate_ratings::ID . ' ASC' + ); $ratingallocateallocation->set_source_table( - get_tablename_for_tableClass('mod_ratingallocate\db\ratingallocate_allocations'), - [ + get_tablename_for_tableClass('mod_ratingallocate\db\ratingallocate_allocations'), + [ this_db\ratingallocate_allocations::RATINGALLOCATEID => backup::VAR_ACTIVITYID, this_db\ratingallocate_allocations::CHOICEID => backup::VAR_PARENTID, ], - this_db\ratingallocate_allocations::ID . ' ASC' + this_db\ratingallocate_allocations::ID . ' ASC' ); } diff --git a/backup/moodle2/backup_ratingallocate_activity_task.class.php b/backup/moodle2/backup_ratingallocate_activity_task.class.php index d6693bf5..e8e7d7b8 100644 --- a/backup/moodle2/backup_ratingallocate_activity_task.class.php +++ b/backup/moodle2/backup_ratingallocate_activity_task.class.php @@ -29,7 +29,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class backup_ratingallocate_activity_task extends backup_activity_task { - /** * Define (add) particular settings this activity can have */ diff --git a/backup/moodle2/restore_ratingallocate_activity_stepslib.php b/backup/moodle2/restore_ratingallocate_activity_stepslib.php index 463c6e25..ee989e0a 100644 --- a/backup/moodle2/restore_ratingallocate_activity_stepslib.php +++ b/backup/moodle2/restore_ratingallocate_activity_stepslib.php @@ -24,7 +24,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class restore_ratingallocate_activity_structure_step extends restore_activity_structure_step { - /** * Define the complete ratingallocate structure for restore. * @return mixed @@ -39,18 +38,28 @@ protected function define_structure() { $choicespath = $ratingallocatepath . '/' . this_db\ratingallocate_choices::TABLE . 's/' . this_db\ratingallocate_choices::TABLE; $paths[] = new restore_path_element(this_db\ratingallocate_choices::TABLE, $choicespath); - $paths[] = new restore_path_element(this_db\ratingallocate_group_choices::TABLE, - $choicespath .'/' . this_db\ratingallocate_group_choices::TABLE .'s/' . this_db\ratingallocate_group_choices::TABLE); - $paths[] = new restore_path_element(this_db\ratingallocate_ch_gengroups::TABLE, - $choicespath .'/'. this_db\ratingallocate_ch_gengroups::TABLE . 's/' . this_db\ratingallocate_ch_gengroups::TABLE); - $paths[] = new restore_path_element(this_db\ratingallocate_groupings::TABLE, - $ratingallocatepath . '/' . this_db\ratingallocate_groupings::TABLE . 's/' . this_db\ratingallocate_groupings::TABLE); + $paths[] = new restore_path_element( + this_db\ratingallocate_group_choices::TABLE, + $choicespath . '/' . this_db\ratingallocate_group_choices::TABLE . 's/' . this_db\ratingallocate_group_choices::TABLE + ); + $paths[] = new restore_path_element( + this_db\ratingallocate_ch_gengroups::TABLE, + $choicespath . '/' . this_db\ratingallocate_ch_gengroups::TABLE . 's/' . this_db\ratingallocate_ch_gengroups::TABLE + ); + $paths[] = new restore_path_element( + this_db\ratingallocate_groupings::TABLE, + $ratingallocatepath . '/' . this_db\ratingallocate_groupings::TABLE . 's/' . this_db\ratingallocate_groupings::TABLE + ); if ($userinfo) { - $paths[] = new restore_path_element(this_db\ratingallocate_ratings::TABLE, - $choicespath . '/' . this_db\ratingallocate_ratings::TABLE . 's/' . this_db\ratingallocate_ratings::TABLE); - $paths[] = new restore_path_element(this_db\ratingallocate_allocations::TABLE, - $choicespath . '/' . this_db\ratingallocate_allocations::TABLE . 's/' . - this_db\ratingallocate_allocations::TABLE); + $paths[] = new restore_path_element( + this_db\ratingallocate_ratings::TABLE, + $choicespath . '/' . this_db\ratingallocate_ratings::TABLE . 's/' . this_db\ratingallocate_ratings::TABLE + ); + $paths[] = new restore_path_element( + this_db\ratingallocate_allocations::TABLE, + $choicespath . '/' . this_db\ratingallocate_allocations::TABLE . 's/' . + this_db\ratingallocate_allocations::TABLE + ); } // Return the paths wrapped into standard activity structure. diff --git a/backup/moodle2/restore_ratingallocate_activity_task.class.php b/backup/moodle2/restore_ratingallocate_activity_task.class.php index 879431fa..40eb42e3 100644 --- a/backup/moodle2/restore_ratingallocate_activity_task.class.php +++ b/backup/moodle2/restore_ratingallocate_activity_task.class.php @@ -35,7 +35,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class restore_ratingallocate_activity_task extends restore_activity_task { - /** * Define (add) particular settings this activity can have */ diff --git a/classes/allocations_table.php b/classes/allocations_table.php index 7e628230..877d8bc8 100644 --- a/classes/allocations_table.php +++ b/classes/allocations_table.php @@ -35,7 +35,6 @@ * @package mod_ratingallocate */ class allocations_table extends \table_sql { - /** * @var ratingallocate */ @@ -95,8 +94,10 @@ public function setup_table() { $headers[] = get_string('firstname'); $columns[] = 'lastname'; $headers[] = get_string('lastname'); - if (in_array('email', $additionalfields) && - has_capability('moodle/course:useremail', $this->ratingallocate->get_context())) { + if ( + in_array('email', $additionalfields) && + has_capability('moodle/course:useremail', $this->ratingallocate->get_context()) + ) { $columns[] = 'email'; $headers[] = get_string('email'); } @@ -128,7 +129,7 @@ public function build_table_by_sql() { $data = $this->rawdata; // Retrieve all users, who rated within the course. - $userwithratingids = array_map(function($x) { + $userwithratingids = array_map(function ($x) { return $x->userid; }, $this->ratingallocate->get_users_with_ratings()); @@ -175,8 +176,9 @@ public function build_table_by_sql() { if (count($userwithrating) > 0 && ($this->currpage + 1) * $this->pagesize >= $this->totalrows) { $noallocation = new \stdClass(); $noallocation->choicetitle = get_string( - 'allocations_table_noallocation', - RATINGALLOCATE_MOD_NAME); + 'allocations_table_noallocation', + RATINGALLOCATE_MOD_NAME + ); foreach ($userwithrating as $userid => $user) { if (object_property_exists($noallocation, 'users')) { @@ -210,8 +212,10 @@ private function get_user_link($user) { if ($COURSE->id == SITEID) { $profileurl = new \moodle_url('/user/profile.php', ['id' => $user->id]); } else { - $profileurl = new \moodle_url('/user/view.php', - ['id' => $user->id, 'course' => $COURSE->id]); + $profileurl = new \moodle_url( + '/user/view.php', + ['id' => $user->id, 'course' => $COURSE->id] + ); } return \html_writer::link($profileurl, $name); } @@ -241,5 +245,4 @@ public function init_sql() { $this->query_db(20); } - } diff --git a/classes/choice/ratingallocate_choice.php b/classes/choice/ratingallocate_choice.php index 3939e9fc..4fab4917 100644 --- a/classes/choice/ratingallocate_choice.php +++ b/classes/choice/ratingallocate_choice.php @@ -67,5 +67,4 @@ public function __set($name, $value) { public function __construct($record) { $this->dbrecord = $record; } - } diff --git a/classes/choice_importer.php b/classes/choice_importer.php index 755dabc6..80cf648d 100644 --- a/classes/choice_importer.php +++ b/classes/choice_importer.php @@ -76,7 +76,7 @@ class choice_importer { * @param array $fields * @return void */ - public static function print_fields($fields=self::REQUIRED_FIELDS) { + public static function print_fields($fields = self::REQUIRED_FIELDS) { return '[' . join(', ', $fields) . ']'; } @@ -137,12 +137,12 @@ public function free_reader() { * - rowcount: The number of being row processed. (Once finished, should add up to readcount.) * - importcount: The number of rows successfully processed. */ - public function import($content, $live=true) { + public function import($content, $live = true) { global $DB; $reader = $this->get_reader(); - $importstatus = new \stdClass; + $importstatus = new \stdClass(); $importstatus->status = self::IMPORT_STATUS_OK; // Unless we hear otherwise. $importstatus->live = $live; // Only commit live transactions. $importstatus->errors = []; @@ -169,8 +169,11 @@ public function import($content, $live=true) { $missingfields = array_diff(self::REQUIRED_FIELDS, $fieldnames); if ($missingfields) { $importstatus->status = self::IMPORT_STATUS_SETUP_ERROR; - $importstatus->errors[] = get_string('csvupload_missing_fields', 'ratingallocate', - self::print_fields($missingfields)); + $importstatus->errors[] = get_string( + 'csvupload_missing_fields', + 'ratingallocate', + self::print_fields($missingfields) + ); return $importstatus; } @@ -181,7 +184,6 @@ public function import($content, $live=true) { // Start DB transaction. $transaction = $this->ratingallocate->db->start_delegated_transaction(); try { - $reader->init(); while ($record = $reader->next()) { $importstatus->rowcount++; @@ -200,8 +202,11 @@ public function import($content, $live=true) { if ($fieldname === 'title' && mb_strlen($cell, 'UTF-8') > 255) { $importstatus->status = self::IMPORT_STATUS_DATA_ERROR; - $importstatus->errors[] = get_string('csvupload_too_long_title', - RATINGALLOCATE_MOD_NAME, $cell); + $importstatus->errors[] = get_string( + 'csvupload_too_long_title', + RATINGALLOCATE_MOD_NAME, + $cell + ); $ischoiceimportable = false; } @@ -275,13 +280,11 @@ public function import($content, $live=true) { $transaction->allow_commit(); } $transaction->dispose(); - } catch (\Exception $e) { if (isset($transaction)) { $transaction->rollback($e); } } - } } @@ -296,11 +299,15 @@ public function import($content, $live=true) { } } else { if ($live) { - $importstatus->status_message = get_string('csvupload_live_problems', 'ratingallocate', + $importstatus->status_message = get_string( + 'csvupload_live_problems', + 'ratingallocate', count($importstatus->errors) ); } else { - $importstatus->status_message = get_string('csvupload_test_problems', 'ratingallocate', + $importstatus->status_message = get_string( + 'csvupload_test_problems', + 'ratingallocate', count($importstatus->errors) ); } @@ -321,9 +328,10 @@ public function import($content, $live=true) { * @param int $max Maximum number of individual notifications to send. * @return void */ - public function issue_notifications($errors, - $notificationtype=\core\output\notification::NOTIFY_WARNING, - $max=self::MAX_WARNING_COUNT + public function issue_notifications( + $errors, + $notificationtype = \core\output\notification::NOTIFY_WARNING, + $max = self::MAX_WARNING_COUNT ) { $errorcount = count($errors); diff --git a/classes/completion/custom_completion.php b/classes/completion/custom_completion.php index e477c750..0d47730d 100644 --- a/classes/completion/custom_completion.php +++ b/classes/completion/custom_completion.php @@ -32,7 +32,6 @@ * @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. * @@ -104,4 +103,3 @@ public function get_sort_order(): array { ]; } } - diff --git a/classes/event/all_ratings_deleted.php b/classes/event/all_ratings_deleted.php index dd356c79..fb020a15 100644 --- a/classes/event/all_ratings_deleted.php +++ b/classes/event/all_ratings_deleted.php @@ -30,7 +30,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later **/ class all_ratings_deleted extends \core\event\base { - /** * Create simple all_ratings_deleted event. * @@ -68,8 +67,11 @@ public static function get_name() { * @throws \coding_exception */ public function get_description() { - return get_string('log_all_ratings_deleted_description', 'mod_ratingallocate', - ['userid' => $this->userid, 'ratingallocateid' => $this->objectid]); + return get_string( + 'log_all_ratings_deleted_description', + 'mod_ratingallocate', + ['userid' => $this->userid, 'ratingallocateid' => $this->objectid] + ); } /** diff --git a/classes/event/allocation_published.php b/classes/event/allocation_published.php index aa8399a3..563ae448 100644 --- a/classes/event/allocation_published.php +++ b/classes/event/allocation_published.php @@ -38,7 +38,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later **/ class allocation_published extends \core\event\base { - /** * Create simple allocation_published event. * @@ -76,8 +75,11 @@ public static function get_name() { * @throws \coding_exception */ public function get_description() { - return get_string('log_allocation_published_description', 'mod_ratingallocate', - ['userid' => $this->userid, 'ratingallocateid' => $this->objectid]); + return get_string( + 'log_allocation_published_description', + 'mod_ratingallocate', + ['userid' => $this->userid, 'ratingallocateid' => $this->objectid] + ); } /** diff --git a/classes/event/allocation_statistics_viewed.php b/classes/event/allocation_statistics_viewed.php index 30f52c0e..a2e21863 100644 --- a/classes/event/allocation_statistics_viewed.php +++ b/classes/event/allocation_statistics_viewed.php @@ -32,7 +32,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later **/ class allocation_statistics_viewed extends \core\event\base { - /** * Create simple allocation_statistics_viewed event. * @@ -70,8 +69,11 @@ public static function get_name() { * @throws \coding_exception */ public function get_description() { - return get_string('log_allocation_statistics_viewed_description', 'mod_ratingallocate', - ['userid' => $this->userid, 'ratingallocateid' => $this->objectid]); + return get_string( + 'log_allocation_statistics_viewed_description', + 'mod_ratingallocate', + ['userid' => $this->userid, 'ratingallocateid' => $this->objectid] + ); } /** diff --git a/classes/event/allocation_table_viewed.php b/classes/event/allocation_table_viewed.php index 1ce5214d..4a5aeb85 100644 --- a/classes/event/allocation_table_viewed.php +++ b/classes/event/allocation_table_viewed.php @@ -32,7 +32,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later **/ class allocation_table_viewed extends \core\event\base { - /** * Create simple allocation_table_viewed event. * @@ -70,8 +69,11 @@ public static function get_name() { * @throws \coding_exception */ public function get_description() { - return get_string('log_allocation_table_viewed_description', 'mod_ratingallocate', - ['userid' => $this->userid, 'ratingallocateid' => $this->objectid]); + return get_string( + 'log_allocation_table_viewed_description', + 'mod_ratingallocate', + ['userid' => $this->userid, 'ratingallocateid' => $this->objectid] + ); } /** diff --git a/classes/event/distribution_triggered.php b/classes/event/distribution_triggered.php index ea93b278..fe6405b1 100644 --- a/classes/event/distribution_triggered.php +++ b/classes/event/distribution_triggered.php @@ -39,7 +39,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later **/ class distribution_triggered extends \core\event\base { - /** * Create simple distribution_triggered event. * @@ -80,10 +79,13 @@ public static function get_name() { * @throws \coding_exception */ public function get_description() { - return get_string('log_distribution_triggered_description', 'mod_ratingallocate', - ['userid' => $this->userid, + return get_string( + 'log_distribution_triggered_description', + 'mod_ratingallocate', + ['userid' => $this->userid, 'ratingallocateid' => $this->objectid, - 'time_needed' => $this->other['time_needed']]); + 'time_needed' => $this->other['time_needed']] + ); } /** diff --git a/classes/event/index_viewed.php b/classes/event/index_viewed.php index 1d2c1a41..91bbcebb 100644 --- a/classes/event/index_viewed.php +++ b/classes/event/index_viewed.php @@ -31,7 +31,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later **/ class index_viewed extends \core\event\base { - /** * Create simple index_viewed event. * diff --git a/classes/event/manual_allocation_saved.php b/classes/event/manual_allocation_saved.php index e1a19946..eb397312 100644 --- a/classes/event/manual_allocation_saved.php +++ b/classes/event/manual_allocation_saved.php @@ -38,7 +38,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later **/ class manual_allocation_saved extends \core\event\base { - /** * Create simple manual_allocation_saved event. * @@ -76,8 +75,11 @@ public static function get_name() { * @throws \coding_exception */ public function get_description() { - return get_string('log_manual_allocation_saved_description', 'mod_ratingallocate', - ['userid' => $this->userid, 'ratingallocateid' => $this->objectid]); + return get_string( + 'log_manual_allocation_saved_description', + 'mod_ratingallocate', + ['userid' => $this->userid, 'ratingallocateid' => $this->objectid] + ); } /** diff --git a/classes/event/rating_deleted.php b/classes/event/rating_deleted.php index 9cac90ff..75147bfe 100644 --- a/classes/event/rating_deleted.php +++ b/classes/event/rating_deleted.php @@ -31,7 +31,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later **/ class rating_deleted extends \core\event\base { - /** * Create simple rating_deleted event. * @@ -69,8 +68,11 @@ public static function get_name() { * @throws \coding_exception */ public function get_description() { - return get_string('log_rating_deleted_description', 'mod_ratingallocate', - ['userid' => $this->userid, 'ratingallocateid' => $this->objectid]); + return get_string( + 'log_rating_deleted_description', + 'mod_ratingallocate', + ['userid' => $this->userid, 'ratingallocateid' => $this->objectid] + ); } /** diff --git a/classes/event/rating_saved.php b/classes/event/rating_saved.php index 700dfa55..7e4ad040 100644 --- a/classes/event/rating_saved.php +++ b/classes/event/rating_saved.php @@ -38,7 +38,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later **/ class rating_saved extends \core\event\base { - /** * Create simple rating_saved event. * @param \stdClass $modulecontext @@ -81,8 +80,11 @@ public static function get_name() { * @throws \coding_exception */ public function get_description() { - return get_string('log_rating_saved_description', 'mod_ratingallocate', - ['userid' => $this->userid, 'ratingallocateid' => $this->objectid]); + return get_string( + 'log_rating_saved_description', + 'mod_ratingallocate', + ['userid' => $this->userid, 'ratingallocateid' => $this->objectid] + ); } /** diff --git a/classes/event/rating_viewed.php b/classes/event/rating_viewed.php index 59aec605..4081753e 100644 --- a/classes/event/rating_viewed.php +++ b/classes/event/rating_viewed.php @@ -32,7 +32,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later **/ class rating_viewed extends \core\event\base { - /** * Create simple rating_viewed event. * @@ -70,8 +69,11 @@ public static function get_name() { * @throws \coding_exception */ public function get_description() { - return get_string('log_rating_viewed_description', 'mod_ratingallocate', - ['userid' => $this->userid, 'ratingallocateid' => $this->objectid]); + return get_string( + 'log_rating_viewed_description', + 'mod_ratingallocate', + ['userid' => $this->userid, 'ratingallocateid' => $this->objectid] + ); } /** diff --git a/classes/event/ratingallocate_viewed.php b/classes/event/ratingallocate_viewed.php index 29edb172..3e0c157e 100644 --- a/classes/event/ratingallocate_viewed.php +++ b/classes/event/ratingallocate_viewed.php @@ -32,7 +32,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later **/ class ratingallocate_viewed extends \core\event\base { - /** * Create simple ratingallocate_viewed event. * @@ -70,8 +69,11 @@ public static function get_name() { * @throws \coding_exception */ public function get_description() { - return get_string('log_ratingallocate_viewed_description', 'mod_ratingallocate', - ['userid' => $this->userid, 'ratingallocateid' => $this->objectid]); + return get_string( + 'log_ratingallocate_viewed_description', + 'mod_ratingallocate', + ['userid' => $this->userid, 'ratingallocateid' => $this->objectid] + ); } /** diff --git a/classes/event/ratings_and_allocation_table_viewed.php b/classes/event/ratings_and_allocation_table_viewed.php index 7c499e31..262fff3e 100644 --- a/classes/event/ratings_and_allocation_table_viewed.php +++ b/classes/event/ratings_and_allocation_table_viewed.php @@ -33,7 +33,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later **/ class ratings_and_allocation_table_viewed extends \core\event\base { - /** * Create simple ratings_and_allocation_table_viewed event. * @@ -71,8 +70,11 @@ public static function get_name() { * @throws \coding_exception */ public function get_description() { - return get_string('log_ratings_and_allocation_table_viewed_description', 'mod_ratingallocate', - ['userid' => $this->userid, 'ratingallocateid' => $this->objectid]); + return get_string( + 'log_ratings_and_allocation_table_viewed_description', + 'mod_ratingallocate', + ['userid' => $this->userid, 'ratingallocateid' => $this->objectid] + ); } /** diff --git a/classes/manager/strategymanager.php b/classes/manager/strategymanager.php index 53a16b44..85296d08 100644 --- a/classes/manager/strategymanager.php +++ b/classes/manager/strategymanager.php @@ -27,7 +27,6 @@ * Simulate a static/singleton class that holds all the strategies that registered with him */ class strategymanager { - /** @var array of string-identifier of all registered strategies */ private static $strategies = []; @@ -46,5 +45,4 @@ public static function add_strategy($strategyname) { public static function get_strategies() { return self::$strategies; } - } diff --git a/classes/privacy/provider.php b/classes/privacy/provider.php index 579e06cf..c36753eb 100644 --- a/classes/privacy/provider.php +++ b/classes/privacy/provider.php @@ -40,15 +40,14 @@ */ class provider implements // This plugin stores personal data. - \core_privacy\local\metadata\provider, + \core_privacy\local\metadata\provider, // This plugin is capable of determining which users have data within it. - \core_privacy\local\request\core_userlist_provider, + \core_privacy\local\request\core_userlist_provider, // This plugin is a core_user_data_provider. - \core_privacy\local\request\plugin\provider, - \core_privacy\local\request\user_preference_provider { - + \core_privacy\local\request\plugin\provider, + \core_privacy\local\request\user_preference_provider { /** * Return the fields which contain personal data. * @@ -57,12 +56,15 @@ class provider implements * @return collection the updated collection of metadata items. */ public static function get_metadata(collection $items): collection { - $items->add_database_table('ratingallocate_ratings', [ + $items->add_database_table( + 'ratingallocate_ratings', + [ 'choiceid' => 'privacy:metadata:ratingallocate_ratings:choiceid', 'userid' => 'privacy:metadata:ratingallocate_ratings:userid', 'rating' => 'privacy:metadata:ratingallocate_ratings:rating', - ], - 'privacy:metadata:ratingallocate_ratings'); + ], + 'privacy:metadata:ratingallocate_ratings' + ); $items->add_database_table('ratingallocate_allocations', [ 'userid' => 'privacy:metadata:ratingallocate_allocations:userid', @@ -70,10 +72,14 @@ public static function get_metadata(collection $items): collection { 'choiceid' => 'privacy:metadata:ratingallocate_allocations:choiceid', ], 'privacy:metadata:ratingallocate_allocations'); - $items->add_user_preference('flextable_mod_ratingallocate_table_filter', - 'privacy:metadata:preference:flextable_filter'); - $items->add_user_preference('flextable_mod_ratingallocate_manual_allocation_filter', - 'privacy:metadata:preference:flextable_manual_filter'); + $items->add_user_preference( + 'flextable_mod_ratingallocate_table_filter', + 'privacy:metadata:preference:flextable_filter' + ); + $items->add_user_preference( + 'flextable_mod_ratingallocate_manual_allocation_filter', + 'privacy:metadata:preference:flextable_manual_filter' + ); return $items; } @@ -123,7 +129,7 @@ public static function export_user_data(approved_contextlist $contextlist) { $user = $contextlist->get_user(); - list($contextsql, $contextparams) = $DB->get_in_or_equal($contextlist->get_contextids(), SQL_PARAMS_NAMED); + [$contextsql, $contextparams] = $DB->get_in_or_equal($contextlist->get_contextids(), SQL_PARAMS_NAMED); // Export choices and ratings. $sql = "SELECT cm.id AS cmid, @@ -222,15 +228,23 @@ public static function export_user_preferences(int $userid) { $filtertable = get_user_preferences('flextable_mod_ratingallocate_table_filter', null, $userid); if (null !== $filtertable) { $filtertabledesc = get_string('filtertabledesc', 'mod_ratingallocate'); - writer::export_user_preference('mod_ratingallocate', - 'flextable_mod_ratingallocate_table_filter', $filtertable, $filtertabledesc); + writer::export_user_preference( + 'mod_ratingallocate', + 'flextable_mod_ratingallocate_table_filter', + $filtertable, + $filtertabledesc + ); } $filtermanualtable = get_user_preferences('flextable_mod_ratingallocate_manual_allocation_filter', null, $userid); if (null !== $filtermanualtable) { $filtermanualtabledesc = get_string('filtermanualtabledesc', 'mod_ratingallocate'); - writer::export_user_preference('mod_ratingallocate', - 'flextable_mod_ratingallocate_manual_allocation_filter', $filtermanualtable, $filtermanualtabledesc); + writer::export_user_preference( + 'mod_ratingallocate', + 'flextable_mod_ratingallocate_manual_allocation_filter', + $filtermanualtable, + $filtermanualtabledesc + ); } } @@ -259,9 +273,9 @@ public static function delete_data_for_all_users_in_context(\context $context) { $DB->delete_records('ratingallocate_allocations', ['ratingallocateid' => $cm->instance]); // Delete Choices. $DB->delete_records_select( - 'ratingallocate_ratings', - "choiceid IN (SELECT id FROM {ratingallocate_choices} WHERE ratingallocateid = :instanceid)", - [ + 'ratingallocate_ratings', + "choiceid IN (SELECT id FROM {ratingallocate_choices} WHERE ratingallocateid = :instanceid)", + [ 'instanceid' => $cm->instance, ] ); @@ -281,7 +295,6 @@ public static function delete_data_for_user(approved_contextlist $contextlist) { $userid = $contextlist->get_user()->id; foreach ($contextlist->get_contexts() as $context) { - if (!$context instanceof \context_module) { return; } @@ -291,10 +304,10 @@ public static function delete_data_for_user(approved_contextlist $contextlist) { $DB->delete_records('ratingallocate_allocations', ['ratingallocateid' => $instanceid, 'userid' => $userid]); // Delete Choices. $DB->delete_records_select( - 'ratingallocate_ratings', - "choiceid IN (SELECT id FROM {ratingallocate_choices} + 'ratingallocate_ratings', + "choiceid IN (SELECT id FROM {ratingallocate_choices} WHERE ratingallocateid = :instanceid) AND userid = :userid", - [ + [ 'instanceid' => $instanceid, 'userid' => $userid, ] @@ -334,7 +347,6 @@ public static function get_users_in_context(userlist $userlist) { JOIN {ratingallocate_allocations} a ON a.ratingallocateid = r.id WHERE cm.id = :instanceid"; $userlist->add_from_sql('userid', $sql, $params); - } /** @@ -349,16 +361,21 @@ public static function delete_data_for_users(approved_userlist $userlist) { $cm = $DB->get_record('course_modules', ['id' => $context->instanceid]); $ratingallocate = $DB->get_record('ratingallocate', ['id' => $cm->instance]); - list($userinsql, $userinparams) = $DB->get_in_or_equal($userlist->get_userids(), SQL_PARAMS_NAMED); + [$userinsql, $userinparams] = $DB->get_in_or_equal($userlist->get_userids(), SQL_PARAMS_NAMED); $params = array_merge(['ratingallocateid' => $ratingallocate->id], $userinparams); // Delete Allocations. - $DB->delete_records_select('ratingallocate_allocations', - "ratingallocateid = :ratingallocateid AND userid {$userinsql}", $params); + $DB->delete_records_select( + 'ratingallocate_allocations', + "ratingallocateid = :ratingallocateid AND userid {$userinsql}", + $params + ); // Delete Ratings. $DB->delete_records_select( - 'ratingallocate_ratings', - "choiceid IN (SELECT id FROM {ratingallocate_choices} " . - "WHERE ratingallocateid = :ratingallocateid) AND userid {$userinsql}", $params); + 'ratingallocate_ratings', + "choiceid IN (SELECT id FROM {ratingallocate_choices} " . + "WHERE ratingallocateid = :ratingallocateid) AND userid {$userinsql}", + $params + ); } } diff --git a/classes/ratingallocate.php b/classes/ratingallocate.php index 6cbab4c8..2226208b 100644 --- a/classes/ratingallocate.php +++ b/classes/ratingallocate.php @@ -73,7 +73,6 @@ * */ class ratingallocate { - /** @var int */ private $ratingallocateid; @@ -169,23 +168,31 @@ private function process_action_start_distribution() { global $CFG, $DB, $PAGE; // Process form: Start distribution and call default page after finishing. if (has_capability('mod/ratingallocate:start_distribution', $this->context)) { - if ($this->get_algorithm_status() === algorithm_status::RUNNING) { // Don't run, if an instance is already running. - redirect(new moodle_url('/mod/ratingallocate/view.php', - ['id' => $this->coursemodule->id]), + redirect( + new moodle_url( + '/mod/ratingallocate/view.php', + ['id' => $this->coursemodule->id] + ), get_string('algorithm_already_running', RATINGALLOCATE_MOD_NAME), null, - notification::NOTIFY_INFO); - } else if ($this->ratingallocate->runalgorithmbycron === "1" && + notification::NOTIFY_INFO + ); + } else if ( + $this->ratingallocate->runalgorithmbycron === "1" && $this->get_algorithm_status() === algorithm_status::NOTSTARTED ) { // Don't run, if the cron has not started yet, but is set as priority. - redirect(new moodle_url('/mod/ratingallocate/view.php', - ['id' => $this->coursemodule->id]), + redirect( + new moodle_url( + '/mod/ratingallocate/view.php', + ['id' => $this->coursemodule->id] + ), get_string('algorithm_scheduled_for_cron', RATINGALLOCATE_MOD_NAME), null, - notification::NOTIFY_INFO); + notification::NOTIFY_INFO + ); } else if ($CFG->ratingallocate_algorithm_force_background_execution === '1') { // Force running algorithm by cron. $this->ratingallocate->runalgorithmbycron = 1; @@ -198,11 +205,15 @@ private function process_action_start_distribution() { // Clear all previous allocations so cron job picks up this task and calculates new allocation. $this->clear_all_allocations(); $DB->update_record(this_db\ratingallocate::TABLE, $this->origdbrecord); - redirect(new moodle_url('/mod/ratingallocate/view.php', - ['id' => $this->coursemodule->id]), + redirect( + new moodle_url( + '/mod/ratingallocate/view.php', + ['id' => $this->coursemodule->id] + ), get_string('algorithm_now_scheduled_for_cron', RATINGALLOCATE_MOD_NAME), null, - notification::NOTIFY_INFO); + notification::NOTIFY_INFO + ); } else { $this->clear_distribute_unallocated_tasks(); $this->origdbrecord->{this_db\ratingallocate::ALGORITHMSTATUS} = algorithm_status::RUNNING; @@ -215,13 +226,18 @@ private function process_action_start_distribution() { // Logging. $event = distribution_triggered::create_simple( - context_module::instance($this->coursemodule->id), $this->ratingallocateid, $timeneeded); + context_module::instance($this->coursemodule->id), + $this->ratingallocateid, + $timeneeded + ); $event->trigger(); - redirect(new moodle_url($PAGE->url->out()), + redirect( + new moodle_url($PAGE->url->out()), get_string('distribution_saved', RATINGALLOCATE_MOD_NAME, $timeneeded), null, - notification::NOTIFY_SUCCESS); + notification::NOTIFY_SUCCESS + ); } } $raters = $this->get_raters_in_course(); @@ -231,8 +247,10 @@ private function process_action_start_distribution() { $completion->update_state($this->coursemodule, COMPLETION_UNKNOWN, $rater->id); } } - redirect(new moodle_url('/mod/ratingallocate/view.php', - ['id' => $this->coursemodule->id])); + redirect(new moodle_url( + '/mod/ratingallocate/view.php', + ['id' => $this->coursemodule->id] + )); return; } @@ -247,20 +265,26 @@ private function delete_all_student_ratings() { global $USER; // Disallow to delete ratings for students and tutors. if (!has_capability('mod/ratingallocate:start_distribution', $this->context, null, false)) { - redirect(new moodle_url('/mod/ratingallocate/view.php', ['id' => $this->coursemodule->id]), - get_string('error_deleting_all_insufficient_permission', RATINGALLOCATE_MOD_NAME)); + redirect( + new moodle_url('/mod/ratingallocate/view.php', ['id' => $this->coursemodule->id]), + get_string('error_deleting_all_insufficient_permission', RATINGALLOCATE_MOD_NAME) + ); return; } // Disallow deletion when there can't be new ratings submitted. $status = $this->get_status(); if ($status !== self::DISTRIBUTION_STATUS_RATING_IN_PROGRESS && $status !== self::DISTRIBUTION_STATUS_TOO_EARLY) { - redirect(new moodle_url('/mod/ratingallocate/view.php', ['id' => $this->coursemodule->id]), - get_string('error_deleting_all_no_rating_possible', RATINGALLOCATE_MOD_NAME)); + redirect( + new moodle_url('/mod/ratingallocate/view.php', ['id' => $this->coursemodule->id]), + get_string('error_deleting_all_no_rating_possible', RATINGALLOCATE_MOD_NAME) + ); return; } $this->delete_all_ratings(); - redirect(new moodle_url('/mod/ratingallocate/view.php', ['id' => $this->coursemodule->id]), - get_string('success_deleting_all', RATINGALLOCATE_MOD_NAME)); + redirect( + new moodle_url('/mod/ratingallocate/view.php', ['id' => $this->coursemodule->id]), + get_string('success_deleting_all', RATINGALLOCATE_MOD_NAME) + ); } /** @@ -305,7 +329,8 @@ private function process_action_give_rating() { redirect( "$CFG->wwwroot/mod/ratingallocate/view.php?id=" . $this->coursemodule->id, get_string('ratings_saved', RATINGALLOCATE_MOD_NAME), - null, notification::NOTIFY_SUCCESS + null, + notification::NOTIFY_SUCCESS ); } @@ -314,7 +339,9 @@ private function process_action_give_rating() { $output .= $renderer->render_ratingallocate_strategyform($mform); // Logging. $event = rating_viewed::create_simple( - context_module::instance($this->coursemodule->id), $this->ratingallocateid); + context_module::instance($this->coursemodule->id), + $this->ratingallocateid + ); $event->trigger(); } } @@ -337,11 +364,15 @@ private function process_action_delete_rating() { $this->delete_ratings_of_user($USER->id); $renderer->add_notification(get_string('ratings_deleted', RATINGALLOCATE_MOD_NAME), self::NOTIFY_SUCCESS); - redirect(new moodle_url('/mod/ratingallocate/view.php', - ['id' => $this->coursemodule->id]), + redirect( + new moodle_url( + '/mod/ratingallocate/view.php', + ['id' => $this->coursemodule->id] + ), get_string('ratings_deleted', RATINGALLOCATE_MOD_NAME), null, - notification::NOTIFY_SUCCESS); + notification::NOTIFY_SUCCESS + ); } } redirect(new moodle_url('/mod/ratingallocate/view.php', ['id' => $this->coursemodule->id])); @@ -384,11 +415,12 @@ private function process_action_show_choices() { echo $renderer->format_text($description); $renderer->ratingallocate_show_choices_table($this, true); - echo $OUTPUT->single_button(new moodle_url('/mod/ratingallocate/view.php', - ['id' => $this->coursemodule->id]), get_string('back'), 'get'); + echo $OUTPUT->single_button(new moodle_url( + '/mod/ratingallocate/view.php', + ['id' => $this->coursemodule->id] + ), get_string('back'), 'get'); echo $renderer->render_footer(); } - } /** @@ -418,20 +450,32 @@ private function process_action_edit_choice() { $data = new stdClass(); $options = ['subdirs' => false, 'maxfiles' => -1, 'accepted_types' => '*', 'return_types' => FILE_INTERNAL]; - file_prepare_standard_filemanager($data, 'attachments', $options, $this->context, - 'mod_ratingallocate', 'choice_attachment', $choiceid); + file_prepare_standard_filemanager( + $data, + 'attachments', + $options, + $this->context, + 'mod_ratingallocate', + 'choice_attachment', + $choiceid + ); - $mform = new modify_choice_form(new moodle_url('/mod/ratingallocate/view.php', - ['id' => $this->coursemodule->id, + $mform = new modify_choice_form( + new moodle_url( + '/mod/ratingallocate/view.php', + ['id' => $this->coursemodule->id, 'ratingallocateid' => $this->ratingallocateid, 'action' => ACTION_EDIT_CHOICE, - ]), - $this, $choice, ['attachment_data' => $data]); + ] + ), + $this, + $choice, + ['attachment_data' => $data] + ); $renderer = $this->get_renderer(); if ($mform->is_submitted() && $data = $mform->get_submitted_data()) { - if (!$mform->is_cancelled()) { if ($mform->is_validated()) { // Processing for editor element (FORMAT_HTML is assumed). @@ -442,15 +486,23 @@ private function process_action_edit_choice() { $this->save_modify_choice_form($data); - $data = file_postupdate_standard_filemanager($data, 'attachments', $options, $this->context, - 'mod_ratingallocate', 'choice_attachment', $data->choiceid); - $renderer->add_notification(get_string("choice_added_notification", RATINGALLOCATE_MOD_NAME), - self::NOTIFY_SUCCESS); + $data = file_postupdate_standard_filemanager( + $data, + 'attachments', + $options, + $this->context, + 'mod_ratingallocate', + 'choice_attachment', + $data->choiceid + ); + $renderer->add_notification( + get_string("choice_added_notification", RATINGALLOCATE_MOD_NAME), + self::NOTIFY_SUCCESS + ); if ($data->usegroups) { $this->update_choice_groups($data->choiceid, $data->groupselector); } - } else { $output .= $OUTPUT->heading(get_string('edit_choice', RATINGALLOCATE_MOD_NAME), 2); $output .= $mform->to_html(); @@ -459,20 +511,27 @@ private function process_action_edit_choice() { } if (object_property_exists($data, 'submitbutton2')) { // If form was submitted using submit2, redirect to the empty edit choice form. - redirect(new moodle_url('/mod/ratingallocate/view.php', + redirect(new moodle_url( + '/mod/ratingallocate/view.php', ['id' => $this->coursemodule->id, 'ratingallocateid' => $this->ratingallocateid, - 'action' => ACTION_EDIT_CHOICE, 'next' => true])); + 'action' => ACTION_EDIT_CHOICE, + 'next' => true] + )); } else { // If form was submitted using save or cancel, redirect to the choices table. - redirect(new moodle_url('/mod/ratingallocate/view.php', - ['id' => $this->coursemodule->id, 'action' => ACTION_SHOW_CHOICES])); + redirect(new moodle_url( + '/mod/ratingallocate/view.php', + ['id' => $this->coursemodule->id, 'action' => ACTION_SHOW_CHOICES] + )); } } else { $isnext = optional_param('next', false, PARAM_BOOL); if ($isnext) { - $renderer->add_notification(get_string("choice_added_notification", RATINGALLOCATE_MOD_NAME), - self::NOTIFY_SUCCESS); + $renderer->add_notification( + get_string("choice_added_notification", RATINGALLOCATE_MOD_NAME), + self::NOTIFY_SUCCESS + ); } $output .= $OUTPUT->heading(get_string('edit_choice', RATINGALLOCATE_MOD_NAME), 2); $output .= $mform->to_html(); @@ -492,7 +551,8 @@ private function process_action_upload_choices() { global $OUTPUT; $PAGE->set_secondary_active_tab('mod_ratingallocate_choices'); - $url = new moodle_url('/mod/ratingallocate/view.php', + $url = new moodle_url( + '/mod/ratingallocate/view.php', ['id' => $this->coursemodule->id, 'ratingallocateid' => $this->ratingallocateid, 'action' => ACTION_UPLOAD_CHOICES, @@ -522,13 +582,17 @@ private function process_action_upload_choices() { case choice_importer::IMPORT_STATUS_SETUP_ERROR: default: \core\notification::error($importstatus->status_message); - $choiceimporter->issue_notifications($importstatus->errors, - notification::NOTIFY_ERROR); + $choiceimporter->issue_notifications( + $importstatus->errors, + notification::NOTIFY_ERROR + ); } } } - redirect(new moodle_url('/mod/ratingallocate/view.php', - ['id' => $this->coursemodule->id, 'action' => ACTION_SHOW_CHOICES])); + redirect(new moodle_url( + '/mod/ratingallocate/view.php', + ['id' => $this->coursemodule->id, 'action' => ACTION_SHOW_CHOICES] + )); } $output .= $OUTPUT->heading(get_string('upload_choices', 'ratingallocate'), 2); @@ -547,13 +611,17 @@ private function process_action_enable_choice($active) { $choiceid = optional_param('choiceid', 0, PARAM_INT); if ($choiceid) { - $DB->set_field(this_db\ratingallocate_choices::TABLE, + $DB->set_field( + this_db\ratingallocate_choices::TABLE, this_db\ratingallocate_choices::ACTIVE, $active, - ['id' => $choiceid]); + ['id' => $choiceid] + ); } - redirect(new moodle_url('/mod/ratingallocate/view.php', - ['id' => $this->coursemodule->id, 'action' => ACTION_SHOW_CHOICES])); + redirect(new moodle_url( + '/mod/ratingallocate/view.php', + ['id' => $this->coursemodule->id, 'action' => ACTION_SHOW_CHOICES] + )); } } @@ -581,22 +649,35 @@ private function process_action_delete_choice() { } } - redirect(new moodle_url('/mod/ratingallocate/view.php', - ['id' => $this->coursemodule->id, 'action' => ACTION_SHOW_CHOICES]), - get_string('choice_deleted_notification', RATINGALLOCATE_MOD_NAME, - $choice->{this_db\ratingallocate_choices::TITLE}), + redirect( + new moodle_url( + '/mod/ratingallocate/view.php', + ['id' => $this->coursemodule->id, 'action' => ACTION_SHOW_CHOICES] + ), + get_string( + 'choice_deleted_notification', + RATINGALLOCATE_MOD_NAME, + $choice->{this_db\ratingallocate_choices::TITLE} + ), null, - notification::NOTIFY_SUCCESS); + notification::NOTIFY_SUCCESS + ); } else { - redirect(new moodle_url('/mod/ratingallocate/view.php', - ['id' => $this->coursemodule->id, 'action' => ACTION_SHOW_CHOICES]), + redirect( + new moodle_url( + '/mod/ratingallocate/view.php', + ['id' => $this->coursemodule->id, 'action' => ACTION_SHOW_CHOICES] + ), get_string('choice_deleted_notification_error', RATINGALLOCATE_MOD_NAME), null, - notification::NOTIFY_ERROR); + notification::NOTIFY_ERROR + ); } } - redirect(new moodle_url('/mod/ratingallocate/view.php', - ['id' => $this->coursemodule->id, 'action' => ACTION_SHOW_CHOICES])); + redirect(new moodle_url( + '/mod/ratingallocate/view.php', + ['id' => $this->coursemodule->id, 'action' => ACTION_SHOW_CHOICES] + )); } } @@ -621,8 +702,10 @@ private function process_action_manual_allocation() { if (!$mform->is_cancelled()) { $renderer = $this->get_renderer(); $status = $this->get_status(); - if ($status === self::DISTRIBUTION_STATUS_TOO_EARLY || - $status === self::DISTRIBUTION_STATUS_RATING_IN_PROGRESS) { + if ( + $status === self::DISTRIBUTION_STATUS_TOO_EARLY || + $status === self::DISTRIBUTION_STATUS_RATING_IN_PROGRESS + ) { $notification = get_string('modify_allocation_group_desc_' . $status, RATINGALLOCATE_MOD_NAME); $notificationtype = notification::NOTIFY_WARNING; } else { @@ -637,30 +720,42 @@ private function process_action_manual_allocation() { } } } else { - redirect(new moodle_url('/mod/ratingallocate/view.php', - ['id' => $this->coursemodule->id])); + redirect(new moodle_url( + '/mod/ratingallocate/view.php', + ['id' => $this->coursemodule->id] + )); } // If form was submitted using save or cancel, retirect to the default page. if (property_exists($data, "submitbutton")) { if ($notification) { - redirect(new moodle_url('/mod/ratingallocate/view.php', - ['id' => $this->coursemodule->id]), $notification, null, $notificationtype); - + redirect(new moodle_url( + '/mod/ratingallocate/view.php', + ['id' => $this->coursemodule->id] + ), $notification, null, $notificationtype); } else { - redirect(new moodle_url('/mod/ratingallocate/view.php', - ['id' => $this->coursemodule->id])); + redirect(new moodle_url( + '/mod/ratingallocate/view.php', + ['id' => $this->coursemodule->id] + )); } // If the save and continue button was pressed, // redirect to the manual allocation form to refresh the checked radiobuttons. } else if (property_exists($data, "submitbutton2")) { if ($notification) { - redirect(new moodle_url('/mod/ratingallocate/view.php', - ['id' => $this->coursemodule->id, 'action' => ACTION_MANUAL_ALLOCATION]), $notification, null, - $notificationtype); - + redirect( + new moodle_url( + '/mod/ratingallocate/view.php', + ['id' => $this->coursemodule->id, 'action' => ACTION_MANUAL_ALLOCATION] + ), + $notification, + null, + $notificationtype + ); } else { - redirect(new moodle_url('/mod/ratingallocate/view.php', - ['id' => $this->coursemodule->id, 'action' => ACTION_MANUAL_ALLOCATION])); + redirect(new moodle_url( + '/mod/ratingallocate/view.php', + ['id' => $this->coursemodule->id, 'action' => ACTION_MANUAL_ALLOCATION] + )); } } $raters = $this->get_raters_in_course(); @@ -685,8 +780,10 @@ private function process_action_manual_allocation() { * @return array of group ids used in rateable choices */ public function get_all_groups_of_choices(): array { - $rateablechoiceswithgrouprestrictions = array_filter($this->get_rateable_choices(), - fn($choice) => !empty($choice->usegroups) && !empty($this->get_choice_groups($choice->id))); + $rateablechoiceswithgrouprestrictions = array_filter( + $this->get_rateable_choices(), + fn($choice) => !empty($choice->usegroups) && !empty($this->get_choice_groups($choice->id)) + ); $rateablechoiceids = array_map(fn($choice) => $choice->id, $rateablechoiceswithgrouprestrictions); $groupids = []; foreach ($rateablechoiceids as $choiceid) { @@ -725,8 +822,10 @@ public function get_user_groupids(int $userid): array { private function get_undistributed_users_with_groupscount(): array { $cachedallocations = $this->get_allocations(); $raters = $this->get_raters_in_course(); - $undistributedusers = array_map(fn($user) => $user->id, array_values(array_filter($raters, - fn($user) => !in_array($user->id, array_keys($cachedallocations))))); + $undistributedusers = array_map(fn($user) => $user->id, array_values(array_filter( + $raters, + fn($user) => !in_array($user->id, array_keys($cachedallocations)) + ))); $undistributeduserswithgroups = []; foreach ($undistributedusers as $user) { @@ -944,7 +1043,6 @@ public function distribute_users_without_choice(string $distributionalgorithm): $usertoassign = array_shift($possibleusers); // As long as we have a user to assign, we try to assign him. while ($usertoassign != null) { - // Calculate the choice to assign the user to depending on the given algorithm. $choicetoassign = $this->get_next_choice_to_assign_user($distributionalgorithm, $usertoassign); if ($choicetoassign === -2) { @@ -988,18 +1086,29 @@ private function process_action_show_ratings_and_alloc_table() { $PAGE->set_secondary_active_tab('mod_ratingallocate_reports'); $renderer = $this->get_renderer(); $status = $this->get_status(); - $output .= $renderer->reports_group($this->ratingallocateid, $this->coursemodule->id, - $status, $this->context, ACTION_SHOW_RATINGS_AND_ALLOCATION_TABLE); + $output .= $renderer->reports_group( + $this->ratingallocateid, + $this->coursemodule->id, + $status, + $this->context, + ACTION_SHOW_RATINGS_AND_ALLOCATION_TABLE + ); - $output .= $renderer->ratings_table_for_ratingallocate($this->get_rateable_choices(), - $this->get_ratings_for_rateable_choices(), $this->get_raters_in_course(), - $this->get_allocations(), $this); + $output .= $renderer->ratings_table_for_ratingallocate( + $this->get_rateable_choices(), + $this->get_ratings_for_rateable_choices(), + $this->get_raters_in_course(), + $this->get_allocations(), + $this + ); $output = html_writer::div($output, 'ratingallocate_ratings_table_container'); // Logging. $event = ratings_and_allocation_table_viewed::create_simple( - context_module::instance($this->coursemodule->id), $this->ratingallocateid); + context_module::instance($this->coursemodule->id), + $this->ratingallocateid + ); $event->trigger(); } return $output; @@ -1021,14 +1130,21 @@ private function process_action_show_allocation_table() { $PAGE->set_secondary_active_tab('mod_ratingallocate_reports'); $renderer = $this->get_renderer(); $status = $this->get_status(); - $output .= $renderer->reports_group($this->ratingallocateid, $this->coursemodule->id, - $status, $this->context, ACTION_SHOW_ALLOCATION_TABLE); + $output .= $renderer->reports_group( + $this->ratingallocateid, + $this->coursemodule->id, + $status, + $this->context, + ACTION_SHOW_ALLOCATION_TABLE + ); $output .= $renderer->allocation_table_for_ratingallocate($this); // Logging. $event = allocation_table_viewed::create_simple( - context_module::instance($this->coursemodule->id), $this->ratingallocateid); + context_module::instance($this->coursemodule->id), + $this->ratingallocateid + ); $event->trigger(); } return $output; @@ -1049,14 +1165,21 @@ private function process_action_show_statistics() { $PAGE->set_secondary_active_tab('mod_ratingallocate_reports'); $renderer = $this->get_renderer(); $status = $this->get_status(); - $output .= $renderer->reports_group($this->ratingallocateid, $this->coursemodule->id, - $status, $this->context, ACTION_SHOW_STATISTICS); + $output .= $renderer->reports_group( + $this->ratingallocateid, + $this->coursemodule->id, + $status, + $this->context, + ACTION_SHOW_STATISTICS + ); $output .= $renderer->statistics_table_for_ratingallocate($this); // Logging. $event = allocation_statistics_viewed::create_simple( - context_module::instance($this->coursemodule->id), $this->ratingallocateid); + context_module::instance($this->coursemodule->id), + $this->ratingallocateid + ); $event->trigger(); } return $output; @@ -1072,18 +1195,23 @@ private function process_action_show_statistics() { private function process_publish_allocations() { $status = $this->get_status(); if ($status === self::DISTRIBUTION_STATUS_READY_ALLOC_STARTED) { - $this->publish_allocation(); - redirect(new moodle_url('/mod/ratingallocate/view.php', - ['id' => $this->coursemodule->id]), + redirect( + new moodle_url( + '/mod/ratingallocate/view.php', + ['id' => $this->coursemodule->id] + ), get_string('distribution_published', RATINGALLOCATE_MOD_NAME), null, - notification::NOTIFY_SUCCESS); + notification::NOTIFY_SUCCESS + ); } - redirect(new moodle_url('/mod/ratingallocate/view.php', - ['id' => $this->coursemodule->id])); + redirect(new moodle_url( + '/mod/ratingallocate/view.php', + ['id' => $this->coursemodule->id] + )); } /** @@ -1097,11 +1225,15 @@ private function process_publish_allocations() { private function process_action_allocation_to_grouping() { $this->synchronize_allocation_and_grouping(); - redirect(new moodle_url('/mod/ratingallocate/view.php', - ['id' => $this->coursemodule->id]), + redirect( + new moodle_url( + '/mod/ratingallocate/view.php', + ['id' => $this->coursemodule->id] + ), get_string('moodlegroups_created', RATINGALLOCATE_MOD_NAME), null, - notification::NOTIFY_SUCCESS); + notification::NOTIFY_SUCCESS + ); } /** @@ -1119,15 +1251,25 @@ private function process_default() { if (has_capability('mod/ratingallocate:give_rating', $this->context, null, false)) { if ($status === self::DISTRIBUTION_STATUS_RATING_IN_PROGRESS) { if ($this->is_setup_ok()) { - $output .= $OUTPUT->single_button(new moodle_url('/mod/ratingallocate/view.php', - ['id' => $this->coursemodule->id, - 'action' => ACTION_GIVE_RATING]), - get_string('edit_rating', RATINGALLOCATE_MOD_NAME), 'get'); + $output .= $OUTPUT->single_button( + new moodle_url( + '/mod/ratingallocate/view.php', + ['id' => $this->coursemodule->id, + 'action' => ACTION_GIVE_RATING] + ), + get_string('edit_rating', RATINGALLOCATE_MOD_NAME), + 'get' + ); - $output .= $OUTPUT->single_button(new moodle_url('/mod/ratingallocate/view.php', - ['id' => $this->coursemodule->id, - 'action' => ACTION_DELETE_RATING]), - get_string('delete_rating', RATINGALLOCATE_MOD_NAME), 'get'); + $output .= $OUTPUT->single_button( + new moodle_url( + '/mod/ratingallocate/view.php', + ['id' => $this->coursemodule->id, + 'action' => ACTION_DELETE_RATING] + ), + get_string('delete_rating', RATINGALLOCATE_MOD_NAME), + 'get' + ); } else { $renderer->add_notification(get_string('no_rating_possible', RATINGALLOCATE_MOD_NAME)); } @@ -1138,11 +1280,16 @@ private function process_default() { if (has_capability('mod/ratingallocate:start_distribution', $this->context)) { $undistributeduserscount = count($this->get_undistributed_users()); - $output .= $renderer->render_ratingallocate_allocation_status($this->coursemodule->id, - $status, $undistributeduserscount); - $output .= $renderer->render_ratingallocate_publish_allocation($this->ratingallocateid, - $this->coursemodule->id, $status); - + $output .= $renderer->render_ratingallocate_allocation_status( + $this->coursemodule->id, + $status, + $undistributeduserscount + ); + $output .= $renderer->render_ratingallocate_publish_allocation( + $this->ratingallocateid, + $this->coursemodule->id, + $status + ); } $completion = new completion_info($this->course); @@ -1150,7 +1297,9 @@ private function process_default() { // Logging. $event = ratingallocate_viewed::create_simple( - context_module::instance($this->coursemodule->id), $this->ratingallocateid); + context_module::instance($this->coursemodule->id), + $this->ratingallocateid + ); $event->trigger(); return $output; @@ -1241,10 +1390,12 @@ public function handle_view() { case ACTION_DISTRIBUTE_UNALLOCATED_EQUALLY: case ACTION_DISTRIBUTE_UNALLOCATED_FILL: $this->queue_distribution_of_users_without_choice($action); - redirect(new moodle_url('/mod/ratingallocate/view.php', ['id' => $this->coursemodule->id]), + redirect( + new moodle_url('/mod/ratingallocate/view.php', ['id' => $this->coursemodule->id]), get_string('distributing_unallocated_users_started', RATINGALLOCATE_MOD_NAME), null, - notification::NOTIFY_SUCCESS); + notification::NOTIFY_SUCCESS + ); break; case ACTION_SHOW_RATINGS_AND_ALLOCATION_TABLE: @@ -1370,7 +1521,6 @@ public function distribute_choices() { foreach ($raters as $rater) { $completion->update_state($this->coursemodule, COMPLETION_UNKNOWN, $rater->id); } - } $timeneeded = (microtime(true) - $timestart); @@ -1418,12 +1568,22 @@ public function synchronize_allocation_and_grouping() { // Loop through existing choices. foreach ($choices as $choice) { - if ($this->db->record_exists(this_db\ratingallocate_choices::TABLE, - ['id' => $choice->id])) { + if ( + $this->db->record_exists( + this_db\ratingallocate_choices::TABLE, + ['id' => $choice->id] + ) + ) { // Checks if there is already a group for this choice. $where = "choiceid = $choice->id AND groupid <> 0"; - if ($groupids = $this->db->get_record_select(this_db\ratingallocate_ch_gengroups::TABLE, - $where, [], 'groupid')) { + if ( + $groupids = $this->db->get_record_select( + this_db\ratingallocate_ch_gengroups::TABLE, + $where, + [], + 'groupid' + ) + ) { $groupid = $groupids->groupid; $group = groups_get_group($groupid); // Delete all the members from the existing group for this choice. @@ -1440,8 +1600,10 @@ public function synchronize_allocation_and_grouping() { if ($createdid) { groups_assign_grouping($groupingid, $createdid); // Insert the mapping between group and choice into the Table. - $this->db->insert_record(this_db\ratingallocate_ch_gengroups::TABLE, - ['choiceid' => $choice->id, 'groupid' => $createdid]); + $this->db->insert_record( + this_db\ratingallocate_ch_gengroups::TABLE, + ['choiceid' => $choice->id, 'groupid' => $createdid] + ); } } } @@ -1452,9 +1614,11 @@ public function synchronize_allocation_and_grouping() { $choiceid = $allocation->choiceid; $userid = $allocation->userid; // Get the group corresponding to the choiceid. - $groupids = $this->db->get_record(this_db\ratingallocate_ch_gengroups::TABLE, + $groupids = $this->db->get_record( + this_db\ratingallocate_ch_gengroups::TABLE, ['choiceid' => $choiceid], - 'groupid'); + 'groupid' + ); if (($groupid = $groupids->groupid) && ($group = groups_get_group($groupid))) { groups_add_member($group, $userid); } @@ -1489,7 +1653,9 @@ public function publish_allocation() { // Logging. $event = allocation_published::create_simple( - context_module::instance($this->coursemodule->id), $this->ratingallocateid); + context_module::instance($this->coursemodule->id), + $this->ratingallocateid + ); $event->trigger(); } @@ -1600,7 +1766,6 @@ public function clear_all_allocations() { $completion->update_state($this->coursemodule, COMPLETION_INCOMPLETE, $rater->id); } } - } /** @@ -1624,7 +1789,6 @@ function ($u) { $choices = $this->get_choices_with_allocationcount(); $allocations = $this->get_allocations(); foreach ($users as $userid => $allocobj) { - // Prepare the email to be sent to the user. $userto = get_complete_user_data('id', $userid); if ($CFG->branch >= 402) { @@ -1634,8 +1798,11 @@ function ($u) { } $notificationsubject = format_string($this->course->shortname, true) . ': ' . - get_string('allocation_notification_message_subject', 'ratingallocate', - $this->ratingallocate->name); + get_string( + 'allocation_notification_message_subject', + 'ratingallocate', + $this->ratingallocate->name + ); $notificationtext = ''; if (array_key_exists($userid, $allocations) && $allocobj = $allocations[$userid]) { @@ -1653,7 +1820,6 @@ function ($u) { // Send message to all users with an allocation or a rating. if (!empty($notificationtext)) { - // Prepare the message. $eventdata = new \core\message\message(); $eventdata->courseid = $this->course->id; @@ -1669,15 +1835,18 @@ function ($u) { $eventdata->fullmessagehtml = ''; $eventdata->smallmessage = ''; - $eventdata->contexturl = new moodle_url('/mod/ratingallocate/view.php', - ['id' => $this->coursemodule->id]); + $eventdata->contexturl = new moodle_url( + '/mod/ratingallocate/view.php', + ['id' => $this->coursemodule->id] + ); $eventdata->contexturlname = $this->ratingallocate->name; $mailresult = message_send($eventdata); if (!$mailresult) { mtrace( "ERROR: mod/ratingallocate/locallib.php: Could not send notification to user $userto->id " . - "... not trying again."); + "... not trying again." + ); } } } @@ -1728,7 +1897,8 @@ public function get_users_with_ratings() { function ($rater) { return $rater->id; }, - $this->get_raters_in_course()); + $this->get_raters_in_course() + ); $sql = "SELECT DISTINCT r.userid FROM {ratingallocate_choices} c @@ -1739,7 +1909,6 @@ function ($rater) { return $this->db->get_records_sql($sql, [ 'ratingallocateid' => $this->ratingallocateid, ]); - } /** @@ -1774,7 +1943,9 @@ public function delete_all_ratings() { // Logging. $event = all_ratings_deleted::create_simple( - context_module::instance($this->coursemodule->id), $this->ratingallocateid); + context_module::instance($this->coursemodule->id), + $this->ratingallocateid + ); $event->trigger(); } catch (Exception $e) { $transaction->rollback($e); @@ -1791,7 +1962,6 @@ public function delete_ratings_of_user($userid) { $transaction = $DB->start_delegated_transaction(); try { - $choices = $this->get_choices(); foreach ($choices as $id => $choice) { @@ -1813,7 +1983,9 @@ public function delete_ratings_of_user($userid) { // Logging. $event = rating_deleted::create_simple( - context_module::instance($this->coursemodule->id), $this->ratingallocateid); + context_module::instance($this->coursemodule->id), + $this->ratingallocateid + ); $event->trigger(); } catch (Exception $e) { $transaction->rollback($e); @@ -1831,7 +2003,7 @@ public function save_ratings_to_db($userid, array $data) { $loggingdata = []; try { foreach ($data as $id => $rdata) { - $rating = new stdClass (); + $rating = new stdClass(); $rating->rating = $rdata['rating']; $ratingexists = [ @@ -1848,8 +2020,10 @@ public function save_ratings_to_db($userid, array $data) { $DB->update_record('ratingallocate_ratings', $rating); // Logging. - array_push($loggingdata, - ['choiceid' => $oldrating->choiceid, 'rating' => $rating->rating]); + array_push( + $loggingdata, + ['choiceid' => $oldrating->choiceid, 'rating' => $rating->rating] + ); } } else { // Create a new rating in the table. @@ -1860,8 +2034,10 @@ public function save_ratings_to_db($userid, array $data) { $DB->insert_record('ratingallocate_ratings', $rating); // Logging. - array_push($loggingdata, - ['choiceid' => $rating->choiceid, 'rating' => $rating->rating]); + array_push( + $loggingdata, + ['choiceid' => $rating->choiceid, 'rating' => $rating->rating] + ); } } $transaction->allow_commit(); @@ -1874,7 +2050,10 @@ public function save_ratings_to_db($userid, array $data) { // Logging. $event = rating_saved::create_simple( - context_module::instance($this->coursemodule->id), $this->ratingallocateid, $loggingdata); + context_module::instance($this->coursemodule->id), + $this->ratingallocateid, + $loggingdata + ); $event->trigger(); } catch (Exception $e) { $transaction->rollback($e); @@ -1886,10 +2065,13 @@ public function save_ratings_to_db($userid, array $data) { */ public function get_rateable_choices() { global $DB; - return $DB->get_records(this_db\ratingallocate_choices::TABLE, + return $DB->get_records( + this_db\ratingallocate_choices::TABLE, [this_db\ratingallocate_choices::RATINGALLOCATEID => $this->ratingallocateid, this_db\ratingallocate_choices::ACTIVE => true, - ], this_db\ratingallocate_choices::TITLE); + ], + this_db\ratingallocate_choices::TITLE + ); } /** @@ -1903,8 +2085,10 @@ public function get_rateable_choices() { public function filter_choices_by_groups($choices, $userid) { // See all the choices, if you have the capability to modify them. - if (has_capability('mod/ratingallocate:modify_choices', $this->context) - || has_capability('mod/ratingallocate:export_ratings', $this->context)) { + if ( + has_capability('mod/ratingallocate:modify_choices', $this->context) + || has_capability('mod/ratingallocate:export_ratings', $this->context) + ) { return $choices; } @@ -1935,9 +2119,12 @@ public function filter_choices_by_groups($choices, $userid) { */ public function get_choices() { global $DB; - return $DB->get_records(this_db\ratingallocate_choices::TABLE, + return $DB->get_records( + this_db\ratingallocate_choices::TABLE, [this_db\ratingallocate_choices::RATINGALLOCATEID => $this->ratingallocateid, - ], this_db\ratingallocate_choices::TITLE); + ], + this_db\ratingallocate_choices::TITLE + ); } /** @@ -1956,8 +2143,11 @@ public function get_ratingallocateid() { */ public function get_choices_by_id($ids) { global $DB; - return $DB->get_records_list(this_db\ratingallocate_choices::TABLE, - 'id', $ids); + return $DB->get_records_list( + this_db\ratingallocate_choices::TABLE, + 'id', + $ids + ); } /** @@ -2007,7 +2197,9 @@ public function save_manual_allocation_form($allocdata, $userdata) { } // Logging. $event = manual_allocation_saved::create_simple( - context_module::instance($this->coursemodule->id), $this->ratingallocateid); + context_module::instance($this->coursemodule->id), + $this->ratingallocateid + ); $event->trigger(); $transaction->allow_commit(); @@ -2018,7 +2210,6 @@ public function save_manual_allocation_form($allocdata, $userdata) { $completion->update_state($this->coursemodule, COMPLETION_UNKNOWN, $rater->id); } } - } catch (Exception $e) { if (isset($transaction)) { $transaction->rollback($e); @@ -2059,7 +2250,6 @@ public function save_modify_choice_form($data) { $transaction->rollback($e); } } - } /** @@ -2123,8 +2313,11 @@ public function add_allocation($choiceid, $userid) { * @return boolean */ public function alter_allocation($oldchoiceid, $newchoiceid, $userid): bool { - $this->db->set_field(this_db\ratingallocate_allocations::TABLE, this_db\ratingallocate_allocations::CHOICEID, - $newchoiceid, [ + $this->db->set_field( + this_db\ratingallocate_allocations::TABLE, + this_db\ratingallocate_allocations::CHOICEID, + $newchoiceid, + [ 'choiceid' => $oldchoiceid, 'userid' => $userid, ] @@ -2422,5 +2615,4 @@ public function clear_distribute_unallocated_tasks(): bool { // If we did not exit with 'false' before, we could clear all scheduled adhoc tasks or there was no task at all. return true; } - } diff --git a/classes/ratingallocate_observer.php b/classes/ratingallocate_observer.php index 489e8e2b..a1bb9f01 100644 --- a/classes/ratingallocate_observer.php +++ b/classes/ratingallocate_observer.php @@ -32,7 +32,6 @@ * @package mod_ratingallocate */ class ratingallocate_observer { - /** * Triggered if group_deleted event is triggered. * @@ -45,17 +44,18 @@ public static function ch_gengroups_delete(\core\event\group_deleted $event) { global $DB; $eventdata = $event->get_record_snapshot('groups', $event->objectid); - if ($DB->record_exists( - 'ratingallocate_ch_gengroups', - ['groupid' => $eventdata->id])) { - + if ( + $DB->record_exists( + 'ratingallocate_ch_gengroups', + ['groupid' => $eventdata->id] + ) + ) { // Delete the group from ratingallocate_ch_gengroups table. $DB->delete_records( 'ratingallocate_ch_gengroups', ['groupid' => $eventdata->id] ); } - } /** @@ -70,17 +70,17 @@ public static function ra_groupings_delete(\core\event\grouping_deleted $event) global $DB; $eventdata = $event->get_record_snapshot('groupings', $event->objectid); - if ($DB->record_exists( - 'ratingallocate_groupings', - ['groupingid' => $eventdata->id])) { - + if ( + $DB->record_exists( + 'ratingallocate_groupings', + ['groupingid' => $eventdata->id] + ) + ) { // Delete the grouping from the ratingallocate_groupings table. $DB->delete_records( 'ratingallocate_groupings', ['groupingid' => $eventdata->id] ); - } } - } diff --git a/classes/ratings_and_allocations_table.php b/classes/ratings_and_allocations_table.php index 69ac7f3a..151c242e 100644 --- a/classes/ratings_and_allocations_table.php +++ b/classes/ratings_and_allocations_table.php @@ -37,7 +37,6 @@ * @package mod_ratingallocate */ class ratings_and_allocations_table extends \table_sql { - /** * Choice column. */ @@ -104,12 +103,14 @@ class ratings_and_allocations_table extends \table_sql { * @throws \coding_exception * @throws \dml_exception */ - public function __construct(mod_ratingallocate_renderer $renderer, - $titles, - $ratingallocate, - $action = ACTION_SHOW_RATINGS_AND_ALLOCATION_TABLE, - $uniqueid = 'mod_ratingallocate_table', - $downloadable = true) { + public function __construct( + mod_ratingallocate_renderer $renderer, + $titles, + $ratingallocate, + $action = ACTION_SHOW_RATINGS_AND_ALLOCATION_TABLE, + $uniqueid = 'mod_ratingallocate_table', + $downloadable = true + ) { parent::__construct($uniqueid); global $PAGE; $url = $PAGE->url; @@ -119,14 +120,16 @@ public function __construct(mod_ratingallocate_renderer $renderer, $this->titles = $titles; $this->ratingallocate = $ratingallocate; $allgroupsofchoices = $this->ratingallocate->get_all_groups_of_choices(); - $this->groupsofallchoices = array_map(function($groupid) { + $this->groupsofallchoices = array_map(function ($groupid) { return groups_get_group($groupid); }, $allgroupsofchoices); if ($downloadable && has_capability('mod/ratingallocate:export_ratings', $ratingallocate->get_context())) { $download = optional_param('download', '', PARAM_ALPHA); - $this->is_downloading($download, + $this->is_downloading( + $download, $ratingallocate->ratingallocate->name . '-ratings_and_allocations', - 'ratings_and_allocations'); + 'ratings_and_allocations' + ); } $this->shownames = true; @@ -160,7 +163,6 @@ public function setup_table($choices, $hidenorating = null, $showallocnecessary } else { $this->choicesum[$choice->id] = 0; } - } ksort($this->choicenames); @@ -199,8 +201,10 @@ public function setup_table($choices, $hidenorating = null, $showallocnecessary $columns[] = 'lastname'; $headers[] = get_string('lastname'); global $COURSE; - if (in_array('email', $additionalfields) && - has_capability('moodle/course:useremail', $this->ratingallocate->get_context())) { + if ( + in_array('email', $additionalfields) && + has_capability('moodle/course:useremail', $this->ratingallocate->get_context()) + ) { $columns[] = 'email'; $headers[] = get_string('email'); } @@ -215,8 +219,10 @@ public function setup_table($choices, $hidenorating = null, $showallocnecessary // Prepare group names of choices. $this->groupnamesofchoices = []; foreach ($choices as $choice) { - $this->groupnamesofchoices[$choice->id] = array_map(fn($group) => groups_get_group_name($group->id), - $this->ratingallocate->get_choice_groups($choice->id)); + $this->groupnamesofchoices[$choice->id] = array_map( + fn($group) => groups_get_group_name($group->id), + $this->ratingallocate->get_choice_groups($choice->id) + ); } } } @@ -226,14 +232,15 @@ public function setup_table($choices, $hidenorating = null, $showallocnecessary $filteredchoices = $this->filter_choiceids(array_keys($this->choicenames)); foreach ($filteredchoices as $choiceid) { - $columns[] = self::CHOICE_COL . $choiceid; $choice = $this->ratingallocate->get_choices()[$choiceid]; if ($this->showgroups) { $choicegroups = $this->groupnamesofchoices[$choiceid]; if (!$this->is_downloading() && !empty($choice->usegroups) && !empty($choicegroups)) { - $this->choicenames[$choiceid] .= '
' . \html_writer::span('(' . implode(';', $choicegroups) . ')', - 'groupsinchoiceheadings'); + $this->choicenames[$choiceid] .= '
' . \html_writer::span( + '(' . implode(';', $choicegroups) . ')', + 'groupsinchoiceheadings' + ); } } $headers[] = $this->choicenames[$choiceid]; @@ -357,10 +364,10 @@ private function add_user_ratings_row($user, $userratings, $userallocations) { $row['fullname'] = $user; // We only can add groups if at least one choice has an active group restriction. if ($this->showgroups) { - $groupsofuser = array_filter($this->groupsofallchoices, function($group) use ($user) { + $groupsofuser = array_filter($this->groupsofallchoices, function ($group) use ($user) { return groups_is_member($group->id, $user->id); }); - $groupnames = array_map(function($group) { + $groupnames = array_map(function ($group) { return $group->name; }, $groupsofuser); $row['groups'] = implode(';', $groupnames); @@ -473,13 +480,16 @@ public function other_cols($column, $row) { return ""; } return $celldata['rating']; - } - return $this->render_cell($row->id, substr($column, 7), - $ratingtext, $hasallocation, $ratingclass); + return $this->render_cell( + $row->id, + substr($column, 7), + $ratingtext, + $hasallocation, + $ratingclass + ); } else { - $ratingtext = get_string('no_rating_given', RATINGALLOCATE_MOD_NAME); if ($this->is_downloading()) { @@ -511,16 +521,19 @@ public function other_cols($column, $row) { private function render_cell($userid, $choiceid, $text, $checked, $class = '') { if ($this->writeable) { $result = \html_writer::start_span(); - $result .= \html_writer::tag('input', '', - ['class' => 'ratingallocate_checkbox_label', + $result .= \html_writer::tag( + 'input', + '', + ['class' => 'ratingallocate_checkbox_label', 'type' => 'radio', 'name' => 'allocdata[' . $userid . ']', 'id' => 'user_' . $userid . '_alloc_' . $choiceid, 'value' => $choiceid, - $checked => '']); + $checked => ''] + ); $result .= \html_writer::label( - \html_writer::span('', 'ratingallocate_checkbox') . $text, - 'user_' . $userid . '_alloc_' . $choiceid + \html_writer::span('', 'ratingallocate_checkbox') . $text, + 'user_' . $userid . '_alloc_' . $choiceid ); return $result; } else { @@ -537,12 +550,15 @@ private function print_hidden_user_fields($users) { if ($this->writeable) { echo \html_writer::start_span(); foreach ($users as $user) { - echo \html_writer::tag('input', '', - [ + echo \html_writer::tag( + 'input', + '', + [ 'name' => 'userdata[' . $user->id . ']', 'value' => $user->id, 'type' => 'hidden', - ]); + ] + ); } echo \html_writer::end_span(); } @@ -636,12 +652,17 @@ private function filter_userids($userids) { } if ($this->groupselect == -1) { $sql .= "AND u.id not in ( SELECT distinct gm.userid FROM {groups_members} gm WHERE gm.groupid in (null"; - if (!empty($gmgroupid = implode(",", - array_map( - function($o) { - return $o->id; - }, - $this->groupsofallchoices)))) { + if ( + !empty($gmgroupid = implode( + ",", + array_map( + function ($o) { + return $o->id; + }, + $this->groupsofallchoices + ) + )) + ) { $sql .= "," . $gmgroupid . ") ) "; } else { $sql .= "))"; @@ -650,16 +671,17 @@ function($o) { $sql .= "AND u.id in ( SELECT gm.userid FROM {groups_members} gm WHERE gm.groupid= :groupselect ) "; } return array_map( - function($u) { - return $u->id; - }, - $DB->get_records_sql($sql, - [ + function ($u) { + return $u->id; + }, + $DB->get_records_sql( + $sql, + [ 'ratingallocateid' => $this->ratingallocate->ratingallocate->id, 'ratingallocateid2' => $this->ratingallocate->ratingallocate->id, 'groupselect' => $this->groupselect, ] - ) + ) ); } @@ -696,24 +718,24 @@ private function filter_choiceids($choiceids) { } return array_map( - function($c) { + function ($c) { return $c->id; }, - $DB->get_records_sql($sql, + $DB->get_records_sql( + $sql, [ 'ratingallocateid' => $this->ratingallocate->ratingallocate->id, 'groupselect' => $this->groupselect, ] ) ); - } /** * Sets up the sql statement for querying the table data. */ public function init_sql() { - $userids = array_map(function($c) { + $userids = array_map(function ($c) { return $c->id; }, $this->ratingallocate->get_raters_in_course()); @@ -744,5 +766,4 @@ public function init_sql() { $this->query_db(20); } - } diff --git a/classes/task/cron_task.php b/classes/task/cron_task.php index b8a050b0..673f724f 100644 --- a/classes/task/cron_task.php +++ b/classes/task/cron_task.php @@ -31,7 +31,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class cron_task extends \core\task\scheduled_task { - /** * Get a descriptive name for this task (shown to admins). * @@ -67,16 +66,20 @@ public function execute() { $timetoterminate = $CFG->ratingallocate_algorithm_timeout + $ratingallocate->ratingallocate->algorithmstarttime; // If last execution exeeds timeout limit assume failure of algorithm run. - if ($ratingallocate->ratingallocate->algorithmstarttime && + if ( + $ratingallocate->ratingallocate->algorithmstarttime && $currenttime >= $timetoterminate && - $ratingallocate->get_algorithm_status() === \mod_ratingallocate\algorithm_status::RUNNING) { + $ratingallocate->get_algorithm_status() === \mod_ratingallocate\algorithm_status::RUNNING + ) { $ratingallocate->set_algorithm_failed(); return true; } // Only start the algorithm, if it should be run by the cron and hasn't been started somehow, yet. - if ($ratingallocate->ratingallocate->runalgorithmbycron === "1" && - $ratingallocate->get_algorithm_status() === \mod_ratingallocate\algorithm_status::NOTSTARTED) { + if ( + $ratingallocate->ratingallocate->runalgorithmbycron === "1" && + $ratingallocate->get_algorithm_status() === \mod_ratingallocate\algorithm_status::NOTSTARTED + ) { // Clear eventually scheduled distribution of unallocated users. $ratingallocate->clear_distribute_unallocated_tasks(); // Run allocation. @@ -85,5 +88,4 @@ public function execute() { } return true; } - } diff --git a/classes/task/distribute_unallocated_task.php b/classes/task/distribute_unallocated_task.php index 1eedbea6..cd9e2c5c 100644 --- a/classes/task/distribute_unallocated_task.php +++ b/classes/task/distribute_unallocated_task.php @@ -38,7 +38,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class distribute_unallocated_task extends adhoc_task { - /** * Executes the distribution of unallocated users. * @@ -50,8 +49,10 @@ public function execute(): void { require_once($CFG->dirroot . '/mod/ratingallocate/locallib.php'); $data = $this->get_custom_data(); - if (empty($data->distributionalgorithm) || - !in_array($data->distributionalgorithm, [ACTION_DISTRIBUTE_UNALLOCATED_EQUALLY, ACTION_DISTRIBUTE_UNALLOCATED_FILL])) { + if ( + empty($data->distributionalgorithm) || + !in_array($data->distributionalgorithm, [ACTION_DISTRIBUTE_UNALLOCATED_EQUALLY, ACTION_DISTRIBUTE_UNALLOCATED_FILL]) + ) { mtrace('No distribution algorithm has been specified, exiting.'); return; } diff --git a/classes/task/send_distribution_notification.php b/classes/task/send_distribution_notification.php index 564db8c8..20c90e69 100644 --- a/classes/task/send_distribution_notification.php +++ b/classes/task/send_distribution_notification.php @@ -37,7 +37,6 @@ * @package mod_ratingallocate */ class send_distribution_notification extends \core\task\adhoc_task { - /** * Gets executed by the task runner. Will lookup the ratingallocation object and command it * to notify users. @@ -58,8 +57,12 @@ public function execute() { // Get instance of ratingallocate. $ratingallocate = - $DB->get_record(this_db\ratingallocate::TABLE, [this_db\ratingallocate::ID => $ratingallocateid], '*', - MUST_EXIST); + $DB->get_record( + this_db\ratingallocate::TABLE, + [this_db\ratingallocate::ID => $ratingallocateid], + '*', + MUST_EXIST + ); $courseid = $ratingallocate->course; $course = get_course($courseid); @@ -69,7 +72,5 @@ public function execute() { $ratingallocateobj = new ratingallocate($ratingallocate, $course, $cm, $context); $ratingallocateobj->notify_users_distribution(); - } } - diff --git a/classes/wrapper/ratingallocate_db_wrapper.php b/classes/wrapper/ratingallocate_db_wrapper.php index a2a846b5..211939ae 100644 --- a/classes/wrapper/ratingallocate_db_wrapper.php +++ b/classes/wrapper/ratingallocate_db_wrapper.php @@ -47,7 +47,6 @@ * @property string $setting */ class ratingallocate_db_wrapper { - /** @var stdClass */ public $dbrecord; @@ -79,5 +78,4 @@ public function __set($name, $value) { public function __construct($record) { $this->dbrecord = $record; } - } diff --git a/db/access.php b/db/access.php index 956b4b58..2ffccd5a 100644 --- a/db/access.php +++ b/db/access.php @@ -111,6 +111,3 @@ ], ], ]; - - - diff --git a/db/upgrade.php b/db/upgrade.php index ce9b603e..938d901c 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -70,7 +70,6 @@ function xmldb_ratingallocate_upgrade($oldversion) { } if ($oldversion < 2014111800) { - // Define field notification_send to be added to ratingallocate. $table = new xmldb_table('ratingallocate'); $field = new xmldb_field('notificationsend', XMLDB_TYPE_INTEGER, '4', null, null, null, '0', 'published'); @@ -129,11 +128,9 @@ function xmldb_ratingallocate_upgrade($oldversion) { $transaction->rollback($e); return false; } - } if ($oldversion < 2021062900) { - // Changing type of field explanation on table ratingallocate_choices to text. $table = new xmldb_table('ratingallocate_choices'); $field = new xmldb_field('explanation', XMLDB_TYPE_TEXT, null, null, null, null, null, 'title'); @@ -146,7 +143,6 @@ function xmldb_ratingallocate_upgrade($oldversion) { } if ($oldversion < 2022120100) { - // Define table ratingallocate_group_choices to be created. $table = new xmldb_table('ratingallocate_group_choices'); @@ -179,7 +175,6 @@ function xmldb_ratingallocate_upgrade($oldversion) { } if ($oldversion < 2023050900) { - // Define table ratingallocate_ch_gengroups to be created. $table = new xmldb_table('ratingallocate_ch_gengroups'); @@ -221,7 +216,6 @@ function xmldb_ratingallocate_upgrade($oldversion) { } if ($oldversion < 2024080900) { - // 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'); diff --git a/form_manual_allocation.php b/form_manual_allocation.php index 3caaf799..5b34b659 100644 --- a/form_manual_allocation.php +++ b/form_manual_allocation.php @@ -36,7 +36,6 @@ * Provides a form for manual allocations */ class manual_alloc_form extends moodleform { - /** @var $ratingallocate ratingallocate */ private $ratingallocate; @@ -92,14 +91,22 @@ protected function render_filter() { global $COURSE; $mform = &$this->_form; - $mform->addElement('advcheckbox', 'hide_users_without_rating', - get_string('filter_hide_users_without_rating', RATINGALLOCATE_MOD_NAME), - null, [0, 1]); + $mform->addElement( + 'advcheckbox', + 'hide_users_without_rating', + get_string('filter_hide_users_without_rating', RATINGALLOCATE_MOD_NAME), + null, + [0, 1] + ); $mform->setType('show_users_with_no_rating', PARAM_BOOL); - $mform->addElement('advcheckbox', 'show_alloc_necessary', - get_string('filter_show_alloc_necessary', RATINGALLOCATE_MOD_NAME), - null, [0, 1]); + $mform->addElement( + 'advcheckbox', + 'show_alloc_necessary', + get_string('filter_show_alloc_necessary', RATINGALLOCATE_MOD_NAME), + null, + [0, 1] + ); $mform->setType('show_alloc_necessary', PARAM_BOOL); // Filter by group. @@ -118,8 +125,11 @@ protected function render_filter() { $mform->addHelpButton('filtergroup', 'filtergroup', RATINGALLOCATE_MOD_NAME); } - $mform->addElement('submit', 'update_filter', - get_string('update_filter', RATINGALLOCATE_MOD_NAME)); + $mform->addElement( + 'submit', + 'update_filter', + get_string('update_filter', RATINGALLOCATE_MOD_NAME) + ); $mform->registerNoSubmitButton('update_filter'); } @@ -155,11 +165,20 @@ public function definition_after_data() { } // Create and set up the flextable for ratings and allocations. - $table = new mod_ratingallocate\ratings_and_allocations_table($this->ratingallocate->get_renderer(), - $this->ratingallocate->get_options_titles($differentratings), $this->ratingallocate, - 'manual_allocation', 'mod_ratingallocate_manual_allocation', false); - $table->setup_table($this->ratingallocate->get_rateable_choices(), - $hidenorating, $showallocnecessary, $groupselect); + $table = new mod_ratingallocate\ratings_and_allocations_table( + $this->ratingallocate->get_renderer(), + $this->ratingallocate->get_options_titles($differentratings), + $this->ratingallocate, + 'manual_allocation', + 'mod_ratingallocate_manual_allocation', + false + ); + $table->setup_table( + $this->ratingallocate->get_rateable_choices(), + $hidenorating, + $showallocnecessary, + $groupselect + ); $filter = $table->get_filter(); @@ -217,5 +236,4 @@ public function to_html() { $o .= $this->_form->toHtml(); return $o; } - } diff --git a/form_modify_choice.php b/form_modify_choice.php index 70e12b26..1556a713 100644 --- a/form_modify_choice.php +++ b/form_modify_choice.php @@ -32,7 +32,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class modify_choice_form extends moodleform { - /** @var $ratingallocate ratingallocate */ private $ratingallocate; @@ -56,8 +55,12 @@ class modify_choice_form extends moodleform { * @return void * @throws coding_exception */ - public function __construct($url, ratingallocate $ratingallocate, - ?ratingallocate_choice $choice, ?array $customdata) { + public function __construct( + $url, + ratingallocate $ratingallocate, + ?ratingallocate_choice $choice, + ?array $customdata + ) { $this->ratingallocate = $ratingallocate; if ($choice) { $this->choice = $choice; @@ -87,8 +90,12 @@ public function definition() { $mform->setType($elementname, PARAM_TEXT); $mform->addHelpButton($elementname, 'choice_title', RATINGALLOCATE_MOD_NAME); $mform->addRule($elementname, get_string('err_required', 'form'), 'required', null, 'server'); - $mform->addRule($elementname, get_string('title_too_long_error', RATINGALLOCATE_MOD_NAME), - 'maxlength', '255'); + $mform->addRule( + $elementname, + get_string('title_too_long_error', RATINGALLOCATE_MOD_NAME), + 'maxlength', + '255' + ); $elementname = 'explanation'; $editoroptions = [ @@ -112,19 +119,35 @@ public function definition() { $this->set_data($this->_customdata['attachment_data']); $elementname = 'active'; - $mform->addElement('advcheckbox', $elementname, get_string('choice_active', RATINGALLOCATE_MOD_NAME), - null, null, [0, 1]); + $mform->addElement( + 'advcheckbox', + $elementname, + get_string('choice_active', RATINGALLOCATE_MOD_NAME), + null, + null, + [0, 1] + ); $mform->addHelpButton($elementname, 'choice_active', RATINGALLOCATE_MOD_NAME); $elementname = 'usegroups'; - $mform->addelement('advcheckbox', $elementname, get_string('choice_usegroups', RATINGALLOCATE_MOD_NAME), - null, null, [0, 1]); + $mform->addelement( + 'advcheckbox', + $elementname, + get_string('choice_usegroups', RATINGALLOCATE_MOD_NAME), + null, + null, + [0, 1] + ); $mform->addHelpButton($elementname, 'choice_usegroups', RATINGALLOCATE_MOD_NAME); $elementname = 'groupselector'; $options = $this->ratingallocate->get_group_selections(); - $selector = $mform->addelement('searchableselector', $elementname, - get_string('choice_groupselect', RATINGALLOCATE_MOD_NAME), $options); + $selector = $mform->addelement( + 'searchableselector', + $elementname, + get_string('choice_groupselect', RATINGALLOCATE_MOD_NAME), + $options + ); $selector->setMultiple(true); $mform->hideIf('groupselector', 'usegroups'); @@ -157,8 +180,11 @@ public function add_buttons() { $buttonarray = []; $buttonarray[] = &$mform->createElement('submit', 'submitbutton', get_string('savechanges')); if ($this->addnew) { - $buttonarray[] = &$mform->createElement('submit', 'submitbutton2', - get_string('saveandnext', RATINGALLOCATE_MOD_NAME)); + $buttonarray[] = &$mform->createElement( + 'submit', + 'submitbutton2', + get_string('saveandnext', RATINGALLOCATE_MOD_NAME) + ); } $buttonarray[] = &$mform->createElement('cancel'); $mform->addGroup($buttonarray, 'buttonar', '', [' '], false); @@ -186,5 +212,4 @@ public function validation($data, $files) { $errors = parent::validation($data, $files); return $errors; } - } diff --git a/form_upload_choices.php b/form_upload_choices.php index d9db477f..8a592c8e 100644 --- a/form_upload_choices.php +++ b/form_upload_choices.php @@ -35,7 +35,6 @@ * A form to upload multiple choices */ class upload_choices_form extends moodleform { - /** @var $ratingallocate ratingallocate */ private $ratingallocate; @@ -57,18 +56,32 @@ public function definition() { $requiredfields = choice_importer::print_fields(); $elementname = 'description'; - $mform->addElement('static', $elementname, get_string('upload_choices_required_fields', 'ratingallocate'), - get_string('upload_choices_fields_desc', 'ratingallocate', $requiredfields)); + $mform->addElement( + 'static', + $elementname, + get_string('upload_choices_required_fields', 'ratingallocate'), + get_string('upload_choices_fields_desc', 'ratingallocate', $requiredfields) + ); $elementname = 'uploadfile'; - $mform->addElement('filepicker', $elementname, get_string('csvupload', 'ratingallocate'), null, + $mform->addElement( + 'filepicker', + $elementname, + get_string('csvupload', 'ratingallocate'), + null, ['accepted_types' => 'text/csv'] ); - $mform->addRule($elementname, get_string('err_required', 'form') , 'required', null, 'server'); + $mform->addRule($elementname, get_string('err_required', 'form'), 'required', null, 'server'); $elementname = 'testimport'; - $mform->addElement('advcheckbox', $elementname, get_string('csvupload_test_upload', 'ratingallocate'), - null, null, [0, 1]); + $mform->addElement( + 'advcheckbox', + $elementname, + get_string('csvupload_test_upload', 'ratingallocate'), + null, + null, + [0, 1] + ); $mform->addHelpButton($elementname, 'csvupload_test_upload', 'ratingallocate'); $this->add_buttons(); diff --git a/grade.php b/grade.php index a1efbe12..5f07b722 100644 --- a/grade.php +++ b/grade.php @@ -28,8 +28,11 @@ require_login(); $id = required_param('id', PARAM_INT); // Course module ID. -$itemnumber = optional_param('itemnumber', 0, - PARAM_INT); // Item number, may be != 0 for activities that allow more than one grade per user. +$itemnumber = optional_param( + 'itemnumber', + 0, + PARAM_INT +); // Item number, may be != 0 for activities that allow more than one grade per user. $userid = optional_param('userid', 0, PARAM_INT); // Graded user ID (optional). // In the simplest case just redirect to the view page. diff --git a/index.php b/index.php index d3ff70ef..f773a2d6 100644 --- a/index.php +++ b/index.php @@ -52,12 +52,15 @@ require_capability('mod/ratingallocate:view', $coursecontext); $event = index_viewed::create_simple( - context_course::instance($course->id)); + context_course::instance($course->id) +); $event->trigger(); if (!$ratingallocates = get_all_instances_in_course('ratingallocate', $course, $USER->id)) { - notice(get_string('noratingallocates', RATINGALLOCATE_MOD_NAME), - new moodle_url('/course/view.php', ['id' => $course->id])); + notice( + get_string('noratingallocates', RATINGALLOCATE_MOD_NAME), + new moodle_url('/course/view.php', ['id' => $course->id]) + ); } $table = new html_table(); @@ -72,18 +75,19 @@ $ratingallocateinstance = $DB->get_record('ratingallocate', ['id' => $ratingallocate->id]); if (!$ratingallocate->visible) { $link = html_writer::link( - new moodle_url('/mod/ratingallocate/view.php', ['id' => $ratingallocate->coursemodule]), - format_string($ratingallocate->name, true), - ['class' => 'dimmed']); + new moodle_url('/mod/ratingallocate/view.php', ['id' => $ratingallocate->coursemodule]), + format_string($ratingallocate->name, true), + ['class' => 'dimmed'] + ); } else { $link = html_writer::link( - new moodle_url('/mod/ratingallocate/view.php', ['id' => $ratingallocate->coursemodule]), - format_string($ratingallocate->name, true)); + new moodle_url('/mod/ratingallocate/view.php', ['id' => $ratingallocate->coursemodule]), + format_string($ratingallocate->name, true) + ); } $table->data[] = [$link, userdate($ratingallocateinstance->accesstimestart), userdate($ratingallocateinstance->accesstimestop), $ratingallocateinstance->published == 0 ? get_string('no') : get_string('yes')]; - } echo html_writer::table($table); diff --git a/lang/en/ratingallocate.php b/lang/en/ratingallocate.php index 0738d45a..830a670a 100644 --- a/lang/en/ratingallocate.php +++ b/lang/en/ratingallocate.php @@ -414,39 +414,3 @@ $string['you_are_not_allocated'] = 'You were not allocated to any choice!'; $string['your_allocated_choice'] = 'Your Allocation'; $string['your_rating'] = 'Your Rating'; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/lib.php b/lib.php index 6420addc..371b004b 100644 --- a/lib.php +++ b/lib.php @@ -63,9 +63,9 @@ function ratingallocate_supports($feature) { } switch ($feature) { - case FEATURE_MOD_INTRO : + case FEATURE_MOD_INTRO: return true; - case FEATURE_SHOW_DESCRIPTION : + case FEATURE_SHOW_DESCRIPTION: return true; case FEATURE_BACKUP_MOODLE2: return true; @@ -73,7 +73,7 @@ function ratingallocate_supports($feature) { return true; case FEATURE_COMPLETION_HAS_RULES: return true; - default : + default: return null; } } @@ -163,9 +163,11 @@ function ratingallocate_update_instance(stdClass $ratingallocate, ?mod_ratingall function ratingallocate_delete_instance($id) { global $DB; - if (!$ratingallocate = $DB->get_record('ratingallocate', [ + if ( + !$ratingallocate = $DB->get_record('ratingallocate', [ 'id' => $id, - ])) { + ]) + ) { return false; } @@ -179,11 +181,17 @@ function ratingallocate_delete_instance($id) { ], '', 'id')); if (!empty($deleteids)) { - list ($insql, $params) = $DB->get_in_or_equal($deleteids); - $DB->delete_records_select('ratingallocate_group_choices', - 'choiceid ' . $insql, $params); - $DB->delete_records_select('ratingallocate_ch_gengroups', - 'choiceid ' . $insql, $params); + [$insql, $params] = $DB->get_in_or_equal($deleteids); + $DB->delete_records_select( + 'ratingallocate_group_choices', + 'choiceid ' . $insql, + $params + ); + $DB->delete_records_select( + 'ratingallocate_ch_gengroups', + 'choiceid ' . $insql, + $params + ); } $DB->delete_records('ratingallocate_groupings', [ @@ -234,8 +242,15 @@ function ratingallocate_print_recent_activity($course, $viewfullnames, $timestar * @param int $groupid check for a particular group's activity only, defaults to 0 (all groups) * @return void adds items into $activities and increases $index */ -function ratingallocate_get_recent_mod_activity(&$activities, &$index, $timestart, $courseid, $cmid, - $userid = 0, $groupid = 0) { +function ratingallocate_get_recent_mod_activity( + &$activities, + &$index, + $timestart, + $courseid, + $cmid, + $userid = 0, + $groupid = 0 +) { } /** @@ -249,7 +264,6 @@ function ratingallocate_get_recent_mod_activity(&$activities, &$index, $timestar * @return void */ function ratingallocate_print_recent_mod_activity($activity, $courseid, $detail, $modnames, $viewfullnames) { - } /** @@ -375,7 +389,6 @@ function ratingallocate_pluginfile($course, $cm, $context, $filearea, array $arg * @return void */ function ratingallocate_extend_navigation(navigation_node $navref, stdClass $course, stdClass $module, cm_info $cm) { - } /** @@ -395,21 +408,28 @@ function ratingallocate_extend_settings_navigation(settings_navigation $settings throw new \moodle_exception('badcontext'); } if (has_capability('mod/ratingallocate:modify_choices', $context)) { - $choicenode = navigation_node::create(get_string('choice_navigation', RATINGALLOCATE_MOD_NAME), + $choicenode = navigation_node::create( + get_string('choice_navigation', RATINGALLOCATE_MOD_NAME), new moodle_url('/mod/ratingallocate/view.php', ['id' => $settingsnav->get_page()->cm->id, 'action' => ACTION_SHOW_CHOICES]), - navigation_node::TYPE_CUSTOM, null, 'mod_ratingallocate_choices'); + navigation_node::TYPE_CUSTOM, + null, + 'mod_ratingallocate_choices' + ); $ratingallocatenode->add_node($choicenode); } if (has_capability('mod/ratingallocate:start_distribution', $context)) { - $reportsnode = navigation_node::create(get_string('reports_group', RATINGALLOCATE_MOD_NAME), + $reportsnode = navigation_node::create( + get_string('reports_group', RATINGALLOCATE_MOD_NAME), new moodle_url('/mod/ratingallocate/view.php', ['id' => $settingsnav->get_page()->cm->id, 'action' => ACTION_SHOW_RATINGS_AND_ALLOCATION_TABLE]), - navigation_node::TYPE_CUSTOM, null, 'mod_ratingallocate_reports'); + navigation_node::TYPE_CUSTOM, + null, + 'mod_ratingallocate_reports' + ); $ratingallocatenode->add_node($reportsnode); } - } /** @@ -467,19 +487,21 @@ function ratingallocate_refresh_events($courseid = 0, $instance = null, $cm = nu function ratingallocate_set_events($ratingallocate) { global $DB, $CFG; - require_once($CFG->dirroot.'/calendar/lib.php'); + require_once($CFG->dirroot . '/calendar/lib.php'); // Get CMID if not sent as part of $ratingallocate. if (!isset($ratingallocate->coursemodule)) { - $cm = get_fast_modinfo($ratingallocate->course)->instances['ratingallocate'][$ratingallocate->id]; $ratingallocate->coursemodule = $cm->id; } // Ratingallocate-accessstart calendar events. - $eventid = $DB->get_field('event', 'id', - ['modulename' => 'ratingallocate', 'instance' => $ratingallocate->id, 'eventtype' => RATINGALLOCATE_EVENT_TYPE_START]); + $eventid = $DB->get_field( + 'event', + 'id', + ['modulename' => 'ratingallocate', 'instance' => $ratingallocate->id, 'eventtype' => RATINGALLOCATE_EVENT_TYPE_START] + ); $timestart = $DB->get_field('ratingallocate', 'accesstimestart', ['id' => $ratingallocate->id]); @@ -522,8 +544,11 @@ function ratingallocate_set_events($ratingallocate) { } // Ratingallocate-accessstop calendar events. - $eventid = $DB->get_field('event', 'id', - ['modulename' => 'ratingallocate', 'instance' => $ratingallocate->id, 'eventtype' => RATINGALLOCATE_EVENT_TYPE_STOP]); + $eventid = $DB->get_field( + 'event', + 'id', + ['modulename' => 'ratingallocate', 'instance' => $ratingallocate->id, 'eventtype' => RATINGALLOCATE_EVENT_TYPE_STOP] + ); $timestop = $DB->get_field('ratingallocate', 'accesstimestop', ['id' => $ratingallocate->id]); @@ -591,7 +616,6 @@ function mod_ratingallocate_core_is_event_visible(calendar_event $event): bool { $raters = $ratingallocate->get_raters_in_course(); return in_array($USER, $raters); - } /** @@ -604,7 +628,7 @@ function mod_ratingallocate_core_is_event_visible(calendar_event $event): bool { * @throws dml_exception * @throws moodle_exception */ -function mod_ratingallocate_core_calendar_event_timestart_updated (\calendar_event $event, \stdClass $ratingallocate) { +function mod_ratingallocate_core_calendar_event_timestart_updated(\calendar_event $event, \stdClass $ratingallocate) { global $CFG, $DB; @@ -672,7 +696,7 @@ function mod_ratingallocate_core_calendar_event_timestart_updated (\calendar_eve * @throws coding_exception * @throws dml_exception */ -function mod_ratingallocate_core_calendar_get_valid_event_timestart_range (\calendar_event $event, \stdClass $instance): array { +function mod_ratingallocate_core_calendar_get_valid_event_timestart_range(\calendar_event $event, \stdClass $instance): array { global $DB; @@ -711,7 +735,6 @@ function ratingallocate_reset_userdata($data) { $params = ['courseid' => $data->courseid]; if (!empty($data->reset_ratings_and_allocations)) { - // Delete all ratings. $ratingidssql = "SELECT r.id FROM {ratingallocate_ratings} r INNER JOIN {ratingallocate_choices} c ON r.choiceid=c.id @@ -763,9 +786,11 @@ function ratingallocate_reset_userdata($data) { function ratingallocate_reset_course_form_definition($mform) { $mform->addElement('header', 'ratingallocateheader', get_string('modulenameplural', RATINGALLOCATE_MOD_NAME)); - $mform->addElement('advcheckbox', 'reset_ratings_and_allocations', - get_string('remove_ratings_and_allocations', RATINGALLOCATE_MOD_NAME)); - + $mform->addElement( + 'advcheckbox', + 'reset_ratings_and_allocations', + get_string('remove_ratings_and_allocations', RATINGALLOCATE_MOD_NAME) + ); } /** diff --git a/locallib.php b/locallib.php index 9fee9db3..3a16b59a 100644 --- a/locallib.php +++ b/locallib.php @@ -89,8 +89,12 @@ function groups_delete_group_members_by_group($groupid): bool { $groups = $DB->get_recordset('groups', ['id' => $groupid]); foreach ($groups as $group) { - $userids = $DB->get_fieldset_select('groups_members', 'userid', 'groupid = :groupid', - ['groupid' => $group->id]); + $userids = $DB->get_fieldset_select( + 'groups_members', + 'userid', + 'groupid = :groupid', + ['groupid' => $group->id] + ); // Very ugly hack because some group-management functions are not provided in lib/grouplib.php // but does not add too much overhead since it does not include more files... diff --git a/mod_form.php b/mod_form.php index 78f10b71..a44c3c62 100644 --- a/mod_form.php +++ b/mod_form.php @@ -118,8 +118,13 @@ public function definition() { foreach (strategymanager::get_strategies() as $strategy) { $selectoptions[$strategy] = get_string($strategy . '_name', self::MOD_NAME); } - $mform->addElement('select', $elementname, get_string('select_strategy', self::MOD_NAME), $selectoptions, - $disablestrategy ? ['disabled' => ''] : null); + $mform->addElement( + 'select', + $elementname, + get_string('select_strategy', self::MOD_NAME), + $selectoptions, + $disablestrategy ? ['disabled' => ''] : null + ); $mform->addHelpButton($elementname, 'select_strategy', self::MOD_NAME); if (!$disablestrategy) { // Disabled elements don't get posted so disable the required rule if strategy selection is disabled. @@ -135,8 +140,12 @@ public function definition() { $mform->setDefault($elementname, time() + 7 * 24 * 60 * 60); // Default: now + one week. $elementname = 'publishdate'; - $mform->addElement('date_time_selector', $elementname, get_string($elementname, self::MOD_NAME), - ['optional' => true]); + $mform->addElement( + 'date_time_selector', + $elementname, + get_string($elementname, self::MOD_NAME), + ['optional' => true] + ); $mform->setDefault($elementname, time() + 9 * 24 * 60 * 60); $elementname = 'runalgorithmbycron'; @@ -268,18 +277,21 @@ public function definition_after_data() { foreach ($dynamicsettingsfields as $key => $value) { $fieldid = $this->get_settingsfield_identifier($strategy, $key); $this->add_settings_field($fieldid, $value, $strategy, $mform); - $mform->insertElementBefore($mform->removeElement($fieldid, false), - $strategyplaceholder); + $mform->insertElementBefore( + $mform->removeElement($fieldid, false), + $strategyplaceholder + ); } // If any dynamic field is present, add a no submit button to refresh the page. if (count($dynamicsettingsfields) > 0) { $buttonname = self::STRATEGY_OPTIONS . $strategy . 'refresh'; $mform->registerNoSubmitButton($buttonname); $mform->addElement('submit', $buttonname, get_string('refresh')); - $mform->insertElementBefore($mform->removeElement($buttonname, false), - $strategyplaceholder); + $mform->insertElementBefore( + $mform->removeElement($buttonname, false), + $strategyplaceholder + ); $mform->hideIf($buttonname, 'strategy', 'neq', $strategy); - } $mform->removeElement($strategyplaceholder); } @@ -352,11 +364,17 @@ public function add_completion_rules() { $mform = $this->_form; $mform->addElement( - 'advcheckbox', $this->get_suffixed_name('vote'), ' ', - get_string('completionvote', RATINGALLOCATE_MOD_NAME)); + '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)); + '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); @@ -433,5 +451,4 @@ public function data_postprocessing($data) { } } } - } diff --git a/renderable.php b/renderable.php index b463c056..a16a58cd 100644 --- a/renderable.php +++ b/renderable.php @@ -65,7 +65,6 @@ public function __construct(ratingallocate_db_wrapper $ratingallocate, $context, * @package mod_ratingallocate */ class ratingallocate_choice_status implements renderable { - /** @var $accesstimestop */ public $accesstimestop; /** @var $accesstimestart */ diff --git a/renderer.php b/renderer.php index 4d2566d1..cb110208 100644 --- a/renderer.php +++ b/renderer.php @@ -31,7 +31,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class mod_ratingallocate_renderer extends plugin_renderer_base { - /** * @var array rendered notifications to output for handle_view() */ @@ -124,25 +123,27 @@ public function render_ratingallocate_allocation_status($coursemoduleid, $status $table = new html_table(); // Add status, buttons for manual and algorithmic allocation and delete all ratings button to the table. - $this->add_table_row_triple($table, + $this->add_table_row_triple( + $table, $description, $this->render($button) . '
' . '
' . $this->single_button( new moodle_url( '/mod/ratingallocate/view.php', ['id' => $coursemoduleid, - 'action' => ACTION_MANUAL_ALLOCATION]), - get_string('manual_allocation_form', - RATINGALLOCATE_MOD_NAME), - 'get', - ['disabled' => !$ratingover || $isdistributionrunning] + 'action' => ACTION_MANUAL_ALLOCATION] + ), + get_string( + 'manual_allocation_form', + RATINGALLOCATE_MOD_NAME ), + 'get', + ['disabled' => !$ratingover || $isdistributionrunning] + ), $this->render($deletebutton) ); if (has_capability('mod/ratingallocate:distribute_unallocated', context_module::instance($coursemoduleid))) { - if ($ratingover && $undistributeduserscount != 0 && !$isdistributionrunning) { - // Add empty row. $this->add_table_row_triple($table, '', '', ''); @@ -150,39 +151,49 @@ public function render_ratingallocate_allocation_status($coursemoduleid, $status $this->page->url, ['action' => ACTION_DISTRIBUTE_UNALLOCATED_EQUALLY] ); - $buttondisteq = new single_button($distributeunallocatedurleq, - get_string('distributeequally', RATINGALLOCATE_MOD_NAME), 'get'); + $buttondisteq = new single_button( + $distributeunallocatedurleq, + get_string('distributeequally', RATINGALLOCATE_MOD_NAME), + 'get' + ); $buttondisteq->class = 'ratingallocate_front_page_buttons'; $buttondisteq->add_action(new confirm_action( - get_string('distribute_unallocated_equally_confirm', RATINGALLOCATE_MOD_NAME))); + get_string('distribute_unallocated_equally_confirm', RATINGALLOCATE_MOD_NAME) + )); $distributeunallocatedurlfill = new moodle_url( $this->page->url, ['action' => ACTION_DISTRIBUTE_UNALLOCATED_FILL] ); - $buttondistfill = new single_button($distributeunallocatedurlfill, - get_string('distributefill', RATINGALLOCATE_MOD_NAME), 'get'); + $buttondistfill = new single_button( + $distributeunallocatedurlfill, + get_string('distributefill', RATINGALLOCATE_MOD_NAME), + 'get' + ); $buttondistfill->class = 'ratingallocate_front_page_buttons'; $buttondistfill->add_action(new confirm_action( - get_string('distribute_unallocated_fill_confirm', RATINGALLOCATE_MOD_NAME))); + get_string('distribute_unallocated_fill_confirm', RATINGALLOCATE_MOD_NAME) + )); // Add Amount of users that are unallocated and buttons to allocate them manually. - $this->add_table_row_triple($table, - get_string('unallocated_user_count', + $this->add_table_row_triple( + $table, + get_string( + 'unallocated_user_count', RATINGALLOCATE_MOD_NAME, - ['count' => $undistributeduserscount]) . + ['count' => $undistributeduserscount] + ) . $this->help_icon('distribution_description', RATINGALLOCATE_MOD_NAME), $this->render($buttondisteq), $this->render($buttondistfill) ); - } else if ($isdistributionrunning) { - // Add empty row. $this->add_table_row_triple($table, '', '', ''); - $this->add_table_row_triple($table, + $this->add_table_row_triple( + $table, get_string('unallocated_user_count', RATINGALLOCATE_MOD_NAME, ['count' => $undistributeduserscount]), get_string('distribution_unallocated_already_running', RATINGALLOCATE_MOD_NAME), '' @@ -228,12 +239,17 @@ public function render_ratingallocate_publish_allocation($ratingallocateid, $cou $description = $this->format_text($description); } - $this->add_table_row_triple($table, + $this->add_table_row_triple( + $table, $description, - $this->single_button(new moodle_url('/mod/ratingallocate/view.php', ['id' => $coursemoduleid, + $this->single_button( + new moodle_url('/mod/ratingallocate/view.php', ['id' => $coursemoduleid, 'ratingallocateid' => $ratingallocateid, - 'action' => ACTION_PUBLISH_ALLOCATIONS]), get_string('publish_allocation', RATINGALLOCATE_MOD_NAME), 'get', - ['disabled' => !$isready]), + 'action' => ACTION_PUBLISH_ALLOCATIONS]), + get_string('publish_allocation', RATINGALLOCATE_MOD_NAME), + 'get', + ['disabled' => !$isready] + ), $this->single_button(new moodle_url('/mod/ratingallocate/view.php', ['id' => $coursemoduleid, 'ratingallocateid' => $ratingallocateid, 'action' => ACTION_ALLOCATION_TO_GROUPING]), get_string('create_moodle_groups', RATINGALLOCATE_MOD_NAME), 'get') @@ -289,20 +305,29 @@ public function render_ratingallocate_choice_status(ratingallocate_choice_status if ($status->ispublished && $status->publishdate) { $this->add_table_row_tuple($t, get_string('publishdate', RATINGALLOCATE_MOD_NAME), userdate($status->publishdate)); } else if ($status->publishdate) { - $this->add_table_row_tuple($t, get_string('publishdate_estimated', RATINGALLOCATE_MOD_NAME), - userdate($status->publishdate)); + $this->add_table_row_tuple( + $t, + get_string('publishdate_estimated', RATINGALLOCATE_MOD_NAME), + userdate($status->publishdate) + ); } if ($status->showdistributioninfo && $status->accesstimestop < $time) { // Print algorithm status and last run time. if ($status->algorithmstarttime) { - $this->add_table_row_tuple($t, get_string('last_algorithm_run_date', RATINGALLOCATE_MOD_NAME), - userdate($status->algorithmstarttime)); + $this->add_table_row_tuple( + $t, + get_string('last_algorithm_run_date', RATINGALLOCATE_MOD_NAME), + userdate($status->algorithmstarttime) + ); } else { $this->add_table_row_tuple($t, get_string('last_algorithm_run_date', RATINGALLOCATE_MOD_NAME), "-"); } - $this->add_table_row_tuple($t, get_string('last_algorithm_run_status', RATINGALLOCATE_MOD_NAME), - get_string('last_algorithm_run_status_' . $status->algorithmstatus, RATINGALLOCATE_MOD_NAME)); + $this->add_table_row_tuple( + $t, + get_string('last_algorithm_run_status', RATINGALLOCATE_MOD_NAME), + get_string('last_algorithm_run_status_' . $status->algorithmstatus, RATINGALLOCATE_MOD_NAME) + ); } // Print own choices or full list of available choices. @@ -352,12 +377,14 @@ public function render_ratingallocate_choice_status(ratingallocate_choice_status if (!empty($status->allocations)) { $row = new html_table_row(); $cell1 = new html_table_cell( - get_string('your_allocated_choice', RATINGALLOCATE_MOD_NAME)); + get_string('your_allocated_choice', RATINGALLOCATE_MOD_NAME) + ); $allocationhtml = ''; foreach ($status->allocations as $allocation) { $allocationhtml .= html_writer::span( - format_string($allocation->{this_db\ratingallocate_choices::TITLE}), - 'allocation tag tag-success'); + format_string($allocation->{this_db\ratingallocate_choices::TITLE}), + 'allocation tag tag-success' + ); $allocationhtml .= '
' . format_text($allocation->{this_db\ratingallocate_choices::EXPLANATION}); } $cell2 = new html_table_cell($allocationhtml); @@ -368,10 +395,12 @@ public function render_ratingallocate_choice_status(ratingallocate_choice_status if ($hasrating) { $row = new html_table_row(); $cell1 = new html_table_cell( - get_string('your_allocated_choice', RATINGALLOCATE_MOD_NAME)); + get_string('your_allocated_choice', RATINGALLOCATE_MOD_NAME) + ); $allocationhtml = html_writer::span( - get_string('you_are_not_allocated', RATINGALLOCATE_MOD_NAME), - 'allocation tag tag-danger'); + get_string('you_are_not_allocated', RATINGALLOCATE_MOD_NAME), + 'allocation tag tag-danger' + ); $cell2 = new html_table_cell($allocationhtml); $row->cells = [$cell1, $cell2]; $t->data[] = $row; @@ -398,14 +427,21 @@ public function render_ratingallocate_choice_status(ratingallocate_choice_status // If results already published. if ($status->ispublished == true) { if (count($status->allocations) > 0) { - $this->add_notification(get_string('rating_is_over_with_allocation', RATINGALLOCATE_MOD_NAME, - array_pop($status->allocations)->title), 'notifysuccess'); + $this->add_notification(get_string( + 'rating_is_over_with_allocation', + RATINGALLOCATE_MOD_NAME, + array_pop($status->allocations)->title + ), 'notifysuccess'); } else if ($hasrating) { - $this->add_notification(get_string('rating_is_over_no_allocation', RATINGALLOCATE_MOD_NAME), - 'notifyproblem'); + $this->add_notification( + get_string('rating_is_over_no_allocation', RATINGALLOCATE_MOD_NAME), + 'notifyproblem' + ); } else { - $this->add_notification(get_string('rating_is_over', RATINGALLOCATE_MOD_NAME), - 'notifymessage'); + $this->add_notification( + get_string('rating_is_over', RATINGALLOCATE_MOD_NAME), + 'notifymessage' + ); } } else { $this->add_notification(get_string('results_not_yet_published', RATINGALLOCATE_MOD_NAME), 'notifymessage'); @@ -482,8 +518,14 @@ public function modify_choices_group($ratingallocateid, $coursemoduleid, $status * @param string $algorithmstatus * @param bool $runalgorithmbycron */ - public function modify_allocation_group($ratingallocateid, $coursemoduleid, - $status, $undistributeduserscount, $algorithmstatus, $runalgorithmbycron) { + public function modify_allocation_group( + $ratingallocateid, + $coursemoduleid, + $status, + $undistributeduserscount, + $algorithmstatus, + $runalgorithmbycron + ) { $isdistributionrunning = $this->is_distribution_of_unallocated_users_running($coursemoduleid); $output = ''; $output .= $this->heading(get_string('modify_allocation_group', RATINGALLOCATE_MOD_NAME), 2); @@ -511,9 +553,13 @@ public function modify_allocation_group($ratingallocateid, $coursemoduleid, $output .= $this->render($button); - $output .= $this->single_button(new moodle_url('/mod/ratingallocate/view.php', ['id' => $coursemoduleid, - 'action' => ACTION_MANUAL_ALLOCATION]), get_string('manual_allocation_form', RATINGALLOCATE_MOD_NAME), 'get', - ['disabled' => !$ratingover || $isdistributionrunning]); + $output .= $this->single_button( + new moodle_url('/mod/ratingallocate/view.php', ['id' => $coursemoduleid, + 'action' => ACTION_MANUAL_ALLOCATION]), + get_string('manual_allocation_form', RATINGALLOCATE_MOD_NAME), + 'get', + ['disabled' => !$ratingover || $isdistributionrunning] + ); // Add delete all ratings button. $deletebutton = new single_button($deleteurl, get_string('delete_all_ratings', RATINGALLOCATE_MOD_NAME, 'get')); @@ -525,34 +571,41 @@ public function modify_allocation_group($ratingallocateid, $coursemoduleid, $output .= $this->render($deletebutton); if (has_capability('mod/ratingallocate:distribute_unallocated', context_module::instance($coursemoduleid))) { - $output .= html_writer::start_div('ratingallocate_distribute_unallocated'); $distributeunallocatedurl = new moodle_url($this->page->url, ['action' => ACTION_DISTRIBUTE_UNALLOCATED_EQUALLY]); - $button = new single_button($distributeunallocatedurl, - get_string('distributeequally', RATINGALLOCATE_MOD_NAME), 'get'); + $button = new single_button( + $distributeunallocatedurl, + get_string('distributeequally', RATINGALLOCATE_MOD_NAME), + 'get' + ); // Enable only if the instance is ready and the algorithm may run manually. $button->disabled = !($ratingover) || $undistributeduserscount === 0 || $isdistributionrunning; $button->add_action(new confirm_action( - get_string('distribute_unallocated_equally_confirm', RATINGALLOCATE_MOD_NAME))); + get_string('distribute_unallocated_equally_confirm', RATINGALLOCATE_MOD_NAME) + )); $output .= $this->render($button); $distributeunallocatedurl = new moodle_url($this->page->url, ['action' => ACTION_DISTRIBUTE_UNALLOCATED_FILL]); - $button = new single_button($distributeunallocatedurl, - get_string('distributefill', RATINGALLOCATE_MOD_NAME), 'get'); + $button = new single_button( + $distributeunallocatedurl, + get_string('distributefill', RATINGALLOCATE_MOD_NAME), + 'get' + ); // Enable only if the instance is ready, there are users to distribute and the algorithm may run manually. $button->disabled = !($ratingover) || $undistributeduserscount === 0 || $isdistributionrunning; $button->add_action(new confirm_action( - get_string('distribute_unallocated_fill_confirm', RATINGALLOCATE_MOD_NAME))); + get_string('distribute_unallocated_fill_confirm', RATINGALLOCATE_MOD_NAME) + )); $output .= $this->render($button); $output .= $this->help_icon('distribution_description', RATINGALLOCATE_MOD_NAME); if ($isdistributionrunning) { $output .= html_writer::div( - get_string('distribution_unallocated_already_running', RATINGALLOCATE_MOD_NAME), - 'alert alert-info m-3' + get_string('distribution_unallocated_already_running', RATINGALLOCATE_MOD_NAME), + 'alert alert-info m-3' ); } $output .= html_writer::end_div(); @@ -583,10 +636,14 @@ public function publish_allocation_group($ratingallocateid, $coursemoduleid, $st $output .= html_writer::empty_tag('br', []); - $output .= $this->single_button(new moodle_url('/mod/ratingallocate/view.php', ['id' => $coursemoduleid, + $output .= $this->single_button( + new moodle_url('/mod/ratingallocate/view.php', ['id' => $coursemoduleid, 'ratingallocateid' => $ratingallocateid, - 'action' => ACTION_PUBLISH_ALLOCATIONS]), get_string('publish_allocation', RATINGALLOCATE_MOD_NAME), 'get', - ['disabled' => !$isready]); + 'action' => ACTION_PUBLISH_ALLOCATIONS]), + get_string('publish_allocation', RATINGALLOCATE_MOD_NAME), + 'get', + ['disabled' => !$isready] + ); $output .= $this->single_button(new moodle_url('/mod/ratingallocate/view.php', ['id' => $coursemoduleid, 'ratingallocateid' => $ratingallocateid, @@ -612,7 +669,8 @@ public function reports_group($ratingallocateid, $coursemoduleid, $status, $cont $output .= $this->output->single_select( new moodle_url('/mod/ratingallocate/view.php', ['id' => $coursemoduleid]), - 'action', [ + 'action', + [ ACTION_SHOW_RATINGS_AND_ALLOCATION_TABLE => get_string('show_table', RATINGALLOCATE_MOD_NAME), ACTION_SHOW_ALLOCATION_TABLE => get_string('show_allocation_table', RATINGALLOCATE_MOD_NAME), ACTION_SHOW_STATISTICS => get_string('show_allocation_statistics', RATINGALLOCATE_MOD_NAME), @@ -695,8 +753,11 @@ public function ratingallocate_show_choices_table(ratingallocate $ratingallocate } if ($choicesmodifiably) { - $row[] = $this->render_tools($idx, $choice->{this_db\ratingallocate_choices::ACTIVE}, - $choice->{this_db\ratingallocate_choices::TITLE}); + $row[] = $this->render_tools( + $idx, + $choice->{this_db\ratingallocate_choices::ACTIVE}, + $choice->{this_db\ratingallocate_choices::TITLE} + ); } if (!$choice->{this_db\ratingallocate_choices::ACTIVE}) { $class = 'dimmed_text'; @@ -719,13 +780,14 @@ public function render_attachments($files, $break = false) { foreach ($files as $f) { $filename = $f->get_filename(); $url = moodle_url::make_pluginfile_url( - $f->get_contextid(), - $f->get_component(), - $f->get_filearea(), - $f->get_itemid(), - $f->get_filepath(), - $f->get_filename(), - false); + $f->get_contextid(), + $f->get_component(), + $f->get_filearea(), + $f->get_itemid(), + $f->get_filepath(), + $f->get_filename(), + false + ); $a = [ 'href' => $url, 'title' => $filename, @@ -761,9 +823,13 @@ private function render_tools($id, $active, $title) { } else { $tools .= $this->format_icon_link(ACTION_ENABLE_CHOICE, $id, 't/show', get_string('enable')); } - $tools .= $this->format_icon_link(ACTION_DELETE_CHOICE, $id, 't/delete', - get_string('delete_choice', RATINGALLOCATE_MOD_NAME), - new \confirm_action(get_string('deleteconfirm', RATINGALLOCATE_MOD_NAME, $title))); + $tools .= $this->format_icon_link( + ACTION_DELETE_CHOICE, + $id, + 't/delete', + get_string('delete_choice', RATINGALLOCATE_MOD_NAME), + new \confirm_action(get_string('deleteconfirm', RATINGALLOCATE_MOD_NAME, $title)) + ); return $tools; } @@ -781,10 +847,15 @@ private function render_tools($id, $active, $title) { private function format_icon_link($action, $choice, $icon, $alt, $confirm = null) { $url = $this->page->url; - return $this->output->action_icon(new \moodle_url($url, - ['action' => $action, 'choiceid' => $choice, 'sesskey' => sesskey()]), - new \pix_icon($icon, $alt, 'moodle', ['title' => $alt]), - $confirm, ['title' => $alt]) . ' '; + return $this->output->action_icon( + new \moodle_url( + $url, + ['action' => $action, 'choiceid' => $choice, 'sesskey' => sesskey()] + ), + new \pix_icon($icon, $alt, 'moodle', ['title' => $alt]), + $confirm, + ['title' => $alt] + ) . ' '; } /** @@ -796,8 +867,12 @@ private function format_icon_link($action, $choice, $icon, $alt, $confirm = null * @return string */ public function render_header($ratingallocate, $context, $coursemodid) { - $headerinfo = new ratingallocate_header($ratingallocate, $context, true, - $coursemodid); + $headerinfo = new ratingallocate_header( + $ratingallocate, + $context, + true, + $coursemodid + ); return $this->render($headerinfo); } @@ -869,19 +944,24 @@ public function statistics_table_for_ratingallocate(ratingallocate $ratingalloca $activeraters = $ratingallocate->get_number_of_active_raters(); $notrated = count($usersinchoice) - $activeraters; if (count($distributiondata) == 0) { - $output .= $this->format_text(get_string('allocation_statistics_description_no_alloc', - RATINGALLOCATE_MOD_NAME, - ['notrated' => $notrated, 'rated' => $activeraters])); + $output .= $this->format_text(get_string( + 'allocation_statistics_description_no_alloc', + RATINGALLOCATE_MOD_NAME, + ['notrated' => $notrated, 'rated' => $activeraters] + )); } else { - $output .= $this->format_text(get_string('allocation_statistics_description', RATINGALLOCATE_MOD_NAME, - ['users' => $distributiondata[max(array_keys($distributiondata))], + $output .= $this->format_text(get_string( + 'allocation_statistics_description', + RATINGALLOCATE_MOD_NAME, + ['users' => $distributiondata[max(array_keys($distributiondata))], 'usersinchoice' => count($usersinchoice), 'total' => count($memberships), 'notrated' => $notrated, 'rated' => $activeraters, 'rating' => $titles[max(array_keys($distributiondata))], 'unassigned' => count($ratingallocate->get_undistributed_users()), - ])); + ] + )); $output .= html_writer::table($allocationtable); } $output .= $this->box_end(); @@ -908,8 +988,10 @@ public function allocation_table_for_ratingallocate($ratingallocate) { ob_end_clean(); $output = $this->heading(get_string('allocations_table', RATINGALLOCATE_MOD_NAME), 2); - $output .= $this->format_text(get_string('allocation_table_description', - RATINGALLOCATE_MOD_NAME)); + $output .= $this->format_text(get_string( + 'allocation_table_description', + RATINGALLOCATE_MOD_NAME + )); $output .= $this->box_start(); $output .= $this->box($tableoutput); $output .= $this->box_end(); @@ -933,7 +1015,7 @@ public function allocation_table_for_ratingallocate($ratingallocate) { public function ratings_table_for_ratingallocate($choices, $ratings, $users, $memberships, $ratingallocate) { // Get rating titles. - $titles = $this->get_options_titles(array_map(function($rating) { + $titles = $this->get_options_titles(array_map(function ($rating) { return $rating->rating; }, $ratings), $ratingallocate); diff --git a/settings.php b/settings.php index 65d0fe1f..7ed7b9ab 100644 --- a/settings.php +++ b/settings.php @@ -24,30 +24,39 @@ defined('MOODLE_INTERNAL') || die; if ($ADMIN->fulltree) { - $settings->add(new admin_setting_configtext('ratingallocate_algorithm_timeout', - get_string('algorithmtimeout', 'ratingallocate'), - get_string('configalgorithmtimeout', 'ratingallocate'), 600, PARAM_INT)); + $settings->add(new admin_setting_configtext( + 'ratingallocate_algorithm_timeout', + get_string('algorithmtimeout', 'ratingallocate'), + get_string('configalgorithmtimeout', 'ratingallocate'), + 600, + PARAM_INT + )); - $settings->add(new admin_setting_configmulticheckbox('ratingallocate_download_userfields', - new lang_string('downloaduserfields', 'ratingallocate'), - new lang_string('configdownloaduserfields', 'ratingallocate'), - [ + $settings->add(new admin_setting_configmulticheckbox( + 'ratingallocate_download_userfields', + new lang_string('downloaduserfields', 'ratingallocate'), + new lang_string('configdownloaduserfields', 'ratingallocate'), + [ 'id' => 1, 'username' => 1, 'department' => 0, 'institution' => 0, 'email' => 1, ], - [ + [ 'id' => new lang_string('userid', 'ratingallocate'), 'username' => new lang_string('username'), 'idnumber' => new lang_string('idnumber'), 'department' => new lang_string('department'), 'institution' => new lang_string('institution'), 'email' => new lang_string('email'), - ])); + ] + )); - $settings->add(new admin_setting_configcheckbox('ratingallocate_algorithm_force_background_execution', + $settings->add(new admin_setting_configcheckbox( + 'ratingallocate_algorithm_force_background_execution', new lang_string('algorithmforcebackground', 'ratingallocate'), - new lang_string('configalgorithmforcebackground', 'ratingallocate'), 0)); + new lang_string('configalgorithmforcebackground', 'ratingallocate'), + 0 + )); } diff --git a/solver/edmonds-karp.php b/solver/edmonds-karp.php index 733445d4..0b84f008 100644 --- a/solver/edmonds-karp.php +++ b/solver/edmonds-karp.php @@ -34,7 +34,6 @@ * @package mod_ratingallocate */ class solver_edmonds_karp extends distributor { - /** * Return name. * @@ -64,7 +63,7 @@ public function compute_distribution($choicerecords, $ratings, $usercount) { $source = 0; $sink = $choicecount + $usercount + 1; - list($fromuserid, $touserid, $fromchoiceid, $tochoiceid) = $this->setup_id_conversions($usercount, $ratings); + [$fromuserid, $touserid, $fromchoiceid, $tochoiceid] = $this->setup_id_conversions($usercount, $ratings); $this->setup_graph($choicecount, $usercount, $fromuserid, $fromchoiceid, $ratings, $choicedata, $source, $sink, -1); @@ -144,5 +143,4 @@ private function find_shortest_path_bellf($from, $to) { $path[] = $from; return $path; } - } diff --git a/solver/export_lp_solve.php b/solver/export_lp_solve.php index 23fdc18f..f50de92d 100644 --- a/solver/export_lp_solve.php +++ b/solver/export_lp_solve.php @@ -170,12 +170,11 @@ public function download_file() { public function __destruct() { fclose($this->fp); } - } global $DB; -$writer = new lp_export_write (); +$writer = new lp_export_write(); $writer->set_filename("lp_solve_export_course_" . $ratingallocate->id); $choices = $ratingallocateobj->get_rateable_choices(); @@ -241,4 +240,3 @@ public function __destruct() { } $writer->download_file(); - diff --git a/solver/ford-fulkerson-koegel.php b/solver/ford-fulkerson-koegel.php index 9e4bc199..5bccad80 100644 --- a/solver/ford-fulkerson-koegel.php +++ b/solver/ford-fulkerson-koegel.php @@ -36,7 +36,6 @@ * @package mod_ratingallocate */ class solver_ford_fulkerson extends distributor { - /** * Starts the distribution algorithm. * Uses the users' ratings and a minimum-cost maximum-flow algorithm @@ -60,7 +59,7 @@ public function compute_distribution($choicerecords, $ratings, $usercount) { // Index of source and sink in the graph. $source = 0; $sink = $groupcount + $usercount + 1; - list($fromuserid, $touserid, $fromgroupid, $togroupid) = $this->setup_id_conversions($usercount, $ratings); + [$fromuserid, $touserid, $fromgroupid, $togroupid] = $this->setup_id_conversions($usercount, $ratings); $this->setup_graph($groupcount, $usercount, $fromuserid, $fromgroupid, $ratings, $groupdata, $source, $sink); @@ -168,5 +167,4 @@ public function find_shortest_path_bellmanf_koegel($from, $to) { public function get_name() { return "ford-fulkerson Koegel2014"; } - } diff --git a/solver/solver-template.php b/solver/solver-template.php index b159e98a..a12636c0 100644 --- a/solver/solver-template.php +++ b/solver/solver-template.php @@ -64,14 +64,12 @@ public function __construct($from, $to, $weight, $space = 0) { $this->weight = $weight; $this->space = $space; } - } /** * Template Class for distribution algorithms */ class distributor { - /** @var $graph Flow-Graph built */ protected $graph; @@ -203,8 +201,17 @@ public static function setup_id_conversions($usercount, $ratings) { * @param stdClass $weightmult * @return void */ - protected function setup_graph($choicecount, $usercount, $fromuserid, $fromchoiceid, $ratings, $choicedata, $source, $sink, - $weightmult = 1) { + protected function setup_graph( + $choicecount, + $usercount, + $fromuserid, + $fromchoiceid, + $ratings, + $choicedata, + $source, + $sink, + $weightmult = 1 + ) { // Construct the datastructures for the algorithm // A directed weighted bipartite graph. // A source is connected to all users with unit cost. @@ -278,5 +285,4 @@ protected function augment_flow($path) { } } } - } diff --git a/strategy/strategy01_yes_no.php b/strategy/strategy01_yes_no.php index 85983b6a..0e9190d7 100644 --- a/strategy/strategy01_yes_no.php +++ b/strategy/strategy01_yes_no.php @@ -41,7 +41,6 @@ * @package mod_ratingallocate */ class strategy extends \strategytemplate_options { - /** * Strategyid. */ diff --git a/strategy/strategy02_yes_maybe_no.php b/strategy/strategy02_yes_maybe_no.php index 9441173f..0c717838 100644 --- a/strategy/strategy02_yes_maybe_no.php +++ b/strategy/strategy02_yes_maybe_no.php @@ -42,7 +42,6 @@ * @package mod_ratingallocate */ class strategy extends \strategytemplate_options { - /** * Strategyid. */ diff --git a/strategy/strategy03_lickert.php b/strategy/strategy03_lickert.php index 01c2d6a3..7a70d41b 100644 --- a/strategy/strategy03_lickert.php +++ b/strategy/strategy03_lickert.php @@ -41,7 +41,6 @@ * @package mod_ratingallocate */ class strategy extends \strategytemplate_options { - /** * Strategyid. */ diff --git a/strategy/strategy04_points.php b/strategy/strategy04_points.php index d01582ad..23ca7ccf 100644 --- a/strategy/strategy04_points.php +++ b/strategy/strategy04_points.php @@ -42,7 +42,6 @@ * @package mod_ratingallocate */ class strategy extends \strategytemplate { - /** * Strategyid. */ @@ -126,7 +125,6 @@ protected function getvalidationinfo() { self::MAXPERCHOICE => [true, 1], ]; } - } // Register with the strategymanager. @@ -138,7 +136,6 @@ protected function getvalidationinfo() { * @package mod_ratingallocate */ class mod_ratingallocate_view_form extends \ratingallocate_strategyform { - /** * Create new strategy. * @param array $strategyoptions @@ -208,14 +205,23 @@ public function definition() { * @throws \coding_exception */ public function describe_strategy() { - $output = get_string(strategy::STRATEGYID . '_explain_distribute_points', RATINGALLOCATE_MOD_NAME, - $this->get_strategysetting(strategy::TOTALPOINTS)); + $output = get_string( + strategy::STRATEGYID . '_explain_distribute_points', + RATINGALLOCATE_MOD_NAME, + $this->get_strategysetting(strategy::TOTALPOINTS) + ); $output .= '
'; - $output .= get_string(strategy::STRATEGYID . '_explain_max_zero', RATINGALLOCATE_MOD_NAME, - $this->get_strategysetting(strategy::MAXZERO)); + $output .= get_string( + strategy::STRATEGYID . '_explain_max_zero', + RATINGALLOCATE_MOD_NAME, + $this->get_strategysetting(strategy::MAXZERO) + ); $output .= '
'; - $output .= get_string(strategy::STRATEGYID . '_explain_max_per_choice', RATINGALLOCATE_MOD_NAME, - $this->get_strategysetting(strategy::MAXPERCHOICE)); + $output .= get_string( + strategy::STRATEGYID . '_explain_max_per_choice', + RATINGALLOCATE_MOD_NAME, + $this->get_strategysetting(strategy::MAXPERCHOICE) + ); return $output; } @@ -268,5 +274,4 @@ public function validation($data, $files) { } return $errors; } - } diff --git a/strategy/strategy05_order.php b/strategy/strategy05_order.php index 04e4cf31..37109709 100644 --- a/strategy/strategy05_order.php +++ b/strategy/strategy05_order.php @@ -41,7 +41,6 @@ * @package mod_ratingallocate */ class strategy extends \strategytemplate { - /** * Strategyid. */ @@ -111,7 +110,6 @@ public function get_default_settings() { protected function getvalidationinfo() { return [self::COUNTOPTIONS => [true, 1]]; } - } // Register with the strategymanager. @@ -124,7 +122,6 @@ protected function getvalidationinfo() { * - shows a drop down menu from which the user can choose a rating */ class mod_ratingallocate_view_form extends \ratingallocate_strategyform { - /** * Create new strategy. * @param array $strategyoptions @@ -168,14 +165,19 @@ public function definition() { // If there is a valid value in the databse, choose the according rating // from the dropdown. // Else use a default value. - if (is_numeric($data->rating) && $data->rating >= 0 && - $mform->elementExists('choice[' . ($choicecounter - ($data->rating - 1)) . ']')) { + if ( + is_numeric($data->rating) && $data->rating >= 0 && + $mform->elementExists('choice[' . ($choicecounter - ($data->rating - 1)) . ']') + ) { $mform->getElement('choice[' . ($choicecounter - ($data->rating - 1)) . ']')->setSelected($data->choiceid); } } - $mform->addElement('header', 'choice_descriptions', - get_string(strategy::STRATEGYID . '_header_description', RATINGALLOCATE_MOD_NAME)); + $mform->addElement( + 'header', + 'choice_descriptions', + get_string(strategy::STRATEGYID . '_header_description', RATINGALLOCATE_MOD_NAME) + ); foreach ($ratingdata as $data) { // Show max. number of allocations. @@ -204,8 +206,11 @@ public function definition() { private function fill_select($select, $i, array $choices) { $select->setName('choice[' . $i . ']'); $select->setLabel(get_string(strategy::STRATEGYID . '_no_choice', RATINGALLOCATE_MOD_NAME, $i)); - $select->addOption(get_string(strategy::STRATEGYID . '_choice_none', RATINGALLOCATE_MOD_NAME, $i), - '', ['disabled' => 'disabled']); + $select->addOption( + get_string(strategy::STRATEGYID . '_choice_none', RATINGALLOCATE_MOD_NAME, $i), + '', + ['disabled' => 'disabled'] + ); foreach ($choices as $id => $name) { $select->addOption($name, $id); } @@ -272,5 +277,4 @@ public function validation($data, $files) { } return $errors; } - } diff --git a/strategy/strategy06_tickyes.php b/strategy/strategy06_tickyes.php index bbe616c3..23956ac5 100644 --- a/strategy/strategy06_tickyes.php +++ b/strategy/strategy06_tickyes.php @@ -42,7 +42,6 @@ * @package mod_ratingallocate */ class strategy extends \strategytemplate { - /** * Strategyid. */ @@ -134,7 +133,6 @@ protected function getvalidationinfo() { * - shows a drop down menu from which the user can choose a rating */ class mod_ratingallocate_view_form extends \ratingallocate_strategyform { - /** * Create a new strategy. * @param array $strategyoptions @@ -181,8 +179,14 @@ public function definition() { ': ' . $data->maxsize . ''); // Use explanation as title/label of checkbox to align with other strategies. - $mform->addElement('advcheckbox', $ratingelem, format_text($data->explanation), - $this->get_strategy()->get_accept_label(), null, [0, 1]); + $mform->addElement( + 'advcheckbox', + $ratingelem, + format_text($data->explanation), + $this->get_strategy()->get_accept_label(), + null, + [0, 1] + ); $mform->setType($ratingelem, PARAM_INT); if (is_numeric($data->rating) && $data->rating >= 0) { @@ -203,8 +207,11 @@ public function definition() { * @throws \coding_exception */ public function describe_strategy() { - return get_string(strategy::STRATEGYID . '_explain_mintickyes', RATINGALLOCATE_MOD_NAME, - $this->get_strategysetting(strategy::MINTICKYES)); + return get_string( + strategy::STRATEGYID . '_explain_mintickyes', + RATINGALLOCATE_MOD_NAME, + $this->get_strategysetting(strategy::MINTICKYES) + ); } /** @@ -240,5 +247,4 @@ public function validation($data, $files) { } return $errors; } - } diff --git a/strategy/strategy_template.php b/strategy/strategy_template.php index 27e3c391..f247cf24 100644 --- a/strategy/strategy_template.php +++ b/strategy/strategy_template.php @@ -39,7 +39,6 @@ * @package mod_ratingallocate */ abstract class strategytemplate { - /** STRATEGYID string identifier, for language translation, etc. */ const STRATEGYID = ''; @@ -63,8 +62,10 @@ public function __construct(?array $strategysettings = null) { * @return either the value of the setting the strategy was initialized with or the default value of the setting. */ protected function get_settings_value($key, $default = true) { - if (isset($this->_strategy_settings) && array_key_exists($key, $this->_strategy_settings) && - $this->_strategy_settings[$key] !== '') { + if ( + isset($this->_strategy_settings) && array_key_exists($key, $this->_strategy_settings) && + $this->_strategy_settings[$key] !== '' + ) { return $value = $this->_strategy_settings[$key]; } return $default ? $this->get_settings_default_value($key) : null; @@ -169,8 +170,10 @@ public function validate_settings() { $errors = []; foreach ($validationinfo as $key => $info) { if (isset($info[0]) && $info[0] === true) { - if (array_key_exists($key, $this->_strategy_settings) && - (!isset($this->_strategy_settings[$key]) || $this->_strategy_settings[$key] === "")) { + if ( + array_key_exists($key, $this->_strategy_settings) && + (!isset($this->_strategy_settings[$key]) || $this->_strategy_settings[$key] === "") + ) { $errors[$key] = get_string('err_required', RATINGALLOCATE_MOD_NAME); break; } diff --git a/strategy/strategy_template_options.php b/strategy/strategy_template_options.php index b3d542b4..2f1d09ce 100644 --- a/strategy/strategy_template_options.php +++ b/strategy/strategy_template_options.php @@ -36,7 +36,6 @@ * @package mod_ratingallocate */ abstract class strategytemplate_options extends \strategytemplate { - /** * Return the different options for each choice (including titles) * @return array: value_of_option => title_of_option @@ -65,7 +64,6 @@ protected function get_default_strategy_option() { * - shows a drop down menu from which the user can choose a rating */ abstract class ratingallocate_options_strategyform extends \ratingallocate_strategyform { - /** * Defines forms elements */ @@ -165,8 +163,11 @@ public function validation($data, $files) { if ($impossibles > $maxno) { foreach ($ratings as $cid => $rating) { if ($rating['rating'] == 0) { - $errors['radioarr_' . $cid] = get_string($this->get_max_nos_string_identyfier(), - RATINGALLOCATE_MOD_NAME, $maxno); + $errors['radioarr_' . $cid] = get_string( + $this->get_max_nos_string_identyfier(), + RATINGALLOCATE_MOD_NAME, + $maxno + ); } } } @@ -193,5 +194,4 @@ abstract protected function get_max_amount_of_nos(); * @return mixed */ abstract protected function get_max_nos_string_identyfier(); - } diff --git a/tests/backup_restore_test.php b/tests/backup_restore_test.php index 65c9093e..be3103b5 100644 --- a/tests/backup_restore_test.php +++ b/tests/backup_restore_test.php @@ -40,7 +40,6 @@ */ #[CoversClass(backup_ratingallocate_activity_structure_step::class)] final class backup_restore_test extends \advanced_testcase { - /** * Test backup and restore of ratingallocate activity. * @@ -60,8 +59,14 @@ public function test_backup_restore(): void { $genmod = new \mod_ratingallocate_generated_module($this); $course1 = $genmod->course; // Create backup file and save it to the backup location. - $bc = new \backup_controller(\backup::TYPE_1ACTIVITY, $genmod->moddb->cmid, \backup::FORMAT_MOODLE, - \backup::INTERACTIVE_NO, \backup::MODE_GENERAL, 2); + $bc = new \backup_controller( + \backup::TYPE_1ACTIVITY, + $genmod->moddb->cmid, + \backup::FORMAT_MOODLE, + \backup::INTERACTIVE_NO, + \backup::MODE_GENERAL, + 2 + ); $bc->execute_plan(); $results = $bc->get_results(); $file = $results['backup_destination']; @@ -80,12 +85,18 @@ public function test_backup_restore(): void { // Create a course that we are going to restore the other course to. $course2 = $this->getDataGenerator()->create_course(); // Now restore the course. - $rc = new \restore_controller('test-restore-course', $course2->id, \backup::INTERACTIVE_NO, - \backup::MODE_GENERAL, 2, \backup::TARGET_NEW_COURSE); + $rc = new \restore_controller( + 'test-restore-course', + $course2->id, + \backup::INTERACTIVE_NO, + \backup::MODE_GENERAL, + 2, + \backup::TARGET_NEW_COURSE + ); $rc->execute_precheck(); $rc->execute_plan(); - $unsetvalues = function($elem1, $elem2, $varname) { + $unsetvalues = function ($elem1, $elem2, $varname) { $this->assertNotEquals($elem1->{$varname}, $elem2->{$varname}); $result = [$elem1->{$varname}, $elem2->{$varname}]; unset($elem1->{$varname}); @@ -93,20 +104,28 @@ public function test_backup_restore(): void { return $result; }; - $ratingallocate1 = $DB->get_record(this_db\ratingallocate::TABLE, - [this_db\ratingallocate::COURSE => $course1->id]); - $ratingallocate2 = $DB->get_record(this_db\ratingallocate::TABLE, - [this_db\ratingallocate::COURSE => $course2->id]); - list($ratingid1, $ratingid2) = $unsetvalues($ratingallocate1, $ratingallocate2, this_db\ratingallocate::ID); + $ratingallocate1 = $DB->get_record( + this_db\ratingallocate::TABLE, + [this_db\ratingallocate::COURSE => $course1->id] + ); + $ratingallocate2 = $DB->get_record( + this_db\ratingallocate::TABLE, + [this_db\ratingallocate::COURSE => $course2->id] + ); + [$ratingid1, $ratingid2] = $unsetvalues($ratingallocate1, $ratingallocate2, this_db\ratingallocate::ID); $unsetvalues($ratingallocate1, $ratingallocate2, this_db\ratingallocate::COURSE); $this->assertEquals($ratingallocate1, $ratingallocate2); - $choices1 = $DB->get_records(this_db\ratingallocate_choices::TABLE, - [this_db\ratingallocate_choices::RATINGALLOCATEID => $ratingid1], - this_db\ratingallocate_choices::TITLE); - $choices2 = $DB->get_records(this_db\ratingallocate_choices::TABLE, - [this_db\ratingallocate_choices::RATINGALLOCATEID => $ratingid2], - this_db\ratingallocate_choices::TITLE); + $choices1 = $DB->get_records( + this_db\ratingallocate_choices::TABLE, + [this_db\ratingallocate_choices::RATINGALLOCATEID => $ratingid1], + this_db\ratingallocate_choices::TITLE + ); + $choices2 = $DB->get_records( + this_db\ratingallocate_choices::TABLE, + [this_db\ratingallocate_choices::RATINGALLOCATEID => $ratingid2], + this_db\ratingallocate_choices::TITLE + ); $this->assertCount(2, $choices1); $this->assertCount(2, array_values($choices2)); $choice2copy = $choices2; @@ -114,16 +133,20 @@ public function test_backup_restore(): void { // Work with copies. $choice2 = json_decode(json_encode(array_shift($choice2copy))); $choice1 = json_decode(json_encode($choice1)); - list($choiceid1, $choiceid2) = $unsetvalues($choice1, $choice2, this_db\ratingallocate_choices::ID); + [$choiceid1, $choiceid2] = $unsetvalues($choice1, $choice2, this_db\ratingallocate_choices::ID); $unsetvalues($choice1, $choice2, this_db\ratingallocate_choices::RATINGALLOCATEID); $this->assertEquals($choice1, $choice2); // Compare ratings for this choice. - $ratings1 = array_values($DB->get_records(this_db\ratingallocate_ratings::TABLE, - [this_db\ratingallocate_ratings::CHOICEID => $choiceid1], - this_db\ratingallocate_ratings::USERID)); - $ratings2 = array_values($DB->get_records(this_db\ratingallocate_ratings::TABLE, - [this_db\ratingallocate_ratings::CHOICEID => $choiceid2], - this_db\ratingallocate_ratings::USERID)); + $ratings1 = array_values($DB->get_records( + this_db\ratingallocate_ratings::TABLE, + [this_db\ratingallocate_ratings::CHOICEID => $choiceid1], + this_db\ratingallocate_ratings::USERID + )); + $ratings2 = array_values($DB->get_records( + this_db\ratingallocate_ratings::TABLE, + [this_db\ratingallocate_ratings::CHOICEID => $choiceid2], + this_db\ratingallocate_ratings::USERID + )); $this->assertEquals(count($ratings1), count($ratings2)); $ratings2copy = $ratings2; foreach ($ratings1 as $rating1) { @@ -136,16 +159,20 @@ public function test_backup_restore(): void { } // Compare allocations. - $allocations1 = $DB->get_records(this_db\ratingallocate_allocations::TABLE, - [this_db\ratingallocate_allocations::RATINGALLOCATEID => $ratingid1], - this_db\ratingallocate_allocations::USERID); - $allocations2 = $DB->get_records(this_db\ratingallocate_allocations::TABLE, - [this_db\ratingallocate_allocations::RATINGALLOCATEID => $ratingid2], - this_db\ratingallocate_allocations::USERID); + $allocations1 = $DB->get_records( + this_db\ratingallocate_allocations::TABLE, + [this_db\ratingallocate_allocations::RATINGALLOCATEID => $ratingid1], + this_db\ratingallocate_allocations::USERID + ); + $allocations2 = $DB->get_records( + this_db\ratingallocate_allocations::TABLE, + [this_db\ratingallocate_allocations::RATINGALLOCATEID => $ratingid2], + this_db\ratingallocate_allocations::USERID + ); // Number of allocations is equal. $this->assertCount(count($genmod->allocations), $allocations2); // Create function that can be used to replace. - $mapallocationtochoicetitle = function(&$alloc, $choices) { + $mapallocationtochoicetitle = function (&$alloc, $choices) { $alloc->{'choice_title'} = $choices[$alloc->{this_db\ratingallocate_allocations::CHOICEID}]->{this_db\ratingallocate_choices::TITLE}; }; diff --git a/tests/behat/behat_mod_ratingallocate.php b/tests/behat/behat_mod_ratingallocate.php index b0f08583..47381fd5 100644 --- a/tests/behat/behat_mod_ratingallocate.php +++ b/tests/behat/behat_mod_ratingallocate.php @@ -23,9 +23,9 @@ */ require_once(__DIR__ . '/../../../../lib/behat/behat_base.php'); -use Behat\Gherkin\Node\TableNode as TableNode, - Behat\Mink\Exception\ExpectationException as ExpectationException, - Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException; +use Behat\Gherkin\Node\TableNode, + Behat\Mink\Exception\ExpectationException, + Behat\Mink\Exception\ElementNotFoundException; /** * Class for Behat tests @@ -35,7 +35,6 @@ * @package mod_ratingallocate */ class behat_mod_ratingallocate extends behat_base { - /** * Creates the specified choices. * @@ -49,20 +48,22 @@ public function the_following_choices_exist(TableNode $data) { global $DB; foreach ($data->getColumnsHash() as $record) { - if (!isset($record['title'])) { throw new coding_exception( - 'title must be present in behat_mod_ratingallocate::the_following_choices_exist() $data'); + 'title must be present in behat_mod_ratingallocate::the_following_choices_exist() $data' + ); } if (!isset($record['maxsize'])) { throw new coding_exception( - 'maxsize must be present in behat_mod_ratingallocate::the_following_choices_exist() $data'); + 'maxsize must be present in behat_mod_ratingallocate::the_following_choices_exist() $data' + ); } if (!isset($record['ratingallocate'])) { throw new coding_exception( - 'ratingallocate must be present in behat_mod_ratingallocate::the_following_choices_exist() $data'); + 'ratingallocate must be present in behat_mod_ratingallocate::the_following_choices_exist() $data' + ); } $ratingallocate = $DB->get_record('ratingallocate', ['name' => $record['ratingallocate']]); @@ -73,7 +74,6 @@ public function the_following_choices_exist(TableNode $data) { // Add the subscription. $record->id = $DB->insert_record('ratingallocate_choices', $record); - } } @@ -90,20 +90,22 @@ public function the_following_ratings_exist(TableNode $data) { global $DB; foreach ($data->getColumnsHash() as $record) { - if (!isset($record['choice'])) { throw new coding_exception( - 'choice must be present in behat_mod_ratingallocate::the_following_ratings_exist() $data'); + 'choice must be present in behat_mod_ratingallocate::the_following_ratings_exist() $data' + ); } if (!isset($record['user'])) { throw new coding_exception( - 'user must be present in behat_mod_ratingallocate::the_following_ratings_exist() $data'); + 'user must be present in behat_mod_ratingallocate::the_following_ratings_exist() $data' + ); } if (!isset($record['rating'])) { throw new coding_exception( - 'rating must be present in behat_mod_ratingallocate::the_following_ratings_exist() $data'); + 'rating must be present in behat_mod_ratingallocate::the_following_ratings_exist() $data' + ); } $user = $DB->get_record('user', ['username' => $record['user']]); @@ -116,7 +118,6 @@ public function the_following_ratings_exist(TableNode $data) { // Add the subscription. $record->id = $DB->insert_record('ratingallocate_ratings', $record); - } } @@ -384,9 +385,11 @@ public function i_uncheck_the_active_checkbox() { public function the_choice_should_be_active($title) { $choice = $this->get_choice($title); if (!$choice->active) { - throw new ExpectationException('The choice "' . $title . + throw new ExpectationException( + 'The choice "' . $title . '" should be active.', - $this->getSession()); + $this->getSession() + ); } } @@ -401,8 +404,10 @@ public function the_choice_should_be_active($title) { public function the_choice_should_not_be_active($title) { $choice = $this->get_choice($title); if ($choice->active) { - throw new ExpectationException('The choice "' . $title . '" should not be active', - $this->getSession()); + throw new ExpectationException( + 'The choice "' . $title . '" should not be active', + $this->getSession() + ); } } @@ -418,9 +423,11 @@ public function the_choice_should_not_be_active($title) { public function the_choice_should_have_explanation_equal($title, $value) { $choice = $this->get_choice($title); if ($choice->explanation !== $value) { - throw new ExpectationException('The explanation of the choice ' . $title . + throw new ExpectationException( + 'The explanation of the choice ' . $title . ' was expected to be "' . $value . '" but was "' . $choice->explanation . '".', - $this->getSession()); + $this->getSession() + ); } } @@ -435,9 +442,11 @@ public function the_choice_should_have_explanation_equal($title, $value) { public function the_user_should_have_ratings($username) { $ratings = $this->get_ratings_for_username($username); if (count($ratings) == 0) { - throw new ExpectationException("It was expected that the user $username has ratings, " . + throw new ExpectationException( + "It was expected that the user $username has ratings, " . "but there were none.", - $this->getSession()); + $this->getSession() + ); } } @@ -452,9 +461,11 @@ public function the_user_should_have_ratings($username) { public function the_user_should_not_have_ratings($username) { $ratings = $this->get_ratings_for_username($username); if (count($ratings) > 0) { - throw new ExpectationException("It was expected that the user $username has no ratings, " . + throw new ExpectationException( + "It was expected that the user $username has no ratings, " . "but there were some.", - $this->getSession()); + $this->getSession() + ); } } @@ -482,9 +493,11 @@ private function get_ratings_for_username($username) { public function the_choice_should_have_maxsize_equal($title, $value) { $choice = $this->get_choice($title); if ($choice->maxsize !== $value) { - throw new ExpectationException('The maxsize of the choice ' . $title . + throw new ExpectationException( + 'The maxsize of the choice ' . $title . ' was expected to be "' . $value . '" but was "' . $choice->explanation . '".', - $this->getSession()); + $this->getSession() + ); } } @@ -557,8 +570,10 @@ public function i_set_the_rating_form_to_the_following_values(TableNode $ratingd $option = $this->find('xpath', $fieldxpath); $option->click(); } catch (ElementNotFoundException $e) { - throw new ExpectationException('Option "' . $value . '" was not found for choice "' . $choice . '".' . $value, - $this->getSession()); + throw new ExpectationException( + 'Option "' . $value . '" was not found for choice "' . $choice . '".' . $value, + $this->getSession() + ); } } } @@ -673,8 +688,10 @@ protected function resolve_page_instance_url(string $type, string $identifier): switch (strtolower($type)) { case 'view': - return new moodle_url('/mod/ratingallocate/view.php', - ['id' => $this->get_cm_by_ratingallocate_name($identifier)->id]); + return new moodle_url( + '/mod/ratingallocate/view.php', + ['id' => $this->get_cm_by_ratingallocate_name($identifier)->id] + ); case 'edit': return new moodle_url('/course/modedit.php', [ @@ -717,5 +734,4 @@ protected function get_cm_by_ratingallocate_name(string $name): stdClass { $ratingallocate = $this->get_ratingallocate_by_name($name); return get_coursemodule_from_instance('ratingallocate', $ratingallocate->id, $ratingallocate->course); } - } diff --git a/tests/cron_test.php b/tests/cron_test.php index 2b4cfed9..1f563a18 100644 --- a/tests/cron_test.php +++ b/tests/cron_test.php @@ -42,7 +42,6 @@ #[CoversClass(cron_task::class)] #[CoversFunction('execute')] final class cron_test extends \advanced_testcase { - /** @var $teacher */ private $teacher; /** @var $mod */ @@ -138,8 +137,10 @@ private function assert_not_started(): void { $record = $DB->get_record(this_db\ratingallocate::TABLE, []); $ratingallocate = \mod_ratingallocate_generator::get_ratingallocate_for_user($this, $record, $this->teacher); $this->assertEquals(algorithm_status::NOTSTARTED, $ratingallocate->get_algorithm_status()); - $this->assertEquals(0, $DB->count_records(this_db\ratingallocate_allocations::TABLE, - [this_db\ratingallocate_allocations::RATINGALLOCATEID => $this->mod->id])); + $this->assertEquals(0, $DB->count_records( + this_db\ratingallocate_allocations::TABLE, + [this_db\ratingallocate_allocations::RATINGALLOCATEID => $this->mod->id] + )); } /** @@ -150,8 +151,10 @@ private function assert_running(): void { $record = $DB->get_record(this_db\ratingallocate::TABLE, []); $ratingallocate = \mod_ratingallocate_generator::get_ratingallocate_for_user($this, $record, $this->teacher); $this->assertEquals(algorithm_status::RUNNING, $ratingallocate->get_algorithm_status()); - $this->assertEquals(0, $DB->count_records(this_db\ratingallocate_allocations::TABLE, - [this_db\ratingallocate_allocations::RATINGALLOCATEID => $this->mod->id])); + $this->assertEquals(0, $DB->count_records( + this_db\ratingallocate_allocations::TABLE, + [this_db\ratingallocate_allocations::RATINGALLOCATEID => $this->mod->id] + )); } /** @@ -162,8 +165,10 @@ private function assert_failure(): void { $record = $DB->get_record(this_db\ratingallocate::TABLE, []); $ratingallocate = \mod_ratingallocate_generator::get_ratingallocate_for_user($this, $record, $this->teacher); $this->assertEquals(algorithm_status::FAILURE, $ratingallocate->get_algorithm_status()); - $this->assertEquals(0, $DB->count_records(this_db\ratingallocate_allocations::TABLE, - [this_db\ratingallocate_allocations::RATINGALLOCATEID => $this->mod->id])); + $this->assertEquals(0, $DB->count_records( + this_db\ratingallocate_allocations::TABLE, + [this_db\ratingallocate_allocations::RATINGALLOCATEID => $this->mod->id] + )); } /** @@ -174,8 +179,10 @@ private function assert_finish(): void { $record = $DB->get_record(this_db\ratingallocate::TABLE, []); $ratingallocate = \mod_ratingallocate_generator::get_ratingallocate_for_user($this, $record, $this->teacher); $this->assertEquals(algorithm_status::FINISHED, $ratingallocate->get_algorithm_status()); - $this->assertEquals(4, $DB->count_records(this_db\ratingallocate_allocations::TABLE, - [this_db\ratingallocate_allocations::RATINGALLOCATEID => $this->mod->id])); + $this->assertEquals(4, $DB->count_records( + this_db\ratingallocate_allocations::TABLE, + [this_db\ratingallocate_allocations::RATINGALLOCATEID => $this->mod->id] + )); } /** @@ -186,8 +193,10 @@ private function assert_already_finish(): void { $record = $DB->get_record(this_db\ratingallocate::TABLE, []); $ratingallocate = \mod_ratingallocate_generator::get_ratingallocate_for_user($this, $record, $this->teacher); $this->assertEquals(algorithm_status::FINISHED, $ratingallocate->get_algorithm_status()); - $this->assertEquals(0, $DB->count_records(this_db\ratingallocate_allocations::TABLE, - [this_db\ratingallocate_allocations::RATINGALLOCATEID => $this->mod->id])); + $this->assertEquals(0, $DB->count_records( + this_db\ratingallocate_allocations::TABLE, + [this_db\ratingallocate_allocations::RATINGALLOCATEID => $this->mod->id] + )); } /** @@ -196,9 +205,11 @@ private function assert_already_finish(): void { * @param int $algorithmstatus the algorithm status of the modul to be created. * @param int $algorithmstarttime the start time of the algorithm. */ - private function create_ratingallocate($ratingperiodended, - $algorithmstatus = algorithm_status::NOTSTARTED, - $algorithmstarttime = null): void { + private function create_ratingallocate( + $ratingperiodended, + $algorithmstatus = algorithm_status::NOTSTARTED, + $algorithmstarttime = null + ): void { global $DB; $this->resetAfterTest(); @@ -210,8 +221,9 @@ private function create_ratingallocate($ratingperiodended, // There should not be any module for that course first. $this->assertFalse( - $DB->record_exists(this_db\ratingallocate::TABLE, [this_db\ratingallocate::COURSE => $course->id, - ])); + $DB->record_exists(this_db\ratingallocate::TABLE, [this_db\ratingallocate::COURSE => $course->id, + ]) + ); $data = \mod_ratingallocate_generator::get_default_values(); $data['course'] = $course; // Shift the rating period depending on its ending. @@ -229,8 +241,10 @@ private function create_ratingallocate($ratingperiodended, // Create activity. $this->mod = \mod_ratingallocate_generator::create_instance_with_choices($this, $data); - $this->assertEquals(2, $DB->count_records(this_db\ratingallocate_choices::TABLE, - [this_db\ratingallocate_choices::RATINGALLOCATEID => $this->mod->id])); + $this->assertEquals(2, $DB->count_records( + this_db\ratingallocate_choices::TABLE, + [this_db\ratingallocate_choices::RATINGALLOCATEID => $this->mod->id] + )); $student1 = \mod_ratingallocate_generator::create_user_and_enrol($this, $course); $student2 = \mod_ratingallocate_generator::create_user_and_enrol($this, $course); @@ -261,7 +275,9 @@ private function create_ratingallocate($ratingperiodended, \mod_ratingallocate_generator::save_rating_for_user($this, $this->mod, $student3, $preferssecond); \mod_ratingallocate_generator::save_rating_for_user($this, $this->mod, $student4, $preferssecond); - $this->assertEquals(0, $DB->count_records(this_db\ratingallocate_allocations::TABLE, - [this_db\ratingallocate_allocations::RATINGALLOCATEID => $this->mod->id])); + $this->assertEquals(0, $DB->count_records( + this_db\ratingallocate_allocations::TABLE, + [this_db\ratingallocate_allocations::RATINGALLOCATEID => $this->mod->id] + )); } } diff --git a/tests/generator/lib.php b/tests/generator/lib.php index 927c600a..919190c1 100644 --- a/tests/generator/lib.php +++ b/tests/generator/lib.php @@ -38,7 +38,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class mod_ratingallocate_generator extends testing_module_generator { - /** * Creates instance of the module with default values. * @param stdClass|null $record @@ -67,8 +66,12 @@ public function create_instance($record = null, ?array $options = null) { * @param null|array $options general options for ratingallocate * @return stdClass record from ratingallocate */ - public static function create_instance_with_choices(advanced_testcase $tc, $moduledata = null, - $choicedata = null, ?array $options = null) { + public static function create_instance_with_choices( + advanced_testcase $tc, + $moduledata = null, + $choicedata = null, + ?array $options = null + ) { if ($choicedata === null) { $choicedata = self::get_default_choice_data(); } @@ -146,12 +149,17 @@ public static function create_user_and_enrol(advanced_testcase $tc, $course, $is if (empty(self::$teacherrole)) { global $DB; // Enrol teacher and student. - self::$teacherrole = $DB->get_record('role', - ['shortname' => 'editingteacher', - ]); + self::$teacherrole = $DB->get_record( + 'role', + ['shortname' => 'editingteacher', + ] + ); } - $enroled = $tc->getDataGenerator()->enrol_user($user->id, $course->id, - self::$teacherrole->id); + $enroled = $tc->getDataGenerator()->enrol_user( + $user->id, + $course->id, + self::$teacherrole->id + ); } else { $enroled = $tc->getDataGenerator()->enrol_user($user->id, $course->id); } @@ -169,8 +177,12 @@ public static function create_user_and_enrol(advanced_testcase $tc, $course, $is * @param stdClass $user * @param array $rating */ - public static function save_rating_for_user(advanced_testcase $tc, $modratingallocate, $user, - $rating) { + public static function save_rating_for_user( + advanced_testcase $tc, + $modratingallocate, + $user, + $rating + ) { $ratingallocate = self::get_ratingallocate_for_user($tc, $modratingallocate, $user); $ratingallocate->save_ratings_to_db($user->id, $rating); } @@ -183,8 +195,11 @@ public static function save_rating_for_user(advanced_testcase $tc, $modratingall * @param stdClass $user * @return ratingallocate */ - public static function get_ratingallocate_for_user(advanced_testcase $tc, $ratingallocatedb, - $user) { + public static function get_ratingallocate_for_user( + advanced_testcase $tc, + $ratingallocatedb, + $user + ) { $tc->setUser($user); return self::get_ratingallocate($ratingallocatedb); } @@ -196,8 +211,10 @@ public static function get_ratingallocate_for_user(advanced_testcase $tc, $ratin * @throws coding_exception */ public static function get_ratingallocate($ratingallocatedb) { - $cm = get_coursemodule_from_instance(RATINGALLOCATE_MOD_NAME, - $ratingallocatedb->{this_db\ratingallocate::ID}); + $cm = get_coursemodule_from_instance( + RATINGALLOCATE_MOD_NAME, + $ratingallocatedb->{this_db\ratingallocate::ID} + ); $course = get_course($cm->course); $context = context_module::instance($cm->id); @@ -213,8 +230,12 @@ public static function get_ratingallocate($ratingallocatedb) { * @param array|null $ratings * @return ratingallocate */ - public static function get_open_ratingallocate_for_teacher(advanced_testcase $tc, $choices = null, - $course = null, $ratings = null) { + public static function get_open_ratingallocate_for_teacher( + advanced_testcase $tc, + $choices = null, + $course = null, + $ratings = null + ) { return self::get_ratingallocate_for_teacher_open_in(0, $tc, $choices, $course, $ratings); } @@ -227,8 +248,12 @@ public static function get_open_ratingallocate_for_teacher(advanced_testcase $tc * @param array|null $ratings * @return ratingallocate */ - public static function get_closed_ratingallocate_for_teacher(advanced_testcase $tc, $choices = null, - $course = null, $ratings = null) { + public static function get_closed_ratingallocate_for_teacher( + advanced_testcase $tc, + $choices = null, + $course = null, + $ratings = null + ) { return self::get_ratingallocate_for_teacher_open_in(-7, $tc, $choices, $course, $ratings); } @@ -241,8 +266,13 @@ public static function get_closed_ratingallocate_for_teacher(advanced_testcase $ * @param array|null $ratings * @return ratingallocate */ - private static function get_ratingallocate_for_teacher_open_in($numdays, advanced_testcase $tc, $choices = null, - $course = null, $ratings = null) { + private static function get_ratingallocate_for_teacher_open_in( + $numdays, + advanced_testcase $tc, + $choices = null, + $course = null, + $ratings = null + ) { $record = self::get_default_values(); $record['accesstimestart'] = time() + ($numdays * 24 * 60 * 60); $record['accesstimestop'] = time() + (($numdays + 6) * 24 * 60 * 60); @@ -251,8 +281,11 @@ private static function get_ratingallocate_for_teacher_open_in($numdays, advance $record['course'] = $course; } $testmodule = new mod_ratingallocate_generated_module($tc, $record, $choices, $ratings); - return self::get_ratingallocate_for_user($tc, - $testmodule->moddb, $testmodule->teacher); + return self::get_ratingallocate_for_user( + $tc, + $testmodule->moddb, + $testmodule->teacher + ); } /** @@ -265,8 +298,11 @@ public static function get_small_ratingallocate_for_filter_tests(advanced_testca $record = self::get_default_values(); $record['num_students'] = 4; $testmodule = new mod_ratingallocate_generated_module($tc, $record, $choices); - return self::get_ratingallocate_for_user($tc, - $testmodule->moddb, $testmodule->teacher); + return self::get_ratingallocate_for_user( + $tc, + $testmodule->moddb, + $testmodule->teacher + ); } } @@ -299,8 +335,13 @@ class mod_ratingallocate_generated_module { * @param array $ratings * @param boolean $assertintermediateresult */ - public function __construct(advanced_testcase $tc, $moduledata = null, $choicedata = null, - $ratings = null, $assertintermediateresult = true) { + public function __construct( + advanced_testcase $tc, + $moduledata = null, + $choicedata = null, + $ratings = null, + $assertintermediateresult = true + ) { global $DB; $tc->resetAfterTest(); $tc->setAdminUser(); @@ -320,17 +361,24 @@ public function __construct(advanced_testcase $tc, $moduledata = null, $choiceda $tc->setUser($this->teacher); if ($assertintermediateresult) { $tc->assertFalse( - $DB->record_exists(this_db\ratingallocate::TABLE, - [this_db\ratingallocate::COURSE => $this->course->id, - ]), 'There should not be any module for that course first'); + $DB->record_exists( + this_db\ratingallocate::TABLE, + [this_db\ratingallocate::COURSE => $this->course->id, + ] + ), + 'There should not be any module for that course first' + ); } // Create activity. $this->moddb = mod_ratingallocate_generator::create_instance_with_choices($tc, $moduledata, $choicedata); // Load Ratingallocate object. - $ratingallocate = mod_ratingallocate_generator::get_ratingallocate_for_user($tc, - $this->moddb, $this->teacher); + $ratingallocate = mod_ratingallocate_generator::get_ratingallocate_for_user( + $tc, + $this->moddb, + $this->teacher + ); // If rating data is provided restore it. Otherwise generate random ones. if ($ratings) { @@ -348,20 +396,28 @@ public function __construct(advanced_testcase $tc, $moduledata = null, $choiceda } } } - mod_ratingallocate_generator::save_rating_for_user($tc, $this->moddb, - $user, $ratingdata); + mod_ratingallocate_generator::save_rating_for_user( + $tc, + $this->moddb, + $user, + $ratingdata + ); } } else { // Create students. $numstudents = array_key_exists('num_students', $moduledata) ? $moduledata['num_students'] : 20; for ($i = 0; $i < $numstudents; $i++) { - $this->students[$i] = mod_ratingallocate_generator::create_user_and_enrol($tc, - $this->course); + $this->students[$i] = mod_ratingallocate_generator::create_user_and_enrol( + $tc, + $this->course + ); } // Assert number of choices is correct. - $numberofrecords = $DB->count_records(this_db\ratingallocate_choices::TABLE, - [this_db\ratingallocate_choices::RATINGALLOCATEID => $this->moddb->id]); + $numberofrecords = $DB->count_records( + this_db\ratingallocate_choices::TABLE, + [this_db\ratingallocate_choices::RATINGALLOCATEID => $this->moddb->id] + ); $tc->assertEquals(2, $numberofrecords); // Load choices. @@ -402,11 +458,18 @@ public function __construct(advanced_testcase $tc, $moduledata = null, $choiceda } // Assign preferences. - mod_ratingallocate_generator::save_rating_for_user($tc, $this->moddb, - $this->students[$i], $rating); + mod_ratingallocate_generator::save_rating_for_user( + $tc, + $this->moddb, + $this->students[$i], + $rating + ); if ($assertintermediateresult) { - $alloc = mod_ratingallocate_generator::get_ratingallocate_for_user($tc, - $this->moddb, $this->students[$i]); + $alloc = mod_ratingallocate_generator::get_ratingallocate_for_user( + $tc, + $this->moddb, + $this->students[$i] + ); $savedratings = $alloc->get_rating_data_for_user($this->students[$i]->id); $savedratingarr = []; foreach ($savedratings as $savedrating) { @@ -421,8 +484,11 @@ public function __construct(advanced_testcase $tc, $moduledata = null, $choiceda } // Allocate choices. - $ratingallocate = mod_ratingallocate_generator::get_ratingallocate_for_user($tc, - $this->moddb, $this->teacher); + $ratingallocate = mod_ratingallocate_generator::get_ratingallocate_for_user( + $tc, + $this->moddb, + $this->teacher + ); $timeneeded = $ratingallocate->distribute_choices(); $tc->assertGreaterThan(0, $timeneeded); $tc->assertLessThan(2.0, $timeneeded, 'Allocation is very slow'); diff --git a/tests/locallib_test.php b/tests/locallib_test.php index 3f19e573..62d32a2d 100644 --- a/tests/locallib_test.php +++ b/tests/locallib_test.php @@ -43,7 +43,6 @@ #[CoversFunction('get_allocations')] #[CoversFunction('get_ratings_for_rateable_choices')] final class locallib_test extends \advanced_testcase { - /** * Tests a simple allocation scenario. * @@ -65,9 +64,10 @@ public function test_simple(): void { // There should not be any module for that course first. $this->assertFalse( - $DB->record_exists(this_db\ratingallocate::TABLE, - [this_db\ratingallocate::COURSE => $course->id] - ) + $DB->record_exists( + this_db\ratingallocate::TABLE, + [this_db\ratingallocate::COURSE => $course->id] + ) ); // Set default data for category. @@ -83,8 +83,11 @@ public function test_simple(): void { // Create activity. $mod = mod_ratingallocate_generator::create_instance_with_choices($this, $moduledata, $choicedata); - $this->assertEquals(2, $DB->count_records(this_db\ratingallocate_choices::TABLE), - "Failure, debug info: " . implode(",", [this_db\ratingallocate_choices::ID => $mod->id])); + $this->assertEquals( + 2, + $DB->count_records(this_db\ratingallocate_choices::TABLE), + "Failure, debug info: " . implode(",", [this_db\ratingallocate_choices::ID => $mod->id]) + ); $student1 = mod_ratingallocate_generator::create_user_and_enrol($this, $course); $student2 = mod_ratingallocate_generator::create_user_and_enrol($this, $course); @@ -128,11 +131,13 @@ public function test_simple(): void { $numallocations = $DB->count_records(this_db\ratingallocate_allocations::TABLE); $this->assertEquals(4, $numallocations, 'There should be only 4 allocations, since there are only 4 choices.'); - $allocations = $DB->get_records(this_db\ratingallocate_allocations::TABLE, - [this_db\ratingallocate_allocations::RATINGALLOCATEID => $mod->{this_db\ratingallocate::ID}], - ''); + $allocations = $DB->get_records( + this_db\ratingallocate_allocations::TABLE, + [this_db\ratingallocate_allocations::RATINGALLOCATEID => $mod->{this_db\ratingallocate::ID}], + '' + ); - $mapuserid = function($elem) { + $mapuserid = function ($elem) { return $elem->{this_db\ratingallocate_allocations::USERID}; }; @@ -151,7 +156,8 @@ public function test_simple(): void { // We now unenrol a user and make sure he will not be considered in distribution. $manualenrolplugin = enrol_get_plugin('manual'); $enrolinstance = array_values( - array_filter(enrol_get_instances($course->id, true), fn($instance) => $instance->enrol == "manual"))[0]; + array_filter(enrol_get_instances($course->id, true), fn($instance) => $instance->enrol == "manual") + )[0]; $manualenrolplugin->unenrol_user($enrolinstance, $student3->id); // Re-distributing will first clear all allocations, so afterwards we will see if the unenrolled user has been considered. @@ -170,7 +176,7 @@ public function test_simple(): void { * @return array */ private static function filter_allocations_by_choice($allocations, $choiceid) { - $filterchoiceid = function($elem) use ($choiceid) { + $filterchoiceid = function ($elem) use ($choiceid) { return $elem->{this_db\ratingallocate_allocations::CHOICEID} == $choiceid; }; return array_filter($allocations, $filterchoiceid); @@ -202,7 +208,10 @@ public function test_get_option_titles_default(): void { $record = mod_ratingallocate_generator::get_default_values(); $testmodule = new \mod_ratingallocate_generated_module($this, $record); $ratingallocate = mod_ratingallocate_generator::get_ratingallocate_for_user( - $this, $testmodule->moddb, $testmodule->teacher); + $this, + $testmodule->moddb, + $testmodule->teacher + ); $result = $ratingallocate->get_options_titles($ratings); $this->assertEquals($expectedresult, $result); @@ -221,7 +230,10 @@ public function test_get_option_titles_custom(): void { $record['strategyopt']['strategy_yesno'] = $expectedresult; $testmodule = new \mod_ratingallocate_generated_module($this, $record); $ratingallocate = mod_ratingallocate_generator::get_ratingallocate_for_user( - $this, $testmodule->moddb, $testmodule->teacher); + $this, + $testmodule->moddb, + $testmodule->teacher + ); $result = $ratingallocate->get_options_titles($ratings); $this->assertEquals($expectedresult, $result); @@ -240,7 +252,10 @@ public function test_get_option_titles_custom1(): void { $record['strategyopt']['strategy_yesno'] = $expectedresult; $testmodule = new \mod_ratingallocate_generated_module($this, $record); $ratingallocate = mod_ratingallocate_generator::get_ratingallocate_for_user( - $this, $testmodule->moddb, $testmodule->teacher); + $this, + $testmodule->moddb, + $testmodule->teacher + ); $result = $ratingallocate->get_options_titles($ratings); $this->assertEquals($expectedresult, $result); @@ -261,7 +276,10 @@ public function test_get_option_titles_mixed(): void { $record['strategyopt']['strategy_yesno'] = $settings; $testmodule = new \mod_ratingallocate_generated_module($this, $record); $ratingallocate = mod_ratingallocate_generator::get_ratingallocate_for_user( - $this, $testmodule->moddb, $testmodule->teacher); + $this, + $testmodule->moddb, + $testmodule->teacher + ); $result = $ratingallocate->get_options_titles($ratings); $this->assertEquals($expectedresult, $result); @@ -291,8 +309,12 @@ public function test_reset_userdata(): void { ]; // Create ratingallocate instance. - $ratingallocate = mod_ratingallocate_generator::get_closed_ratingallocate_for_teacher($this, $choices, - $course, $ratings); + $ratingallocate = mod_ratingallocate_generator::get_closed_ratingallocate_for_teacher( + $this, + $choices, + $course, + $ratings + ); // Simulate Allocation. $ratingallocate->distribute_choices(); @@ -336,5 +358,4 @@ public function test_reset_userdata(): void { $this->assertEquals($accesstimestart + (2 * DAYSECS), $ra->accesstimestart); $this->assertEquals($accesstimestop + (2 * DAYSECS), $ra->accesstimestop); } - } diff --git a/tests/mod_generator_test.php b/tests/mod_generator_test.php index e45709ba..8a8dd417 100644 --- a/tests/mod_generator_test.php +++ b/tests/mod_generator_test.php @@ -35,7 +35,6 @@ */ #[CoversClass(mod_ratingallocate_generator::class)] final class mod_generator_test extends \advanced_testcase { - /** * Test the creation of a mod_ratingallocate instance with choices. * @@ -52,14 +51,17 @@ public function test_create_instance(): void { // There should not be any module for that course first. $this->assertFalse( - $DB->record_exists('ratingallocate', ['course' => $course->id, - ])); + $DB->record_exists('ratingallocate', ['course' => $course->id, + ]) + ); $records = $DB->get_records('ratingallocate_choices', [], 'id'); $this->assertEquals(0, count($records)); // Create activity. - $mod = mod_ratingallocate_generator::create_instance_with_choices($this, - ['course' => $course]); + $mod = mod_ratingallocate_generator::create_instance_with_choices( + $this, + ['course' => $course] + ); $records = $DB->get_records('ratingallocate', ['course' => $course->id, ], 'id'); $this->assertEquals(1, count($records)); @@ -88,9 +90,12 @@ public function test_create_instance(): void { $this->assertEquals(json_decode(json_encode($expectedvaluesdb, false)), reset($records)); // Must have two choices. - $records = $DB->get_records('ratingallocate_choices', - ['ratingallocateid' => $mod->id, - ], 'title'); + $records = $DB->get_records( + 'ratingallocate_choices', + ['ratingallocateid' => $mod->id, + ], + 'title' + ); $this->assertEquals(2, count($records)); $choiceids = array_keys($records); $expectedchoices = [ @@ -155,7 +160,10 @@ public function test_mod_ratingallocate_generated_module(): void { $this->assertCount(20, $testmodule->allocations); $ratingallocate = mod_ratingallocate_generator::get_ratingallocate_for_user( - $this, $testmodule->moddb, $testmodule->teacher); + $this, + $testmodule->moddb, + $testmodule->teacher + ); foreach ($ratingallocate->get_choices_with_allocationcount() as $choice) { $this->assertEquals(10, $choice->{'usercount'}); } diff --git a/tests/mod_ratingallocate_allocate_unrated_test.php b/tests/mod_ratingallocate_allocate_unrated_test.php index 911398e5..35d0eee9 100644 --- a/tests/mod_ratingallocate_allocate_unrated_test.php +++ b/tests/mod_ratingallocate_allocate_unrated_test.php @@ -48,7 +48,6 @@ #[CoversFunction('get_choices_with_allocationcount')] #[CoversFunction('get_allocations_for_user')] final class mod_ratingallocate_allocate_unrated_test extends \advanced_testcase { - /** @var stdClass Course object. */ private stdClass $course; /** @var stdClass Enrolled teacher. */ @@ -110,8 +109,12 @@ private function test_group_memberships(): void { foreach ($students as $student) { $allocations = $this->ratingallocate->get_allocations_for_user($student->id); foreach ($allocations as $allocation) { - if (empty(array_filter($this->ratingallocate->get_rateable_choices(), - fn($choice) => $choice->id === $allocation->choiceid)[0]->usegroups)) { + if ( + empty(array_filter( + $this->ratingallocate->get_rateable_choices(), + fn($choice) => $choice->id === $allocation->choiceid + )[0]->usegroups) + ) { // If the choice has no group restrictions active we do not have to assert anything. continue; } @@ -145,11 +148,13 @@ public function test_get_all_groups_of_choices(): void { ]; } - $mod = mod_ratingallocate_generator::create_instance_with_choices($this, + $mod = mod_ratingallocate_generator::create_instance_with_choices( + $this, ['course' => $this->course, 'strategyopt' => ['countoptions' => 3], 'strategy' => 'strategy_order'], - $choices); + $choices + ); $this->ratingallocate = mod_ratingallocate_generator::get_ratingallocate_for_user($this, $mod, $this->teacher); // Assign blue group to choice D, green group to choice E. @@ -187,11 +192,13 @@ public function test_get_user_groupids(): void { ]; } - $mod = mod_ratingallocate_generator::create_instance_with_choices($this, + $mod = mod_ratingallocate_generator::create_instance_with_choices( + $this, ['course' => $this->course, 'strategyopt' => ['countoptions' => 3], 'strategy' => 'strategy_order'], - $choices); + $choices + ); $this->ratingallocate = mod_ratingallocate_generator::get_ratingallocate_for_user($this, $mod, $this->teacher); // Pick random red group user, also assign to group blue and green. @@ -239,16 +246,20 @@ public function test_get_undistributed_users(): void { ]; } - $mod = mod_ratingallocate_generator::create_instance_with_choices($this, + $mod = mod_ratingallocate_generator::create_instance_with_choices( + $this, ['course' => $this->course, 'strategyopt' => ['countoptions' => 3], 'strategy' => 'strategy_order'], - $choices); + $choices + ); $this->ratingallocate = mod_ratingallocate_generator::get_ratingallocate_for_user($this, $mod, $this->teacher); // Assign blue and green group to choice D, red group to choice E. - $this->ratingallocate->update_choice_groups($this->get_choice_id_by_title('D'), - [$this->blue->id, $this->green->id, $this->red->id]); + $this->ratingallocate->update_choice_groups( + $this->get_choice_id_by_title('D'), + [$this->blue->id, $this->green->id, $this->red->id] + ); $this->ratingallocate->update_choice_groups($this->get_choice_id_by_title('E'), [$this->red->id]); $studentonetwogroups = $this->studentsred[7]; @@ -292,22 +303,32 @@ public function test_get_undistributed_users(): void { $raters = array_values($this->ratingallocate->get_raters_in_course()); // Additionally check that the original order of the users has been preserved if group count is equal. // For groupcount 2. - $this->assertEquals(array_search($studentonetwogroups, $raters) > array_search($studenttwotwogroups, $raters), - array_search($studentonetwogroups->id, $users) > array_search($studenttwotwogroups->id, $users)); - $this->assertEquals(array_search($studenttwotwogroups, $raters) > array_search($studentthreetwogroups, $raters), - array_search($studenttwotwogroups->id, $users) > array_search($studentthreetwogroups->id, $users)); + $this->assertEquals( + array_search($studentonetwogroups, $raters) > array_search($studenttwotwogroups, $raters), + array_search($studentonetwogroups->id, $users) > array_search($studenttwotwogroups->id, $users) + ); + $this->assertEquals( + array_search($studenttwotwogroups, $raters) > array_search($studentthreetwogroups, $raters), + array_search($studenttwotwogroups->id, $users) > array_search($studentthreetwogroups->id, $users) + ); // For groupcount 3. - $this->assertEquals(array_search($studentonethreegroups, $raters) > array_search($studenttwothreegroups, $raters), - array_search($studentonethreegroups->id, $users) > array_search($studenttwothreegroups->id, $users)); + $this->assertEquals( + array_search($studentonethreegroups, $raters) > array_search($studenttwothreegroups, $raters), + array_search($studentonethreegroups->id, $users) > array_search($studenttwothreegroups->id, $users) + ); // For groupcount 1. for ($i = 0; $i < 25; $i++) { - $this->assertEquals(array_values(array_filter($raters, - fn($rater) => count($this->ratingallocate->get_user_groupids($rater->id)) == 1))[$i]->id, $users[$i]); + $this->assertEquals(array_values(array_filter( + $raters, + fn($rater) => count($this->ratingallocate->get_user_groupids($rater->id)) == 1 + ))[$i]->id, $users[$i]); } // For groupcount 0. for ($i = 0; $i < 10; $i++) { - $this->assertEquals(array_values(array_filter($raters, - fn($rater) => count($this->ratingallocate->get_user_groupids($rater->id)) == 0))[$i]->id, $users[$i + 30]); + $this->assertEquals(array_values(array_filter( + $raters, + fn($rater) => count($this->ratingallocate->get_user_groupids($rater->id)) == 0 + ))[$i]->id, $users[$i + 30]); } } @@ -329,8 +350,10 @@ private function get_choice_id_by_title(string $title): int { * @return stdClass the choice object */ private function get_choice_by_title(string $title): stdClass { - return array_values(array_filter($this->ratingallocate->get_rateable_choices(), - fn($choice) => $choice->title === $title))[0]; + return array_values(array_filter( + $this->ratingallocate->get_rateable_choices(), + fn($choice) => $choice->title === $title + ))[0]; } /** @@ -352,8 +375,10 @@ private function get_allocation_count_for_choice(string $title): int { * @return array */ private function get_allocations_for_choice(string $title): array { - $allocationsofchoice = array_filter($this->ratingallocate->get_allocations(), - fn($allocation) => $allocation->choiceid == $this->get_choice_id_by_title($title)); + $allocationsofchoice = array_filter( + $this->ratingallocate->get_allocations(), + fn($allocation) => $allocation->choiceid == $this->get_choice_id_by_title($title) + ); return array_map(fn($allocation) => $allocation->userid, $allocationsofchoice); } @@ -375,14 +400,22 @@ private function allocate_random_users(): void { * @return void */ private function assert_allocation_of_random_users(): void { - $this->assertEquals($this->get_choice_id_by_title('B'), - array_values($this->ratingallocate->get_allocations_for_user($this->studentsgreen[3]->id))[0]->choiceid); - $this->assertEquals($this->get_choice_id_by_title('B'), - array_values($this->ratingallocate->get_allocations_for_user($this->studentsred[7]->id))[0]->choiceid); - $this->assertEquals($this->get_choice_id_by_title('C'), - array_values($this->ratingallocate->get_allocations_for_user($this->studentsblue[9]->id))[0]->choiceid); - $this->assertEquals($this->get_choice_id_by_title('D'), - array_values($this->ratingallocate->get_allocations_for_user($this->studentsnogroup[2]->id))[0]->choiceid); + $this->assertEquals( + $this->get_choice_id_by_title('B'), + array_values($this->ratingallocate->get_allocations_for_user($this->studentsgreen[3]->id))[0]->choiceid + ); + $this->assertEquals( + $this->get_choice_id_by_title('B'), + array_values($this->ratingallocate->get_allocations_for_user($this->studentsred[7]->id))[0]->choiceid + ); + $this->assertEquals( + $this->get_choice_id_by_title('C'), + array_values($this->ratingallocate->get_allocations_for_user($this->studentsblue[9]->id))[0]->choiceid + ); + $this->assertEquals( + $this->get_choice_id_by_title('D'), + array_values($this->ratingallocate->get_allocations_for_user($this->studentsnogroup[2]->id))[0]->choiceid + ); } /** @@ -405,11 +438,13 @@ public function test_distribution_without_groups(): void { 'usegroups' => false, ]; } - $mod = mod_ratingallocate_generator::create_instance_with_choices($this, + $mod = mod_ratingallocate_generator::create_instance_with_choices( + $this, ['course' => $this->course, 'strategyopt' => ['countoptions' => 3], 'strategy' => 'strategy_order'], - $choices); + $choices + ); $this->ratingallocate = mod_ratingallocate_generator::get_ratingallocate_for_user($this, $mod, $this->teacher); $this->ratingallocate->add_allocation($this->get_choice_id_by_title('A'), $this->studentsnogroup[0]->id); @@ -475,11 +510,13 @@ private function test_allocation_with_groups_with_algorithm(string $algorithm): ]; } - $mod = mod_ratingallocate_generator::create_instance_with_choices($this, + $mod = mod_ratingallocate_generator::create_instance_with_choices( + $this, ['course' => $this->course, 'strategyopt' => ['countoptions' => 3], 'strategy' => 'strategy_order'], - $choices); + $choices + ); $this->ratingallocate = mod_ratingallocate_generator::get_ratingallocate_for_user($this, $mod, $this->teacher); // Assign blue and green group to choice D. So D is only available to green and blue students. $this->ratingallocate->update_choice_groups($this->get_choice_id_by_title('D'), [$this->blue->id, $this->green->id]); @@ -546,11 +583,13 @@ private function test_allocation_without_groups_with_algorithm(string $algorithm $choices[] = $choice; } - $mod = mod_ratingallocate_generator::create_instance_with_choices($this, + $mod = mod_ratingallocate_generator::create_instance_with_choices( + $this, ['course' => $this->course, 'strategyopt' => ['countoptions' => 3], 'strategy' => 'strategy_order'], - $choices); + $choices + ); $this->ratingallocate = mod_ratingallocate_generator::get_ratingallocate_for_user($this, $mod, $this->teacher); // We now test what happens with more users than places in the choices. @@ -600,11 +639,13 @@ public function test_distribute_equally_without_groups(): void { $choices[] = $choice; $i -= 2; } - $mod = mod_ratingallocate_generator::create_instance_with_choices($this, + $mod = mod_ratingallocate_generator::create_instance_with_choices( + $this, ['course' => $this->course, 'strategyopt' => ['countoptions' => 3], 'strategy' => 'strategy_order'], - $choices); + $choices + ); $this->ratingallocate = mod_ratingallocate_generator::get_ratingallocate_for_user($this, $mod, $this->teacher); // Randomly manually allocate some students to some choices to see if the algorithm can deal with that. @@ -650,11 +691,13 @@ public function test_distribute_fill_without_groups(): void { ]; $i -= 2; } - $mod = mod_ratingallocate_generator::create_instance_with_choices($this, + $mod = mod_ratingallocate_generator::create_instance_with_choices( + $this, ['course' => $this->course, 'strategyopt' => ['countoptions' => 3], 'strategy' => 'strategy_order'], - $choices); + $choices + ); $this->ratingallocate = mod_ratingallocate_generator::get_ratingallocate_for_user($this, $mod, $this->teacher); // Randomly manually allocate some students to some choices to see if the algorithm can deal with that. diff --git a/tests/mod_ratingallocate_choice_groups_test.php b/tests/mod_ratingallocate_choice_groups_test.php index 102b44d6..435c7007 100644 --- a/tests/mod_ratingallocate_choice_groups_test.php +++ b/tests/mod_ratingallocate_choice_groups_test.php @@ -38,7 +38,6 @@ #[CoversFunction('filter_choices_by_groups')] #[CoversFunction('update_choice_groups')] final class mod_ratingallocate_choice_groups_test extends \advanced_testcase { - /** * @var stdClass The environment that will be used for testing * This Class contains: @@ -82,10 +81,11 @@ private function get_choice_map(array|null $choices = null): array { $choices = $this->env->ratingallocate->get_rateable_choices(); } return array_flip(array_map( - function($a) { + function ($a) { return $a->title; }, - $choices)); + $choices + )); } /** @@ -276,5 +276,4 @@ public function test_update_choice_groups(): void { $this->assertNotContains($groupidmap['Green Group'], array_keys($groups)); $this->assertContains($groupidmap['Blue Group'], array_keys($groups)); } - } diff --git a/tests/mod_ratingallocate_choice_importer_test.php b/tests/mod_ratingallocate_choice_importer_test.php index e2f68541..5de48e51 100644 --- a/tests/mod_ratingallocate_choice_importer_test.php +++ b/tests/mod_ratingallocate_choice_importer_test.php @@ -33,7 +33,6 @@ * @covers \choice_importer */ final class mod_ratingallocate_choice_importer_test extends \advanced_testcase { - /** @var object The environment that will be used for testing * This Class contains: * - A course @@ -51,7 +50,7 @@ final class mod_ratingallocate_choice_importer_test extends \advanced_testcase { * * @return array Lines of text. */ - private function get_choice_lines($joined=false) { + private function get_choice_lines($joined = false) { // Whitespace should be trimmed by the importer. $contents = []; $contents[] = 'title, explanation, maxsize, active, groups'; @@ -113,7 +112,8 @@ public function test_choice_importer_testmode(): void { $this->assertEquals($importstatus->status, choice_importer::IMPORT_STATUS_OK); $this->assertEquals($importstatus->readcount, 4); $this->assertEquals($importstatus->importcount, 3); - $this->assertEquals($importstatus->status_message, + $this->assertEquals( + $importstatus->status_message, get_string('csvupload_test_success', 'ratingallocate', ['importcount' => $importstatus->importcount]) ); @@ -133,7 +133,8 @@ public function test_choice_importer_livemode(): void { $this->assertEquals($importstatus->status, choice_importer::IMPORT_STATUS_OK); $this->assertEquals($importstatus->readcount, 4); $this->assertEquals($importstatus->importcount, 3); - $this->assertEquals($importstatus->status_message, + $this->assertEquals( + $importstatus->status_message, get_string('csvupload_live_success', 'ratingallocate', ['importcount' => $importstatus->importcount]) ); $choices = $this->env->ratingallocate->get_choices(); @@ -227,7 +228,8 @@ public function test_bad_group(): void { 'row' => 5, 'invalidgroups' => 'Blue Man Group', ])); - $this->assertEquals($importstatus->status_message, + $this->assertEquals( + $importstatus->status_message, get_string('csvupload_live_problems', 'ratingallocate', 1) ); $choices = $this->env->ratingallocate->get_choices(); @@ -242,5 +244,4 @@ public function test_bad_group(): void { $badgroups = $this->env->ratingallocate->get_choice_groups($badchoice->id); $this->assertEquals(count($badgroups), 0, 'Bad group has not been added'); } - } diff --git a/tests/mod_ratingallocate_notification_test.php b/tests/mod_ratingallocate_notification_test.php index 62e260f3..190e0e6b 100644 --- a/tests/mod_ratingallocate_notification_test.php +++ b/tests/mod_ratingallocate_notification_test.php @@ -30,7 +30,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ final class mod_ratingallocate_notification_test extends \advanced_testcase { - /** * Choice 1. */ @@ -96,8 +95,12 @@ public function test_allocation_notification(): void { ], ]; - $ratingallocate = \mod_ratingallocate_generator::get_closed_ratingallocate_for_teacher($this, $choices, - $course, $ratings); + $ratingallocate = \mod_ratingallocate_generator::get_closed_ratingallocate_for_teacher( + $this, + $choices, + $course, + $ratings + ); $allocations = $ratingallocate->get_allocations(); $this->assertArrayHasKey($students[1]->id, $allocations); $this->assertArrayHasKey($students[2]->id, $allocations); diff --git a/tests/mod_ratingallocate_privacy_provider_test.php b/tests/mod_ratingallocate_privacy_provider_test.php index 37a5a6f2..c8adffd9 100644 --- a/tests/mod_ratingallocate_privacy_provider_test.php +++ b/tests/mod_ratingallocate_privacy_provider_test.php @@ -145,8 +145,11 @@ public function test_delete_data_for_user(): void { $count = $DB->count_records('ratingallocate_ratings'); $this->assertEquals(20, $count); - $contextlist = new \core_privacy\local\request\approved_contextlist($student, 'ratingallocate', - [$context->id]); + $contextlist = new \core_privacy\local\request\approved_contextlist( + $student, + 'ratingallocate', + [$context->id] + ); provider::delete_data_for_user($contextlist); // After deletion, the ratings and allocations for the first student should have been deleted. @@ -212,16 +215,22 @@ public function test_delete_for_users_in_context(): void { ]; // Before deletion, we should have 20 responses and 10 allocations in instance 1. - $count = $DB->count_records_select('ratingallocate_ratings', - "choiceid IN (SELECT id FROM {ratingallocate_choices} " . - "WHERE ratingallocateid = :ratingallocateid)", $params1); + $count = $DB->count_records_select( + 'ratingallocate_ratings', + "choiceid IN (SELECT id FROM {ratingallocate_choices} " . + "WHERE ratingallocateid = :ratingallocateid)", + $params1 + ); $this->assertEquals(20, $count); $count = $DB->count_records('ratingallocate_allocations', $params1); $this->assertEquals(10, $count); // Before deletion, we should have 20 responses and 10 allocations in instance 2. - $count = $DB->count_records_select('ratingallocate_ratings', - "choiceid IN (SELECT id FROM {ratingallocate_choices} " . - "WHERE ratingallocateid = :ratingallocateid)", $params2); + $count = $DB->count_records_select( + 'ratingallocate_ratings', + "choiceid IN (SELECT id FROM {ratingallocate_choices} " . + "WHERE ratingallocateid = :ratingallocateid)", + $params2 + ); $this->assertEquals(20, $count); $count = $DB->count_records('ratingallocate_allocations', $params2); $this->assertEquals(10, $count); @@ -239,24 +248,32 @@ public function test_delete_for_users_in_context(): void { // Select one assigned student. $userlist[] = array_pop($this->testmodule->allocations)->userid; - $approveduserlist = new \core_privacy\local\request\approved_userlist($cmcontext, 'mod_ratingallocate', - $userlist); + $approveduserlist = new \core_privacy\local\request\approved_userlist( + $cmcontext, + 'mod_ratingallocate', + $userlist + ); provider::delete_data_for_users($approveduserlist); // Afterwards 2 ratings and 1 allocation should be missing. - $count = $DB->count_records_select('ratingallocate_ratings', - "choiceid IN (SELECT id FROM {ratingallocate_choices} " . - "WHERE ratingallocateid = :ratingallocateid)", $params1); + $count = $DB->count_records_select( + 'ratingallocate_ratings', + "choiceid IN (SELECT id FROM {ratingallocate_choices} " . + "WHERE ratingallocateid = :ratingallocateid)", + $params1 + ); $this->assertEquals(18, $count); $count = $DB->count_records('ratingallocate_allocations', $params1); $this->assertEquals(9, $count); // The second instance should not be touched. - $count = $DB->count_records_select('ratingallocate_ratings', - "choiceid IN (SELECT id FROM {ratingallocate_choices} " . - "WHERE ratingallocateid = :ratingallocateid)", $params2); + $count = $DB->count_records_select( + 'ratingallocate_ratings', + "choiceid IN (SELECT id FROM {ratingallocate_choices} " . + "WHERE ratingallocateid = :ratingallocateid)", + $params2 + ); $this->assertEquals(20, $count); $count = $DB->count_records('ratingallocate_allocations', $params2); $this->assertEquals(10, $count); } - } diff --git a/tests/mod_ratingallocate_processor_test.php b/tests/mod_ratingallocate_processor_test.php index 7b2093ab..7ddd2833 100644 --- a/tests/mod_ratingallocate_processor_test.php +++ b/tests/mod_ratingallocate_processor_test.php @@ -29,7 +29,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ final class mod_ratingallocate_processor_test extends \advanced_testcase { - public function setUp(): void { global $PAGE; parent::setUp(); @@ -110,26 +109,37 @@ public function test_ratings_table_filter(): void { // Count of users with ratings should equal to 4. $table = $this->setup_ratings_table_with_filter_options($ratingallocate, true, false, 0); - self::assertEquals(4, count($table->rawdata), - "Filtering the users to those with ratings should return 4 users."); + self::assertEquals( + 4, + count($table->rawdata), + "Filtering the users to those with ratings should return 4 users." + ); // Count of users in total should be equal to 6. $table = $this->setup_ratings_table_with_filter_options($ratingallocate, false, false, 0); - self::assertEquals(6, count($table->rawdata), - "Filtering the users to those with or without ratings should return 6 users."); + self::assertEquals( + 6, + count($table->rawdata), + "Filtering the users to those with or without ratings should return 6 users." + ); // Count of users with ratings where a allocation is necessary equal to 1. $table = $this->setup_ratings_table_with_filter_options($ratingallocate, true, true, 0); - self::assertEquals(1, count($table->rawdata), - 'Filtering the users to those with ratings and' . - 'where a allocation is necessary should return 1 user.'); + self::assertEquals( + 1, + count($table->rawdata), + 'Filtering the users to those with ratings and' . + 'where a allocation is necessary should return 1 user.' + ); // Count of users with or without ratings where a allocation is necessary equal to 1. $table = $this->setup_ratings_table_with_filter_options($ratingallocate, false, true, 0); - self::assertEquals(2, count($table->rawdata), - 'Filtering the users to those with or without ratings and' . - 'where a allocation is necessary should return 2 users.'); - + self::assertEquals( + 2, + count($table->rawdata), + 'Filtering the users to those with or without ratings and' . + 'where a allocation is necessary should return 2 users.' + ); } /** @@ -190,23 +200,35 @@ public function test_ratings_table_groupfilter(): void { // Count of participants in total should be equal to 4. $table = $this->setup_ratings_table_with_filter_options($ratingallocate, false, false, 0); - self::assertEquals(4, count($table->rawdata), - "Filtering the users to all course participants who could access the activity should return 4 users."); + self::assertEquals( + 4, + count($table->rawdata), + "Filtering the users to all course participants who could access the activity should return 4 users." + ); // Count of users in group1 should be equal to 2. $table = $this->setup_ratings_table_with_filter_options($ratingallocate, false, false, $groupidmap['group1']); - self::assertEquals(2, count($table->rawdata), - "Filtering the users to those in group1 should return 2 users."); + self::assertEquals( + 2, + count($table->rawdata), + "Filtering the users to those in group1 should return 2 users." + ); // Count of users in group1 should be equal to 2. $table = $this->setup_ratings_table_with_filter_options($ratingallocate, false, false, $groupidmap['group2']); - self::assertEquals(2, count($table->rawdata), - "Filtering the users to those in group2 should return 2 users."); + self::assertEquals( + 2, + count($table->rawdata), + "Filtering the users to those in group2 should return 2 users." + ); // Count of users in neither group used in the ratingallocate activity should be equal to 1. $table = $this->setup_ratings_table_with_filter_options($ratingallocate, false, false, -1); - self::assertEquals(1, count($table->rawdata), - "Filtering the users to those in neither group should return 1 user."); + self::assertEquals( + 1, + count($table->rawdata), + "Filtering the users to those in neither group should return 1 user." + ); } /** @@ -223,13 +245,17 @@ private function alter_user_base_for_filter_test($ratingallocate) { $ratingallocate->remove_allocation(reset($allocationsofuser)->choiceid, $userwithoutallocation->id); // Enrol a new user without ratings to the course. - \mod_ratingallocate_generator::create_user_and_enrol($this, - get_course($ratingallocate->ratingallocate->course)); + \mod_ratingallocate_generator::create_user_and_enrol( + $this, + get_course($ratingallocate->ratingallocate->course) + ); $choices = $ratingallocate->get_rateable_choices(); // Enrol a new user without ratings to the course and create an allocation for her. - $userwithoutratingwithallocation = \mod_ratingallocate_generator::create_user_and_enrol($this, - get_course($ratingallocate->ratingallocate->course)); + $userwithoutratingwithallocation = \mod_ratingallocate_generator::create_user_and_enrol( + $this, + get_course($ratingallocate->ratingallocate->course) + ); $ratingallocate->add_allocation(reset($choices)->id, $userwithoutratingwithallocation->id); } @@ -245,8 +271,14 @@ private function alter_user_base_for_filter_test($ratingallocate) { private function setup_ratings_table_with_filter_options($ratingallocate, $hidenorating, $showallocnecessary, $groupselect) { // Create and set up the flextable for ratings and allocations. $choices = $ratingallocate->get_rateable_choices(); - $table = new ratings_and_allocations_table($ratingallocate->get_renderer(), - [], $ratingallocate, 'show_alloc_table', 'mod_ratingallocate_test', false); + $table = new ratings_and_allocations_table( + $ratingallocate->get_renderer(), + [], + $ratingallocate, + 'show_alloc_table', + 'mod_ratingallocate_test', + false + ); $table->setup_table($choices, $hidenorating, $showallocnecessary, $groupselect); return $table; @@ -299,10 +331,11 @@ private function get_choice_map($ratingallocate, $choices = null) { $choices = $ratingallocate->get_rateable_choices(); } $choiceidmap = array_flip(array_map( - function($a) { + function ($a) { return $a->title; }, - $choices)); + $choices + )); return $choiceidmap; } diff --git a/tests/mod_ratingallocate_solver_test.php b/tests/mod_ratingallocate_solver_test.php index c703d178..ac03aff2 100644 --- a/tests/mod_ratingallocate_solver_test.php +++ b/tests/mod_ratingallocate_solver_test.php @@ -34,7 +34,6 @@ * @covers \solver */ final class mod_ratingallocate_solver_test extends \basic_testcase { - /** * Perform race. * @@ -84,7 +83,7 @@ private function perform_race($groupsnum, $ratersnum) { $solvers = ['solver_edmonds_karp', 'solver_ford_fulkerson']; foreach ($solvers as $solver) { - $solver1 = new $solver; + $solver1 = new $solver(); $timestart = microtime(true); $distribution1 = $solver1->compute_distribution($groups, $ratings, $usercount); $result[$solver1->get_name()]['elapsed_sec'] = (microtime(true) - $timestart); @@ -114,8 +113,10 @@ public function teston_random() { $rundenergebnis = []; for ($i = 0; $i < 10; $i++) { $ergebnis = $this->perform_race($paramgroups, $paramusers); - $this->assertEquals($ergebnis['ford-fulkerson Koegel2014']['gesamtpunktzahl'], - $ergebnis['edmonds_karp']['gesamtpunktzahl']); + $this->assertEquals( + $ergebnis['ford-fulkerson Koegel2014']['gesamtpunktzahl'], + $ergebnis['edmonds_karp']['gesamtpunktzahl'] + ); $rundenergebnis[] = $ergebnis; } $durchschnitt = []; @@ -216,8 +217,10 @@ public function test_edmondskarp(): void { $solverkoe = new \solver_ford_fulkerson(); $distributionkoe = $solverkoe->compute_distribution($choices, $ratings, $usercount); $this->assertEquals($solverkoe::compute_target_function($ratings, $distributionkoe), 15); - $this->assertEquals($solverkoe::compute_target_function($ratings, $distributionkoe), - $solver::compute_target_function($ratings, $distribution)); + $this->assertEquals( + $solverkoe::compute_target_function($ratings, $distributionkoe), + $solver::compute_target_function($ratings, $distribution) + ); } /** @@ -266,8 +269,10 @@ public function test_negweightcycle(): void { $distributionkoe = $solverkoe->compute_distribution($choices, $ratings, $usercount); $this->assertEquals($solverkoe::compute_target_function($ratings, $distributionkoe), 10); - $this->assertEquals($solverkoe::compute_target_function($ratings, $distributionkoe), - $solver::compute_target_function($ratings, $distribution)); + $this->assertEquals( + $solverkoe::compute_target_function($ratings, $distributionkoe), + $solver::compute_target_function($ratings, $distribution) + ); } /** @@ -329,7 +334,7 @@ public function test_setupids(): void { $ratings[4]->rating = 2; $usercount = 2; - list($fromuserid, $touserid, $fromchoiceid, $tochoiceid) = \solver_edmonds_karp::setup_id_conversions($usercount, $ratings); + [$fromuserid, $touserid, $fromchoiceid, $tochoiceid] = \solver_edmonds_karp::setup_id_conversions($usercount, $ratings); $this->assertEquals([3 => 1, 2 => 2], $fromuserid); $this->assertEquals([1 => 3, 2 => 2], $touserid); @@ -337,5 +342,4 @@ public function test_setupids(): void { $this->assertEquals([1 => 3, 2 => 4], $fromchoiceid); $this->assertEquals([3 => 1, 4 => 2], $tochoiceid); } - } diff --git a/tests/mod_ratingallocate_status_test.php b/tests/mod_ratingallocate_status_test.php index a2905e2f..e7a13930 100644 --- a/tests/mod_ratingallocate_status_test.php +++ b/tests/mod_ratingallocate_status_test.php @@ -39,7 +39,6 @@ #[CoversClass(ratingallocate::class)] #[CoversMethod(ratingallocate::class, 'get_status')] final class mod_ratingallocate_status_test extends \advanced_testcase { - public function setUp(): void { global $PAGE; parent::setUp(); @@ -116,5 +115,4 @@ public function test_get_status($addtostart, $addtostop, $published, $hasallocat $status = $ratingallocate->get_status(); $this->assertEquals($expected, $status); } - } diff --git a/tests/mod_ratingallocate_strategy_test.php b/tests/mod_ratingallocate_strategy_test.php index 63073891..c7604395 100644 --- a/tests/mod_ratingallocate_strategy_test.php +++ b/tests/mod_ratingallocate_strategy_test.php @@ -34,7 +34,6 @@ * @package mod_ratingallocate */ final class mod_ratingallocate_strategy_test extends \advanced_testcase { - /** * Test for correct validation of settings * @@ -191,5 +190,4 @@ public function test_tickyes_validation(): void { $strategy = new \mod_ratingallocate\strategy_tickyes\strategy($settings); $this->assertCount(0, $strategy->validate_settings()); } - }