ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
ILIAS\BookingManager\BookingProcess\BookingProcessManager Class Reference
+ Collaboration diagram for ILIAS\BookingManager\BookingProcess\BookingProcessManager:

Public Member Functions

 __construct (InternalDataService $data, InternalRepoService $repo, InternalDomainService $domain)
 
 getRecurrenceMissingAvailability (int $obj_id, int $slot_from, int $slot_to, int $recurrence_weeks, int $requested_nr, \ilDate $until)
 Get missing availability of an object for a given weekly recurrence, object id, starting slot and requested nr. More...
 
 bookAvailableObjects (int $obj_id, int $user_to_book, int $assigner_id, int $context_obj_id, int $from, int $to, int $recurrence, int $nr, ?\ilDateTime $until, string $message="")
 
 bookSingle (int $object_id, int $user_to_book, int $assigner_id=0, int $context_obj_id=0, int $a_from=null, int $a_to=null, int $a_group_id=null, string $message="")
 Book object for date. More...
 

Protected Member Functions

 addDaysDate (string $a_date, int $a_days)
 
 addDaysStamp (int $a_stamp, int $a_days)
 

Protected Attributes

InternalDataService $data
 
InternalRepoService $repo
 
InternalDomainService $domain
 

Detailed Description

Author
Alexander Killing killi.nosp@m.ng@l.nosp@m.eifos.nosp@m..de

Definition at line 27 of file class.BookingProcessManager.php.

Constructor & Destructor Documentation

◆ __construct()

Member Function Documentation

◆ addDaysDate()

ILIAS\BookingManager\BookingProcess\BookingProcessManager::addDaysDate ( string  $a_date,
int  $a_days 
)
protected

Definition at line 77 of file class.BookingProcessManager.php.

80  : string {
81  $date = date_parse($a_date);
82  $stamp = mktime(0, 0, 1, $date["month"], $date["day"] + $a_days, $date["year"]);
83  return date("Y-m-d", $stamp);
84  }

◆ addDaysStamp()

ILIAS\BookingManager\BookingProcess\BookingProcessManager::addDaysStamp ( int  $a_stamp,
int  $a_days 
)
protected

Definition at line 86 of file class.BookingProcessManager.php.

Referenced by ILIAS\BookingManager\BookingProcess\BookingProcessManager\bookAvailableObjects(), and ILIAS\BookingManager\BookingProcess\BookingProcessManager\getRecurrenceMissingAvailability().

89  : int {
90  $date = getdate($a_stamp);
91  return mktime(
92  $date["hours"],
93  $date["minutes"],
94  $date["seconds"],
95  $date["mon"],
96  $date["mday"] + $a_days,
97  $date["year"]
98  );
99  }
+ Here is the caller graph for this function:

◆ bookAvailableObjects()

ILIAS\BookingManager\BookingProcess\BookingProcessManager::bookAvailableObjects ( int  $obj_id,
int  $user_to_book,
int  $assigner_id,
int  $context_obj_id,
int  $from,
int  $to,
int  $recurrence,
int  $nr,
?\ilDateTime  $until,
string  $message = "" 
)

Definition at line 101 of file class.BookingProcessManager.php.

References ILIAS\BookingManager\BookingProcess\BookingProcessManager\addDaysStamp(), ILIAS\BookingManager\BookingProcess\BookingProcessManager\bookSingle(), ilDateTime\get(), ilBookingReservation\getAvailableObject(), and IL_CAL_UNIX.

112  : array {
113  $reservation_repo = $this->repo->reservation();
114 
115  $rsv_ids = [];
116 
117  if (is_null($until)) {
118  $end = $from;
119  $cut = 999; // only one iteration
120  $cycle = 0; // no recurrence
121  } else {
122  $end = $until->get(IL_CAL_UNIX);
123  $cut = 0;
124  $cycle = $recurrence * 7;
125  }
126  $booked_out_slots = [];
127  $check_slot_from = $from;
128  $group_id = $reservation_repo->getNewGroupId();
129  while ($cut < 1000 && $check_slot_from <= $end) {
130  $check_slot_from = $this->addDaysStamp($from, $cycle * $cut);
131  $check_slot_to = $this->addDaysStamp($to, $cycle * $cut);
132  $available = \ilBookingReservation::getAvailableObject(array($obj_id), $check_slot_from, $check_slot_to, false, true);
133  $available = $available[$obj_id] ?? 0;
134  $book_nr = min($nr, $available);
135  for ($loop = 0; $loop < $book_nr; $loop++) {
136  $rsv_ids[] = $this->bookSingle(
137  $obj_id,
138  $user_to_book,
139  $assigner_id,
140  $context_obj_id,
141  $check_slot_from,
142  $check_slot_to,
143  $group_id,
144  $message
145  );
146  $success = $obj_id;
147  }
148  $cut++;
149  }
150  return $rsv_ids;
151  }
static getAvailableObject(array $a_ids, int $a_from, int $a_to, bool $a_return_single=true, bool $a_return_counter=false)
Check if any of given objects are bookable.
const IL_CAL_UNIX
bookSingle(int $object_id, int $user_to_book, int $assigner_id=0, int $context_obj_id=0, int $a_from=null, int $a_to=null, int $a_group_id=null, string $message="")
Book object for date.
+ Here is the call graph for this function:

