ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
GroupsTable.php
Go to the documentation of this file.
1<?php
2
20
24use Psr\Http\Message\ServerRequestInterface;
28use ILIAS\GlobalScreen\Scope\MainMenu\Collector\Renderer\Hasher;
31use ILIAS\GlobalScreen\GUI\I18n\Translator;
35
37{
38 use Hasher;
39
40 public const COLUMN_ACTIVE = 'active';
41 public const COLUMN_TITLE = 'title';
42 public const CLUMNS_ITEMS = 'items';
44 private Translator $translator;
45 private ServerRequestInterface $request;
47 private ?URLBuilderToken $id_token = null;
48 private ?URLBuilder $url_builder = null;
51
52 public function __construct(
53 private Pons $pons,
54 private readonly GroupsRepository $repository,
55 private readonly TokenContainer $token_container,
56 ) {
57 global $DIC;
58
59 $this->translator = $pons->i18n();
60 $this->ui_factory = $pons->out()->ui()->factory();
61 $this->url_builder = $this->token_container->builder();
62 $this->id_token = $this->token_container->token();
63 $this->request = $pons->in()->request();
64 $this->translations_repository = $pons->i18n()->ml()->repository();
65 $this->collector = $DIC->globalScreen()->collector()->footer();
66 $this->identification = $DIC->globalScreen()->identification();
67 }
68
69 public function getRows(OrderingRowBuilder $row_builder, array $visible_column_ids): \Generator
70 {
71 $ok = $this->pons->out()->ok();
72 $nok = $this->pons->out()->nok();
73 $edit_entries = $this->pons->flow()->getTargetURI(\ilFooterEntriesGUI::class, \ilFooterEntriesGUI::CMD_DEFAULT);
74
75 $write_access = $this->pons->access()->hasUserPermissionTo('write');
76
77 foreach ($this->repository->all() as $group) {
78 if ($group->isCore()) {
79 $title = $this->collector->getSingleItemFromRaw(
80 $this->identification->fromSerializedIdentification($group->getId()),
81 )?->getTitle()??'';
82 } else {
83 $title = $this->translations_repository->get($group)->getDefault()?->getTranslation(
84 ) ?? $group->getTitle();
85 }
86 $row = $row_builder->buildOrderingRow(
87 $this->hash($group->getId()),
88 [
89 self::COLUMN_TITLE => $this->ui_factory->link()->standard(
90 $title,
91 $this->url_builder
92 ->withURI($edit_entries)
93 ->withParameter($this->id_token, $this->hash($group->getId()))
94 ->buildURI()
95 ),
96 self::COLUMN_ACTIVE => $group->isActive() ? $ok : $nok,
97 self::CLUMNS_ITEMS => $group->getItems(),
98 ]
99 );
100
101 if (!$write_access || $group->isCore()) {
102 $row = $row->withDisabledAction('delete')
103 ->withDisabledAction('translate')
104 ->withDisabledAction('move');
105 }
106
107 yield $row;
108 }
109 }
110
111 public function get(): Ordering
112 {
113 $flow = $this->pons->flow();
114 return $this->ui_factory
115 ->table()
116 ->ordering(
117 $this,
118 $flow->getHereAsURI(\ilFooterGroupsGUI::CMD_SAVE_ORDER),
119 $this->translator->translate('groups'),
120 [
121 self::COLUMN_TITLE => $this->ui_factory->table()->column()->link(
122 $this->translator->translate('title', 'group')
123 ),
124 self::COLUMN_ACTIVE => $this->ui_factory->table()->column()->statusIcon(
125 $this->translator->translate('active', 'group')
126 ),
127 self::CLUMNS_ITEMS => $this->ui_factory->table()->column()->text(
128 $this->translator->translate('items', 'group')
129 ),
130 ],
131 )
132 ->withRequest($this->request)
133 ->withActions(
134 [
135 'edit_entries' => $this->ui_factory->table()->action()->single(
136 $this->translator->translate('edit_entries', 'group'),
137 $this->url_builder->withURI(
138 $flow->getTargetURI(\ilFooterEntriesGUI::class, \ilFooterEntriesGUI::CMD_DEFAULT)
139 ),
140 $this->id_token
141 )->withAsync(false),
142
143 'edit' => $this->ui_factory->table()->action()->single(
144 $this->translator->translate('edit', 'group'),
145 $this->url_builder->withURI($flow->getHereAsURI(\ilFooterGroupsGUI::CMD_EDIT)),
146 $this->id_token
147 )->withAsync(true),
148
149 'toggle_activation' => $this->ui_factory->table()->action()->standard(
150 $this->translator->translate('toggle_activation', 'group'),
151 $this->url_builder->withURI($flow->getHereAsURI(\ilFooterGroupsGUI::CMD_TOGGLE_ACTIVATION)),
152 $this->id_token
153 )->withAsync(false),
154
155 'delete' => $this->ui_factory->table()->action()->standard(
156 $this->translator->translate('delete', 'group'),
157 $this->url_builder->withURI($flow->getHereAsURI(\ilFooterGroupsGUI::CMD_CONFIRM_DELETE)),
158 $this->id_token
159 )->withAsync(true),
160 'translate' => $this->ui_factory->table()->action()->single(
161 $this->translator->translate('translate', 'group'),
162 $this->url_builder->withURI(
163 $flow->getTranslationAsURI()
164 ),
165 $this->id_token
166 )->withAsync(true),
167 ]
168 );
169 }
170
171}
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
Class IdentificationFactory All elements in the GlobalScreen service must be identifiable for the sup...
__construct(private Pons $pons, private readonly GroupsRepository $repository, private readonly TokenContainer $token_container,)
Definition: GroupsTable.php:52
getRows(OrderingRowBuilder $row_builder, array $visible_column_ids)
This is called by the (ordering-)table to retrieve rows; map data-records to rows using the $row_buil...
Definition: GroupsTable.php:69
TranslationsRepositoryDB $translations_repository
Definition: GroupsTable.php:46
buildOrderingRow(string $id, array $record)
This describes a Table to specify the order of its data (rows).
Definition: Ordering.php:29
This is how the factory for UI elements looks.
Definition: Factory.php:38
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Group.php:19
global $DIC
Definition: shib_login.php:26