From fd0f6c455593ed8f886b2e3413fe1a8dd243814a Mon Sep 17 00:00:00 2001 From: Riedler Date: Sat, 14 Dec 2024 20:07:20 +0100 Subject: [PATCH 1/3] added supervisor userIDs to slot data structures --- lbplanner/classes/model/slot.php | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/lbplanner/classes/model/slot.php b/lbplanner/classes/model/slot.php index cff914bc..76e5b655 100644 --- a/lbplanner/classes/model/slot.php +++ b/lbplanner/classes/model/slot.php @@ -28,6 +28,7 @@ use local_lbplanner\enums\WEEKDAY; use local_lbplanner\helpers\slot_helper; +use external_multiple_structure; use external_single_structure; use external_value; use moodle_exception; @@ -68,6 +69,10 @@ class slot { * @var ?bool $forcuruser whether the current user has reserved this slot (gets filled in by helper functions) */ private ?bool $forcuruser; + /** + * @var ?int[] $supervisors list of supervisors for this slot + */ + private ?array $supervisors; /** * Constructs a new Slot @@ -166,6 +171,25 @@ public function get_forcuruser(): bool { return $this->forcuruser; } + /** + * Returns the list of supervisor userIDs + * + * @return int[] this slot's supervsisors' userIDs + */ + public function get_supervisors(): array { + global $DB; + if (is_null($this->supervisors)) { + $this->supervisors = $DB->get_records( + slot_helper::TABLE_SUPERVISORS, + ['slotid' => $this->id], + '', + ['userid'] + ); + } + + return $this->supervisors; + } + /** * Returns whether this and $other overlap in their time. * @param slot $other the other slot @@ -229,6 +253,7 @@ public function prepare_for_api(): array { 'size' => $this->size, 'fullness' => $this->get_fullness(), 'forcuruser' => $this->get_forcuruser(), + 'supervisors' => $this->get_supervisors(), ]; } @@ -248,6 +273,10 @@ public static function api_structure(): external_single_structure { 'size' => new external_value(PARAM_INT, 'total capacity of the slot'), 'fullness' => new external_value(PARAM_INT, 'how many people have already reserved this slot'), 'forcuruser' => new external_value(PARAM_BOOL, 'whether the current user has reserved this slot'), + 'supervisors' => new external_multiple_structure( + new external_value(PARAM_INT), + 'this slot\'s supervisors\' userIDs' + ), ] ); } From 4f05fa094f2ef6341fc921b1b0fc3fcb0e3f8a66 Mon Sep 17 00:00:00 2001 From: Riedler Date: Sun, 15 Dec 2024 20:03:51 +0100 Subject: [PATCH 2/3] fixed slot API documentation --- lbplanner/classes/model/slot.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lbplanner/classes/model/slot.php b/lbplanner/classes/model/slot.php index 76e5b655..7408f9c8 100644 --- a/lbplanner/classes/model/slot.php +++ b/lbplanner/classes/model/slot.php @@ -274,8 +274,7 @@ public static function api_structure(): external_single_structure { 'fullness' => new external_value(PARAM_INT, 'how many people have already reserved this slot'), 'forcuruser' => new external_value(PARAM_BOOL, 'whether the current user has reserved this slot'), 'supervisors' => new external_multiple_structure( - new external_value(PARAM_INT), - 'this slot\'s supervisors\' userIDs' + new external_value(PARAM_INT, 'this slot\'s supervisors\' userIDs') ), ] ); From 299c767f55c411700d904ca75ab1ab48adcbd48a Mon Sep 17 00:00:00 2001 From: Riedler Date: Tue, 17 Dec 2024 17:56:38 +0100 Subject: [PATCH 3/3] fix: parameter typing in slot_helper::filter_slots_for_user() --- lbplanner/classes/helpers/slot_helper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lbplanner/classes/helpers/slot_helper.php b/lbplanner/classes/helpers/slot_helper.php index 2083e989..f642ad53 100644 --- a/lbplanner/classes/helpers/slot_helper.php +++ b/lbplanner/classes/helpers/slot_helper.php @@ -285,10 +285,10 @@ public static function get_filters_for_slot(int $slotid): array { * NOTE: not taking into account time or fullness, only filters i.e. users' class and courses * TODO: replace $user with $vintage * @param slot[] $allslots the slots to filter - * @param mixed $user a user object - e.g. $USER or a user object from the database + * @param \stdClass $user a user object - e.g. $USER or a user object from the database * @return slot[] the filtered slot array */ - public static function filter_slots_for_user(array $allslots, mixed $user): array { + public static function filter_slots_for_user(array $allslots, \stdClass $user): array { $mycourses = course_helper::get_all_lbplanner_courses(); $mycourseids = []; foreach ($mycourses as $course) {