ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
ILIAS\Badge\ilObjectBadgeTableGUI Class Reference
+ Inheritance diagram for ILIAS\Badge\ilObjectBadgeTableGUI:
+ Collaboration diagram for ILIAS\Badge\ilObjectBadgeTableGUI:

Public Member Functions

 __construct (ilObjBadgeAdministrationGUI $parentObj, protected bool $has_write=false)
 
 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...
 
 getColumns ()
 
 renderTable (string $url)
 
 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...
 

Private Member Functions

 enrichRecord (ModalBuilder $modal_builder, string $container_deleted_title_part, array $record)
 
 getRecords ()
 
 getActions (URLBuilder $url_builder, URLBuilderToken $action_parameter_token, URLBuilderToken $row_id_token)
 

Private Attributes

const RECORD_RAW = '__raw__'
 
readonly Factory $factory
 
readonly Renderer $renderer
 
readonly ILIAS Refinery Factory $refinery
 
readonly ServerRequestInterface RequestInterface $request
 
readonly Services $http
 
readonly ilLanguage $lng
 
readonly ilGlobalTemplateInterface $tpl
 
readonly ilObjBadgeAdministrationGUI $parent_obj
 
readonly ilAccessHandler $access
 
readonly ILIAS ResourceStorage Services $irss
 
readonly ilBadgeImage $badge_image_service
 
array $cached_records = null
 
array $has_access_by_parent_cache = []
 
array $first_ref_id_for_parent_cache = []
 

Detailed Description

Definition at line 56 of file class.ilObjectBadgeTableGUI.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\Badge\ilObjectBadgeTableGUI::__construct ( ilObjBadgeAdministrationGUI  $parentObj,
protected bool  $has_write = false 
)

Definition at line 91 of file class.ilObjectBadgeTableGUI.php.

94 {
95 global $DIC;
96
97 $this->lng = $DIC->language();
98 $this->tpl = $DIC->ui()->mainTemplate();
99 $this->factory = $DIC->ui()->factory();
100 $this->renderer = $DIC->ui()->renderer();
101 $this->refinery = $DIC->refinery();
102 $this->request = $DIC->http()->request();
103 $this->http = $DIC->http();
104 $this->access = $DIC->access();
105 $this->parent_obj = $parentObj;
106 $this->irss = $DIC->resourceStorage();
107 $this->badge_image_service = new ilBadgeImage(
108 $this->irss,
109 $DIC->upload(),
110 $DIC->ui()->mainTemplate()
111 );
112 }
renderer()
factory()
static http()
Fetches the global http state from ILIAS.
global $DIC
Definition: shib_login.php:26

References $DIC, ILIAS\Repository\access(), factory(), ILIAS\FileDelivery\http(), ILIAS\Repository\lng(), ILIAS\Repository\refinery(), and renderer().

+ Here is the call graph for this function:

Member Function Documentation

◆ enrichRecord()

ILIAS\Badge\ilObjectBadgeTableGUI::enrichRecord ( ModalBuilder  $modal_builder,
string  $container_deleted_title_part,
array  $record 
)
private
Parameters
array{id: int, active: bool, type: string, title_sortable: string, container_sortable: string, raw: array{ id: int, parent_id: int, type_id: string, active: int, title: ?string, descr: ?string, conf: ?string, valid: ?string, crit: ?string, image_rid: ?string, parent_title: ?string, parent_type: ?string, deleted: bool } } $record
Returns
array{ id: int, active: bool, type: string, image: string, title: string, title_sortable: string, container: string, container_sortable: string }

Definition at line 221 of file class.ilObjectBadgeTableGUI.php.

