ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
LSOAdaptiveTable.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
26readonly class LSOAdaptiveTable
27{
33 public function __construct(
35 private \ILIAS\UI\Factory $ui_factory,
39 private array $objects,
41 private ?\ILIAS\UI\Component\Input\Container\Filter\Standard $filter = null,
43 private int $start_ref_id = 0,
45 private int $end_ref_id = 0,
47 private ?\ilObjLearningSequenceContentGUI $parent_gui = null,
49 private int $ref_id = 0,
51 private ?\ilLanguage $lng = null,
53 private ?\ilCtrl $ctrl = null,
55 private ?\Psr\Http\Message\ServerRequestInterface $request = null,
57 private ?\ilGlobalTemplateInterface $tpl = null
58 ) {
59 }
60
64 public function render(): string
65 {
66 $data = $this->objects;
67 $view_controls = [];
68
69 if ($this->filter !== null) {
70 $view_controls[] = $this->filter;
71 }
72
73 $modals = [];
74 $item_status = new LSOAdaptiveItemStatus($this->ui_factory, $this->lng);
75 $environment = $this->buildEnvironment($modals, $item_status);
76
77 $mapping = function (
78 $row,
80 $ui_factory,
81 array $env
82 ) {
83 $leading_icon = $ui_factory->symbol()->icon()->custom(
84 $record->icon_path,
85 $record->type
86 );
87
88 $actions = $env['actions']($record);
89 $content = $env['content']($record);
90 $headline = $env['headline']($record);
91
92 return $row
93 ->withHeadline($headline)
94 ->withLeadingSymbol($leading_icon)
95 ->withSubheadline($record->description)
96 ->withTags(...$env['tags']($record))
97 ->withContent($content)
98 ->withFurtherFieldsHeadline($this->lng->txt('lso_adaptive_information'))
99 ->withFurtherFields($env['further_fields']($record))
100 ->withAction($actions);
101 };
102
103 $table = $this->ui_factory->table()->presentation(
104 $this->lng->txt('table_sequence_content'),
105 $view_controls,
106 $mapping
107 )
108 ->withEnvironment($environment)
109 ->withData($data);
110
111 $html = $this->ui_renderer->render($table);
112
113 if ($modals !== []) {
114 $html .= $this->ui_renderer->render($modals);
115 }
116
117 return $html;
118 }
119
126 private function buildEnvironment(array &$modals, LSOAdaptiveItemStatus $item_status): array
127 {
128 $headline = function (\ilObjLearningSequenceContentData $record): string {
129 return $this->ui_renderer->render(
130 $this->ui_factory->link()->standard($record->title, $record->href)
131 );
132 };
133
134 $tags = fn(\ilObjLearningSequenceContentData $record): array => $item_status->getTags($record);
135
136 $actions = function (\ilObjLearningSequenceContentData $record) use (&$modals) {
137 $dropdown_items = [];
138 $lso = \ilObjLearningSequence::getInstanceByRefId($this->ref_id);
139 $ref_id = $lso->getRefId();
140 $obj_id = $lso->getId();
141
142 $specific_actions = new LSOAdaptiveContent(
143 $this->parent_gui,
144 $this->ui_factory,
145 $this->ui_renderer,
146 $this->lng,
147 $this->ctrl,
148 $this->request,
149 $this->tpl,
150 $ref_id,
151 $obj_id
153 $record->ref_id,
154 $this->start_ref_id,
155 $this->end_ref_id
156 );
157 $action_data = $this->parent_gui->getTableActionHandler()->collectActions(
158 $record->ref_id,
159 $specific_actions,
160 $record->is_online
161 );
162
163 foreach ($action_data as $id => $action) {
164 if ($action->is_divider) {
165 $dropdown_items[] = $this->ui_factory->divider()->horizontal();
166 continue;
167 }
168
169 $label = $action->label;
170 $link = $action->link;
171 if (strpos($link, 'http') !== 0 && strpos($link, 'ilias.php') === false) {
172 $this->ctrl->setParameter($this->parent_gui, 'item_ref_id', $record->ref_id);
173 $link = $this->ctrl->getLinkTarget($this->parent_gui, $link);
174 }
175
176 $dropdown_items[] = $this->ui_factory->button()->shy($label, $link);
177 }
178
179 $delete_modal = $this->buildDeleteModal($record->ref_id, $record->title);
180 $modals[$record->ref_id] = $delete_modal;
181 $dropdown_items[] = $this->ui_factory->button()->shy(
182 $this->lng->txt('delete'),
183 ''
184 )->withOnClick($delete_modal->getShowSignal());
185
186 return $this->ui_factory->dropdown()->standard($dropdown_items)->withLabel('');
187 };
188
189 $content = function (\ilObjLearningSequenceContentData $record) use ($item_status) {
190 $items = [
191 $this->lng->txt('input_conditions') => $this->buildConditionListing($record->input_conditions),
192 $this->lng->txt('output_conditions') => $this->buildConditionListing($record->output_conditions),
193 ];
194 $issues = $item_status->getConfigurationIssues($record);
195 if ($issues !== null) {
196 $items[$this->lng->txt('lso_adaptive_misconfigured')] = $issues;
197 }
198
199 return $this->ui_factory->listing()->descriptive($items);
200 };
201
202 $further_fields = fn(\ilObjLearningSequenceContentData $record): array => [
203 $this->lng->txt('lso_adaptive_previous_object') . ':' => htmlspecialchars(trim($record->previous_objects)),
204 $this->lng->txt('lso_adaptive_next_object') . ':' => htmlspecialchars(trim($record->next_objects)),
205 ];
206
207 return [
208 'headline' => $headline,
209 'tags' => $tags,
210 'actions' => $actions,
211 'content' => $content,
212 'further_fields' => $further_fields,
213 ];
214 }
215
219 private function buildDeleteModal(int $ref_id, string $title): \ILIAS\UI\Component\Modal\Interruptive
220 {
221 $this->ctrl->setParameter($this->parent_gui, 'item_ref_id', '');
222 $form_action = $this->ctrl->getFormAction(
223 $this->parent_gui,
225 );
226
227 $item = $this->ui_factory->modal()->interruptiveItem()->keyValue(
228 (string) $ref_id,
229 $this->lng->txt('title'),
230 $title
231 );
232
233 return $this->ui_factory->modal()->interruptive(
234 $this->lng->txt('delete'),
235 $this->lng->txt('info_delete_sure'),
236 $form_action
237 )
238 ->withAffectedItems([$item])
239 ->withActionButtonLabel($this->lng->txt('delete'));
240 }
241
247 private function buildConditionListing(array $conditions): string|\ILIAS\UI\Component\Listing\Property
248 {
249 if ($conditions === []) {
250 return $this->lng->txt('no_conditions');
251 }
252
253 $listing = $this->ui_factory->listing()->property();
254 foreach ($conditions as $condition) {
255 $listing = $condition->value === ''
256 ? $listing->withProperty($condition->title, $condition->title, false)
257 : $listing->withProperty($condition->title, $condition->value);
258 }
259
260 return $listing;
261 }
262}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Controls adaptive learning sequence content management.
getSpecificActions(int $ref_id, int $start_ref_id, int $end_ref_id)
Gets actions specific to an adaptive learning sequence item.
Describes the status of an item in the adaptive content table: the tags shown below its title and the...
getTags(\ilObjLearningSequenceContentData $record)
The status tags of the item.
getConfigurationIssues(\ilObjLearningSequenceContentData $record)
The configuration issues of a misconfigured item, or null if its configuration is fine.
Renders the adaptive learning sequence content table.
buildEnvironment(array &$modals, LSOAdaptiveItemStatus $item_status)
Builds the presentation table environment.
buildConditionListing(array $conditions)
Builds a listing of condition titles and values.
buildDeleteModal(int $ref_id, string $title)
Builds the delete confirmation modal for an item.
Definition: UI.php:27
__construct()
Constructor setup ILIAS global object @access public.
Definition: class.ilias.php:76
Class ilCtrl provides processing control methods.
language handling
Data transfer object for an item in the learning sequence content table.
static getInstanceByRefId(int $ref_id)
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
$request
@ilCtrl_Calls ilObjLearningSequenceContentGUI: ilObjLearningSequenceConditionsGUI
Definition: ltiauth.php:39
withAction(URI|Signal|string $action)
readonly ilGlobalTemplateInterface $tpl
filter(string $filter_id, array $class_path, string $cmd, bool $activated=true, bool $expanded=true)
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
global $lng
Definition: privfeed.php:26
$data
Definition: storeScorm.php:45