diff --git a/.github/workflows/moodle-ci.yml b/.github/workflows/moodle-ci.yml index d3e3a4f8..6903de17 100644 --- a/.github/workflows/moodle-ci.yml +++ b/.github/workflows/moodle-ci.yml @@ -8,8 +8,8 @@ jobs: strategy: matrix: - php: ['8.2'] - moodle-branch: ['MOODLE_403_STABLE'] + php: ['8.3'] + moodle-branch: ['MOODLE_404_STABLE'] database: ['pgsql'] steps: @@ -17,7 +17,7 @@ jobs: run: docker run -p 5432:5432 -e POSTGRES_USER=postgres -e POSTGRES_HOST_AUTH_METHOD=trust -d postgres:14 - name: Check out repository code - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: path: plugin @@ -28,29 +28,9 @@ jobs: ini-values: max_input_vars=5000 coverage: none - - name: Get composer cache directory - id: composer-cache - run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT - - - name: Composer cache - uses: actions/cache@v3 - with: - path: ${{ steps.composer-cache.outputs.dir }} - key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} - restore-keys: | - ${{ runner.os }}-composer- - - - name: npm cache - uses: actions/cache@v3 - with: - path: ~/.npm - key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} - restore-keys: | - ${{ runner.os }}-node- - - name: Initialise moodle-plugin-ci run: | - composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^3 + composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^4 echo $(cd ci/bin; pwd) >> $GITHUB_PATH echo $(cd ci/vendor/bin; pwd) >> $GITHUB_PATH sudo locale-gen en_AU.UTF-8 @@ -67,11 +47,6 @@ jobs: if: ${{ always() }} run: moodle-plugin-ci phplint - - name: PHP Copy/Paste Detector - if: ${{ always() }} - run: moodle-plugin-ci phpcpd - continue-on-error: true - - name: PHP Mess Detector if: ${{ always() }} run: moodle-plugin-ci phpmd @@ -108,19 +83,27 @@ jobs: strategy: fail-fast: false matrix: - php: ['8.0', '8.1', '8.2'] - moodle-branch: ['MOODLE_401_STABLE', 'MOODLE_402_STABLE', 'MOODLE_403_STABLE'] + php: ['8.0', '8.1', '8.2', '8.3'] + moodle-branch: ['MOODLE_401_STABLE', 'MOODLE_402_STABLE', 'MOODLE_403_STABLE', 'MOODLE_404_STABLE'] database: ['mariadb', 'pgsql'] exclude: + - php: '8.0' + moodle-branch: 'MOODLE_404_STABLE' - php: '8.2' moodle-branch: 'MOODLE_401_STABLE' + - php: '8.3' + moodle-branch: 'MOODLE_401_STABLE' + - php: '8.3' + moodle-branch: 'MOODLE_402_STABLE' + - php: '8.3' + moodle-branch: 'MOODLE_403_STABLE' include: - - php: '8.0' - moodle-branch: 'MOODLE_400_STABLE' - database: 'mariadb' - - php: '8.0' - moodle-branch: 'MOODLE_400_STABLE' + - php: '7.4' + moodle-branch: 'MOODLE_401_STABLE' database: 'pgsql' + - php: '7.4' + moodle-branch: 'MOODLE_401_STABLE' + database: 'mariadb' steps: - name: Start MariaDB @@ -132,7 +115,7 @@ jobs: run: docker run -p 5432:5432 -e POSTGRES_USER=postgres -e POSTGRES_HOST_AUTH_METHOD=trust -d postgres:14 - name: Check out repository code - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: path: plugin @@ -143,24 +126,6 @@ jobs: ini-values: max_input_vars=5000 coverage: none - - name: Get composer cache directory - id: composer-cache - run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT - - name: Composer cache - uses: actions/cache@v3 - with: - path: ${{ steps.composer-cache.outputs.dir }} - key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} - restore-keys: | - ${{ runner.os }}-composer- - - name: npm cache - uses: actions/cache@v3 - with: - path: ~/.npm - key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} - restore-keys: | - ${{ runner.os }}-node- - - name: Initialise moodle-plugin-ci run: | composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^3 @@ -183,3 +148,15 @@ jobs: - name: Behat features if: ${{ always() }} run: moodle-plugin-ci behat --profile chrome --auto-rerun 0 + + # This step allows to upload Behat faildump (screenshots) as workflow artifact, + # so it can be downloaded and inspected. You do not need this step if you + # are not running Behat test. Artifact will be retained for 7 days. + - name: Upload Behat Faildump + if: ${{ failure() && steps.behat.outcome == 'failure' }} + uses: actions/upload-artifact@v4 + with: + name: Behat Faildump (${{ join(matrix.*, ', ') }}) + path: ${{ github.workspace }}/moodledata/behat_dump + retention-days: 7 + if-no-files-found: ignore diff --git a/backup/moodle2/backup_ratingallocate_activity_stepslib.php b/backup/moodle2/backup_ratingallocate_activity_stepslib.php index b682791f..1e209ab3 100644 --- a/backup/moodle2/backup_ratingallocate_activity_stepslib.php +++ b/backup/moodle2/backup_ratingallocate_activity_stepslib.php @@ -93,9 +93,9 @@ protected function define_structure() { // Define sources. $ratingallocate->set_source_table(get_tablename_for_tableClass('mod_ratingallocate\db\ratingallocate'), - array(this_db\ratingallocate::ID => backup::VAR_ACTIVITYID), this_db\ratingallocate_choices::ID . ' ASC'); + [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'), - array(this_db\ratingallocate_choices::RATINGALLOCATEID => backup::VAR_PARENTID), + [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( @@ -106,13 +106,14 @@ protected function define_structure() { if ($userinfo) { $ratingallocaterating->set_source_table(get_tablename_for_tableClass( 'mod_ratingallocate\db\ratingallocate_ratings'), - array(this_db\ratingallocate_ratings::CHOICEID => backup::VAR_PARENTID), + [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'), - array( - this_db\ratingallocate_allocations::RATINGALLOCATEID => backup::VAR_ACTIVITYID, - this_db\ratingallocate_allocations::CHOICEID => backup::VAR_PARENTID), + [ + this_db\ratingallocate_allocations::RATINGALLOCATEID => backup::VAR_ACTIVITYID, + this_db\ratingallocate_allocations::CHOICEID => backup::VAR_PARENTID, + ], this_db\ratingallocate_allocations::ID . ' ASC' ); } diff --git a/backup/moodle2/backup_restore_helper.php b/backup/moodle2/backup_restore_helper.php index 99cd1307..30b65c5a 100644 --- a/backup/moodle2/backup_restore_helper.php +++ b/backup/moodle2/backup_restore_helper.php @@ -15,32 +15,55 @@ // along with Moodle. If not, see . /** - * @package moodlecore + * Backup restore helper. + * + * @package mod_ratingallocate * @subpackage backup-moodle2 * @copyright 2014 C. Usener * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +/** + * Get fields for tableclass + * + * @param $class + * @return array + * @throws ReflectionException + */ function get_fields_for_tableclass($class) { $class = new ReflectionClass($class); $constants = $class->getConstants(); - $keystoremove = array('ID', 'TABLE'); + $keystoremove = ['ID', 'TABLE']; foreach ($constants as $key => $value) { - if (count(array_intersect(array($key), $keystoremove)) > 0) { + if (count(array_intersect([$key], $keystoremove)) > 0) { unset($constants[$key]); } } return array_values($constants); } +/** + * Get tablename for tableclass. + * + * @param $class + * @return mixed + * @throws ReflectionException + */ function get_tablename_for_tableclass($class) { $class = new ReflectionClass($class); $constants = $class->getConstants(); return $constants['TABLE']; } +/** + * Get id for tableclass. + * + * @param $class + * @return array + * @throws ReflectionException + */ function get_id_for_tableclass($class) { $class = new ReflectionClass($class); $constants = $class->getConstants(); - return array($constants['ID']); + return [$constants['ID']]; } diff --git a/backup/moodle2/restore_ratingallocate_activity_stepslib.php b/backup/moodle2/restore_ratingallocate_activity_stepslib.php index d89b4437..897a7a86 100644 --- a/backup/moodle2/restore_ratingallocate_activity_stepslib.php +++ b/backup/moodle2/restore_ratingallocate_activity_stepslib.php @@ -18,7 +18,7 @@ /** * - * @package moodlecore + * @package mod_ratingallocate * @subpackage backup-moodle2 * @copyright 2014 C. Usener * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later diff --git a/backup/moodle2/restore_ratingallocate_activity_task.class.php b/backup/moodle2/restore_ratingallocate_activity_task.class.php index 6fc7f75a..3a36cf24 100644 --- a/backup/moodle2/restore_ratingallocate_activity_task.class.php +++ b/backup/moodle2/restore_ratingallocate_activity_task.class.php @@ -27,6 +27,13 @@ */ require_once($CFG->dirroot . '/mod/ratingallocate/backup/moodle2/restore_ratingallocate_activity_stepslib.php'); +/** + * Restore ratingallocate activity class + * + * @package mod_ratingallocate + * @copyright 214 C. Usener + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ class restore_ratingallocate_activity_task extends restore_activity_task { /** @@ -49,7 +56,7 @@ protected function define_my_steps() { * processed by the link decoder */ public static function define_decode_contents() { - $contents = array(); + $contents = []; return $contents; } @@ -59,7 +66,7 @@ public static function define_decode_contents() { * to the activity to be executed by the link decoder */ public static function define_decode_rules() { - $rules = array(); + $rules = []; return $rules; } @@ -72,7 +79,7 @@ public static function define_decode_rules() { * of {@link restore_log_rule} objects */ public static function define_restore_log_rules() { - $rules = array(); + $rules = []; return $rules; } @@ -89,7 +96,7 @@ public static function define_restore_log_rules() { * activity level. All them are rules not linked to any module instance (cmid = 0) */ public static function define_restore_log_rules_for_course() { - $rules = array(); + $rules = []; return $rules; } } diff --git a/classes/algorithm_status.php b/classes/algorithm_status.php index 4cc3f497..ca12b028 100644 --- a/classes/algorithm_status.php +++ b/classes/algorithm_status.php @@ -23,8 +23,20 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class algorithm_status { - const FAILURE = -1; // Algorithm did not finish correctly. - const NOTSTARTED = 0; // Default status for new instances. - const RUNNING = 1; // Algorithm is currently running. - const FINISHED = 2; // Algorithm finished correctly. + /** + * Algorithm did not finish correctly. + */ + const FAILURE = -1; + /** + * Default status for new instances. + */ + const NOTSTARTED = 0; + /** + * Algorithm is currently running. + */ + const RUNNING = 1; + /** + * Algorithm finished correctly. + */ + const FINISHED = 2; } diff --git a/classes/allocations_table.php b/classes/allocations_table.php index 6418a037..541ef96b 100644 --- a/classes/allocations_table.php +++ b/classes/allocations_table.php @@ -29,6 +29,11 @@ require_once($CFG->libdir . '/tablelib.php'); require_once($CFG->dirroot . '/user/lib.php'); +/** + * Allocations table. + * + * @package mod_ratingallocate + */ class allocations_table extends \table_sql { /** @@ -44,7 +49,7 @@ public function __construct($ratingallocate) { parent::__construct('mod_ratingallocate_allocation_table'); global $PAGE; $url = $PAGE->url; - $url->params(array("action" => ACTION_SHOW_ALLOCATION_TABLE)); + $url->params(["action" => ACTION_SHOW_ALLOCATION_TABLE]); $PAGE->set_url($url); $this->ratingallocate = $ratingallocate; if (has_capability('mod/ratingallocate:export_ratings', $ratingallocate->get_context())) { @@ -203,10 +208,10 @@ private function get_user_link($user) { $name = fullname($user); if ($COURSE->id == SITEID) { - $profileurl = new \moodle_url('/user/profile.php', array('id' => $user->id)); + $profileurl = new \moodle_url('/user/profile.php', ['id' => $user->id]); } else { $profileurl = new \moodle_url('/user/view.php', - array('id' => $user->id, 'course' => $COURSE->id)); + ['id' => $user->id, 'course' => $COURSE->id]); } return \html_writer::link($profileurl, $name); } @@ -229,7 +234,7 @@ public function init_sql() { $where = "c.ratingallocateid = :ratingallocateid"; - $params = array(); + $params = []; $params['ratingallocateid'] = $this->ratingallocate->ratingallocate->id; $this->set_sql($fields, $from, $where, $params); diff --git a/classes/choice_importer.php b/classes/choice_importer.php index cd80e9c2..7954b0e7 100644 --- a/classes/choice_importer.php +++ b/classes/choice_importer.php @@ -15,6 +15,8 @@ // along with Moodle. If not, see . /** + * Choice importer. + * * @package mod_ratingallocate * @copyright 2021 Catalyst IT * @author David Thompson @@ -27,18 +29,29 @@ require_once($CFG->libdir . '/csvlib.class.php'); - +/** + * Choice importer. + * + * @package mod_ratingallocate + */ class choice_importer { - const REQUIRED_FIELDS = array("title", "explanation", "maxsize", "active", "groups"); + /** + * Required fields. + */ + const REQUIRED_FIELDS = ["title", "explanation", "maxsize", "active", "groups"]; - // The import process worked as expected. + /** + * The import process worked as expected. + */ const IMPORT_STATUS_OK = 'csvupload_ok'; - // Something went wrong during setup; import cannot continue. + /** + * Something went wrong during setup; import cannot continue. + */ const IMPORT_STATUS_SETUP_ERROR = 'csvupload_setuperror'; - // Partial success with data errors. + /** Partial success with data errors.*/ const IMPORT_STATUS_DATA_ERROR = 'csvupload_dataerror'; - // Default maximum number of warnings to show notifications for on import problems. + /** Default maximum number of warnings to show notifications for on import problems. */ const MAX_WARNING_COUNT = 5; /** @@ -66,11 +79,20 @@ public static function print_fields($fields=self::REQUIRED_FIELDS) { return '[' . join(', ', $fields) . ']'; } + /** + * Construct. + * + * @param $ratingallocateid + * @param $ratingallocate + */ public function __construct($ratingallocateid, $ratingallocate) { $this->ratingallocate = $ratingallocate; $this->ratingallocateid = $ratingallocateid; } + /** + * Destruct. + */ public function __destruct() { $this->free_reader(); } @@ -122,7 +144,7 @@ public function import($content, $live=true) { $importstatus = new \stdClass; $importstatus->status = self::IMPORT_STATUS_OK; // Unless we hear otherwise. $importstatus->live = $live; // Only commit live transactions. - $importstatus->errors = array(); + $importstatus->errors = []; $importstatus->importcount = 0; $importstatus->rowcount = 1; // Start at 1 for header. @@ -183,7 +205,7 @@ public function import($content, $live=true) { } if ($fieldname == 'groups') { - $groups = array(); + $groups = []; // Turn off 'usegroups' if no groups specified. if (empty(trim($cell))) { @@ -229,10 +251,10 @@ public function import($content, $live=true) { // Note for warnings. if (!empty($invalidgroups)) { $importstatus->status = self::IMPORT_STATUS_DATA_ERROR; - $warningmessage = get_string('csvupload_missing_groups', 'ratingallocate', array( + $warningmessage = get_string('csvupload_missing_groups', 'ratingallocate', [ 'row' => $importstatus->rowcount, 'invalidgroups' => join(', ', $invalidgroups), - )); + ]); $importstatus->errors[] = $warningmessage; } diff --git a/classes/event/all_ratings_deleted.php b/classes/event/all_ratings_deleted.php index 8730dbd3..3e08006a 100644 --- a/classes/event/all_ratings_deleted.php +++ b/classes/event/all_ratings_deleted.php @@ -32,7 +32,7 @@ class all_ratings_deleted extends \core\event\base { public static function create_simple($modulecontext, $ratingallocateid) { - return self::create(array('context' => $modulecontext, 'objectid' => $ratingallocateid)); + return self::create(['context' => $modulecontext, 'objectid' => $ratingallocateid]); } protected function init() { $this->data['crud'] = 'd'; @@ -46,15 +46,15 @@ public static function get_name() { public function get_description() { return get_string('log_all_ratings_deleted_description', 'mod_ratingallocate', - array('userid' => $this->userid, 'ratingallocateid' => $this->objectid)); + ['userid' => $this->userid, 'ratingallocateid' => $this->objectid]); } public function get_url() { - return new \moodle_url('/mod/ratingallocate/view.php', array('m' => $this->objectid)); + return new \moodle_url('/mod/ratingallocate/view.php', ['m' => $this->objectid]); } public static function get_objectid_mapping() { - return array('db' => 'ratingallocate', 'restore' => 'ratingallocate'); + return ['db' => 'ratingallocate', 'restore' => 'ratingallocate']; } public static function get_other_mapping() { diff --git a/classes/event/allocation_published.php b/classes/event/allocation_published.php index 71ded730..95a6a74a 100644 --- a/classes/event/allocation_published.php +++ b/classes/event/allocation_published.php @@ -40,7 +40,7 @@ class allocation_published extends \core\event\base { public static function create_simple($modulecontext, $ratingallocateid) { - return self::create(array('context' => $modulecontext, 'objectid' => $ratingallocateid)); + return self::create(['context' => $modulecontext, 'objectid' => $ratingallocateid]); } protected function init() { @@ -55,15 +55,15 @@ public static function get_name() { public function get_description() { return get_string('log_allocation_published_description', 'mod_ratingallocate', - array('userid' => $this->userid, 'ratingallocateid' => $this->objectid)); + ['userid' => $this->userid, 'ratingallocateid' => $this->objectid]); } public function get_url() { - return new \moodle_url('/mod/ratingallocate/view.php', array('m' => $this->objectid)); + return new \moodle_url('/mod/ratingallocate/view.php', ['m' => $this->objectid]); } public static function get_objectid_mapping() { - return array('db' => 'ratingallocate', 'restore' => 'ratingallocate'); + return ['db' => 'ratingallocate', 'restore' => 'ratingallocate']; } public static function get_other_mapping() { diff --git a/classes/event/allocation_statistics_viewed.php b/classes/event/allocation_statistics_viewed.php index f4d66954..df50f162 100644 --- a/classes/event/allocation_statistics_viewed.php +++ b/classes/event/allocation_statistics_viewed.php @@ -34,7 +34,7 @@ class allocation_statistics_viewed extends \core\event\base { public static function create_simple($modulecontext, $ratingallocateid) { - return self::create(array('context' => $modulecontext, 'objectid' => $ratingallocateid)); + return self::create(['context' => $modulecontext, 'objectid' => $ratingallocateid]); } protected function init() { @@ -49,15 +49,15 @@ public static function get_name() { public function get_description() { return get_string('log_allocation_statistics_viewed_description', 'mod_ratingallocate', - array('userid' => $this->userid, 'ratingallocateid' => $this->objectid)); + ['userid' => $this->userid, 'ratingallocateid' => $this->objectid]); } public function get_url() { - return new \moodle_url('/mod/ratingallocate/view.php', array('m' => $this->objectid)); + return new \moodle_url('/mod/ratingallocate/view.php', ['m' => $this->objectid]); } public static function get_objectid_mapping() { - return array('db' => 'ratingallocate', 'restore' => 'ratingallocate'); + return ['db' => 'ratingallocate', 'restore' => 'ratingallocate']; } public static function get_other_mapping() { diff --git a/classes/event/allocation_table_viewed.php b/classes/event/allocation_table_viewed.php index b1384949..d6cbc3ab 100644 --- a/classes/event/allocation_table_viewed.php +++ b/classes/event/allocation_table_viewed.php @@ -34,7 +34,7 @@ class allocation_table_viewed extends \core\event\base { public static function create_simple($modulecontext, $ratingallocateid) { - return self::create(array('context' => $modulecontext, 'objectid' => $ratingallocateid)); + return self::create(['context' => $modulecontext, 'objectid' => $ratingallocateid]); } protected function init() { @@ -49,15 +49,15 @@ public static function get_name() { public function get_description() { return get_string('log_allocation_table_viewed_description', 'mod_ratingallocate', - array('userid' => $this->userid, 'ratingallocateid' => $this->objectid)); + ['userid' => $this->userid, 'ratingallocateid' => $this->objectid]); } public function get_url() { - return new \moodle_url('/mod/ratingallocate/view.php', array('m' => $this->objectid)); + return new \moodle_url('/mod/ratingallocate/view.php', ['m' => $this->objectid]); } public static function get_objectid_mapping() { - return array('db' => 'ratingallocate', 'restore' => 'ratingallocate'); + return ['db' => 'ratingallocate', 'restore' => 'ratingallocate']; } public static function get_other_mapping() { diff --git a/classes/event/distribution_triggered.php b/classes/event/distribution_triggered.php index df587ac1..6e866f64 100644 --- a/classes/event/distribution_triggered.php +++ b/classes/event/distribution_triggered.php @@ -42,8 +42,8 @@ class distribution_triggered extends \core\event\base { public static function create_simple($modulecontext, $ratingallocateid, $timeneeded) { $timeneededjsonvalid = json_decode(json_encode($timeneeded), true); - return self::create(array('context' => $modulecontext, 'objectid' => $ratingallocateid, - 'other' => array('time_needed' => $timeneededjsonvalid))); + return self::create(['context' => $modulecontext, 'objectid' => $ratingallocateid, + 'other' => ['time_needed' => $timeneededjsonvalid]]); } protected function init() { @@ -58,17 +58,17 @@ public static function get_name() { public function get_description() { return get_string('log_distribution_triggered_description', 'mod_ratingallocate', - array('userid' => $this->userid, + ['userid' => $this->userid, 'ratingallocateid' => $this->objectid, - 'time_needed' => $this->other['time_needed'])); + 'time_needed' => $this->other['time_needed']]); } public function get_url() { - return new \moodle_url('/mod/ratingallocate/view.php', array('m' => $this->objectid)); + return new \moodle_url('/mod/ratingallocate/view.php', ['m' => $this->objectid]); } public static function get_objectid_mapping() { - return array('db' => 'ratingallocate', 'restore' => 'ratingallocate'); + return ['db' => 'ratingallocate', 'restore' => 'ratingallocate']; } public static function get_other_mapping() { diff --git a/classes/event/index_viewed.php b/classes/event/index_viewed.php index 34283943..7f42064e 100644 --- a/classes/event/index_viewed.php +++ b/classes/event/index_viewed.php @@ -33,7 +33,7 @@ class index_viewed extends \core\event\base { public static function create_simple($coursecontext) { - return self::create(array('context' => $coursecontext)); + return self::create(['context' => $coursecontext]); } protected function init() { @@ -46,15 +46,15 @@ public static function get_name() { } public function get_description() { - return get_string('log_index_viewed_description', 'mod_ratingallocate', array('userid' => $this->userid)); + return get_string('log_index_viewed_description', 'mod_ratingallocate', ['userid' => $this->userid]); } public function get_url() { - return new \moodle_url('/mod/ratingallocate/index.php', array('id' => $this->courseid)); + return new \moodle_url('/mod/ratingallocate/index.php', ['id' => $this->courseid]); } public static function get_objectid_mapping() { - return array(); + return []; } public static function get_other_mapping() { diff --git a/classes/event/manual_allocation_saved.php b/classes/event/manual_allocation_saved.php index 8e3fa01c..19c18d04 100644 --- a/classes/event/manual_allocation_saved.php +++ b/classes/event/manual_allocation_saved.php @@ -40,7 +40,7 @@ class manual_allocation_saved extends \core\event\base { public static function create_simple($modulecontext, $ratingallocateid) { - return self::create(array('context' => $modulecontext, 'objectid' => $ratingallocateid)); + return self::create(['context' => $modulecontext, 'objectid' => $ratingallocateid]); } protected function init() { @@ -55,15 +55,15 @@ public static function get_name() { public function get_description() { return get_string('log_manual_allocation_saved_description', 'mod_ratingallocate', - array('userid' => $this->userid, 'ratingallocateid' => $this->objectid)); + ['userid' => $this->userid, 'ratingallocateid' => $this->objectid]); } public function get_url() { - return new \moodle_url('/mod/ratingallocate/view.php', array('m' => $this->objectid)); + return new \moodle_url('/mod/ratingallocate/view.php', ['m' => $this->objectid]); } public static function get_objectid_mapping() { - return array('db' => 'ratingallocate', 'restore' => 'ratingallocate'); + return ['db' => 'ratingallocate', 'restore' => 'ratingallocate']; } public static function get_other_mapping() { diff --git a/classes/event/rating_deleted.php b/classes/event/rating_deleted.php index d2cbf8b8..d797096d 100644 --- a/classes/event/rating_deleted.php +++ b/classes/event/rating_deleted.php @@ -33,7 +33,7 @@ class rating_deleted extends \core\event\base { public static function create_simple($modulecontext, $ratingallocateid) { - return self::create(array('context' => $modulecontext, 'objectid' => $ratingallocateid)); + return self::create(['context' => $modulecontext, 'objectid' => $ratingallocateid]); } protected function init() { @@ -48,15 +48,15 @@ public static function get_name() { public function get_description() { return get_string('log_rating_deleted_description', 'mod_ratingallocate', - array('userid' => $this->userid, 'ratingallocateid' => $this->objectid)); + ['userid' => $this->userid, 'ratingallocateid' => $this->objectid]); } public function get_url() { - return new \moodle_url('/mod/ratingallocate/view.php', array('m' => $this->objectid)); + return new \moodle_url('/mod/ratingallocate/view.php', ['m' => $this->objectid]); } public static function get_objectid_mapping() { - return array('db' => 'ratingallocate', 'restore' => 'ratingallocate'); + return ['db' => 'ratingallocate', 'restore' => 'ratingallocate']; } public static function get_other_mapping() { diff --git a/classes/event/rating_saved.php b/classes/event/rating_saved.php index dd64697b..c3850746 100644 --- a/classes/event/rating_saved.php +++ b/classes/event/rating_saved.php @@ -44,8 +44,8 @@ public static function create_simple($modulecontext, $ratingallocateid, $rating) // of a decoded encoded other instance with the original // this is not given for nested arrays. $ratingjsonvalid = json_decode(json_encode($rating), true); - return self::create(array('context' => $modulecontext, 'objectid' => $ratingallocateid, - 'other' => array('ratings' => $ratingjsonvalid))); + return self::create(['context' => $modulecontext, 'objectid' => $ratingallocateid, + 'other' => ['ratings' => $ratingjsonvalid]]); } protected function init() { @@ -60,15 +60,15 @@ public static function get_name() { public function get_description() { return get_string('log_rating_saved_description', 'mod_ratingallocate', - array('userid' => $this->userid, 'ratingallocateid' => $this->objectid)); + ['userid' => $this->userid, 'ratingallocateid' => $this->objectid]); } public function get_url() { - return new \moodle_url('/mod/ratingallocate/view.php', array('m' => $this->objectid)); + return new \moodle_url('/mod/ratingallocate/view.php', ['m' => $this->objectid]); } public static function get_objectid_mapping() { - return array('db' => 'ratingallocate', 'restore' => 'ratingallocate'); + return ['db' => 'ratingallocate', 'restore' => 'ratingallocate']; } public static function get_other_mapping() { diff --git a/classes/event/rating_viewed.php b/classes/event/rating_viewed.php index cc8374b7..3bf74eb7 100644 --- a/classes/event/rating_viewed.php +++ b/classes/event/rating_viewed.php @@ -34,7 +34,7 @@ class rating_viewed extends \core\event\base { public static function create_simple($modulecontext, $ratingallocateid) { - return self::create(array('context' => $modulecontext, 'objectid' => $ratingallocateid)); + return self::create(['context' => $modulecontext, 'objectid' => $ratingallocateid]); } protected function init() { @@ -49,15 +49,15 @@ public static function get_name() { public function get_description() { return get_string('log_rating_viewed_description', 'mod_ratingallocate', - array('userid' => $this->userid, 'ratingallocateid' => $this->objectid)); + ['userid' => $this->userid, 'ratingallocateid' => $this->objectid]); } public function get_url() { - return new \moodle_url('/mod/ratingallocate/view.php', array('m' => $this->objectid)); + return new \moodle_url('/mod/ratingallocate/view.php', ['m' => $this->objectid]); } public static function get_objectid_mapping() { - return array('db' => 'ratingallocate', 'restore' => 'ratingallocate'); + return ['db' => 'ratingallocate', 'restore' => 'ratingallocate']; } public static function get_other_mapping() { diff --git a/classes/event/ratingallocate_viewed.php b/classes/event/ratingallocate_viewed.php index 068af428..7d9b8b27 100644 --- a/classes/event/ratingallocate_viewed.php +++ b/classes/event/ratingallocate_viewed.php @@ -34,7 +34,7 @@ class ratingallocate_viewed extends \core\event\base { public static function create_simple($modulecontext, $ratingallocateid) { - return self::create(array('context' => $modulecontext, 'objectid' => $ratingallocateid)); + return self::create(['context' => $modulecontext, 'objectid' => $ratingallocateid]); } protected function init() { @@ -49,15 +49,15 @@ public static function get_name() { public function get_description() { return get_string('log_ratingallocate_viewed_description', 'mod_ratingallocate', - array('userid' => $this->userid, 'ratingallocateid' => $this->objectid)); + ['userid' => $this->userid, 'ratingallocateid' => $this->objectid]); } public function get_url() { - return new \moodle_url('/mod/ratingallocate/view.php', array('m' => $this->objectid)); + return new \moodle_url('/mod/ratingallocate/view.php', ['m' => $this->objectid]); } public static function get_objectid_mapping() { - return array('db' => 'ratingallocate', 'restore' => 'ratingallocate'); + return ['db' => 'ratingallocate', 'restore' => 'ratingallocate']; } public static function get_other_mapping() { diff --git a/classes/event/ratings_and_allocation_table_viewed.php b/classes/event/ratings_and_allocation_table_viewed.php index 119c6d8c..d163731e 100644 --- a/classes/event/ratings_and_allocation_table_viewed.php +++ b/classes/event/ratings_and_allocation_table_viewed.php @@ -35,7 +35,7 @@ class ratings_and_allocation_table_viewed extends \core\event\base { public static function create_simple($modulecontext, $ratingallocateid) { - return self::create(array('context' => $modulecontext, 'objectid' => $ratingallocateid)); + return self::create(['context' => $modulecontext, 'objectid' => $ratingallocateid]); } protected function init() { @@ -50,15 +50,15 @@ public static function get_name() { public function get_description() { return get_string('log_ratings_and_allocation_table_viewed_description', 'mod_ratingallocate', - array('userid' => $this->userid, 'ratingallocateid' => $this->objectid)); + ['userid' => $this->userid, 'ratingallocateid' => $this->objectid]); } public function get_url() { - return new \moodle_url('/mod/ratingallocate/view.php', array('m' => $this->objectid)); + return new \moodle_url('/mod/ratingallocate/view.php', ['m' => $this->objectid]); } public static function get_objectid_mapping() { - return array('db' => 'ratingallocate', 'restore' => 'ratingallocate'); + return ['db' => 'ratingallocate', 'restore' => 'ratingallocate']; } public static function get_other_mapping() { diff --git a/classes/privacy/provider.php b/classes/privacy/provider.php index a5ffa665..7082691a 100644 --- a/classes/privacy/provider.php +++ b/classes/privacy/provider.php @@ -60,14 +60,14 @@ public static function get_metadata(collection $items): collection { $items->add_database_table('ratingallocate_ratings', [ 'choiceid' => 'privacy:metadata:ratingallocate_ratings:choiceid', 'userid' => 'privacy:metadata:ratingallocate_ratings:userid', - 'rating' => 'privacy:metadata:ratingallocate_ratings:rating' + 'rating' => 'privacy:metadata:ratingallocate_ratings:rating', ], 'privacy:metadata:ratingallocate_ratings'); $items->add_database_table('ratingallocate_allocations', [ 'userid' => 'privacy:metadata:ratingallocate_allocations:userid', 'ratingallocateid' => 'privacy:metadata:ratingallocate_allocations:ratingallocateid', - 'choiceid' => 'privacy:metadata:ratingallocate_allocations:choiceid' + 'choiceid' => 'privacy:metadata:ratingallocate_allocations:choiceid', ], 'privacy:metadata:ratingallocate_allocations'); $items->add_user_preference('flextable_mod_ratingallocate_table_filter', @@ -141,7 +141,7 @@ public static function export_user_data(approved_contextlist $contextlist) { $params = ['modname' => 'ratingallocate', 'contextlevel' => CONTEXT_MODULE, 'userid' => $user->id] + $contextparams; $choiceanswers = $DB->get_recordset_sql($sql, $params); - $choices = array(); + $choices = []; foreach ($choiceanswers as $choiceanswer) { $choicedata = new \stdClass(); $choicedata->choice = $choiceanswer->choice; @@ -155,7 +155,7 @@ public static function export_user_data(approved_contextlist $contextlist) { $choiceanswers->close(); foreach ($choices as $key => $value) { - $area = array('ratings'); + $area = ['ratings']; $context = \context_module::instance($key); // Fetch the generic module data for the choice. @@ -184,7 +184,7 @@ public static function export_user_data(approved_contextlist $contextlist) { $params = ['modname' => 'ratingallocate', 'contextlevel' => CONTEXT_MODULE, 'userid' => $user->id] + $contextparams; $alloc = $DB->get_recordset_sql($sql, $params); - $allocations = array(); + $allocations = []; foreach ($alloc as $allocation) { $allocationdata = new \stdClass(); $allocationdata->choice = $allocation->choice; @@ -197,7 +197,7 @@ public static function export_user_data(approved_contextlist $contextlist) { $alloc->close(); foreach ($allocations as $key => $value) { - $area = array('allocations'); + $area = ['allocations']; $context = \context_module::instance($key); // Fetch the generic module data for the choice. @@ -290,7 +290,7 @@ public static function delete_data_for_user(approved_contextlist $contextlist) { WHERE ratingallocateid = :instanceid) AND userid = :userid", [ 'instanceid' => $instanceid, - 'userid' => $userid + 'userid' => $userid, ] ); } diff --git a/classes/ratingallocate_observer.php b/classes/ratingallocate_observer.php index 48743376..489e8e2b 100644 --- a/classes/ratingallocate_observer.php +++ b/classes/ratingallocate_observer.php @@ -26,6 +26,11 @@ use coding_exception; use dml_exception; +/** + * Ratingallocate observer. + * + * @package mod_ratingallocate + */ class ratingallocate_observer { /** @@ -36,7 +41,7 @@ class ratingallocate_observer { * @throws coding_exception * @throws dml_exception */ - public static function ch_gengroups_delete (\core\event\group_deleted $event) { + public static function ch_gengroups_delete(\core\event\group_deleted $event) { global $DB; $eventdata = $event->get_record_snapshot('groups', $event->objectid); @@ -61,7 +66,7 @@ public static function ch_gengroups_delete (\core\event\group_deleted $event) { * @throws coding_exception * @throws dml_exception */ - public static function ra_groupings_delete (\core\event\grouping_deleted $event) { + public static function ra_groupings_delete(\core\event\grouping_deleted $event) { global $DB; $eventdata = $event->get_record_snapshot('groupings', $event->objectid); diff --git a/classes/ratings_and_allocations_table.php b/classes/ratings_and_allocations_table.php index 48e386b4..585f74a8 100644 --- a/classes/ratings_and_allocations_table.php +++ b/classes/ratings_and_allocations_table.php @@ -15,6 +15,8 @@ // along with Moodle. If not, see . /** + * Ratings and allocations table. + * * @package mod_ratingallocate * @copyright 2016 Janek Lasocki-Biczysko * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later @@ -27,18 +29,35 @@ global $CFG; require_once($CFG->libdir . '/tablelib.php'); +/** + * Ratings and allocations table + * + * @package mod_ratingallocate + */ class ratings_and_allocations_table extends \table_sql { + /** + * Choice column. + */ const CHOICE_COL = 'choice_'; + /** + * Alloc suffix. + */ const EXPORT_CHOICE_ALLOC_SUFFIX = 'alloc'; + /** + * Text suffix. + */ const EXPORT_CHOICE_TEXT_SUFFIX = 'text'; - private $choicenames = array(); - private $choicemax = array(); - private $choicesum = array(); - + /** @var array $choicenames */ + private $choicenames = []; + /** @var array $choicemax */ + private $choicemax = []; + /** @var array $choicesum */ + private $choicesum = []; + /** @var $titles */ private $titles; - + /** @var true $shownames */ private $shownames; /** @@ -71,12 +90,24 @@ class ratings_and_allocations_table extends \table_sql { */ private $renderer; + /** + * Construct. + * + * @param \mod_ratingallocate_renderer $renderer + * @param $titles + * @param $ratingallocate + * @param $action + * @param $uniqueid + * @param $downloadable + * @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) { parent::__construct($uniqueid); global $PAGE; $url = $PAGE->url; - $url->params(array("action" => $action)); + $url->params(["action" => $action]); $PAGE->set_url($url); $this->renderer = $renderer; $this->titles = $titles; @@ -243,27 +274,27 @@ public function build_table_by_sql($ratings, $allocations, $writeable = false) { $users = $this->rawdata; // Group all ratings per user to match table structure. - $ratingsbyuser = array(); + $ratingsbyuser = []; foreach ($ratings as $rating) { if (empty($ratingsbyuser[$rating->userid])) { - $ratingsbyuser[$rating->userid] = array(); + $ratingsbyuser[$rating->userid] = []; } $ratingsbyuser[$rating->userid][$rating->choiceid] = $rating->rating; } // Group all memberships per user per choice. - $allocationsbyuser = array(); + $allocationsbyuser = []; foreach ($allocations as $allocation) { if (empty($allocationsbyuser[$allocation->userid])) { - $allocationsbyuser[$allocation->userid] = array(); + $allocationsbyuser[$allocation->userid] = []; } $allocationsbyuser[$allocation->userid][$allocation->choiceid] = true; } // Add rating rows for each user. foreach ($users as $user) { - $userratings = isset($ratingsbyuser[$user->id]) ? $ratingsbyuser[$user->id] : array(); - $userallocations = isset($allocationsbyuser[$user->id]) ? $allocationsbyuser[$user->id] : array(); + $userratings = isset($ratingsbyuser[$user->id]) ? $ratingsbyuser[$user->id] : []; + $userallocations = isset($allocationsbyuser[$user->id]) ? $allocationsbyuser[$user->id] : []; $this->add_user_ratings_row($user, $userratings, $userallocations); } @@ -330,10 +361,10 @@ private function add_user_ratings_row($user, $userratings, $userallocations) { } foreach ($userratings as $choiceid => $userrating) { - $row[self::CHOICE_COL . $choiceid] = array( + $row[self::CHOICE_COL . $choiceid] = [ 'rating' => $userrating, - 'hasallocation' => false // May be overridden later. - ); + 'hasallocation' => false, // May be overridden later. + ]; } // Process allocations separately, since assignment can exist for choices that have not been rated. @@ -347,10 +378,10 @@ private function add_user_ratings_row($user, $userratings, $userallocations) { $rowkey = self::CHOICE_COL . $choiceid; if (!isset($row[$rowkey])) { // User has not rated this choice, but it was assigned to him/her. - $row[$rowkey] = array( + $row[$rowkey] = [ 'rating' => null, - 'hasallocation' => true - ); + 'hasallocation' => true, + ]; } else { // User has rated this choice. $row[$rowkey]['hasallocation'] = true; @@ -365,7 +396,7 @@ private function add_user_ratings_row($user, $userratings, $userallocations) { */ private function add_summary_row() { - $row = array(); + $row = []; if ($this->shownames) { $row[] = get_string('ratings_table_sum_allocations', RATINGALLOCATE_MOD_NAME); @@ -380,7 +411,7 @@ private function add_summary_row() { $row[] = get_string( 'ratings_table_sum_allocations_value', RATINGALLOCATE_MOD_NAME, - array('sum' => $sum, 'max' => $this->choicemax[$choiceid]) + ['sum' => $sum, 'max' => $this->choicemax[$choiceid]] ); } } @@ -405,7 +436,7 @@ public function other_cols($column, $row) { $suffix = ''; // Suffixes for additional columns have to be removed. if ($this->is_downloading()) { - foreach (array('text', 'alloc') as $key) { + foreach (['text', 'alloc'] as $key) { if (strpos($column, $key)) { $suffix = $key; $column = str_replace($key, '', $column); @@ -474,12 +505,12 @@ private function render_cell($userid, $choiceid, $text, $checked, $class = '') { if ($this->writeable) { $result = \html_writer::start_span(); $result .= \html_writer::tag('input', '', - array('class' => 'ratingallocate_checkbox_label', + ['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 @@ -500,11 +531,11 @@ private function print_hidden_user_fields($users) { echo \html_writer::start_span(); foreach ($users as $user) { echo \html_writer::tag('input', '', - array( + [ 'name' => 'userdata[' . $user->id . ']', 'value' => $user->id, 'type' => 'hidden', - )); + ]); } echo \html_writer::end_span(); } @@ -529,11 +560,11 @@ private function setup_filter($hidenorating = null, $showallocnecessary = null, $filter = $settings ? json_decode($settings, true) : null; if (!$filter) { - $filter = array( + $filter = [ 'hidenorating' => $this->hidenorating, 'showallocnecessary' => $this->showallocnecessary, - 'groupselect' => $this->groupselect - ); + 'groupselect' => $this->groupselect, + ]; } if (!is_null($hidenorating)) { $filter['hidenorating'] = $hidenorating; @@ -555,11 +586,11 @@ private function setup_filter($hidenorating = null, $showallocnecessary = null, * @return array with keys hidenorating and showallocnecessary */ public function get_filter() { - $filter = array( + $filter = [ 'hidenorating' => $this->hidenorating, 'showallocnecessary' => $this->showallocnecessary, - 'groupselect' => $this->groupselect - ); + 'groupselect' => $this->groupselect, + ]; return $filter; } @@ -614,15 +645,22 @@ function($u) { return $u->id; }, $DB->get_records_sql($sql, - array( + [ 'ratingallocateid' => $this->ratingallocate->ratingallocate->id, 'ratingallocateid2' => $this->ratingallocate->ratingallocate->id, - 'groupselect' => $this->groupselect - ) + 'groupselect' => $this->groupselect, + ] ) ); } + /** + * Filter choiceids. + * + * @param $choiceids + * @return array + * @throws \dml_exception + */ private function filter_choiceids($choiceids) { global $DB; if (!$choiceids) { @@ -653,10 +691,10 @@ function($c) { return $c->id; }, $DB->get_records_sql($sql, - array( + [ 'ratingallocateid' => $this->ratingallocate->ratingallocate->id, - 'groupselect' => $this->groupselect - ) + 'groupselect' => $this->groupselect, + ] ) ); @@ -682,7 +720,7 @@ public function init_sql() { $from = "{user} u"; - $params = array(); + $params = []; for ($i = 0; $i < count($sortfields); $i++) { $key = array_keys($sortfields)[$i]; if (substr($key, 0, 6) == "choice") { diff --git a/classes/task/cron_task.php b/classes/task/cron_task.php index aca7c3a1..f31a857b 100644 --- a/classes/task/cron_task.php +++ b/classes/task/cron_task.php @@ -58,7 +58,7 @@ public function execute() { $cm = get_coursemodule_from_instance(this_db\ratingallocate::TABLE, $record->{this_db\ratingallocate::ID}); // Fetch the data for the course, if is has changed. if (!$course || $course->id != $record->{this_db\ratingallocate::COURSE}) { - $course = $DB->get_record('course', array('id' => $record->{this_db\ratingallocate::COURSE}), '*', MUST_EXIST); + $course = $DB->get_record('course', ['id' => $record->{this_db\ratingallocate::COURSE}], '*', MUST_EXIST); } // Create ratingallocate instance from record. $ratingallocate = new \ratingallocate($record, $course, $cm, \context_module::instance($cm->id)); diff --git a/classes/task/send_distribution_notification.php b/classes/task/send_distribution_notification.php index 2a70360b..5f1b8301 100644 --- a/classes/task/send_distribution_notification.php +++ b/classes/task/send_distribution_notification.php @@ -15,6 +15,8 @@ // along with Moodle. If not, see . /** + * Send distibution notification. + * * @package mod_ratingallocate * @copyright 2014 M Schulze * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later @@ -28,6 +30,11 @@ use mod_ratingallocate\db as this_db; +/** + * Send distribution notification + * + * @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. @@ -43,7 +50,7 @@ public function execute() { // Get instance of ratingallocate. $ratingallocate = - $DB->get_record(this_db\ratingallocate::TABLE, array(this_db\ratingallocate::ID => $ratingallocateid), '*', + $DB->get_record(this_db\ratingallocate::TABLE, [this_db\ratingallocate::ID => $ratingallocateid], '*', MUST_EXIST); $courseid = $ratingallocate->course; diff --git a/db/access.php b/db/access.php index f54f6af9..956b4b58 100644 --- a/db/access.php +++ b/db/access.php @@ -45,72 +45,72 @@ */ defined('MOODLE_INTERNAL') || die(); -$capabilities = array( +$capabilities = [ - 'mod/ratingallocate:addinstance' => array( + 'mod/ratingallocate:addinstance' => [ 'riskbitmask' => RISK_XSS | RISK_PERSONAL, 'contextlevel' => CONTEXT_COURSE, 'captype' => 'write', - 'archetypes' => array( + 'archetypes' => [ 'editingteacher' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ), - 'clonepermissionsfrom' => 'moodle/course:manageactivities' - ), - 'mod/ratingallocate:view' => array( + 'manager' => CAP_ALLOW, + ], + 'clonepermissionsfrom' => 'moodle/course:manageactivities', + ], + 'mod/ratingallocate:view' => [ 'captype' => 'read', 'contextlevel' => CONTEXT_MODULE, - 'legacy' => array( + 'legacy' => [ 'guest' => CAP_ALLOW, 'student' => CAP_ALLOW, 'teacher' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ) - ), - 'mod/ratingallocate:give_rating' => array( + 'manager' => CAP_ALLOW, + ], + ], + 'mod/ratingallocate:give_rating' => [ 'contextlevel' => CONTEXT_MODULE, 'captype' => 'write', - 'archetypes' => array( - 'student' => CAP_ALLOW - ) - ), - 'mod/ratingallocate:start_distribution' => array( + 'archetypes' => [ + 'student' => CAP_ALLOW, + ], + ], + 'mod/ratingallocate:start_distribution' => [ 'contextlevel' => CONTEXT_MODULE, 'riskbitmask' => RISK_PERSONAL, 'captype' => 'write', - 'archetypes' => array( + 'archetypes' => [ 'editingteacher' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ) - ), - 'mod/ratingallocate:modify_choices' => array( + 'manager' => CAP_ALLOW, + ], + ], + 'mod/ratingallocate:modify_choices' => [ 'contextlevel' => CONTEXT_MODULE, 'captype' => 'write', - 'archetypes' => array( + 'archetypes' => [ 'editingteacher' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ) - ), - 'mod/ratingallocate:export_ratings' => array( + 'manager' => CAP_ALLOW, + ], + ], + 'mod/ratingallocate:export_ratings' => [ 'contextlevel' => CONTEXT_MODULE, 'riskbitmask' => RISK_PERSONAL, 'captype' => 'read', - 'archetypes' => array( + 'archetypes' => [ 'editingteacher' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ) - ), - 'mod/ratingallocate:distribute_unallocated' => array( + 'manager' => CAP_ALLOW, + ], + ], + 'mod/ratingallocate:distribute_unallocated' => [ 'contextlevel' => CONTEXT_MODULE, 'riskbitmask' => RISK_PERSONAL, 'captype' => 'write', - 'archetypes' => array( + 'archetypes' => [ 'editingteacher' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ) - ), -); + 'manager' => CAP_ALLOW, + ], + ], +]; diff --git a/db/db_structure.php b/db/db_structure.php index 2c3959a7..ce9c5a64 100644 --- a/db/db_structure.php +++ b/db/db_structure.php @@ -26,71 +26,251 @@ namespace mod_ratingallocate\db; defined('MOODLE_INTERNAL') || die(); + +/** + * Ratingallocate. + * + * @package mod_ratingallocate + */ class ratingallocate { + /** + * The ratingallocate table. + */ const TABLE = 'ratingallocate'; + /** + * Ratingallocateid. + */ const ID = 'id'; + /** + * The course. + */ const COURSE = 'course'; + /** + * Name of the instance. + */ const NAME = 'name'; + /** + * Intro. + */ const INTRO = 'intro'; + /** + * The introformat. + */ const INTROFORMAT = 'introformat'; + /** + * When the instance was created. + */ const TIMECREATED = 'timecreated'; + /** + * Time it was modified. + */ const TIMEMODIFIED = 'timemodified'; + /** + * Beginning voting. + */ const ACCESSTIMESTART = 'accesstimestart'; + /** + * End of voting. + */ const ACCESSTIMESTOP = 'accesstimestop'; + /** + * Setting. + */ const SETTING = 'setting'; + /** + * The strategy used. + */ const STRATEGY = 'strategy'; + /** + * Date to publish allocation. + */ const PUBLISHDATE = 'publishdate'; + /** + * Wether its published. + */ const PUBLISHED = 'published'; + /** + * Send notification to users. + */ const NOTIFICATIONSEND = 'notificationsend'; + /** + * Strat time of algorithm. + */ const ALGORITHMSTARTTIME = 'algorithmstarttime'; + /** + * Wether algorithm is run by cron task. + */ const RUNALGORITHMBYCRON = 'runalgorithmbycron'; + /** + * Status of the most recent algorithm run. + */ const ALGORITHMSTATUS = 'algorithmstatus'; } +/** + * Ratingallocate choices. + * + * @package mod_ratingallocate + */ class ratingallocate_choices { + /** + * Table. + */ const TABLE = 'ratingallocate_choices'; + /** + * ID. + */ const ID = 'id'; + /** + * Ratingallocateid. + */ const RATINGALLOCATEID = 'ratingallocateid'; + /** + * Title of choice. + */ const TITLE = 'title'; + /** + * Explanation. + */ const EXPLANATION = 'explanation'; + /** + * Max number of users. + */ const MAXSIZE = 'maxsize'; + /** + * If its active. + */ const ACTIVE = 'active'; + /** + * Restrict visibility by groups. + */ const USEGROUPS = 'usegroups'; } + +/** + * Ratingallocate group choices. + * + * @package mod_ratingallocate + */ class ratingallocate_group_choices { + /** + * Table. + */ const TABLE = 'ratingallocate_group_choices'; + /** + * Id. + */ const ID = 'id'; + /** + * Choiceid. + */ const CHOICEID = 'choiceid'; + /** + * Groupid. + */ const GROUPID = 'groupid'; } - +/** + * Ratingallocate generated groups of choices + * + * @package mod_ratingallocate + */ class ratingallocate_ch_gengroups { + /** + * Table. + */ const TABLE = 'ratingallocate_ch_gengroups'; + /** + * Id. + */ const ID = 'id'; + /** + * Groupid. + */ const GROUPID = 'groupid'; + /** + * Choiceid. + */ const CHOICEID = 'choiceid'; } +/** + * Ratingallocate groupings + * + * @package mod_ratingallocate + */ class ratingallocate_groupings { + /** + * Table. + */ const TABLE = 'ratingallocate_groupings'; + /** + * Id. + */ const ID = 'id'; + /** + * Ratingallocateid. + */ const RATINGALLOCATEID = 'ratingallocateid'; + /** + * Groupingid. + */ const GROUPINGID = 'groupingid'; } +/** + * Ratingallocate ratings + * + * @package mod_ratingallocate + */ class ratingallocate_ratings { + /** + * Table. + */ const TABLE = 'ratingallocate_ratings'; + /** + * Id. + */ const ID = 'id'; + /** + * The choiceid. + */ const CHOICEID = 'choiceid'; + /** + * The userid. + */ const USERID = 'userid'; + /** + * How the user rated the choice. + */ const RATING = 'rating'; } +/** + * Ratingallocate allocations. + * + * @package mod_ratingallocate + */ class ratingallocate_allocations { + /** + * Table. + */ const TABLE = 'ratingallocate_allocations'; + /** + * Id. + */ const ID = 'id'; + /** + * Userid. + */ const USERID = 'userid'; + /** + * Id of ratingallocate instance. + */ const RATINGALLOCATEID = 'ratingallocateid'; + /** + * Choiceid. + */ const CHOICEID = 'choiceid'; } diff --git a/db/events.php b/db/events.php index f73121e2..134b9a65 100644 --- a/db/events.php +++ b/db/events.php @@ -29,17 +29,17 @@ defined('MOODLE_INTERNAL') || die(); -$handlers = array(); +$handlers = []; // List of observers for group_deleted and grouping_deleted. -$observers = array( - array( +$observers = [ + [ 'eventname' => '\core\event\group_deleted', 'callback' => 'mod_ratingallocate\ratingallocate_observer::ch_gengroups_delete', - ), - array( + ], + [ 'eventname' => '\core\event\grouping_deleted', - 'callback' => 'mod_ratingallocate\ratingallocate_observer::ra_groupings_delete' - ) -); + 'callback' => 'mod_ratingallocate\ratingallocate_observer::ra_groupings_delete', + ], +]; diff --git a/db/log.php b/db/log.php index f0a4d461..dfcfb84e 100644 --- a/db/log.php +++ b/db/log.php @@ -29,9 +29,9 @@ global $DB; -$logs = array( - array('module' => 'ratingallocate', 'action' => 'add', 'mtable' => 'ratingallocate', 'field' => 'name'), - array('module' => 'ratingallocate', 'action' => 'update', 'mtable' => 'ratingallocate', 'field' => 'name'), - array('module' => 'ratingallocate', 'action' => 'view', 'mtable' => 'ratingallocate', 'field' => 'name'), - array('module' => 'ratingallocate', 'action' => 'view all', 'mtable' => 'ratingallocate', 'field' => 'name') -); +$logs = [ + ['module' => 'ratingallocate', 'action' => 'add', 'mtable' => 'ratingallocate', 'field' => 'name'], + ['module' => 'ratingallocate', 'action' => 'update', 'mtable' => 'ratingallocate', 'field' => 'name'], + ['module' => 'ratingallocate', 'action' => 'view', 'mtable' => 'ratingallocate', 'field' => 'name'], + ['module' => 'ratingallocate', 'action' => 'view all', 'mtable' => 'ratingallocate', 'field' => 'name'], +]; diff --git a/db/messages.php b/db/messages.php index af7d23e8..da7af966 100644 --- a/db/messages.php +++ b/db/messages.php @@ -25,9 +25,9 @@ defined('MOODLE_INTERNAL') || die(); -$messageproviders = array( +$messageproviders = [ // Notify student about published allocation. - 'allocation' => array( - 'capability' => 'mod/ratingallocate:give_rating' - ) -); + 'allocation' => [ + 'capability' => 'mod/ratingallocate:give_rating', + ], +]; diff --git a/db/tasks.php b/db/tasks.php index 5e56d4a1..8cc5a50f 100644 --- a/db/tasks.php +++ b/db/tasks.php @@ -25,8 +25,8 @@ defined('MOODLE_INTERNAL') || die(); -$tasks = array( - array( +$tasks = [ + [ 'classname' => 'mod_ratingallocate\task\cron_task', 'blocking' => 0, 'minute' => '*', @@ -35,5 +35,5 @@ 'month' => '*', 'dayofweek' => '*', 'faildelay' => 1, - ) -); + ], +]; diff --git a/db/uninstall.php b/db/uninstall.php index fcf07ba7..d9bdf5e4 100644 --- a/db/uninstall.php +++ b/db/uninstall.php @@ -15,6 +15,8 @@ // along with Moodle. If not, see . /** + * Db uninstall. + * * @see uninstall_plugin() * * @package mod_ratingallocate @@ -23,7 +25,9 @@ */ /** - * Custom uninstallation procedure + * Uninstall. + * + * @package mod_ratingallocate */ function xmldb_ratingallocate_uninstall() { return true; diff --git a/db/upgrade.php b/db/upgrade.php index e111a143..c6885680 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -42,7 +42,7 @@ function xmldb_ratingallocate_upgrade($oldversion) { if ($oldversion < 2014103000) { try { $transaction = $DB->start_delegated_transaction(); - $results = $DB->get_records('ratingallocate', array('publishdate_show' => 0)); + $results = $DB->get_records('ratingallocate', ['publishdate_show' => 0]); foreach ($results as $singleresult) { $singleresult->publishdate = 0; @@ -114,7 +114,7 @@ function xmldb_ratingallocate_upgrade($oldversion) { // Set status to notstarted if the instance has no allocations; otherwise to finished. foreach ($results as $singleresult) { - $allocations = $DB->get_records('ratingallocate_allocations', array('ratingallocateid' => $singleresult->id)); + $allocations = $DB->get_records('ratingallocate_allocations', ['ratingallocateid' => $singleresult->id]); $singleresult->algorithmstatus = (count($allocations) === 0 ? \mod_ratingallocate\algorithm_status::NOTSTARTED : \mod_ratingallocate\algorithm_status::FINISHED); $DB->update_record('ratingallocate', $singleresult); diff --git a/form_manual_allocation.php b/form_manual_allocation.php index 62356a13..2d854b7b 100644 --- a/form_manual_allocation.php +++ b/form_manual_allocation.php @@ -37,7 +37,13 @@ class manual_alloc_form extends moodleform { /** @var $ratingallocate ratingallocate */ private $ratingallocate; + /** + * Constant for the action + */ const FORM_ACTION = 'action'; + /** + * Assign. + */ const ASSIGN = 'assign'; /** @@ -47,7 +53,7 @@ class manual_alloc_form extends moodleform { */ public function __construct($url, ratingallocate $ratingallocate) { $this->ratingallocate = $ratingallocate; - $url->params(array("action" => "manual_allocation")); + $url->params(["action" => "manual_allocation"]); parent::__construct($url->out(false)); $this->definition_after_data(); } @@ -72,23 +78,30 @@ public function definition() { $this->render_filter(); } + /** + * Render filter. + * + * @return void + * @throws coding_exception + * @throws dml_exception + */ 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, array(0, 1)); + 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, array(0, 1)); + null, [0, 1]); $mform->setType('show_alloc_necessary', PARAM_BOOL); // Filter by group. $choicegroups = $this->ratingallocate->get_all_groups_of_choices(); - $allgroups = array(); + $allgroups = []; foreach ($choicegroups as $choicegroup) { $allgroups[$choicegroup] = groups_get_group($choicegroup); } @@ -114,7 +127,7 @@ public function definition_after_data() { $mform = &$this->_form; $ratingdata = $this->ratingallocate->get_ratings_for_rateable_choices(); - $differentratings = array(); + $differentratings = []; // Add actual rating data to userdata. foreach ($ratingdata as $rating) { if ($rating->rating != null) { @@ -177,13 +190,13 @@ public function add_special_action_buttons() { $mform = $this->_form; // Elements in a row need a group. - $buttonarray = array(); + $buttonarray = []; $buttonarray[] = &$mform->createElement('submit', 'submitbutton2', $submit2label); $buttonarray[] = &$mform->createElement('submit', 'submitbutton', $submitlabel); $buttonarray[] = &$mform->createElement('cancel'); - $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false); + $mform->addGroup($buttonarray, 'buttonar', '', [' '], false); $mform->setType('buttonar', PARAM_RAW); $mform->closeHeaderBefore('buttonar'); } diff --git a/form_modify_choice.php b/form_modify_choice.php index 7fbdaf40..e09ea742 100644 --- a/form_modify_choice.php +++ b/form_modify_choice.php @@ -36,8 +36,11 @@ class modify_choice_form extends moodleform { /** @var $choice ratingallocate_choice */ private $choice; + /** The form action. */ const FORM_ACTION = 'action'; + /** @var $msgerrorrequired */ private $msgerrorrequired; + /** @var bool $addnew */ private $addnew = false; /** @@ -53,10 +56,10 @@ public function __construct($url, ratingallocate $ratingallocate, if ($choice) { $this->choice = $choice; // Special handling for HTML editor. - $this->choice->explanation = array( + $this->choice->explanation = [ 'text' => $this->choice->explanation, 'format' => FORMAT_HTML, - ); + ]; } else { $this->addnew = true; } @@ -82,9 +85,9 @@ public function definition() { 'maxlength', '255'); $elementname = 'explanation'; - $editoroptions = array( + $editoroptions = [ 'enable_filemanagement' => false, - ); + ]; $mform->addElement('editor', $elementname, get_string('choice_explanation', RATINGALLOCATE_MOD_NAME), $editoroptions); $mform->setType($elementname, PARAM_RAW); @@ -96,20 +99,20 @@ public function definition() { $mform->addRule($elementname, get_string('err_positivnumber', 'ratingallocate'), 'regex', '/^[1-9][0-9]*|0/', 'server'); $elementname = 'attachments_filemanager'; - $mform->addElement('filemanager', $elementname, get_string('uploadafile'), null, array( + $mform->addElement('filemanager', $elementname, get_string('uploadafile'), null, [ 'accepted_types' => '*', 'subdirs' => false, - )); + ]); $this->set_data($this->_customdata['attachment_data']); $elementname = 'active'; $mform->addElement('advcheckbox', $elementname, get_string('choice_active', RATINGALLOCATE_MOD_NAME), - null, null, array(0, 1)); + 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, array(0, 1)); + null, null, [0, 1]); $mform->addHelpButton($elementname, 'choice_usegroups', RATINGALLOCATE_MOD_NAME); $elementname = 'groupselector'; @@ -136,17 +139,23 @@ public function definition() { $this->add_buttons(); } + /** + * Add buttons to form. + * + * @return void + * @throws coding_exception + */ public function add_buttons() { $mform =& $this->_form; - $buttonarray = array(); + $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('cancel'); - $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false); + $mform->addGroup($buttonarray, 'buttonar', '', [' '], false); $mform->closeHeaderBefore('buttonar'); } diff --git a/form_upload_choices.php b/form_upload_choices.php index b2be5d9a..0a4a7511 100644 --- a/form_upload_choices.php +++ b/form_upload_choices.php @@ -64,7 +64,7 @@ public function definition() { $elementname = 'testimport'; $mform->addElement('advcheckbox', $elementname, get_string('csvupload_test_upload', 'ratingallocate'), - null, null, array(0, 1)); + null, null, [0, 1]); $mform->addHelpButton($elementname, 'csvupload_test_upload', 'ratingallocate'); $this->add_buttons(); @@ -73,10 +73,10 @@ public function definition() { public function add_buttons() { $mform =& $this->_form; - $buttonarray = array(); + $buttonarray = []; $buttonarray[] = &$mform->createElement('submit', 'submitbutton', get_string('csvupload', 'ratingallocate')); $buttonarray[] = &$mform->createElement('cancel'); - $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false); + $mform->addGroup($buttonarray, 'buttonar', '', [' '], false); $mform->closeHeaderBefore('buttonar'); } diff --git a/index.php b/index.php index ae25d428..9fbe71ee 100644 --- a/index.php +++ b/index.php @@ -39,7 +39,7 @@ $coursecontext = context_course::instance($course->id); $PAGE->set_pagelayout('incourse'); -$PAGE->set_url('/mod/ratingallocate/index.php', array('id' => $id)); +$PAGE->set_url('/mod/ratingallocate/index.php', ['id' => $id]); $PAGE->set_title(format_string($course->fullname)); $PAGE->set_heading(format_string($course->fullname)); $PAGE->set_context($coursecontext); @@ -55,32 +55,32 @@ if (!$ratingallocates = get_all_instances_in_course('ratingallocate', $course, $USER->id)) { notice(get_string('noratingallocates', RATINGALLOCATE_MOD_NAME), - new moodle_url('/course/view.php', array('id' => $course->id))); + new moodle_url('/course/view.php', ['id' => $course->id])); } $table = new html_table(); -$table->head = array( +$table->head = [ get_string('name'), get_string('rating_begintime', 'mod_ratingallocate'), get_string('rating_endtime', 'mod_ratingallocate'), - get_string('is_published', 'mod_ratingallocate')); -$table->align = array('left', 'left', 'left', 'left'); + get_string('is_published', 'mod_ratingallocate')]; +$table->align = ['left', 'left', 'left', 'left']; foreach ($ratingallocates as $ratingallocate) { - $ratingallocateinstance = $DB->get_record('ratingallocate', array('id' => $ratingallocate->id)); + $ratingallocateinstance = $DB->get_record('ratingallocate', ['id' => $ratingallocate->id]); if (!$ratingallocate->visible) { $link = html_writer::link( - new moodle_url('/mod/ratingallocate/view.php', array('id' => $ratingallocate->coursemodule)), + new moodle_url('/mod/ratingallocate/view.php', ['id' => $ratingallocate->coursemodule]), format_string($ratingallocate->name, true), - array('class' => 'dimmed')); + ['class' => 'dimmed']); } else { $link = html_writer::link( - new moodle_url('/mod/ratingallocate/view.php', array('id' => $ratingallocate->coursemodule)), + new moodle_url('/mod/ratingallocate/view.php', ['id' => $ratingallocate->coursemodule]), format_string($ratingallocate->name, true)); } - $table->data[] = array($link, userdate($ratingallocateinstance->accesstimestart), + $table->data[] = [$link, userdate($ratingallocateinstance->accesstimestart), userdate($ratingallocateinstance->accesstimestop), - $ratingallocateinstance->published == 0 ? get_string('no') : get_string('yes')); + $ratingallocateinstance->published == 0 ? get_string('no') : get_string('yes')]; } diff --git a/lib.php b/lib.php index 57d77ec5..283006d8 100644 --- a/lib.php +++ b/lib.php @@ -160,20 +160,20 @@ function ratingallocate_update_instance(stdClass $ratingallocate, mod_ratingallo function ratingallocate_delete_instance($id) { global $DB; - if (!$ratingallocate = $DB->get_record('ratingallocate', array( - 'id' => $id - ))) { + if (!$ratingallocate = $DB->get_record('ratingallocate', [ + 'id' => $id, + ])) { return false; } // Delete any dependent records here # . - $DB->delete_records('ratingallocate_allocations', array( - 'ratingallocateid' => $ratingallocate->id - )); + $DB->delete_records('ratingallocate_allocations', [ + 'ratingallocateid' => $ratingallocate->id, + ]); - $deleteids = array_keys($DB->get_records('ratingallocate_choices', array( - 'ratingallocateid' => $ratingallocate->id - ), '', 'id')); + $deleteids = array_keys($DB->get_records('ratingallocate_choices', [ + 'ratingallocateid' => $ratingallocate->id, + ], '', 'id')); if (!empty($deleteids)) { list ($insql, $params) = $DB->get_in_or_equal($deleteids); @@ -183,22 +183,22 @@ function ratingallocate_delete_instance($id) { 'choiceid ' . $insql, $params); } - $DB->delete_records('ratingallocate_groupings', array( - 'ratingallocateid' => $ratingallocate->id - )); + $DB->delete_records('ratingallocate_groupings', [ + 'ratingallocateid' => $ratingallocate->id, + ]); $DB->delete_records_list('ratingallocate_ratings', 'choiceid', $deleteids); - $DB->delete_records('ratingallocate_choices', array( - 'ratingallocateid' => $ratingallocate->id - )); + $DB->delete_records('ratingallocate_choices', [ + 'ratingallocateid' => $ratingallocate->id, + ]); // Delete associated events. - $DB->delete_records('event', array('modulename' => 'ratingallocate', 'instance' => $ratingallocate->id)); + $DB->delete_records('event', ['modulename' => 'ratingallocate', 'instance' => $ratingallocate->id]); - $DB->delete_records('ratingallocate', array( - 'id' => $ratingallocate->id - )); + $DB->delete_records('ratingallocate', [ + 'id' => $ratingallocate->id, + ]); return true; } @@ -250,7 +250,7 @@ function ratingallocate_print_recent_mod_activity($activity, $courseid, $detail, * @return array */ function ratingallocate_get_extra_capabilities() { - return array(); + return[]; } // ////////////////////////////////////////////////////////////////////////////// @@ -269,7 +269,7 @@ function ratingallocate_get_extra_capabilities() { * @return array of [(string)filearea] => (string)description */ function ratingallocate_get_file_areas($course, $cm, $context) { - return array(); + return[]; } /** @@ -314,7 +314,7 @@ function ratingallocate_get_file_info($browser, $areas, $course, $cm, $context, * * @package mod_ratingallocate */ -function ratingallocate_pluginfile($course, $cm, $context, $filearea, array $args, $forcedownload, array $options = array()) { +function ratingallocate_pluginfile($course, $cm, $context, $filearea, array $args, $forcedownload, array $options = []) { global $DB, $CFG; if ($context->contextlevel != CONTEXT_MODULE) { @@ -423,14 +423,14 @@ function ratingallocate_refresh_events($courseid = 0, $instance = null, $cm = nu // If we have instance information then we can just update the one event instead of updating all events. if (isset($instance)) { if (!is_object($instance)) { - $instance = $DB->get_record('ratingallocate', array('id' => $instance), '*', MUST_EXIST); + $instance = $DB->get_record('ratingallocate', ['id' => $instance], '*', MUST_EXIST); } ratingallocate_set_events($instance); return true; } if ($courseid) { - if (! $ratingallocates = $DB->get_records('ratingallocate', array('course' => $courseid))) { + if (! $ratingallocates = $DB->get_records('ratingallocate', ['course' => $courseid])) { return true; } } else { @@ -469,9 +469,9 @@ function ratingallocate_set_events($ratingallocate) { // Ratingallocate-accessstart calendar events. $eventid = $DB->get_field('event', 'id', - array('modulename' => 'ratingallocate', 'instance' => $ratingallocate->id, 'eventtype' => RATINGALLOCATE_EVENT_TYPE_START)); + ['modulename' => 'ratingallocate', 'instance' => $ratingallocate->id, 'eventtype' => RATINGALLOCATE_EVENT_TYPE_START]); - $timestart = $DB->get_field('ratingallocate', 'accesstimestart', array('id' => $ratingallocate->id)); + $timestart = $DB->get_field('ratingallocate', 'accesstimestart', ['id' => $ratingallocate->id]); if (isset($timestart) && $timestart > 0) { $event = new stdClass(); @@ -513,9 +513,9 @@ function ratingallocate_set_events($ratingallocate) { // Ratingallocate-accessstop calendar events. $eventid = $DB->get_field('event', 'id', - array('modulename' => 'ratingallocate', 'instance' => $ratingallocate->id, 'eventtype' => RATINGALLOCATE_EVENT_TYPE_STOP)); + ['modulename' => 'ratingallocate', 'instance' => $ratingallocate->id, 'eventtype' => RATINGALLOCATE_EVENT_TYPE_STOP]); - $timestop = $DB->get_field('ratingallocate', 'accesstimestop', array('id' => $ratingallocate->id)); + $timestop = $DB->get_field('ratingallocate', 'accesstimestop', ['id' => $ratingallocate->id]); if (isset($timestop) && $timestop > 0) { $event = new stdClass(); @@ -587,7 +587,6 @@ function mod_ratingallocate_core_is_event_visible(calendar_event $event): bool { /** * This function will update the ratingallocate module according to the event that has been modified. * - * @params calendar_event, stdClass * @throws coding_exception * @throws dml_exception * @throws moodle_exception @@ -698,7 +697,7 @@ function ratingallocate_reset_userdata($data) { $componentstr = get_string('modulenameplural', RATINGALLOCATE_MOD_NAME); $status = []; - $params = array('courseid' => $data->courseid); + $params = ['courseid' => $data->courseid]; if (!empty($data->reset_ratings_and_allocations)) { @@ -725,8 +724,9 @@ function ratingallocate_reset_userdata($data) { if ($data->timeshift) { // Any changes to the list of dates that needs to be rolled should be same during course restore and course reset. // See MDL-9367. - shift_course_mod_dates(RATINGALLOCATE_MOD_NAME, array('accesstimestart', 'accesstimestop'), $data->timeshift, $data->courseid); - $status[] = array('component' => $componentstr, 'item' => get_string('datechanged'), 'error' => false); + shift_course_mod_dates(RATINGALLOCATE_MOD_NAME, ['accesstimestart', 'accesstimestop'], $data->timeshift, $data->courseid); + $status[] = ['component' => $componentstr, 'item' => get_string('datechanged'), 'error' + => false]; } return $status; @@ -767,7 +767,7 @@ function ratingallocate_reset_course_form_defaults($course) { function ratingallocate_get_coursemodule_info($coursemodule) { global $DB; - $dbparams = array('id' => $coursemodule->instance); + $dbparams = ['id' => $coursemodule->instance]; if (! $ratingallocate = $DB->get_record('ratingallocate', $dbparams)) { return false; } diff --git a/locallib.php b/locallib.php index f9074831..4884889e 100644 --- a/locallib.php +++ b/locallib.php @@ -60,7 +60,7 @@ class strategymanager { /** @var array of string-identifier of all registered strategies */ - private static $strategies = array(); + private static $strategies = []; /** * Add a strategy to the strategymanager @@ -135,6 +135,11 @@ public function __get($name) { return $this->dbrecord->{$name}; } + /** + * Construct. + * + * @param $record + */ public function __construct($record) { $this->dbrecord = $record; } @@ -175,7 +180,9 @@ class ratingallocate { */ protected $renderer; + /** @var string notify success */ const NOTIFY_SUCCESS = 'notifysuccess'; + /** @var string notify message */ const NOTIFY_MESSAGE = 'notifymessage'; /** @@ -203,7 +210,7 @@ public function get_raters_in_course(): array { * @return array A mapping of group IDs to names. */ public function get_group_candidates() { - $options = array(); + $options = []; $groupcandidates = groups_get_all_groups($this->course->id); foreach ($groupcandidates as $group) { $options[$group->id] = $group->name; @@ -211,6 +218,14 @@ public function get_group_candidates() { return $options; } + /** + * Construct. + * + * @param $ratingallocaterecord + * @param $course + * @param $coursem + * @param context_module $context + */ public function __construct($ratingallocaterecord, $course, $coursem, context_module $context) { global $DB; $this->db = &$DB; @@ -224,6 +239,8 @@ public function __construct($ratingallocaterecord, $course, $coursem, context_mo } /** + * Start distribution. + * * @return string * @throws coding_exception */ @@ -235,7 +252,7 @@ private function process_action_start_distribution() { if ($this->get_algorithm_status() === \mod_ratingallocate\algorithm_status::RUNNING) { // Don't run, if an instance is already running. redirect(new moodle_url('/mod/ratingallocate/view.php', - array('id' => $this->coursemodule->id)), + ['id' => $this->coursemodule->id]), get_string('algorithm_already_running', RATINGALLOCATE_MOD_NAME), null, \core\output\notification::NOTIFY_INFO); @@ -244,7 +261,7 @@ private function process_action_start_distribution() { ) { // Don't run, if the cron has not started yet, but is set as priority. redirect(new moodle_url('/mod/ratingallocate/view.php', - array('id' => $this->coursemodule->id)), + ['id' => $this->coursemodule->id]), get_string('algorithm_scheduled_for_cron', RATINGALLOCATE_MOD_NAME), null, \core\output\notification::NOTIFY_INFO); @@ -261,7 +278,7 @@ private function process_action_start_distribution() { $this->clear_all_allocations(); $DB->update_record(this_db\ratingallocate::TABLE, $this->origdbrecord); redirect(new moodle_url('/mod/ratingallocate/view.php', - array('id' => $this->coursemodule->id)), + ['id' => $this->coursemodule->id]), get_string('algorithm_now_scheduled_for_cron', RATINGALLOCATE_MOD_NAME), null, \core\output\notification::NOTIFY_INFO); @@ -287,30 +304,45 @@ private function process_action_start_distribution() { } } redirect(new moodle_url('/mod/ratingallocate/view.php', - array('id' => $this->coursemodule->id))); + ['id' => $this->coursemodule->id])); return; } + /** + * Delete sutdent ratings. + * + * @return void + * @throws coding_exception + * @throws moodle_exception + */ 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', array('id' => $this->coursemodule->id)), + 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', array('id' => $this->coursemodule->id)), + 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', array('id' => $this->coursemodule->id)), + redirect(new moodle_url('/mod/ratingallocate/view.php', ['id' => $this->coursemodule->id]), get_string('success_deleting_all', RATINGALLOCATE_MOD_NAME)); } + /** + * Give rating. + * + * @return string + * @throws coding_exception + * @throws dml_exception + * @throws moodle_exception + */ private function process_action_give_rating() { global $CFG; @@ -322,7 +354,7 @@ private function process_action_give_rating() { $status = $this->get_status(); // If no choice option exists WARN! - if (!$DB->record_exists('ratingallocate_choices', array('ratingallocateid' => $this->ratingallocateid))) { + if (!$DB->record_exists('ratingallocate_choices', ['ratingallocateid' => $this->ratingallocateid])) { $renderer->add_notification(get_string('no_choice_to_rate', RATINGALLOCATE_MOD_NAME)); } else if ($status === self::DISTRIBUTION_STATUS_RATING_IN_PROGRESS) { // Rating is possible... @@ -378,15 +410,22 @@ private function process_action_delete_rating() { $renderer->add_notification(get_string('ratings_deleted', RATINGALLOCATE_MOD_NAME), self::NOTIFY_SUCCESS); redirect(new moodle_url('/mod/ratingallocate/view.php', - array('id' => $this->coursemodule->id)), + ['id' => $this->coursemodule->id]), get_string('ratings_deleted', RATINGALLOCATE_MOD_NAME), null, \core\output\notification::NOTIFY_SUCCESS); } } - redirect(new moodle_url('/mod/ratingallocate/view.php', array('id' => $this->coursemodule->id))); + redirect(new moodle_url('/mod/ratingallocate/view.php', ['id' => $this->coursemodule->id])); } + /** + * Show choices. + * + * @return void + * @throws coding_exception + * @throws moodle_exception + */ private function process_action_show_choices() { if (has_capability('mod/ratingallocate:modify_choices', $this->context)) { @@ -418,12 +457,21 @@ private function process_action_show_choices() { $renderer->ratingallocate_show_choices_table($this, true); echo $OUTPUT->single_button(new moodle_url('/mod/ratingallocate/view.php', - array('id' => $this->coursemodule->id)), get_string('back'), 'get'); + ['id' => $this->coursemodule->id]), get_string('back'), 'get'); echo $renderer->render_footer(); } } + /** + * Edit choice. + * + * @return string + * @throws coding_exception + * @throws dml_exception + * @throws dml_transaction_exception + * @throws moodle_exception + */ private function process_action_edit_choice() { global $DB, $PAGE; @@ -434,23 +482,23 @@ private function process_action_edit_choice() { $choiceid = optional_param('choiceid', 0, PARAM_INT); if ($choiceid) { - $record = $DB->get_record(this_db\ratingallocate_choices::TABLE, array('id' => $choiceid)); + $record = $DB->get_record(this_db\ratingallocate_choices::TABLE, ['id' => $choiceid]); $choice = new ratingallocate_choice($record); } else { $choice = null; } $data = new stdClass(); - $options = array('subdirs' => false, 'maxfiles' => -1, 'accepted_types' => '*', 'return_types' => FILE_INTERNAL); + $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); $mform = new modify_choice_form(new moodle_url('/mod/ratingallocate/view.php', - array('id' => $this->coursemodule->id, + ['id' => $this->coursemodule->id, 'ratingallocateid' => $this->ratingallocateid, 'action' => ACTION_EDIT_CHOICE, - )), - $this, $choice, array('attachment_data' => $data)); + ]), + $this, $choice, ['attachment_data' => $data]); $renderer = $this->get_renderer(); @@ -484,13 +532,13 @@ 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', - array('id' => $this->coursemodule->id, + ['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', - array('id' => $this->coursemodule->id, 'action' => ACTION_SHOW_CHOICES))); + ['id' => $this->coursemodule->id, 'action' => ACTION_SHOW_CHOICES])); } } else { $isnext = optional_param('next', false, PARAM_BOOL); @@ -517,10 +565,10 @@ private function process_action_upload_choices() { $PAGE->set_secondary_active_tab('mod_ratingallocate_choices'); $url = new moodle_url('/mod/ratingallocate/view.php', - array('id' => $this->coursemodule->id, + ['id' => $this->coursemodule->id, 'ratingallocateid' => $this->ratingallocateid, 'action' => ACTION_UPLOAD_CHOICES, - ) + ] ); $mform = new upload_choices_form($url, $this); $renderer = $this->get_renderer(); @@ -552,7 +600,7 @@ private function process_action_upload_choices() { } } redirect(new moodle_url('/mod/ratingallocate/view.php', - array('id' => $this->coursemodule->id, 'action' => ACTION_SHOW_CHOICES))); + ['id' => $this->coursemodule->id, 'action' => ACTION_SHOW_CHOICES])); } $output .= $OUTPUT->heading(get_string('upload_choices', 'ratingallocate'), 2); @@ -574,10 +622,10 @@ private function process_action_enable_choice($active) { $DB->set_field(this_db\ratingallocate_choices::TABLE, this_db\ratingallocate_choices::ACTIVE, $active, - array('id' => $choiceid)); + ['id' => $choiceid]); } redirect(new moodle_url('/mod/ratingallocate/view.php', - array('id' => $this->coursemodule->id, 'action' => ACTION_SHOW_CHOICES))); + ['id' => $this->coursemodule->id, 'action' => ACTION_SHOW_CHOICES])); } } @@ -590,32 +638,39 @@ private function process_action_delete_choice() { $choiceid = optional_param('choiceid', 0, PARAM_INT); if ($choiceid) { - $choice = $DB->get_record(this_db\ratingallocate_choices::TABLE, array('id' => $choiceid)); + $choice = $DB->get_record(this_db\ratingallocate_choices::TABLE, ['id' => $choiceid]); if ($choice) { // Delete related group associations, if any. $DB->delete_records(this_db\ratingallocate_group_choices::TABLE, ['choiceid' => $choiceid]); $DB->delete_records(this_db\ratingallocate_ch_gengroups::TABLE, ['choiceid' => $choiceid]); - $DB->delete_records(this_db\ratingallocate_choices::TABLE, array('id' => $choiceid)); + $DB->delete_records(this_db\ratingallocate_choices::TABLE, ['id' => $choiceid]); redirect(new moodle_url('/mod/ratingallocate/view.php', - array('id' => $this->coursemodule->id, 'action' => ACTION_SHOW_CHOICES)), + ['id' => $this->coursemodule->id, 'action' => ACTION_SHOW_CHOICES]), get_string('choice_deleted_notification', RATINGALLOCATE_MOD_NAME, $choice->{this_db\ratingallocate_choices::TITLE}), null, \core\output\notification::NOTIFY_SUCCESS); } else { redirect(new moodle_url('/mod/ratingallocate/view.php', - array('id' => $this->coursemodule->id, 'action' => ACTION_SHOW_CHOICES)), + ['id' => $this->coursemodule->id, 'action' => ACTION_SHOW_CHOICES]), get_string('choice_deleted_notification_error', RATINGALLOCATE_MOD_NAME), null, \core\output\notification::NOTIFY_ERROR); } } redirect(new moodle_url('/mod/ratingallocate/view.php', - array('id' => $this->coursemodule->id, 'action' => ACTION_SHOW_CHOICES))); + ['id' => $this->coursemodule->id, 'action' => ACTION_SHOW_CHOICES])); } } + /** + * Manual allocation. + * + * @return string + * @throws coding_exception + * @throws moodle_exception + */ private function process_action_manual_allocation() { // Manual allocation. $output = ''; @@ -635,7 +690,7 @@ private function process_action_manual_allocation() { $notification = get_string('modify_allocation_group_desc_' . $status, RATINGALLOCATE_MOD_NAME); $notificationtype = \core\output\notification::NOTIFY_WARNING; } else { - $allocationdata = optional_param_array('allocdata', array(), PARAM_INT); + $allocationdata = optional_param_array('allocdata', [], PARAM_INT); if ($userdata = optional_param_array('userdata', null, PARAM_INT)) { $this->save_manual_allocation_form($allocationdata, $userdata); $notification = get_string('manual_allocation_saved', RATINGALLOCATE_MOD_NAME); @@ -647,29 +702,29 @@ private function process_action_manual_allocation() { } } else { redirect(new moodle_url('/mod/ratingallocate/view.php', - array('id' => $this->coursemodule->id))); + ['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', - array('id' => $this->coursemodule->id)), $notification, null, $notificationtype); + ['id' => $this->coursemodule->id]), $notification, null, $notificationtype); } else { redirect(new moodle_url('/mod/ratingallocate/view.php', - array('id' => $this->coursemodule->id))); + ['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', - array('id' => $this->coursemodule->id, 'action' => ACTION_MANUAL_ALLOCATION)), $notification, null, + ['id' => $this->coursemodule->id, 'action' => ACTION_MANUAL_ALLOCATION]), $notification, null, $notificationtype); } else { redirect(new moodle_url('/mod/ratingallocate/view.php', - array('id' => $this->coursemodule->id, 'action' => ACTION_MANUAL_ALLOCATION))); + ['id' => $this->coursemodule->id, 'action' => ACTION_MANUAL_ALLOCATION])); } } } @@ -906,7 +961,8 @@ public function get_next_choice_to_assign_user(string $distributionalgorithm, in /** * Wrapper function to queue an adhoc task for distributing unallocated users. * - * @param string $distributionalgorithm one of the string constants ACTION_DISTRIBUTE_UNALLOCATED_FILL or ACTION_DISTRIBUTE_UNALLOCATED_EQUALLY + * @param string $distributionalgorithm + * one of the string constants ACTION_DISTRIBUTE_UNALLOCATED_FILL or ACTION_DISTRIBUTE_UNALLOCATED_EQUALLY * @return void */ public function queue_distribution_of_users_without_choice(string $distributionalgorithm): void { @@ -966,6 +1022,13 @@ public function distribute_users_without_choice(string $distributionalgorithm): $transaction->allow_commit(); } + /** + * Show ratings and allocation table. + * + * @return string + * @throws coding_exception + * @throws moodle_exception + */ private function process_action_show_ratings_and_alloc_table() { $output = ''; @@ -991,6 +1054,13 @@ private function process_action_show_ratings_and_alloc_table() { return $output; } + /** + * Process action show allocation table. + * + * @return string + * @throws coding_exception + * @throws moodle_exception + */ private function process_action_show_allocation_table() { $output = ''; @@ -1012,6 +1082,13 @@ private function process_action_show_allocation_table() { return $output; } + /** + * Process action show statistics. + * + * @return string + * @throws coding_exception + * @throws moodle_exception + */ private function process_action_show_statistics() { $output = ''; // Print ratings table. @@ -1032,6 +1109,13 @@ private function process_action_show_statistics() { return $output; } + /** + * Process action publish allocations. + * + * @return void + * @throws coding_exception + * @throws moodle_exception + */ private function process_publish_allocations() { $status = $this->get_status(); if ($status === self::DISTRIBUTION_STATUS_READY_ALLOC_STARTED) { @@ -1039,26 +1123,41 @@ private function process_publish_allocations() { $this->publish_allocation(); redirect(new moodle_url('/mod/ratingallocate/view.php', - array('id' => $this->coursemodule->id)), + ['id' => $this->coursemodule->id]), get_string('distribution_published', RATINGALLOCATE_MOD_NAME), null, \core\output\notification::NOTIFY_SUCCESS); } redirect(new moodle_url('/mod/ratingallocate/view.php', - array('id' => $this->coursemodule->id))); + ['id' => $this->coursemodule->id])); } + /** + * Allocation to grouping. + * + * @return void + * @throws coding_exception + * @throws moodle_exception + * @throws required_capability_exception + */ private function process_action_allocation_to_grouping() { $this->synchronize_allocation_and_grouping(); redirect(new moodle_url('/mod/ratingallocate/view.php', - array('id' => $this->coursemodule->id)), + ['id' => $this->coursemodule->id]), get_string('moodlegroups_created', RATINGALLOCATE_MOD_NAME), null, \core\output\notification::NOTIFY_SUCCESS); } + /** + * Process default. + * + * @return string + * @throws coding_exception + * @throws moodle_exception + */ private function process_default() { global $OUTPUT; $output = ''; @@ -1068,13 +1167,13 @@ private function process_default() { if ($status === self::DISTRIBUTION_STATUS_RATING_IN_PROGRESS) { if ($this->is_setup_ok()) { $output .= $OUTPUT->single_button(new moodle_url('/mod/ratingallocate/view.php', - array('id' => $this->coursemodule->id, - 'action' => ACTION_GIVE_RATING)), + ['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', - array('id' => $this->coursemodule->id, - 'action' => ACTION_DELETE_RATING)), + ['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)); @@ -1100,7 +1199,7 @@ private function process_default() { return $output; } - // States if the ratingallocate info schould be displayed. + /** @var bool $showinfo States if the ratingallocate info schould be displayed. */ private $showinfo = true; /** @@ -1256,8 +1355,8 @@ public function get_number_of_active_raters() { ON ra.id = ra_choices.ratingallocateid INNER JOIN {ratingallocate_ratings} ra_ratings ON ra_choices.id = ra_ratings.choiceid WHERE ra.course = :courseid AND ra.id = :ratingallocateid'; - $numberofratersfromdb = $this->db->get_field_sql($sql, array( - 'courseid' => $this->course->id, 'ratingallocateid' => $this->ratingallocateid)); + $numberofratersfromdb = $this->db->get_field_sql($sql, [ + 'courseid' => $this->course->id, 'ratingallocateid' => $this->ratingallocateid]); return (int) $numberofratersfromdb; } @@ -1271,9 +1370,9 @@ public function get_ratings_for_rateable_choices() { ON c.id = r.choiceid WHERE c.ratingallocateid = :ratingallocateid AND c.active = 1'; - $ratings = $this->db->get_records_sql($sql, array( - 'ratingallocateid' => $this->ratingallocateid - )); + $ratings = $this->db->get_records_sql($sql, [ + 'ratingallocateid' => $this->ratingallocateid, + ]); $raters = $this->get_raters_in_course(); // Filter out everyone who can't give ratings. @@ -1320,7 +1419,7 @@ public function synchronize_allocation_and_grouping() { // Search if there is already a grouping from us. if (!$groupingids = $this->db->get_record(this_db\ratingallocate_groupings::TABLE, - array('ratingallocateid' => $this->ratingallocateid), + ['ratingallocateid' => $this->ratingallocateid], 'groupingid')) { // Create grouping. $data = new stdClass(); @@ -1349,7 +1448,7 @@ public function synchronize_allocation_and_grouping() { // Checks if there is already a group for this choice. if ($groupids = $this->db->get_record(this_db\ratingallocate_ch_gengroups::TABLE, - array('choiceid' => $choice->id), + ['choiceid' => $choice->id], 'groupid')) { $groupid = $groupids->groupid; @@ -1386,7 +1485,7 @@ public function synchronize_allocation_and_grouping() { // Get the group corresponding to the choiceid. $groupids = $this->db->get_record(this_db\ratingallocate_ch_gengroups::TABLE, - array('choiceid' => $choiceid), + ['choiceid' => $choiceid], 'groupid'); $groupid = $groupids->groupid; $group = groups_get_group($groupid); @@ -1395,7 +1494,7 @@ public function synchronize_allocation_and_grouping() { } } // Invalidate the grouping cache for the course. - cache_helper::invalidate_by_definition('core', 'groupdata', array(), array($this->course->id)); + cache_helper::invalidate_by_definition('core', 'groupdata', [], [$this->course->id]); } /** @@ -1415,9 +1514,9 @@ public function publish_allocation() { // Add custom data. $task->set_component('mod_ratingallocate'); - $task->set_custom_data(array( - 'ratingallocateid' => $this->ratingallocateid - )); + $task->set_custom_data([ + 'ratingallocateid' => $this->ratingallocateid, + ]); // Queue it. \core\task\manager::queue_adhoc_task($task); @@ -1446,9 +1545,9 @@ public function get_ratings_for_rateable_choices_for_raters_without_alloc() { FROM {ratingallocate_allocations} al WHERE al.ratingallocateid = :ratingallocateid'; - $allocated = $this->db->get_records_sql($sql, array( - 'ratingallocateid' => $this->ratingallocateid - )); + $allocated = $this->db->get_records_sql($sql, [ + 'ratingallocateid' => $this->ratingallocateid, + ]); $ratings = $this->get_ratings_for_rateable_choices(); // Macht daraus ein Array mit userid => quatsch. $allocated = array_flip(array_map(function($entry) { @@ -1463,8 +1562,11 @@ public function get_ratings_for_rateable_choices_for_raters_without_alloc() { return $unallocraters; } - /* + /** * Returns all active choices with allocation count + * + * @return array + * @throws dml_exception */ public function get_choices_with_allocationcount() { $sql = 'SELECT c.*, al.usercount @@ -1477,11 +1579,11 @@ public function get_choices_with_allocationcount() { ) AS al ON c.id = al.choiceid WHERE c.ratingallocateid =:ratingallocateid and c.active = :active'; - $choices = $this->db->get_records_sql($sql, array( + $choices = $this->db->get_records_sql($sql, [ 'ratingallocateid' => $this->ratingallocateid, 'ratingallocateid1' => $this->ratingallocateid, 'active' => true, - )); + ]); return $choices; } @@ -1495,9 +1597,9 @@ public function get_allocations() { LEFT JOIN {ratingallocate_choices} c ON al.choiceid = c.id LEFT JOIN {ratingallocate_ratings} r ON al.choiceid = r.choiceid AND al.userid = r.userid WHERE al.ratingallocateid = :ratingallocateid AND c.active = 1'; - $records = $this->db->get_records_sql($query, array( - 'ratingallocateid' => $this->ratingallocateid - )); + $records = $this->db->get_records_sql($query, [ + 'ratingallocateid' => $this->ratingallocateid, + ]); return $records; } @@ -1505,7 +1607,8 @@ public function get_allocations() { * Removes all allocations for choices in $ratingallocateid */ public function clear_all_allocations() { - $this->db->delete_records('ratingallocate_allocations', array('ratingallocateid' => intval($this->ratingallocateid))); + $this->db->delete_records('ratingallocate_allocations', ['ratingallocateid' => intval + ($this->ratingallocateid)]); } /** @@ -1549,13 +1652,13 @@ function ($u) { // Get the assigned choice_id. $allocchoiceid = $allocobj->choiceid; - $notificationtext = get_string('allocation_notification_message', 'ratingallocate', array( + $notificationtext = get_string('allocation_notification_message', 'ratingallocate', [ 'ratingallocate' => $this->ratingallocate->name, 'choice' => $choices[$allocchoiceid]->title, - 'explanation' => format_text($choices[$allocchoiceid]->explanation))); + 'explanation' => format_text($choices[$allocchoiceid]->explanation)]); } else if (array_key_exists($userid, $this->get_users_with_ratings())) { - $notificationtext = get_string('no_allocation_notification_message', 'ratingallocate', array( - 'ratingallocate' => $this->ratingallocate->name)); + $notificationtext = get_string('no_allocation_notification_message', 'ratingallocate', [ + 'ratingallocate' => $this->ratingallocate->name]); } // Send message to all users with an allocation or a rating. @@ -1577,7 +1680,7 @@ function ($u) { $eventdata->smallmessage = ''; $eventdata->contexturl = new moodle_url('/mod/ratingallocate/view.php', - array('id' => $this->coursemodule->id)); + ['id' => $this->coursemodule->id]); $eventdata->contexturlname = $this->ratingallocate->name; $mailresult = message_send($eventdata); @@ -1619,10 +1722,10 @@ public function get_rating_data_for_user($userid) { ON c.id = r.choiceid and r.userid = :userid WHERE c.ratingallocateid = :ratingallocateid AND c.active = 1 ORDER by c.title"; - return $this->db->get_records_sql($sql, array( + return $this->db->get_records_sql($sql, [ 'ratingallocateid' => $this->ratingallocateid, - 'userid' => $userid - )); + 'userid' => $userid, + ]); } /** @@ -1635,9 +1738,9 @@ public function get_users_with_ratings() { JOIN {ratingallocate_ratings} r ON c.id = r.choiceid WHERE c.ratingallocateid = :ratingallocateid AND c.active = 1"; - return $this->db->get_records_sql($sql, array( - 'ratingallocateid' => $this->ratingallocateid - )); + return $this->db->get_records_sql($sql, [ + 'ratingallocateid' => $this->ratingallocateid, + ]); } /** @@ -1652,9 +1755,9 @@ public function delete_all_ratings() { $choices = $this->get_choices(); foreach ($choices as $id => $choice) { - $data = array( - 'choiceid' => $id - ); + $data = [ + 'choiceid' => $id, + ]; // Delete the allocations associated with this rating. $DB->delete_records('ratingallocate_allocations', $data); @@ -1688,10 +1791,10 @@ public function delete_ratings_of_user($userid) { $choices = $this->get_choices(); foreach ($choices as $id => $choice) { - $data = array( + $data = [ 'userid' => $userid, - 'choiceid' => $id - ); + 'choiceid' => $id, + ]; // Actually delete the rating. $DB->delete_records('ratingallocate_ratings', $data); @@ -1716,16 +1819,16 @@ public function delete_ratings_of_user($userid) { public function save_ratings_to_db($userid, array $data) { global $DB; $transaction = $DB->start_delegated_transaction(); - $loggingdata = array(); + $loggingdata = []; try { foreach ($data as $id => $rdata) { $rating = new stdClass (); $rating->rating = $rdata['rating']; - $ratingexists = array( + $ratingexists = [ 'choiceid' => $rdata['choiceid'], - 'userid' => $userid - ); + 'userid' => $userid, + ]; if ($DB->record_exists('ratingallocate_ratings', $ratingexists)) { // The rating exists, we need to update its value // We get the id from the database. @@ -1737,7 +1840,7 @@ public function save_ratings_to_db($userid, array $data) { // Logging. array_push($loggingdata, - array('choiceid' => $oldrating->choiceid, 'rating' => $rating->rating)); + ['choiceid' => $oldrating->choiceid, 'rating' => $rating->rating]); } } else { // Create a new rating in the table. @@ -1749,7 +1852,7 @@ public function save_ratings_to_db($userid, array $data) { // Logging. array_push($loggingdata, - array('choiceid' => $rating->choiceid, 'rating' => $rating->rating)); + ['choiceid' => $rating->choiceid, 'rating' => $rating->rating]); } } $transaction->allow_commit(); @@ -1772,9 +1875,9 @@ 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, - array(this_db\ratingallocate_choices::RATINGALLOCATEID => $this->ratingallocateid, + [this_db\ratingallocate_choices::RATINGALLOCATEID => $this->ratingallocateid, this_db\ratingallocate_choices::ACTIVE => true, - ), this_db\ratingallocate_choices::TITLE); + ], this_db\ratingallocate_choices::TITLE); } /** @@ -1793,7 +1896,7 @@ public function filter_choices_by_groups($choices, $userid) { return $choices; } - $filteredchoices = array(); + $filteredchoices = []; // Index 0 for "all groups" without groupings. $usergroupids = groups_get_user_groups($this->course->id, $userid)[0]; @@ -1821,8 +1924,8 @@ public function filter_choices_by_groups($choices, $userid) { public function get_choices() { global $DB; return $DB->get_records(this_db\ratingallocate_choices::TABLE, - array(this_db\ratingallocate_choices::RATINGALLOCATEID => $this->ratingallocateid, - ), this_db\ratingallocate_choices::TITLE); + [this_db\ratingallocate_choices::RATINGALLOCATEID => $this->ratingallocateid, + ], this_db\ratingallocate_choices::TITLE); } /** @@ -1858,10 +1961,10 @@ public function get_allocations_for_user($userid) { WHERE al.ratingallocateid = :ratingallocateid AND al.userid = :userid'; - return $this->db->get_records_sql($sql, array( + return $this->db->get_records_sql($sql, [ 'ratingallocateid' => $this->ratingallocateid, - 'userid' => $userid - )); + 'userid' => $userid, + ]); } /** @@ -1900,11 +2003,18 @@ public function save_manual_allocation_form($allocdata, $userdata) { } } + /** + * Save form. + * + * @param $data + * @return void + * @throws dml_transaction_exception + */ public function save_modify_choice_form($data) { global $DB; try { $transaction = $this->db->start_delegated_transaction(); - $loggingdata = array(); + $loggingdata = []; $allusers = $this->get_raters_in_course(); $allchoices = $this->get_rateable_choices(); @@ -1936,10 +2046,10 @@ public function save_modify_choice_form($data) { * @return boolean */ public function remove_allocation($choiceid, $userid) { - $this->db->delete_records('ratingallocate_allocations', array( + $this->db->delete_records('ratingallocate_allocations', [ 'choiceid' => $choiceid, - 'userid' => $userid - )); + 'userid' => $userid, + ]); return true; } @@ -1949,10 +2059,10 @@ public function remove_allocation($choiceid, $userid) { * @param int $userid id of the user. */ public function remove_allocations($userid) { - $this->db->delete_records('ratingallocate_allocations', array( + $this->db->delete_records('ratingallocate_allocations', [ 'userid' => $userid, - 'ratingallocateid' => $this->ratingallocateid - )); + 'ratingallocateid' => $this->ratingallocateid, + ]); } /** @@ -1962,11 +2072,11 @@ public function remove_allocations($userid) { * @return boolean */ public function add_allocation($choiceid, $userid) { - $this->db->insert_record_raw('ratingallocate_allocations', array( + $this->db->insert_record_raw('ratingallocate_allocations', [ 'choiceid' => $choiceid, 'userid' => $userid, - 'ratingallocateid' => $this->ratingallocateid - )); + 'ratingallocateid' => $this->ratingallocateid, + ]); return true; } @@ -1979,10 +2089,10 @@ public function add_allocation($choiceid, $userid) { */ public function alter_allocation($oldchoiceid, $newchoiceid, $userid) { $this->db->set_field(this_db\ratingallocate_allocations::TABLE, this_db\ratingallocate_allocations::CHOICEID, - $newchoiceid, array( + $newchoiceid, [ 'choiceid' => $oldchoiceid, - 'userid' => $userid - ) + 'userid' => $userid, + ] ); return true; } @@ -2029,7 +2139,7 @@ public function get_renderer() { * @return array radioarray */ public function prepare_horizontal_radio_choice($radioarray, $mform) { - $result = array(); + $result = []; // Add static elements to provide a list with choices annotated with css classes. $result[] =& $mform->createElement('static', 'li', null, '
    '); foreach ($radioarray as $id => $radio) { @@ -2106,7 +2216,9 @@ public function get_algorithm_status() { return (int) $this->ratingallocate->algorithmstatus; } - /** Returns the context of the ratingallocate instance + /** + * Returns the context of the ratingallocate instance + * * @return context_module */ public function get_context() { @@ -2121,7 +2233,7 @@ public function get_context() { * @return array A mapping of group IDs to names. */ public function get_group_selections($grouplist=null) { - $options = array(); + $options = []; // Default to all relevant groups for this context. if (!$grouplist) { @@ -2150,8 +2262,8 @@ public function get_choice_groups($choiceid) { JOIN {groups} g ON gc.groupid=g.id WHERE choiceid=:choiceid'; - $records = $DB->get_records_sql($sql, array('choiceid' => $choiceid)); - $results = array(); + $records = $DB->get_records_sql($sql, ['choiceid' => $choiceid]); + $results = []; foreach ($records as $record) { $results[$record->id] = $record; @@ -2189,14 +2301,16 @@ public function update_choice_groups($choiceid, $groupids) { // Remove records for obsolete choice group entries. foreach ($removals as $gid) { - $DB->delete_records('ratingallocate_group_choices', array( + $DB->delete_records('ratingallocate_group_choices', [ 'choiceid' => $choiceid, 'groupid' => $gid, - )); + ]); } } /** + * Is the setup ok? + * * @return bool true, if all strategy settings are ok. */ public function is_setup_ok() { @@ -2213,12 +2327,14 @@ public function is_setup_ok() { } /** + * Get File attachments. + * * @param int choiceid * @return array of file objects. */ public function get_file_attachments_for_choice($choiceid) { $areafiles = get_file_storage()->get_area_files($this->context->id, 'mod_ratingallocate', 'choice_attachment', $choiceid); - $files = array(); + $files = []; foreach ($areafiles as $f) { if ($f->is_directory()) { // Skip directories. @@ -2306,6 +2422,11 @@ public function __set($name, $value) { $this->dbrecord->{$name} = $value; } + /** + * Construct. + * + * @param $record + */ public function __construct($record) { $this->dbrecord = $record; } @@ -2342,6 +2463,11 @@ public function __set($name, $value) { $this->dbrecord->{$name} = $value; } + /** + * Construct. + * + * @param $record + */ public function __construct($record) { $this->dbrecord = $record; } @@ -2362,11 +2488,11 @@ function groups_delete_group_members_by_group($groupid) { } // Select * so that the function groups_remove_member() gets the whole record. - $groups = $DB->get_recordset('groups', array('id' => $groupid)); + $groups = $DB->get_recordset('groups', ['id' => $groupid]); foreach ($groups as $group) { $userids = $DB->get_fieldset_select('groups_members', 'userid', 'groupid = :groupid', - array('groupid' => $group->id)); + ['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 45adb8bf..dcea11da 100644 --- a/mod_form.php +++ b/mod_form.php @@ -34,11 +34,25 @@ * Module instance settings form */ class mod_ratingallocate_mod_form extends moodleform_mod { + /** + * Mod_name. + */ const MOD_NAME = 'ratingallocate'; + /** + * Choice placeholder. + */ const CHOICE_PLACEHOLDER_IDENTIFIER = 'placeholder_for_choices'; + /** + * Strategy options. + */ const STRATEGY_OPTIONS = 'strategyopt'; + /** + * Strategyoptions placeholder. + */ const STRATEGY_OPTIONS_PLACEHOLDER = 'placeholder_strategyopt'; + /** @var int $newchoicecounter */ private $newchoicecounter = 0; + /** @var lang_string|string $msgerrorrequired */ private $msgerrorrequired; /** @@ -72,9 +86,9 @@ public function definition() { $mform->addElement('header', 'general', get_string('general', 'form')); // Adding the standard "name" field. - $mform->addElement('text', 'name', get_string('ratingallocatename', self::MOD_NAME), array( - 'size' => '64' - )); + $mform->addElement('text', 'name', get_string('ratingallocatename', self::MOD_NAME), [ + 'size' => '64', + ]); if (!empty($CFG->formatstringstriptags)) { $mform->setType('name', PARAM_TEXT); } else { @@ -90,7 +104,7 @@ public function definition() { // ------------------------------------------------------------------------------- $elementname = 'strategy'; // Define options for select. - $selectoptions = array(); + $selectoptions = []; foreach (\strategymanager::get_strategies() as $strategy) { $selectoptions[$strategy] = get_string($strategy . '_name', self::MOD_NAME); } @@ -112,11 +126,11 @@ public function definition() { $elementname = 'publishdate'; $mform->addElement('date_time_selector', $elementname, get_string($elementname, self::MOD_NAME), - array('optional' => true)); + ['optional' => true]); $mform->setDefault($elementname, time() + 9 * 24 * 60 * 60); $elementname = 'runalgorithmbycron'; - $mform->addElement('advcheckbox', $elementname, get_string($elementname, self::MOD_NAME), null, null, array(0, 1)); + $mform->addElement('advcheckbox', $elementname, get_string($elementname, self::MOD_NAME), null, null, [0, 1]); $mform->addHelpButton($elementname, $elementname, self::MOD_NAME); $mform->setDefault($elementname, 1); @@ -151,7 +165,7 @@ public function get_disable_strategy($includeratingallocate = false) { $courseid = $update; $cm = get_coursemodule_from_id('ratingallocate', $courseid, 0, false, MUST_EXIST); $course = get_course($cm->course); - $ratingallocatedb = $DB->get_record('ratingallocate', array('id' => $cm->instance), '*', MUST_EXIST); + $ratingallocatedb = $DB->get_record('ratingallocate', ['id' => $cm->instance], '*', MUST_EXIST); $context = context_module::instance($cm->id); $ratingallocate = new ratingallocate($ratingallocatedb, $course, $cm, $context); $disablestrategy = $ratingallocate->get_number_of_active_raters() > 0; @@ -164,7 +178,7 @@ public function get_disable_strategy($includeratingallocate = false) { } else { return [ 'ratingallocate' => $ratingallocate, - 'disable_strategy' => $disablestrategy + 'disable_strategy' => $disablestrategy, ]; } } @@ -202,7 +216,12 @@ private function add_settings_field($stratfieldid, array $value, $strategyid, Mo $mform->hideIf($stratfieldid, 'strategy', 'neq', $strategyid); } - // Override if you need to setup the form depending on current values. + /** + * Override if you need to setup the form depending on current values. + * + * @return void + * @throws coding_exception + */ public function definition_after_data() { parent::definition_after_data(); $mform = &$this->_form; diff --git a/renderable.php b/renderable.php index 96874eb4..0b3e443b 100644 --- a/renderable.php +++ b/renderable.php @@ -40,6 +40,14 @@ class ratingallocate_header implements renderable { /** @var int coursemoduleid - The course module id */ public $coursemoduleid = 0; + /** + * Construct. + * + * @param ratingallocate_db_wrapper $ratingallocate + * @param $context + * @param $showintro + * @param $coursemoduleid + */ public function __construct(ratingallocate_db_wrapper $ratingallocate, $context, $showintro, $coursemoduleid) { $this->ratingallocate = $ratingallocate; $this->context = $context; @@ -48,21 +56,37 @@ public function __construct(ratingallocate_db_wrapper $ratingallocate, $context, } } +/** + * Choice status + * + * @package mod_ratingallocate + */ class ratingallocate_choice_status implements renderable { + /** @var $accesstimestop */ public $accesstimestop; + /** @var $accesstimestart */ public $accesstimestart; + /** @var $ispublished */ public $ispublished; + /** @var $publishdate */ public $publishdate; + /** @var $availablechoices */ public $availablechoices; + /** @var $necessarychoices */ public $necessarychoices; + /** @var $ownchoices */ public $ownchoices; + /** @var $allocations */ public $allocations; + /** @var $strategy */ public $strategy; /** @var bool show_distribution_info specifies if the info regarding the distribution should be displayed. * */ public $showdistributioninfo; /** @var bool show_user_info specifies if the current ratings of the user shoulld be renderer. * */ public $showuserinfo; + /** @var $algorithmstarttime */ public $algorithmstarttime; + /** @var $algorithmstatus */ public $algorithmstatus; } diff --git a/renderer.php b/renderer.php index 1fbccfe4..953a3858 100644 --- a/renderer.php +++ b/renderer.php @@ -22,6 +22,8 @@ require_once(dirname(__FILE__) . '/locallib.php'); /** + * Renderer for ratingallocate. + * * @package mod_ratingallocate * @copyright 2014 M Schulze, T Reischmann, C Usener * @copyright based on code by Stefan Koegel copyright (C) 2013 Stefan Koegel @@ -32,7 +34,7 @@ class mod_ratingallocate_renderer extends plugin_renderer_base { /** * @var array rendered notifications to output for handle_view() */ - private $notifications = array(); + private $notifications = []; /** * Render the header. @@ -58,6 +60,8 @@ public function render_ratingallocate_header(ratingallocate_header $header) { } /** + * Render strategyform. + * * @param $mform ratingallocate_strategyform * @return string * @throws coding_exception @@ -273,10 +277,10 @@ public function render_ratingallocate_choice_status(ratingallocate_choice_status } else { $cell2 = new html_table_cell(format_time($duedate - $time)); } - $row->cells = array( + $row->cells = [ $cell1, - $cell2 - ); + $cell2, + ]; $t->data[] = $row; } } @@ -304,32 +308,32 @@ public function render_ratingallocate_choice_status(ratingallocate_choice_status $row = new html_table_row(); $cell1 = new html_table_cell(get_string('your_rating', RATINGALLOCATE_MOD_NAME)); - $choiceshtml = array(); + $choiceshtml = []; foreach ($status->ownchoices as $choice) { array_push($choiceshtml, format_string($choice->title) . ' (' . s($this->get_option_title($choice->rating, $status->strategy)) . ')'); } $cell2 = new html_table_cell(html_writer::alist($choiceshtml)); - $row->cells = array( + $row->cells = [ $cell1, - $cell2 - ); + $cell2, + ]; $t->data[] = $row; } else if (!empty($status->availablechoices)) { $row = new html_table_row(); $cell1 = new html_table_cell(get_string('rateable_choices', RATINGALLOCATE_MOD_NAME)); - $choiceshtml = array(); + $choiceshtml = []; foreach ($status->ownchoices as $choice) { array_push($choiceshtml, format_string($choice->title)); } $cell2 = new html_table_cell(html_writer::alist($choiceshtml)); - $row->cells = array( + $row->cells = [ $cell1, - $cell2 - ); + $cell2, + ]; $t->data[] = $row; } @@ -355,7 +359,7 @@ public function render_ratingallocate_choice_status(ratingallocate_choice_status $allocationhtml .= '
    ' . format_text($allocation->{this_db\ratingallocate_choices::EXPLANATION}); } $cell2 = new html_table_cell($allocationhtml); - $row->cells = array($cell1, $cell2); + $row->cells = [$cell1, $cell2]; $t->data[] = $row; } else if (!empty($status->ownchoices)) { // Only print warning that user is not allocated if she has any rating. @@ -367,7 +371,7 @@ public function render_ratingallocate_choice_status(ratingallocate_choice_status get_string('you_are_not_allocated', RATINGALLOCATE_MOD_NAME), 'allocation tag tag-danger'); $cell2 = new html_table_cell($allocationhtml); - $row->cells = array($cell1, $cell2); + $row->cells = [$cell1, $cell2]; $t->data[] = $row; } } @@ -438,7 +442,7 @@ public function modify_choices_group($ratingallocateid, $coursemoduleid, $status $output .= $this->heading(get_string('modify_choices_group', RATINGALLOCATE_MOD_NAME), 2); $output .= $this->box_start(); - $starturl = new moodle_url($this->page->url->out(), array('action' => ACTION_SHOW_CHOICES)); + $starturl = new moodle_url($this->page->url->out(), ['action' => ACTION_SHOW_CHOICES]); // Get description dependent on status. $descriptionbaseid = 'modify_choices_group_desc_'; @@ -446,7 +450,7 @@ public function modify_choices_group($ratingallocateid, $coursemoduleid, $status $output .= $this->format_text($description); - $output .= html_writer::empty_tag('br', array()); + $output .= html_writer::empty_tag('br', []); $button = new single_button($starturl, get_string('modify_choices', RATINGALLOCATE_MOD_NAME), 'get'); $button->tooltip = get_string('modify_choices_explanation', RATINGALLOCATE_MOD_NAME); @@ -470,8 +474,8 @@ public function modify_allocation_group($ratingallocateid, $coursemoduleid, $ratingover = $status !== ratingallocate::DISTRIBUTION_STATUS_TOO_EARLY && $status !== ratingallocate::DISTRIBUTION_STATUS_RATING_IN_PROGRESS; - $starturl = new moodle_url($this->page->url, array('action' => ACTION_START_DISTRIBUTION)); - $deleteurl = new moodle_url($this->page->url, array('id' => $coursemoduleid, 'action' => ACTION_DELETE_ALL_RATINGS)); + $starturl = new moodle_url($this->page->url, ['action' => ACTION_START_DISTRIBUTION]); + $deleteurl = new moodle_url($this->page->url, ['id' => $coursemoduleid, 'action' => ACTION_DELETE_ALL_RATINGS]); // Get description dependent on status. $descriptionbaseid = 'modify_allocation_group_desc_'; @@ -479,7 +483,7 @@ public function modify_allocation_group($ratingallocateid, $coursemoduleid, $output .= $this->format_text($description); - $output .= html_writer::empty_tag('br', array()); + $output .= html_writer::empty_tag('br', []); $button = new single_button($starturl, get_string('start_distribution', RATINGALLOCATE_MOD_NAME), 'get'); // Enable only if the instance is ready and the algorithm may run manually. @@ -489,9 +493,9 @@ public function modify_allocation_group($ratingallocateid, $coursemoduleid, $output .= $this->render($button); - $output .= $this->single_button(new moodle_url('/mod/ratingallocate/view.php', array('id' => $coursemoduleid, - 'action' => ACTION_MANUAL_ALLOCATION)), get_string('manual_allocation_form', RATINGALLOCATE_MOD_NAME), 'get', - array('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')); @@ -506,7 +510,7 @@ public function modify_allocation_group($ratingallocateid, $coursemoduleid, $output .= html_writer::start_div('ratingallocate_distribute_unallocated'); - $distributeunallocatedurl = new moodle_url($this->page->url, array('action' => ACTION_DISTRIBUTE_UNALLOCATED_EQUALLY)); + $distributeunallocatedurl = new moodle_url($this->page->url, ['action' => ACTION_DISTRIBUTE_UNALLOCATED_EQUALLY]); $button = new single_button($distributeunallocatedurl, get_string('distributeequally', RATINGALLOCATE_MOD_NAME), 'get'); @@ -517,7 +521,7 @@ public function modify_allocation_group($ratingallocateid, $coursemoduleid, $output .= $this->render($button); - $distributeunallocatedurl = new moodle_url($this->page->url, array('action' => ACTION_DISTRIBUTE_UNALLOCATED_FILL)); + $distributeunallocatedurl = new moodle_url($this->page->url, ['action' => ACTION_DISTRIBUTE_UNALLOCATED_FILL]); $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. @@ -555,16 +559,16 @@ public function publish_allocation_group($ratingallocateid, $coursemoduleid, $st $output .= $this->format_text($description); - $output .= html_writer::empty_tag('br', array()); + $output .= html_writer::empty_tag('br', []); - $output .= $this->single_button(new moodle_url('/mod/ratingallocate/view.php', array('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', - array('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', array('id' => $coursemoduleid, + $output .= $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'); + 'action' => ACTION_ALLOCATION_TO_GROUPING]), get_string('create_moodle_groups', RATINGALLOCATE_MOD_NAME), 'get'); $output .= $this->box_end(); return $output; @@ -583,18 +587,18 @@ public function reports_group($ratingallocateid, $coursemoduleid, $status, $cont 'action', array( 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) + ACTION_SHOW_STATISTICS => get_string('show_allocation_statistics', RATINGALLOCATE_MOD_NAME), ), $action ); /* TODO: File not readable - $output .= html_writer::empty_tag('br', array()); + $output .= html_writer::empty_tag('br', []); if (has_capability('mod/ratingallocate:export_ratings', $context)) { $output .= $this->action_link(new moodle_url( - '/mod/ratingallocate/solver/export_lp_solve.php', array('id' => $coursemoduleid, - 'ratingallocateid' => $ratingallocateid)), get_string('download_problem_mps_format', RATINGALLOCATE_MOD_NAME)); + '/mod/ratingallocate/solver/export_lp_solve.php', ['id' => $coursemoduleid, + 'ratingallocateid' => $ratingallocateid]), get_string('download_problem_mps_format', RATINGALLOCATE_MOD_NAME)); }*/ $output .= $this->box_end(); @@ -610,32 +614,32 @@ public function ratingallocate_show_choices_table(ratingallocate $ratingallocate global $CFG; require_once($CFG->libdir . '/tablelib.php'); - $starturl = new moodle_url($this->page->url, array('action' => ACTION_EDIT_CHOICE)); + $starturl = new moodle_url($this->page->url, ['action' => ACTION_EDIT_CHOICE]); echo $this->output->single_button($starturl, get_string('newchoice', 'mod_ratingallocate'), 'get'); - $uploadcsvurl = new moodle_url($this->page->url, array('action' => ACTION_UPLOAD_CHOICES)); - echo $this->output->single_button($uploadcsvurl, get_string('csvupload', 'ratingallocate'), 'get', array( - 'tooltip' => get_string('csvupload_explanation', 'ratingallocate') - )); + $uploadcsvurl = new moodle_url($this->page->url, ['action' => ACTION_UPLOAD_CHOICES]); + echo $this->output->single_button($uploadcsvurl, get_string('csvupload', 'ratingallocate'), 'get', [ + 'tooltip' => get_string('csvupload_explanation', 'ratingallocate'), + ]); // Set up the table. $table = new \flexible_table('show_ratingallocate_options'); $table->define_baseurl($this->page->url); if ($choicesmodifiably) { - $table->define_columns(array('title', 'explanation', 'maxsize', 'active', 'usegroups', 'tools')); - $table->define_headers(array(get_string('choice_table_title', 'mod_ratingallocate'), + $table->define_columns(['title', 'explanation', 'maxsize', 'active', 'usegroups', 'tools']); + $table->define_headers([get_string('choice_table_title', 'mod_ratingallocate'), get_string('choice_table_explanation', 'mod_ratingallocate'), get_string('choice_table_maxsize', 'mod_ratingallocate'), get_string('choice_table_active', 'mod_ratingallocate'), get_string('choice_table_usegroups', 'mod_ratingallocate'), - get_string('choice_table_tools', 'mod_ratingallocate'))); + get_string('choice_table_tools', 'mod_ratingallocate')]); } else { - $table->define_columns(array('title', 'explanation', 'maxsize', 'active', 'usegroups')); - $table->define_headers(array(get_string('choice_table_title', 'mod_ratingallocate'), + $table->define_columns(['title', 'explanation', 'maxsize', 'active', 'usegroups']); + $table->define_headers([get_string('choice_table_title', 'mod_ratingallocate'), get_string('choice_table_explanation', 'mod_ratingallocate'), get_string('choice_table_maxsize', 'mod_ratingallocate'), get_string('choice_table_usegroups', 'mod_ratingallocate'), - get_string('choice_table_tools', 'mod_ratingallocate'))); + get_string('choice_table_tools', 'mod_ratingallocate')]); } $table->set_attribute('id', 'mod_ratingallocateshowoptions'); $table->set_attribute('class', 'admintable generaltable'); @@ -648,7 +652,7 @@ public function ratingallocate_show_choices_table(ratingallocate $ratingallocate return; } foreach ($choices as $idx => $choice) { - $row = array(); + $row = []; $class = ''; $row[] = $choice->{this_db\ratingallocate_choices::TITLE}; $explanation = format_text($choice->{this_db\ratingallocate_choices::EXPLANATION}); @@ -690,7 +694,7 @@ public function ratingallocate_show_choices_table(ratingallocate $ratingallocate * @return string HTML for the attachments */ public function render_attachments($files, $break = false) { - $entries = array(); + $entries = []; foreach ($files as $f) { $filename = $f->get_filename(); $url = moodle_url::make_pluginfile_url( @@ -701,10 +705,10 @@ public function render_attachments($files, $break = false) { $f->get_filepath(), $f->get_filename(), false); - $a = array( + $a = [ 'href' => $url, 'title' => $filename, - ); + ]; $entry = ''; if (!$break) { @@ -714,7 +718,7 @@ public function render_attachments($files, $break = false) { $entry .= html_writer::empty_tag('br'); } $entry .= html_writer::start_tag('a', $a); - $entry .= $this->output->image_icon('t/right', $filename, 'moodle', array('title' => 'Download file')); + $entry .= $this->output->image_icon('t/right', $filename, 'moodle', ['title' => 'Download file']); $entry .= $filename; $entry .= html_writer::end_tag('a'); $entries[] = $entry; @@ -756,9 +760,9 @@ private function format_icon_link($action, $choice, $icon, $alt, $confirm = null $url = $this->page->url; return $this->output->action_icon(new \moodle_url($url, - array('action' => $action, 'choiceid' => $choice, 'sesskey' => sesskey())), - new \pix_icon($icon, $alt, 'moodle', array('title' => $alt)), - $confirm, array('title' => $alt)) . ' '; + ['action' => $action, 'choiceid' => $choice, 'sesskey' => sesskey()]), + new \pix_icon($icon, $alt, 'moodle', ['title' => $alt]), + $confirm, ['title' => $alt]) . ' '; } /** @@ -788,7 +792,7 @@ public function render_footer() { */ public function statistics_table_for_ratingallocate(ratingallocate $ratingallocate) { // Count the number of allocations with a specific rating. - $distributiondata = array(); + $distributiondata = []; $memberships = $ratingallocate->get_allocations(); @@ -807,8 +811,8 @@ public function statistics_table_for_ratingallocate(ratingallocate $ratingalloca // Although all indices should be numeric or null, // SORT_STRING cares for the correct comparison of null and 0. krsort($distributiondata, SORT_STRING); - $allocationrow = array(); - $allocationhead = array(); + $allocationrow = []; + $allocationhead = []; foreach ($distributiondata as $rating => $count) { $cell = new html_table_cell(); $cell->text = $count; @@ -830,7 +834,7 @@ public function statistics_table_for_ratingallocate(ratingallocate $ratingalloca $allocationhead[] = $cell; $allocationtable = new html_table(); - $allocationtable->data = array($allocationrow); + $allocationtable->data = [$allocationrow]; $allocationtable->head = $allocationhead; $output = $this->heading(get_string('allocation_statistics', RATINGALLOCATE_MOD_NAME), 2); @@ -841,16 +845,17 @@ public function statistics_table_for_ratingallocate(ratingallocate $ratingalloca if (count($distributiondata) == 0) { $output .= $this->format_text(get_string('allocation_statistics_description_no_alloc', RATINGALLOCATE_MOD_NAME, - array('notrated' => $notrated, 'rated' => $activeraters))); + ['notrated' => $notrated, 'rated' => $activeraters])); } else { $output .= $this->format_text(get_string('allocation_statistics_description', RATINGALLOCATE_MOD_NAME, - array('users' => $distributiondata[max(array_keys($distributiondata))], + ['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())))); + 'unassigned' => count($ratingallocate->get_undistributed_users()), + ])); $output .= html_writer::table($allocationtable); } $output .= $this->box_end(); @@ -922,7 +927,7 @@ public function ratings_table_for_ratingallocate($choices, $ratings, $users, $me * @return multitype:Ambigous */ private function get_options_titles($ratings, ratingallocate $ratingallocate) { - $titles = array(); + $titles = []; $uniqueratings = array_unique($ratings); $options = $ratingallocate->get_options_titles($uniqueratings); foreach ($options as $id => $option) { @@ -956,7 +961,7 @@ private function add_table_row_tuple(html_table $table, $first, $second) { $row = new html_table_row(); $cell1 = new html_table_cell($first); $cell2 = new html_table_cell($second); - $row->cells = array($cell1, $cell2); + $row->cells = [$cell1, $cell2]; $table->data[] = $row; } diff --git a/settings.php b/settings.php index 1c4c0ac1..65d0fe1f 100644 --- a/settings.php +++ b/settings.php @@ -36,7 +36,7 @@ 'username' => 1, 'department' => 0, 'institution' => 0, - 'email' => 1 + 'email' => 1, ], [ 'id' => new lang_string('userid', 'ratingallocate'), diff --git a/solver/edmonds-karp.php b/solver/edmonds-karp.php index 9fdf8846..05a2f012 100644 --- a/solver/edmonds-karp.php +++ b/solver/edmonds-karp.php @@ -28,14 +28,33 @@ require_once(dirname(__FILE__) . '/../locallib.php'); require_once(dirname(__FILE__) . '/solver-template.php'); +/** + * Solver edmonds-karp. + * + * @package mod_ratingallocate + */ class solver_edmonds_karp extends distributor { + /** + * Return name. + * + * @return string + */ public function get_name() { return 'edmonds_karp'; } + /** + * Compute distribution. + * + * @param $choicerecords + * @param $ratings + * @param $usercount + * @return an|array + * @throws moodle_exception + */ public function compute_distribution($choicerecords, $ratings, $usercount) { - $choicedata = array(); + $choicedata = []; foreach ($choicerecords as $record) { $choicedata[$record->id] = $record; } @@ -71,9 +90,9 @@ public function compute_distribution($choicerecords, $ratings, $usercount) { */ private function find_shortest_path_bellf($from, $to) { // Table of distances known so far. - $dists = array(); + $dists = []; // Table of predecessors (used to reconstruct the shortest path later). - $preds = array(); + $preds = []; // Number of nodes in the graph. $count = $this->graph['count']; @@ -116,7 +135,7 @@ private function find_shortest_path_bellf($from, $to) { unset($dists); // Use the preds table to reconstruct the shortest path. - $path = array(); + $path = []; $p = $to; while ($p != $from) { $path[] = $p; diff --git a/solver/export_lp_solve.php b/solver/export_lp_solve.php index a33c624f..4a006b39 100644 --- a/solver/export_lp_solve.php +++ b/solver/export_lp_solve.php @@ -34,9 +34,9 @@ if ($id) { $cm = get_coursemodule_from_id('ratingallocate', $id, 0, false, MUST_EXIST); $course = get_course($cm->course); - $ratingallocate = $DB->get_record('ratingallocate', array( - 'id' => $cm->instance - ), '*', MUST_EXIST); + $ratingallocate = $DB->get_record('ratingallocate', [ + 'id' => $cm->instance, + ], '*', MUST_EXIST); } else { error('You must specify a course_module ID'); } @@ -52,6 +52,7 @@ * Eine beim csv_export_writer abgeschaute Klasse, die in Dateien schreiben kann und zum Download anbieten. * @copyright (c) 2014, M Schulze * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @package mod_ratingallocate */ class lp_export_write { /** @var $filename path to write file */ @@ -180,10 +181,10 @@ public function __destruct() { $choices = $ratingallocateobj->get_rateable_choices(); $ratings = $ratingallocateobj->get_ratings_for_rateable_choices(); -$ratingscells = array(); +$ratingscells = []; foreach ($ratings as $rating) { if (!array_key_exists($rating->userid, $ratingscells)) { - $ratingscells[$rating->userid] = array(); + $ratingscells[$rating->userid] = []; } $ratingscells[$rating->userid][$rating->choiceid] = $rating->rating; } @@ -191,7 +192,7 @@ public function __destruct() { $zielfkt = 'max '; // The function to maximise. $usernb = ''; // Constraint for each user, to be only allocated to one choice. $variablenerkl = ''; -$nbkurs = array(); // Constraint for each course. +$nbkurs = []; // Constraint for each course. foreach ($ratingscells as $userid => $userrating) { $variablenerkl .= 'bin'; $nbkursakt = ''; diff --git a/solver/ford-fulkerson-koegel.php b/solver/ford-fulkerson-koegel.php index d8f2c1e6..fce4b315 100644 --- a/solver/ford-fulkerson-koegel.php +++ b/solver/ford-fulkerson-koegel.php @@ -30,6 +30,11 @@ require_once(dirname(__FILE__) . '/../locallib.php'); require_once(dirname(__FILE__) . '/solver-template.php'); +/** + * Solver Ford-fulkerson. + * + * @package mod_ratingallocate + */ class solver_ford_fulkerson extends distributor { /** @@ -43,7 +48,7 @@ class solver_ford_fulkerson extends distributor { * */ public function compute_distribution($choicerecords, $ratings, $usercount) { - $groupdata = array(); + $groupdata = []; foreach ($choicerecords as $record) { $groupdata[$record->id] = $record; } @@ -87,9 +92,9 @@ public function compute_distribution($choicerecords, $ratings, $usercount) { public function find_shortest_path_bellmanf_koegel($from, $to) { // Table of distances known so far. - $dists = array(); + $dists = []; // Table of predecessors (used to reconstruct the shortest path later). - $preds = array(); + $preds = []; // Stack of the edges we need to test next. $edges = $this->graph[$from]; // Number of nodes in the graph. @@ -141,7 +146,7 @@ public function find_shortest_path_bellmanf_koegel($from, $to) { } // Use the preds table to reconstruct the shortest path. - $path = array(); + $path = []; $p = $to; while ($p != $from) { $path[] = $p; @@ -152,6 +157,11 @@ public function find_shortest_path_bellmanf_koegel($from, $to) { return $path; } + /** + * Return name. + * + * @return string + */ public function get_name() { return "ford-fulkerson Koegel2014"; } diff --git a/solver/solver-template.php b/solver/solver-template.php index 3b9e8370..42f24141 100644 --- a/solver/solver-template.php +++ b/solver/solver-template.php @@ -32,6 +32,11 @@ */ defined('MOODLE_INTERNAL') || die(); +/** + * Edge. + * + * @package mod_ratingallocate + */ class edge { /** @var from int */ public $from; @@ -42,6 +47,14 @@ class edge { /** @var space int (places left for choices) */ public $space; + /** + * Construct. + * + * @param $from + * @param $to + * @param $weight + * @param $space + */ public function __construct($from, $to, $weight, $space = 0) { $this->from = $from; $this->to = $to; @@ -121,10 +134,10 @@ public function distribute_users(\ratingallocate $ratingallocate) { * @return an array of the form array(groupid => array(userid, ...), ...) */ protected function extract_allocation($touserid, $tochoiceid) { - $distribution = array(); + $distribution = []; foreach ($tochoiceid as $index => $groupid) { $group = $this->graph[$index]; - $distribution[$groupid] = array(); + $distribution[$groupid] = []; foreach ($group as $assignment) { $user = intval($assignment->to); if (array_key_exists($user, $touserid)) { @@ -144,12 +157,12 @@ protected function extract_allocation($touserid, $tochoiceid) { public static function setup_id_conversions($usercount, $ratings) { // These tables convert userids to their index in the graph // The range is [1..$usercount]. - $fromuserid = array(); - $touserid = array(); + $fromuserid = []; + $touserid = []; // These tables convert choiceids to their index in the graph // The range is [$usercount + 1 .. $usercount + $choicecount]. - $fromchoiceid = array(); - $tochoiceid = array(); + $fromchoiceid = []; + $tochoiceid = []; // User counter. $ui = 1; @@ -170,7 +183,7 @@ public static function setup_id_conversions($usercount, $ratings) { } } - return array($fromuserid, $touserid, $fromchoiceid, $tochoiceid); + return[$fromuserid, $touserid, $fromchoiceid, $tochoiceid]; } /** @@ -191,19 +204,19 @@ protected function setup_graph($choicecount, $usercount, $fromuserid, $fromchoic // A source is connected to all users with unit cost. // The users are connected to their choices with cost equal to their rating. // The choices are connected to a sink with 0 cost. - $this->graph = array(); + $this->graph = []; // Add source, sink and number of nodes to the graph. - $this->graph[$source] = array(); - $this->graph[$sink] = array(); + $this->graph[$source] = []; + $this->graph[$sink] = []; $this->graph['count'] = $choicecount + $usercount + 2; // Add users and choices to the graph and connect them to the source and sink. foreach ($fromuserid as $id => $user) { - $this->graph[$user] = array(); + $this->graph[$user] = []; $this->graph[$source][] = new edge($source, $user, 0); } foreach ($fromchoiceid as $id => $choice) { - $this->graph[$choice] = array(); + $this->graph[$choice] = []; if ($choicedata[$id]->maxsize > 0) { $this->graph[$choice][] = new edge($choice, $sink, 0, $choicedata[$id]->maxsize); } diff --git a/strategy/strategy01_yes_no.php b/strategy/strategy01_yes_no.php index e8328f43..9d7a2850 100644 --- a/strategy/strategy01_yes_no.php +++ b/strategy/strategy01_yes_no.php @@ -33,65 +33,81 @@ require_once(dirname(__FILE__) . '/../locallib.php'); require_once(dirname(__FILE__) . '/strategy_template_options.php'); +/** + * Strategy + * + * @package mod_ratingallocate + */ class strategy extends \strategytemplate_options { + /** + * Strategyid. + */ const STRATEGYID = 'strategy_yesno'; - const MAXCROSSOUT = 'maxcrossout'; // Maximum to deny. + /** + * Maximum to deny. + */ + const MAXCROSSOUT = 'maxcrossout'; public function get_strategyid() { return self::STRATEGYID; } public function get_static_settingfields() { - $output = array( - self::MAXCROSSOUT => array( + $output = [ + self::MAXCROSSOUT => [ 'int', get_string(self::STRATEGYID . '_setting_crossout', RATINGALLOCATE_MOD_NAME), $this->get_settings_value(self::MAXCROSSOUT), - null - ) - ); + null, + ], + ]; foreach (array_keys($this->get_choiceoptions()) as $id) { - $output[$id] = array( + $output[$id] = [ 'text', get_string('strategy_settings_label', RATINGALLOCATE_MOD_NAME, $this->get_settings_default_value($id)), null, - $this->get_settings_default_value($id) - ); + $this->get_settings_default_value($id), + ]; } $output += $this->get_default_strategy_option(); return $output; } public function get_dynamic_settingfields() { - return array(); + return []; } public function get_choiceoptions() { - $options = array( + $options = [ 0 => $this->get_settings_value(0), - 1 => $this->get_settings_value(1) - ); + 1 => $this->get_settings_value(1), + ]; return $options; } public function get_default_settings() { - return array( + return [ self::MAXCROSSOUT => 3, 0 => get_string(self::STRATEGYID . '_rating_crossout', RATINGALLOCATE_MOD_NAME), 1 => get_string(self::STRATEGYID . '_rating_choose', RATINGALLOCATE_MOD_NAME), 'default' => 1, - ); + ]; } protected function getvalidationinfo() { - return array(self::MAXCROSSOUT => array(true, 0)); + return [self::MAXCROSSOUT => [true, 0]]; } } // Register with the strategymanager. \strategymanager::add_strategy(strategy::STRATEGYID); +/** + * View form + * + * @package mod_ratingallocate + */ class mod_ratingallocate_view_form extends \ratingallocate_options_strategyform { // Already specified by parent class. diff --git a/strategy/strategy02_yes_maybe_no.php b/strategy/strategy02_yes_maybe_no.php index 226f0a37..c1e8af01 100644 --- a/strategy/strategy02_yes_maybe_no.php +++ b/strategy/strategy02_yes_maybe_no.php @@ -34,9 +34,20 @@ require_once(dirname(__FILE__) . '/../locallib.php'); require_once(dirname(__FILE__) . '/strategy_template_options.php'); +/** + * Strategy. + * + * @package mod_ratingallocate + */ class strategy extends \strategytemplate_options { + /** + * Strategyid. + */ const STRATEGYID = 'strategy_yesmaybeno'; + /** + * Maximal votes for no. + */ const MAXNO = 'maxno'; public function get_strategyid() { @@ -44,57 +55,83 @@ public function get_strategyid() { } public function get_static_settingfields() { - $output = array( - self::MAXNO => array(// Maximum count of 'No'. + $output = [ + self::MAXNO => [// Maximum count of 'No'. 'int', get_string(self::STRATEGYID . '_setting_maxno', RATINGALLOCATE_MOD_NAME), $this->get_settings_value(self::MAXNO), - null - ) - ); + null, + ], + ]; foreach (array_keys($this->get_choiceoptions()) as $id) { - $output[$id] = array( + $output[$id] = [ 'text', get_string('strategy_settings_label', RATINGALLOCATE_MOD_NAME, $this->get_settings_default_value($id)), null, - $this->get_settings_default_value($id) - ); + $this->get_settings_default_value($id), + ]; } $output += $this->get_default_strategy_option(); return $output; } + /** + * Get dynamic settingfields. + * + * @return array + */ public function get_dynamic_settingfields() { - return array(); + return []; } + /** + * Get choiceoptions. + * + * @return array + */ public function get_choiceoptions() { - $options = array( + $options = [ 0 => $this->get_settings_value(0), 3 => $this->get_settings_value(3), - 5 => $this->get_settings_value(5) - ); + 5 => $this->get_settings_value(5), + ]; return $options; } + /** + * Get default settings. + * + * @return array + * @throws \coding_exception + */ public function get_default_settings() { - return array( + return [ self::MAXNO => 3, 0 => get_string(self::STRATEGYID . '_rating_no', RATINGALLOCATE_MOD_NAME), 3 => get_string(self::STRATEGYID . '_rating_maybe', RATINGALLOCATE_MOD_NAME), 5 => get_string(self::STRATEGYID . '_rating_yes', RATINGALLOCATE_MOD_NAME), 'default' => 3, - ); + ]; } + /** + * Get validation info. + * + * @return array[] + */ protected function getvalidationinfo() { - return array(self::MAXNO => array(true, 0)); + return [self::MAXNO => [true, 0]]; } } // Register with the strategymanager. \strategymanager::add_strategy(strategy::STRATEGYID); +/** + * View form. + * + * @package mod_ratingallocate + */ class mod_ratingallocate_view_form extends \ratingallocate_options_strategyform { // Already specified by parent class. diff --git a/strategy/strategy03_lickert.php b/strategy/strategy03_lickert.php index cff271cc..28aa4093 100644 --- a/strategy/strategy03_lickert.php +++ b/strategy/strategy03_lickert.php @@ -33,11 +33,26 @@ require_once(dirname(__FILE__) . '/../locallib.php'); require_once(dirname(__FILE__) . '/strategy_template_options.php'); +/** + * Strategy + * + * @package mod_ratingallocate + */ class strategy extends \strategytemplate_options { + /** + * Strategyid. + */ const STRATEGYID = 'strategy_lickert'; + /** + * Max NO. + */ const MAXNO = 'maxno'; + /** + * Countlickert. + */ const COUNTLICKERT = 'countlickert'; + /** @var mixed $maxlickert */ private $maxlickert; public function __construct(array $strategysettings = null) { @@ -54,51 +69,62 @@ public function get_strategyid() { } public function get_static_settingfields() { - return array( - self::MAXNO => array(// Maximum count of 'No'. + return [ + self::MAXNO => [// Maximum count of 'No'. 'int', get_string(self::STRATEGYID . '_setting_maxno', RATINGALLOCATE_MOD_NAME), $this->get_settings_value(self::MAXNO), - null - ), - self::COUNTLICKERT => array(// How many fields there are. + null, + ], + self::COUNTLICKERT => [// How many fields there are. 'int', get_string(self::STRATEGYID . '_setting_maxlickert', RATINGALLOCATE_MOD_NAME), $this->get_settings_value(self::COUNTLICKERT), - null - ) - ); + null, + ], + ]; } public function get_dynamic_settingfields() { - $output = array(); + $output = []; foreach (array_keys($this->get_choiceoptions()) as $id) { - $output[$id] = array( + $output[$id] = [ 'text', get_string('strategy_settings_label', RATINGALLOCATE_MOD_NAME, $this->get_settings_default_value($id)), null, - $this->get_settings_default_value($id) - ); + $this->get_settings_default_value($id), + ]; } $output += $this->get_default_strategy_option(); return $output; } + /** + * Get choiceoptions. + * + * @return array + */ public function get_choiceoptions() { - $options = array(); + $options = []; for ($i = 0; $i <= $this->maxlickert; $i++) { $options[$i] = $this->get_settings_value($i); } return $options; } + /** + * Get default settings. + * + * @return array + * @throws \coding_exception + */ public function get_default_settings() { - $defaults = array( + $defaults = [ self::MAXNO => 3, self::COUNTLICKERT => 4, 0 => get_string(self::STRATEGYID . '_rating_exclude', RATINGALLOCATE_MOD_NAME, "0"), 'default' => $this->maxlickert, - ); + ]; for ($i = 1; $i <= $this->maxlickert; $i++) { if ($i == $this->maxlickert) { @@ -110,16 +136,26 @@ public function get_default_settings() { return $defaults; } + /** + * Get validation info. + * + * @return array[] + */ protected function getvalidationinfo() { - return array(self::MAXNO => array(true, 0), - self::COUNTLICKERT => array(true, 2) - ); + return [self::MAXNO => [true, 0], + self::COUNTLICKERT => [true, 2], + ]; } } // Register with the strategymanager. \strategymanager::add_strategy(strategy::STRATEGYID); +/** + * View form. + * + * @package mod_ratingallocate + */ class mod_ratingallocate_view_form extends \ratingallocate_options_strategyform { // Already specified by parent class. diff --git a/strategy/strategy04_points.php b/strategy/strategy04_points.php index 33b58249..2c94773b 100644 --- a/strategy/strategy04_points.php +++ b/strategy/strategy04_points.php @@ -34,11 +34,28 @@ require_once(dirname(__FILE__) . '/../locallib.php'); require_once(dirname(__FILE__) . '/strategy_template.php'); +/** + * Strategy + * + * @package mod_ratingallocate + */ class strategy extends \strategytemplate { + /** + * Strategyid. + */ const STRATEGYID = 'strategy_points'; + /** + * Max zero. + */ const MAXZERO = 'maxzero'; + /** + * Totalpoints. + */ const TOTALPOINTS = 'totalpoints'; + /** + * Max per choice. + */ const MAXPERCHOICE = 'maxperchoice'; public function get_strategyid() { @@ -46,45 +63,45 @@ public function get_strategyid() { } public function get_static_settingfields() { - return array( - self::MAXZERO => array( // Maximum count of 'No'. + return [ + self::MAXZERO => [ // Maximum count of 'No'. 'int', get_string(self::STRATEGYID . '_setting_maxzero', RATINGALLOCATE_MOD_NAME), $this->get_settings_value(self::MAXZERO), - null - ), - self::TOTALPOINTS => array( // Amount of fields. + null, + ], + self::TOTALPOINTS => [ // Amount of fields. 'int', get_string(self::STRATEGYID . '_setting_totalpoints', RATINGALLOCATE_MOD_NAME), $this->get_settings_value(self::TOTALPOINTS), - null - ), - self::MAXPERCHOICE => array( // Maximum amount of points the student can give per choice. + null, + ], + self::MAXPERCHOICE => [// Maximum amount of points the student can give per choice. 'int', get_string(self::STRATEGYID . '_setting_maxperchoice', RATINGALLOCATE_MOD_NAME), $this->get_settings_value(self::MAXPERCHOICE), - null - ) - ); + null, + ], + ]; } public function get_dynamic_settingfields() { - return array(); + return []; } public function get_default_settings() { - return array( + return [ self::MAXZERO => 3, self::TOTALPOINTS => 100, - self::MAXPERCHOICE => 100 - ); + self::MAXPERCHOICE => 100, + ]; } protected function getvalidationinfo() { - return array(self::MAXZERO => array(true, 0), - self::TOTALPOINTS => array(true, 1), - self::MAXPERCHOICE => array(true, 1) - ); + return [self::MAXZERO => [true, 0], + self::TOTALPOINTS => [true, 1], + self::MAXPERCHOICE => [true, 1], + ]; } } @@ -92,6 +109,11 @@ protected function getvalidationinfo() { // Register with the strategymanager. \strategymanager::add_strategy(strategy::STRATEGYID); +/** + * View form. + * + * @package mod_ratingallocate + */ class mod_ratingallocate_view_form extends \ratingallocate_strategyform { protected function construct_strategy($strategyoptions) { diff --git a/strategy/strategy05_order.php b/strategy/strategy05_order.php index 6abc6cc4..4c473caf 100644 --- a/strategy/strategy05_order.php +++ b/strategy/strategy05_order.php @@ -33,9 +33,20 @@ require_once(dirname(__FILE__) . '/../locallib.php'); require_once(dirname(__FILE__) . '/strategy_template.php'); +/** + * Strategy. + * + * @package mod_ratingallocate + */ class strategy extends \strategytemplate { + /** + * Strategyid. + */ const STRATEGYID = 'strategy_order'; + /** + * Countoptions. + */ const COUNTOPTIONS = 'countoptions'; public function get_strategyid() { @@ -43,25 +54,25 @@ public function get_strategyid() { } public function get_static_settingfields() { - return array( - self::COUNTOPTIONS => array(// Amount of fields. + return [ + self::COUNTOPTIONS => [// Amount of fields. 'int', get_string(self::STRATEGYID . '_setting_countoptions', RATINGALLOCATE_MOD_NAME), $this->get_settings_value(self::COUNTOPTIONS), - null - ) - ); + null, + ], + ]; } public function get_dynamic_settingfields() { - return array(); + return []; } public function get_default_settings() { $defaultcountoptions = 2; - $output = array( - self::COUNTOPTIONS => $defaultcountoptions - ); + $output = [ + self::COUNTOPTIONS => $defaultcountoptions, + ]; $countoptions = $this->get_settings_value(self::COUNTOPTIONS, false); if (is_null($countoptions)) { $countoptions = $defaultcountoptions; @@ -74,8 +85,7 @@ public function get_default_settings() { } protected function getvalidationinfo() { - return array(self::COUNTOPTIONS => array(true, 1) - ); + return [self::COUNTOPTIONS => [true, 1]]; } } @@ -107,7 +117,7 @@ public function definition() { // If we have less options because of group restrictions than configured for the strategy, // we have to limit it, because user cannot vote for one option multiple times. $choicecounter = min($this->get_strategysetting(strategy::COUNTOPTIONS), count($ratingdata)); - $choices = array(); + $choices = []; foreach ($ratingdata as $data) { $choices[$data->choiceid] = $data->title; @@ -159,7 +169,7 @@ 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), - '', array('disabled' => 'disabled')); + '', ['disabled' => 'disabled']); foreach ($choices as $id => $name) { $select->addOption($name, $id); } @@ -177,7 +187,7 @@ public function describe_strategy() { */ public function get_data() { $data = parent::get_data(); - $data->data = array(); + $data->data = []; // Necessary to initialize an empty entry for every choice to enable the deletion of ratings. $choices = $this->ratingallocate->get_rateable_choices(); @@ -199,7 +209,7 @@ public function get_data() { public function validation($data, $files) { $errors = parent::validation($data, $files); - $usedchoices = array(); + $usedchoices = []; // No data exists, so skip. if (!array_key_exists('choice', $data)) { diff --git a/strategy/strategy06_tickyes.php b/strategy/strategy06_tickyes.php index 23d243fb..eac7a8e2 100644 --- a/strategy/strategy06_tickyes.php +++ b/strategy/strategy06_tickyes.php @@ -34,10 +34,24 @@ require_once(dirname(__FILE__) . '/../locallib.php'); require_once(dirname(__FILE__) . '/strategy_template.php'); +/** + * Strategy. + * + * @package mod_ratingallocate + */ class strategy extends \strategytemplate { + /** + * Strategyid. + */ const STRATEGYID = 'strategy_tickyes'; + /** + * Min ticks for yes. + */ const MINTICKYES = 'mintickyes'; + /** + * Accept label. + */ const ACCEPT_LABEL = 'accept'; public function get_strategyid() { @@ -45,25 +59,24 @@ public function get_strategyid() { } public function get_static_settingfields() { - $output = array( - self::MINTICKYES => array('int', + $output = [ + self::MINTICKYES => ['int', get_string(self::STRATEGYID . '_setting_mintickyes', RATINGALLOCATE_MOD_NAME), - $this->get_settings_value(self::MINTICKYES) - ) - ); + $this->get_settings_value(self::MINTICKYES), + ], + ]; - $output[1] = array( + $output[1] = [ 'text', get_string('strategy_settings_label', RATINGALLOCATE_MOD_NAME, $this->get_settings_default_value(1)), null, - $this->get_settings_default_value(1) - - ); + $this->get_settings_default_value(1), + ]; return $output; } public function get_dynamic_settingfields() { - return array(); + return []; } public function get_accept_label() { @@ -71,16 +84,15 @@ public function get_accept_label() { } public function get_default_settings() { - return array( + return [ self::MINTICKYES => 3, 1 => get_string(self::STRATEGYID . '_' . self::ACCEPT_LABEL, RATINGALLOCATE_MOD_NAME), - 0 => get_string(self::STRATEGYID . '_not_' . self::ACCEPT_LABEL, RATINGALLOCATE_MOD_NAME) - ); + 0 => get_string(self::STRATEGYID . '_not_' . self::ACCEPT_LABEL, RATINGALLOCATE_MOD_NAME), + ]; } protected function getvalidationinfo() { - return array(self::MINTICKYES => array(true, 1) - ); + return [self::MINTICKYES => [true, 1]]; } } @@ -131,7 +143,7 @@ public function definition() { // 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, array(0, 1)); + $this->get_strategy()->get_accept_label(), null, [0, 1]); $mform->setType($ratingelem, PARAM_INT); if (is_numeric($data->rating) && $data->rating >= 0) { diff --git a/strategy/strategy_template.php b/strategy/strategy_template.php index 24caa823..9337c9a9 100644 --- a/strategy/strategy_template.php +++ b/strategy/strategy_template.php @@ -14,8 +14,6 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -defined('MOODLE_INTERNAL') || die(); - /** * Internal library of functions for module ratingallocate * @@ -27,20 +25,30 @@ * @copyright based on code by M Schulze copyright (C) 2014 M Schulze * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ + +defined('MOODLE_INTERNAL') || die(); + require_once($CFG->libdir . '/formslib.php'); /** * Template for Strategies, which present the interface in which the user votes * @copyright 2014 M Schulze * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @package mod_ratingallocate */ abstract class strategytemplate { - /** @const STRATEGYID string identifier, for language translation, etc. */ + /** STRATEGYID string identifier, for language translation, etc. */ const STRATEGYID = ''; + /** @var array|null $_strategy_settings */ private $_strategy_settings; + /** + * Construct. + * + * @param array|null $strategysettings + */ public function __construct(array $strategysettings = null) { $this->_strategy_settings = $strategysettings; } @@ -112,6 +120,11 @@ public function get_strategyname() { return get_string($this->get_strategyid() . '_name', RATINGALLOCATE_MOD_NAME); } + /** + * Get strategyid. + * + * @return mixed + */ abstract public function get_strategyid(); /** @@ -122,7 +135,7 @@ abstract public function get_strategyid(); * @return array of rating titles */ public function translate_ratings_to_titles(array $ratings) { - $result = array(); + $result = []; foreach ($ratings as $id => $rating) { $result[$rating] = $this->translate_rating_to_titles($rating); } @@ -149,7 +162,7 @@ public function translate_rating_to_titles($rating) { */ public function validate_settings() { $validationinfo = $this->getValidationInfo(); - $errors = array(); + $errors = []; foreach ($validationinfo as $key => $info) { if (isset($info[0]) && $info[0] === true) { if (array_key_exists($key, $this->_strategy_settings) && @@ -175,6 +188,8 @@ public function validate_settings() { } /** + * Get validation info. + * * @return array of arrays: key - identifier of setting_dependenc * value[0] - is setting required * value[1] - min value of setting (if numeric) @@ -187,13 +202,16 @@ abstract protected function getvalidationinfo(); * Form that asks users to express their ratings for choices * @copyright 2014 M Schulze * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @package mod_ratingallocate */ abstract class ratingallocate_strategyform extends \moodleform { /** @var \ratingallocate pointer to the parent \ratingallocate object */ protected $ratingallocate; + /** @var array|mixed $strategyoptions */ private $strategyoptions; + /** @var strategytemplate $strategy */ private $strategy; /** @@ -209,7 +227,7 @@ public function __construct($url, \ratingallocate $ratingallocate) { if (array_key_exists($strategyid, $allstrategyoptions)) { $this->strategyoptions = $allstrategyoptions[$strategyid]; } else { - $this->strategyoptions = array(); + $this->strategyoptions = []; } $this->strategy = $this->construct_strategy($this->strategyoptions); parent::__construct($url); @@ -222,6 +240,8 @@ public function __construct($url, \ratingallocate $ratingallocate) { abstract protected function construct_strategy($strategyoptions); /** + * Get strategy. + * * @return \strategytemplate Returns the underlying strategy object. */ protected function get_strategy() { @@ -268,7 +288,7 @@ protected function get_strategyname() { /** * returns strategy specific option for a strategy * @param string $key - * @returns the specific option or null if it does not exist + * @return the specific option or null if it does not exist */ protected function get_strategysetting($key) { if (array_key_exists($key, $this->strategyoptions)) { diff --git a/strategy/strategy_template_options.php b/strategy/strategy_template_options.php index d8c50b64..d97f1773 100644 --- a/strategy/strategy_template_options.php +++ b/strategy/strategy_template_options.php @@ -30,6 +30,11 @@ require_once(dirname(__FILE__) . '/../locallib.php'); require_once(dirname(__FILE__) . '/strategy_template.php'); +/** + * Strategytemplate options. + * + * @package mod_ratingallocate + */ abstract class strategytemplate_options extends \strategytemplate { /** @@ -43,13 +48,13 @@ abstract public function get_choiceoptions(); * @return array */ protected function get_default_strategy_option() { - return ['default' => array( + return ['default' => [ 'select', get_string('strategy_settings_default', RATINGALLOCATE_MOD_NAME), $this->get_settings_value('default'), $this->get_choiceoptions(), - 'strategy_settings_default' - )]; + 'strategy_settings_default', + ]]; } } @@ -97,7 +102,7 @@ public function definition() { // Options for each choice. $choiceoptions = $this->get_choiceoptions(); - $radioarray = array(); + $radioarray = []; foreach ($choiceoptions as $id => $option) { $radioarray[] =& $mform->createElement('radio', $ratingelem, '', $option, $id); } diff --git a/tests/backup_restore_test.php b/tests/backup_restore_test.php index 5e91b123..aa0f9526 100644 --- a/tests/backup_restore_test.php +++ b/tests/backup_restore_test.php @@ -74,25 +74,25 @@ public function test_backup_restore() { $unsetvalues = function($elem1, $elem2, $varname) { $this->assertNotEquals($elem1->{$varname}, $elem2->{$varname}); - $result = array($elem1->{$varname}, $elem2->{$varname}); + $result = [$elem1->{$varname}, $elem2->{$varname}]; unset($elem1->{$varname}); unset($elem2->{$varname}); return $result; }; $ratingallocate1 = $DB->get_record(this_db\ratingallocate::TABLE, - array(this_db\ratingallocate::COURSE => $course1->id)); + [this_db\ratingallocate::COURSE => $course1->id]); $ratingallocate2 = $DB->get_record(this_db\ratingallocate::TABLE, - array(this_db\ratingallocate::COURSE => $course2->id)); + [this_db\ratingallocate::COURSE => $course2->id]); list($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, - array(this_db\ratingallocate_choices::RATINGALLOCATEID => $ratingid1), + [this_db\ratingallocate_choices::RATINGALLOCATEID => $ratingid1], this_db\ratingallocate_choices::TITLE); $choices2 = $DB->get_records(this_db\ratingallocate_choices::TABLE, - array(this_db\ratingallocate_choices::RATINGALLOCATEID => $ratingid2), + [this_db\ratingallocate_choices::RATINGALLOCATEID => $ratingid2], this_db\ratingallocate_choices::TITLE); $this->assertCount(2, $choices1); $this->assertCount(2, array_values($choices2)); @@ -106,10 +106,10 @@ public function test_backup_restore() { $this->assertEquals($choice1, $choice2); // Compare ratings for this choice. $ratings1 = array_values($DB->get_records(this_db\ratingallocate_ratings::TABLE, - array(this_db\ratingallocate_ratings::CHOICEID => $choiceid1), + [this_db\ratingallocate_ratings::CHOICEID => $choiceid1], this_db\ratingallocate_ratings::USERID)); $ratings2 = array_values($DB->get_records(this_db\ratingallocate_ratings::TABLE, - array(this_db\ratingallocate_ratings::CHOICEID => $choiceid2), + [this_db\ratingallocate_ratings::CHOICEID => $choiceid2], this_db\ratingallocate_ratings::USERID)); $this->assertEquals(count($ratings1), count($ratings2)); $ratings2copy = $ratings2; @@ -124,10 +124,10 @@ public function test_backup_restore() { // Compare allocations. $allocations1 = $DB->get_records(this_db\ratingallocate_allocations::TABLE, - array(this_db\ratingallocate_allocations::RATINGALLOCATEID => $ratingid1), + [this_db\ratingallocate_allocations::RATINGALLOCATEID => $ratingid1], this_db\ratingallocate_allocations::USERID); $allocations2 = $DB->get_records(this_db\ratingallocate_allocations::TABLE, - array(this_db\ratingallocate_allocations::RATINGALLOCATEID => $ratingid2), + [this_db\ratingallocate_allocations::RATINGALLOCATEID => $ratingid2], this_db\ratingallocate_allocations::USERID); // Number of allocations is equal. $this->assertCount(count($genmod->allocations), $allocations2); diff --git a/tests/behat/behat_mod_ratingallocate.php b/tests/behat/behat_mod_ratingallocate.php index b5800c39..ad0af1fb 100644 --- a/tests/behat/behat_mod_ratingallocate.php +++ b/tests/behat/behat_mod_ratingallocate.php @@ -27,6 +27,13 @@ Behat\Mink\Exception\ExpectationException as ExpectationException, Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException; +/** + * Class for Behat tests + * + * @copyright 2014 Tobias Reischmann + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @package mod_ratingallocate + */ class behat_mod_ratingallocate extends behat_base { /** @@ -58,7 +65,7 @@ public function the_following_choices_exist(TableNode $data) { 'ratingallocate must be present in behat_mod_ratingallocate::the_following_choices_exist() $data'); } - $ratingallocate = $DB->get_record('ratingallocate', array('name' => $record['ratingallocate'])); + $ratingallocate = $DB->get_record('ratingallocate', ['name' => $record['ratingallocate']]); $record['ratingallocateid'] = $ratingallocate->id; @@ -99,8 +106,8 @@ public function the_following_ratings_exist(TableNode $data) { 'rating must be present in behat_mod_ratingallocate::the_following_ratings_exist() $data'); } - $user = $DB->get_record('user', array('username' => $record['user'])); - $choice = $DB->get_record('ratingallocate_choices', array('title' => $record['choice'])); + $user = $DB->get_record('user', ['username' => $record['user']]); + $choice = $DB->get_record('ratingallocate_choices', ['title' => $record['choice']]); $record['userid'] = $user->id; $record['choiceid'] = $choice->id; @@ -131,7 +138,7 @@ public function i_set_the_values_of_the_choice_to(TableNode $choicedata) { $this->execute('behat_mod_ratingallocate::i_uncheck_the_active_checkbox'); } } else { - $this->execute('behat_forms::i_set_the_field_to', array($locator, $value)); + $this->execute('behat_forms::i_set_the_field_to', [$locator, $value]); } } } @@ -146,7 +153,7 @@ public function i_set_the_values_of_the_choice_to(TableNode $choicedata) { public function i_add_a_new_choice_with_the_values(TableNode $choicedata) { $this->i_add_a_new_choice(); $this->i_set_the_values_of_the_choice_to($choicedata); - $this->execute('behat_forms::press_button', array("id_submitbutton")); + $this->execute('behat_forms::press_button', ["id_submitbutton"]); } /** @@ -161,9 +168,9 @@ public function i_add_new_choices_with_the_values(TableNode $choicedata) { $this->i_add_a_new_choice(); $choicedatahash = $choicedata->getHash(); foreach ($choicedatahash as $entry) { - $newrows = array(); + $newrows = []; foreach ($entry as $key => $val) { - array_push($newrows, array($key, $val)); + array_push($newrows, [$key, $val]); } // TODO: Ensure backward-compatibility after changed TableNode constructor in Moodle 3.1. if ($CFG->version < 2016052300) { @@ -174,7 +181,7 @@ public function i_add_new_choices_with_the_values(TableNode $choicedata) { $this->i_add_a_next_choice(); } - $this->execute('behat_forms::press_button', array("id_cancel")); + $this->execute('behat_forms::press_button', ["id_cancel"]); } /** @@ -189,7 +196,7 @@ public function i_delete_the_choice_with_the_title($choicetitle) { "//following-sibling::td/a[@title='Delete choice']"; $link = $this->find('xpath', $fieldxpath); $link->click(); - $this->execute('behat_general::i_click_on', array("Yes", "button")); + $this->execute('behat_general::i_click_on', ["Yes", "button"]); } /** @@ -204,8 +211,8 @@ public function i_delete_the_choice_with_the_title($choicetitle) { */ public function i_should_see_assigned_to($firstname, $choicetitle) { global $DB; - $choice = $DB->get_record('ratingallocate_choices', array('title' => $choicetitle)); - $user = $DB->get_record('user', array('firstname' => $firstname)); + $choice = $DB->get_record('ratingallocate_choices', ['title' => $choicetitle]); + $user = $DB->get_record('user', ['firstname' => $firstname]); $fieldxpath = "//table[contains(concat(\" \", normalize-space(@class), \" \"), \" ratingallocate_ratings_table \")]"; $fieldxpath .= "//td//input[@id='user_{$user->id}_alloc_{$choice->id}' and @checked]"; @@ -229,8 +236,8 @@ public function i_should_see_assigned_to($firstname, $choicetitle) { */ public function i_should_see_not_assigned_to($firstname, $choicetitle) { global $DB; - $choice = $DB->get_record('ratingallocate_choices', array('title' => $choicetitle)); - $user = $DB->get_record('user', array('firstname' => $firstname)); + $choice = $DB->get_record('ratingallocate_choices', ['title' => $choicetitle]); + $user = $DB->get_record('user', ['firstname' => $firstname]); $fieldxpath = "//table[contains(concat(\" \", normalize-space(@class), \" \"), \" ratingallocate_ratings_table \")]"; $checkbox = $fieldxpath . "//td//input[@id='user_{$user->id}_alloc_{$choice->id}']"; @@ -262,8 +269,8 @@ public function i_should_see_not_assigned_to($firstname, $choicetitle) { public function i_assign_to_choice($firstname, $choicetitle) { global $DB; - $choice = $DB->get_record('ratingallocate_choices', array('title' => $choicetitle)); - $user = $DB->get_record('user', array('firstname' => $firstname)); + $choice = $DB->get_record('ratingallocate_choices', ['title' => $choicetitle]); + $user = $DB->get_record('user', ['firstname' => $firstname]); $fieldxpath = "//input[@name='allocdata[{$user->id}]']"; $elements = $this->find_all('xpath', $fieldxpath); @@ -333,7 +340,7 @@ public function i_set_the_choice_with_the_title_to_active($choicetitle) { * @Given /^I add a new choice$/ */ public function i_add_a_new_choice() { - $this->execute("behat_forms::press_button", array(get_string('newchoice', "ratingallocate"))); + $this->execute("behat_forms::press_button", [get_string('newchoice', "ratingallocate")]); } /** @@ -342,7 +349,7 @@ public function i_add_a_new_choice() { * @Given /^I add a next choice$/ */ public function i_add_a_next_choice() { - $this->execute("behat_forms::press_button", array("id_submitbutton2")); + $this->execute("behat_forms::press_button", ["id_submitbutton2"]); } /** @@ -417,6 +424,8 @@ public function the_choice_should_have_explanation_equal($title, $value) { } /** + * User should have ratings. + * * @Then the user :useridentifier should have ratings * * @param string $username username of a user. @@ -432,6 +441,8 @@ public function the_user_should_have_ratings($username) { } /** + * User should not have ratings. + * * @Then the user :useridentifier should not have ratings * * @param string $username username of a user. @@ -455,7 +466,7 @@ public function the_user_should_not_have_ratings($username) { private function get_ratings_for_username($username) { global $DB; $user = \core_user::get_user_by_username($username); - return $DB->get_records("ratingallocate_ratings", array('userid' => $user->id)); + return $DB->get_records("ratingallocate_ratings", ['userid' => $user->id]); } /** @@ -486,7 +497,7 @@ public function the_choice_should_have_maxsize_equal($title, $value) { */ private function get_choice($title) { global $DB; - $choices = $DB->get_records("ratingallocate_choices", array('title' => $title)); + $choices = $DB->get_records("ratingallocate_choices", ['title' => $title]); if (count($choices) != 1) { throw new ExpectationException('Excatly one choice with the name "' . $title . '" is expected but ' . count($choices) . ' found.', $this->getSession()); @@ -572,6 +583,59 @@ public function i_rate_choices_with_the_following_points(TableNode $ratingdata) } } + /** + * Adds a new ratingallocate to the specified course and section and fills the form with values. + * + * @Given I add a ratingallocate to course :coursefullname section :sectionnum and I fill the form with: + * @param $courseshortname + * @param $sectionnumber + * @param $data + * @return void + */ + public function i_add_a_ratingallocate_to_course_section_and_fill_form($courseshortname, $sectionnumber, TableNode $data) { + global $CFG; + + if ($CFG->branch >= 404) { + $this->execute( + "behat_course::i_add_to_course_section_and_i_fill_the_form_with", + [$this->escape('ratingallocate'), $this->escape($courseshortname), $this->escape($sectionnumber), $data] + ); + } else { + // This is the code from the deprecated behat function "i_add_to_section_and_i_fill_the_form_with". + // Add activity to section and fill form. + $this->execute( + "behat_course::i_add_to_section_and_i_fill_the_form_with", + [$this->escape('Fair Allocation'), $this->escape($sectionnumber), $data] + ); + } + } + + /** + * Adds a new ratingallocate to the specified course and section. + * + * @Given I add a ratingallocate to course :coursefullname section :sectionnum + * @param $courseshortname + * @param $sectionnumber + * @return void + */ + public function i_add_a_ratingallocate_to_course_section($courseshortname, $sectionnumber) { + global $CFG; + + if ($CFG->branch >= 404) { + $this->execute( + "behat_course::i_add_to_course_section", + [$this->escape('ratingallocate'), $this->escape($courseshortname), $this->escape($sectionnumber)] + ); + } else { + // This is the code from the deprecated behat function "i_add_to_section". + // Add activity to section: + $this->execute( + "behat_course::i_add_to_section", + [$this->escape('Fair Allocation'), $this->escape($sectionnumber)] + ); + } + } + /** * Convert page names to URLs for steps like 'When I am on the "mod_ratingallocate > [page name]" page'. * @@ -617,13 +681,13 @@ protected function resolve_page_instance_url(string $type, string $identifier): case 'choices': return new moodle_url('/mod/ratingallocate/view.php', [ - 'id' => $this->get_cm_by_ratingallocate_name($identifier)->id, 'action' => ACTION_SHOW_CHOICES + 'id' => $this->get_cm_by_ratingallocate_name($identifier)->id, 'action' => ACTION_SHOW_CHOICES, ]); case 'reports': return new moodle_url('/mod/ratingallocate/view.php', [ 'id' => $this->get_cm_by_ratingallocate_name($identifier)->id, - 'action' => ACTION_SHOW_RATINGS_AND_ALLOCATION_TABLE + 'action' => ACTION_SHOW_RATINGS_AND_ALLOCATION_TABLE, ]); default: diff --git a/tests/behat/mod_form.feature b/tests/behat/mod_form.feature index 0b6a6585..7955b023 100644 --- a/tests/behat/mod_form.feature +++ b/tests/behat/mod_form.feature @@ -16,7 +16,7 @@ Feature: Creating a new rating allocation, where new choices need to | student1 | C1 | student | And I log in as "teacher1" And I am on "Course 1" course homepage with editing mode on - And I add a "Fair Allocation" to section "0" and I fill the form with: + And I add a ratingallocate to course "Course 1" section "0" and I fill the form with: | id_name | My Fair Allocation | And I am on the "My Fair Allocation" "mod_ratingallocate > Choices" page And I add a new choice with the values: diff --git a/tests/behat/select_strategy.feature b/tests/behat/select_strategy.feature index 82bfd2fb..18379847 100644 --- a/tests/behat/select_strategy.feature +++ b/tests/behat/select_strategy.feature @@ -4,16 +4,16 @@ Feature: When a teacher selects a strategy the appropriate options are displayed Background: Given the following "courses" exist: | fullname | shortname | category | groupmode | - | Course 1 | C1 | 0 | 1 | + | Course 1 | CO1 | 0 | 1 | And the following "users" exist: | username | firstname | lastname | email | | teacher1 | Teacher | 1 | teacher1@example.com | And the following "course enrolments" exist: | user | course | role | - | teacher1 | C1 | editingteacher | + | teacher1 | CO1 | editingteacher | And I log in as "teacher1" And I am on "Course 1" course homepage with editing mode on - And I add a "Fair Allocation" to section "1" + And I add a ratingallocate to course "Course 1" section "1" @javascript Scenario: The correct options are displayed for the default strategy (Yes-No) diff --git a/tests/behat/validate_rating.feature b/tests/behat/validate_rating.feature index e680a12d..94997977 100644 --- a/tests/behat/validate_rating.feature +++ b/tests/behat/validate_rating.feature @@ -15,7 +15,7 @@ Feature: When a student attempts to rate choices it should be validated prior to | student1 | C1 | student | And I log in as "teacher1" And I am on "Course 1" course homepage with editing mode on - And I add a "Fair Allocation" to section "1" and I fill the form with: + And I add a ratingallocate to course "Course 1" section "1" and I fill the form with: | id_name | Validated Rating | | strategy | strategy_points | | Rating begins at | ##2 days ago## | diff --git a/tests/cron_test.php b/tests/cron_test.php index 6be4c450..e754ed23 100644 --- a/tests/cron_test.php +++ b/tests/cron_test.php @@ -37,7 +37,9 @@ */ class cron_test extends \advanced_testcase { + /** @var $teacher */ private $teacher; + /** @var $mod */ private $mod; // @@ -123,11 +125,11 @@ private function run_cron() { */ private function assert_not_started() { global $DB; - $record = $DB->get_record(this_db\ratingallocate::TABLE, array()); + $record = $DB->get_record(this_db\ratingallocate::TABLE, []); $ratingallocate = \mod_ratingallocate_generator::get_ratingallocate_for_user($this, $record, $this->teacher); $this->assertEquals(\mod_ratingallocate\algorithm_status::NOTSTARTED, $ratingallocate->get_algorithm_status()); $this->assertEquals(0, $DB->count_records(this_db\ratingallocate_allocations::TABLE, - array(this_db\ratingallocate_allocations::RATINGALLOCATEID => $this->mod->id))); + [this_db\ratingallocate_allocations::RATINGALLOCATEID => $this->mod->id])); } /** @@ -135,11 +137,11 @@ private function assert_not_started() { */ private function assert_running() { global $DB; - $record = $DB->get_record(this_db\ratingallocate::TABLE, array()); + $record = $DB->get_record(this_db\ratingallocate::TABLE, []); $ratingallocate = \mod_ratingallocate_generator::get_ratingallocate_for_user($this, $record, $this->teacher); $this->assertEquals(\mod_ratingallocate\algorithm_status::RUNNING, $ratingallocate->get_algorithm_status()); $this->assertEquals(0, $DB->count_records(this_db\ratingallocate_allocations::TABLE, - array(this_db\ratingallocate_allocations::RATINGALLOCATEID => $this->mod->id))); + [this_db\ratingallocate_allocations::RATINGALLOCATEID => $this->mod->id])); } /** @@ -147,11 +149,11 @@ private function assert_running() { */ private function assert_failure() { global $DB; - $record = $DB->get_record(this_db\ratingallocate::TABLE, array()); + $record = $DB->get_record(this_db\ratingallocate::TABLE, []); $ratingallocate = \mod_ratingallocate_generator::get_ratingallocate_for_user($this, $record, $this->teacher); $this->assertEquals(\mod_ratingallocate\algorithm_status::FAILURE, $ratingallocate->get_algorithm_status()); $this->assertEquals(0, $DB->count_records(this_db\ratingallocate_allocations::TABLE, - array(this_db\ratingallocate_allocations::RATINGALLOCATEID => $this->mod->id))); + [this_db\ratingallocate_allocations::RATINGALLOCATEID => $this->mod->id])); } /** @@ -159,11 +161,11 @@ private function assert_failure() { */ private function assert_finish() { global $DB; - $record = $DB->get_record(this_db\ratingallocate::TABLE, array()); + $record = $DB->get_record(this_db\ratingallocate::TABLE, []); $ratingallocate = \mod_ratingallocate_generator::get_ratingallocate_for_user($this, $record, $this->teacher); $this->assertEquals(\mod_ratingallocate\algorithm_status::FINISHED, $ratingallocate->get_algorithm_status()); $this->assertEquals(4, $DB->count_records(this_db\ratingallocate_allocations::TABLE, - array(this_db\ratingallocate_allocations::RATINGALLOCATEID => $this->mod->id))); + [this_db\ratingallocate_allocations::RATINGALLOCATEID => $this->mod->id])); } /** @@ -171,11 +173,11 @@ private function assert_finish() { */ private function assert_already_finish() { global $DB; - $record = $DB->get_record(this_db\ratingallocate::TABLE, array()); + $record = $DB->get_record(this_db\ratingallocate::TABLE, []); $ratingallocate = \mod_ratingallocate_generator::get_ratingallocate_for_user($this, $record, $this->teacher); $this->assertEquals(\mod_ratingallocate\algorithm_status::FINISHED, $ratingallocate->get_algorithm_status()); $this->assertEquals(0, $DB->count_records(this_db\ratingallocate_allocations::TABLE, - array(this_db\ratingallocate_allocations::RATINGALLOCATEID => $this->mod->id))); + [this_db\ratingallocate_allocations::RATINGALLOCATEID => $this->mod->id])); } /** @@ -197,8 +199,8 @@ private function create_ratingallocate($ratingperiodended, // There should not be any module for that course first. $this->assertFalse( - $DB->record_exists(this_db\ratingallocate::TABLE, array(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. @@ -217,7 +219,7 @@ 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, - array(this_db\ratingallocate_choices::RATINGALLOCATEID => $this->mod->id))); + [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); @@ -231,11 +233,11 @@ private function create_ratingallocate($ratingperiodended, $choice2 = end($choices); // Create preferences. - $prefersnon = array(); + $prefersnon = []; foreach ($choices as $choice) { - $prefersnon[$choice->{this_db\ratingallocate_choices::ID}] = array( + $prefersnon[$choice->{this_db\ratingallocate_choices::ID}] = [ this_db\ratingallocate_ratings::CHOICEID => $choice->{this_db\ratingallocate_choices::ID}, - this_db\ratingallocate_ratings::RATING => 0); + this_db\ratingallocate_ratings::RATING => 0]; } $prefersfirst = json_decode(json_encode($prefersnon), true); $prefersfirst[$choice1->{this_db\ratingallocate_choices::ID}][this_db\ratingallocate_ratings::RATING] = true; @@ -249,7 +251,7 @@ private function create_ratingallocate($ratingperiodended, \mod_ratingallocate_generator::save_rating_for_user($this, $this->mod, $student4, $preferssecond); $this->assertEquals(0, $DB->count_records(this_db\ratingallocate_allocations::TABLE, - array(this_db\ratingallocate_allocations::RATINGALLOCATEID => $this->mod->id))); + [this_db\ratingallocate_allocations::RATINGALLOCATEID => $this->mod->id])); } // diff --git a/tests/generator/lib.php b/tests/generator/lib.php index b195d634..a7e8df3b 100644 --- a/tests/generator/lib.php +++ b/tests/generator/lib.php @@ -14,6 +14,14 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +/** + * Library for Tests + * + * @package mod_ratingallocate + * @copyright usener + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + defined('MOODLE_INTERNAL') || die(); require_once(dirname(__FILE__) . '/../../locallib.php'); @@ -72,37 +80,39 @@ public static function create_instance_with_choices(advanced_testcase $tc, $modu public static function get_default_values() { if (empty(self::$defaultvalue)) { - self::$defaultvalue = array( + self::$defaultvalue = [ 'name' => 'Rating Allocation', 'accesstimestart' => time() + (0 * 24 * 60 * 60), 'accesstimestop' => time() + (6 * 24 * 60 * 60), 'publishdate' => time() + (7 * 24 * 60 * 60), - 'strategyopt' => array('strategy_yesno' => array('maxcrossout' => '1')), + 'strategyopt' => ['strategy_yesno' => ['maxcrossout' => '1']], 'strategy' => 'strategy_yesno', - ); + ]; } return self::$defaultvalue; } + /** @var $defaultvalue */ private static $defaultvalue; public static function get_default_choice_data() { if (empty(self::$defaultchoicedata)) { - self::$defaultchoicedata = array( - array('title' => 'Choice 1', + self::$defaultchoicedata = [ + ['title' => 'Choice 1', 'explanation' => 'Some explanatory text for choice 1', 'maxsize' => '10', - 'active' => true), - array('title' => 'Choice 2', + 'active' => true], + ['title' => 'Choice 2', 'explanation' => 'Some explanatory text for choice 2', 'maxsize' => '5', - 'active' => false - ) - ); + 'active' => false, + ], + ]; } return self::$defaultchoicedata; } + /** @var $defaultchoicedata */ private static $defaultchoicedata; /** @@ -121,8 +131,8 @@ public static function create_user_and_enrol(advanced_testcase $tc, $course, $is global $DB; // Enrol teacher and student. self::$teacherrole = $DB->get_record('role', - array('shortname' => 'editingteacher' - )); + ['shortname' => 'editingteacher', + ]); } $enroled = $tc->getDataGenerator()->enrol_user($user->id, $course->id, self::$teacherrole->id); @@ -133,6 +143,7 @@ public static function create_user_and_enrol(advanced_testcase $tc, $course, $is return $user; } + /** @var $teacherrole */ private static $teacherrole; /** @@ -210,13 +221,25 @@ public static function get_small_ratingallocate_for_filter_tests(advanced_testca } } +/** + * Generated Module. + * + * @package mod_ratingallocate + */ class mod_ratingallocate_generated_module { + /** @var stdClass $moddb */ public $moddb; + /** @var stdClass $teacher */ public $teacher; - public $students = array(); + /** @var array $students */ + public $students = []; + /** @var mixed|stdClass $course */ public $course; + /** @var array|mixed $ratings */ public $ratings; + /** @var array $choices */ public $choices; + /** @var array $allocations */ public $allocations; /** @@ -234,7 +257,7 @@ public function __construct(advanced_testcase $tc, $moduledata = null, $choiceda $tc->setAdminUser(); if (is_null($moduledata)) { - $moduledata = array(); + $moduledata = []; } else if (!is_array($moduledata)) { $tc->fail('$moduledata must be null or an array'); } @@ -249,8 +272,8 @@ public function __construct(advanced_testcase $tc, $moduledata = null, $choiceda if ($assertintermediateresult) { $tc->assertFalse( $DB->record_exists(this_db\ratingallocate::TABLE, - array(this_db\ratingallocate::COURSE => $this->course->id - )), 'There should not be any module for that course first'); + [this_db\ratingallocate::COURSE => $this->course->id, + ]), 'There should not be any module for that course first'); } // Create activity. @@ -265,14 +288,14 @@ public function __construct(advanced_testcase $tc, $moduledata = null, $choiceda foreach ($ratings as $userid => $rating) { $choices = $ratingallocate->get_choices(); $user = get_complete_user_data('id', $userid); - $ratingdata = array(); + $ratingdata = []; foreach ($rating as $singlerating) { foreach ($choices as $choice) { if ($choice->title == $singlerating['choice']) { - $ratingdata[] = array( + $ratingdata[] = [ 'rating' => $singlerating['rating'], - 'choiceid' => $choice->id - ); + 'choiceid' => $choice->id, + ]; } } } @@ -289,7 +312,7 @@ public function __construct(advanced_testcase $tc, $moduledata = null, $choiceda // Assert number of choices is correct. $numberofrecords = $DB->count_records(this_db\ratingallocate_choices::TABLE, - array(this_db\ratingallocate_choices::RATINGALLOCATEID => $this->moddb->id)); + [this_db\ratingallocate_choices::RATINGALLOCATEID => $this->moddb->id]); $tc->assertEquals(2, $numberofrecords); // Load choices. @@ -299,23 +322,23 @@ public function __construct(advanced_testcase $tc, $moduledata = null, $choiceda // Create students' preferences as array. if (!array_key_exists('ratings', $moduledata)) { - $moduledata['ratings'] = array(); + $moduledata['ratings'] = []; for ($i = 0; $i < $numstudents; $i++) { - $moduledata['ratings'][$i] = array( - $choicesnummerated[$i % $numchoices]->{this_db\ratingallocate_choices::TITLE} => 1 - ); + $moduledata['ratings'][$i] = [ + $choicesnummerated[$i % $numchoices]->{this_db\ratingallocate_choices::TITLE} => 1, + ]; } } $this->ratings = $moduledata['ratings']; // Create preferences. - $prefersnon = array(); - $choiceidbytitle = array(); + $prefersnon = []; + $choiceidbytitle = []; foreach ($choices as $choice) { - $prefersnon[$choice->{this_db\ratingallocate_choices::ID}] = array( + $prefersnon[$choice->{this_db\ratingallocate_choices::ID}] = [ this_db\ratingallocate_ratings::CHOICEID => $choice->{this_db\ratingallocate_choices::ID}, - this_db\ratingallocate_ratings::RATING => 0 - ); + this_db\ratingallocate_ratings::RATING => 0, + ]; $choiceidbytitle[$choice->{this_db\ratingallocate_choices::TITLE}] = $choice->{this_db\ratingallocate_choices::ID}; } @@ -336,7 +359,7 @@ public function __construct(advanced_testcase $tc, $moduledata = null, $choiceda $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 = array(); + $savedratingarr = []; foreach ($savedratings as $savedrating) { if (!$savedrating->{this_db\ratingallocate_ratings::RATING} == 0) { $savedratingarr[$savedrating->{this_db\ratingallocate_choices::TITLE}] = diff --git a/tests/locallib_test.php b/tests/locallib_test.php index a6322f5e..7a97e920 100644 --- a/tests/locallib_test.php +++ b/tests/locallib_test.php @@ -48,7 +48,7 @@ public function test_simple() { // There should not be any module for that course first. $this->assertFalse( $DB->record_exists(this_db\ratingallocate::TABLE, - array(this_db\ratingallocate::COURSE => $course->id) + [this_db\ratingallocate::COURSE => $course->id] ) ); @@ -66,7 +66,7 @@ public function test_simple() { // 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(",", array(this_db\ratingallocate_choices::ID => $mod->id))); + "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); @@ -80,11 +80,11 @@ public function test_simple() { $choice2 = end($choices); // Create preferences. - $prefersnon = array(); + $prefersnon = []; foreach ($choices as $choice) { - $prefersnon[$choice->{this_db\ratingallocate_choices::ID}] = array( + $prefersnon[$choice->{this_db\ratingallocate_choices::ID}] = [ this_db\ratingallocate_ratings::CHOICEID => $choice->{this_db\ratingallocate_choices::ID}, - this_db\ratingallocate_ratings::RATING => 0); + this_db\ratingallocate_ratings::RATING => 0]; } $prefersfirst = json_decode(json_encode($prefersnon), true); $prefersfirst[$choice1->{this_db\ratingallocate_choices::ID}][this_db\ratingallocate_ratings::RATING] = true; @@ -111,7 +111,7 @@ public function test_simple() { $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, - array(this_db\ratingallocate_allocations::RATINGALLOCATEID => $mod->{this_db\ratingallocate::ID}), + [this_db\ratingallocate_allocations::RATINGALLOCATEID => $mod->{this_db\ratingallocate::ID}], ''); $mapuserid = function($elem) { @@ -167,8 +167,8 @@ public function test_get_ratable_choices() { * Test if option titles are returned according to the default values */ public function test_get_option_titles_default() { - $expectedresult = array(1 => 'Accept', 0 => 'Deny'); // Depends on language file. - $ratings = array(0, 1, 1, 1, 0); + $expectedresult = [1 => 'Accept', 0 => 'Deny']; // Depends on language file. + $ratings = [0, 1, 1, 1, 0]; $record = \mod_ratingallocate_generator::get_default_values(); $testmodule = new \mod_ratingallocate_generated_module($this, $record); @@ -183,8 +183,8 @@ public function test_get_option_titles_default() { * Test if option titles are returned according to defined custom values */ public function test_get_option_titles_custom() { - $expectedresult = array(1 => 'Ja1234', 0 => 'Nein1234'); // Test data. - $ratings = array(1, 1, 1, 0, 1, 1); + $expectedresult = [1 => 'Ja1234', 0 => 'Nein1234']; // Test data. + $ratings = [1, 1, 1, 0, 1, 1]; $record = \mod_ratingallocate_generator::get_default_values(); $record['strategyopt']['strategy_yesno'] = $expectedresult; @@ -200,8 +200,8 @@ public function test_get_option_titles_custom() { * Test if option titles are returned according to defined custom values, if ratings consist of just one rating */ public function test_get_option_titles_custom1() { - $expectedresult = array(1 => 'Ja1234'); // Test data. - $ratings = array(1, 1, 1, 1, 1); + $expectedresult = [1 => 'Ja1234']; // Test data. + $ratings = [1, 1, 1, 1, 1]; $record = \mod_ratingallocate_generator::get_default_values(); $record['strategyopt']['strategy_yesno'] = $expectedresult; @@ -217,8 +217,8 @@ public function test_get_option_titles_custom1() { * Test if option titles are returned according to a mixture of defined and custom values, */ public function test_get_option_titles_mixed() { - $settings = array(1 => 'Ja1234'); // Test data. - $ratings = array(0, 1, 1, 1, 1); + $settings = [1 => 'Ja1234']; // Test data. + $ratings = [0, 1, 1, 1, 1]; $expectedresult = $settings; $expectedresult[0] = 'Deny'; // Depends on language file. @@ -244,40 +244,40 @@ public function test_reset_userdata() { $this->setUser($teacher); - $choices = array( - array( + $choices = [ + [ 'title' => 'C1', 'maxsize' => '1', 'active' => '1', - ), - array( + ], + [ 'title' => 'C2', 'maxsize' => '1', 'active' => '1', - ) - ); - $ratings = array( - $student1->id => array( - array( + ], + ]; + $ratings = [ + $student1->id => [ + [ 'choice' => 'C1', - 'rating' => 1 - ), - array( + 'rating' => 1, + ], + [ 'choice' => 'C2', - 'rating' => 0 - ) - ), - $student2->id => array( - array( + 'rating' => 0, + ], + ], + $student2->id => [ + [ 'choice' => 'C1', - 'rating' => 0 - ), - array( + 'rating' => 0, + ], + [ 'choice' => 'C2', - 'rating' => 1 - ) - ) - ); + 'rating' => 1, + ], + ], + ]; // Create ratingallocate instance. $ratingallocate = \mod_ratingallocate_generator::get_closed_ratingallocate_for_teacher($this, $choices, @@ -303,7 +303,7 @@ public function test_reset_userdata() { $status = ratingallocate_reset_userdata($data); // Reload the instance data. - $ra = $DB->get_record('ratingallocate', array('id' => $ratingallocate->get_ratingallocateid())); + $ra = $DB->get_record('ratingallocate', ['id' => $ratingallocate->get_ratingallocateid()]); $ratingallocate = \mod_ratingallocate_generator::get_ratingallocate($ra); // There should be no ratings and allocations anymore. diff --git a/tests/mod_generator_test.php b/tests/mod_generator_test.php index f0331ce4..771882d9 100644 --- a/tests/mod_generator_test.php +++ b/tests/mod_generator_test.php @@ -42,19 +42,19 @@ public function test_create_instance() { // There should not be any module for that course first. $this->assertFalse( - $DB->record_exists('ratingallocate', array('course' => $course->id - ))); - $records = $DB->get_records('ratingallocate_choices', array(), '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, - array('course' => $course)); - $records = $DB->get_records('ratingallocate', array('course' => $course->id - ), 'id'); + ['course' => $course]); + $records = $DB->get_records('ratingallocate', ['course' => $course->id, + ], 'id'); $this->assertEquals(1, count($records)); $this->assertTrue(array_key_exists($mod->id, $records)); - $expectedvaluesdb = array( + $expectedvaluesdb = [ 'id' => $mod->id, 'course' => $course->id, 'name' => 'Rating Allocation', @@ -71,56 +71,56 @@ public function test_create_instance() { 'notificationsend' => '0', 'algorithmstarttime' => null, 'algorithmstatus' => '0', - 'runalgorithmbycron' => '1' - ); + 'runalgorithmbycron' => '1', + ]; $this->assertEquals(json_decode(json_encode($expectedvaluesdb, false)), reset($records)); // Must have two choices. $records = $DB->get_records('ratingallocate_choices', - array('ratingallocateid' => $mod->id - ), 'title'); + ['ratingallocateid' => $mod->id, + ], 'title'); $this->assertEquals(2, count($records)); $choiceids = array_keys($records); - $expectedchoices = array( - $choiceids[0] => (object) array( + $expectedchoices = [ + $choiceids[0] => (object) [ 'title' => 'Choice 1', 'id' => $choiceids[0], 'ratingallocateid' => $mod->id, 'explanation' => 'Some explanatory text for choice 1', 'maxsize' => '10', 'usegroups' => '0', - 'active' => '1' - ), - $choiceids[1] => (object) array( + 'active' => '1', + ], + $choiceids[1] => (object) [ 'title' => 'Choice 2', 'id' => $choiceids[1], 'ratingallocateid' => $mod->id, 'explanation' => 'Some explanatory text for choice 2', 'maxsize' => '5', 'usegroups' => '0', - 'active' => '0' - ) - ); + 'active' => '0', + ], + ]; $this->assertEquals($expectedchoices, $records); // Create an other mod_ratingallocate within the course. - $params = array('course' => $course->id, 'name' => 'Another mod_ratingallocate' - ); + $params = ['course' => $course->id, 'name' => 'Another mod_ratingallocate', + ]; $mod = \mod_ratingallocate_generator::create_instance_with_choices($this, $params); - $records = $DB->get_records('ratingallocate', array('course' => $course->id - ), 'id'); + $records = $DB->get_records('ratingallocate', ['course' => $course->id, + ], 'id'); // Are there 2 modules within the course? $this->assertEquals(2, count($records)); // Is the name correct? $this->assertEquals('Another mod_ratingallocate', $records[$mod->id]->name); - $records = $DB->get_records('ratingallocate_choices', array(), 'id'); + $records = $DB->get_records('ratingallocate_choices', [], 'id'); $this->assertEquals(4, count($records)); // Other tables. - $records = $DB->get_records('ratingallocate_ratings', array(), 'id'); + $records = $DB->get_records('ratingallocate_ratings', [], 'id'); $this->assertEquals(0, count($records)); - $records = $DB->get_records('ratingallocate_allocations', array(), 'id'); + $records = $DB->get_records('ratingallocate_allocations', [], 'id'); $this->assertEquals(0, count($records)); } diff --git a/tests/mod_ratingallocate_allocate_unrated_test.php b/tests/mod_ratingallocate_allocate_unrated_test.php index a26a1f66..5f88024a 100644 --- a/tests/mod_ratingallocate_allocate_unrated_test.php +++ b/tests/mod_ratingallocate_allocate_unrated_test.php @@ -407,7 +407,7 @@ public function test_distribution_without_groups(): void { 'explanation' => "Explain Choice $letter", 'maxsize' => 8, 'active' => true, - 'usegroups' => false + 'usegroups' => false, ]; $choices[] = $choice; } @@ -602,7 +602,7 @@ public function test_distribute_equally_without_groups(): void { 'usegroups' => false, // We choose 14, 12, 10, 8 and 6 maxsize values for the groups A, B, C, D, E. // This means 50 places for 40 users in the course. - 'maxsize' => $i + 'maxsize' => $i, ]; $choices[] = $choice; @@ -653,7 +653,7 @@ public function test_distribute_fill_without_groups(): void { 'usegroups' => false, // We choose 14, 12, 10, 8 and 6 maxsize values for the groups A, B, C, D, E. // This means 50 places for 40 users in the course. - 'maxsize' => $i + 'maxsize' => $i, ]; $choices[] = $choice; diff --git a/tests/mod_ratingallocate_choice_groups_test.php b/tests/mod_ratingallocate_choice_groups_test.php index 26b1ece1..72c7599b 100644 --- a/tests/mod_ratingallocate_choice_groups_test.php +++ b/tests/mod_ratingallocate_choice_groups_test.php @@ -35,16 +35,16 @@ class mod_ratingallocate_choice_groups_test extends \advanced_testcase { * A thru D use groups, E does not. */ private function get_choice_data() { - $choices = array(); + $choices = []; $letters = range('A', 'E'); foreach ($letters as $key => $letter) { - $choice = array( + $choice = [ 'title' => "Choice $letter", 'explanation' => "Explain Choice $letter", 'maxsize' => 10, 'active' => true, - ); + ]; if ($letter === 'E') { $choice['usegroups'] = false; } else { @@ -102,9 +102,9 @@ protected function setUp(): void { $this->setUser($this->teacher); // Make test groups and enrol students. - $green = $generator->create_group(array('name' => 'Green Group', 'courseid' => $course->id)); - $blue = $generator->create_group(array('name' => 'Blue Group', 'courseid' => $course->id)); - $red = $generator->create_group(array('name' => 'Red Group', 'courseid' => $course->id)); + $green = $generator->create_group(['name' => 'Green Group', 'courseid' => $course->id]); + $blue = $generator->create_group(['name' => 'Blue Group', 'courseid' => $course->id]); + $red = $generator->create_group(['name' => 'Red Group', 'courseid' => $course->id]); $this->student1 = \mod_ratingallocate_generator::create_user_and_enrol($this, $course); groups_add_member($green, $this->student1); @@ -116,7 +116,7 @@ protected function setUp(): void { // No groups for student 4. $this->choicedata = $this->get_choice_data(); - $mod = \mod_ratingallocate_generator::create_instance_with_choices($this, array('course' => $course), $this->choicedata); + $mod = \mod_ratingallocate_generator::create_instance_with_choices($this, ['course' => $course], $this->choicedata); $this->ratingallocate = \mod_ratingallocate_generator::get_ratingallocate_for_user($this, $mod, $this->teacher); } @@ -128,6 +128,8 @@ protected function tearDown(): void { } /** + * Test the setup. + * * @return void * @covers ::get_group_selections */ @@ -147,6 +149,8 @@ public function test_setup() { } /** + * Test choice groups. + * * @return void * @covers ::filter_choices_by_groups */ @@ -167,15 +171,15 @@ public function test_choice_groups() { * Choice D: 'usegroups' is selected, but no groups; never available to students. * Choice E: 'usegroups' is not selected; always available. */ - $this->ratingallocate->update_choice_groups($choiceidmap['Choice A'], array( - $groupidmap['Green Group'] - )); - $this->ratingallocate->update_choice_groups($choiceidmap['Choice B'], array( - $groupidmap['Green Group'], $groupidmap['Blue Group'] - )); - $this->ratingallocate->update_choice_groups($choiceidmap['Choice C'], array( - $groupidmap['Red Group'] - )); + $this->ratingallocate->update_choice_groups($choiceidmap['Choice A'], [ + $groupidmap['Green Group'], + ]); + $this->ratingallocate->update_choice_groups($choiceidmap['Choice B'], [ + $groupidmap['Green Group'], $groupidmap['Blue Group'], + ]); + $this->ratingallocate->update_choice_groups($choiceidmap['Choice C'], [ + $groupidmap['Red Group'], + ]); // Teacher context: all choices shown in teacher view. $basechoices = array_keys($this->ratingallocate->filter_choices_by_groups($choices, $this->teacher->id)); @@ -223,6 +227,8 @@ public function test_choice_groups() { } /** + * Test update choice groups. + * * @return void * @covers ::update_choice_groups */ @@ -237,24 +243,24 @@ public function test_update_choice_groups() { $this->assertTrue(empty($groups)); // Add one. - $this->ratingallocate->update_choice_groups($choiceidmap['Choice A'], array( - $groupidmap['Green Group'] - )); + $this->ratingallocate->update_choice_groups($choiceidmap['Choice A'], [ + $groupidmap['Green Group'], + ]); $groups = $this->ratingallocate->get_choice_groups($choiceidmap['Choice A']); $this->assertContains($groupidmap['Green Group'], array_keys($groups)); // Update to two. - $this->ratingallocate->update_choice_groups($choiceidmap['Choice A'], array( - $groupidmap['Green Group'], $groupidmap['Blue Group'] - )); + $this->ratingallocate->update_choice_groups($choiceidmap['Choice A'], [ + $groupidmap['Green Group'], $groupidmap['Blue Group'], + ]); $groups = $this->ratingallocate->get_choice_groups($choiceidmap['Choice A']); $this->assertContains($groupidmap['Green Group'], array_keys($groups)); $this->assertContains($groupidmap['Blue Group'], array_keys($groups)); // Remove one. - $this->ratingallocate->update_choice_groups($choiceidmap['Choice A'], array( - $groupidmap['Blue Group'] - )); + $this->ratingallocate->update_choice_groups($choiceidmap['Choice A'], [ + $groupidmap['Blue Group'], + ]); $groups = $this->ratingallocate->get_choice_groups($choiceidmap['Choice A']); $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 29eaf993..5266780a 100644 --- a/tests/mod_ratingallocate_choice_importer_test.php +++ b/tests/mod_ratingallocate_choice_importer_test.php @@ -40,7 +40,7 @@ class mod_ratingallocate_choice_importer_test extends \advanced_testcase { */ private function get_choice_lines($joined=false) { // Whitespace should be trimmed by the importer. - $contents = array(); + $contents = []; $contents[] = 'title, explanation, maxsize, active, groups'; $contents[] = 'New Test Choice 3,Explain New Choice 3, 10, 1,'; $contents[] = 'New Test Choice 4,Explain New Choice 4, 100, 1,Green Group'; @@ -63,11 +63,11 @@ protected function setUp(): void { $this->teacher = \mod_ratingallocate_generator::create_user_and_enrol($this, $course, true); // Make test groups. - $this->green = $generator->create_group(array('name' => 'Green Group', 'courseid' => $course->id)); - $this->blue = $generator->create_group(array('name' => 'Blue Group', 'courseid' => $course->id)); - $this->red = $generator->create_group(array('name' => 'Red Group', 'courseid' => $course->id)); + $this->green = $generator->create_group(['name' => 'Green Group', 'courseid' => $course->id]); + $this->blue = $generator->create_group(['name' => 'Blue Group', 'courseid' => $course->id]); + $this->red = $generator->create_group(['name' => 'Red Group', 'courseid' => $course->id]); - $mod = \mod_ratingallocate_generator::create_instance_with_choices($this, array('course' => $course)); + $mod = \mod_ratingallocate_generator::create_instance_with_choices($this, ['course' => $course]); $this->ratingallocate = \mod_ratingallocate_generator::get_ratingallocate_for_user($this, $mod, $this->teacher); $this->ratingallocateid = $mod->id; @@ -99,7 +99,7 @@ public function test_choice_importer_testmode() { $this->assertEquals($importstatus->readcount, 4); $this->assertEquals($importstatus->importcount, 3); $this->assertEquals($importstatus->status_message, - get_string('csvupload_test_success', 'ratingallocate', array('importcount' => $importstatus->importcount)) + get_string('csvupload_test_success', 'ratingallocate', ['importcount' => $importstatus->importcount]) ); /* Note: delegated transaction rollback doesn't seme to be working inside PHPUnit tests. @@ -119,7 +119,7 @@ public function test_choice_importer_livemode() { $this->assertEquals($importstatus->readcount, 4); $this->assertEquals($importstatus->importcount, 3); $this->assertEquals($importstatus->status_message, - get_string('csvupload_live_success', 'ratingallocate', array('importcount' => $importstatus->importcount)) + get_string('csvupload_live_success', 'ratingallocate', ['importcount' => $importstatus->importcount]) ); $choices = $this->ratingallocate->get_choices(); $this->assertEquals(5, count($choices), 'Three new choices imported'); @@ -208,10 +208,10 @@ public function test_bad_group() { $this->assertEquals($importstatus->status, \mod_ratingallocate\choice_importer::IMPORT_STATUS_DATA_ERROR); $this->assertEquals($importstatus->readcount, 5); $this->assertEquals($importstatus->importcount, 4); // Will import, but no group association. - $this->assertEquals($importstatus->errors[0], get_string('csvupload_missing_groups', 'ratingallocate', array( + $this->assertEquals($importstatus->errors[0], get_string('csvupload_missing_groups', 'ratingallocate', [ 'row' => 5, 'invalidgroups' => 'Blue Man Group', - ))); + ])); $this->assertEquals($importstatus->status_message, get_string('csvupload_live_problems', 'ratingallocate', 1) ); diff --git a/tests/mod_ratingallocate_notification_test.php b/tests/mod_ratingallocate_notification_test.php index c833208f..fde1547a 100644 --- a/tests/mod_ratingallocate_notification_test.php +++ b/tests/mod_ratingallocate_notification_test.php @@ -28,7 +28,13 @@ */ class mod_ratingallocate_notification_test extends \advanced_testcase { + /** + * Choice 1. + */ const CHOICE1 = 'Choice 1'; + /** + * Choice 2. + */ const CHOICE2 = 'Choice 2'; /** @@ -38,54 +44,54 @@ class mod_ratingallocate_notification_test extends \advanced_testcase { */ public function test_allocation_notification() { $course = $this->getDataGenerator()->create_course(); - $students = array(); + $students = []; for ($i = 1; $i <= 4; $i++) { $students[$i] = \mod_ratingallocate_generator::create_user_and_enrol($this, $course); } - $choices = array( - array( + $choices = [ + [ 'title' => self::CHOICE1, 'maxsize' => '1', 'active' => '1', - ), - array( + ], + [ 'title' => self::CHOICE2, 'maxsize' => '1', 'active' => '1', - ) - ); - $ratings = array( - $students[1]->id => array( - array( + ], + ]; + $ratings = [ + $students[1]->id => [ + [ 'choice' => self::CHOICE1, - 'rating' => 1 - ), - array( + 'rating' => 1, + ], + [ 'choice' => self::CHOICE2, - 'rating' => 0 - ) - ), - $students[2]->id => array( - array( + 'rating' => 0, + ], + ], + $students[2]->id => [ + [ 'choice' => self::CHOICE1, - 'rating' => 0 - ), - array( + 'rating' => 0, + ], + [ 'choice' => self::CHOICE2, - 'rating' => 1 - ) - ), - $students[3]->id => array( - array( + 'rating' => 1, + ], + ], + $students[3]->id => [ + [ 'choice' => self::CHOICE1, - 'rating' => 0 - ), - array( + 'rating' => 0, + ], + [ 'choice' => self::CHOICE2, - 'rating' => 0 - ) - ) - ); + 'rating' => 0, + ], + ], + ]; $ratingallocate = \mod_ratingallocate_generator::get_closed_ratingallocate_for_teacher($this, $choices, $course, $ratings); @@ -105,9 +111,9 @@ public function test_allocation_notification() { // Add custom data. $task->set_component('mod_ratingallocate'); - $task->set_custom_data(array( - 'ratingallocateid' => $ratingallocate->ratingallocate->id - )); + $task->set_custom_data([ + 'ratingallocateid' => $ratingallocate->ratingallocate->id, + ]); $this->setAdminUser(); $task->execute(); diff --git a/tests/mod_ratingallocate_privacy_provider_test.php b/tests/mod_ratingallocate_privacy_provider_test.php index 79c6e011..7c79503f 100644 --- a/tests/mod_ratingallocate_privacy_provider_test.php +++ b/tests/mod_ratingallocate_privacy_provider_test.php @@ -38,6 +38,7 @@ * @covers \classes\privacy\provider */ class mod_ratingallocate_privacy_provider_test extends \core_privacy\tests\provider_testcase { + /** @var \mod_ratingallocate_generated_module $testmodule */ protected $testmodule; /** @@ -201,12 +202,12 @@ public function test_delete_for_users_in_context() { $testmodule2 = new \mod_ratingallocate_generated_module($this); $cm = get_coursemodule_from_instance('ratingallocate', $this->testmodule->moddb->id); - $params1 = array( - 'ratingallocateid' => $this->testmodule->moddb->id - ); - $params2 = array( - 'ratingallocateid' => $testmodule2->moddb->id - ); + $params1 = [ + 'ratingallocateid' => $this->testmodule->moddb->id, + ]; + $params2 = [ + 'ratingallocateid' => $testmodule2->moddb->id, + ]; // Before deletion, we should have 20 responses and 10 allocations in instance 1. $count = $DB->count_records_select('ratingallocate_ratings', @@ -226,7 +227,7 @@ public function test_delete_for_users_in_context() { // Delete data based on context. $cmcontext = \context_module::instance($cm->id); - $userlist = array(); + $userlist = []; // Select one unassigned student. $userlist[] = $DB->get_record_sql("SELECT ra.userid FROM {ratingallocate_choices} ch JOIN diff --git a/tests/mod_ratingallocate_processor_test.php b/tests/mod_ratingallocate_processor_test.php index d26e21e1..0aa14916 100644 --- a/tests/mod_ratingallocate_processor_test.php +++ b/tests/mod_ratingallocate_processor_test.php @@ -84,7 +84,7 @@ public function modify_allocation_provider() { 20], 'Rating phase is not over, yet.' => [ 'get_open_ratingallocate_for_teacher', - 10] + 10], ]; } @@ -138,12 +138,12 @@ public function test_ratings_table_groupfilter() { $this->setUser($teacher); // Create two groups. - $group1 = $this->getDataGenerator()->create_group(array( + $group1 = $this->getDataGenerator()->create_group([ 'courseid' => $course->id, - 'name' => 'group1')); - $group2 = $this->getDataGenerator()->create_group(array( + 'name' => 'group1']); + $group2 = $this->getDataGenerator()->create_group([ 'courseid' => $course->id, - 'name' => 'group2')); + 'name' => 'group2']); // Add 1 member to each group, and 1 member to both groups. $student1 = \mod_ratingallocate_generator::create_user_and_enrol($this, $course); @@ -156,7 +156,7 @@ public function test_ratings_table_groupfilter() { $student4 = \mod_ratingallocate_generator::create_user_and_enrol($this, $course); // Setup ratingallocate instance. - $mod = \mod_ratingallocate_generator::create_instance_with_choices($this, array('course' => $course), $this->get_choice_data()); + $mod = \mod_ratingallocate_generator::create_instance_with_choices($this, ['course' => $course], $this->get_choice_data()); $ratingallocate = \mod_ratingallocate_generator::get_ratingallocate_for_user($this, $mod, $teacher); // Map choice titles to choice IDs, group names to group IDs. @@ -170,12 +170,12 @@ public function test_ratings_table_groupfilter() { * Choice B: only rateable by group2 * Choice C: ratable by all students */ - $ratingallocate->update_choice_groups($choiceidmap['Choice A'], array( - $groupidmap['group1'] - )); - $ratingallocate->update_choice_groups($choiceidmap['Choice B'], array( - $groupidmap['group2'] - )); + $ratingallocate->update_choice_groups($choiceidmap['Choice A'], [ + $groupidmap['group1'], + ]); + $ratingallocate->update_choice_groups($choiceidmap['Choice B'], [ + $groupidmap['group2'], + ]); // Test the group filter only (set hidenorating and showalloccount to false). @@ -236,7 +236,7 @@ private function setup_ratings_table_with_filter_options($ratingallocate, $hiden // Create and set up the flextable for ratings and allocations. $choices = $ratingallocate->get_rateable_choices(); $table = new \mod_ratingallocate\ratings_and_allocations_table($ratingallocate->get_renderer(), - array(), $ratingallocate, 'show_alloc_table', 'mod_ratingallocate_test', false); + [], $ratingallocate, 'show_alloc_table', 'mod_ratingallocate_test', false); $table->setup_table($choices, $hidenorating, $showallocnecessary, $groupselect); return $table; @@ -248,30 +248,30 @@ private function setup_ratings_table_with_filter_options($ratingallocate, $hiden * @return array */ private function get_choice_data() { - $choicedata = array(); - $choice1 = array( + $choicedata = []; + $choice1 = [ 'title' => "Choice A", 'explanation' => "Ratable by group1", 'maxsize' => 10, 'active' => true, - 'usegroups' => true - ); + 'usegroups' => true, + ]; $choicedata[] = $choice1; - $choice2 = array( + $choice2 = [ 'title' => "Choice B", 'explanation' => "Ratable by group2", 'maxsize' => 10, 'active' => true, - 'usegroups' => true - ); + 'usegroups' => true, + ]; $choicedata[] = $choice2; - $choice3 = array( + $choice3 = [ 'title' => "Choice C", 'explanation' => "Ratable by all students", 'maxsize' => 10, 'active' => true, - 'usegroups' => false - ); + 'usegroups' => false, + ]; $choicedata[] = $choice3; return $choicedata; } diff --git a/tests/mod_ratingallocate_solver_test.php b/tests/mod_ratingallocate_solver_test.php index 3ff6ace2..ea9bc371 100644 --- a/tests/mod_ratingallocate_solver_test.php +++ b/tests/mod_ratingallocate_solver_test.php @@ -24,7 +24,7 @@ /** * Contains unit tests for the distribution algorithm. * - * @package mod + * @package mod_ratingallocate * @subpackage mod_groupdistribution * @group mod_ratingallocate * @copyright original Version 2013 Stefan Koegel @@ -40,8 +40,8 @@ private function perform_race($groupsnum, $ratersnum) { $rateminimum = 0.7; // Every Student gives a min voting. $ratingmax = 5; // Rating from 1 to X. - $result = array(); - $groups = array(); + $result = []; + $groups = []; for ($i = 1; $i < $groupsnum; $i++) { $groups[$i] = new \stdClass(); @@ -49,7 +49,7 @@ private function perform_race($groupsnum, $ratersnum) { $groups[$i]->maxsize = rand($groupsmaxsizemin, $groupsmaxsizemax); } - $ratings = array(); + $ratings = []; for ($i = 1; $i < $ratersnum; $i++) { $ratingsgiven = 0; @@ -74,7 +74,7 @@ private function perform_race($groupsnum, $ratersnum) { $usercount = $ratersnum; - $solvers = array('solver_edmonds_karp', 'solver_ford_fulkerson'); + $solvers = ['solver_edmonds_karp', 'solver_ford_fulkerson']; foreach ($solvers as $solver) { $solver1 = new $solver; $timestart = microtime(true); @@ -92,20 +92,20 @@ public function teston_random() { if (!PHPUNIT_LONGTEST) { return; // This test takes longer than 10s. } - $testparams = array(array(5, 25), array(10, 50), array(10, 100), - array(20, 200)); - $testergebnisse = array(); + $testparams = [[5, 25], [10, 50], [10, 100], + [20, 200]]; + $testergebnisse = []; foreach ($testparams as $testset) { $paramgroups = ceil(sqrt($testset[1])); $paramusers = $testset[1]; - $rundenergebnis = array(); + $rundenergebnis = []; for ($i = 0; $i < 10; $i++) { $ergebnis = $this->perform_race($paramgroups, $paramusers); $this->assertEquals($ergebnis['ford-fulkerson Koegel2014']['gesamtpunktzahl'], $ergebnis['edmonds_karp']['gesamtpunktzahl']); $rundenergebnis[] = $ergebnis; } - $durchschnitt = array(); + $durchschnitt = []; $counter = 0; // Calculate average for each round. foreach ($rundenergebnis as $einzelergebnis) { @@ -131,11 +131,13 @@ public function teston_random() { } /** + * Test Edmonds-Karp algorithm. + * * @return void * @covers \solver_edmonds_karp */ public function test_edmondskarp() { - $choices = array(); + $choices = []; $choices[1] = new \stdClass(); $choices[1]->maxsize = 2; $choices[1]->id = 1; @@ -143,7 +145,7 @@ public function test_edmondskarp() { $choices[2]->maxsize = 2; $choices[2]->id = 2; - $ratings = array(); + $ratings = []; $ratings[1] = new \stdClass(); $ratings[1]->userid = 1; $ratings[1]->choiceid = 1; @@ -193,7 +195,7 @@ public function test_edmondskarp() { $solver = new \solver_edmonds_karp(); $distribution = $solver->compute_distribution($choices, $ratings, $usercount); - $expected = array(1 => array(2, 5), 2 => array(4, 1)); + $expected = [1 => [2, 5], 2 => [4, 1]]; $this->assertEquals($expected, $distribution); $this->assertEquals($solver::compute_target_function($ratings, $distribution), 15); @@ -206,11 +208,13 @@ public function test_edmondskarp() { } /** + * Test algorithm for negativeweightcycle. + * * @return void */ public function test_negweightcycle() { // Experimental. - $choices = array(); + $choices = []; $choices[1] = new \stdClass(); $choices[1]->maxsize = 2; $choices[1]->id = 1; @@ -218,7 +222,7 @@ public function test_negweightcycle() { $choices[2]->maxsize = 2; $choices[2]->id = 2; - $ratings = array(); + $ratings = []; $ratings[1] = new \stdClass(); $ratings[1]->userid = 1; $ratings[1]->choiceid = 1; @@ -254,10 +258,12 @@ public function test_negweightcycle() { } /** + * Test tagetfunction. + * * @return void */ public function test_targetfunc() { - $ratings = array(); + $ratings = []; $ratings[1] = new \stdClass(); $ratings[1]->userid = 1; $ratings[1]->choiceid = 1; @@ -278,16 +284,17 @@ public function test_targetfunc() { $ratings[4]->choiceid = 2; $ratings[4]->rating = 4; - $this->assertEquals(\distributor::compute_target_function($ratings, array(1 => array(1), 2 => array(2))), 9); - $this->assertEquals(\distributor::compute_target_function($ratings, array(1 => array(1, 2))), 8); - $this->assertEquals(\distributor::compute_target_function($ratings, array(1 => array(2), 2 => array(1))), 7); + $this->assertEquals(\distributor::compute_target_function($ratings, [1 => [1], 2 => + [2]]), 9); + $this->assertEquals(\distributor::compute_target_function($ratings, [1 => [1, 2]]), 8); + $this->assertEquals(\distributor::compute_target_function($ratings, [1 => [2], 2 => [1]]), 7); } /** * Test id conversions from user+choicids to graphids */ public function test_setupids() { - $ratings = array(); + $ratings = []; $ratings[1] = new \stdClass(); $ratings[1]->userid = 3; $ratings[1]->choiceid = 1; @@ -311,11 +318,11 @@ public function test_setupids() { $usercount = 2; list($fromuserid, $touserid, $fromchoiceid, $tochoiceid) = \solver_edmonds_karp::setup_id_conversions($usercount, $ratings); - $this->assertEquals(array(3 => 1, 2 => 2), $fromuserid); - $this->assertEquals(array(1 => 3, 2 => 2), $touserid); + $this->assertEquals([3 => 1, 2 => 2], $fromuserid); + $this->assertEquals([1 => 3, 2 => 2], $touserid); - $this->assertEquals(array(1 => 3, 2 => 4), $fromchoiceid); - $this->assertEquals(array(3 => 1, 4 => 2), $tochoiceid); + $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 ebf5e99e..09dd0e85 100644 --- a/tests/mod_ratingallocate_status_test.php +++ b/tests/mod_ratingallocate_status_test.php @@ -15,6 +15,9 @@ // along with Moodle. If not, see . namespace mod_ratingallocate; +use PHP_CodeSniffer\Generators\Generator; +use PhpOffice\PhpSpreadsheet\Worksheet\Iterator; + defined('MOODLE_INTERNAL') || die(); require_once(__DIR__ . '/generator/lib.php'); @@ -38,9 +41,11 @@ public function setUp(): void { } /** - * @return array the different testing scenarios. + * Provider + * + * @return array */ - public function ratingallocate_provider() { + public function ratingallocate_provider(): array { return [ 'Rating phase is not started.' => [ 3, 6, false, false, \ratingallocate::DISTRIBUTION_STATUS_TOO_EARLY], @@ -65,7 +70,7 @@ public function ratingallocate_provider() { 'The rating phase is running and allocation is published.' => [ -7, -6, true, false, \ratingallocate::DISTRIBUTION_STATUS_PUBLISHED], 'The rating phase is running and allocations exist and are published.' => [ - -7, -6, true, true, \ratingallocate::DISTRIBUTION_STATUS_PUBLISHED] + -7, -6, true, true, \ratingallocate::DISTRIBUTION_STATUS_PUBLISHED], ]; } @@ -75,12 +80,12 @@ public function ratingallocate_provider() { * @covers ::get_status() */ public function test_get_status($addtostart, $addtostop, $published, $hasallocations, $expected) { - $record = array( + $record = [ 'name' => 'Rating Allocation', 'accesstimestart' => time() + ($addtostart * 24 * 60 * 60), 'accesstimestop' => time() + ($addtostop * 24 * 60 * 60), - 'strategyopt' => array('strategy_yesno' => array('maxcrossout' => '1')), - 'strategy' => 'strategy_yesno'); + 'strategyopt' => ['strategy_yesno' => ['maxcrossout' => '1']], + 'strategy' => 'strategy_yesno']; if ($hasallocations) { $genmod = new \mod_ratingallocate_generated_module($this, $record); $moddb = $genmod->moddb; diff --git a/tests/mod_ratingallocate_strategy_test.php b/tests/mod_ratingallocate_strategy_test.php index 8b950f86..642f5f95 100644 --- a/tests/mod_ratingallocate_strategy_test.php +++ b/tests/mod_ratingallocate_strategy_test.php @@ -25,6 +25,11 @@ * @covers ::validate_settings() */ +/** + * Strategy test + * + * @package mod_ratingallocate + */ class mod_ratingallocate_strategy_test extends \advanced_testcase { /** @@ -32,15 +37,15 @@ class mod_ratingallocate_strategy_test extends \advanced_testcase { */ public function test_yes_no_validation() { // Attribute required. - $settings = array(\mod_ratingallocate\strategy_yesno\strategy::MAXCROSSOUT => null); + $settings = [\mod_ratingallocate\strategy_yesno\strategy::MAXCROSSOUT => null]; $strategy = new \mod_ratingallocate\strategy_yesno\strategy($settings); $this->assertCount(1, $strategy->validate_settings()); // Attribute minimum error. - $settings = array(\mod_ratingallocate\strategy_yesno\strategy::MAXCROSSOUT => -1); + $settings = [\mod_ratingallocate\strategy_yesno\strategy::MAXCROSSOUT => -1]; $strategy = new \mod_ratingallocate\strategy_yesno\strategy($settings); $this->assertCount(1, $strategy->validate_settings()); // No validation error. - $settings = array(\mod_ratingallocate\strategy_yesno\strategy::MAXCROSSOUT => 1); + $settings = [\mod_ratingallocate\strategy_yesno\strategy::MAXCROSSOUT => 1]; $strategy = new \mod_ratingallocate\strategy_yesno\strategy($settings); $this->assertCount(0, $strategy->validate_settings()); } @@ -50,15 +55,15 @@ public function test_yes_no_validation() { */ public function test_yes_maybe_no_validation() { // Attribute required. - $settings = array(\mod_ratingallocate\strategy_yesmaybeno\strategy::MAXNO => null); + $settings = [\mod_ratingallocate\strategy_yesmaybeno\strategy::MAXNO => null]; $strategy = new \mod_ratingallocate\strategy_yesmaybeno\strategy($settings); $this->assertCount(1, $strategy->validate_settings()); // Attribute minimum error. - $settings = array(\mod_ratingallocate\strategy_yesmaybeno\strategy::MAXNO => -1); + $settings = [\mod_ratingallocate\strategy_yesmaybeno\strategy::MAXNO => -1]; $strategy = new \mod_ratingallocate\strategy_yesmaybeno\strategy($settings); $this->assertCount(1, $strategy->validate_settings()); // No validation error. - $settings = array(\mod_ratingallocate\strategy_yesmaybeno\strategy::MAXNO => 1); + $settings = [\mod_ratingallocate\strategy_yesmaybeno\strategy::MAXNO => 1]; $strategy = new \mod_ratingallocate\strategy_yesmaybeno\strategy($settings); $this->assertCount(0, $strategy->validate_settings()); } @@ -68,27 +73,27 @@ public function test_yes_maybe_no_validation() { */ public function test_lickert_validation() { // Attribute required. - $settings = array(\mod_ratingallocate\strategy_lickert\strategy::COUNTLICKERT => null); + $settings = [\mod_ratingallocate\strategy_lickert\strategy::COUNTLICKERT => null]; $strategy = new \mod_ratingallocate\strategy_lickert\strategy($settings); $this->assertCount(1, $strategy->validate_settings()); // Attribute required. - $settings = array(\mod_ratingallocate\strategy_lickert\strategy::MAXNO => null); + $settings = [\mod_ratingallocate\strategy_lickert\strategy::MAXNO => null]; $strategy = new \mod_ratingallocate\strategy_lickert\strategy($settings); $this->assertCount(1, $strategy->validate_settings()); // Attribute minimum error. - $settings = array(\mod_ratingallocate\strategy_lickert\strategy::COUNTLICKERT => 1); + $settings = [\mod_ratingallocate\strategy_lickert\strategy::COUNTLICKERT => 1]; $strategy = new \mod_ratingallocate\strategy_lickert\strategy($settings); $this->assertCount(1, $strategy->validate_settings()); // Attribute minimum error. - $settings = array(\mod_ratingallocate\strategy_lickert\strategy::MAXNO => -1); + $settings = [\mod_ratingallocate\strategy_lickert\strategy::MAXNO => -1]; $strategy = new \mod_ratingallocate\strategy_lickert\strategy($settings); $this->assertCount(1, $strategy->validate_settings()); // No validation error. - $settings = array(\mod_ratingallocate\strategy_lickert\strategy::COUNTLICKERT => 3); + $settings = [\mod_ratingallocate\strategy_lickert\strategy::COUNTLICKERT => 3]; $strategy = new \mod_ratingallocate\strategy_lickert\strategy($settings); $this->assertCount(0, $strategy->validate_settings()); // No validation error. - $settings = array(\mod_ratingallocate\strategy_lickert\strategy::MAXNO => 1); + $settings = [\mod_ratingallocate\strategy_lickert\strategy::MAXNO => 1]; $strategy = new \mod_ratingallocate\strategy_lickert\strategy($settings); $this->assertCount(0, $strategy->validate_settings()); } @@ -98,39 +103,39 @@ public function test_lickert_validation() { */ public function test_points_validation() { // Attribute required. - $settings = array(\mod_ratingallocate\strategy_points\strategy::MAXZERO => null); + $settings = [\mod_ratingallocate\strategy_points\strategy::MAXZERO => null]; $strategy = new \mod_ratingallocate\strategy_points\strategy($settings); $this->assertCount(1, $strategy->validate_settings()); // Attribute required. - $settings = array(\mod_ratingallocate\strategy_points\strategy::TOTALPOINTS => null); + $settings = [\mod_ratingallocate\strategy_points\strategy::TOTALPOINTS => null]; $strategy = new \mod_ratingallocate\strategy_points\strategy($settings); $this->assertCount(1, $strategy->validate_settings()); // Attribute required. - $settings = array(\mod_ratingallocate\strategy_points\strategy::MAXPERCHOICE => null); + $settings = [\mod_ratingallocate\strategy_points\strategy::MAXPERCHOICE => null]; $strategy = new \mod_ratingallocate\strategy_points\strategy($settings); $this->assertCount(1, $strategy->validate_settings()); // Attribute minimum error. - $settings = array(\mod_ratingallocate\strategy_points\strategy::MAXZERO => -1); + $settings = [\mod_ratingallocate\strategy_points\strategy::MAXZERO => -1]; $strategy = new \mod_ratingallocate\strategy_points\strategy($settings); $this->assertCount(1, $strategy->validate_settings()); // Attribute minimum error. - $settings = array(\mod_ratingallocate\strategy_points\strategy::TOTALPOINTS => 0); + $settings = [\mod_ratingallocate\strategy_points\strategy::TOTALPOINTS => 0]; $strategy = new \mod_ratingallocate\strategy_points\strategy($settings); $this->assertCount(1, $strategy->validate_settings()); // Attribute minimum error. - $settings = array(\mod_ratingallocate\strategy_points\strategy::MAXPERCHOICE => 0); + $settings = [\mod_ratingallocate\strategy_points\strategy::MAXPERCHOICE => 0]; $strategy = new \mod_ratingallocate\strategy_points\strategy($settings); $this->assertCount(1, $strategy->validate_settings()); // No validation error. - $settings = array(\mod_ratingallocate\strategy_points\strategy::MAXZERO => 0); + $settings = [\mod_ratingallocate\strategy_points\strategy::MAXZERO => 0]; $strategy = new \mod_ratingallocate\strategy_points\strategy($settings); $this->assertCount(0, $strategy->validate_settings()); // No validation error. - $settings = array(\mod_ratingallocate\strategy_points\strategy::TOTALPOINTS => 1); + $settings = [\mod_ratingallocate\strategy_points\strategy::TOTALPOINTS => 1]; $strategy = new \mod_ratingallocate\strategy_points\strategy($settings); $this->assertCount(0, $strategy->validate_settings()); // No validation error. - $settings = array(\mod_ratingallocate\strategy_points\strategy::MAXPERCHOICE => 1); + $settings = [\mod_ratingallocate\strategy_points\strategy::MAXPERCHOICE => 1]; $strategy = new \mod_ratingallocate\strategy_points\strategy($settings); $this->assertCount(0, $strategy->validate_settings()); } @@ -140,15 +145,15 @@ public function test_points_validation() { */ public function test_order_validation() { // Attribute required. - $settings = array(\mod_ratingallocate\strategy_order\strategy::COUNTOPTIONS => null); + $settings = [\mod_ratingallocate\strategy_order\strategy::COUNTOPTIONS => null]; $strategy = new \mod_ratingallocate\strategy_order\strategy($settings); $this->assertCount(1, $strategy->validate_settings()); // Attribute minimum error. - $settings = array(\mod_ratingallocate\strategy_order\strategy::COUNTOPTIONS => 0); + $settings = [\mod_ratingallocate\strategy_order\strategy::COUNTOPTIONS => 0]; $strategy = new \mod_ratingallocate\strategy_order\strategy($settings); $this->assertCount(1, $strategy->validate_settings()); // No validation error. - $settings = array(\mod_ratingallocate\strategy_order\strategy::COUNTOPTIONS => 1); + $settings = [\mod_ratingallocate\strategy_order\strategy::COUNTOPTIONS => 1]; $strategy = new \mod_ratingallocate\strategy_order\strategy($settings); $this->assertCount(0, $strategy->validate_settings()); } @@ -158,15 +163,15 @@ public function test_order_validation() { */ public function test_tickyes_validation() { // Attribute required. - $settings = array(\mod_ratingallocate\strategy_tickyes\strategy::MINTICKYES => null); + $settings = [\mod_ratingallocate\strategy_tickyes\strategy::MINTICKYES => null]; $strategy = new \mod_ratingallocate\strategy_tickyes\strategy($settings); $this->assertCount(1, $strategy->validate_settings()); // Attribute minimum error. - $settings = array(\mod_ratingallocate\strategy_tickyes\strategy::MINTICKYES => 0); + $settings = [\mod_ratingallocate\strategy_tickyes\strategy::MINTICKYES => 0]; $strategy = new \mod_ratingallocate\strategy_tickyes\strategy($settings); $this->assertCount(1, $strategy->validate_settings()); // No validation error. - $settings = array(\mod_ratingallocate\strategy_tickyes\strategy::MINTICKYES => 1); + $settings = [\mod_ratingallocate\strategy_tickyes\strategy::MINTICKYES => 1]; $strategy = new \mod_ratingallocate\strategy_tickyes\strategy($settings); $this->assertCount(0, $strategy->validate_settings()); } diff --git a/version.php b/version.php index 57cc2f0d..ab6e9631 100644 --- a/version.php +++ b/version.php @@ -25,8 +25,8 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2023101900; // The current module version (Date: YYYYMMDDXX). +$plugin->version = 2024060300; // The current module version (Date: YYYYMMDDXX). $plugin->requires = 2020061500; // Requires Moodle 3.9+. $plugin->maturity = MATURITY_STABLE; -$plugin->release = 'v4.3-r1'; +$plugin->release = 'v4.4-r1'; $plugin->component = 'mod_ratingallocate'; // To check on upgrade, that module sits in correct place. diff --git a/view.php b/view.php index 62cc46e3..6860fa1c 100644 --- a/view.php +++ b/view.php @@ -38,9 +38,9 @@ if ($id) { $cm = get_coursemodule_from_id('ratingallocate', $id, 0, false, MUST_EXIST); $course = get_course($cm->course); - $ratingallocate = $DB->get_record('ratingallocate', array('id' => $cm->instance), '*', MUST_EXIST); + $ratingallocate = $DB->get_record('ratingallocate', ['id' => $cm->instance], '*', MUST_EXIST); } else if ($n) { - $ratingallocate = $DB->get_record('ratingallocate', array('id' => $n), '*', MUST_EXIST); + $ratingallocate = $DB->get_record('ratingallocate', ['id' => $n], '*', MUST_EXIST); $course = get_course($ratingallocate->course); $cm = get_coursemodule_from_instance('ratingallocate', $ratingallocate->id, $course->id, false, MUST_EXIST); } else { @@ -51,7 +51,7 @@ $context = context_module::instance($cm->id); $PAGE->set_title($cm->name); $PAGE->set_context($context); -$PAGE->set_url('/mod/ratingallocate/view.php', array('id' => $cm->id)); +$PAGE->set_url('/mod/ratingallocate/view.php', ['id' => $cm->id]); require_capability('mod/ratingallocate:view', $context);