diff --git a/calendar/classes/local/event/forms/create.php b/calendar/classes/local/event/forms/create.php index 4003c497b0a..c5e21e288a1 100644 --- a/calendar/classes/local/event/forms/create.php +++ b/calendar/classes/local/event/forms/create.php @@ -1,5 +1,4 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - * @package calendar */ namespace core_calendar\local\event\forms; @@ -55,7 +53,7 @@ class create extends \moodleform { $this->add_default_hidden_elements($mform); // Event name field. - $mform->addElement('text', 'name', get_string('eventname','calendar'), 'size="50"'); + $mform->addElement('text', 'name', get_string('eventname', 'calendar'), 'size="50"'); $mform->addRule('name', get_string('required'), 'required', null, 'client'); $mform->setType('name', PARAM_TEXT); @@ -65,10 +63,10 @@ class create extends \moodleform { // Add the select elements for the available event types. $this->add_event_type_elements($mform, $eventtypes); - // ********* START OF ADVANCED ELEMENTS *********. - // Advanced elements are not visible to the user by default. They are - // displayed through the user of a show more / less button. - $mform->addElement('editor', 'description', get_string('eventdescription','calendar'), ['rows' => 3]); + // Start of advanced elements. + // Advanced elements are not visible to the user by default. + // They are displayed through the user of a show more / less button. + $mform->addElement('editor', 'description', get_string('eventdescription', 'calendar'), ['rows' => 3]); $mform->setType('description', PARAM_RAW); $mform->setAdvanced('description'); @@ -78,8 +76,8 @@ class create extends \moodleform { // Add the form elements for repeating events. $this->add_event_repeat_elements($mform); - // Add the javascript required to enhance this mform. Including the show/hide of advanced elements - // and the display of the correct select elements for chosen event types. + // Add the javascript required to enhance this mform. + // Including the show/hide of advanced elements and the display of the correct select elements for event types. $PAGE->requires->js_call_amd('core_calendar/event_form', 'init', [$mform->getAttribute('id'), $haserror]); } @@ -125,7 +123,7 @@ class create extends \moodleform { protected function add_default_hidden_elements($mform) { global $USER; - // Add some hidden fields + // Add some hidden fields. $mform->addElement('hidden', 'id'); $mform->setType('id', PARAM_INT); $mform->setDefault('id', 0); @@ -260,7 +258,7 @@ class create extends \moodleform { $mform->disabledIf('timedurationuntil[minute]', 'duration', 'noteq', 1); $mform->setType('timedurationminutes', PARAM_INT); - $mform->disabledIf('timedurationminutes','duration','noteq', 2); + $mform->disabledIf('timedurationminutes', 'duration', 'noteq', 2); $mform->setDefault('duration', 0); } @@ -276,7 +274,7 @@ class create extends \moodleform { $mform->addElement('text', 'repeats', get_string('repeatweeksl', 'calendar'), 'maxlength="10" size="10"'); $mform->setType('repeats', PARAM_INT); $mform->setDefault('repeats', 1); - $mform->disabledIf('repeats','repeat','notchecked'); + $mform->disabledIf('repeats', 'repeat', 'notchecked'); $mform->setAdvanced('repeat'); $mform->setAdvanced('repeats'); } diff --git a/calendar/classes/local/event/forms/update.php b/calendar/classes/local/event/forms/update.php index ec8905b1185..9096b65394a 100644 --- a/calendar/classes/local/event/forms/update.php +++ b/calendar/classes/local/event/forms/update.php @@ -1,5 +1,4 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - * @package calendar */ namespace core_calendar\local\event\forms; @@ -39,9 +37,7 @@ class update extends create { /** * Add the repeat elements for the form when editing an existing event. * - * @method add_event_repeat_elements * @param MoodleQuickForm $mform - * @param stdClass $event The event properties */ protected function add_event_repeat_elements($mform) { $event = $this->_customdata['event']; @@ -50,7 +46,8 @@ class update extends create { $mform->setType('repeatid', PARAM_INT); $group = []; - $group[] = $mform->createElement('radio', 'repeateditall', null, get_string('repeateditall', 'calendar', $event->eventrepeats), 1); + $group[] = $mform->createElement('radio', 'repeateditall', null, get_string('repeateditall', 'calendar', + $event->eventrepeats), 1); $group[] = $mform->createElement('radio', 'repeateditall', null, get_string('repeateditthis', 'calendar'), 0); $mform->addGroup($group, 'repeatgroup', get_string('repeatedevents', 'calendar'), '
', false); diff --git a/calendar/classes/local/event/mappers/create_update_form_mapper.php b/calendar/classes/local/event/mappers/create_update_form_mapper.php index 00b700237b3..d8ff4b1cd0c 100644 --- a/calendar/classes/local/event/mappers/create_update_form_mapper.php +++ b/calendar/classes/local/event/mappers/create_update_form_mapper.php @@ -47,8 +47,7 @@ class create_update_form_mapper implements create_update_form_mapper_interface { /** * Generate the appropriate data for the form from a legacy event. * - * @method from_legacy_event_to_data - * @param calendar_event $legacyevent + * @param \calendar_event $legacyevent * @return stdClass */ public function from_legacy_event_to_data(\calendar_event $legacyevent) { @@ -69,8 +68,7 @@ class create_update_form_mapper implements create_update_form_mapper_interface { /** * Generate the appropriate calendar_event properties from the form data. * - * @method from_data_to_event_properties - * @param stdClass $data + * @param \stdClass $data * @return stdClass */ public function from_data_to_event_properties(\stdClass $data) { @@ -105,13 +103,12 @@ class create_update_form_mapper implements create_update_form_mapper_interface { * A helper function to calculate the time duration for an event based on * the event_form data. * - * @method get_time_duration_from_form_data * @param \stdClass $data event_form data * @return int */ private function get_time_duration_from_form_data(\stdClass $data) { if ($data->duration == 1) { - return $data->timedurationuntil- $data->timestart; + return $data->timedurationuntil - $data->timestart; } else if ($data->duration == 2) { return $data->timedurationminutes * MINSECS; } else { diff --git a/calendar/classes/local/event/mappers/create_update_form_mapper_interface.php b/calendar/classes/local/event/mappers/create_update_form_mapper_interface.php index 16e29029aca..6b38c7c8020 100644 --- a/calendar/classes/local/event/mappers/create_update_form_mapper_interface.php +++ b/calendar/classes/local/event/mappers/create_update_form_mapper_interface.php @@ -38,8 +38,7 @@ interface create_update_form_mapper_interface { /** * Generate the appropriate data for the form from a legacy event. * - * @method from_legacy_event_to_data - * @param calendar_event $legacyevent + * @param \calendar_event $legacyevent * @return stdClass */ public function from_legacy_event_to_data(\calendar_event $legacyevent); @@ -47,8 +46,7 @@ interface create_update_form_mapper_interface { /** * Generate the appropriate calendar_event properties from the form data. * - * @method from_data_to_event_properties - * @param stdClass $data + * @param \stdClass $data * @return stdClass */ public function from_data_to_event_properties(\stdClass $data); diff --git a/calendar/lib.php b/calendar/lib.php index 2f3bdf77dd7..45d12971782 100644 --- a/calendar/lib.php +++ b/calendar/lib.php @@ -2744,7 +2744,7 @@ function calendar_get_allowed_types(&$allowed, $course = null, $groups = null) { * 'groupcourses' : array of courses that the groups belong to (can * be different from the list in 'course'. * - * @param array The available types for the logged in user + * @return array The array of allowed types. */ function calendar_get_all_allowed_types() { global $CFG, $USER; @@ -3416,6 +3416,12 @@ function calendar_get_legacy_events($tstart, $tend, $users, $groups, $courses, $ }, []); } +/** + * Request and render event form fragment. + * + * @param array $args The fragment arguments. + * @return string The rendered mform fragment. + */ function calendar_output_fragment_event_form($args) { global $CFG, $OUTPUT; require_once($CFG->dirroot.'/calendar/event_form.php'); diff --git a/lib/grouplib.php b/lib/grouplib.php index 25d1e962f30..cd48e62b837 100644 --- a/lib/grouplib.php +++ b/lib/grouplib.php @@ -352,44 +352,46 @@ function groups_get_all_groups_for_courses($courses) { $results = $DB->get_records_sql($sql, $params); - // The results will come back as a flat dataset thanks to the left - // join so we will need to do some post processing to blow it out - // into a more useable data structure. - // - // This loop will extract the distinct groups from the result set - // and add it's list of members to the object as a property called - // 'members'. Then each group will be added to the result set indexed - // by it's course id. - // - // The resulting data structure for $groups should be: - // $groups = [ - // '1' = [ - // '1' => (object) [ - // 'id' => 1, - // - // 'members' => [ - // '1' => (object) [ - // - // ], - // '2' => (object) [ - // - // ] - // ] - // ], - // '2' => (object) [ - // 'id' => 2, - // - // 'members' => [ - // '1' => (object) [ - // - // ], - // '3' => (object) [ - // - // ] - // ] - // ] - // ] - // ] + /** + * The results will come back as a flat dataset thanks to the left + * join so we will need to do some post processing to blow it out + * into a more usable data structure. + * + * This loop will extract the distinct groups from the result set + * and add it's list of members to the object as a property called + * 'members'. Then each group will be added to the result set indexed + * by it's course id. + * + * The resulting data structure for $groups should be: + * $groups = [ + * '1' = [ + * '1' => (object) [ + * 'id' => 1, + * + * 'members' => [ + * '1' => (object) [ + * + * ], + * '2' => (object) [ + * + * ] + * ] + * ], + * '2' => (object) [ + * 'id' => 2, + * + * 'members' => [ + * '1' => (object) [ + * + * ], + * '3' => (object) [ + * + * ] + * ] + * ] + * ] + * ] + */ foreach ($results as $key => $result) { $groupid = $result->gid; $courseid = $result->courseid; diff --git a/lib/tests/grouplib_test.php b/lib/tests/grouplib_test.php index 4679db6fcdf..e8aa1231e19 100644 --- a/lib/tests/grouplib_test.php +++ b/lib/tests/grouplib_test.php @@ -1548,6 +1548,9 @@ class core_grouplib_testcase extends advanced_testcase { $this->assertEquals([$user1->id, $user3->id], array_keys($members), '', 0.0, 10, true); } + /** + * Test groups_get_all_groups_for_courses() method. + */ public function test_groups_get_all_groups_for_courses_no_courses() { $this->resetAfterTest(true); $generator = $this->getDataGenerator(); @@ -1555,6 +1558,9 @@ class core_grouplib_testcase extends advanced_testcase { $this->assertEquals([], groups_get_all_groups_for_courses([])); } + /** + * Test groups_get_all_groups_for_courses() method. + */ public function test_groups_get_all_groups_for_courses_with_courses() { $this->resetAfterTest(true); $generator = $this->getDataGenerator(); @@ -1606,7 +1612,7 @@ class core_grouplib_testcase extends advanced_testcase { $generator->create_group_member(array('groupid' => $group9->id, 'userid' => $user2->id)); $result = groups_get_all_groups_for_courses($courses); - $assertPropertiesMatch = function($expected, $actual) { + $assertpropertiesmatch = function($expected, $actual) { $props = get_object_vars($expected); foreach ($props as $name => $val) { @@ -1627,7 +1633,7 @@ class core_grouplib_testcase extends advanced_testcase { $coursegroup = $coursegroups[$group1->id]; $this->assertCount(1, $coursegroups); $this->assertEquals([], $coursegroup->members); - $assertPropertiesMatch($group1, $coursegroup); + $assertpropertiesmatch($group1, $coursegroup); // Course 3 has one group with one member. $coursegroups = $result[$course3->id]; @@ -1635,7 +1641,7 @@ class core_grouplib_testcase extends advanced_testcase { $groupmember1 = $coursegroup->members[$user1->id]; $this->assertCount(1, $coursegroups); $this->assertCount(1, $coursegroup->members); - $assertPropertiesMatch($group2, $coursegroup); + $assertpropertiesmatch($group2, $coursegroup); $this->assertEquals($user1->id, $groupmember1->userid); // Course 4 has one group with multiple members. @@ -1645,7 +1651,7 @@ class core_grouplib_testcase extends advanced_testcase { $groupmember2 = $coursegroup->members[$user2->id]; $this->assertCount(1, $coursegroups); $this->assertCount(2, $coursegroup->members); - $assertPropertiesMatch($group3, $coursegroup); + $assertpropertiesmatch($group3, $coursegroup); $this->assertEquals($user1->id, $groupmember1->userid); $this->assertEquals($user2->id, $groupmember2->userid); @@ -1656,8 +1662,8 @@ class core_grouplib_testcase extends advanced_testcase { $this->assertCount(2, $coursegroups); $this->assertEquals([], $coursegroup1->members); $this->assertEquals([], $coursegroup2->members); - $assertPropertiesMatch($group4, $coursegroup1); - $assertPropertiesMatch($group5, $coursegroup2); + $assertpropertiesmatch($group4, $coursegroup1); + $assertpropertiesmatch($group5, $coursegroup2); // Course 6 has multiple groups with one member. $coursegroups = $result[$course6->id]; @@ -1668,8 +1674,8 @@ class core_grouplib_testcase extends advanced_testcase { $this->assertCount(2, $coursegroups); $this->assertCount(1, $coursegroup1->members); $this->assertCount(1, $coursegroup2->members); - $assertPropertiesMatch($group6, $coursegroup1); - $assertPropertiesMatch($group7, $coursegroup2); + $assertpropertiesmatch($group6, $coursegroup1); + $assertpropertiesmatch($group7, $coursegroup2); $this->assertEquals($user1->id, $group1member1->userid); $this->assertEquals($user1->id, $group2member1->userid); @@ -1684,8 +1690,8 @@ class core_grouplib_testcase extends advanced_testcase { $this->assertCount(2, $coursegroups); $this->assertCount(2, $coursegroup1->members); $this->assertCount(2, $coursegroup2->members); - $assertPropertiesMatch($group8, $coursegroup1); - $assertPropertiesMatch($group9, $coursegroup2); + $assertpropertiesmatch($group8, $coursegroup1); + $assertpropertiesmatch($group9, $coursegroup2); $this->assertEquals($user1->id, $group1member1->userid); $this->assertEquals($user2->id, $group1member2->userid); $this->assertEquals($user1->id, $group2member1->userid);