◆ bookSingle()

ILIAS\BookingManager\BookingProcess\BookingProcessManager::bookSingle ( int  $object_id,
int  $user_to_book,
int  $assigner_id = 0,
int  $context_obj_id = 0,
int  $a_from = null,
int  $a_to = null,
int  $a_group_id = null,
string  $message = "" 
)

Book object for date.

Returns
int reservation id
Exceptions

Definition at line 158 of file class.BookingProcessManager.php.

References $lng, IL_CAL_UNIX, ilCalendarUtil\initDefaultCalendarByType(), ilBookingObject\lookupPoolId(), and ilCalendarCategory\TYPE_BOOK.

Referenced by ILIAS\BookingManager\BookingProcess\BookingProcessManager\bookAvailableObjects().

167  : int {
168  $lng = $this->domain->lng();
169 
170  // add user to participants, if not existing
171  $pool_id = \ilBookingObject::lookupPoolId($object_id);
172  $this->domain->participants()->createIfNotExisting($user_to_book, $pool_id);
173 
174  // create new reservation
175  $reservation = new \ilBookingReservation();
176  $reservation->setObjectId($object_id);
177  $reservation->setUserId($user_to_book);
178  $reservation->setAssignerId($assigner_id);
179  $reservation->setFrom((int) $a_from);
180  $reservation->setTo((int) $a_to);
181  $reservation->setGroupId((int) $a_group_id);
182  $reservation->setContextObjId($context_obj_id);
183  $reservation->setMessage($message);
184  $reservation->save();
185 
186  // create calendar entry
187  if ($a_from) {
188  $lng->loadLanguageModule('dateplaner');
191  $user_to_book,
192  $lng->txt('cal_ch_personal_book'),
193  true
194  );
195 
196  $object = new \ilBookingObject($object_id);
197 
198  $entry = new \ilCalendarEntry();
199  $entry->setStart(new \ilDateTime($a_from, IL_CAL_UNIX));
200  $entry->setEnd(new \ilDateTime($a_to, IL_CAL_UNIX));
201  $entry->setTitle($lng->txt('book_cal_entry') . ' ' . $object->getTitle());
202  $entry->setContextId($reservation->getId());
203  $entry->save();
204 
205  $assignment = new \ilCalendarCategoryAssignments($entry->getEntryId());
206  if ($def_cat !== null) {
207  $assignment->addAssignment($def_cat->getCategoryID());
208  }
209  }
210 
211  return $reservation->getId();
212  }
const IL_CAL_UNIX
static initDefaultCalendarByType(int $a_type_id, int $a_usr_id, string $a_title, bool $a_create=false)
Init the default calendar for given type and user.
global $lng
Definition: privfeed.php:32
static lookupPoolId(int $object_id)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getRecurrenceMissingAvailability()

ILIAS\BookingManager\BookingProcess\BookingProcessManager::getRecurrenceMissingAvailability ( int  $obj_id,
int  $slot_from,
int  $slot_to,
int  $recurrence_weeks,
int  $requested_nr,
\ilDate  $until 
)

Get missing availability of an object for a given weekly recurrence, object id, starting slot and requested nr.

Definition at line 47 of file class.BookingProcessManager.php.

References ILIAS\BookingManager\BookingProcess\BookingProcessManager\addDaysStamp(), ilDate\get(), ilBookingReservation\getAvailableObject(), and IL_CAL_UNIX.

54  : array {
55  $end = $until->get(IL_CAL_UNIX);
56  $cut = 0;
57  $cycle = $recurrence_weeks * 7;
58  $booked_out_slots = [];
59  $check_slot_from = $slot_from;
60  while ($cut < 1000 && $check_slot_from <= $end) {
61  $check_slot_from = $this->addDaysStamp($slot_from, $cycle * $cut);
62  $check_slot_to = $this->addDaysStamp($slot_to, $cycle * $cut);
63  $available = \ilBookingReservation::getAvailableObject(array($obj_id), $check_slot_from, $check_slot_to, false, true);
64  $available = $available[$obj_id] ?? 0;
65  if ($available < $requested_nr) {
66  $booked_out_slots[] = [
67  "from" => $check_slot_from,
68  "to" => $check_slot_to,
69  "missing" => $requested_nr - $available
70  ];
71  }
72  $cut++;
73  }
74  return $booked_out_slots;
75  }
static getAvailableObject(array $a_ids, int $a_from, int $a_to, bool $a_return_single=true, bool $a_return_counter=false)
Check if any of given objects are bookable.
const IL_CAL_UNIX
+ Here is the call graph for this function:

Field Documentation

◆ $data

InternalDataService ILIAS\BookingManager\BookingProcess\BookingProcessManager::$data
protected

◆ $domain

InternalDomainService ILIAS\BookingManager\BookingProcess\BookingProcessManager::$domain
protected

◆ $repo

InternalRepoService ILIAS\BookingManager\BookingProcess\BookingProcessManager::$repo
protected

The documentation for this class was generated from the following file: