ILIAS  trunk Revision v12.0_alpha-1540-g00f839d5fa1
class.ilUnitConfigurationGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
23
28{
31 protected ?ilPropertyFormGUI $unit_form = null;
33 protected ilLanguage $lng;
36
37 public function __construct(
38 protected ilUnitConfigurationRepository $repository
39 ) {
40 global $DIC;
41 $this->lng = $DIC->language();
42 $this->ctrl = $DIC->ctrl();
43 $this->tpl = $DIC->ui()->mainTemplate();
44 $this->access = $DIC->access();
45
46 $local_dic = QuestionPoolDIC::dic();
47 $this->request = $local_dic['request_data_collector'];
48
49 $this->lng->loadLanguageModule('assessment');
50 }
51
52 abstract protected function getDefaultCommand(): string;
53
54 abstract public function getUnitCategoryOverviewCommand(): string;
55
56 abstract public function isCRUDContext(): bool;
57
58 abstract public function getUniqueId(): string;
59
60 abstract protected function showUnitCategories(array $categories): void;
61
62 protected function getCategoryById(int $id, bool $for_CRUD = true): assFormulaQuestionUnitCategory
63 {
64 $category = $this->repository->getUnitCategoryById($id);
65 if ($for_CRUD && $category->getQuestionFi() !== $this->repository->getConsumerId()) {
66 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('change_adm_categories_not_allowed'), true);
67 $this->ctrl->redirect($this, $this->getDefaultCommand());
68 }
69
70 return $category;
71 }
72
73 protected function handleSubtabs(): void
74 {
75 }
76
77 protected function checkPermissions(string $cmd): void
78 {
79 if (!$this->access->checkAccess('read', '', $this->request->getRefId())) {
80 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('permission_denied'), true);
81 $this->ctrl->redirectToURL(ilUserUtil::getStartingPointAsUrl());
82 return;
83 }
84
85 if (in_array($cmd, ['showUnitCategories', 'showUnitsOfCategory', 'showGlobalUnitCategories'], true)) {
86 return;
87 }
88
89 if ($this->access->checkAccess('write', '', $this->request->getRefId())) {
90 return;
91 }
92
93 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('permission_denied'), true);
94 $this->ctrl->redirect($this, $this->getDefaultCommand());
95 }
96
97 public function executeCommand(): void
98 {
99 $cmd = $this->ctrl->getCmd($this->getDefaultCommand());
100 $this->checkPermissions($cmd);
101 match ($cmd) {
102 'confirmImportGlobalCategories' => $this->$cmd($this->request->getUnitCategoryIds()),
103 default => $this->$cmd(),
104 };
105
106 $this->handleSubtabs();
107 }
108
109 protected function confirmDeleteUnit(): void
110 {
111 if (!$this->request->isset('unit_id')) {
112 $this->showUnitsOfCategory();
113 return;
114 }
115
116 $this->confirmDeleteUnits([$this->request->int('unit_id')]);
117 }
118
124 protected function confirmDeleteUnits(?array $unit_ids = null): void
125 {
126 if (!$this->isCRUDContext()) {
127 $this->showUnitsOfCategory();
128 return;
129 }
130
131 $unit_ids = $unit_ids ?? $this->request->getUnitIds();
132 if (count($unit_ids) === 0) {
133 $this->showUnitsOfCategory();
134 return;
135 }
136
137 $this->ctrl->setParameter($this, 'category_id', $this->request->int('category_id'));
138 $confirmation = new ilConfirmationGUI();
139 $confirmation->setFormAction($this->ctrl->getFormAction($this, 'deleteUnits'));
140 $confirmation->setConfirm($this->lng->txt('confirm'), 'deleteUnits');
141 $confirmation->setCancel($this->lng->txt('cancel'), 'showUnitsOfCategory');
142
143 $errors = [];
144 $num_to_confirm = 0;
145 foreach ($unit_ids as $unit_id) {
146 try {
147 $unit = $this->repository->getUnit((int) $unit_id);
148 if (!$unit) {
149 continue;
150 }
151
152 if ($check_result = $this->repository->checkDeleteUnit($unit->getId())) {
153 $errors[] = $unit->getDisplayString() . ' - ' . $check_result;
154 continue;
155 }
156
157 $confirmation->addItem('unit_ids[]', (string) $unit->getId(), $unit->getDisplayString());
158 ++$num_to_confirm;
159 } catch (ilException $e) {
160 continue;
161 }
162 }
163
164 if ($errors) {
165 $num_errors = count($errors);
166
167 $error_message = array_map(static function (string $message): string {
168 return '<li>' . $message . '</li>';
169 }, $errors);
170 if ($num_errors === 1) {
171 $this->tpl->setOnScreenMessage(
172 'failure',
173 $this->lng->txt('un_unit_deletion_errors_f_s') . '<ul>' . implode('', $error_message) . '<ul>'
174 );
175 } else {
176 $this->tpl->setOnScreenMessage(
177 'failure',
178 $this->lng->txt('un_unit_deletion_errors_f') . '<ul>' . implode('', $error_message) . '<ul>'
179 );
180 }
181 }
182
183 if ($num_to_confirm) {
184 if ($num_to_confirm === 1) {
185 $confirmation->setHeaderText($this->lng->txt('un_sure_delete_units_s'));
186 } else {
187 $confirmation->setHeaderText($this->lng->txt('un_sure_delete_units'));
188 }
189
190 $this->tpl->setContent($confirmation->getHTML());
191 } else {
192 $this->showUnitsOfCategory();
193 }
194 }
195
196 public function deleteUnits(): void
197 {
198 if (!$this->isCRUDContext()) {
199 $this->showUnitsOfCategory();
200 return;
201 }
202
203 $unit_ids = $this->request->getUnitIds();
204 if (count($unit_ids) === 0) {
205 $this->showUnitsOfCategory();
206 return;
207 }
208
209 $errors = [];
210 $num_deleted = 0;
211 foreach ($unit_ids as $unit_id) {
212 try {
213 $unit = $this->repository->getUnit($unit_id);
214 if (!$unit) {
215 continue;
216 }
217
218 $check_result = $this->repository->deleteUnit($unit->getId());
219 if (!is_null($check_result)) {
220 $errors[] = $unit->getDisplayString() . ' - ' . $check_result;
221 continue;
222 }
223
224 ++$num_deleted;
225 } catch (ilException $e) {
226 continue;
227 }
228 }
229
230 if ($errors) {
231 $num_errors = count($errors);
232
233 $error_message = array_map(static function (string $message): string {
234 return '<li>' . $message . '</li>';
235 }, $errors);
236 if ($num_errors === 1) {
237 $this->tpl->setOnScreenMessage(
238 'failure',
239 $this->lng->txt('un_unit_deletion_errors_p_s') . '<ul>' . implode('', $error_message) . '<ul>'
240 );
241 } else {
242 $this->tpl->setOnScreenMessage(
243 'failure',
244 $this->lng->txt('un_unit_deletion_errors_p') . '<ul>' . implode('', $error_message) . '<ul>'
245 );
246 }
247 }
248
249 if ($num_deleted) {
250 if ($num_deleted === 1) {
251 $this->tpl->setOnScreenMessage('success', $this->lng->txt('un_deleted_units_s'));
252 } else {
253 $this->tpl->setOnScreenMessage('success', $this->lng->txt('un_deleted_units'));
254 }
255 }
256
257 $this->showUnitsOfCategory();
258 }
259
260 protected function saveOrder(): void
261 {
262 if (!$this->isCRUDContext()) {
263 $this->showUnitsOfCategory();
264 return;
265 }
266
267 if (!$this->request->isset('sequence') || !is_array($this->request->raw('sequence'))) {
268 $this->showUnitsOfCategory();
269 return;
270 }
271
272 $sequences = $this->request->raw('sequence');
273 foreach ($sequences as $id => $sequence) {
274 $sorting_value = str_replace(',', '.', $sequence);
275 $sorting_value = (int) $sorting_value * 100;
276 $this->repository->saveUnitOrder((int) $id, $sorting_value);
277 }
278
279 $this->tpl->setOnScreenMessage('success', $this->lng->txt('saved_successfully'));
280 $this->showUnitsOfCategory();
281 }
282
283 protected function saveUnit(): void
284 {
285 if (!$this->isCRUDContext()) {
286 $this->showUnitsOfCategory();
287 return;
288 }
289
290 $category = $this->getCategoryById($this->request->int('category_id'));
291 $unit = $this->repository->getUnit($this->request->int('unit_id'));
292
293 if ($this->repository->isUnitInUse($unit->getId())) {
295 return;
296 }
297
298 $this->initUnitForm($category, $unit);
299 if ($this->unit_form->checkInput()) {
300 $unit->setUnit($this->unit_form->getInput('unit_title'));
301 $unit->setFactor((float) $this->unit_form->getInput('factor'));
302 $unit->setBaseUnit((int) $this->unit_form->getInput('base_unit') !== $unit->getId() ? (int) $this->unit_form->getInput('base_unit') : 0);
303 $unit->setCategory($category->getId());
304 $this->repository->saveUnit($unit);
305
306 $this->tpl->setOnScreenMessage('success', $this->lng->txt('saved_successfully'));
307 $this->showUnitsOfCategory();
308 return;
309 }
310
311 $this->unit_form->setValuesByPost();
312
313 $this->tpl->setContent($this->unit_form->getHtml());
314 }
315
316 protected function showUnitModificationForm(): void
317 {
318 if (!$this->isCRUDContext()) {
319 $this->showUnitsOfCategory();
320 return;
321 }
322
323 $category = $this->getCategoryById($this->request->int('category_id'));
324 $unit = $this->repository->getUnit($this->request->int('unit_id'));
325
326 $this->initUnitForm($category, $unit);
327 $this->unit_form->setValuesByArray([
328 'factor' => $unit->getFactor(),
329 'unit_title' => $unit->getUnit(),
330 'base_unit' => $unit->getBaseUnit() !== $unit->getId() ? $unit->getBaseUnit() : 0
331 ]);
332
333 $this->tpl->setContent($this->unit_form->getHtml());
334 }
335
336 protected function addUnit(): void
337 {
338 if (!$this->isCRUDContext()) {
339 $this->showUnitsOfCategory();
340 return;
341 }
342
343 $category = $this->getCategoryById($this->request->int('category_id'));
344
345 $this->initUnitForm($category);
346 if ($this->unit_form->checkInput()) {
347 $unit = new assFormulaQuestionUnit();
348 $unit->setUnit($this->unit_form->getInput('unit_title'));
349 $unit->setCategory($category->getId());
350
351 $this->repository->createNewUnit($unit);
352
353 $unit->setBaseUnit((int) $this->unit_form->getInput('base_unit'));
354 $unit->setFactor((float) $this->unit_form->getInput('factor'));
355
356 $this->repository->saveUnit($unit);
357
358 $this->tpl->setOnScreenMessage('success', $this->lng->txt('saved_successfully'));
359 $this->showUnitsOfCategory();
360 return;
361 }
362
363 $this->unit_form->setValuesByPost();
364
365 $this->tpl->setContent($this->unit_form->getHtml());
366 }
367
368 protected function showUnitCreationForm(): void
369 {
370 if (!$this->isCRUDContext()) {
371 $this->showUnitsOfCategory();
372 return;
373 }
374
375 $category = $this->getCategoryById($this->request->int('category_id'));
376
377 $this->initUnitForm($category);
378 $this->unit_form->setValuesByArray([
379 'factor' => 1,
380 'unit_title' => $this->lng->txt('unit_placeholder')
381 ]);
382
383 $this->tpl->setContent($this->unit_form->getHtml());
384 }
385
386 protected function initUnitForm(
387 ?assFormulaQuestionUnitCategory $category = null,
388 ?assFormulaQuestionUnit $unit = null
390 if ($this->unit_form instanceof ilPropertyFormGUI) {
391 return $this->unit_form;
392 }
393
394 $unit_in_use = false;
395 if ($unit instanceof assFormulaQuestionUnit && $this->repository->isUnitInUse($unit->getId())) {
396 $unit_in_use = true;
397 }
398
399 $this->unit_form = new ilPropertyFormGUI();
400
401 $title = new ilTextInputGUI($this->lng->txt('unit'), 'unit_title');
402 $title->setDisabled($unit_in_use);
403 $title->setRequired(true);
404 $this->unit_form->addItem($title);
405
406 $baseunit = new ilSelectInputGUI($this->lng->txt('baseunit'), 'base_unit');
407 $items = $this->repository->getCategorizedUnits();
408 $options = [];
409 $category_name = '';
410 $new_category = false;
411 foreach ($items as $item) {
412 if (
413 $unit instanceof assFormulaQuestionUnit &&
414 $unit->getId() === $item->getId()
415 ) {
416 continue;
417 }
418
419 if ($item instanceof assFormulaQuestionUnitCategory) {
420 if ($category_name !== $item->getDisplayString()) {
421 $new_category = true;
422 $category_name = $item->getDisplayString();
423 }
424 continue;
425 }
426
427 $options[$item->getId()] = $item->getDisplayString() . ($new_category ? ' (' . $category_name . ')' : '');
428 $new_category = false;
429 }
430 $baseunit->setDisabled($unit_in_use);
431 $baseunit->setOptions([0 => $this->lng->txt('no_selection')] + $options);
432 $this->unit_form->addItem($baseunit);
433
434 $factor = new ilNumberInputGUI($this->lng->txt('factor'), 'factor');
435 $factor->setRequired(true);
436 $factor->setSize(3);
437 $factor->setMinValue(0);
438 $factor->allowDecimals(true);
439 $factor->setDisabled($unit_in_use);
440 $this->unit_form->addItem($factor);
441
442 $this->ctrl->setParameterByClass(get_class($this), 'category_id', $this->request->int('category_id'));
443 if (null === $unit) {
444 $this->unit_form->setTitle($this->lng->txt('new_unit'));
445 $this->unit_form->setFormAction($this->ctrl->getFormAction($this, 'addUnit'));
446 $this->unit_form->addCommandButton('addUnit', $this->lng->txt('save'));
447 } else {
448 $this->ctrl->setParameter($this, 'unit_id', $unit->getId());
449 if ($unit_in_use) {
450 $this->unit_form->setFormAction($this->ctrl->getFormAction($this, 'showUnitsOfCategory'));
451 } else {
452 $this->unit_form->addCommandButton('saveUnit', $this->lng->txt('save'));
453 $this->unit_form->setFormAction($this->ctrl->getFormAction($this, 'saveUnit'));
454 }
455 $this->unit_form->setTitle(sprintf(
456 $this->lng->txt('un_sel_cat_sel_unit'),
457 $category->getDisplayString(),
458 $unit->getDisplayString()
459 ));
460 }
461 $this->ctrl->clearParameterByClass(get_class($this), 'category_id');
462
463 $this->unit_form->addCommandButton('showUnitsOfCategory', $this->lng->txt('cancel'));
464 return $this->unit_form;
465 }
466
467 protected function showUnitsOfCategory(): void
468 {
469 global $DIC;
470
471 $ilToolbar = $DIC->toolbar();
472
473 $category = $this->getCategoryById($this->request->int('category_id'), false);
474
475 $this->tpl->addJavaScript("assets/js/Basic.js");
476 $this->tpl->addJavaScript("assets/js/Form.js");
477 $this->lng->loadLanguageModule('form');
478
479 $ilToolbar->addButton(
480 $this->lng->txt('back'),
481 $this->ctrl->getLinkTarget($this, $this->getUnitCategoryOverviewCommand())
482 );
483 if ($this->isCRUDContext() && $this->access->checkAccess('write', '', $this->request->getRefId())) {
484 $this->ctrl->setParameterByClass(get_class($this), 'category_id', $category->getId());
485 $ilToolbar->addButton(
486 $this->lng->txt('un_add_unit'),
487 $this->ctrl->getLinkTarget($this, 'showUnitCreationForm')
488 );
489 $this->ctrl->clearParameterByClass(get_class($this), 'category_id');
490 }
491 $table = new ilUnitTableGUI($this, 'showUnitsOfCategory', $category);
492 $units = $this->repository->loadUnitsForCategory($category->getId());
493 $data = [];
494 foreach ($units as $unit) {
496 $data[] = [
497 'unit_id' => $unit->getId(),
498 'unit' => $unit->getSanitizedUnit(),
499 'baseunit' => $unit->getSanitizedBaseunitTitle(),
500 'baseunit_id' => $unit->getBaseUnit(),
501 'factor' => $unit->getFactor(),
502 'sequence' => $unit->getSequence(),
503 ];
504 }
505 $table->setData($data);
506
507 $this->tpl->setContent($table->getHTML());
508 }
509
510 protected function showGlobalUnitCategories(): void
511 {
512 $categories = array_filter(
513 $this->repository->getAllUnitCategories(),
514 static function (assFormulaQuestionUnitCategory $category): bool {
515 return !$category->getQuestionFi() ? true : false;
516 }
517 );
518 $data = [];
519 foreach ($categories as $category) {
521 $data[] = [
522 'category_id' => $category->getId(),
523 'category' => $category->getDisplayString()
524 ];
525 }
526
527 $this->showUnitCategories($data);
528 }
529
530 protected function confirmDeleteCategory(): void
531 {
532 if (!$this->request->isset('category_id')) {
533 $this->{$this->getUnitCategoryOverviewCommand()}();
534 return;
535 }
536
537 $this->confirmDeleteCategories([$this->request->int('category_id')]);
538 }
539
545 protected function confirmDeleteCategories(?array $category_ids = null): void
546 {
547 if (!$this->isCRUDContext()) {
548 $this->{$this->getDefaultCommand()}();
549 return;
550 }
551
552 $category_ids = $category_ids ?? $this->request->getUnitCategoryIds();
553 if (count($category_ids) === 0) {
554 $this->{$this->getUnitCategoryOverviewCommand()}();
555 return;
556 }
557
558 $confirmation = new ilConfirmationGUI();
559 $confirmation->setFormAction($this->ctrl->getFormAction($this, 'deleteCategories'));
560 $confirmation->setConfirm($this->lng->txt('confirm'), 'deleteCategories');
561 $confirmation->setCancel($this->lng->txt('cancel'), $this->getUnitCategoryOverviewCommand());
562
563 $errors = [];
564 $num_to_confirm = 0;
565 foreach ($category_ids as $category_id) {
566 try {
567 $category = $this->repository->getUnitCategoryById($category_id);
568 } catch (ilException $e) {
569 continue;
570 }
571
572 if (!$this->repository->isCRUDAllowed($category_id)) {
573 $errors[] = $category->getDisplayString() . ' - ' . $this->lng->txt('change_adm_categories_not_allowed');
574 continue;
575 }
576
577 $possible_error = $this->repository->checkDeleteCategory($category_id);
578 if (is_string($possible_error) && $possible_error !== '') {
579 $errors[] = $category->getDisplayString() . ' - ' . $possible_error;
580 continue;
581 }
582
583 $confirmation->addItem('category_ids[]', (string) $category->getId(), $category->getDisplayString());
584 ++$num_to_confirm;
585 }
586
587 if ($errors) {
588 $num_errors = count($errors);
589
590 $error_message = array_map(static function (string $message): string {
591 return '<li>' . $message . '</li>';
592 }, $errors);
593 if ($num_errors === 1) {
594 $this->tpl->setOnScreenMessage(
595 'failure',
596 $this->lng->txt('un_cat_deletion_errors_f_s') . '<ul>' . implode('', $error_message) . '<ul>'
597 );
598 } else {
599 $this->tpl->setOnScreenMessage(
600 'failure',
601 $this->lng->txt('un_cat_deletion_errors_f') . '<ul>' . implode('', $error_message) . '<ul>'
602 );
603 }
604 }
605
606 if ($num_to_confirm) {
607 if ($num_to_confirm === 1) {
608 $confirmation->setHeaderText($this->lng->txt('un_sure_delete_categories_s'));
609 } else {
610 $confirmation->setHeaderText($this->lng->txt('un_sure_delete_categories'));
611 }
612
613 $this->tpl->setContent($confirmation->getHTML());
614 } else {
615 $this->{$this->getUnitCategoryOverviewCommand()}();
616 }
617 }
618
619 protected function deleteCategories(): void
620 {
621 if (!$this->isCRUDContext()) {
622 $this->{$this->getDefaultCommand()}();
623 return;
624 }
625
626 $category_ids = $this->request->getUnitCategoryIds();
627 if (count($category_ids) === 0) {
628 $this->{$this->getUnitCategoryOverviewCommand()}();
629 return;
630 }
631
632 $errors = [];
633 $num_deleted = 0;
634 foreach ($category_ids as $category_id) {
635 try {
636 $category = $this->repository->getUnitCategoryById($category_id);
637 } catch (ilException $e) {
638 continue;
639 }
640
641 if (!$this->repository->isCRUDAllowed($category_id)) {
642 $errors[] = $category->getDisplayString() . ' - ' . $this->lng->txt('change_adm_categories_not_allowed');
643 continue;
644 }
645
646 $possible_error = $this->repository->deleteCategory($category_id);
647 if (is_string($possible_error) && $possible_error !== '') {
648 $errors[] = $category->getDisplayString() . ' - ' . $possible_error;
649 continue;
650 }
651
652 ++$num_deleted;
653 }
654
655 if ($errors) {
656 $num_errors = count($errors);
657
658 $error_message = array_map(static function (string $message): string {
659 return '<li>' . $message . '</li>';
660 }, $errors);
661 if ($num_errors === 1) {
662 $this->tpl->setOnScreenMessage(
663 'failure',
664 $this->lng->txt('un_cat_deletion_errors_p_s') . '<ul>' . implode('', $error_message) . '<ul>'
665 );
666 } else {
667 $this->tpl->setOnScreenMessage(
668 'failure',
669 $this->lng->txt('un_cat_deletion_errors_p') . '<ul>' . implode('', $error_message) . '<ul>'
670 );
671 }
672 }
673
674 if ($num_deleted) {
675 if ($num_deleted === 1) {
676 $this->tpl->setOnScreenMessage('success', $this->lng->txt('un_deleted_categories_s'));
677 } else {
678 $this->tpl->setOnScreenMessage('success', $this->lng->txt('un_deleted_categories'));
679 }
680 }
681
682 $this->{$this->getUnitCategoryOverviewCommand()}();
683 }
684
686 {
687 if ($this->unit_cat_form instanceof ilPropertyFormGUI) {
688 return $this->unit_cat_form;
689 }
690
691 $this->unit_cat_form = new ilPropertyFormGUI();
692
693 $title = new ilTextInputGUI($this->lng->txt('title'), 'category_name');
694 $title->setRequired(true);
695 $this->unit_cat_form->addItem($title);
696
697 if (null === $cat) {
698 $this->unit_cat_form->setTitle($this->lng->txt('new_category'));
699 $this->unit_cat_form->setFormAction($this->ctrl->getFormAction($this, 'addCategory'));
700 $this->unit_cat_form->addCommandButton('addCategory', $this->lng->txt('save'));
701 } else {
702 $this->ctrl->setParameter($this, 'category_id', $cat->getId());
703 $this->unit_cat_form->addCommandButton('saveCategory', $this->lng->txt('save'));
704 $this->unit_cat_form->setFormAction($this->ctrl->getFormAction($this, 'saveCategory'));
705 $this->unit_cat_form->setTitle(sprintf($this->lng->txt('selected_category'), $cat->getDisplayString()));
706 }
707
708 $this->unit_cat_form->addCommandButton($this->getUnitCategoryOverviewCommand(), $this->lng->txt('cancel'));
709 return $this->unit_cat_form;
710 }
711
712 protected function addCategory(): void
713 {
714 if (!$this->isCRUDContext()) {
715 $this->{$this->getDefaultCommand()}();
716 return;
717 }
718
719 $this->initUnitCategoryForm();
720 if ($this->unit_cat_form->checkInput()) {
721 try {
722 $category = new assFormulaQuestionUnitCategory();
723 $category->setCategory($this->unit_cat_form->getInput('category_name'));
724 $this->repository->saveNewUnitCategory($category);
725 $this->tpl->setOnScreenMessage('success', $this->lng->txt('saved_successfully'));
726
727 $this->{$this->getUnitCategoryOverviewCommand()}();
728 return;
729 } catch (ilException $e) {
730 $this->unit_cat_form->getItemByPostVar('category_name')->setAlert($this->lng->txt($e->getMessage()));
731 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('form_input_not_valid'));
732 }
733 }
734
735 $this->unit_cat_form->setValuesByPost();
736
737 $this->tpl->setContent($this->unit_cat_form->getHtml());
738 }
739
740 protected function showUnitCategoryCreationForm(): void
741 {
742 if (!$this->isCRUDContext()) {
743 $this->{$this->getDefaultCommand()}();
744 return;
745 }
746
747 $this->initUnitCategoryForm();
748
749 $this->tpl->setContent($this->unit_cat_form->getHtml());
750 }
751
752 protected function saveCategory(): void
753 {
754 if (!$this->isCRUDContext()) {
755 $this->{$this->getDefaultCommand()}();
756 return;
757 }
758
759 $category = $this->getCategoryById($this->request->int('category_id'));
760
761 $this->initUnitCategoryForm($category);
762 if ($this->unit_cat_form->checkInput()) {
763 try {
764 $category->setCategory($this->unit_cat_form->getInput('category_name'));
765 $this->repository->saveCategory($category);
766 $this->tpl->setOnScreenMessage('success', $this->lng->txt('saved_successfully'));
767
768 $this->{$this->getUnitCategoryOverviewCommand()}();
769 return;
770 } catch (ilException $e) {
771 $this->unit_cat_form->getItemByPostVar('category_name')->setAlert($this->lng->txt($e->getMessage()));
772 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('form_input_not_valid'));
773 }
774 }
775
776 $this->unit_cat_form->setValuesByPost();
777
778 $this->tpl->setContent($this->unit_cat_form->getHtml());
779 }
780
781 protected function showUnitCategoryModificationForm(): void
782 {
783 if (!$this->isCRUDContext()) {
784 $this->{$this->getDefaultCommand()}();
785 return;
786 }
787
788 $category = $this->getCategoryById($this->request->int('category_id'));
789
790 $this->initUnitCategoryForm($category);
791 $this->unit_cat_form->setValuesByArray([
792 'category_name' => $category->getCategory()
793 ]);
794
795 $this->tpl->setContent($this->unit_cat_form->getHtml());
796 }
797}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Base class for ILIAS Exception handling.
language handling
This class represents a number property in a property form.
This class represents a property form user interface.
This class represents a selection list property in a property form.
This class represents a text property in a property form.
Class ilUnitConfigurationGUI.
showUnitCategories(array $categories)
initUnitCategoryForm(?assFormulaQuestionUnitCategory $cat=null)
getCategoryById(int $id, bool $for_CRUD=true)
initUnitForm(?assFormulaQuestionUnitCategory $category=null, ?assFormulaQuestionUnit $unit=null)
confirmDeleteUnits(?array $unit_ids=null)
ilGlobalTemplateInterface $tpl
confirmDeleteCategories(?array $category_ids=null)
__construct(protected ilUnitConfigurationRepository $repository)
Class ilUnitConfigurationRepository.
Class ilUnitTableGUI.
static getStartingPointAsUrl()
Interface ilAccessHandler This interface combines all available interfaces which can be called via gl...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
if(!file_exists('../ilias.ini.php'))
global $DIC
Definition: shib_login.php:26