19declare(strict_types=1);
30use Psr\Http\Message\ServerRequestInterface;
32use Psr\Http\Message\RequestInterface;
57 private readonly ServerRequestInterface|RequestInterface
$request;
63 private readonly \ILIAS\ResourceStorage\Services
$irss;
85 protected bool $has_write =
false
89 $this->
lng = $DIC->language();
90 $this->tpl =
$DIC->ui()->mainTemplate();
91 $this->
factory = $DIC->ui()->factory();
92 $this->
renderer = $DIC->ui()->renderer();
94 $this->request =
$DIC->http()->request();
95 $this->
http = $DIC->http();
96 $this->
access = $DIC->access();
97 $this->parent_obj = $parentObj;
98 $this->irss =
$DIC->resourceStorage();
102 $DIC->ui()->mainTemplate()
108 array $visible_column_ids,
111 mixed $additional_viewcontrol_data,
113 mixed $additional_parameters
118 [$order_field, $order_direction] = $order->
join(
120 fn($ret, $key, $value) => [$key, $value]
123 usort($records,
static function (array $left, array $right) use ($order_field):
int {
124 if (\in_array($order_field, [
'container',
'title',
'type'],
true)) {
125 if (\in_array($order_field, [
'container',
'title'],
true)) {
126 $order_field .=
'_sortable';
129 return \ilStr::strCmp(
135 if ($order_field ===
'active') {
136 return $right[$order_field] <=> $left[$order_field];
139 return $left[$order_field] <=> $right[$order_field];
143 $records = array_reverse($records);
151 $identifications = [];
152 foreach ($records as $record) {
153 if (isset($record[self::RECORD_RAW][
'image_rid']) && $record[self::RECORD_RAW][
'image_rid'] !==
'') {
158 $this->irss->preload($identifications);
160 $modal_container =
new ModalBuilder();
161 $container_deleted_title_part =
'<span class="il_ItemAlertProperty">' . $this->
lng->txt(
'deleted') .
'</span>';
162 foreach ($records as $record) {
164 (
string) $record[
'id'],
165 $this->
enrichRecord($modal_container, $container_deleted_title_part, $record)
171 mixed $additional_viewcontrol_data,
173 mixed $additional_parameters
175 return \count($this->getRecords());
215 string $container_deleted_title_part,
218 $badge_item = $record[self::RECORD_RAW];
221 $badge->setId($badge_item[
'id']);
222 $badge->setImageRid($badge_item[
'image_rid']);
223 $badge->setImage($badge_item[
'image']);
229 $image_src = $this->badge_image_service->getImageFromResourceId($badge);
230 if ($image_src !==
'') {
231 $images[
'rendered'] = $this->
renderer->render(
232 $this->
factory->image()->responsive(
238 $image_src_large = $this->badge_image_service->getImageFromResourceId(
240 ilBadgeImage::IMAGE_SIZE_XL
242 if ($image_src_large !==
'') {
243 $images[
'large'] = $this->
factory->image()->responsive(
250 $container_title_parts = [
252 $this->
factory->symbol()->icon()->custom(
253 ilObject::_getIcon($badge_item[
'parent_id'],
'big', $badge_item[
'parent_type'] ??
''),
254 $this->lng->txt(
'obj_' . ($badge_item[
'parent_type'] ??
''))
257 'title' => $badge_item[
'parent_title'] ??
'',
260 $sortable_container_title_parts = [
261 'title' => $badge_item[
'parent_title'] ??
''
263 if ($badge_item[
'deleted']) {
264 $container_title_parts[
'suffix'] = $container_deleted_title_part;
265 $sortable_container_title_parts[
'suffix'] = $container_deleted_title_part;
267 if (isset($this->has_access_by_parent_cache[$badge_item[
'parent_id']])) {
268 $has_access = $this->has_access_by_parent_cache[$badge_item[
'parent_id']] ??
false;
269 $ref_id = $this->first_ref_id_for_parent_cache[$badge_item[
'parent_id']] ??
null;
272 $ref_id = array_shift($ref_ids);
273 $this->first_ref_id_for_parent_cache[$badge_item[
'parent_id']] =
$ref_id;
275 $this->has_access_by_parent_cache[$badge_item[
'parent_id']] = $has_access;
279 $container_title_parts[
'title'] = $this->
renderer->render(
281 $container_title_parts[
'title'],
285 $badge_item[
'parent_type'] ??
''
291 $container_title_parts[
'suffix'] = $container_deleted_title_part;
292 $sortable_container_title_parts[
'suffix'] = $container_deleted_title_part;
298 $badge_item[
'title'],
300 'active' => $badge_item[
'active'] ? $this->
lng->txt(
'yes') : $this->lng->txt(
'no'),
301 'type' => $record[
'type'],
302 'container' => implode(
' ', \array_slice($container_title_parts, 1,
null,
true)),
308 'id' => $badge_item[
'id'],
309 'active' => (bool) $badge_item[
'active'],
310 'type' => $record[
'type'],
315 'title' => implode(
'', [
319 'title_sortable' => $badge_item[
'title'],
320 'container' => implode(
' ', $container_title_parts),
321 'container_sortable' => implode(
' ', $sortable_container_title_parts),
352 if ($this->cached_records !==
null) {
353 return $this->cached_records;
366 $sortable_rows = array_map(
function (array $badge_item) use ($types) {
368 'id' => $badge_item[
'id'],
369 'active' => (bool) $badge_item[
'active'],
371 'title_sortable' => $badge_item[
'title'],
372 'container_sortable' => ($badge_item[
'parent_title'] ??
'') .
373 ($badge_item[
'deleted'] ?
' ' . $this->
lng->txt(
'deleted') :
''),
374 self::RECORD_RAW => $badge_item
378 $this->cached_records = $sortable_rows;
380 return $this->cached_records;
389 'image' => $this->
factory->table()->column()->text($this->
lng->txt(
'image'))->withIsSortable(
false),
390 'title' => $this->
factory->table()->column()->text($this->
lng->txt(
'title')),
391 'type' => $this->
factory->table()->column()->text($this->
lng->txt(
'type')),
392 'container' => $this->
factory->table()->column()->text($this->
lng->txt(
'object')),
393 'active' => $this->
factory->table()->column()->boolean(
394 $this->
lng->txt(
'active'),
395 $this->lng->txt(
'yes'),
396 $this->lng->txt(
'no')
397 )->withOrderingLabels(
398 $this->
lng->txt(
'badge_sort_active_badges_first'),
399 $this->lng->txt(
'badge_sort_active_badges_last')
412 return $this->has_write ? [
413 'obj_badge_activate' => $this->
factory->table()->action()->multi(
414 $this->
lng->txt(
'activate'),
415 $url_builder->withParameter($action_parameter_token,
'obj_badge_activate'),
418 'obj_badge_deactivate' =>
419 $this->
factory->table()->action()->multi(
420 $this->
lng->txt(
'deactivate'),
421 $url_builder->withParameter($action_parameter_token,
'obj_badge_deactivate'),
424 'obj_badge_delete' =>
425 $this->
factory->table()->action()->multi(
426 $this->
lng->txt(
'delete'),
427 $url_builder->withParameter($action_parameter_token,
'obj_badge_delete'),
430 'obj_badge_show_users' =>
431 $this->
factory->table()->action()->single(
432 $this->
lng->txt(
'user'),
433 $url_builder->withParameter($action_parameter_token,
'obj_badge_show_users'),
441 $df = new \ILIAS\Data\Factory();
443 $table_uri = $df->uri(
$url);
445 $query_params_namespace = [
'tid'];
447 [$url_builder, $action_parameter_token, $row_id_token] = $url_builder->acquireParameters(
448 $query_params_namespace,
455 ->data($this, $this->
lng->txt(
'badge_object_badges'), $this->getColumns())
456 ->withId(str_replace(
'\\',
'', self::class))
457 ->withOrder(
new Order(
'title', Order::ASC))
458 ->withRange(
new Range(0, 100))
459 ->withActions($this->getActions($url_builder, $action_parameter_token, $row_id_token))
460 ->withRequest($this->request);
462 $query = $this->
http->wrapper()->query();
463 if ($query->has($action_parameter_token->getName())) {
464 $action = $query->retrieve($action_parameter_token->getName(), $this->refinery->kindlyTo()->string());
465 $ids = $query->retrieve($row_id_token->getName(), $this->refinery->custom()->transformation(fn($v) => $v));
467 if ($action ===
'obj_badge_delete') {
469 if (\is_array($ids) && \count($ids) > 0) {
470 if ($ids === [
'ALL_OBJECTS']) {
478 $ids[] = $badge_item[
'id'];
482 foreach ($ids as
$id) {
484 $items[] = $this->
factory->modal()->interruptiveItem()->keyValue(
486 (
string) $badge->getId(),
491 $this->
http->saveResponse(
495 Streams::ofString($this->
renderer->renderAsync([
496 $this->factory->modal()->interruptive(
497 $this->lng->txt(
'badge_deletion'),
498 $this->lng->txt(
'badge_deletion_confirmation'),
500 )->withAffectedItems($items)
504 $this->
http->sendResponse();
505 $this->
http->close();
511 $this->tpl->setContent($this->
renderer->render(
512 $content_wrapper->wrap(
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
renderShyButton(string $label, Modal $modal)
renderModal(Modal $modal)
constructModal(?Image $badge_image, string $badge_title, array $badge_properties=[], bool $enclose_in_div=false)
This class provides a central helper method to wrap the content of a KS/UI > Table > Data into a spec...
array $has_access_by_parent_cache
readonly ilGlobalTemplateInterface $tpl
readonly ilObjBadgeAdministrationGUI $parent_obj
readonly ilBadgeImage $badge_image_service
readonly Factory $factory
readonly ilAccessHandler $access
readonly ServerRequestInterface RequestInterface $request
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 recor...
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....
getActions(URLBuilder $url_builder, URLBuilderToken $action_parameter_token, URLBuilderToken $row_id_token)
readonly ILIAS ResourceStorage Services $irss
enrichRecord(ModalBuilder $modal_builder, string $container_deleted_title_part, array $record)
readonly ILIAS Refinery Factory $refinery
__construct(ilObjBadgeAdministrationGUI $parentObj, protected bool $has_write=false)
readonly Renderer $renderer
array $first_ref_id_for_parent_cache
Builds a Color from either hex- or rgb values.
Both the subject and the direction need to be specified when expressing an order.
join($init, callable $fn)
A simple class to express a naive range of whole positive numbers.
The scope of this class is split ilias-conform URI's into components.
Stream factory which enables the user to create streams without the knowledge of the concrete class.
static getExtendedTypeCaption(ilBadgeType $a_type)
static getObjectInstances(?array $filter=null)
@ilCtrl_Calls ilObjBadgeAdministrationGUI: ilPermissionGUI, ilBadgeManagementGUI @ilCtrl_IsCalledBy i...
Class ilObject Basic functions for all objects.
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
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
A Column describes the form of presentation for a certain aspect of data, i.e.
buildDataRow(string $id, array $record)
This is how the factory for UI elements looks.
An entity that renders components to a string output.
Interface ilAccessHandler This interface combines all available interfaces which can be called via gl...
static http()
Fetches the global http state from ILIAS.