ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
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 $this->lng->loadLanguageModule('qsts');
51 }
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 713 of file class.ilUnitConfigurationGUI.php.

713 : void
714 {
715 if (!$this->isCRUDContext()) {
716 $this->{$this->getDefaultCommand()}();
717 return;
718 }
719
720 $this->initUnitCategoryForm();
721 if ($this->unit_cat_form->checkInput()) {
722 try {
723 $category = new assFormulaQuestionUnitCategory();
724 $category->setCategory($this->unit_cat_form->getInput('category_name'));
725 $this->repository->saveNewUnitCategory($category);
726 $this->tpl->setOnScreenMessage('success', $this->lng->txt('saved_successfully'));
727
728 $this->{$this->getUnitCategoryOverviewCommand()}();
729 return;
730 } catch (ilException $e) {
731 $this->unit_cat_form->getItemByPostVar('category_name')->setAlert($this->lng->txt($e->getMessage()));
732 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('form_input_not_valid'));
733 }
734 }
735
736 $this->unit_cat_form->setValuesByPost();
737
738 $this->tpl->setContent($this->unit_cat_form->getHtml());
739 }
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 337 of file class.ilUnitConfigurationGUI.php.

337 : void
338 {
339 if (!$this->isCRUDContext()) {
340 $this->showUnitsOfCategory();
341 return;
342 }
343
344 $category = $this->getCategoryById($this->request->int('category_id'));
345
346 $this->initUnitForm($category);
347 if ($this->unit_form->checkInput()) {
348 $unit = new assFormulaQuestionUnit();
349 $unit->setUnit($this->unit_form->getInput('unit_title'));
350 $unit->setCategory($category->getId());
351
352 $this->repository->createNewUnit($unit);
353
354 $unit->setBaseUnit((int) $this->unit_form->getInput('base_unit'));
355 $unit->setFactor((float) $this->unit_form->getInput('factor'));
356
357 $this->repository->saveUnit($unit);
358
359 $this->tpl->setOnScreenMessage('success', $this->lng->txt('saved_successfully'));
360 $this->showUnitsOfCategory();
361 return;
362 }
363
364 $this->unit_form->setValuesByPost();
365
366 $this->tpl->setContent($this->unit_form->getHtml());
367 }
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 78 of file class.ilUnitConfigurationGUI.php.

78 : void
79 {
80 if (!$this->access->checkAccess('read', '', $this->request->getRefId())) {
81 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('permission_denied'), true);
82 $this->ctrl->redirectToURL(ilUserUtil::getStartingPointAsUrl());
83 return;
84 }
85
86 if (in_array($cmd, ['showUnitCategories', 'showUnitsOfCategory', 'showGlobalUnitCategories'], true)) {
87 return;
88 }
89
90 if ($this->access->checkAccess('write', '', $this->request->getRefId())) {
91 return;
92 }
93
94 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('permission_denied'), true);
95 $this->ctrl->redirect($this, $this->getDefaultCommand());
96 }
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 546 of file class.ilUnitConfigurationGUI.php.

546 : void
547 {
548 if (!$this->isCRUDContext()) {
549 $this->{$this->getDefaultCommand()}();
550 return;
551 }
552
553 $category_ids = $category_ids ?? $this->request->getUnitCategoryIds();
554 if (count($category_ids) === 0) {
555 $this->{$this->getUnitCategoryOverviewCommand()}();
556 return;
557 }
558
559 $confirmation = new ilConfirmationGUI();
560 $confirmation->setFormAction($this->ctrl->getFormAction($this, 'deleteCategories'));
561 $confirmation->setConfirm($this->lng->txt('confirm'), 'deleteCategories');
562 $confirmation->setCancel($this->lng->txt('cancel'), $this->getUnitCategoryOverviewCommand());
563
564 $errors = [];
565 $num_to_confirm = 0;
566 foreach ($category_ids as $category_id) {
567 try {
568 $category = $this->repository->getUnitCategoryById($category_id);
569 } catch (ilException $e) {
570 continue;
571 }
572
573 if (!$this->repository->isCRUDAllowed($category_id)) {
574 $errors[] = $category->getDisplayString() . ' - ' . $this->lng->txt('change_adm_categories_not_allowed');
575 continue;
576 }
577
578 $possible_error = $this->repository->checkDeleteCategory($category_id);
579 if (is_string($possible_error) && $possible_error !== '') {
580 $errors[] = $category->getDisplayString() . ' - ' . $possible_error;
581 continue;
582 }
583
584 $confirmation->addItem('category_ids[]', (string) $category->getId(), $category->getDisplayString());
585 ++$num_to_confirm;
586 }
587
588 if ($errors) {
589 $num_errors = count($errors);
590
591 $error_message = array_map(static function (string $message): string {
592 return '<li>' . $message . '</li>';
593 }, $errors);
594 if ($num_errors === 1) {
595 $this->tpl->setOnScreenMessage(
596 'failure',
597 $this->lng->txt('un_cat_deletion_errors_f_s') . '<ul>' . implode('', $error_message) . '<ul>'
598 );
599 } else {
600 $this->tpl->setOnScreenMessage(
601 'failure',
602 $this->lng->txt('un_cat_deletion_errors_f') . '<ul>' . implode('', $error_message) . '<ul>'
603 );
604 }
605 }
606
607 if ($num_to_confirm) {
608 if ($num_to_confirm === 1) {
609 $confirmation->setHeaderText($this->lng->txt('un_sure_delete_categories_s'));
610 } else {
611 $confirmation->setHeaderText($this->lng->txt('un_sure_delete_categories'));
612 }
613
614 $this->tpl->setContent($confirmation->getHTML());
615 } else {
616 $this->{$this->getUnitCategoryOverviewCommand()}();
617 }
618 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

References Vendor\Package\$e, $message, 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 531 of file class.ilUnitConfigurationGUI.php.

531 : void
532 {
533 if (!$this->request->isset('category_id')) {
534 $this->{$this->getUnitCategoryOverviewCommand()}();
535 return;
536 }
537
538 $this->confirmDeleteCategories([$this->request->int('category_id')]);
539 }
confirmDeleteCategories(?array $category_ids=null)

◆ confirmDeleteUnit()

ilUnitConfigurationGUI::confirmDeleteUnit ( )
protected

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

110 : void
111 {
112 if (!$this->request->isset('unit_id')) {
113 $this->showUnitsOfCategory();
114 return;
115 }
116
117 $this->confirmDeleteUnits([$this->request->int('unit_id')]);
118 }
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 125 of file class.ilUnitConfigurationGUI.php.

125 : void
126 {
127 if (!$this->isCRUDContext()) {
128 $this->showUnitsOfCategory();
129 return;
130 }
131
132 $unit_ids = $unit_ids ?? $this->request->getUnitIds();
133 if (count($unit_ids) === 0) {
134 $this->showUnitsOfCategory();
135 return;
136 }
137
138 $this->ctrl->setParameter($this, 'category_id', $this->request->int('category_id'));
139 $confirmation = new ilConfirmationGUI();
140 $confirmation->setFormAction($this->ctrl->getFormAction($this, 'deleteUnits'));
141 $confirmation->setConfirm($this->lng->txt('confirm'), 'deleteUnits');
142 $confirmation->setCancel($this->lng->txt('cancel'), 'showUnitsOfCategory');
143
144 $errors = [];
145 $num_to_confirm = 0;
146 foreach ($unit_ids as $unit_id) {
147 try {
148 $unit = $this->repository->getUnit((int) $unit_id);
149 if (!$unit) {
150 continue;
151 }
152
153 if ($check_result = $this->repository->checkDeleteUnit($unit->getId())) {
154 $errors[] = $unit->getDisplayString() . ' - ' . $check_result;
155 continue;
156 }
157
158 $confirmation->addItem('unit_ids[]', (string) $unit->getId(), $unit->getDisplayString());
159 ++$num_to_confirm;
160 } catch (ilException $e) {
161 continue;
162 }
163 }
164
165 if ($errors) {
166 $num_errors = count($errors);
167
168 $error_message = array_map(static function (string $message): string {
169 return '<li>' . $message . '</li>';
170 }, $errors);
171 if ($num_errors === 1) {
172 $this->tpl->setOnScreenMessage(
173 'failure',
174 $this->lng->txt('un_unit_deletion_errors_f_s') . '<ul>' . implode('', $error_message) . '<ul>'
175 );
176 } else {
177 $this->tpl->setOnScreenMessage(
178 'failure',
179 $this->lng->txt('un_unit_deletion_errors_f') . '<ul>' . implode('', $error_message) . '<ul>'
180 );
181 }
182 }
183
184 if ($num_to_confirm) {
185 if ($num_to_confirm === 1) {
186 $confirmation->setHeaderText($this->lng->txt('un_sure_delete_units_s'));
187 } else {
188 $confirmation->setHeaderText($this->lng->txt('un_sure_delete_units'));
189 }
190
191 $this->tpl->setContent($confirmation->getHTML());
192 } else {
193 $this->showUnitsOfCategory();
194 }
195 }

References Vendor\Package\$e, $message, 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 620 of file class.ilUnitConfigurationGUI.php.

620 : void
621 {
622 if (!$this->isCRUDContext()) {
623 $this->{$this->getDefaultCommand()}();
624 return;
625 }
626
627 $category_ids = $this->request->getUnitCategoryIds();
628 if (count($category_ids) === 0) {
629 $this->{$this->getUnitCategoryOverviewCommand()}();
630 return;
631 }
632
633 $errors = [];
634 $num_deleted = 0;
635 foreach ($category_ids as $category_id) {
636 try {
637 $category = $this->repository->getUnitCategoryById($category_id);
638 } catch (ilException $e) {
639 continue;
640 }
641
642 if (!$this->repository->isCRUDAllowed($category_id)) {
643 $errors[] = $category->getDisplayString() . ' - ' . $this->lng->txt('change_adm_categories_not_allowed');
644 continue;
645 }
646
647 $possible_error = $this->repository->deleteCategory($category_id);
648 if (is_string($possible_error) && $possible_error !== '') {
649 $errors[] = $category->getDisplayString() . ' - ' . $possible_error;
650 continue;
651 }
652
653 ++$num_deleted;
654 }
655
656 if ($errors) {
657 $num_errors = count($errors);
658
659 $error_message = array_map(static function (string $message): string {
660 return '<li>' . $message . '</li>';
661 }, $errors);
662 if ($num_errors === 1) {
663 $this->tpl->setOnScreenMessage(
664 'failure',
665 $this->lng->txt('un_cat_deletion_errors_p_s') . '<ul>' . implode('', $error_message) . '<ul>'
666 );
667 } else {
668 $this->tpl->setOnScreenMessage(
669 'failure',
670 $this->lng->txt('un_cat_deletion_errors_p') . '<ul>' . implode('', $error_message) . '<ul>'
671 );
672 }
673 }
674
675 if ($num_deleted) {
676 if ($num_deleted === 1) {
677 $this->tpl->setOnScreenMessage('success', $this->lng->txt('un_deleted_categories_s'));
678 } else {
679 $this->tpl->setOnScreenMessage('success', $this->lng->txt('un_deleted_categories'));
680 }
681 }
682
683 $this->{$this->getUnitCategoryOverviewCommand()}();
684 }

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

+ Here is the call graph for this function:

◆ deleteUnits()

ilUnitConfigurationGUI::deleteUnits ( )

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

197 : void
198 {
199 if (!$this->isCRUDContext()) {
200 $this->showUnitsOfCategory();
201 return;
202 }
203
204 $unit_ids = $this->request->getUnitIds();
205 if (count($unit_ids) === 0) {
206 $this->showUnitsOfCategory();
207 return;
208 }
209
210 $errors = [];
211 $num_deleted = 0;
212 foreach ($unit_ids as $unit_id) {
213 try {
214 $unit = $this->repository->getUnit($unit_id);
215 if (!$unit) {
216 continue;
217 }
218
219 $check_result = $this->repository->deleteUnit($unit->getId());
220 if (!is_null($check_result)) {
221 $errors[] = $unit->getDisplayString() . ' - ' . $check_result;
222 continue;
223 }
224
225 ++$num_deleted;
226 } catch (ilException $e) {
227 continue;
228 }
229 }
230
231 if ($errors) {
232 $num_errors = count($errors);
233
234 $error_message = array_map(static function (string $message): string {
235 return '<li>' . $message . '</li>';
236 }, $errors);
237 if ($num_errors === 1) {
238 $this->tpl->setOnScreenMessage(
239 'failure',
240 $this->lng->txt('un_unit_deletion_errors_p_s') . '<ul>' . implode('', $error_message) . '<ul>'
241 );
242 } else {
243 $this->tpl->setOnScreenMessage(
244 'failure',
245 $this->lng->txt('un_unit_deletion_errors_p') . '<ul>' . implode('', $error_message) . '<ul>'
246 );
247 }
248 }
249
250 if ($num_deleted) {
251 if ($num_deleted === 1) {
252 $this->tpl->setOnScreenMessage('success', $this->lng->txt('un_deleted_units_s'));
253 } else {
254 $this->tpl->setOnScreenMessage('success', $this->lng->txt('un_deleted_units'));
255 }
256 }
257
258 $this->showUnitsOfCategory();
259 }

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

+ Here is the call graph for this function:

◆ executeCommand()

ilUnitConfigurationGUI::executeCommand ( )

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

98 : void
99 {
100 $cmd = $this->ctrl->getCmd($this->getDefaultCommand());
101 $this->checkPermissions($cmd);
102 match ($cmd) {
103 'confirmImportGlobalCategories' => $this->$cmd($this->request->getUnitCategoryIds()),
104 default => $this->$cmd(),
105 };
106
107 $this->handleSubtabs();
108 }

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 63 of file class.ilUnitConfigurationGUI.php.

64 {
65 $category = $this->repository->getUnitCategoryById($id);
66 if ($for_CRUD && $category->getQuestionFi() !== $this->repository->getConsumerId()) {
67 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('change_adm_categories_not_allowed'), true);
68 $this->ctrl->redirect($this, $this->getDefaultCommand());
69 }
70
71 return $category;
72 }
$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 74 of file class.ilUnitConfigurationGUI.php.

74 : void
75 {
76 }

Referenced by executeCommand().

+ Here is the caller graph for this function:

◆ initUnitCategoryForm()

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

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

687 {
688 if ($this->unit_cat_form instanceof ilPropertyFormGUI) {
690 }
691
692 $this->unit_cat_form = new ilPropertyFormGUI();
693
694 $title = new ilTextInputGUI($this->lng->txt('title'), 'category_name');
695 $title->setRequired(true);
696 $this->unit_cat_form->addItem($title);
697
698 if (null === $cat) {
699 $this->unit_cat_form->setTitle($this->lng->txt('new_category'));
700 $this->unit_cat_form->setFormAction($this->ctrl->getFormAction($this, 'addCategory'));
701 $this->unit_cat_form->addCommandButton('addCategory', $this->lng->txt('save'));
702 } else {
703 $this->ctrl->setParameter($this, 'category_id', $cat->getId());
704 $this->unit_cat_form->addCommandButton('saveCategory', $this->lng->txt('save'));
705 $this->unit_cat_form->setFormAction($this->ctrl->getFormAction($this, 'saveCategory'));
706 $this->unit_cat_form->setTitle(sprintf($this->lng->txt('selected_category'), $cat->getDisplayString()));
707 }
708
709 $this->unit_cat_form->addCommandButton($this->getUnitCategoryOverviewCommand(), $this->lng->txt('cancel'));
711 }
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 387 of file class.ilUnitConfigurationGUI.php.

391 if ($this->unit_form instanceof ilPropertyFormGUI) {
392 return $this->unit_form;
393 }
394
395 $unit_in_use = false;
396 if ($unit instanceof assFormulaQuestionUnit && $this->repository->isUnitInUse($unit->getId())) {
397 $unit_in_use = true;
398 }
399
400 $this->unit_form = new ilPropertyFormGUI();
401
402 $title = new ilTextInputGUI($this->lng->txt('unit'), 'unit_title');
403 $title->setDisabled($unit_in_use);
404 $title->setRequired(true);
405 $this->unit_form->addItem($title);
406
407 $baseunit = new ilSelectInputGUI($this->lng->txt('baseunit'), 'base_unit');
408 $items = $this->repository->getCategorizedUnits();
409 $options = [];
410 $category_name = '';
411 $new_category = false;
412 foreach ($items as $item) {
413 if (
414 $unit instanceof assFormulaQuestionUnit &&
415 $unit->getId() === $item->getId()
416 ) {
417 continue;
418 }
419
420 if ($item instanceof assFormulaQuestionUnitCategory) {
421 if ($category_name !== $item->getDisplayString()) {
422 $new_category = true;
423 $category_name = $item->getDisplayString();
424 }
425 continue;
426 }
427
428 $options[$item->getId()] = $item->getDisplayString() . ($new_category ? ' (' . $category_name . ')' : '');
429 $new_category = false;
430 }
431 $baseunit->setDisabled($unit_in_use);
432 $baseunit->setOptions([0 => $this->lng->txt('no_selection')] + $options);
433 $this->unit_form->addItem($baseunit);
434
435 $factor = new ilNumberInputGUI($this->lng->txt('factor'), 'factor');
436 $factor->setRequired(true);
437 $factor->setSize(3);
438 $factor->setMinValue(0);
439 $factor->allowDecimals(true);
440 $factor->setDisabled($unit_in_use);
441 $this->unit_form->addItem($factor);
442
443 $this->ctrl->setParameterByClass(get_class($this), 'category_id', $this->request->int('category_id'));
444 if (null === $unit) {
445 $this->unit_form->setTitle($this->lng->txt('new_unit'));
446 $this->unit_form->setFormAction($this->ctrl->getFormAction($this, 'addUnit'));
447 $this->unit_form->addCommandButton('addUnit', $this->lng->txt('save'));
448 } else {
449 $this->ctrl->setParameter($this, 'unit_id', $unit->getId());
450 if ($unit_in_use) {
451 $this->unit_form->setFormAction($this->ctrl->getFormAction($this, 'showUnitsOfCategory'));
452 } else {
453 $this->unit_form->addCommandButton('saveUnit', $this->lng->txt('save'));
454 $this->unit_form->setFormAction($this->ctrl->getFormAction($this, 'saveUnit'));
455 }
456 $this->unit_form->setTitle(sprintf(
457 $this->lng->txt('un_sel_cat_sel_unit'),
458 $category->getDisplayString(),
459 $unit->getDisplayString()
460 ));
461 }
462 $this->ctrl->clearParameterByClass(get_class($this), 'category_id');
463
464 $this->unit_form->addCommandButton('showUnitsOfCategory', $this->lng->txt('cancel'));
465 return $this->unit_form;
466 }
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 753 of file class.ilUnitConfigurationGUI.php.

753 : void
754 {
755 if (!$this->isCRUDContext()) {
756 $this->{$this->getDefaultCommand()}();
757 return;
758 }
759
760 $category = $this->getCategoryById($this->request->int('category_id'));
761
762 $this->initUnitCategoryForm($category);
763 if ($this->unit_cat_form->checkInput()) {
764 try {
765 $category->setCategory($this->unit_cat_form->getInput('category_name'));
766 $this->repository->saveCategory($category);
767 $this->tpl->setOnScreenMessage('success', $this->lng->txt('saved_successfully'));
768
769 $this->{$this->getUnitCategoryOverviewCommand()}();
770 return;
771 } catch (ilException $e) {
772 $this->unit_cat_form->getItemByPostVar('category_name')->setAlert($this->lng->txt($e->getMessage()));
773 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('form_input_not_valid'));
774 }
775 }
776
777 $this->unit_cat_form->setValuesByPost();
778
779 $this->tpl->setContent($this->unit_cat_form->getHtml());
780 }

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 261 of file class.ilUnitConfigurationGUI.php.

261 : void
262 {
263 if (!$this->isCRUDContext()) {
264 $this->showUnitsOfCategory();
265 return;
266 }
267
268 if (!$this->request->isset('sequence') || !is_array($this->request->raw('sequence'))) {
269 $this->showUnitsOfCategory();
270 return;
271 }
272
273 $sequences = $this->request->raw('sequence');
274 foreach ($sequences as $id => $sequence) {
275 $sorting_value = str_replace(',', '.', $sequence);
276 $sorting_value = (int) $sorting_value * 100;
277 $this->repository->saveUnitOrder((int) $id, $sorting_value);
278 }
279
280 $this->tpl->setOnScreenMessage('success', $this->lng->txt('saved_successfully'));
281 $this->showUnitsOfCategory();
282 }

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 284 of file class.ilUnitConfigurationGUI.php.

284 : void
285 {
286 if (!$this->isCRUDContext()) {
287 $this->showUnitsOfCategory();
288 return;
289 }
290
291 $category = $this->getCategoryById($this->request->int('category_id'));
292 $unit = $this->repository->getUnit($this->request->int('unit_id'));
293
294 if ($this->repository->isUnitInUse($unit->getId())) {
296 return;
297 }
298
299 $this->initUnitForm($category, $unit);
300 if ($this->unit_form->checkInput()) {
301 $unit->setUnit($this->unit_form->getInput('unit_title'));
302 $unit->setFactor((float) $this->unit_form->getInput('factor'));
303 $unit->setBaseUnit((int) $this->unit_form->getInput('base_unit') !== $unit->getId() ? (int) $this->unit_form->getInput('base_unit') : 0);
304 $unit->setCategory($category->getId());
305 $this->repository->saveUnit($unit);
306
307 $this->tpl->setOnScreenMessage('success', $this->lng->txt('saved_successfully'));
308 $this->showUnitsOfCategory();
309 return;
310 }
311
312 $this->unit_form->setValuesByPost();
313
314 $this->tpl->setContent($this->unit_form->getHtml());
315 }

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 741 of file class.ilUnitConfigurationGUI.php.

741 : void
742 {
743 if (!$this->isCRUDContext()) {
744 $this->{$this->getDefaultCommand()}();
745 return;
746 }
747
748 $this->initUnitCategoryForm();
749
750 $this->tpl->setContent($this->unit_cat_form->getHtml());
751 }

◆ showUnitCategoryModificationForm()

ilUnitConfigurationGUI::showUnitCategoryModificationForm ( )
protected

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

782 : void
783 {
784 if (!$this->isCRUDContext()) {
785 $this->{$this->getDefaultCommand()}();
786 return;
787 }
788
789 $category = $this->getCategoryById($this->request->int('category_id'));
790
791 $this->initUnitCategoryForm($category);
792 $this->unit_cat_form->setValuesByArray([
793 'category_name' => $category->getCategory()
794 ]);
795
796 $this->tpl->setContent($this->unit_cat_form->getHtml());
797 }

◆ showUnitCreationForm()

ilUnitConfigurationGUI::showUnitCreationForm ( )
protected

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

369 : void
370 {
371 if (!$this->isCRUDContext()) {
372 $this->showUnitsOfCategory();
373 return;
374 }
375
376 $category = $this->getCategoryById($this->request->int('category_id'));
377
378 $this->initUnitForm($category);
379 $this->unit_form->setValuesByArray([
380 'factor' => 1,
381 'unit_title' => $this->lng->txt('unit_placeholder')
382 ]);
383
384 $this->tpl->setContent($this->unit_form->getHtml());
385 }

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

+ Here is the call graph for this function:

◆ showUnitModificationForm()

ilUnitConfigurationGUI::showUnitModificationForm ( )
protected

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

317 : void
318 {
319 if (!$this->isCRUDContext()) {
320 $this->showUnitsOfCategory();
321 return;
322 }
323
324 $category = $this->getCategoryById($this->request->int('category_id'));
325 $unit = $this->repository->getUnit($this->request->int('unit_id'));
326
327 $this->initUnitForm($category, $unit);
328 $this->unit_form->setValuesByArray([
329 'factor' => $unit->getFactor(),
330 'unit_title' => $unit->getUnit(),
331 'base_unit' => $unit->getBaseUnit() !== $unit->getId() ? $unit->getBaseUnit() : 0
332 ]);
333
334 $this->tpl->setContent($this->unit_form->getHtml());
335 }

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: