ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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 30 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 80 of file class.BookingProcessManager.php.

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

◆ addDaysStamp()

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

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

92 : int {
93 $date = getdate($a_stamp);
94 return mktime(
95 $date["hours"],
96 $date["minutes"],
97 $date["seconds"],
98 $date["mon"],
99 $date["mday"] + $a_days,
100 $date["year"]
101 );
102 }

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

+ 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 104 of file class.BookingProcessManager.php.

115 : array {
116 $reservation_repo = $this->repo->reservation();
117
118 $rsv_ids = [];
119
120 if (is_null($until)) {
121 $end = $from;
122 $cut = 999; // only one iteration
123 $cycle = 0; // no recurrence
124 } else {
125 $end = $until->get(IL_CAL_UNIX);
126 $cut = 0;
127 $cycle = $recurrence * 7;
128 }
129 $booked_out_slots = [];
130 $check_slot_from = $from;
131 $group_id = $reservation_repo->getNewGroupId();
132 while ($cut < 1000 && $check_slot_from <= $end) {
133 $check_slot_from = $this->addDaysStamp($from, $cycle * $cut);
134 $check_slot_to = $this->addDaysStamp($to, $cycle * $cut);
135 $available = \ilBookingReservation::getAvailableObject(array($obj_id), $check_slot_from, $check_slot_to, false, true);
136 $available = $available[$obj_id] ?? 0;
137 $book_nr = min($nr, $available);
138 for ($loop = 0; $loop < $book_nr; $loop++) {
139 $rsv_ids[] = $this->bookSingle(
140 $obj_id,
141 $user_to_book,
142 $assigner_id,
143 $context_obj_id,
144 $check_slot_from,
145 $check_slot_to,
146 $group_id,
148 );
149 $success = $obj_id;
150 }
151 $cut++;
152 }
153 return $rsv_ids;
154 }
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.
const IL_CAL_UNIX
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.
$message
Definition: xapiexit.php:31

◆ 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

ilDateTimeException

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

170 : int {
171 $lng = $this->domain->lng();
172
173 // add user to participants, if not existing
174 $pool_id = \ilBookingObject::lookupPoolId($object_id);
175 $this->domain->participants()->createIfNotExisting($user_to_book, $pool_id);
176
177 // create new reservation
178 $reservation = new \ilBookingReservation();
179 $reservation->setObjectId($object_id);
180 $reservation->setUserId($user_to_book);
181 $reservation->setAssignerId($assigner_id);
182 $reservation->setFrom((int) $a_from);
183 $reservation->setTo((int) $a_to);
184 $reservation->setGroupId((int) $a_group_id);
185 $reservation->setContextObjId($context_obj_id);
186 $reservation->setMessage($message);
187 $reservation->save();
188
189 // create calendar entry
190 if ($a_from) {
191 $lng->loadLanguageModule('dateplaner');
194 $user_to_book,
195 $lng->txt('cal_ch_personal_book'),
196 true
197 );
198
199 $object = new \ilBookingObject($object_id);
200
201 $entry = new \ilCalendarEntry();
202 $entry->setStart(new \ilDateTime($a_from, IL_CAL_UNIX));
203 $entry->setEnd(new \ilDateTime($a_to, IL_CAL_UNIX));
204 $entry->setTitle($lng->txt('book_cal_entry') . ' ' . $object->getTitle());
205 $entry->setContextId($reservation->getId());
206 $entry->save();
207
208 $assignment = new \ilCalendarCategoryAssignments($entry->getEntryId());
209 if ($def_cat !== null) {
210 $assignment->addAssignment($def_cat->getCategoryID());
211 }
212 }
213
214 return $reservation->getId();
215 }
static lookupPoolId(int $object_id)
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.
@classDescription Date and time handling
global $lng
Definition: privfeed.php:31

◆ 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 50 of file class.BookingProcessManager.php.

57 : array {
58 $end = $until->get(IL_CAL_UNIX);
59 $cut = 0;
60 $cycle = $recurrence_weeks * 7;
61 $booked_out_slots = [];
62 $check_slot_from = $slot_from;
63 while ($cut < 1000 && $check_slot_from <= $end) {
64 $check_slot_from = $this->addDaysStamp($slot_from, $cycle * $cut);
65 $check_slot_to = $this->addDaysStamp($slot_to, $cycle * $cut);
66 $available = \ilBookingReservation::getAvailableObject(array($obj_id), $check_slot_from, $check_slot_to, false, true);
67 $available = $available[$obj_id] ?? 0;
68 if ($available < $requested_nr) {
69 $booked_out_slots[] = [
70 "from" => $check_slot_from,
71 "to" => $check_slot_to,
72 "missing" => $requested_nr - $available
73 ];
74 }
75 $cut++;
76 }
77 return $booked_out_slots;
78 }

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

+ 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: