ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
class.ilMMSubItemTableComponent.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
30use ILIAS\GlobalScreen\GUI\Hasher;
32
37{
38 use Hasher;
39
43 public const ACTION_EDIT = 'edit';
47 public const ACTION_TRANSLATE = 'translate';
51 public const ACTION_ACTIVATE = 'activate';
55 public const ACTION_DEACTIVATE = 'deactivate';
59 public const ACTION_MOVE = 'move';
63 public const ACTION_DELETE = 'delete';
64 private UIServices $ui;
65 private ?URLBuilder $url_builder = null;
66 private ?URLBuilderToken $token = null;
69
70 public function __construct(
71 private Pons $pons,
72 TokenContainer $token_container,
73 private ilMMItemRepository $repository,
74 private ?ilMMItemFacadeInterface $parent_item,
75 private bool $write_access
76 ) {
77 $this->ui_factory = $this->pons->out()->ui()->factory();
78 $this->ui_renderer = $this->pons->out()->ui()->renderer();
79 $this->url_builder = $token_container->builder();
80 $this->token = $token_container->token();
81 }
82
83 public function getRows(OrderingRowBuilder $row_builder, array $visible_column_ids): Generator
84 {
85 if ($this->parent_item === null) {
86 $items = $this->repository->getLostItems();
87 } else {
88 $items = $this->repository->getSubItemsForTable($this->parent_item);
89 }
90
91 foreach ($items as $sub_item) {
92 $id = $sub_item['identification'];
93 $item = $this->repository->getItemFacade(
94 $this->repository->resolveIdentificationFromString($id)
95 );
96
97 $remark = $item->getStatus() !== null ? $this->ui_renderer->render($item->getStatus()) : '';
98
99 if (preg_match('/^-\w+-$/', $remark)) {
100 // this is a language variable, translate it
101 $remark = $this->pons->i18n()->t(substr($remark, 1, -1));
102 }
103
104 yield $row_builder->buildOrderingRow(
105 $this->hash($id),
106 [
107 'title' => $item->getDefaultTitle(),
108 'active' => $item->isActivated(),
109 'status' => $remark,
110 'type' => $item->getTypeForPresentation(),
111 'provider' => $item->getProviderNameForPresentation(),
112 ]
113 )->withDisabledAction(
114 self::ACTION_ACTIVATE,
115 !$this->write_access || $item->isActivated()
116 )->withDisabledAction(
117 self::ACTION_DEACTIVATE,
118 !$this->write_access || !$item->isActivated(),
119 )->withDisabledAction(
120 self::ACTION_MOVE,
121 !$this->write_access || !$item->isInterchangeable()
122 )->withDisabledAction(
123 self::ACTION_DELETE,
124 !$this->write_access || !$item->isCustom()
125 )->withDisabledAction(
126 self::ACTION_TRANSLATE,
127 !$this->write_access
128 )->withDisabledAction(
129 self::ACTION_EDIT,
130 !$this->write_access
131 )->withDisabledAction(
132 self::ACTION_DEACTIVATE,
133 !$item->canBeDeactivated(),
134 );
135 }
136 }
137
138 public function get(): Component|array
139 {
140 if ($this->write_access) {
141 $actions = [
142 self::ACTION_EDIT => $this->ui_factory->table()->action()->single(
143 $this->pons->i18n()->t('edit'),
144 $this->url_builder->withURI(
145 $this->pons->flow()->getHereAsURI(ilMMSubItemGUI::CMD_EDIT)
146 ),
148 )->withAsync(true),
149 self::ACTION_TRANSLATE => $this->ui_factory->table()->action()->single(
150 $this->pons->i18n()->t('translate'),
151 $this->url_builder->withURI(
152 $this->pons->flow()->getTranslationAsURI()
153 ),
155 )->withAsync(true),
156 self::ACTION_ACTIVATE => $this->ui_factory->table()->action()->standard(
157 $this->pons->i18n()->t('activate'),
158 $this->url_builder->withURI(
159 $this->pons->flow()->getHereAsURI(ilMMSubItemGUI::CMD_ACTIVATE)
160 ),
162 ),
163 self::ACTION_DEACTIVATE => $this->ui_factory->table()->action()->standard(
164 $this->pons->i18n()->t('deactivate'),
165 $this->url_builder->withURI(
166 $this->pons->flow()->getHereAsURI(ilMMSubItemGUI::CMD_DEACTIVATE)
167 ),
169 ),
170 self::ACTION_MOVE => $this->ui_factory->table()->action()->standard(
171 $this->pons->i18n()->t('move'),
172 $this->url_builder->withURI(
173 $this->pons->flow()->getHereAsURI(ilMMSubItemGUI::CMD_CONFIRM_MOVE)
174 ),
176 )->withAsync(true),
177 self::ACTION_DELETE => $this->ui_factory->table()->action()->standard(
178 $this->pons->i18n()->t('delete'),
179 $this->url_builder->withURI(
180 $this->pons->flow()->getHereAsURI(ilMMSubItemGUI::CMD_CONFIRM_DELETE)
181 ),
183 )->withAsync(true),
184 ];
185 } else {
186 $actions = [];
187 }
188 return [
189 $this
190 ->ui_factory
191 ->table()
192 ->ordering(
193 $this,
194 $this->pons->flow()->getHereAsURI(ilMMSubItemGUI::CMD_SAVE_ORDER),
195 $this->parent_item?->getDefaultTitle() ?? $this->pons->i18n()->t('mme_lost_items'),
196 [
197 'title' => $this->ui_factory->table()->column()->text(
198 $this->pons->i18n()->t('title', 'sub'),
199 ),
200 'active' => $this->ui_factory->table()->column()->boolean(
201 $this->pons->i18n()->t('active', 'sub'),
202 $this->pons->out()->ok(),
203 $this->pons->out()->nok(),
204 ),
205 'status' => $this->ui_factory->table()->column()->text(
206 $this->pons->i18n()->t('status', 'sub'),
207 ),
208 'type' => $this->ui_factory->table()->column()->text(
209 $this->pons->i18n()->t('type', 'topitem'),
210 ),
211 'provider' => $this->ui_factory->table()->column()->text(
212 $this->pons->i18n()->t('provider', 'topitem'),
213 ),
214 ]
215 )->withRequest(
216 $this->pons->in()->request()
217 )
218 ->withOrderingDisabled(!$this->write_access)
219 ->withActions($actions)
220 ];
221 }
222}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Provides fluid interface to RBAC services.
Definition: UIServices.php:25
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
const CMD_CONFIRM_DELETE
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...
__construct(private Pons $pons, TokenContainer $token_container, private ilMMItemRepository $repository, private ?ilMMItemFacadeInterface $parent_item, private bool $write_access)
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
Interface ilMMItemFacadeInterface.