diff --git a/backup/moodle2/backup_restore_helper.php b/backup/moodle2/backup_restore_helper.php index 35711a61..b2267a4f 100644 --- a/backup/moodle2/backup_restore_helper.php +++ b/backup/moodle2/backup_restore_helper.php @@ -15,12 +15,19 @@ // 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 */ +/** + * @param $class + * @return array + * @throws ReflectionException + */ function get_fields_for_tableclass($class) { $class = new ReflectionClass($class); $constants = $class->getConstants(); @@ -33,12 +40,22 @@ function get_fields_for_tableclass($class) { return array_values($constants); } +/** + * @param $class + * @return mixed + * @throws ReflectionException + */ function get_tablename_for_tableclass($class) { $class = new ReflectionClass($class); $constants = $class->getConstants(); return $constants['TABLE']; } +/** + * @param $class + * @return array + * @throws ReflectionException + */ function get_id_for_tableclass($class) { $class = new ReflectionClass($class); $constants = $class->getConstants(); diff --git a/backup/moodle2/restore_ratingallocate_activity_stepslib.php b/backup/moodle2/restore_ratingallocate_activity_stepslib.php index d27aa25c..0be2b767 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 c26f16a5..1a82f154 100644 --- a/backup/moodle2/restore_ratingallocate_activity_task.class.php +++ b/backup/moodle2/restore_ratingallocate_activity_task.class.php @@ -27,6 +27,11 @@ */ require_once($CFG->dirroot . '/mod/ratingallocate/backup/moodle2/restore_ratingallocate_activity_stepslib.php'); +/** + * @class restore_ratingallocate_activity_task + * @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 { /** 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 f06bff8e..4a96b0e2 100644 --- a/classes/allocations_table.php +++ b/classes/allocations_table.php @@ -29,6 +29,9 @@ require_once($CFG->libdir . '/tablelib.php'); require_once($CFG->dirroot . '/user/lib.php'); +/** + * @class allocations_table + */ class allocations_table extends \table_sql { /** @@ -203,7 +206,7 @@ private function get_user_link($user) { $name = fullname($user); if ($COURSE->id == SITEID) { - $profileurl = new \moodle_url('/user/profile.php',['id' => $user->id]); + $profileurl = new \moodle_url('/user/profile.php', ['id' => $user->id]); } else { $profileurl = new \moodle_url('/user/view.php', ['id' => $user->id, 'course' => $COURSE->id]); @@ -229,7 +232,7 @@ public function init_sql() { $where = "c.ratingallocateid = :ratingallocateid"; - $params =[]; + $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 d842ce52..c1e51fb5 100644 --- a/classes/choice_importer.php +++ b/classes/choice_importer.php @@ -27,18 +27,27 @@ require_once($CFG->libdir . '/csvlib.class.php'); - +/** + * @class choice_importer + */ class choice_importer { + /** + * 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 +75,18 @@ public static function print_fields($fields=self::REQUIRED_FIELDS) { return '[' . join(', ', $fields) . ']'; } + /** + * @param $ratingallocateid + * @param $ratingallocate + */ public function __construct($ratingallocateid, $ratingallocate) { $this->ratingallocate = $ratingallocate; $this->ratingallocateid = $ratingallocateid; } + /** + * Destruct. + */ public function __destruct() { $this->free_reader(); } diff --git a/classes/privacy/provider.php b/classes/privacy/provider.php index 03582678..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', @@ -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..6ae72054 100644 --- a/classes/ratingallocate_observer.php +++ b/classes/ratingallocate_observer.php @@ -26,6 +26,9 @@ use coding_exception; use dml_exception; +/** + * @class ratingallocate_observer + */ class ratingallocate_observer { /** @@ -36,7 +39,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 +64,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 517ae352..5ca101b8 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,33 @@ global $CFG; require_once($CFG->libdir . '/tablelib.php'); +/** + * @class ratings_and_allocations_table + */ 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 =[]; - private $choicemax =[]; - private $choicesum =[]; - + /** @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,6 +88,16 @@ class ratings_and_allocations_table extends \table_sql { */ private $renderer; + /** + * @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); @@ -243,7 +270,7 @@ public function build_table_by_sql($ratings, $allocations, $writeable = false) { $users = $this->rawdata; // Group all ratings per user to match table structure. - $ratingsbyuser =[]; + $ratingsbyuser = []; foreach ($ratings as $rating) { if (empty($ratingsbyuser[$rating->userid])) { $ratingsbyuser[$rating->userid] = []; @@ -332,7 +359,7 @@ private function add_user_ratings_row($user, $userratings, $userallocations) { foreach ($userratings as $choiceid => $userrating) { $row[self::CHOICE_COL . $choiceid] = [ 'rating' => $userrating, - 'hasallocation' => false // May be overridden later. + 'hasallocation' => false, // May be overridden later. ]; } @@ -349,7 +376,7 @@ private function add_user_ratings_row($user, $userratings, $userallocations) { // User has not rated this choice, but it was assigned to him/her. $row[$rowkey] = [ 'rating' => null, - 'hasallocation' => true + 'hasallocation' => true, ]; } else { // User has rated this choice. @@ -532,7 +559,7 @@ private function setup_filter($hidenorating = null, $showallocnecessary = null, $filter = [ 'hidenorating' => $this->hidenorating, 'showallocnecessary' => $this->showallocnecessary, - 'groupselect' => $this->groupselect + 'groupselect' => $this->groupselect, ]; } if (!is_null($hidenorating)) { @@ -558,7 +585,7 @@ public function get_filter() { $filter = [ 'hidenorating' => $this->hidenorating, 'showallocnecessary' => $this->showallocnecessary, - 'groupselect' => $this->groupselect + 'groupselect' => $this->groupselect, ]; return $filter; } @@ -617,12 +644,17 @@ function($u) { [ 'ratingallocateid' => $this->ratingallocate->ratingallocate->id, 'ratingallocateid2' => $this->ratingallocate->ratingallocate->id, - 'groupselect' => $this->groupselect + 'groupselect' => $this->groupselect, ] ) ); } + /** + * @param $choiceids + * @return array + * @throws \dml_exception + */ private function filter_choiceids($choiceids) { global $DB; if (!$choiceids) { @@ -655,7 +687,7 @@ function($c) { $DB->get_records_sql($sql, [ 'ratingallocateid' => $this->ratingallocate->ratingallocate->id, - 'groupselect' => $this->groupselect + 'groupselect' => $this->groupselect, ] ) ); diff --git a/classes/task/send_distribution_notification.php b/classes/task/send_distribution_notification.php index f72f4ec6..c7e6d9ba 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,9 @@ use ratingallocate\db as this_db; +/** + * @class send_distibution_notification + */ 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. diff --git a/db/access.php b/db/access.php index 0261446d..956b4b58 100644 --- a/db/access.php +++ b/db/access.php @@ -45,7 +45,7 @@ */ defined('MOODLE_INTERNAL') || die(); -$capabilities =[ +$capabilities = [ 'mod/ratingallocate:addinstance' => [ 'riskbitmask' => RISK_XSS | RISK_PERSONAL, @@ -53,11 +53,11 @@ 'captype' => 'write', 'archetypes' => [ 'editingteacher' => CAP_ALLOW, - 'manager' => CAP_ALLOW + 'manager' => CAP_ALLOW, ], - 'clonepermissionsfrom' => 'moodle/course:manageactivities' + 'clonepermissionsfrom' => 'moodle/course:manageactivities', ], - 'mod/ratingallocate:view' =>[ + 'mod/ratingallocate:view' => [ 'captype' => 'read', 'contextlevel' => CONTEXT_MODULE, 'legacy' => [ @@ -65,50 +65,50 @@ 'student' => CAP_ALLOW, 'teacher' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ] + 'manager' => CAP_ALLOW, + ], ], - 'mod/ratingallocate:give_rating' =>[ + 'mod/ratingallocate:give_rating' => [ 'contextlevel' => CONTEXT_MODULE, 'captype' => 'write', 'archetypes' => [ - 'student' => CAP_ALLOW - ] + 'student' => CAP_ALLOW, + ], ], - 'mod/ratingallocate:start_distribution' =>[ + 'mod/ratingallocate:start_distribution' => [ 'contextlevel' => CONTEXT_MODULE, 'riskbitmask' => RISK_PERSONAL, 'captype' => 'write', 'archetypes' => [ 'editingteacher' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ] + 'manager' => CAP_ALLOW, + ], ], - 'mod/ratingallocate:modify_choices' =>[ + 'mod/ratingallocate:modify_choices' => [ 'contextlevel' => CONTEXT_MODULE, 'captype' => 'write', 'archetypes' => [ 'editingteacher' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ] + 'manager' => CAP_ALLOW, + ], ], - 'mod/ratingallocate:export_ratings' =>[ + 'mod/ratingallocate:export_ratings' => [ 'contextlevel' => CONTEXT_MODULE, 'riskbitmask' => RISK_PERSONAL, 'captype' => 'read', 'archetypes' => [ 'editingteacher' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ] + 'manager' => CAP_ALLOW, + ], ], - 'mod/ratingallocate:distribute_unallocated' =>[ + 'mod/ratingallocate:distribute_unallocated' => [ 'contextlevel' => CONTEXT_MODULE, 'riskbitmask' => RISK_PERSONAL, 'captype' => 'write', 'archetypes' => [ 'editingteacher' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ] + 'manager' => CAP_ALLOW, + ], ], ]; diff --git a/db/db_structure.php b/db/db_structure.php index 1095c0e7..4f248015 100644 --- a/db/db_structure.php +++ b/db/db_structure.php @@ -26,71 +26,237 @@ namespace ratingallocate\db; defined('MOODLE_INTERNAL') || die(); + +/** + * @class 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'; } +/** + * @class Ratingallocate choices + */ 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'; } + +/** + * @class ratingallocate_group_choices + */ class ratingallocate_group_choices { + /** + * Table. + */ const TABLE = 'ratingallocate_group_choices'; + /** + * Id. + */ const ID = 'id'; + /** + * Choiceid. + */ const CHOICEID = 'choiceid'; + /** + * Groupid. + */ const GROUPID = 'groupid'; } - +/** + * @class ratingallocate_ch_gengroups + */ class ratingallocate_ch_gengroups { + /** + * Table. + */ const TABLE = 'ratingallocate_ch_gengroups'; + /** + * Id. + */ const ID = 'id'; + /** + * Groupid. + */ const GROUPID = 'groupid'; + /** + * Choiceid. + */ const CHOICEID = 'choiceid'; } +/** + * @class ratingallocate_groupings Generated grouping by instance + */ class ratingallocate_groupings { + /** + * Table. + */ const TABLE = 'ratingallocate_groupings'; + /** + * Id. + */ const ID = 'id'; + /** + * Ratingallocateid. + */ const RATINGALLOCATEID = 'ratingallocateid'; + /** + * Groupingid. + */ const GROUPINGID = 'groupingid'; } +/** + * @class ratings (map user to choice) + */ 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'; } +/** + * @class allocations + */ 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 89e62273..134b9a65 100644 --- a/db/events.php +++ b/db/events.php @@ -29,17 +29,17 @@ defined('MOODLE_INTERNAL') || die(); -$handlers =[]; +$handlers = []; // List of observers for group_deleted and grouping_deleted. -$observers =[ +$observers = [ [ 'eventname' => '\core\event\group_deleted', 'callback' => 'mod_ratingallocate\ratingallocate_observer::ch_gengroups_delete', ], - [ + [ '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 b6b90567..dfcfb84e 100644 --- a/db/log.php +++ b/db/log.php @@ -29,9 +29,9 @@ global $DB; -$logs =[ +$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'] + ['module' => 'ratingallocate', 'action' => 'view all', 'mtable' => 'ratingallocate', 'field' => 'name'], ]; diff --git a/db/messages.php b/db/messages.php index 87a029ff..da7af966 100644 --- a/db/messages.php +++ b/db/messages.php @@ -25,9 +25,9 @@ defined('MOODLE_INTERNAL') || die(); -$messageproviders =[ +$messageproviders = [ // Notify student about published allocation. 'allocation' => [ - 'capability' => 'mod/ratingallocate:give_rating' - ] + 'capability' => 'mod/ratingallocate:give_rating', + ], ]; diff --git a/db/tasks.php b/db/tasks.php index a62fa401..8cc5a50f 100644 --- a/db/tasks.php +++ b/db/tasks.php @@ -25,7 +25,7 @@ defined('MOODLE_INTERNAL') || die(); -$tasks =[ +$tasks = [ [ 'classname' => 'mod_ratingallocate\task\cron_task', 'blocking' => 0, @@ -35,5 +35,5 @@ 'month' => '*', 'dayofweek' => '*', 'faildelay' => 1, - ] + ], ]; diff --git a/db/uninstall.php b/db/uninstall.php index fcf07ba7..7f69a2ad 100644 --- a/db/uninstall.php +++ b/db/uninstall.php @@ -23,7 +23,7 @@ */ /** - * Custom uninstallation procedure + * @function uninstall Custom uninstallation procedure */ function xmldb_ratingallocate_uninstall() { return true; diff --git a/db/upgrade.php b/db/upgrade.php index 5ce24b34..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',['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',['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 c6f815a4..2d854b7b 100644 --- a/form_manual_allocation.php +++ b/form_manual_allocation.php @@ -41,6 +41,9 @@ class manual_alloc_form extends moodleform { * Constant for the action */ const FORM_ACTION = 'action'; + /** + * Assign. + */ const ASSIGN = 'assign'; /** @@ -76,6 +79,8 @@ public function definition() { } /** + * Render filter. + * * @return void * @throws coding_exception * @throws dml_exception @@ -86,17 +91,17 @@ protected function render_filter() { $mform->addElement('advcheckbox', 'hide_users_without_rating', get_string('filter_hide_users_without_rating', RATINGALLOCATE_MOD_NAME), - null,[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,[0, 1]); + null, [0, 1]); $mform->setType('show_alloc_necessary', PARAM_BOOL); // Filter by group. $choicegroups = $this->ratingallocate->get_all_groups_of_choices(); - $allgroups =[]; + $allgroups = []; foreach ($choicegroups as $choicegroup) { $allgroups[$choicegroup] = groups_get_group($choicegroup); } @@ -122,7 +127,7 @@ public function definition_after_data() { $mform = &$this->_form; $ratingdata = $this->ratingallocate->get_ratings_for_rateable_choices(); - $differentratings =[]; + $differentratings = []; // Add actual rating data to userdata. foreach ($ratingdata as $rating) { if ($rating->rating != null) { @@ -185,13 +190,13 @@ public function add_special_action_buttons() { $mform = $this->_form; // Elements in a row need a group. - $buttonarray =[]; + $buttonarray = []; $buttonarray[] = &$mform->createElement('submit', 'submitbutton2', $submit2label); $buttonarray[] = &$mform->createElement('submit', 'submitbutton', $submitlabel); $buttonarray[] = &$mform->createElement('cancel'); - $mform->addGroup($buttonarray, 'buttonar', '',[' '], 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 cc33b763..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,7 +56,7 @@ public function __construct($url, ratingallocate $ratingallocate, if ($choice) { $this->choice = $choice; // Special handling for HTML editor. - $this->choice->explanation =[ + $this->choice->explanation = [ 'text' => $this->choice->explanation, 'format' => FORMAT_HTML, ]; @@ -82,7 +85,7 @@ public function definition() { 'maxlength', '255'); $elementname = 'explanation'; - $editoroptions =[ + $editoroptions = [ 'enable_filemanagement' => false, ]; $mform->addElement('editor', $elementname, get_string('choice_explanation', RATINGALLOCATE_MOD_NAME), $editoroptions); @@ -96,7 +99,7 @@ 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,[ + $mform->addElement('filemanager', $elementname, get_string('uploadafile'), null, [ 'accepted_types' => '*', 'subdirs' => false, ]); @@ -104,12 +107,12 @@ public function definition() { $elementname = 'active'; $mform->addElement('advcheckbox', $elementname, get_string('choice_active', RATINGALLOCATE_MOD_NAME), - null, null,[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,[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 =[]; + $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', '',[' '], false); + $mform->addGroup($buttonarray, 'buttonar', '', [' '], false); $mform->closeHeaderBefore('buttonar'); } diff --git a/index.php b/index.php index 0d1e57f6..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',['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,30 +55,30 @@ if (!$ratingallocates = get_all_instances_in_course('ratingallocate', $course, $USER->id)) { notice(get_string('noratingallocates', RATINGALLOCATE_MOD_NAME), - new moodle_url('/course/view.php',['id' => $course->id])); + new moodle_url('/course/view.php', ['id' => $course->id])); } $table = new html_table(); -$table->head =[ +$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 =['left', 'left', 'left', 'left']; +$table->align = ['left', 'left', 'left', 'left']; foreach ($ratingallocates as $ratingallocate) { - $ratingallocateinstance = $DB->get_record('ratingallocate',['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',['id' => $ratingallocate->coursemodule]), + new moodle_url('/mod/ratingallocate/view.php', ['id' => $ratingallocate->coursemodule]), format_string($ratingallocate->name, true), ['class' => 'dimmed']); } else { $link = html_writer::link( - new moodle_url('/mod/ratingallocate/view.php',['id' => $ratingallocate->coursemodule]), + new moodle_url('/mod/ratingallocate/view.php', ['id' => $ratingallocate->coursemodule]), format_string($ratingallocate->name, true)); } - $table->data[] =[$link, userdate($ratingallocateinstance->accesstimestart), + $table->data[] = [$link, userdate($ratingallocateinstance->accesstimestart), userdate($ratingallocateinstance->accesstimestop), $ratingallocateinstance->published == 0 ? get_string('no') : get_string('yes')]; diff --git a/lib.php b/lib.php index e815ce61..e3c521e4 100644 --- a/lib.php +++ b/lib.php @@ -159,19 +159,19 @@ function ratingallocate_update_instance(stdClass $ratingallocate, mod_ratingallo function ratingallocate_delete_instance($id) { global $DB; - if (!$ratingallocate = $DB->get_record('ratingallocate',[ - 'id' => $id + if (!$ratingallocate = $DB->get_record('ratingallocate', [ + 'id' => $id, ])) { return false; } // Delete any dependent records here # . - $DB->delete_records('ratingallocate_allocations',[ - 'ratingallocateid' => $ratingallocate->id + $DB->delete_records('ratingallocate_allocations', [ + 'ratingallocateid' => $ratingallocate->id, ]); - $deleteids = array_keys($DB->get_records('ratingallocate_choices',[ - 'ratingallocateid' => $ratingallocate->id + $deleteids = array_keys($DB->get_records('ratingallocate_choices', [ + 'ratingallocateid' => $ratingallocate->id, ], '', 'id')); if (!empty($deleteids)) { @@ -182,21 +182,21 @@ function ratingallocate_delete_instance($id) { 'choiceid ' . $insql, $params); } - $DB->delete_records('ratingallocate_groupings',[ - 'ratingallocateid' => $ratingallocate->id + $DB->delete_records('ratingallocate_groupings', [ + 'ratingallocateid' => $ratingallocate->id, ]); $DB->delete_records_list('ratingallocate_ratings', 'choiceid', $deleteids); - $DB->delete_records('ratingallocate_choices',[ - 'ratingallocateid' => $ratingallocate->id + $DB->delete_records('ratingallocate_choices', [ + 'ratingallocateid' => $ratingallocate->id, ]); // Delete associated events. - $DB->delete_records('event',['modulename' => 'ratingallocate', 'instance' => $ratingallocate->id]); + $DB->delete_records('event', ['modulename' => 'ratingallocate', 'instance' => $ratingallocate->id]); - $DB->delete_records('ratingallocate',[ - 'id' => $ratingallocate->id + $DB->delete_records('ratingallocate', [ + 'id' => $ratingallocate->id, ]); return true; @@ -569,7 +569,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 diff --git a/locallib.php b/locallib.php index 0b51d94e..a05fef8e 100644 --- a/locallib.php +++ b/locallib.php @@ -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'; /** @@ -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 */ @@ -291,6 +308,13 @@ private function process_action_start_distribution() { 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. @@ -311,6 +335,14 @@ private function delete_all_student_ratings() { 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; @@ -387,6 +419,13 @@ private function process_action_delete_rating() { 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)) { @@ -417,6 +456,15 @@ private function process_action_show_choices() { } + /** + * 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; @@ -607,6 +655,13 @@ private function process_action_delete_choice() { } } + /** + * Manual allocation. + * + * @return string + * @throws coding_exception + * @throws moodle_exception + */ private function process_action_manual_allocation() { // Manual allocation. $output = ''; @@ -897,7 +952,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 { @@ -957,6 +1013,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 = ''; // Print ratings table. @@ -981,6 +1044,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 = ''; // Print ratings table. @@ -1001,6 +1071,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. @@ -1021,6 +1098,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) { @@ -1038,6 +1122,14 @@ private function process_publish_allocations() { ['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(); @@ -1048,6 +1140,13 @@ private function process_action_allocation_to_grouping() { \core\output\notification::NOTIFY_SUCCESS); } + /** + * Process default. + * + * @return string + * @throws coding_exception + * @throws moodle_exception + */ private function process_default() { global $OUTPUT; $output = ''; @@ -1093,7 +1192,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; /** @@ -1265,7 +1364,7 @@ public function get_ratings_for_rateable_choices() { WHERE c.ratingallocateid = :ratingallocateid AND c.active = 1'; $ratings = $this->db->get_records_sql($sql, [ - 'ratingallocateid' => $this->ratingallocateid + 'ratingallocateid' => $this->ratingallocateid, ]); $raters = $this->get_raters_in_course(); @@ -1409,7 +1508,7 @@ public function publish_allocation() { // Add custom data. $task->set_component('mod_ratingallocate'); $task->set_custom_data([ - 'ratingallocateid' => $this->ratingallocateid + 'ratingallocateid' => $this->ratingallocateid, ]); // Queue it. @@ -1440,7 +1539,7 @@ public function get_ratings_for_rateable_choices_for_raters_without_alloc() { WHERE al.ratingallocateid = :ratingallocateid'; $allocated = $this->db->get_records_sql($sql, [ - 'ratingallocateid' => $this->ratingallocateid + 'ratingallocateid' => $this->ratingallocateid, ]); $ratings = $this->get_ratings_for_rateable_choices(); // Macht daraus ein Array mit userid => quatsch. @@ -1456,8 +1555,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 @@ -1489,7 +1591,7 @@ public function get_allocations() { 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, [ - 'ratingallocateid' => $this->ratingallocateid + 'ratingallocateid' => $this->ratingallocateid, ]); return $records; } @@ -1615,7 +1717,7 @@ public function get_rating_data_for_user($userid) { ORDER by c.title"; return $this->db->get_records_sql($sql, [ 'ratingallocateid' => $this->ratingallocateid, - 'userid' => $userid + 'userid' => $userid, ]); } @@ -1630,7 +1732,7 @@ public function get_users_with_ratings() { ON c.id = r.choiceid WHERE c.ratingallocateid = :ratingallocateid AND c.active = 1"; return $this->db->get_records_sql($sql, [ - 'ratingallocateid' => $this->ratingallocateid + 'ratingallocateid' => $this->ratingallocateid, ]); } @@ -1647,7 +1749,7 @@ public function delete_all_ratings() { foreach ($choices as $id => $choice) { $data = [ - 'choiceid' => $id + 'choiceid' => $id, ]; // Delete the allocations associated with this rating. @@ -1684,7 +1786,7 @@ public function delete_ratings_of_user($userid) { foreach ($choices as $id => $choice) { $data = [ 'userid' => $userid, - 'choiceid' => $id + 'choiceid' => $id, ]; // Actually delete the rating. @@ -1718,7 +1820,7 @@ public function save_ratings_to_db($userid, array $data) { $ratingexists = [ 'choiceid' => $rdata['choiceid'], - 'userid' => $userid + 'userid' => $userid, ]; if ($DB->record_exists('ratingallocate_ratings', $ratingexists)) { // The rating exists, we need to update its value @@ -1854,7 +1956,7 @@ public function get_allocations_for_user($userid) { return $this->db->get_records_sql($sql, [ 'ratingallocateid' => $this->ratingallocateid, - 'userid' => $userid + 'userid' => $userid, ]); } @@ -1894,6 +1996,13 @@ 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 { @@ -1932,7 +2041,7 @@ public function save_modify_choice_form($data) { public function remove_allocation($choiceid, $userid) { $this->db->delete_records('ratingallocate_allocations', [ 'choiceid' => $choiceid, - 'userid' => $userid + 'userid' => $userid, ]); return true; } @@ -1945,7 +2054,7 @@ public function remove_allocation($choiceid, $userid) { public function remove_allocations($userid) { $this->db->delete_records('ratingallocate_allocations', [ 'userid' => $userid, - 'ratingallocateid' => $this->ratingallocateid + 'ratingallocateid' => $this->ratingallocateid, ]); } @@ -1959,7 +2068,7 @@ public function add_allocation($choiceid, $userid) { $this->db->insert_record_raw('ratingallocate_allocations', [ 'choiceid' => $choiceid, 'userid' => $userid, - 'ratingallocateid' => $this->ratingallocateid + 'ratingallocateid' => $this->ratingallocateid, ]); return true; } @@ -1975,7 +2084,7 @@ public function alter_allocation($oldchoiceid, $newchoiceid, $userid) { $this->db->set_field(this_db\ratingallocate_allocations::TABLE, this_db\ratingallocate_allocations::CHOICEID, $newchoiceid, [ 'choiceid' => $oldchoiceid, - 'userid' => $userid + 'userid' => $userid, ] ); return true; @@ -2100,7 +2209,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() { @@ -2191,6 +2302,8 @@ public function update_choice_groups($choiceid, $groupids) { } /** + * Is the setup ok? + * * @return bool true, if all strategy settings are ok. */ public function is_setup_ok() { @@ -2207,6 +2320,8 @@ public function is_setup_ok() { } /** + * Get File attachments. + * * @param int choiceid * @return array of file objects. */ @@ -2300,6 +2415,11 @@ public function __set($name, $value) { $this->dbrecord->{$name} = $value; } + /** + * Construct. + * + * @param $record + */ public function __construct($record) { $this->dbrecord = $record; } @@ -2336,6 +2456,11 @@ public function __set($name, $value) { $this->dbrecord->{$name} = $value; } + /** + * Construct. + * + * @param $record + */ public function __construct($record) { $this->dbrecord = $record; } diff --git a/mod_form.php b/mod_form.php index ad9eaeef..1dbce8d1 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,8 +86,8 @@ 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),[ - 'size' => '64' + $mform->addElement('text', 'name', get_string('ratingallocatename', self::MOD_NAME), [ + 'size' => '64', ]); if (!empty($CFG->formatstringstriptags)) { $mform->setType('name', PARAM_TEXT); @@ -90,7 +104,7 @@ public function definition() { // ------------------------------------------------------------------------------- $elementname = 'strategy'; // Define options for select. - $selectoptions =[]; + $selectoptions = []; foreach (\strategymanager::get_strategies() as $strategy) { $selectoptions[$strategy] = get_string($strategy . '_name', self::MOD_NAME); } @@ -116,7 +130,7 @@ public function definition() { $mform->setDefault($elementname, time() + 9 * 24 * 60 * 60); $elementname = 'runalgorithmbycron'; - $mform->addElement('advcheckbox', $elementname, get_string($elementname, self::MOD_NAME), null, null,[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',['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 01da7359..9bb68e34 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 =[]; + 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 @@ -105,9 +109,9 @@ public function render_ratingallocate_choice_status(ratingallocate_choice_status } else { $cell2 = new html_table_cell(format_time($duedate - $time)); } - $row->cells =[ + $row->cells = [ $cell1, - $cell2 + $cell2, ]; $t->data[] = $row; } @@ -136,31 +140,31 @@ 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 =[]; + $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 =[ + $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 =[]; + $choiceshtml = []; foreach ($status->ownchoices as $choice) { array_push($choiceshtml, format_string($choice->title)); } $cell2 = new html_table_cell(html_writer::alist($choiceshtml)); - $row->cells =[ + $row->cells = [ $cell1, - $cell2 + $cell2, ]; $t->data[] = $row; } @@ -187,7 +191,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 =[$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. @@ -452,7 +456,7 @@ public function ratingallocate_show_choices_table(ratingallocate $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') + 'tooltip' => get_string('csvupload_explanation', 'ratingallocate'), ]); // Set up the table. 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 7044f6c6..3247ef34 100644 --- a/solver/edmonds-karp.php +++ b/solver/edmonds-karp.php @@ -28,14 +28,27 @@ require_once(dirname(__FILE__) . '/../locallib.php'); require_once(dirname(__FILE__) . '/solver-template.php'); +/** + * @class solver_edmonds_karp + */ class solver_edmonds_karp extends distributor { + /** + * @return string + */ public function get_name() { return 'edmonds_karp'; } + /** + * @param $choicerecords + * @param $ratings + * @param $usercount + * @return an|array + * @throws moodle_exception + */ public function compute_distribution($choicerecords, $ratings, $usercount) { - $choicedata =[]; + $choicedata = []; foreach ($choicerecords as $record) { $choicedata[$record->id] = $record; } @@ -71,9 +84,9 @@ public function compute_distribution($choicerecords, $ratings, $usercount) { */ private function find_shortest_path_bellf($from, $to) { // Table of distances known so far. - $dists =[]; + $dists = []; // Table of predecessors (used to reconstruct the shortest path later). - $preds =[]; + $preds = []; // Number of nodes in the graph. $count = $this->graph['count']; @@ -116,7 +129,7 @@ private function find_shortest_path_bellf($from, $to) { unset($dists); // Use the preds table to reconstruct the shortest path. - $path =[]; + $path = []; $p = $to; while ($p != $from) { $path[] = $p; diff --git a/solver/export_lp_solve.php b/solver/export_lp_solve.php index 3e69d794..4a006b39 100644 --- a/solver/export_lp_solve.php +++ b/solver/export_lp_solve.php @@ -35,7 +35,7 @@ $cm = get_coursemodule_from_id('ratingallocate', $id, 0, false, MUST_EXIST); $course = get_course($cm->course); $ratingallocate = $DB->get_record('ratingallocate', [ - 'id' => $cm->instance + '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 */ diff --git a/solver/ford-fulkerson-koegel.php b/solver/ford-fulkerson-koegel.php index 78224f42..2d77858a 100644 --- a/solver/ford-fulkerson-koegel.php +++ b/solver/ford-fulkerson-koegel.php @@ -30,6 +30,9 @@ require_once(dirname(__FILE__) . '/../locallib.php'); require_once(dirname(__FILE__) . '/solver-template.php'); +/** + * @class solver_ford_fulkerson + */ class solver_ford_fulkerson extends distributor { /** @@ -152,6 +155,9 @@ public function find_shortest_path_bellmanf_koegel($from, $to) { return $path; } + /** + * @return string + */ public function get_name() { return "ford-fulkerson Koegel2014"; } diff --git a/solver/solver-template.php b/solver/solver-template.php index 4fed963b..85e09f90 100644 --- a/solver/solver-template.php +++ b/solver/solver-template.php @@ -32,6 +32,9 @@ */ defined('MOODLE_INTERNAL') || die(); +/** + * @class edge + */ class edge { /** @var from int */ public $from; @@ -42,6 +45,12 @@ class edge { /** @var space int (places left for choices) */ public $space; + /** + * @param $from + * @param $to + * @param $weight + * @param $space + */ public function __construct($from, $to, $weight, $space = 0) { $this->from = $from; $this->to = $to; @@ -121,10 +130,10 @@ public function distribute_users(\ratingallocate $ratingallocate) { * @return an array of the form array(groupid => array(userid, ...), ...) */ protected function extract_allocation($touserid, $tochoiceid) { - $distribution =[]; + $distribution = []; foreach ($tochoiceid as $index => $groupid) { $group = $this->graph[$index]; - $distribution[$groupid] =[]; + $distribution[$groupid] = []; foreach ($group as $assignment) { $user = intval($assignment->to); if (array_key_exists($user, $touserid)) { @@ -144,12 +153,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 =[]; - $touserid =[]; + $fromuserid = []; + $touserid = []; // These tables convert choiceids to their index in the graph // The range is [$usercount + 1 .. $usercount + $choicecount]. - $fromchoiceid =[]; - $tochoiceid =[]; + $fromchoiceid = []; + $tochoiceid = []; // User counter. $ui = 1; @@ -191,19 +200,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 =[]; + $this->graph = []; // Add source, sink and number of nodes to the graph. - $this->graph[$source] =[]; - $this->graph[$sink] =[]; + $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] =[]; + $this->graph[$user] = []; $this->graph[$source][] = new edge($source, $user, 0); } foreach ($fromchoiceid as $id => $choice) { - $this->graph[$choice] =[]; + $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 a0a91577..ab34342d 100644 --- a/strategy/strategy01_yes_no.php +++ b/strategy/strategy01_yes_no.php @@ -33,10 +33,21 @@ require_once(dirname(__FILE__) . '/../locallib.php'); require_once(dirname(__FILE__) . '/strategy_template_options.php'); +/** + * Strategy + * + * @class strategy + */ 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; @@ -48,15 +59,15 @@ public function get_static_settingfields() { '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] = [ '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(); @@ -70,7 +81,7 @@ public function get_dynamic_settingfields() { public function get_choiceoptions() { $options = [ 0 => $this->get_settings_value(0), - 1 => $this->get_settings_value(1) + 1 => $this->get_settings_value(1), ]; return $options; } @@ -92,6 +103,11 @@ protected function getvalidationinfo() { // Register with the strategymanager. \strategymanager::add_strategy(strategy::STRATEGYID); +/** + * View form + * + * @class mod_ratingallocate_view_form + */ 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 121cba63..399b0542 100644 --- a/strategy/strategy02_yes_maybe_no.php +++ b/strategy/strategy02_yes_maybe_no.php @@ -34,9 +34,18 @@ require_once(dirname(__FILE__) . '/../locallib.php'); require_once(dirname(__FILE__) . '/strategy_template_options.php'); +/** + * @class strategy + */ class strategy extends \strategytemplate_options { + /** + * Strategyid. + */ const STRATEGYID = 'strategy_yesmaybeno'; + /** + * Maximal votes for no. + */ const MAXNO = 'maxno'; public function get_strategyid() { @@ -49,34 +58,50 @@ public function get_static_settingfields() { '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] = [ '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 []; } + /** + * Get choiceoptions. + * + * @return array + */ public function get_choiceoptions() { $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 [ self::MAXNO => 3, @@ -87,6 +112,11 @@ public function get_default_settings() { ]; } + /** + * Get validation info. + * + * @return array[] + */ protected function getvalidationinfo() { return [self::MAXNO => [true, 0]]; } @@ -95,6 +125,9 @@ protected function getvalidationinfo() { // Register with the strategymanager. \strategymanager::add_strategy(strategy::STRATEGYID); +/** + * @class mod_ratingallocate_view_form + */ 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 b8a9fbf1..d80bb789 100644 --- a/strategy/strategy03_lickert.php +++ b/strategy/strategy03_lickert.php @@ -33,11 +33,25 @@ require_once(dirname(__FILE__) . '/../locallib.php'); require_once(dirname(__FILE__) . '/strategy_template_options.php'); +/** + * Strategy + * @class strategy + */ 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) { @@ -59,14 +73,14 @@ public function get_static_settingfields() { 'int', get_string(self::STRATEGYID . '_setting_maxno', RATINGALLOCATE_MOD_NAME), $this->get_settings_value(self::MAXNO), - null + 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, + ], ]; } @@ -77,13 +91,18 @@ public function get_dynamic_settingfields() { '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 = []; for ($i = 0; $i <= $this->maxlickert; $i++) { @@ -92,6 +111,12 @@ public function get_choiceoptions() { return $options; } + /** + * Get default settings. + * + * @return array + * @throws \coding_exception + */ public function get_default_settings() { $defaults = [ self::MAXNO => 3, @@ -110,9 +135,14 @@ public function get_default_settings() { return $defaults; } + /** + * Get validation info. + * + * @return array[] + */ protected function getvalidationinfo() { return [self::MAXNO => [true, 0], - self::COUNTLICKERT => [true, 2] + self::COUNTLICKERT => [true, 2], ]; } } @@ -120,6 +150,11 @@ protected function getvalidationinfo() { // Register with the strategymanager. \strategymanager::add_strategy(strategy::STRATEGYID); +/** + * View form. + * + * @class mod_ratinallocate_view_form + */ 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 5e5bdeb6..730d11b4 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 + * + * @class strategy + */ 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() { @@ -51,20 +68,20 @@ public function get_static_settingfields() { 'int', get_string(self::STRATEGYID . '_setting_maxzero', RATINGALLOCATE_MOD_NAME), $this->get_settings_value(self::MAXZERO), - null + null, ], self::TOTALPOINTS => [ // Amount of fields. 'int', get_string(self::STRATEGYID . '_setting_totalpoints', RATINGALLOCATE_MOD_NAME), $this->get_settings_value(self::TOTALPOINTS), - null + null, ], - self::MAXPERCHOICE => [// Maximum amount of points the student can give per choice. + 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, + ], ]; } @@ -76,14 +93,14 @@ public function get_default_settings() { return [ self::MAXZERO => 3, self::TOTALPOINTS => 100, - self::MAXPERCHOICE => 100 + self::MAXPERCHOICE => 100, ]; } protected function getvalidationinfo() { return [self::MAXZERO => [true, 0], self::TOTALPOINTS => [true, 1], - self::MAXPERCHOICE => [true, 1] + self::MAXPERCHOICE => [true, 1], ]; } @@ -92,6 +109,11 @@ protected function getvalidationinfo() { // Register with the strategymanager. \strategymanager::add_strategy(strategy::STRATEGYID); +/** + * View form. + * + * @class mod_ratingallocate_view_form + */ 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 9294b094..04fdfc39 100644 --- a/strategy/strategy05_order.php +++ b/strategy/strategy05_order.php @@ -33,9 +33,18 @@ require_once(dirname(__FILE__) . '/../locallib.php'); require_once(dirname(__FILE__) . '/strategy_template.php'); +/** + * @class strategy + */ class strategy extends \strategytemplate { + /** + * Strategyid. + */ const STRATEGYID = 'strategy_order'; + /** + * Countoptions. + */ const COUNTOPTIONS = 'countoptions'; public function get_strategyid() { @@ -48,8 +57,8 @@ public function get_static_settingfields() { 'int', get_string(self::STRATEGYID . '_setting_countoptions', RATINGALLOCATE_MOD_NAME), $this->get_settings_value(self::COUNTOPTIONS), - null - ] + null, + ], ]; } @@ -60,7 +69,7 @@ public function get_dynamic_settingfields() { public function get_default_settings() { $defaultcountoptions = 2; $output = [ - self::COUNTOPTIONS => $defaultcountoptions + self::COUNTOPTIONS => $defaultcountoptions, ]; $countoptions = $this->get_settings_value(self::COUNTOPTIONS, false); if (is_null($countoptions)) { diff --git a/strategy/strategy06_tickyes.php b/strategy/strategy06_tickyes.php index 47829e64..83fcc10a 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. + * + * @class strategy + */ 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() { @@ -48,16 +62,15 @@ public function get_static_settingfields() { $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] = [ '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; } @@ -74,7 +87,7 @@ public function get_default_settings() { 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), ]; } diff --git a/strategy/strategy_template.php b/strategy/strategy_template.php index de66821b..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(); /** @@ -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; /** @@ -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 51ec8b7e..5d2a2b7b 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. + * + * @class strategytemplate_options + */ abstract class strategytemplate_options extends \strategytemplate { /** @@ -48,7 +53,7 @@ protected function get_default_strategy_option() { get_string('strategy_settings_default', RATINGALLOCATE_MOD_NAME), $this->get_settings_value('default'), $this->get_choiceoptions(), - 'strategy_settings_default' + 'strategy_settings_default', ]]; } } diff --git a/tests/backup_restore_test.php b/tests/backup_restore_test.php index 3d93aa4a..d15d827b 100644 --- a/tests/backup_restore_test.php +++ b/tests/backup_restore_test.php @@ -74,7 +74,7 @@ public function test_backup_restore() { $unsetvalues = function($elem1, $elem2, $varname) { $this->assertNotEquals($elem1->{$varname}, $elem2->{$varname}); - $result =[$elem1->{$varname}, $elem2->{$varname}]; + $result = [$elem1->{$varname}, $elem2->{$varname}]; unset($elem1->{$varname}); unset($elem2->{$varname}); return $result; diff --git a/tests/behat/behat_mod_ratingallocate.php b/tests/behat/behat_mod_ratingallocate.php index d1da183d..0fb2eba1 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 { /** @@ -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. diff --git a/tests/cron_test.php b/tests/cron_test.php index 23daa142..4369ab4a 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; // @@ -197,7 +199,7 @@ private function create_ratingallocate($ratingperiodended, // There should not be any module for that course first. $this->assertFalse( - $DB->record_exists(this_db\ratingallocate::TABLE, [this_db\ratingallocate::COURSE => $course->id + $DB->record_exists(this_db\ratingallocate::TABLE, [this_db\ratingallocate::COURSE => $course->id, ])); $data = \mod_ratingallocate_generator::get_default_values(); $data['course'] = $course; diff --git a/tests/generator/lib.php b/tests/generator/lib.php index 9bbc5f56..f3b53f10 100644 --- a/tests/generator/lib.php +++ b/tests/generator/lib.php @@ -14,6 +14,12 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +/** + * Library for Tests + * + * @package mod_ratingallocate + */ + defined('MOODLE_INTERNAL') || die(); require_once(dirname(__FILE__) . '/../../locallib.php'); @@ -84,6 +90,7 @@ public static function get_default_values() { return self::$defaultvalue; } + /** @var $defaultvalue */ private static $defaultvalue; public static function get_default_choice_data() { @@ -96,13 +103,14 @@ public static function get_default_choice_data() { ['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,7 +129,7 @@ public static function create_user_and_enrol(advanced_testcase $tc, $course, $is global $DB; // Enrol teacher and student. self::$teacherrole = $DB->get_record('role', - ['shortname' => 'editingteacher' + ['shortname' => 'editingteacher', ]); } $enroled = $tc->getDataGenerator()->enrol_user($user->id, $course->id, @@ -133,6 +141,7 @@ public static function create_user_and_enrol(advanced_testcase $tc, $course, $is return $user; } + /** @var $teacherrole */ private static $teacherrole; /** @@ -210,13 +219,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; + /** @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; /** @@ -249,7 +270,7 @@ public function __construct(advanced_testcase $tc, $moduledata = null, $choiceda if ($assertintermediateresult) { $tc->assertFalse( $DB->record_exists(this_db\ratingallocate::TABLE, - [this_db\ratingallocate::COURSE => $this->course->id + [this_db\ratingallocate::COURSE => $this->course->id, ]), 'There should not be any module for that course first'); } @@ -271,7 +292,7 @@ public function __construct(advanced_testcase $tc, $moduledata = null, $choiceda if ($choice->title == $singlerating['choice']) { $ratingdata[] = [ 'rating' => $singlerating['rating'], - 'choiceid' => $choice->id + 'choiceid' => $choice->id, ]; } } @@ -302,7 +323,7 @@ public function __construct(advanced_testcase $tc, $moduledata = null, $choiceda $moduledata['ratings'] = []; for ($i = 0; $i < $numstudents; $i++) { $moduledata['ratings'][$i] = [ - $choicesnummerated[$i % $numchoices]->{this_db\ratingallocate_choices::TITLE} => 1 + $choicesnummerated[$i % $numchoices]->{this_db\ratingallocate_choices::TITLE} => 1, ]; } } @@ -314,7 +335,7 @@ public function __construct(advanced_testcase $tc, $moduledata = null, $choiceda foreach ($choices as $choice) { $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}; } diff --git a/tests/locallib_test.php b/tests/locallib_test.php index aae0e8f0..1f9e9a13 100644 --- a/tests/locallib_test.php +++ b/tests/locallib_test.php @@ -254,29 +254,29 @@ public function test_reset_userdata() { 'title' => 'C2', 'maxsize' => '1', 'active' => '1', - ] + ], ]; $ratings = [ $student1->id => [ [ 'choice' => 'C1', - 'rating' => 1 + 'rating' => 1, ], [ 'choice' => 'C2', - 'rating' => 0 - ] + 'rating' => 0, + ], ], $student2->id => [ [ 'choice' => 'C1', - 'rating' => 0 + 'rating' => 0, ], [ 'choice' => 'C2', - 'rating' => 1 - ] - ] + 'rating' => 1, + ], + ], ]; // Create ratingallocate instance. diff --git a/tests/mod_generator_test.php b/tests/mod_generator_test.php index d694b9a8..40d6669a 100644 --- a/tests/mod_generator_test.php +++ b/tests/mod_generator_test.php @@ -42,7 +42,7 @@ public function test_create_instance() { // There should not be any module for that course first. $this->assertFalse( - $DB->record_exists('ratingallocate',['course' => $course->id + $DB->record_exists('ratingallocate',['course' => $course->id, ])); $records = $DB->get_records('ratingallocate_choices', [], 'id'); $this->assertEquals(0, count($records)); @@ -50,7 +50,7 @@ public function test_create_instance() { // Create activity. $mod = \mod_ratingallocate_generator::create_instance_with_choices($this, ['course' => $course]); - $records = $DB->get_records('ratingallocate', ['course' => $course->id + $records = $DB->get_records('ratingallocate', ['course' => $course->id, ], 'id'); $this->assertEquals(1, count($records)); $this->assertTrue(array_key_exists($mod->id, $records)); @@ -71,13 +71,13 @@ 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', - ['ratingallocateid' => $mod->id + ['ratingallocateid' => $mod->id, ], 'title'); $this->assertEquals(2, count($records)); $choiceids = array_keys($records); @@ -89,7 +89,7 @@ public function test_create_instance() { 'explanation' => 'Some explanatory text for choice 1', 'maxsize' => '10', 'usegroups' => '0', - 'active' => '1' + 'active' => '1', ], $choiceids[1] => (object) [ 'title' => 'Choice 2', @@ -98,16 +98,16 @@ public function test_create_instance() { '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 = ['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', ['course' => $course->id + $records = $DB->get_records('ratingallocate', ['course' => $course->id, ], 'id'); // Are there 2 modules within the course? $this->assertEquals(2, 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 681efbd9..3b7399f7 100644 --- a/tests/mod_ratingallocate_choice_groups_test.php +++ b/tests/mod_ratingallocate_choice_groups_test.php @@ -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 */ @@ -168,13 +172,13 @@ public function test_choice_groups() { * Choice E: 'usegroups' is not selected; always available. */ $this->ratingallocate->update_choice_groups($choiceidmap['Choice A'], [ - $groupidmap['Green Group'] + $groupidmap['Green Group'], ]); $this->ratingallocate->update_choice_groups($choiceidmap['Choice B'], [ - $groupidmap['Green Group'], $groupidmap['Blue Group'] + $groupidmap['Green Group'], $groupidmap['Blue Group'], ]); $this->ratingallocate->update_choice_groups($choiceidmap['Choice C'], [ - $groupidmap['Red Group'] + $groupidmap['Red Group'], ]); // Teacher context: all choices shown in teacher view. @@ -238,14 +242,14 @@ public function test_update_choice_groups() { // Add one. $this->ratingallocate->update_choice_groups($choiceidmap['Choice A'], [ - $groupidmap['Green Group'] + $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'], [ - $groupidmap['Green Group'], $groupidmap['Blue Group'] + $groupidmap['Green Group'], $groupidmap['Blue Group'], ]); $groups = $this->ratingallocate->get_choice_groups($choiceidmap['Choice A']); $this->assertContains($groupidmap['Green Group'], array_keys($groups)); @@ -253,7 +257,7 @@ public function test_update_choice_groups() { // Remove one. $this->ratingallocate->update_choice_groups($choiceidmap['Choice A'], [ - $groupidmap['Blue Group'] + $groupidmap['Blue Group'], ]); $groups = $this->ratingallocate->get_choice_groups($choiceidmap['Choice A']); $this->assertNotContains($groupidmap['Green Group'], array_keys($groups)); diff --git a/tests/mod_ratingallocate_choice_importer_test.php b/tests/mod_ratingallocate_choice_importer_test.php index 3dc3f4c3..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 =[]; + $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'; @@ -67,7 +67,7 @@ protected function setUp(): void { $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,['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',['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',['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,7 +208,7 @@ 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',[ + $this->assertEquals($importstatus->errors[0], get_string('csvupload_missing_groups', 'ratingallocate', [ 'row' => 5, 'invalidgroups' => 'Blue Man Group', ])); diff --git a/tests/mod_ratingallocate_notification_test.php b/tests/mod_ratingallocate_notification_test.php index 8acc597d..30501047 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,7 +44,7 @@ class mod_ratingallocate_notification_test extends \advanced_testcase { */ public function test_allocation_notification() { $course = $this->getDataGenerator()->create_course(); - $students =[]; + $students = []; for ($i = 1; $i <= 4; $i++) { $students[$i] = \mod_ratingallocate_generator::create_user_and_enrol($this, $course); } @@ -52,38 +58,38 @@ public function test_allocation_notification() { 'title' => self::CHOICE2, 'maxsize' => '1', 'active' => '1', - ] + ], ]; $ratings = [ $students[1]->id => [ [ 'choice' => self::CHOICE1, - 'rating' => 1 + 'rating' => 1, ], [ 'choice' => self::CHOICE2, - 'rating' => 0 - ] + 'rating' => 0, + ], ], $students[2]->id => [ [ 'choice' => self::CHOICE1, - 'rating' => 0 + 'rating' => 0, ], [ 'choice' => self::CHOICE2, - 'rating' => 1 - ] + 'rating' => 1, + ], ], $students[3]->id => [ [ 'choice' => self::CHOICE1, - 'rating' => 0 + 'rating' => 0, ], [ 'choice' => self::CHOICE2, - 'rating' => 0 - ] + 'rating' => 0, + ], ] ]; @@ -106,7 +112,7 @@ public function test_allocation_notification() { // Add custom data. $task->set_component('mod_ratingallocate'); $task->set_custom_data([ - 'ratingallocateid' => $ratingallocate->ratingallocate->id + 'ratingallocateid' => $ratingallocate->ratingallocate->id, ]); $this->setAdminUser(); diff --git a/tests/mod_ratingallocate_privacy_provider_test.php b/tests/mod_ratingallocate_privacy_provider_test.php index 066fbdf6..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,11 +202,11 @@ 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 =[ - 'ratingallocateid' => $this->testmodule->moddb->id + $params1 = [ + 'ratingallocateid' => $this->testmodule->moddb->id, ]; $params2 = [ - 'ratingallocateid' => $testmodule2->moddb->id + 'ratingallocateid' => $testmodule2->moddb->id, ]; // Before deletion, we should have 20 responses and 10 allocations in instance 1. diff --git a/tests/mod_ratingallocate_processor_test.php b/tests/mod_ratingallocate_processor_test.php index 0f7c733c..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], ]; } @@ -171,10 +171,10 @@ public function test_ratings_table_groupfilter() { * Choice C: ratable by all students */ $ratingallocate->update_choice_groups($choiceidmap['Choice A'], [ - $groupidmap['group1'] + $groupidmap['group1'], ]); $ratingallocate->update_choice_groups($choiceidmap['Choice B'], [ - $groupidmap['group2'] + $groupidmap['group2'], ]); // Test the group filter only (set hidenorating and showalloccount to false). @@ -254,7 +254,7 @@ private function get_choice_data() { 'explanation' => "Ratable by group1", 'maxsize' => 10, 'active' => true, - 'usegroups' => true + 'usegroups' => true, ]; $choicedata[] = $choice1; $choice2 = [ @@ -262,7 +262,7 @@ private function get_choice_data() { 'explanation' => "Ratable by group2", 'maxsize' => 10, 'active' => true, - 'usegroups' => true + 'usegroups' => true, ]; $choicedata[] = $choice2; $choice3 = [ @@ -270,7 +270,7 @@ private function get_choice_data() { '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 321c5344..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 @@ -131,6 +131,8 @@ public function teston_random() { } /** + * Test Edmonds-Karp algorithm. + * * @return void * @covers \solver_edmonds_karp */ @@ -206,6 +208,8 @@ public function test_edmondskarp() { } /** + * Test algorithm for negativeweightcycle. + * * @return void */ public function test_negweightcycle() { @@ -254,6 +258,8 @@ public function test_negweightcycle() { } /** + * Test tagetfunction. + * * @return void */ public function test_targetfunc() { diff --git a/tests/mod_ratingallocate_status_test.php b/tests/mod_ratingallocate_status_test.php index bf451872..0ffc3ded 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,7 +41,9 @@ public function setUp(): void { } /** - * @return array the different testing scenarios. + * Provider. + * + * @return array|Iterable|Generator the different testing scenarios. */ public function ratingallocate_provider() { return [ @@ -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,7 +80,7 @@ public function ratingallocate_provider() { * @covers ::get_status() */ public function test_get_status($addtostart, $addtostop, $published, $hasallocations, $expected) { - $record =[ + $record = [ 'name' => 'Rating Allocation', 'accesstimestart' => time() + ($addtostart * 24 * 60 * 60), 'accesstimestop' => time() + ($addtostop * 24 * 60 * 60), diff --git a/tests/mod_ratingallocate_strategy_test.php b/tests/mod_ratingallocate_strategy_test.php index 508e83cf..f9eb08d7 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 { /**