ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilMMTopItemTableComponent.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
29use ILIAS\GlobalScreen\GUI\Hasher;
31
36{
37 use Hasher;
38
42 public const ACTION_EDIT_SUB_TEMS = 'edit_sub_tems';
46 public const ACTION_EDIT = 'edit';
50 public const ACTION_TRANSLATE = 'translate';
54 public const ACTION_ACTIVATE = 'activate';
58 public const ACTION_DEACTIVATE = 'deactivate';
62 public const ACTION_MOVE = 'move';
66 public const ACTION_DELETE = 'delete';
67 private ?URLBuilder $url_builder = null;
68 private ?URLBuilderToken $token = null;
71
72 public function __construct(
73 private Pons $pons,
74 TokenContainer $token_container,
75 private ilMMItemRepository $repository,
76 private bool $write_access
77 ) {
78 $this->ui_factory = $this->pons->out()->ui()->factory();
79 $this->ui_renderer = $this->pons->out()->ui()->renderer();
80 $this->url_builder = $token_container->builder();
81 $this->token = $token_container->token();
82 }
83
84 public function getRows(OrderingRowBuilder $row_builder, array $visible_column_ids): Generator
85 {
86 foreach ($this->repository->getTopItems() as $top_item) {
87 $id = $top_item['identification'];
88 $item = $this->repository->getItemFacade(
89 $this->repository->resolveIdentificationFromString($id)
90 );
91
92 $link = $this->ui_factory->link()->standard(
93 $item->getDefaultTitle(),
94 (string) $this->url_builder
95 ->withURI(
96 $this->pons->flow()->getTargetURI(ilMMSubItemGUI::class, ilMMSubItemGUI::CMD_DEFAULT)
97 )
98 ->withParameter($this->token, $this->hash($id))
99 ->buildURI()
100 )->withDisabled(
101 !$item->canHaveChildren()
102 );
103
104 $remark = $item->getStatus() !== null ? $this->ui_renderer->render($item->getStatus()) : '';
105
106 if (preg_match('/-[^-]*-/', $remark)) {
107 // this is a language variable, translate it
108 $substr = substr($remark, 1, -1);
109 $remark = $this->pons->i18n()->t($substr);
110 }
111
112 yield $row_builder->buildOrderingRow(
113 $this->hash($id),
114 [
115 'title' => $link,
116 'active' => $item->isActivated(),
117 'status' => $remark,
118 'sub_items' => ($item->canHaveChildren() ? $item->getAmountOfChildren() : '-'),
119 'css_id' => "mm_" . $item->identification()->getInternalIdentifier(),
120 'type' => $item->getTypeForPresentation(),
121 'provider' => $item->getProviderNameForPresentation(),
122 ]
123 )->withDisabledAction(
124 self::ACTION_ACTIVATE,
125 !$this->write_access || $item->isActivated()
126 )->withDisabledAction(
127 self::ACTION_DEACTIVATE,
128 !$this->write_access || !$item->isActivated(),
129 )->withDisabledAction(
130 self::ACTION_MOVE,
131 !$this->write_access || !$item->isInterchangeable()
132 )->withDisabledAction(
133 self::ACTION_DELETE,
134 !$this->write_access || !$item->isCustom()
135 )->withDisabledAction(
136 self::ACTION_EDIT,
137 !$this->write_access
138 )->withDisabledAction(
139 self::ACTION_TRANSLATE,
140 !$this->write_access
141 )->withDisabledAction(
142 self::ACTION_EDIT_SUB_TEMS,
143 !$item->canHaveChildren()
144 )->withDisabledAction(
145 self::ACTION_DEACTIVATE,
146 !$item->canBeDeactivated(),
147 );
148 }
149 }
150
151 public function get(): Component|array
152 {
153 return [
154 $this->ui_factory
155 ->table()
156 ->ordering(
157 $this,
158 $this->pons->flow()->getHereAsURI(ilMMTopItemGUI::CMD_SAVE_ORDER),
159 $this->pons->i18n()->t('subtab_topitems'),
160 [
161 'title' => $this->ui_factory->table()->column()->link(
162 $this->pons->i18n()->t('title', 'topitem'),
163 ),
164 'active' => $this->ui_factory->table()->column()->boolean(
165 $this->pons->i18n()->t('active', 'topitem'),
166 $this->pons->out()->ok(),
167 $this->pons->out()->nok(),
168 ),
169 'status' => $this->ui_factory->table()->column()->text(
170 $this->pons->i18n()->t('status', 'sub')
171 ),
172 'sub_items' => $this->ui_factory->table()->column()->text(
173 $this->pons->i18n()->t('subentries', 'topitem'),
174 ),
175 'type' => $this->ui_factory->table()->column()->text(
176 $this->pons->i18n()->t('type', 'topitem'),
177 ),
178 'provider' => $this->ui_factory->table()->column()->text(
179 $this->pons->i18n()->t('provider', 'topitem'),
180 ),
181 ]
182 )
183 ->withRequest($this->pons->in()->request())
184 ->withActions(
185 [
186 self::ACTION_EDIT_SUB_TEMS => $this->ui_factory->table()->action()->single(
187 $this->pons->i18n()->t('edit_sub_tems'),
188 $this->url_builder->withURI(
189 $this->pons->flow()->getTargetURI(ilMMSubItemGUI::class, ilMMSubItemGUI::CMD_DEFAULT)
190 ),
191 $this->token
192 ),
193 self::ACTION_EDIT => $this->ui_factory->table()->action()->single(
194 $this->pons->i18n()->t('edit'),
195 $this->url_builder->withURI(
196 $this->pons->flow()->getHereAsURI(ilMMTopItemGUI::CMD_EDIT)
197 ),
198 $this->token
199 )->withAsync(true),
200 self::ACTION_TRANSLATE => $this->ui_factory->table()->action()->single(
201 $this->pons->i18n()->t('translate'),
202 $this->url_builder->withURI(
203 $this->pons->flow()->getTranslationAsURI()
204 ),
205 $this->token
206 )->withAsync(true),
207 self::ACTION_ACTIVATE => $this->ui_factory->table()->action()->standard(
208 $this->pons->i18n()->t('activate'),
209 $this->url_builder->withURI(
210 $this->pons->flow()->getHereAsURI(ilMMTopItemGUI::CMD_ACTIVATE)
211 ),
212 $this->token
213 ),
214 self::ACTION_DEACTIVATE => $this->ui_factory->table()->action()->standard(
215 $this->pons->i18n()->t('deactivate'),
216 $this->url_builder->withURI(
217 $this->pons->flow()->getHereAsURI(ilMMTopItemGUI::CMD_DEACTIVATE)
218 ),
219 $this->token
220 ),
221 self::ACTION_MOVE => $this->ui_factory->table()->action()->standard(
222 $this->pons->i18n()->t('move'),
223 $this->url_builder->withURI(
224 $this->pons->flow()->getHereAsURI(ilMMTopItemGUI::CMD_SELECT_PARENT)
225 ),
226 $this->token
227 )->withAsync(true),
228 self::ACTION_DELETE => $this->ui_factory->table()->action()->standard(
229 $this->pons->i18n()->t('delete'),
230 $this->url_builder->withURI(
231 $this->pons->flow()->getHereAsURI(ilMMTopItemGUI::CMD_CONFIRM_DELETE)
232 ),
233 $this->token
234 )->withAsync(true),
235 ]
236 )
237 ];
238 }
239}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
const CMD_CONFIRM_DELETE
__construct(private Pons $pons, TokenContainer $token_container, private ilMMItemRepository $repository, private bool $write_access)
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...
A component is the most general form of an entity in the UI.
Definition: Component.php:28
buildOrderingRow(string $id, array $record)
This is how the factory for UI elements looks.
Definition: Factory.php:38
An entity that renders components to a string output.
Definition: Renderer.php:31