ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
class.ilLOTestAssignmentTableGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=0);
20
21use ILIAS\Data\Factory as ilDataFactory;
22use ILIAS\HTTP\Services as ilHTTPServices;
23use ILIAS\Refinery\Factory as ilRefineryFactory;
24use ILIAS\UI\Component\Table\Data as ilDataTable;
26use ILIAS\DI\UIServices as ilUIServices;
27use ILIAS\UI\URLBuilderToken as ilURLBuilderToken;
28use JetBrains\PhpStorm\NoReturn;
29
35{
36 public const int TYPE_MULTIPLE_ASSIGNMENTS = 1;
37 public const int TYPE_SINGLE_ASSIGNMENTS = 2;
38 public const string TABLE_COL_TITLE = 'title';
39 public const string TABLE_COL_COURSE_OBJECTIVES = 'objective';
40 public const string TABLE_COL_SELECTION_OF_TEST_QUESTIONS = 'ttype';
41 public const string TABLE_COL_QESTIONS = 'qstqpl';
42 protected const string ALL_OBJECTS = "ALL_OBJECTS";
43 protected const string TABLE_ID = 'lotstasstbl';
44 protected const string ROW_ID = 'row_ids';
45 protected const string TABLE_ACTION_ID = 'table_action';
46 protected const string TABLE_ACTION_CONFIRM_DELETE_TESTS = 'confirmDeleteTests';
47 protected const string TABLE_ACTION_CONFIRM_DELETE_TEST = 'confirmDeleteTest';
48 protected const string ACTION_CONFIRM_DELETE_TEST = "delete_selected_test";
49 protected const string ACTION_CONFIRM_DELETE_TESTS = "delete_selected_tests";
50 protected const string LNG_TABLE_COL_TITLE = 'title';
51 protected const string LNG_TABLE_COL_COURSE_OBJECTIVES = 'crs_objectives';
52 protected const string LNG_TABLE_COL_SELECTION_OF_TEST_QUESTIONS = 'crs_loc_tbl_tst_type';
53 protected const string LNG_TABLE_COL_QESTIONS = 'crs_loc_tbl_tst_qst_qpl';
54 protected const string LNG_TABLE_ACTION_CONFIRM_DELETE_TESTS = 'crs_loc_delete_assignment';
55 protected const string LNG_TABLE_ACTION_CONFIRM_DELETE_TEST = 'crs_loc_delete_assignment';
56
58 protected ilDataFactory $data_factory;
59 protected ilURLBuilderToken $action_parameter_token;
60 protected ilURLBuilderToken $row_id_token;
61 protected ilDataTable $table;
63
64 public function __construct(
65 protected int $assignment_type,
66 protected int $test_type,
67 protected int $container_id,
68 protected ilLanguage $lng,
69 protected ilUIServices $ui_services,
70 protected ilHTTPServices $http_services,
71 protected ilLOTestAssignmentTableDataRetrieval $data_retrieval,
72 protected ilRefineryFactory $refinery,
73 protected ilCtrl $ctrl,
74 protected object $parent_object
75 ) {
76 $this->data_factory = new ilDataFactory();
77 $this->settings = ilLOSettings::getInstanceByObjId($container_id);
78 }
79
80 protected function getColumns(): array
81 {
82 $columns = [];
83 $columns[self::TABLE_COL_TITLE] = $this->ui_services->factory()->table()->column()->link(
84 $this->lng->txt(self::LNG_TABLE_COL_TITLE)
85 )->withIsSortable(true);
86 if ($this->getAssignmentType() == self::TYPE_MULTIPLE_ASSIGNMENTS) {
87 $columns[self::TABLE_COL_COURSE_OBJECTIVES] = $this->ui_services->factory()->table()->column()->text(
88 $this->lng->txt(self::LNG_TABLE_COL_COURSE_OBJECTIVES)
89 )->withIsSortable(false);
90 }
91 $columns[self::TABLE_COL_SELECTION_OF_TEST_QUESTIONS] = $this->ui_services->factory()->table()->column()->text(
92 $this->lng->txt(self::LNG_TABLE_COL_SELECTION_OF_TEST_QUESTIONS)
93 )->withIsSortable(false);
94 $columns[self::TABLE_COL_QESTIONS] = $this->ui_services->factory()->table()->column()->text(
95 $this->lng->txt(self::LNG_TABLE_COL_QESTIONS)
96 )->withIsSortable(false);
97 return $columns;
98 }
99
100 protected function getActions(): array
101 {
102 $this->url_builder = new URLBuilder($this->data_factory->uri($this->http_services->request()->getUri()->__toString()));
103 list($this->url_builder, $this->action_parameter_token, $this->row_id_token) =
104 $this->url_builder->acquireParameters(
105 ['datatable', self::TABLE_ID],
106 self::TABLE_ACTION_ID,
107 self::ROW_ID
108 );
109 $actions = [];
110 if ($this->getAssignmentType() === self::TYPE_MULTIPLE_ASSIGNMENTS) {
111 $actions[self::TABLE_ACTION_CONFIRM_DELETE_TESTS] = $this->ui_services->factory()->table()->action()->multi(
112 $this->lng->txt(self::LNG_TABLE_ACTION_CONFIRM_DELETE_TESTS),
113 $this->url_builder->withParameter($this->action_parameter_token, self::TABLE_ACTION_CONFIRM_DELETE_TESTS),
114 $this->row_id_token,
115 )->withAsync();
116 }
117 if ($this->getAssignmentType() !== self::TYPE_MULTIPLE_ASSIGNMENTS) {
118 $actions[self::TABLE_ACTION_CONFIRM_DELETE_TESTS] = $this->ui_services->factory()->table()->action()->multi(
119 $this->lng->txt(self::LNG_TABLE_ACTION_CONFIRM_DELETE_TEST),
120 $this->url_builder->withParameter($this->action_parameter_token, self::TABLE_ACTION_CONFIRM_DELETE_TEST),
121 $this->row_id_token,
122 )->withAsync();
123 }
124 return $actions;
125 }
126
127 protected function getTitleLangVar(): string
128 {
129 switch ($this->test_type) {
131 if (
132 $this->getAssignmentType() === self::TYPE_SINGLE_ASSIGNMENTS &&
133 $this->getSettings()->isInitialTestQualifying()
134 ) {
135 return 'crs_loc_settings_tbl_its_q_all';
136 }
137 if (
138 $this->getAssignmentType() === self::TYPE_SINGLE_ASSIGNMENTS &&
139 !$this->getSettings()->isInitialTestQualifying()
140 ) {
141 return 'crs_loc_settings_tbl_its_nq_all';
142 }
143 if ($this->getSettings()->isInitialTestQualifying()) {
144 return 'crs_loc_settings_tbl_it_q';
145 }
146 if (!$this->getSettings()->isInitialTestQualifying()) {
147 return 'crs_loc_settings_tbl_it_nq';
148 }
149 break;
150
152 if ($this->getAssignmentType() === self::TYPE_SINGLE_ASSIGNMENTS) {
153 return 'crs_loc_settings_tbl_qts_all';
154 }
155 if ($this->getAssignmentType() !== self::TYPE_SINGLE_ASSIGNMENTS) {
156 return 'crs_loc_settings_tbl_qt';
157 }
158 break;
159 }
160 return 'lng_title_missing';
161 }
162
163 protected function initTable(): void
164 {
165 if (isset($this->table)) {
166 return;
167 }
168 $this->table = $this->ui_services->factory()->table()->data(
169 $this->data_retrieval,
170 $this->lng->txt($this->getTitleLangVar()),
171 $this->getColumns()
172 )
173 ->withId(self::TABLE_ID)
174 ->withActions($this->getActions())
175 ->withRequest($this->http_services->request());
176 }
177
178 protected function allIds(): array
179 {
180 return $this->data_retrieval->allIds();
181 }
182
183 protected function readIdsFromQuery(): array
184 {
185 $tokens = $this->http_services->wrapper()->query()->retrieve(
186 $this->row_id_token->getName(),
187 $this->refinery->custom()->transformation(fn($v) => $v)
188 );
189 return is_null($tokens)
190 ? []
191 : (is_array($tokens) ? $tokens : [$tokens]);
192 }
193
194 #[NoReturn] protected function showDeleteModal(
195 array $id_map,
197 ): void {
198 $items = [];
199 foreach ($id_map as $id => $obj_id) {
200 $items[] = $this->ui_services->factory()->modal()->interruptiveItem()->standard(
201 $id,
202 ilObject::_lookupTitle($obj_id),
203 );
204 }
205 echo($this->ui_services->renderer()->renderAsync([
206 $this->ui_services->factory()->modal()->interruptive(
207 $this->lng->txt('crs_loc_delete_assignment'),
208 $this->lng->txt('crs_loc_confirm_delete_tst'),
209 (string) $this->url_builder
210 ->withParameter(
211 $this->action_parameter_token,
213 )->withParameter(
214 $this->row_id_token,
215 array_keys($id_map)
216 )->buildURI()
217 )->withAffectedItems($items)
218 ]));
219 exit();
220 }
221
222 protected function deleteTests(array $ids): void
223 {
224 foreach ($ids as $assign_id) {
225 $assignment = new ilLOTestAssignment($assign_id);
226 $assignment->delete();
227
228 // finally delete start object assignment
229 $start = new ilContainerStartObjects(
230 $this->getParentObject()->getRefId(),
231 $this->getParentObject()->getId()
232 );
233 $start->deleteItem($assignment->getTestRefId());
234
235 // ... and assigned questions
236 ilCourseObjectiveQuestion::deleteTest($assignment->getTestRefId());
237 }
238 $this->ctrl->redirectByClass('ilLOEditorGUI', 'testOverview');
239 }
240
241 protected function deleteTest(array $ids): void
242 {
244 foreach ($ids as $tst_id) {
245 switch ($this->getTestType()) {
247 $settings->setInitialTest(0);
248 break;
249
252 break;
253 }
254 $settings->update();
255
256 // finally delete start object assignment
257 $start = new ilContainerStartObjects(
258 $this->getParentObject()->getRefId(),
259 $this->getParentObject()->getId()
260 );
261 $start->deleteItem($tst_id);
262
263 // ... and assigned questions
265 }
266 $this->ctrl->redirectByClass('ilLOEditorGUI', 'testOverview');
267 }
268
269 public function getHTML(): string
270 {
271 $this->initTable();
272 return $this->ui_services->renderer()->render([$this->table]);
273 }
274
275 public function getAssignmentType(): int
276 {
277 return $this->assignment_type;
278 }
279
280 public function getSettings(): ilLOSettings
281 {
282 return $this->settings;
283 }
284
285 public function getParentObject(): object
286 {
287 return $this->parent_object;
288 }
289
290 public function getTestType(): int
291 {
292 return $this->test_type;
293 }
294
295 public function handleCommands(): void
296 {
297 $this->initTable();
298 if (!$this->http_services->wrapper()->query()->has($this->action_parameter_token->getName())) {
299 return;
300 }
301 $action = $this->http_services->wrapper()->query()->retrieve(
302 $this->action_parameter_token->getName(),
303 $this->refinery->to()->string()
304 );
305 $tokens = $this->http_services->wrapper()->query()->retrieve(
306 $this->row_id_token->getName(),
307 $this->refinery->custom()->transformation(fn($v) => $v)
308 );
309 $all_entries = ($tokens[0] ?? "") === self::ALL_OBJECTS;
310 $ids = [];
311 if ($all_entries) {
312 $ids = $this->allIds();
313 }
314 if (!$all_entries) {
315 $ids = $this->readIdsFromQuery();
316 }
317 if (is_null($ids[0]) || count($ids) === 0) {
318 return;
319 }
320 switch ($action) {
322 $id_map = [];
323 foreach ($ids as $id) {
325 ;
326 }
327 $this->showDeleteModal($id_map, self::ACTION_CONFIRM_DELETE_TEST);
328 break;
330 $id_map = [];
331 foreach ($ids as $id) {
332 $assignment = new ilLOTestAssignment($id);
333 $id_map[$id] = ilObject::_lookupObjId($assignment->getTestRefId());
334 }
335 $this->showDeleteModal($id_map, self::ACTION_CONFIRM_DELETE_TESTS);
336 break;
338 $this->deleteTest($ids);
339 break;
341 $this->deleteTests($ids);
342 break;
343 }
344 }
345}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Provides fluid interface to RBAC services.
Definition: UIServices.php:25
Builds data types.
Definition: Factory.php:36
Class Services.
Definition: Services.php:38
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilCtrl provides processing control methods.
Settings for LO courses.
static getInstanceByObjId(int $a_obj_id)
setInitialTest(int $a_id)
setQualifiedTest(int $a_id)
Class ilLOTestAssignmentTableGUI.
__construct(protected int $assignment_type, protected int $test_type, protected int $container_id, protected ilLanguage $lng, protected ilUIServices $ui_services, protected ilHTTPServices $http_services, protected ilLOTestAssignmentTableDataRetrieval $data_retrieval, protected ilRefineryFactory $refinery, protected ilCtrl $ctrl, protected object $parent_object)
Settings for LO courses.
language handling
static _lookupObjId(int $ref_id)
static _lookupTitle(int $obj_id)
exit
This describes a Data Table.
Definition: Data.php:33
global $lng
Definition: privfeed.php:31