35 ?
int $current_time = null,
36 int $bookings_per_user = self::BOOKINGS_PER_USER_DEFAULT
38 $this->current_time = ($current_time > 0)
73 ?array $booking_object_ids = null
76 $this->book_repo->storeBookings($this->pool->getId(), $bookings);
84 $booking_object_ids = array_map(
static function (
$i) {
85 return $i[
"booking_object_id"];
87 return $this->book_repo->getBookings($booking_object_ids);
97 ?array $booking_object_ids = null,
98 ?array $availability = null
110 if ($booking_object_ids === null) {
111 $booking_object_ids = array_map(
function (
$i) {
112 return $i[
"booking_object_id"];
116 if ($availability === null) {
118 foreach ($booking_object_ids as $book_obj_id) {
126 foreach ($availability as $book_obj_id => $cnt) {
134 $end_phase_one =
false;
137 while (!$end_phase_one) {
140 if ($low_pop_book_obj_id > 0) {
142 if (count($user_ids) > 0) {
144 $this->
addBooking($bookings, $preferences, $availability, $user_id, $low_pop_book_obj_id);
147 $end_phase_one =
true;
151 $end_phase_two =
false;
154 while (!$end_phase_two) {
156 if ($random_user_id > 0) {
158 if ($rare_assigned_book_obj_id > 0) {
159 $this->
addBooking($bookings, $preferences, $availability, $random_user_id, $rare_assigned_book_obj_id);
164 $end_phase_two =
true;
173 array &$availability,
177 $bookings[$user_id][] = $book_obj_id;
178 $availability[$book_obj_id]--;
179 if (count($bookings[$user_id]) >= $this->bookings_per_user) {
182 $preferences = $this->
removePreference($user_id, $book_obj_id, $preferences);
184 if ($availability[$book_obj_id] <= 0) {
195 return $items[array_rand($items)];
208 foreach ($preferences as $user_id => $obj_ids) {
209 foreach ($obj_ids as $obj_id) {
210 if ((
int) $obj_id === $sel_obj_id) {
211 $user_ids[] = (
int) $user_id;
223 array $booking_object_ids,
227 foreach ($booking_object_ids as $book_obj_id) {
228 $popularity[$book_obj_id] = 0;
230 foreach ($preferences as $user_id => $bobj_ids) {
231 foreach ($bobj_ids as $bobj_id) {
232 ++$popularity[$bobj_id];
247 asort($popularity, SORT_NUMERIC);
248 foreach ($popularity as $obj_id => $pop) {
249 if ($pop > 0 && $availability[$obj_id] > 0) {
250 return (
int) $obj_id;
264 if (is_array($preferences[$user_id])) {
265 $preferences[$user_id] = array_filter($preferences[$user_id],
static function (
$i) use ($obj_id) {
266 return (
$i !== $obj_id);
279 $new_preferences = [];
280 foreach ($preferences as $user_id => $obj_ids) {
281 $new_preferences[$user_id] = array_filter($obj_ids,
static function (
$i) use ($obj_id) {
282 return (
$i !== $obj_id);
285 return $new_preferences;
295 if (is_array($preferences[$user_id])) {
296 unset($preferences[$user_id]);
307 if (count($preferences) === 0) {
310 $user_ids = array_keys($preferences);
325 array $booking_object_ids,
327 array $user_preferences,
331 $count_assignments = [];
332 foreach ($booking_object_ids as $obj_id) {
333 $count_assignments[$obj_id] = 0;
335 foreach ($bookings as $user => $obj_ids) {
336 foreach ($obj_ids as $obj_id) {
337 $count_assignments[$obj_id]++;
342 asort($count_assignments, SORT_NUMERIC);
343 foreach ($count_assignments as $obj_id => $cnt) {
346 if ($availability[$obj_id] > 0 && (count($user_preferences) === 0 || in_array($obj_id, $user_preferences))) {
347 return (
int) $obj_id;
355 return $this->book_repo->hasRun($this->pool->getId());
360 $this->book_repo->resetRun($this->pool->getId());
isGivingPreferencesPossible()
Can participants hand in preferences.
static getNumAvailablesNoSchedule(int $a_obj_id)
addBooking(array &$bookings, array &$preferences, array &$availability, int $user_id, int $book_obj_id)
getUsersForObject(array $preferences, int $sel_obj_id)
Get users for object.
getObjectWithLowestPopularity(array $popularity, array $availability)
Get an availabe object with lowest popularity > 0.
calculatePopularity(array $booking_object_ids, array $preferences)
Calculate popularity (number of preferences each object got from users)
storeBookings(ilBookingPreferences $preferences, ?array $booking_object_ids=null)
Calculate and store bookings.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
removeObjectFromPreferences(int $obj_id, array $preferences)
Remove an object from the preference array.
removeUserFromPreferences(int $user_id, array $preferences)
Remove user from preference array.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
selectRandomEntry(array $items)
Select a random entry of an array.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getPreferences()
Get user preferences.
chooseRandomUserFromPreferences(array $preferences)
Choose random user from the preference array.
getMinimalAssignedEntryForUser(array $booking_object_ids, array $bookings, array $user_preferences, array $availability)
Get an available object within the preferences (if no preferences left, even outside of preferences) ...
__construct(ilObjBookingPool $pool, ilBookingPrefBasedBookGatewayRepository $book_repo, ?int $current_time=null, int $bookings_per_user=self::BOOKINGS_PER_USER_DEFAULT)
const TYPE_NO_SCHEDULE_PREFERENCES
const BOOKINGS_PER_USER_DEFAULT
ilBookingPrefBasedBookGatewayRepository $book_repo
calculateBookings(ilBookingPreferences $preferences, ?array $booking_object_ids=null, ?array $availability=null)
Calculate bookings.
removePreference(int $user_id, int $obj_id, array $preferences)
Remove a preference from the preference array.
static getList(int $a_pool_id, string $a_title=null)
Get list of booking objects.
isPreferenceDeadlineReached()
Can participants hand in preferences.