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) { diff --git a/lbplanner/classes/model/slot.php b/lbplanner/classes/model/slot.php index cff914bc..7408f9c8 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,9 @@ 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') + ), ] ); }