225 : array {
226 $badge_item = $record[self::RECORD_RAW];
227
228 $badge = new ilBadge(0);
229 $badge->setId($badge_item['id']);
230 $badge->setImageRid($badge_item['image_rid']);
231
232 $images = [
233 'rendered' => null,
234 'large' => null,
235 ];
236 $image_src = $this->badge_image_service->getImageFromResourceId($badge);
237 if ($image_src !== '') {
238 $images['rendered'] = $this->renderer->render(
239 $this->factory->image()->responsive(
240 $image_src,
241 $badge_item['title']
242 )
243 );
244
245 $image_src_large = $this->badge_image_service->getImageFromResourceId(
246 $badge,
248 );
249 if ($image_src_large !== '') {
250 $images['large'] = $this->factory->image()->responsive(
251 $image_src_large,
252 $badge_item['title']
253 );
254 }
255 }
256
257 $container_title_parts = [
258 'icon' => $this->renderer->render(
259 $this->factory->symbol()->icon()->custom(
260 ilObject::_getIcon($badge_item['parent_id'], 'big', $badge_item['parent_type'] ?? ''),
261 $this->lng->txt('obj_' . ($badge_item['parent_type'] ?? ''))
262 )
263 ),
264 'title' => $badge_item['parent_title'] ?? '',
265 ];
266
267 $sortable_container_title_parts = [
268 'title' => $badge_item['parent_title'] ?? ''
269 ];
270 if ($badge_item['deleted']) {
271 $container_title_parts['suffix'] = $container_deleted_title_part;
272 $sortable_container_title_parts['suffix'] = $container_deleted_title_part;
273 } else {
274 if (isset($this->has_access_by_parent_cache[$badge_item['parent_id']])) {
275 $has_access = $this->has_access_by_parent_cache[$badge_item['parent_id']] ?? false;
276 $ref_id = $this->first_ref_id_for_parent_cache[$badge_item['parent_id']] ?? null;
277 } else {
278 $ref_ids = ilObject::_getAllReferences($badge_item['parent_id']);
279 $ref_id = array_shift($ref_ids);
280 $this->first_ref_id_for_parent_cache[$badge_item['parent_id']] = $ref_id;
281 $has_access = $ref_id && $this->access->checkAccess('read', '', $ref_id);
282 $this->has_access_by_parent_cache[$badge_item['parent_id']] = $has_access;
283 }
284
285 if ($has_access) {
286 $container_title_parts['title'] = $this->renderer->render(
287 new Standard(
288 $container_title_parts['title'],
289 (string) new URI(
290 ilLink::_getLink(
291 $ref_id,
292 $badge_item['parent_type'] ?? ''
293 )
294 )
295 )
296 );
297 } else {
298 $container_title_parts['suffix'] = $container_deleted_title_part;
299 $sortable_container_title_parts['suffix'] = $container_deleted_title_part;
300 }
301 }
302
303 $modal = $modal_builder->constructModal(
304 $images['large'],
305 $badge_item['title'],
306 [
307 'active' => $badge_item['active'] ? $this->lng->txt('yes') : $this->lng->txt('no'),
308 'type' => $record['type'],
309 'container' => implode(' ', array_slice($container_title_parts, 1, null, true)),
310 ],
311 true
312 );
313
314 return [
315 'id' => $badge_item['id'],
316 'active' => (bool) $badge_item['active'],
317 'type' => $record['type'],
318 'image' => $images['rendered'] ? ($modal_builder->renderShyButton(
319 $images['rendered'],
320 $modal
321 ) . ' ') : '',
322 'title' => implode('', [
323 $modal_builder->renderShyButton($badge_item['title'], $modal),
324 $modal_builder->renderModal($modal)
325 ]),
326 'title_sortable' => $badge_item['title'],
327 'container' => implode(' ', $container_title_parts),
328 'container_sortable' => implode(' ', $sortable_container_title_parts),
329 ];
330 }
renderShyButton(string $label, Modal $modal)
renderModal(Modal $modal)
constructModal(?Image $badge_image, string $badge_title, array $badge_properties=[], bool $enclose_in_div=false)
static _getIcon(int $obj_id=0, string $size="big", string $type="", bool $offline=false)
Get icon for repository item.
static _getAllReferences(int $id)
get all reference ids for object ID

◆ getActions()

ILIAS\Badge\ilObjectBadgeTableGUI::getActions ( URLBuilder  $url_builder,
URLBuilderToken  $action_parameter_token,
URLBuilderToken  $row_id_token 
)
private
Returns
array<string, Action>

Definition at line 413 of file class.ilObjectBadgeTableGUI.php.

