19declare(strict_types=1);
30use Psr\Http\Message\ServerRequestInterface;
32use Psr\Http\Message\RequestInterface;
56 private readonly ServerRequestInterface|RequestInterface
$request;
62 private readonly \ILIAS\ResourceStorage\Services
$irss;
84 protected bool $has_write =
false
88 $this->
lng = $DIC->language();
89 $this->tpl =
$DIC->ui()->mainTemplate();
90 $this->
factory = $DIC->ui()->factory();
91 $this->
renderer = $DIC->ui()->renderer();
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();
101 $DIC->ui()->mainTemplate()
107 array $visible_column_ids,
110 mixed $additional_viewcontrol_data,
112 mixed $additional_parameters
117 [$order_field, $order_direction] = $order->
join(
119 fn($ret, $key, $value) => [$key, $value]
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';
128 return \ilStr::strCmp(
134 if ($order_field ===
'active') {
135 return $right[$order_field] <=> $left[$order_field];
138 return $left[$order_field] <=> $right[$order_field];
142 $records = array_reverse($records);
150 $identifications = [];
151 foreach ($records as $record) {
152 if (isset($record[self::RECORD_RAW][
'image_rid']) && $record[self::RECORD_RAW][
'image_rid'] !==
'') {
157 $this->irss->preload($identifications);
159 $modal_container =
new ModalBuilder();
160 $container_deleted_title_part =
'<span class="il_ItemAlertProperty">' . $this->
lng->txt(
'deleted') .
'</span>';
161 foreach ($records as $record) {
163 (
string) $record[
'id'],
164 $this->
enrichRecord($modal_container, $container_deleted_title_part, $record)
170 mixed $additional_viewcontrol_data,
172 mixed $additional_parameters
174 return \count($this->getRecords());
214 string $container_deleted_title_part,
217 $badge_item = $record[self::RECORD_RAW];
220 $badge->setId($badge_item[
'id']);
221 $badge->setImageRid($badge_item[
'image_rid']);
222 $badge->setImage($badge_item[
'image']);
228 $image_src = $this->badge_image_service->getImageFromResourceId($badge);
229 if ($image_src !==
'') {
230 $images[
'rendered'] = $this->
renderer->render(
231 $this->
factory->image()->responsive(
237 $image_src_large = $this->badge_image_service->getImageFromResourceId(
239 ilBadgeImage::IMAGE_SIZE_XL
241 if ($image_src_large !==
'') {
242 $images[
'large'] = $this->
factory->image()->responsive(
249 $container_title_parts = [
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'] ??
''))
256 'title' => $badge_item[
'parent_title'] ??
'',
259 $sortable_container_title_parts = [
260 'title' => $badge_item[
'parent_title'] ??
''
262 if ($badge_item[
'deleted']) {
263 $container_title_parts[
'suffix'] = $container_deleted_title_part;
264 $sortable_container_title_parts[
'suffix'] = $container_deleted_title_part;
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;
271 $ref_id = array_shift($ref_ids);
272 $this->first_ref_id_for_parent_cache[$badge_item[
'parent_id']] =
$ref_id;
274 $this->has_access_by_parent_cache[$badge_item[
'parent_id']] = $has_access;
278 $container_title_parts[
'title'] = $this->
renderer->render(
280 $container_title_parts[
'title'],
284 $badge_item[
'parent_type'] ??
''
290 $container_title_parts[
'suffix'] = $container_deleted_title_part;
291 $sortable_container_title_parts[
'suffix'] = $container_deleted_title_part;
297 $badge_item[
'title'],
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)),
306 'id' => $badge_item[
'id'],
307 'active' => (bool) $badge_item[
'active'],
308 'type' => $record[
'type'],
313 'title' => implode(
'', [
317 'title_sortable' => $badge_item[
'title'],
318 'container' => implode(
' ', $container_title_parts),
319 'container_sortable' => implode(
' ', $sortable_container_title_parts),
350 if ($this->cached_records !==
null) {
351 return $this->cached_records;
364 $sortable_rows = array_map(
function (array $badge_item) use ($types) {
366 'id' => $badge_item[
'id'],
367 'active' => (bool) $badge_item[
'active'],
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
376 $this->cached_records = $sortable_rows;
378 return $this->cached_records;
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')
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'),
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'),
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'),
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'),
439 $df = new \ILIAS\Data\Factory();
441 $table_uri = $df->uri(
$url);
443 $query_params_namespace = [
'tid'];
445 [$url_builder, $action_parameter_token, $row_id_token] = $url_builder->acquireParameters(
446 $query_params_namespace,
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);
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));
466 if ($action ===
'obj_badge_delete') {
468 if (\is_array($ids) && \count($ids) > 0) {
469 if ($ids === [
'ALL_OBJECTS']) {
477 $ids[] = $badge_item[
'id'];
481 foreach ($ids as
$id) {
483 $items[] = $this->
factory->modal()->interruptiveItem()->keyValue(
485 (
string) $badge->getId(),
490 $this->
http->saveResponse(
494 Streams::ofString($this->
renderer->renderAsync([
495 $this->factory->modal()->interruptive(
496 $this->lng->txt(
'badge_deletion'),
497 $this->lng->txt(
'badge_deletion_confirmation'),
499 )->withAffectedItems($items)
503 $this->
http->sendResponse();
504 $this->
http->close();
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
renderShyButton(string $label, Modal $modal)
constructModal(?Image $badge_image, string $badge_title, array $badge_properties=[])
renderModal(Modal $modal)
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.