ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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 foreach ($this->repository->getSubItemsForTable($this->parent_item) as $top_item) {
86 $id = $top_item['identification'];
87 $item = $this->repository->getItemFacade(
88 $this->repository->resolveIdentificationFromString($id)
89 );
90
91 $remark = $item->getStatus() !== null ? $this->ui_renderer->render($item->getStatus()) : '';
92
93 if (preg_match('/^-[a-zA-Z0-9_]+-$/', $remark)) {
94 // this is a language variable, translate it
95 $remark = $this->pons->i18n()->t(substr($remark, 1, -1));
96 }
97
98 yield $row_builder->buildOrderingRow(
99 $this->hash($id),
100 [
101 'title' => $item->getDefaultTitle(),
102 'active' => $item->isActivated(),
103 'status' => $remark,
104 'type' => $item->getTypeForPresentation(),
105 'provider' => $item->getProviderNameForPresentation(),
106 ]
107 )->withDisabledAction(
108 self::ACTION_ACTIVATE,
109 !$this->write_access || $item->isActivated()
110 )->withDisabledAction(
111 self::ACTION_DEACTIVATE,
112 !$this->write_access || !$item->isActivated(),
113 )->withDisabledAction(
114 self::ACTION_MOVE,
115 !$this->write_access || !$item->isInterchangeable()
116 )->withDisabledAction(
117 self::ACTION_DELETE,
118 !$this->write_access || !$item->isCustom()
119 )->withDisabledAction(
120 self::ACTION_TRANSLATE,
121 !$this->write_access
122 )->withDisabledAction(
123 self::ACTION_EDIT,
124 !$this->write_access
125 )->withDisabledAction(
126 self::ACTION_DEACTIVATE,
127 !$item->canBeDeactivated(),
128 );
129 }
130 }
131
132 public function get(): Component|array
133 {
134 return [
135 $this->ui_factory->table()->ordering(
136 $this,
137 $this->pons->flow()->getHereAsURI(ilMMSubItemGUI::CMD_SAVE_ORDER),
138 $this->parent_item->getDefaultTitle(),
139 [
140 'title' => $this->ui_factory->table()->column()->text(
141 $this->pons->i18n()->t('title', 'sub'),
142 ),
143 'active' => $this->ui_factory->table()->column()->boolean(
144 $this->pons->i18n()->t('active', 'sub'),
145 $this->pons->out()->ok(),
146 $this->pons->out()->nok(),
147 ),
148 'status' => $this->ui_factory->table()->column()->text(
149 $this->pons->i18n()->t('status', 'sub'),
150 ),
151 'type' => $this->ui_factory->table()->column()->text(
152 $this->pons->i18n()->t('type', 'topitem'),
153 ),
154 'provider' => $this->ui_factory->table()->column()->text(
155 $this->pons->i18n()->t('provider', 'topitem'),
156 ),
157 ]
158 )->withRequest($this->pons->in()->request())
159 ->withActions(
160 [
161 self::ACTION_EDIT => $this->ui_factory->table()->action()->single(
162 $this->pons->i18n()->t('edit'),
163 $this->url_builder->withURI(
164 $this->pons->flow()->getHereAsURI(ilMMSubItemGUI::CMD_EDIT)
165 ),
166 $this->token
167 )->withAsync(true),
168 self::ACTION_TRANSLATE => $this->ui_factory->table()->action()->single(
169 $this->pons->i18n()->t('translate'),
170 $this->url_builder->withURI(
171 $this->pons->flow()->getTranslationAsURI()
172 ),
173 $this->token
174 )->withAsync(true),
175 self::ACTION_ACTIVATE => $this->ui_factory->table()->action()->standard(
176 $this->pons->i18n()->t('activate'),
177 $this->url_builder->withURI(
178 $this->pons->flow()->getHereAsURI(ilMMSubItemGUI::CMD_ACTIVATE)
179 ),
180 $this->token
181 ),
182 self::ACTION_DEACTIVATE => $this->ui_factory->table()->action()->standard(
183 $this->pons->i18n()->t('deactivate'),
184 $this->url_builder->withURI(
185 $this->pons->flow()->getHereAsURI(ilMMSubItemGUI::CMD_DEACTIVATE)
186 ),
187 $this->token
188 ),
189 self::ACTION_MOVE => $this->ui_factory->table()->action()->standard(
190 $this->pons->i18n()->t('move'),
191 $this->url_builder->withURI(
192 $this->pons->flow()->getHereAsURI(ilMMSubItemGUI::CMD_CONFIRM_MOVE)
193 ),
194 $this->token
195 )->withAsync(true),
196 self::ACTION_DELETE => $this->ui_factory->table()->action()->standard(
197 $this->pons->i18n()->t('delete'),
198 $this->url_builder->withURI(
199 $this->pons->flow()->getHereAsURI(ilMMSubItemGUI::CMD_CONFIRM_DELETE)
200 ),
201 $this->token
202 )->withAsync(true),
203 ]
204 )
205 ];
206 }
207}
$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.