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
100 $preferences = $preferences->getPreferences();
106 if (!$this->isPreferenceDeadlineReached()) {
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) {
128 $preferences = $this->removeObjectFromPreferences($book_obj_id, $preferences);
134 $end_phase_one =
false;
137 while (!$end_phase_one) {
138 $popularity = $this->calculatePopularity($booking_object_ids, $preferences);
139 $low_pop_book_obj_id = $this->getObjectWithLowestPopularity($popularity, $availability);
140 if ($low_pop_book_obj_id > 0) {
141 $user_ids = $this->getUsersForObject($preferences, $low_pop_book_obj_id);
142 if (count($user_ids) > 0) {
143 $user_id = $this->selectRandomEntry($user_ids);
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) {
155 $random_user_id = $this->chooseRandomUserFromPreferences($preferences);
156 if ($random_user_id > 0) {
157 $rare_assigned_book_obj_id = $this->getMinimalAssignedEntryForUser($booking_object_ids, $bookings, $preferences[$random_user_id], $availability);
158 if ($rare_assigned_book_obj_id > 0) {
159 $this->addBooking($bookings, $preferences, $availability, $random_user_id, $rare_assigned_book_obj_id);
161 $preferences = $this->removeUserFromPreferences($random_user_id, $preferences);
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) {
180 $preferences = $this->removeUserFromPreferences(
$user_id, $preferences);
182 $preferences = $this->removePreference(
$user_id, $book_obj_id, $preferences);
184 if ($availability[$book_obj_id] <= 0) {
185 $preferences = $this->removeObjectFromPreferences($book_obj_id, $preferences);
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) {
225 foreach ($booking_object_ids as $book_obj_id) {
226 $popularity[$book_obj_id] = 0;
229 foreach ($preferences as $bobj_ids) {
230 foreach ($bobj_ids as $bobj_id) {
231 if (!isset($popularity[$bobj_id])) {
235 ++$popularity[$bobj_id];
250 asort($popularity, SORT_NUMERIC);
251 foreach ($popularity as $obj_id => $pop) {
252 if ($pop > 0 && $availability[$obj_id] > 0) {
253 return (
int) $obj_id;
268 $preferences[
$user_id] = array_filter($preferences[
$user_id],
static function ($i) use ($obj_id) {
269 return ($i !== $obj_id);
282 $new_preferences = [];
283 foreach ($preferences as
$user_id => $obj_ids) {
284 $new_preferences[
$user_id] = array_filter($obj_ids,
static function ($i) use ($obj_id) {
285 return ($i !== $obj_id);
288 return $new_preferences;
310 if (count($preferences) === 0) {
313 $user_ids = array_keys($preferences);
314 return $this->selectRandomEntry($user_ids);
328 array $booking_object_ids,
330 array $user_preferences,
334 $count_assignments = [];
335 foreach ($booking_object_ids as $obj_id) {
336 $count_assignments[$obj_id] = 0;
338 foreach ($bookings as $user => $obj_ids) {
339 foreach ($obj_ids as $obj_id) {
340 $count_assignments[$obj_id]++;
345 asort($count_assignments, SORT_NUMERIC);
346 foreach ($count_assignments as $obj_id => $cnt) {
349 if ($availability[$obj_id] > 0 && (count($user_preferences) === 0 || in_array($obj_id, $user_preferences))) {
350 return (
int) $obj_id;
358 return $this->book_repo->hasRun($this->pool->getId());
363 $this->book_repo->resetRun($this->pool->getId());
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getList(int $a_pool_id, ?string $a_title=null)
Get list of booking objects.
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...
addBooking(array &$bookings, array &$preferences, array &$availability, int $user_id, int $book_obj_id)
getObjectWithLowestPopularity(array $popularity, array $availability)
Get an availabe object with lowest popularity > 0.
isPreferenceDeadlineReached()
Can participants hand in preferences.
removeUserFromPreferences(int $user_id, array $preferences)
Remove user from preference array.
__construct(ilObjBookingPool $pool, ilBookingPrefBasedBookGatewayRepository $book_repo, ?int $current_time=null, int $bookings_per_user=self::BOOKINGS_PER_USER_DEFAULT)
ilBookingPrefBasedBookGatewayRepository $book_repo
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) ...
calculatePopularity(array $booking_object_ids, array $preferences)
Calculate popularity (number of preferences each object got from users)
isGivingPreferencesPossible()
Can participants hand in preferences.
calculateBookings(ilBookingPreferences $preferences, ?array $booking_object_ids=null, ?array $availability=null)
Calculate bookings.
const BOOKINGS_PER_USER_DEFAULT
getUsersForObject(array $preferences, int $sel_obj_id)
Get users for object.
storeBookings(ilBookingPreferences $preferences, ?array $booking_object_ids=null)
Calculate and store bookings.
removePreference(int $user_id, int $obj_id, array $preferences)
Remove a preference from the preference array.
chooseRandomUserFromPreferences(array $preferences)
Choose random user from the preference array.
selectRandomEntry(array $items)
Select a random entry of an array.
removeObjectFromPreferences(int $obj_id, array $preferences)
Remove an object from the preference array.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getNumAvailablesNoSchedule(int $a_obj_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const TYPE_NO_SCHEDULE_PREFERENCES
if(!file_exists('../ilias.ini.php'))