ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
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 49 of file class.ilObjectBadgeTableGUI.php.

Constructor & Destructor Documentation

◆ __construct()

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

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

85 {
86 global $DIC;
87
88 $this->lng = $DIC->language();
89 $this->tpl = $DIC->ui()->mainTemplate();
90 $this->factory = $DIC->ui()->factory();
91 $this->renderer = $DIC->ui()->renderer();
92 $this->refinery = $DIC->refinery();
93 $this->request = $DIC->http()->request();
94 $this->http = $DIC->http();
95 $this->access = $DIC->access();
96 $this->parent_obj = $parentObj;
97 $this->irss = $DIC->resourceStorage();
98 $this->badge_image_service = new ilBadgeImage(
99 $this->irss,
100 $DIC->upload(),
101 $DIC->ui()->mainTemplate()
102 );
103 }
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, image: ?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 212 of file class.ilObjectBadgeTableGUI.php.

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

◆ getActions()

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

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

409 : array {
410 return $this->has_write ? [
411 'obj_badge_activate' => $this->factory->table()->action()->multi(
412 $this->lng->txt('activate'),
413 $url_builder->withParameter($action_parameter_token, 'obj_badge_activate'),
414 $row_id_token
415 ),
416 'obj_badge_deactivate' =>
417 $this->factory->table()->action()->multi(
418 $this->lng->txt('deactivate'),
419 $url_builder->withParameter($action_parameter_token, 'obj_badge_deactivate'),
420 $row_id_token
421 ),
422 'obj_badge_delete' =>
423 $this->factory->table()->action()->multi(
424 $this->lng->txt('delete'),
425 $url_builder->withParameter($action_parameter_token, 'obj_badge_delete'),
426 $row_id_token
427 ),
428 'obj_badge_show_users' =>
429 $this->factory->table()->action()->single(
430 $this->lng->txt('user'),
431 $url_builder->withParameter($action_parameter_token, 'obj_badge_show_users'),
432 $row_id_token
433 )
434 ] : [];
435 }
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 384 of file class.ilObjectBadgeTableGUI.php.

384 : array
385 {
386 return [
387 'image' => $this->factory->table()->column()->text($this->lng->txt('image'))->withIsSortable(false),
388 'title' => $this->factory->table()->column()->text($this->lng->txt('title')),
389 'type' => $this->factory->table()->column()->text($this->lng->txt('type')),
390 'container' => $this->factory->table()->column()->text($this->lng->txt('object')),
391 'active' => $this->factory->table()->column()->boolean(
392 $this->lng->txt('active'),
393 $this->lng->txt('yes'),
394 $this->lng->txt('no')
395 )->withOrderingLabels(
396 $this->lng->txt('badge_sort_active_badges_first'),
397 $this->lng->txt('badge_sort_active_badges_last')
398 )
399 ];
400 }

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, image: ?string, valid: ?string, crit: ?string, image_rid: ?string, parent_title: ?string, parent_type: ?string, deleted: bool } }>

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

348 : array
349 {
350 if ($this->cached_records !== null) {
352 }
353
354 // A filter is not implemented, yet
355 $filter = [
356 'type' => '',
357 'title' => '',
358 'object' => ''
359 ];
360
361 $types = ilBadgeHandler::getInstance()->getAvailableTypes(false);
362 $raw_records = ilBadge::getObjectInstances($filter);
363
364 $sortable_rows = array_map(function (array $badge_item) use ($types) {
365 return [
366 'id' => $badge_item['id'],
367 'active' => (bool) $badge_item['active'],
368 'type' => ilBadge::getExtendedTypeCaption($types[$badge_item['type_id']]),
369 'title_sortable' => $badge_item['title'],
370 'container_sortable' => ($badge_item['parent_title'] ?? '') .
371 ($badge_item['deleted'] ? ' ' . $this->lng->txt('deleted') : ''),
372 self::RECORD_RAW => $badge_item
373 ];
374 }, $raw_records);
375
376 $this->cached_records = $sortable_rows;
377
379 }
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 105 of file class.ilObjectBadgeTableGUI.php.

