91 $this->book_repo->storeBookings($this->pool->getId(), $bookings);
101 $booking_object_ids = array_map(
function (
$i) {
102 return $i[
"booking_object_id"];
104 return $this->book_repo->getBookings($booking_object_ids);
117 $booking_object_ids = null,
130 if ($booking_object_ids == null) {
131 $booking_object_ids = array_map(
function (
$i) {
132 return $i[
"booking_object_id"];
136 if ($availability == null) {
138 foreach ($booking_object_ids as $book_obj_id) {
146 foreach ($availability as $book_obj_id => $cnt) {
154 $end_phase_one =
false;
157 while (!$end_phase_one) {
161 if ($low_pop_book_obj_id > 0) {
163 if (count($user_ids) > 0) {
165 $this->
addBooking($bookings, $preferences, $availability, $user_id, $low_pop_book_obj_id);
168 $end_phase_one =
true;
172 $end_phase_two =
false;
175 while (!$end_phase_two) {
177 if ($random_user_id > 0) {
179 if ($rare_assigned_book_obj_id > 0) {
180 $this->
addBooking($bookings, $preferences, $availability, $random_user_id, $rare_assigned_book_obj_id);
185 $end_phase_two =
true;
200 protected function addBooking(&$bookings, &$preferences, &$availability, $user_id, $book_obj_id)
202 $bookings[$user_id][] = $book_obj_id;
203 $availability[$book_obj_id]--;
204 if (count($bookings[$user_id]) >= $this->bookings_per_user) {
207 $preferences = $this->
removePreference($user_id, $book_obj_id, $preferences);
209 if ($availability[$book_obj_id] <= 0) {
223 $nr = rand(0, count($items) - 1);
238 foreach ($preferences as $user_id => $obj_ids) {
239 foreach ($obj_ids as $obj_id) {
240 if ($obj_id == $sel_obj_id) {
241 $user_ids[] = $user_id;
259 foreach ($booking_object_ids as $book_obj_id) {
260 $popularity[$book_obj_id] = 0;
262 foreach ($preferences as $user_id => $bobj_ids) {
263 foreach ($bobj_ids as $bobj_id) {
264 $popularity[$bobj_id] += 1;
280 asort($popularity, SORT_NUMERIC);
281 foreach ($popularity as $obj_id => $pop) {
282 if ($pop > 0 && $availability[$obj_id] > 0) {
283 return (
int) $obj_id;
299 if (is_array($preferences[$user_id])) {
300 $preferences[$user_id] = array_filter($preferences[$user_id],
function (
$i) use ($obj_id) {
301 return (
$i != $obj_id);
317 $new_preferences = [];
318 foreach ($preferences as $user_id => $obj_ids) {
319 $new_preferences[$user_id] = array_filter($preferences[$user_id],
function (
$i) use ($obj_id) {
320 return (
$i != $obj_id);
323 return $new_preferences;
335 if (is_array($preferences[$user_id])) {
336 unset($preferences[$user_id]);
349 $user_ids = array_keys($preferences);
365 $count_assignments = [];
366 foreach ($booking_object_ids as $obj_id) {
367 $count_assignments[$obj_id] = 0;
369 foreach ($bookings as $user => $obj_ids) {
370 foreach ($obj_ids as $obj_id) {
371 $count_assignments[$obj_id]++;
376 asort($count_assignments, SORT_NUMERIC);
377 foreach ($count_assignments as $obj_id => $cnt) {
380 if ((count($user_preferences) == 0 || in_array($obj_id, $user_preferences))
381 && $availability[$obj_id] > 0) {
382 return (
int) $obj_id;
390 return $this->book_repo->hasRun($this->pool->getId());
395 $this->book_repo->resetRun($this->pool->getId());
isGivingPreferencesPossible()
Can participants hand in preferences.
getObjectWithLowestPopularity($popularity, $availability)
Get an availabe object with lowest popularity > 0.
static getList($a_pool_id, $a_title=null)
Get list of booking objects for given type.
removePreference($user_id, $obj_id, $preferences)
Remove a preference from the preference array.
selectRandomEntry($items)
Select a random entry of an array.
chooseRandomUserFromPreferences($preferences)
Choose random user from the preference array.
calculatePopularity(array $booking_object_ids, array $preferences)
Calculate popularity (number of preferences each object got from users)
getUsersForObject($preferences, $sel_obj_id)
Get users for object.
addBooking(&$bookings, &$preferences, &$availability, $user_id, $book_obj_id)
Add booking.
removeObjectFromPreferences($obj_id, $preferences)
Remove an object from the preference array.
calculateBookings(ilBookingPreferences $preferences, $booking_object_ids=null, $availability=null)
Calculate bookings.
readBookings()
Read the bookings.
storeBookings($preferences, $booking_object_ids=null)
Calculate and store bookings.
getMinimalAssignedEntryForUser($booking_object_ids, $bookings, $user_preferences, $availability)
Get an available object within the preferences (if no preferences left, even outside of preferences) ...
Booking preferences business logic.
Booking calculation exception.
Manages the booking storage of the preference based calculated bookings.
getPreferences()
Get user preferences.
__construct(ilObjBookingPool $pool, ilBookingPrefBasedBookGatewayRepository $book_repo, int $current_time=null, $bookings_per_user=self::BOOKINGS_PER_USER_DEFAULT)
Constructor.
removeUserFromPreferences($user_id, $preferences)
Remove user from preference array.
const TYPE_NO_SCHEDULE_PREFERENCES
const BOOKINGS_PER_USER_DEFAULT
static getNumAvailablesNoSchedule($a_obj_id)
isPreferenceDeadlineReached()
Can participants hand in preferences.