19 declare(strict_types=1);
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()
106 DataRowBuilder $row_builder,
107 array $visible_column_ids,
111 ?array $additional_parameters
116 [$order_field, $order_direction] = $order->
join(
118 fn($ret, $key, $value) => [$key, $value]
121 usort($records,
static function (array $left, array $right) use ($order_field):
int {
122 if (\in_array($order_field, [
'container',
'title',
'type'],
true)) {
123 if (\in_array($order_field, [
'container',
'title'],
true)) {
124 $order_field .=
'_sortable';
127 return \ilStr::strCmp(
133 if ($order_field ===
'active') {
134 return $right[$order_field] <=> $left[$order_field];
137 return $left[$order_field] <=> $right[$order_field];
141 $records = array_reverse($records);
149 $identifications = [];
150 foreach ($records as $record) {
151 if (isset($record[self::RECORD_RAW][
'image_rid']) && $record[self::RECORD_RAW][
'image_rid'] !==
'') {
152 $identifications[] = $record[self::RECORD_RAW][
'image_rid'];
156 $this->irss->preload($identifications);
159 $container_deleted_title_part =
'<span class="il_ItemAlertProperty">' . $this->
lng->txt(
'deleted') .
'</span>';
160 foreach ($records as $record) {
161 yield $row_builder->buildDataRow(
162 (
string) $record[
'id'],
163 $this->
enrichRecord($modal_container, $container_deleted_title_part, $record)
170 ?array $additional_parameters
212 string $container_deleted_title_part,
215 $badge_item = $record[self::RECORD_RAW];
218 $badge->setId($badge_item[
'id']);
219 $badge->setImageRid($badge_item[
'image_rid']);
220 $badge->setImage($badge_item[
'image']);
226 $image_src = $this->badge_image_service->getImageFromResourceId($badge);
227 if ($image_src !==
'') {
228 $images[
'rendered'] = $this->
renderer->render(
229 $this->
factory->image()->responsive(
235 $image_src_large = $this->badge_image_service->getImageFromResourceId(
239 if ($image_src_large !==
'') {
240 $images[
'large'] = $this->
factory->image()->responsive(
247 $container_title_parts = [
249 $this->
factory->symbol()->icon()->custom(
250 ilObject::_getIcon($badge_item[
'parent_id'],
'big', $badge_item[
'parent_type'] ??
''),
251 $this->
lng->txt(
'obj_' . ($badge_item[
'parent_type'] ??
''))
254 'title' => $badge_item[
'parent_title'] ??
'',
257 $sortable_container_title_parts = [
258 'title' => $badge_item[
'parent_title'] ??
'' 260 if ($badge_item[
'deleted']) {
261 $container_title_parts[
'suffix'] = $container_deleted_title_part;
262 $sortable_container_title_parts[
'suffix'] = $container_deleted_title_part;
264 if (isset($this->has_access_by_parent_cache[$badge_item[
'parent_id']])) {
265 $has_access = $this->has_access_by_parent_cache[$badge_item[
'parent_id']] ??
false;
266 $ref_id = $this->first_ref_id_for_parent_cache[$badge_item[
'parent_id']] ??
null;
269 $ref_id = array_shift($ref_ids);
270 $this->first_ref_id_for_parent_cache[$badge_item[
'parent_id']] =
$ref_id;
272 $this->has_access_by_parent_cache[$badge_item[
'parent_id']] = $has_access;
276 $container_title_parts[
'title'] = $this->
renderer->render(
278 $container_title_parts[
'title'],
282 $badge_item[
'parent_type'] ??
'' 288 $container_title_parts[
'suffix'] = $container_deleted_title_part;
289 $sortable_container_title_parts[
'suffix'] = $container_deleted_title_part;
295 $badge_item[
'title'],
297 'active' => $badge_item[
'active'] ? $this->
lng->txt(
'yes') : $this->
lng->txt(
'no'),
298 'type' => $record[
'type'],
299 'container' => implode(
' ', \array_slice($container_title_parts, 1,
null,
true)),
304 'id' => $badge_item[
'id'],
305 'active' => (bool) $badge_item[
'active'],
306 'type' => $record[
'type'],
311 'title' => implode(
'', [
315 'title_sortable' => $badge_item[
'title'],
316 'container' => implode(
' ', $container_title_parts),
317 'container_sortable' => implode(
' ', $sortable_container_title_parts),
348 if ($this->cached_records !==
null) {
362 $sortable_rows =
array_map(
function (array $badge_item) use ($types) {
364 'id' => $badge_item[
'id'],
365 'active' => (bool) $badge_item[
'active'],
367 'title_sortable' => $badge_item[
'title'],
368 'container_sortable' => ($badge_item[
'parent_title'] ??
'') .
369 ($badge_item[
'deleted'] ?
' ' . $this->
lng->txt(
'deleted') :
''),
370 self::RECORD_RAW => $badge_item
374 $this->cached_records = $sortable_rows;
385 'image' => $this->
factory->table()->column()->text($this->
lng->txt(
'image'))->withIsSortable(
false),
386 'title' => $this->
factory->table()->column()->text($this->
lng->txt(
'title')),
387 'type' => $this->
factory->table()->column()->text($this->
lng->txt(
'type')),
388 'container' => $this->
factory->table()->column()->text($this->
lng->txt(
'object')),
389 'active' => $this->
factory->table()->column()->boolean(
390 $this->
lng->txt(
'active'),
391 $this->
lng->txt(
'yes'),
392 $this->
lng->txt(
'no')
393 )->withOrderingLabels(
394 $this->
lng->txt(
'badge_sort_active_badges_first'),
395 $this->
lng->txt(
'badge_sort_active_badges_last')
408 return $this->has_write ? [
409 'obj_badge_activate' => $this->
factory->table()->action()->multi(
410 $this->
lng->txt(
'activate'),
411 $url_builder->
withParameter($action_parameter_token,
'obj_badge_activate'),
414 'obj_badge_deactivate' =>
415 $this->
factory->table()->action()->multi(
416 $this->
lng->txt(
'deactivate'),
417 $url_builder->
withParameter($action_parameter_token,
'obj_badge_deactivate'),
420 'obj_badge_delete' =>
421 $this->
factory->table()->action()->multi(
422 $this->
lng->txt(
'delete'),
423 $url_builder->
withParameter($action_parameter_token,
'obj_badge_delete'),
426 'obj_badge_show_users' =>
427 $this->
factory->table()->action()->single(
428 $this->
lng->txt(
'user'),
429 $url_builder->
withParameter($action_parameter_token,
'obj_badge_show_users'),
437 $df = new \ILIAS\Data\Factory();
439 $table_uri = $df->uri($url);
441 $query_params_namespace = [
'tid'];
443 [$url_builder, $action_parameter_token, $row_id_token] = $url_builder->acquireParameters(
444 $query_params_namespace,
451 ->data($this, $this->
lng->txt(
'badge_object_badges'), $this->
getColumns())
452 ->withId(self::class)
454 ->withActions($this->
getActions($url_builder, $action_parameter_token, $row_id_token))
455 ->withRequest($this->request);
459 $query = $this->
http->wrapper()->query();
460 if ($query->has($action_parameter_token->getName())) {
461 $action = $query->retrieve($action_parameter_token->getName(), $this->
refinery->kindlyTo()->string());
462 $ids = $query->retrieve($row_id_token->getName(), $this->
refinery->custom()->transformation(fn($v) => $v));
464 if ($action ===
'obj_badge_delete') {
466 if (\is_array($ids) && \count($ids) > 0) {
467 if ($ids === [
'ALL_OBJECTS']) {
475 $ids[] = $badge_item[
'id'];
479 foreach ($ids as
$id) {
480 $badge =
new ilBadge((
int) $id);
481 $items[] = $this->
factory->modal()->interruptiveItem()->keyValue(
483 (
string) $badge->getId(),
488 $this->
http->saveResponse(
493 $this->factory->modal()->interruptive(
494 $this->
lng->txt(
'badge_deletion'),
495 $this->
lng->txt(
'badge_deletion_confirmation'),
497 )->withAffectedItems($items)
501 $this->
http->sendResponse();
502 $this->
http->close();
constructModal(?Image $badge_image, string $badge_title, array $badge_properties=[])
getRows(DataRowBuilder $row_builder, array $visible_column_ids, Range $range, Order $order, ?array $filter_data, ?array $additional_parameters)
join($init, callable $fn)
static _getIcon(int $obj_id=0, string $size="big", string $type="", bool $offline=false)
Get icon for repository item.
__construct(ilObjBadgeAdministrationGUI $parentObj, protected bool $has_write=false)
readonly Renderer $renderer
readonly ilAccessHandler $access
static _getAllReferences(int $id)
get all reference ids for object ID
array $first_ref_id_for_parent_cache
renderModal(Modal $modal)
getActions(URLBuilder $url_builder, URLBuilderToken $action_parameter_token, URLBuilderToken $row_id_token)
readonly ServerRequestInterface RequestInterface $request
readonly Factory $factory
enrichRecord(ModalBuilder $modal_builder, string $container_deleted_title_part, array $record)
Both the subject and the direction need to be specified when expressing an order. ...
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
getTotalRowCount(?array $filter_data, ?array $additional_parameters)
Mainly for the purpose of pagination-support, it is important to know about the total number of recor...
static http()
Fetches the global http state from ILIAS.
readonly ilObjBadgeAdministrationGUI $parent_obj
readonly ilBadgeImage $badge_image_service
static getExtendedTypeCaption(ilBadgeType $a_type)
array $has_access_by_parent_cache
readonly ILIAS ResourceStorage Services $irss
readonly ilGlobalTemplateInterface $tpl
readonly ILIAS Refinery Factory $refinery
static ofString(string $string)
Creates a new stream with an initial value.
withParameter(URLBuilderToken $token, string|array $value)
Change an acquired parameter's value if the supplied token is valid.
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
static getObjectInstances(?array $filter=null)
renderShyButton(string $label, Modal $modal)
A simple class to express a naive range of whole positive numbers.