ILIAS  trunk Revision v12.0_alpha-1540-g00f839d5fa1
ilUnitConfigurationGUI Class Reference

Class ilUnitConfigurationGUI. More...

+ Inheritance diagram for ilUnitConfigurationGUI:
+ Collaboration diagram for ilUnitConfigurationGUI:

Public Member Functions

 __construct (protected ilUnitConfigurationRepository $repository)
 
 getUnitCategoryOverviewCommand ()
 
 isCRUDContext ()
 
 getUniqueId ()
 
 executeCommand ()
 
 deleteUnits ()
 

Protected Member Functions

 getDefaultCommand ()
 
 showUnitCategories (array $categories)
 
 getCategoryById (int $id, bool $for_CRUD=true)
 
 handleSubtabs ()
 
 checkPermissions (string $cmd)
 
 confirmDeleteUnit ()
 
 confirmDeleteUnits (?array $unit_ids=null)
 
 saveOrder ()
 
 saveUnit ()
 
 showUnitModificationForm ()
 
 addUnit ()
 
 showUnitCreationForm ()
 
 initUnitForm (?assFormulaQuestionUnitCategory $category=null, ?assFormulaQuestionUnit $unit=null)
 
 confirmDeleteCategory ()
 
 confirmDeleteCategories (?array $category_ids=null)
 
 deleteCategories ()
 
 initUnitCategoryForm (?assFormulaQuestionUnitCategory $cat=null)
 
 addCategory ()
 
 showUnitCategoryCreationForm ()
 
 saveCategory ()
 
 showUnitCategoryModificationForm ()
 

Protected Attributes

RequestDataCollector $request
 
ilPropertyFormGUI $unit_cat_form = null
 
ilPropertyFormGUI $unit_form = null
 
ilGlobalTemplateInterface $tpl
 
ilLanguage $lng
 
ilCtrlInterface $ctrl
 
ilAccessHandler $access
 

Detailed Description

Class ilUnitConfigurationGUI.

Definition at line 27 of file class.ilUnitConfigurationGUI.php.

Constructor & Destructor Documentation

◆ __construct()

ilUnitConfigurationGUI::__construct ( protected ilUnitConfigurationRepository  $repository)

Definition at line 37 of file class.ilUnitConfigurationGUI.php.

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 }
global $DIC
Definition: shib_login.php:26

References $DIC, ILIAS\Repository\access(), ILIAS\Repository\ctrl(), and ILIAS\Repository\lng().

+ Here is the call graph for this function:

Member Function Documentation

◆ addCategory()

ilUnitConfigurationGUI::addCategory ( )
protected

Definition at line 712 of file class.ilUnitConfigurationGUI.php.

712 : 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 }
Base class for ILIAS Exception handling.
initUnitCategoryForm(?assFormulaQuestionUnitCategory $cat=null)

References Vendor\Package\$e, ILIAS\Repository\lng(), and ILIAS\UI\examples\Deck\repository().

+ Here is the call graph for this function:

◆ addUnit()

ilUnitConfigurationGUI::addUnit ( )
protected

Definition at line 336 of file class.ilUnitConfigurationGUI.php.

336 : 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 }
getCategoryById(int $id, bool $for_CRUD=true)
initUnitForm(?assFormulaQuestionUnitCategory $category=null, ?assFormulaQuestionUnit $unit=null)

References getCategoryById(), initUnitForm(), isCRUDContext(), ILIAS\Repository\lng(), and ILIAS\UI\examples\Deck\repository().

+ Here is the call graph for this function:

◆ checkPermissions()

ilUnitConfigurationGUI::checkPermissions ( string  $cmd)
protected

Definition at line 77 of file class.ilUnitConfigurationGUI.php.

77 : 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 }
static getStartingPointAsUrl()

References ILIAS\Repository\access(), ILIAS\Repository\ctrl(), getDefaultCommand(), ilUserUtil\getStartingPointAsUrl(), and ILIAS\Repository\lng().

Referenced by executeCommand().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ confirmDeleteCategories()

ilUnitConfigurationGUI::confirmDeleteCategories ( ?array  $category_ids = null)
protected
Parameters
int[] | null$category_ids
Returns
void
Exceptions
ilCtrlException

Definition at line 545 of file class.ilUnitConfigurationGUI.php.

545 : 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 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

References Vendor\Package\$e, ILIAS\Repository\ctrl(), ILIAS\Repository\lng(), and ILIAS\UI\examples\Deck\repository().

+ Here is the call graph for this function:

◆ confirmDeleteCategory()

ilUnitConfigurationGUI::confirmDeleteCategory ( )
protected

Definition at line 530 of file class.ilUnitConfigurationGUI.php.

530 : 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 }
confirmDeleteCategories(?array $category_ids=null)

◆ confirmDeleteUnit()

ilUnitConfigurationGUI::confirmDeleteUnit ( )
protected

Definition at line 109 of file class.ilUnitConfigurationGUI.php.

109 : 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 }
confirmDeleteUnits(?array $unit_ids=null)

References confirmDeleteUnits().

+ Here is the call graph for this function:

◆ confirmDeleteUnits()

ilUnitConfigurationGUI::confirmDeleteUnits ( ?array  $unit_ids = null)
protected
Parameters
int[] | null$unit_ids
Returns
void
Exceptions
ilCtrlException

Definition at line 124 of file class.ilUnitConfigurationGUI.php.

124 : 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 }

References Vendor\Package\$e, ILIAS\Repository\ctrl(), isCRUDContext(), ILIAS\Repository\lng(), and ILIAS\UI\examples\Deck\repository().

Referenced by confirmDeleteUnit().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deleteCategories()

ilUnitConfigurationGUI::deleteCategories ( )
protected

Definition at line 619 of file class.ilUnitConfigurationGUI.php.

619 : 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 }

References Vendor\Package\$e, ILIAS\Repository\lng(), and ILIAS\UI\examples\Deck\repository().

+ Here is the call graph for this function:

◆ deleteUnits()

ilUnitConfigurationGUI::deleteUnits ( )

Definition at line 196 of file class.ilUnitConfigurationGUI.php.

196 : 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 }

References Vendor\Package\$e, isCRUDContext(), ILIAS\Repository\lng(), and ILIAS\UI\examples\Deck\repository().

+ Here is the call graph for this function:

◆ executeCommand()

ilUnitConfigurationGUI::executeCommand ( )

Definition at line 97 of file class.ilUnitConfigurationGUI.php.

97 : 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 }

References checkPermissions(), ILIAS\Repository\ctrl(), getDefaultCommand(), and handleSubtabs().

+ Here is the call graph for this function:

◆ getCategoryById()

ilUnitConfigurationGUI::getCategoryById ( int  $id,
bool  $for_CRUD = true 
)
protected

Definition at line 62 of file class.ilUnitConfigurationGUI.php.

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 }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23

References ILIAS\Repository\ctrl(), getDefaultCommand(), ILIAS\Repository\lng(), and ILIAS\UI\examples\Deck\repository().

Referenced by addUnit(), saveUnit(), showUnitCreationForm(), and showUnitModificationForm().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getDefaultCommand()

ilUnitConfigurationGUI::getDefaultCommand ( )
abstractprotected

Reimplemented in ilGlobalUnitConfigurationGUI, and ilLocalUnitConfigurationGUI.

Referenced by checkPermissions(), executeCommand(), and getCategoryById().

+ Here is the caller graph for this function:

◆ getUniqueId()

ilUnitConfigurationGUI::getUniqueId ( )
abstract

◆ getUnitCategoryOverviewCommand()

ilUnitConfigurationGUI::getUnitCategoryOverviewCommand ( )
abstract

◆ handleSubtabs()

ilUnitConfigurationGUI::handleSubtabs ( )
protected

Reimplemented in ilLocalUnitConfigurationGUI.

Definition at line 73 of file class.ilUnitConfigurationGUI.php.

73 : void
74 {
75 }

Referenced by executeCommand().

+ Here is the caller graph for this function:

◆ initUnitCategoryForm()

ilUnitConfigurationGUI::initUnitCategoryForm ( ?assFormulaQuestionUnitCategory  $cat = null)
protected

Definition at line 685 of file class.ilUnitConfigurationGUI.php.

686 {
687 if ($this->unit_cat_form instanceof ilPropertyFormGUI) {
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'));
710 }
This class represents a property form user interface.
This class represents a text property in a property form.

References ILIAS\Repository\ctrl(), and ILIAS\Repository\lng().

+ Here is the call graph for this function:

◆ initUnitForm()

ilUnitConfigurationGUI::initUnitForm ( ?assFormulaQuestionUnitCategory  $category = null,
?assFormulaQuestionUnit  $unit = null 
)
protected

Definition at line 386 of file class.ilUnitConfigurationGUI.php.

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 }
This class represents a number property in a property form.
This class represents a selection list property in a property form.

References $unit_form.

Referenced by addUnit(), saveUnit(), showUnitCreationForm(), and showUnitModificationForm().

+ Here is the caller graph for this function:

◆ isCRUDContext()

ilUnitConfigurationGUI::isCRUDContext ( )
abstract

◆ saveCategory()

ilUnitConfigurationGUI::saveCategory ( )
protected

Definition at line 752 of file class.ilUnitConfigurationGUI.php.

752 : 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 }

References Vendor\Package\$e, ILIAS\Repository\lng(), and ILIAS\UI\examples\Deck\repository().

+ Here is the call graph for this function:

◆ saveOrder()

ilUnitConfigurationGUI::saveOrder ( )
protected

Definition at line 260 of file class.ilUnitConfigurationGUI.php.

260 : 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 }

References $id, ILIAS\Repository\int(), isCRUDContext(), ILIAS\Repository\lng(), and ILIAS\UI\examples\Deck\repository().

+ Here is the call graph for this function:

◆ saveUnit()

ilUnitConfigurationGUI::saveUnit ( )
protected

Definition at line 283 of file class.ilUnitConfigurationGUI.php.

283 : 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 }

References getCategoryById(), initUnitForm(), isCRUDContext(), ILIAS\Repository\lng(), ILIAS\UI\examples\Deck\repository(), and showUnitModificationForm().

+ Here is the call graph for this function:

◆ showUnitCategories()

ilUnitConfigurationGUI::showUnitCategories ( array  $categories)
abstractprotected

◆ showUnitCategoryCreationForm()

ilUnitConfigurationGUI::showUnitCategoryCreationForm ( )
protected

Definition at line 740 of file class.ilUnitConfigurationGUI.php.

740 : 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 }

◆ showUnitCategoryModificationForm()

ilUnitConfigurationGUI::showUnitCategoryModificationForm ( )
protected

Definition at line 781 of file class.ilUnitConfigurationGUI.php.

781 : 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 }

◆ showUnitCreationForm()

ilUnitConfigurationGUI::showUnitCreationForm ( )
protected

Definition at line 368 of file class.ilUnitConfigurationGUI.php.

368 : 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 }

References getCategoryById(), initUnitForm(), isCRUDContext(), and ILIAS\Repository\lng().

+ Here is the call graph for this function:

◆ showUnitModificationForm()

ilUnitConfigurationGUI::showUnitModificationForm ( )
protected

Definition at line 316 of file class.ilUnitConfigurationGUI.php.

316 : 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 }

References getCategoryById(), initUnitForm(), isCRUDContext(), and ILIAS\UI\examples\Deck\repository().

Referenced by saveUnit().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $access

ilAccessHandler ilUnitConfigurationGUI::$access
protected

Definition at line 35 of file class.ilUnitConfigurationGUI.php.

◆ $ctrl

ilCtrlInterface ilUnitConfigurationGUI::$ctrl
protected

Definition at line 34 of file class.ilUnitConfigurationGUI.php.

◆ $lng

ilLanguage ilUnitConfigurationGUI::$lng
protected

Definition at line 33 of file class.ilUnitConfigurationGUI.php.

◆ $request

RequestDataCollector ilUnitConfigurationGUI::$request
protected

Definition at line 29 of file class.ilUnitConfigurationGUI.php.

◆ $tpl

ilGlobalTemplateInterface ilUnitConfigurationGUI::$tpl
protected

Definition at line 32 of file class.ilUnitConfigurationGUI.php.

◆ $unit_cat_form

ilPropertyFormGUI ilUnitConfigurationGUI::$unit_cat_form = null
protected

Definition at line 30 of file class.ilUnitConfigurationGUI.php.

◆ $unit_form

ilPropertyFormGUI ilUnitConfigurationGUI::$unit_form = null
protected

Definition at line 31 of file class.ilUnitConfigurationGUI.php.

Referenced by initUnitForm().


The documentation for this class was generated from the following file: