ILIAS  trunk Revision v12.0_alpha-1613-gae4c99ebb18
ILIAS\BookingManager\BookableItem\Table\BookableItemTable Class Reference
+ Inheritance diagram for ILIAS\BookingManager\BookableItem\Table\BookableItemTable:
+ Collaboration diagram for ILIAS\BookingManager\BookableItem\Table\BookableItemTable:

Public Member Functions

 __construct (protected readonly UIFactory $ui_factory, protected readonly UIRenderer $ui_renderer, protected readonly ilLanguage $lng, protected readonly HttpService $http, protected readonly ilUIService $ui_service, protected readonly ilCtrlInterface $ctrl, protected readonly ilGlobalTemplateInterface $tpl, protected readonly Refinery $refinery, protected readonly AccessManager $access, protected readonly ilObjBookingPool $pool, protected readonly BookingProcessManager $process_manager, protected readonly Settings $settings, protected readonly ilObjUser $user, protected readonly int $ref_id, protected readonly bool $active_management, protected readonly int $booking_context_obj_id,)
 
 getTableId ()
 
 getComponents (URLBuilder $url_builder)
 
 getTotalRowCount (mixed $additional_viewcontrol_data, mixed $filter_data, mixed $additional_parameters)
 Mainly for the purpose of pagination-support, it is important to know about the total number of records available. More...
 
 getRows (DataRowBuilder $row_builder, array $visible_column_ids, Range $range, Order $order, mixed $additional_viewcontrol_data, mixed $filter_data, mixed $additional_parameters)
 This is called by the table to retrieve rows; map data-records to rows using the $row_builder e.g. More...
 
- Public Member Functions inherited from ILIAS\BookingManager\Common\Table\Table
 getTableId ()
 
 execute (URLBuilder $url_builder)
 
 getComponents (URLBuilder $url_builder)
 
 getRows (DataRowBuilder $row_builder, array $visible_column_ids, Range $range, Order $order, mixed $additional_viewcontrol_data, mixed $filter_data, mixed $additional_parameters)
 This is called by the table to retrieve rows; map data-records to rows using the $row_builder e.g. More...
 
 getTotalRowCount (mixed $additional_viewcontrol_data, mixed $filter_data, mixed $additional_parameters)
 Mainly for the purpose of pagination-support, it is important to know about the total number of records available. More...
 

Data Fields

const string ROW_ID_PARAMETER = 'bookable_item_row'
 
const string ACTION_PARAMETER = 'action'
 
const string ACTION_TYPE_PARAMETER = 'action_type'
 

Protected Member Functions

 getColumns ()
 
 getFilterInputs ()
 
 loadRecords (mixed $filter_data)
 
 buildRowCells (array $record)
 
 sortRecords (Order $order, array $records)
 
 getSortCallable (string $key, int $direction)
 
 limitRecords (Range $range, array $records)
 
 getFilterComponent ()
 
 acquireParameters (URLBuilder $url_builder)
 
 getTableActions ()
 
 loadFilteredBookingObjects (?string $title_filter, ?string $description_filter, ?array $object_ids_filter)
 
 getReservationsForObject (int $booking_object_id)
 
 buildAvailabilityCell (int $available, int $total)
 

Private Member Functions

 presetFilterInputs (array $filter_inputs)
 

Private Attributes

array $reservation_cache = []
 
TableActions $table_actions = null
 

Detailed Description

Definition at line 54 of file BookableItemTable.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\BookingManager\BookableItem\Table\BookableItemTable::__construct ( protected readonly UIFactory  $ui_factory,
protected readonly UIRenderer  $ui_renderer,
protected readonly ilLanguage  $lng,
protected readonly HttpService  $http,
protected readonly ilUIService  $ui_service,
protected readonly ilCtrlInterface  $ctrl,
protected readonly ilGlobalTemplateInterface  $tpl,
protected readonly Refinery  $refinery,
protected readonly AccessManager  $access,
protected readonly ilObjBookingPool  $pool,
protected readonly BookingProcessManager  $process_manager,
protected readonly Settings  $settings,
protected readonly ilObjUser  $user,
protected readonly int  $ref_id,
protected readonly bool  $active_management,
protected readonly int  $booking_context_obj_id 
)

Definition at line 71 of file BookableItemTable.php.

88 {
89 }

Member Function Documentation

◆ acquireParameters()

ILIAS\BookingManager\BookableItem\Table\BookableItemTable::acquireParameters ( URLBuilder  $url_builder)
protected
Returns
array{URLBuilder, URLBuilderToken, URLBuilderToken, URLBuilderToken}

Definition at line 258 of file BookableItemTable.php.

258 : array
259 {
260 return $url_builder->acquireParameters(
261 [$this->getTableId()],
262 self::ROW_ID_PARAMETER,
263 self::ACTION_PARAMETER,
264 self::ACTION_TYPE_PARAMETER
265 );
266 }
acquireParameters(array $namespace, string ... $names)
Definition: URLBuilder.php:138

References ILIAS\UI\URLBuilder\acquireParameters().

Referenced by ILIAS\BookingManager\BookableItem\Table\BookableItemTable\getComponents().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buildAvailabilityCell()

ILIAS\BookingManager\BookableItem\Table\BookableItemTable::buildAvailabilityCell ( int  $available,
int  $total 
)
protected

Definition at line 347 of file BookableItemTable.php.

347 : string
348 {
349 $icon = $this->ui_factory->symbol()->icon()->custom(
350 ilUtil::getImagePath($available > 0 ? 'standard/icon_ok.svg' : 'standard/icon_not_ok.svg'),
351 $this->lng->txt($available > 0 ? 'book_book' : 'book_no_objects')
352 );
353 return "{$this->ui_renderer->render($icon)} ({$available} / {$total})";
354 }
static getImagePath(string $image_name, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)

References ilUtil\getImagePath(), and ILIAS\Repository\lng().

Referenced by ILIAS\BookingManager\BookableItem\Table\BookableItemWithoutScheduleTable\buildRowCells(), and ILIAS\BookingManager\BookableItem\Table\BookableItemWithScheduleTable\buildRowCells().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buildRowCells()

ILIAS\BookingManager\BookableItem\Table\BookableItemTable::buildRowCells ( array  $record)
abstractprotected

◆ getColumns()

ILIAS\BookingManager\BookableItem\Table\BookableItemTable::getColumns ( )
abstractprotected

◆ getComponents()

ILIAS\BookingManager\BookableItem\Table\BookableItemTable::getComponents ( URLBuilder  $url_builder)
Returns
Component[]

Implements ILIAS\BookingManager\Common\Table\Table.

Definition at line 99 of file BookableItemTable.php.

99 : array
100 {
101 $components = [];
102
103 if ($this->pool->getScheduleType() === ilObjBookingPool::TYPE_NO_SCHEDULE) {
105 $this->user->getId(),
106 $this->pool->getId()
107 );
108
109 if ($this->pool->getOverallLimit() <= $booking_count) {
110 $components[] = $this->ui_factory->messageBox()->info($this->lng->txt('book_overall_limit_warning'));
111 }
112 }
113
114 $components[] = $filter = $this->getFilterComponent();
115 $filter_data = $this->ui_service->filter()->getData($filter);
116
117 $components[] = $this->ui_factory->table()->data(
118 $this,
119 $this->lng->txt('book_booking_objects'),
120 $this->getColumns()
121 )
122 ->withActions($this->getTableActions()->getEnabledActions(...$this->acquireParameters($url_builder)))
123 ->withRequest($this->http->getRequest())
124 ->withId($this->getTableId())
125 ->withFilter($filter_data)
126 ->withOrder(new Order($this instanceof BookableItemWithScheduleTable ? 'date_time' : 'title', Order::ASC));
127
128 return array_filter($components);
129 }
$components
static isBookingPoolLimitReachedByUser(int $a_user_id, int $a_pool_id)
static http()
Fetches the global http state from ILIAS.

References $components, ILIAS\BookingManager\BookableItem\Table\BookableItemTable\acquireParameters(), ILIAS\Data\Order\ASC, ILIAS\BookingManager\BookableItem\Table\BookableItemTable\getFilterComponent(), ILIAS\BookingManager\BookableItem\Table\BookableItemTable\getTableActions(), ILIAS\BookingManager\BookableItem\Table\BookableItemTable\getTableId(), ILIAS\FileDelivery\http(), ilBookingReservation\isBookingPoolLimitReachedByUser(), ILIAS\Repository\lng(), ilObjBookingPool\TYPE_NO_SCHEDULE, and ILIAS\Repository\user().

+ Here is the call graph for this function:

◆ getFilterComponent()

ILIAS\BookingManager\BookableItem\Table\BookableItemTable::getFilterComponent ( )
protected

Definition at line 225 of file BookableItemTable.php.

225 : FilterComponent
226 {
227 $filter_inputs = $this->getFilterInputs();
228
229 $filter_inputs = $this->presetFilterInputs($filter_inputs);
230
231 return $this->ui_service->filter()->standard(
232 "bookable_item_filter_{$this->pool->getId()}",
233 $this->ctrl->getLinkTargetByClass(ilBookingObjectGUI::class),
234 $filter_inputs,
235 array_fill(0, count($filter_inputs), true),
236 true,
237 true
238 );
239 }

References ILIAS\Repository\ctrl().

Referenced by ILIAS\BookingManager\BookableItem\Table\BookableItemTable\getComponents().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getFilterInputs()

ILIAS\BookingManager\BookableItem\Table\BookableItemTable::getFilterInputs ( )
abstractprotected

◆ getReservationsForObject()

ILIAS\BookingManager\BookableItem\Table\BookableItemTable::getReservationsForObject ( int  $booking_object_id)
protected
Returns
array{user_id: int, status: ?int, date_from: int, date_to: int}[]

Definition at line 327 of file BookableItemTable.php.

327 : array
328 {
329 if (isset($this->reservation_cache[$booking_object_id])) {
330 return $this->reservation_cache[$booking_object_id];
331 }
332
333 $list = ilBookingReservation::getList([$booking_object_id], 1000, 0, []);
334 $this->reservation_cache[$booking_object_id] = array_values(array_map(
335 static fn(array $row): array => [
336 'user_id' => (int) $row['user_id'],
337 'status' => isset($row['status']) ? (int) $row['status'] : null,
338 'date_from' => (int) $row['date_from'],
339 'date_to' => (int) $row['date_to'],
340 ],
341 $list['data'] ?? []
342 ));
343
344 return $this->reservation_cache[$booking_object_id];
345 }
static getList(array $a_object_ids, int $a_limit=10, int $a_offset=0, array $filter=[])
List all reservations.

References ilBookingReservation\getList().

Referenced by ILIAS\BookingManager\BookableItem\Table\BookableItemWithoutScheduleTable\hasActiveReservations(), and ILIAS\BookingManager\BookableItem\Table\BookableItemWithoutScheduleTable\loadRecords().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getRows()

ILIAS\BookingManager\BookableItem\Table\BookableItemTable::getRows ( DataRowBuilder  $row_builder,
array  $visible_column_ids,
Range  $range,
Order  $order,
mixed  $additional_viewcontrol_data,
mixed  $filter_data,
mixed  $additional_parameters 
)

This is called by the table to retrieve rows; map data-records to rows using the $row_builder e.g.

yield $row_builder->buildStandardRow($row_id, $record).

Parameters
string[]$visible_column_ids

Implements ILIAS\UI\Component\Table\DataRetrieval.

Definition at line 139 of file BookableItemTable.php.

147 : Generator {
148 $records = $this->limitRecords($range, $this->sortRecords($order, $this->loadRecords($filter_data)));
149
150 foreach ($records as $record) {
151 yield $this->getTableActions()->onDataRow(
152 $row_builder->buildDataRow((string) $record['row_id'], $this->buildRowCells($record)),
153 $record
154 );
155 }
156 }
buildDataRow(string $id, array $record)

References ILIAS\UI\Component\Table\DataRowBuilder\buildDataRow(), and ILIAS\BookingManager\Common\Table\getTableActions().

+ Here is the call graph for this function:

◆ getSortCallable()

ILIAS\BookingManager\BookableItem\Table\BookableItemTable::getSortCallable ( string  $key,
int  $direction 
)
protected

Reimplemented in ILIAS\BookingManager\BookableItem\Table\BookableItemWithScheduleTable.

Definition at line 203 of file BookableItemTable.php.

203 : ?callable
204 {
205 return match ($key) {
206 'availability' => static fn(array $a, array $b): int
207 => ((int) $a['available'] <=> (int) $b['available']) * $direction,
208 'title' => static fn(array $a, array $b): int
209 => strcasecmp((string) $a['title'], (string) $b['title']) * $direction,
210 'description' => static fn(array $a, array $b): int
211 => strcasecmp((string) $a['description'], (string) $b['description']) * $direction,
212 default => null,
213 };
214 }
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples

References Vendor\Package\$a, Vendor\Package\$b, and ILIAS\Repository\int().

+ Here is the call graph for this function:

◆ getTableActions()

ILIAS\BookingManager\BookableItem\Table\BookableItemTable::getTableActions ( )
protected

Definition at line 268 of file BookableItemTable.php.

269 {
270 return $this->table_actions ??= (new BookableItemTableActionsFactory(
271 $this->ctrl,
272 $this->lng,
273 $this->tpl,
274 $this->ui_factory,
275 $this->ui_renderer,
276 $this->refinery,
277 $this->http,
278 $this->access,
279 $this->pool,
280 $this->process_manager,
281 $this->user,
282 $this->ref_id,
283 $this->active_management,
284 $this->booking_context_obj_id,
285 array_column($this->loadRecords([]), null, 'row_id'),
286 ))->getTableActions();
287 }

References ILIAS\Repository\access(), ILIAS\Repository\ctrl(), ILIAS\BookingManager\Common\Table\getTableActions(), ILIAS\FileDelivery\http(), ILIAS\Repository\lng(), ILIAS\Repository\refinery(), and ILIAS\Repository\user().

Referenced by ILIAS\BookingManager\BookableItem\Table\BookableItemTable\getComponents().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getTableId()

ILIAS\BookingManager\BookableItem\Table\BookableItemTable::getTableId ( )

Implements ILIAS\BookingManager\Common\Table\Table.

Definition at line 91 of file BookableItemTable.php.

91 : string
92 {
93 return static::ID;
94 }

Referenced by ILIAS\BookingManager\BookableItem\Table\BookableItemTable\getComponents().

+ Here is the caller graph for this function:

◆ getTotalRowCount()

ILIAS\BookingManager\BookableItem\Table\BookableItemTable::getTotalRowCount ( mixed  $additional_viewcontrol_data,
mixed  $filter_data,
mixed  $additional_parameters 
)

Mainly for the purpose of pagination-support, it is important to know about the total number of records available.

Given the nature of a DataTable, which is, opposite to a PresentationTable, rather administrative than explorative, this information will increase user experience quite a bit. However, you may return null, if the call is to costly, but expect the View Control to look a little different in this case.

Make sure that potential filters or user restrictions are being applied to the count.

Implements ILIAS\UI\Component\Table\DataRetrieval.

Definition at line 131 of file BookableItemTable.php.

135 : ?int {
136 return count($this->loadRecords($filter_data));
137 }

◆ limitRecords()

ILIAS\BookingManager\BookableItem\Table\BookableItemTable::limitRecords ( Range  $range,
array  $records 
)
protected
Parameters
array<string,mixed>[]$records
Returns
array<string, mixed>[]

Definition at line 220 of file BookableItemTable.php.

220 : array
221 {
222 return array_slice($records, $range->getStart(), $range->getLength());
223 }

References ILIAS\UI\Implementation\Component\Table\$range, ILIAS\Data\Range\getLength(), and ILIAS\Data\Range\getStart().

+ Here is the call graph for this function:

◆ loadFilteredBookingObjects()

ILIAS\BookingManager\BookableItem\Table\BookableItemTable::loadFilteredBookingObjects ( ?string  $title_filter,
?string  $description_filter,
?array  $object_ids_filter 
)
protected
Returns
array<string, mixed>[]

Definition at line 292 of file BookableItemTable.php.

296 : array {
297 $items = ilBookingObject::getList($this->pool->getId());
298 $title_filter = mb_strtolower($title_filter ?? '') ?: null;
299 $description_filter = mb_strtolower($description_filter ?? '') ?: null;
300 $object_ids_filter = $object_ids_filter ?: null;
301
302 $filtered = [];
303 foreach ($items as $item) {
304 $object_id = (int) $item['booking_object_id'];
305
306 if ($object_ids_filter !== null && !in_array($object_id, $object_ids_filter, true)) {
307 continue;
308 }
309
310 if ($title_filter !== null && !str_contains(mb_strtolower((string) $item['title']), $title_filter)) {
311 continue;
312 }
313
314 if ($description_filter !== null && !str_contains(mb_strtolower((string) ($item['description'] ?? '')), $description_filter)) {
315 continue;
316 }
317
318 $filtered[] = $item;
319 }
320
321 return $filtered;
322 }
static getList(int $a_pool_id, ?string $a_title=null)
Get list of booking objects.

References ILIAS\Repository\int().

Referenced by ILIAS\BookingManager\BookableItem\Table\BookableItemWithoutScheduleTable\loadRecords(), and ILIAS\BookingManager\BookableItem\Table\BookableItemWithScheduleTable\loadRecords().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ loadRecords()

ILIAS\BookingManager\BookableItem\Table\BookableItemTable::loadRecords ( mixed  $filter_data)
abstractprotected

◆ presetFilterInputs()

ILIAS\BookingManager\BookableItem\Table\BookableItemTable::presetFilterInputs ( array  $filter_inputs)
private

Definition at line 241 of file BookableItemTable.php.

241 : array
242 {
243 if ($this->settings->getReservationPeriod() > 0) {
244 $filter_inputs['period'] = $filter_inputs['period']->withValue(
245 [
246 new DateTimeImmutable('today 00:00:00'),
247 new DateTimeImmutable("today +{$this->settings->getReservationPeriod()} days 23:59:59")
248 ]
249 );
250 }
251
252 return $filter_inputs;
253 }

References ILIAS\Repository\settings().

+ Here is the call graph for this function:

◆ sortRecords()

ILIAS\BookingManager\BookableItem\Table\BookableItemTable::sortRecords ( Order  $order,
array  $records 
)
protected
Parameters
array<string,mixed>[]$records
Returns
array<string, mixed>[]

Definition at line 182 of file BookableItemTable.php.

182 : array
183 {
184 $order_data = $order->get();
185 if ($order_data === []) {
186 return $records;
187 }
188
189 foreach ($order_data as $key => $direction) {
190 $order_direction = $direction === Order::DESC ? -1 : 1;
191 $callable = $this->getSortCallable($key, $order_direction);
192
193 if ($callable === null) {
194 continue;
195 }
196
197 usort($records, $callable);
198 }
199
200 return $records;
201 }
const DESC
Definition: Order.php:31

References ILIAS\Data\Order\get().

+ Here is the call graph for this function:

Field Documentation

◆ $reservation_cache

array ILIAS\BookingManager\BookableItem\Table\BookableItemTable::$reservation_cache = []
private

Definition at line 67 of file BookableItemTable.php.

◆ $table_actions

TableActions ILIAS\BookingManager\BookableItem\Table\BookableItemTable::$table_actions = null
private

Definition at line 69 of file BookableItemTable.php.

◆ ACTION_PARAMETER

const string ILIAS\BookingManager\BookableItem\Table\BookableItemTable::ACTION_PARAMETER = 'action'

Definition at line 60 of file BookableItemTable.php.

◆ ACTION_TYPE_PARAMETER

const string ILIAS\BookingManager\BookableItem\Table\BookableItemTable::ACTION_TYPE_PARAMETER = 'action_type'

Definition at line 62 of file BookableItemTable.php.

◆ ROW_ID_PARAMETER

const string ILIAS\BookingManager\BookableItem\Table\BookableItemTable::ROW_ID_PARAMETER = 'bookable_item_row'

Definition at line 58 of file BookableItemTable.php.


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