417 : array {
418 return $this->has_write ? [
419 'obj_badge_activate' => $this->factory->table()->action()->multi(
420 $this->lng->txt('activate'),
421 $url_builder->withParameter($action_parameter_token, 'obj_badge_activate'),
422 $row_id_token
423 ),
424 'obj_badge_deactivate' => $this->factory->table()->action()->multi(
425 $this->lng->txt('deactivate'),
426 $url_builder->withParameter($action_parameter_token, 'obj_badge_deactivate'),
427 $row_id_token
428 ),
429 'obj_badge_delete' => $this->factory->table()->action()->multi(
430 $this->lng->txt('delete'),
431 $url_builder->withParameter($action_parameter_token, 'obj_badge_delete'),
432 $row_id_token
433 ),
434 'obj_badge_show_users' => $this->factory->table()->action()->single(
435 $this->lng->txt('user'),
436 $url_builder->withParameter($action_parameter_token, 'obj_badge_show_users'),
437 $row_id_token
438 )
439 ] : [];
440 }
withParameter(URLBuilderToken $token, string|array $value)
Change an acquired parameter's value if the supplied token is valid.
Definition: URLBuilder.php:166

◆ getColumns()

ILIAS\Badge\ilObjectBadgeTableGUI::getColumns ( )
Returns
array<string, Column>

Definition at line 392 of file class.ilObjectBadgeTableGUI.php.

392 : array
393 {
394 return [
395 'image' => $this->factory->table()->column()->text($this->lng->txt('image'))->withIsSortable(false),
396 'title' => $this->factory->table()->column()->text($this->lng->txt('title')),
397 'type' => $this->factory->table()->column()->text($this->lng->txt('type')),
398 'container' => $this->factory->table()->column()->text($this->lng->txt('object')),
399 'active' => $this->factory->table()->column()->boolean(
400 $this->lng->txt('active'),
401 $this->lng->txt('yes'),
402 $this->lng->txt('no')
403 )->withOrderingLabels(
404 $this->lng->txt('badge_sort_active_badges_first'),
405 $this->lng->txt('badge_sort_active_badges_last')
406 )
407 ];
408 }

References factory(), and ILIAS\Repository\lng().

+ Here is the call graph for this function:

◆ getRecords()

ILIAS\Badge\ilObjectBadgeTableGUI::getRecords ( )
private
Returns
list<array{ id: int, active: bool, type: string, title_sortable: string, container_sortable: string, raw: array{ id: int, parent_id: int, type_id: string, active: int, title: ?string, descr: ?string, conf: ?string, valid: ?string, crit: ?string, image_rid: ?string, parent_title: ?string, parent_type: ?string, deleted: bool } }>

Definition at line 356 of file class.ilObjectBadgeTableGUI.php.

356 : array
357 {
358 if ($this->cached_records !== null) {
360 }
361
362 // A filter is not implemented, yet
363 $filter = [
364 'type' => '',
365 'title' => '',
366 'object' => ''
367 ];
368
369 $types = ilBadgeHandler::getInstance()->getAvailableTypes(false);
370 $raw_records = ilBadge::getObjectInstances($filter);
371
372 $sortable_rows = array_map(function (array $badge_item) use ($types) {
373 return [
374 'id' => $badge_item['id'],
375 'active' => (bool) $badge_item['active'],
376 'type' => ilBadge::getExtendedTypeCaption($types[$badge_item['type_id']]),
377 'title_sortable' => $badge_item['title'],
378 'container_sortable' => ($badge_item['parent_title'] ?? '') .
379 ($badge_item['deleted'] ? ' ' . $this->lng->txt('deleted') : ''),
380 self::RECORD_RAW => $badge_item
381 ];
382 }, $raw_records);
383
384 $this->cached_records = $sortable_rows;
385
387 }
static getExtendedTypeCaption(ilBadgeType $a_type)
static getObjectInstances(?array $filter=null)

References ilBadge\getExtendedTypeCaption(), ilBadgeHandler\getInstance(), ilBadge\getObjectInstances(), and ILIAS\Repository\lng().

+ Here is the call graph for this function:

◆ getRows()

ILIAS\Badge\ilObjectBadgeTableGUI::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 114 of file class.ilObjectBadgeTableGUI.php.

