Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lbplanner/classes/helpers/slot_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
28 changes: 28 additions & 0 deletions lbplanner/classes/model/slot.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(),
];
}

Expand All @@ -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')
),
]
);
}
Expand Down
Loading