113 : Generator {
114 $records = $this->getRecords();
115
116 if ($order) {
117 [$order_field, $order_direction] = $order->join(
118 [],
119 fn($ret, $key, $value) => [$key, $value]
120 );
121
122 usort($records, static function (array $left, array $right) use ($order_field): int {
123 if (\in_array($order_field, ['container', 'title', 'type'], true)) {
124 if (\in_array($order_field, ['container', 'title'], true)) {
125 $order_field .= '_sortable';
126 }
127
128 return \ilStr::strCmp(
129 $left[$order_field],
130 $right[$order_field]
131 );
132 }
133
134 if ($order_field === 'active') {
135 return $right[$order_field] <=> $left[$order_field];
136 }
137
138 return $left[$order_field] <=> $right[$order_field];
139 });
140
141 if ($order_direction === Order::DESC) {
142 $records = array_reverse($records);
143 }
144 }
145
146 if ($range) {
147 $records = \array_slice($records, $range->getStart(), $range->getLength());
148 }
149
150 $identifications = [];
151 foreach ($records as $record) {
152 if (isset($record[self::RECORD_RAW]['image_rid']) && $record[self::RECORD_RAW]['image_rid'] !== '') {
153 $identifications[] = $record[self::RECORD_RAW]['image_rid'];
154 }
155 }
156
157 $this->irss->preload($identifications);
158
159 $modal_container = new ModalBuilder();
160 $container_deleted_title_part = '<span class="il_ItemAlertProperty">' . $this->lng->txt('deleted') . '</span>';
161 foreach ($records as $record) {
162 yield $row_builder->buildDataRow(
163 (string) $record['id'],
164 $this->enrichRecord($modal_container, $container_deleted_title_part, $record)
165 );
166 }
167 }
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
buildDataRow(string $id, array $record)

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

+ 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 169 of file class.ilObjectBadgeTableGUI.php.

173 : ?int {
174 return \count($this->getRecords());
175 }

◆ renderTable()

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

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

437 : void
438 {
439 $df = new \ILIAS\Data\Factory();
440
441 $table_uri = $df->uri($url);
442 $url_builder = new URLBuilder($table_uri);
443 $query_params_namespace = ['tid'];
444
445 [$url_builder, $action_parameter_token, $row_id_token] = $url_builder->acquireParameters(
446 $query_params_namespace,
447 'table_action',
448 'id',
449 );
450
451 $table = $this->factory
452 ->table()
453 ->data($this, $this->lng->txt('badge_object_badges'), $this->getColumns())
454 ->withId(self::class)
455 ->withOrder(new Order('title', Order::ASC))
456 ->withActions($this->getActions($url_builder, $action_parameter_token, $row_id_token))
457 ->withRequest($this->request);
458
459 $out = [$table];
460
461 $query = $this->http->wrapper()->query();
462 if ($query->has($action_parameter_token->getName())) {
463 $action = $query->retrieve($action_parameter_token->getName(), $this->refinery->kindlyTo()->string());
464 $ids = $query->retrieve($row_id_token->getName(), $this->refinery->custom()->transformation(fn($v) => $v));
465
466 if ($action === 'obj_badge_delete') {
467 $items = [];
468 if (\is_array($ids) && \count($ids) > 0) {
469 if ($ids === ['ALL_OBJECTS']) {
470 $filter = [
471 'type' => '',
472 'title' => '',
473 'object' => ''
474 ];
475 $ids = [];
476 foreach (ilBadge::getObjectInstances($filter) as $badge_item) {
477 $ids[] = $badge_item['id'];
478 }
479 }
480
481 foreach ($ids as $id) {
482 $badge = new ilBadge((int) $id);
483 $items[] = $this->factory->modal()->interruptiveItem()->keyValue(
484 (string) $id,
485 (string) $badge->getId(),
486 $badge->getTitle()
487 );
488 }
489
490 $this->http->saveResponse(
491 $this->http
492 ->response()
493 ->withBody(
494 Streams::ofString($this->renderer->renderAsync([
495 $this->factory->modal()->interruptive(
496 $this->lng->txt('badge_deletion'),
497 $this->lng->txt('badge_deletion_confirmation'),
498 '#'
499 )->withAffectedItems($items)
500 ]))
501 )
502 );
503 $this->http->sendResponse();
504 $this->http->close();
505 }
506 }
507 }
508
509 $this->tpl->setContent($this->renderer->render($out));
510 }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
$out
Definition: buildRTE.php:24
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
$url
Definition: shib_logout.php:68

References $id, $out, $url, 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 61 of file class.ilObjectBadgeTableGUI.php.

◆ $badge_image_service

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

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

◆ $cached_records

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

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

◆ $factory

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

Definition at line 53 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 80 of file class.ilObjectBadgeTableGUI.php.

◆ $has_access_by_parent_cache

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

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

◆ $http

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

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

◆ $irss

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

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

◆ $lng

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

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

◆ $parent_obj

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

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

◆ $refinery

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

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

◆ $renderer

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

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

◆ $request

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

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

◆ $tpl

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

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

◆ RECORD_RAW

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

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


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