122 : Generator {
123 $records = $this->getRecords();
124
125 if ($order) {
126 [$order_field, $order_direction] = $order->join(
127 [],
128 fn($ret, $key, $value) => [$key, $value]
129 );
130
131 usort($records, static function (array $left, array $right) use ($order_field): int {
132 if (in_array($order_field, ['container', 'title', 'type'], true)) {
133 if (in_array($order_field, ['container', 'title'], true)) {
134 $order_field .= '_sortable';
135 }
136
137 return ilStr::strCmp(
138 $left[$order_field],
139 $right[$order_field]
140 );
141 }
142
143 if ($order_field === 'active') {
144 return $right[$order_field] <=> $left[$order_field];
145 }
146
147 return $left[$order_field] <=> $right[$order_field];
148 });
149
150 if ($order_direction === Order::DESC) {
151 $records = array_reverse($records);
152 }
153 }
154
155 if ($range) {
156 $records = array_slice($records, $range->getStart(), $range->getLength());
157 }
158
159 $identifications = [];
160 foreach ($records as $record) {
161 $image_rid = $record[self::RECORD_RAW]['image_rid'] ?? null;
162 if (is_string($image_rid) && $image_rid !== '' && $image_rid !== '-') {
163 $identifications[] = $image_rid;
164 }
165 }
166
167 $this->irss->preload($identifications);
168
169 $modal_container = new ModalBuilder();
170 $container_deleted_title_part = '<span class="il_ItemAlertProperty">' . $this->lng->txt('deleted') . '</span>';
171 foreach ($records as $record) {
172 yield $row_builder->buildDataRow(
173 (string) $record['id'],
174 $this->enrichRecord($modal_container, $container_deleted_title_part, $record)
175 );
176 }
177 }
enrichRecord(ModalBuilder $modal_builder, string $container_deleted_title_part, array $record)
join($init, callable $fn)
Definition: Order.php:75
const DESC
Definition: Order.php:31
static strCmp(string $a, string $b)
Definition: class.ilStr.php:87
buildDataRow(string $id, array $record)

References ILIAS\Data\Order\DESC, ILIAS\Data\Order\join(), and ilStr\strCmp().

+ Here is the call graph for this function:

◆ getTotalRowCount()

ILIAS\Badge\ilObjectBadgeTableGUI::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 179 of file class.ilObjectBadgeTableGUI.php.

183 : ?int {
184 return count($this->getRecords());
185 }

◆ renderTable()

ILIAS\Badge\ilObjectBadgeTableGUI::renderTable ( string  $url)

Definition at line 442 of file class.ilObjectBadgeTableGUI.php.

442 : void
443 {
444 $df = new \ILIAS\Data\Factory();
445
446 $table_uri = $df->uri($url);
447 $url_builder = new URLBuilder($table_uri);
448 $query_params_namespace = ['tid'];
449
450 [$url_builder, $action_parameter_token, $row_id_token] = $url_builder->acquireParameters(
451 $query_params_namespace,
452 'table_action',
453 'id',
454 );
455
456 $table = $this->factory
457 ->table()
458 ->data($this, $this->lng->txt('badge_object_badges'), $this->getColumns())
459 ->withId(str_replace('\\', '', self::class))
460 ->withOrder(new Order('title', Order::ASC))
461 ->withRange(new Range(0, 100))
462 ->withActions($this->getActions($url_builder, $action_parameter_token, $row_id_token))
463 ->withRequest($this->request);
464
465 $query = $this->http->wrapper()->query();
466 if ($query->has($action_parameter_token->getName())) {
467 $action = $query->retrieve($action_parameter_token->getName(), $this->refinery->kindlyTo()->string());
468 $ids = $query->retrieve($row_id_token->getName(), $this->refinery->custom()->transformation(fn($v) => $v));
469
470 if ($action === 'obj_badge_delete') {
471 $items = [];
472 if (is_array($ids) && count($ids) > 0) {
473 if ($ids === ['ALL_OBJECTS']) {
474 $filter = [
475 'type' => '',
476 'title' => '',
477 'object' => ''
478 ];
479 $ids = [];
480 foreach (ilBadge::getObjectInstances($filter) as $badge_item) {
481 $ids[] = $badge_item['id'];
482 }
483 }
484
485 foreach ($ids as $id) {
486 $badge = new ilBadge((int) $id);
487 $items[] = $this->factory->modal()->interruptiveItem()->keyValue(
488 (string) $id,
489 (string) $badge->getId(),
490 $badge->getTitle()
491 );
492 }
493
494 $this->http->saveResponse(
495 $this->http
496 ->response()
497 ->withBody(
498 Streams::ofString($this->renderer->renderAsync([
499 $this->factory->modal()->interruptive(
500 $this->lng->txt('badge_deletion'),
501 $this->lng->txt('badge_deletion_confirmation'),
502 '#'
503 )->withAffectedItems($items)
504 ]))
505 )
506 );
507 $this->http->sendResponse();
508 $this->http->close();
509 }
510 }
511 }
512
513 $content_wrapper = new TableContentWrapper($this->renderer, $this->factory);
514 $this->tpl->setContent($this->renderer->render(
515 $content_wrapper->wrap(
516 $table
517 )
518 ));
519 }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
getActions(URLBuilder $url_builder, URLBuilderToken $action_parameter_token, URLBuilderToken $row_id_token)
Both the subject and the direction need to be specified when expressing an order.
Definition: Order.php:29
static ofString(string $string)
Creates a new stream with an initial value.
Definition: Streams.php:41

References $id, factory(), ilBadge\getObjectInstances(), ILIAS\FileDelivery\http(), ILIAS\Repository\lng(), and renderer().

+ Here is the call graph for this function:

Field Documentation

◆ $access

readonly ilAccessHandler ILIAS\Badge\ilObjectBadgeTableGUI::$access
private

Definition at line 67 of file class.ilObjectBadgeTableGUI.php.

◆ $badge_image_service

readonly ilBadgeImage ILIAS\Badge\ilObjectBadgeTableGUI::$badge_image_service
private

Definition at line 69 of file class.ilObjectBadgeTableGUI.php.

◆ $cached_records

array ILIAS\Badge\ilObjectBadgeTableGUI::$cached_records = null
private

Definition at line 83 of file class.ilObjectBadgeTableGUI.php.

◆ $factory

readonly Factory ILIAS\Badge\ilObjectBadgeTableGUI::$factory
private

Definition at line 59 of file class.ilObjectBadgeTableGUI.php.

◆ $first_ref_id_for_parent_cache

array ILIAS\Badge\ilObjectBadgeTableGUI::$first_ref_id_for_parent_cache = []
private

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

◆ $has_access_by_parent_cache

array ILIAS\Badge\ilObjectBadgeTableGUI::$has_access_by_parent_cache = []
private

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

◆ $http

readonly Services ILIAS\Badge\ilObjectBadgeTableGUI::$http
private

Definition at line 63 of file class.ilObjectBadgeTableGUI.php.

◆ $irss

readonly ILIAS ResourceStorage Services ILIAS\Badge\ilObjectBadgeTableGUI::$irss
private

Definition at line 68 of file class.ilObjectBadgeTableGUI.php.

◆ $lng

readonly ilLanguage ILIAS\Badge\ilObjectBadgeTableGUI::$lng
private

Definition at line 64 of file class.ilObjectBadgeTableGUI.php.

◆ $parent_obj

readonly ilObjBadgeAdministrationGUI ILIAS\Badge\ilObjectBadgeTableGUI::$parent_obj
private

Definition at line 66 of file class.ilObjectBadgeTableGUI.php.

◆ $refinery

readonly ILIAS Refinery Factory ILIAS\Badge\ilObjectBadgeTableGUI::$refinery
private

Definition at line 61 of file class.ilObjectBadgeTableGUI.php.

◆ $renderer

readonly Renderer ILIAS\Badge\ilObjectBadgeTableGUI::$renderer
private

Definition at line 60 of file class.ilObjectBadgeTableGUI.php.

◆ $request

readonly ServerRequestInterface RequestInterface ILIAS\Badge\ilObjectBadgeTableGUI::$request
private

Definition at line 62 of file class.ilObjectBadgeTableGUI.php.

◆ $tpl

readonly ilGlobalTemplateInterface ILIAS\Badge\ilObjectBadgeTableGUI::$tpl
private

Definition at line 65 of file class.ilObjectBadgeTableGUI.php.

◆ RECORD_RAW

const ILIAS\Badge\ilObjectBadgeTableGUI::RECORD_RAW = '__raw__'
private

Definition at line 58 of file class.ilObjectBadgeTableGUI.php.


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