ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ilUnitConfigurationGUI Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

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

Public Member Functions

 __construct (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

ilUnitConfigurationRepository $repository
 
ILIAS TestQuestionPool InternalRequestService $request
 
ilPropertyFormGUI $unit_cat_form = null
 
ilPropertyFormGUI $unit_form = null
 
ilGlobalTemplateInterface $tpl
 
ilLanguage $lng
 
ilCtrlInterface $ctrl
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning Class ilUnitConfigurationGUI

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

Constructor & Destructor Documentation

◆ __construct()

ilUnitConfigurationGUI::__construct ( ilUnitConfigurationRepository  $repository)

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

References $DIC, $lng, $repository, $tpl, ILIAS\Repository\ctrl(), getDefaultCommand(), getUniqueId(), getUnitCategoryOverviewCommand(), isCRUDContext(), ILIAS\Repository\lng(), ILIAS\UI\examples\Deck\repository(), and showUnitCategories().

35  {
36  global $DIC;
37 
38  $lng = $DIC->language();
39  $ilCtrl = $DIC->ctrl();
40  $tpl = $DIC->ui()->mainTemplate();
41  $this->request = $DIC->testQuestionPool()->internal()->request();
42 
43  $this->repository = $repository;
44  $this->lng = $lng;
45  $this->ctrl = $ilCtrl;
46  $this->tpl = $tpl;
47 
48  $this->lng->loadLanguageModule('assessment');
49  }
global $DIC
Definition: feed.php:28
ilUnitConfigurationRepository $repository
ilGlobalTemplateInterface $tpl
+ Here is the call graph for this function:

Member Function Documentation

◆ addCategory()

ilUnitConfigurationGUI::addCategory ( )
protected

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

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

700  : void
701  {
702  if (!$this->isCRUDContext()) {
703  $this->{$this->getDefaultCommand()}();
704  return;
705  }
706 
707  $this->initUnitCategoryForm();
708  if ($this->unit_cat_form->checkInput()) {
709  try {
710  $category = new assFormulaQuestionUnitCategory();
711  $category->setCategory($this->unit_cat_form->getInput('category_name'));
712  $this->repository->saveNewUnitCategory($category);
713  $this->tpl->setOnScreenMessage('success', $this->lng->txt('saved_successfully'));
714 
715  $this->{$this->getUnitCategoryOverviewCommand()}();
716  return;
717  } catch (ilException $e) {
718  $this->unit_cat_form->getItemByPostVar('category_name')->setAlert($this->lng->txt($e->getMessage()));
719  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('form_input_not_valid'));
720  }
721  }
722 
723  $this->unit_cat_form->setValuesByPost();
724 
725  $this->tpl->setContent($this->unit_cat_form->getHtml());
726  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
initUnitCategoryForm(assFormulaQuestionUnitCategory $cat=null)
+ Here is the call graph for this function:

◆ addUnit()

ilUnitConfigurationGUI::addUnit ( )
protected

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

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

324  : void
325  {
326  if (!$this->isCRUDContext()) {
327  $this->showUnitsOfCategory();
328  return;
329  }
330 
331  $category = $this->getCategoryById($this->request->int('category_id'));
332 
333  $this->initUnitForm($category);
334  if ($this->unit_form->checkInput()) {
335  $unit = new assFormulaQuestionUnit();
336  $unit->setUnit($this->unit_form->getInput('unit_title'));
337  $unit->setCategory($category->getId());
338 
339  $this->repository->createNewUnit($unit);
340 
341  $unit->setBaseUnit((int) $this->unit_form->getInput('base_unit'));
342  $unit->setFactor((float) $this->unit_form->getInput('factor'));
343 
344  $this->repository->saveUnit($unit);
345 
346  $this->tpl->setOnScreenMessage('success', $this->lng->txt('saved_successfully'));
347  $this->showUnitsOfCategory();
348  return;
349  }
350 
351  $this->unit_form->setValuesByPost();
352 
353  $this->tpl->setContent($this->unit_form->getHtml());
354  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getCategoryById(int $id, bool $for_CRUD=true)
initUnitForm(assFormulaQuestionUnitCategory $category=null, assFormulaQuestionUnit $unit=null)
+ Here is the call graph for this function:

◆ checkPermissions()

ilUnitConfigurationGUI::checkPermissions ( string  $cmd)
protected

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

Referenced by executeCommand().

76  : void
77  {
78  }
+ 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 533 of file class.ilUnitConfigurationGUI.php.

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

Referenced by confirmDeleteCategory().

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

◆ confirmDeleteCategory()

ilUnitConfigurationGUI::confirmDeleteCategory ( )
protected

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

References confirmDeleteCategories(), and getUnitCategoryOverviewCommand().

518  : void
519  {
520  if (!$this->request->isset('category_id')) {
521  $this->{$this->getUnitCategoryOverviewCommand()}();
522  return;
523  }
524 
525  $this->confirmDeleteCategories([$this->request->int('category_id')]);
526  }
confirmDeleteCategories(array $category_ids=null)
+ Here is the call graph for this function:

◆ confirmDeleteUnit()

ilUnitConfigurationGUI::confirmDeleteUnit ( )
protected

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

References confirmDeleteUnits().

97  : void
98  {
99  if (!$this->request->isset('unit_id')) {
100  $this->showUnitsOfCategory();
101  return;
102  }
103 
104  $this->confirmDeleteUnits([$this->request->int('unit_id')]);
105  }
confirmDeleteUnits(array $unit_ids=null)
+ 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 112 of file class.ilUnitConfigurationGUI.php.

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

Referenced by confirmDeleteUnit().

112  : void
113  {
114  if (!$this->isCRUDContext()) {
115  $this->showUnitsOfCategory();
116  return;
117  }
118 
119  $unit_ids = $unit_ids ?? $this->request->getUnitIds();
120  if (count($unit_ids) === 0) {
121  $this->showUnitsOfCategory();
122  return;
123  }
124 
125  $this->ctrl->setParameter($this, 'category_id', $this->request->int('category_id'));
126  $confirmation = new ilConfirmationGUI();
127  $confirmation->setFormAction($this->ctrl->getFormAction($this, 'deleteUnits'));
128  $confirmation->setConfirm($this->lng->txt('confirm'), 'deleteUnits');
129  $confirmation->setCancel($this->lng->txt('cancel'), 'showUnitsOfCategory');
130 
131  $errors = [];
132  $num_to_confirm = 0;
133  foreach ($unit_ids as $unit_id) {
134  try {
135  $unit = $this->repository->getUnit((int) $unit_id);
136  if (!$unit) {
137  continue;
138  }
139 
140  if ($check_result = $this->repository->checkDeleteUnit($unit->getId())) {
141  $errors[] = $unit->getDisplayString() . ' - ' . $check_result;
142  continue;
143  }
144 
145  $confirmation->addItem('unit_ids[]', (string) $unit->getId(), $unit->getDisplayString());
146  ++$num_to_confirm;
147  } catch (ilException $e) {
148  continue;
149  }
150  }
151 
152  if ($errors) {
153  $num_errors = count($errors);
154 
155  $error_message = array_map(static function (string $message): string {
156  return '<li>' . $message . '</li>';
157  }, $errors);
158  if ($num_errors === 1) {
159  $this->tpl->setOnScreenMessage(
160  'failure',
161  $this->lng->txt('un_unit_deletion_errors_f_s') . '<ul>' . implode('', $error_message) . '<ul>'
162  );
163  } else {
164  $this->tpl->setOnScreenMessage(
165  'failure',
166  $this->lng->txt('un_unit_deletion_errors_f') . '<ul>' . implode('', $error_message) . '<ul>'
167  );
168  }
169  }
170 
171  if ($num_to_confirm) {
172  if ($num_to_confirm === 1) {
173  $confirmation->setHeaderText($this->lng->txt('un_sure_delete_units_s'));
174  } else {
175  $confirmation->setHeaderText($this->lng->txt('un_sure_delete_units'));
176  }
177 
178  $this->tpl->setContent($confirmation->getHTML());
179  } else {
180  $this->showUnitsOfCategory();
181  }
182  }
$errors
Definition: imgupload.php:65
$message
Definition: xapiexit.php:32
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deleteCategories()

ilUnitConfigurationGUI::deleteCategories ( )
protected

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

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

607  : void
608  {
609  if (!$this->isCRUDContext()) {
610  $this->{$this->getDefaultCommand()}();
611  return;
612  }
613 
614  $category_ids = $this->request->getUnitCategoryIds();
615  if (count($category_ids) === 0) {
616  $this->{$this->getUnitCategoryOverviewCommand()}();
617  return;
618  }
619 
620  $errors = [];
621  $num_deleted = 0;
622  foreach ($category_ids as $category_id) {
623  try {
624  $category = $this->repository->getUnitCategoryById($category_id);
625  } catch (ilException $e) {
626  continue;
627  }
628 
629  if (!$this->repository->isCRUDAllowed($category_id)) {
630  $errors[] = $category->getDisplayString() . ' - ' . $this->lng->txt('change_adm_categories_not_allowed');
631  continue;
632  }
633 
634  $possible_error = $this->repository->deleteCategory($category_id);
635  if (is_string($possible_error) && $possible_error !== '') {
636  $errors[] = $category->getDisplayString() . ' - ' . $possible_error;
637  continue;
638  }
639 
640  ++$num_deleted;
641  }
642 
643  if ($errors) {
644  $num_errors = count($errors);
645 
646  $error_message = array_map(static function (string $message): string {
647  return '<li>' . $message . '</li>';
648  }, $errors);
649  if ($num_errors === 1) {
650  $this->tpl->setOnScreenMessage(
651  'failure',
652  $this->lng->txt('un_cat_deletion_errors_p_s') . '<ul>' . implode('', $error_message) . '<ul>'
653  );
654  } else {
655  $this->tpl->setOnScreenMessage(
656  'failure',
657  $this->lng->txt('un_cat_deletion_errors_p') . '<ul>' . implode('', $error_message) . '<ul>'
658  );
659  }
660  }
661 
662  if ($num_deleted) {
663  if ($num_deleted === 1) {
664  $this->tpl->setOnScreenMessage('success', $this->lng->txt('un_deleted_categories_s'));
665  } else {
666  $this->tpl->setOnScreenMessage('success', $this->lng->txt('un_deleted_categories'));
667  }
668  }
669 
670  $this->{$this->getUnitCategoryOverviewCommand()}();
671  }
$errors
Definition: imgupload.php:65
$message
Definition: xapiexit.php:32
+ Here is the call graph for this function:

◆ deleteUnits()

ilUnitConfigurationGUI::deleteUnits ( )

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

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

184  : void
185  {
186  if (!$this->isCRUDContext()) {
187  $this->showUnitsOfCategory();
188  return;
189  }
190 
191  $unit_ids = $this->request->getUnitIds();
192  if (count($unit_ids) === 0) {
193  $this->showUnitsOfCategory();
194  return;
195  }
196 
197  $errors = [];
198  $num_deleted = 0;
199  foreach ($unit_ids as $unit_id) {
200  try {
201  $unit = $this->repository->getUnit($unit_id);
202  if (!$unit) {
203  continue;
204  }
205 
206  $check_result = $this->repository->deleteUnit($unit->getId());
207  if (!is_null($check_result)) {
208  $errors[] = $unit->getDisplayString() . ' - ' . $check_result;
209  continue;
210  }
211 
212  ++$num_deleted;
213  } catch (ilException $e) {
214  continue;
215  }
216  }
217 
218  if ($errors) {
219  $num_errors = count($errors);
220 
221  $error_message = array_map(static function (string $message): string {
222  return '<li>' . $message . '</li>';
223  }, $errors);
224  if ($num_errors === 1) {
225  $this->tpl->setOnScreenMessage(
226  'failure',
227  $this->lng->txt('un_unit_deletion_errors_p_s') . '<ul>' . implode('', $error_message) . '<ul>'
228  );
229  } else {
230  $this->tpl->setOnScreenMessage(
231  'failure',
232  $this->lng->txt('un_unit_deletion_errors_p') . '<ul>' . implode('', $error_message) . '<ul>'
233  );
234  }
235  }
236 
237  if ($num_deleted) {
238  if ($num_deleted === 1) {
239  $this->tpl->setOnScreenMessage('success', $this->lng->txt('un_deleted_units_s'));
240  } else {
241  $this->tpl->setOnScreenMessage('success', $this->lng->txt('un_deleted_units'));
242  }
243  }
244 
245  $this->showUnitsOfCategory();
246  }
$errors
Definition: imgupload.php:65
$message
Definition: xapiexit.php:32
+ Here is the call graph for this function:

◆ executeCommand()

ilUnitConfigurationGUI::executeCommand ( )

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

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

Referenced by ilLocalUnitConfigurationGUI\getUniqueId().

80  : void
81  {
82  $cmd = $this->ctrl->getCmd($this->getDefaultCommand());
83  $this->checkPermissions($cmd);
84  switch ($cmd) {
85  case 'confirmImportGlobalCategories':
86  $category_ids = $this->request->raw('category_ids');
87  $this->$cmd($category_ids);
88  break;
89  default:
90  $this->$cmd();
91  break;
92  }
93 
94  $this->handleSubtabs();
95  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getCategoryById()

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

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

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

Referenced by addUnit(), initUnitForm(), saveCategory(), saveUnit(), showUnitCategoryModificationForm(), showUnitCreationForm(), and showUnitModificationForm().

62  {
63  $category = $this->repository->getUnitCategoryById($id);
64  if ($for_CRUD && $category->getQuestionFi() !== $this->repository->getConsumerId()) {
65  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('change_adm_categories_not_allowed'), true);
66  $this->ctrl->redirect($this, $this->getDefaultCommand());
67  }
68 
69  return $category;
70  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getDefaultCommand()

ilUnitConfigurationGUI::getDefaultCommand ( )
abstractprotected

◆ getUniqueId()

ilUnitConfigurationGUI::getUniqueId ( )
abstract

Referenced by __construct().

+ Here is the caller graph for this function:

◆ getUnitCategoryOverviewCommand()

ilUnitConfigurationGUI::getUnitCategoryOverviewCommand ( )
abstract

◆ handleSubtabs()

ilUnitConfigurationGUI::handleSubtabs ( )
protected

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

Referenced by executeCommand().

72  : void
73  {
74  }
+ Here is the caller graph for this function:

◆ initUnitCategoryForm()

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

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

References $unit_cat_form, ILIAS\Repository\ctrl(), getUnitCategoryOverviewCommand(), and ILIAS\Repository\lng().

Referenced by addCategory(), saveCategory(), showUnitCategoryCreationForm(), and showUnitCategoryModificationForm().

674  {
675  if ($this->unit_cat_form instanceof ilPropertyFormGUI) {
676  return $this->unit_cat_form;
677  }
678 
679  $this->unit_cat_form = new ilPropertyFormGUI();
680 
681  $title = new ilTextInputGUI($this->lng->txt('title'), 'category_name');
682  $title->setRequired(true);
683  $this->unit_cat_form->addItem($title);
684 
685  if (null === $cat) {
686  $this->unit_cat_form->setTitle($this->lng->txt('new_category'));
687  $this->unit_cat_form->setFormAction($this->ctrl->getFormAction($this, 'addCategory'));
688  $this->unit_cat_form->addCommandButton('addCategory', $this->lng->txt('save'));
689  } else {
690  $this->ctrl->setParameter($this, 'category_id', $cat->getId());
691  $this->unit_cat_form->addCommandButton('saveCategory', $this->lng->txt('save'));
692  $this->unit_cat_form->setFormAction($this->ctrl->getFormAction($this, 'saveCategory'));
693  $this->unit_cat_form->setTitle(sprintf($this->lng->txt('selected_category'), $cat->getDisplayString()));
694  }
695 
696  $this->unit_cat_form->addCommandButton($this->getUnitCategoryOverviewCommand(), $this->lng->txt('cancel'));
697  return $this->unit_cat_form;
698  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ initUnitForm()

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

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

References $data, $DIC, $unit_form, ILIAS\Repository\ctrl(), getCategoryById(), assFormulaQuestionUnit\getId(), getUnitCategoryOverviewCommand(), isCRUDContext(), ILIAS\Repository\lng(), ILIAS\UI\examples\Deck\repository(), ilFormPropertyGUI\setRequired(), and showUnitCategories().

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

378  if ($this->unit_form instanceof ilPropertyFormGUI) {
379  return $this->unit_form;
380  }
381 
382  $unit_in_use = false;
383  if ($unit instanceof assFormulaQuestionUnit && $this->repository->isUnitInUse($unit->getId())) {
384  $unit_in_use = true;
385  }
386 
387  $this->unit_form = new ilPropertyFormGUI();
388 
389  $title = new ilTextInputGUI($this->lng->txt('unit'), 'unit_title');
390  $title->setDisabled($unit_in_use);
391  $title->setRequired(true);
392  $this->unit_form->addItem($title);
393 
394  $baseunit = new ilSelectInputGUI($this->lng->txt('baseunit'), 'base_unit');
395  $items = $this->repository->getCategorizedUnits();
396  $options = [];
397  $category_name = '';
398  $new_category = false;
399  foreach ($items as $item) {
400  if (
401  $unit instanceof assFormulaQuestionUnit &&
402  $unit->getId() === $item->getId()
403  ) {
404  continue;
405  }
406 
407  if ($item instanceof assFormulaQuestionUnitCategory) {
408  if ($category_name !== $item->getDisplayString()) {
409  $new_category = true;
410  $category_name = $item->getDisplayString();
411  }
412  continue;
413  }
414 
415  $options[$item->getId()] = $item->getDisplayString() . ($new_category ? ' (' . $category_name . ')' : '');
416  $new_category = false;
417  }
418  $baseunit->setDisabled($unit_in_use);
419  $baseunit->setOptions([0 => $this->lng->txt('no_selection')] + $options);
420  $this->unit_form->addItem($baseunit);
421 
422  $factor = new ilNumberInputGUI($this->lng->txt('factor'), 'factor');
423  $factor->setRequired(true);
424  $factor->setSize(3);
425  $factor->setMinValue(0);
426  $factor->allowDecimals(true);
427  $factor->setDisabled($unit_in_use);
428  $this->unit_form->addItem($factor);
429 
430  $this->ctrl->setParameterByClass(get_class($this), 'category_id', $this->request->int('category_id'));
431  if (null === $unit) {
432  $this->unit_form->setTitle($this->lng->txt('new_unit'));
433  $this->unit_form->setFormAction($this->ctrl->getFormAction($this, 'addUnit'));
434  $this->unit_form->addCommandButton('addUnit', $this->lng->txt('save'));
435  } else {
436  $this->ctrl->setParameter($this, 'unit_id', $unit->getId());
437  if ($unit_in_use) {
438  $this->unit_form->setFormAction($this->ctrl->getFormAction($this, 'showUnitsOfCategory'));
439  } else {
440  $this->unit_form->addCommandButton('saveUnit', $this->lng->txt('save'));
441  $this->unit_form->setFormAction($this->ctrl->getFormAction($this, 'saveUnit'));
442  }
443  $this->unit_form->setTitle(sprintf(
444  $this->lng->txt('un_sel_cat_sel_unit'),
445  $category->getDisplayString(),
446  $unit->getDisplayString()
447  ));
448  }
449  $this->ctrl->clearParameterByClass(get_class($this), 'category_id');
450 
451  $this->unit_form->addCommandButton('showUnitsOfCategory', $this->lng->txt('cancel'));
452  return $this->unit_form;
453  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class represents a number property in a property form.
setRequired(bool $a_required)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isCRUDContext()

◆ saveCategory()

ilUnitConfigurationGUI::saveCategory ( )
protected

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

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

740  : void
741  {
742  if (!$this->isCRUDContext()) {
743  $this->{$this->getDefaultCommand()}();
744  return;
745  }
746 
747  $category = $this->getCategoryById($this->request->int('category_id'));
748 
749  $this->initUnitCategoryForm($category);
750  if ($this->unit_cat_form->checkInput()) {
751  try {
752  $category->setCategory($this->unit_cat_form->getInput('category_name'));
753  $this->repository->saveCategory($category);
754  $this->tpl->setOnScreenMessage('success', $this->lng->txt('saved_successfully'));
755 
756  $this->{$this->getUnitCategoryOverviewCommand()}();
757  return;
758  } catch (ilException $e) {
759  $this->unit_cat_form->getItemByPostVar('category_name')->setAlert($this->lng->txt($e->getMessage()));
760  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('form_input_not_valid'));
761  }
762  }
763 
764  $this->unit_cat_form->setValuesByPost();
765 
766  $this->tpl->setContent($this->unit_cat_form->getHtml());
767  }
initUnitCategoryForm(assFormulaQuestionUnitCategory $cat=null)
getCategoryById(int $id, bool $for_CRUD=true)
+ Here is the call graph for this function:

◆ saveOrder()

ilUnitConfigurationGUI::saveOrder ( )
protected

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

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

248  : void
249  {
250  if (!$this->isCRUDContext()) {
251  $this->showUnitsOfCategory();
252  return;
253  }
254 
255  if (!$this->request->isset('sequence') || !is_array($this->request->raw('sequence'))) {
256  $this->showUnitsOfCategory();
257  return;
258  }
259 
260  $sequences = $this->request->raw('sequence');
261  foreach ($sequences as $id => $sequence) {
262  $sorting_value = str_replace(',', '.', $sequence);
263  $sorting_value = (int) $sorting_value * 100;
264  $this->repository->saveUnitOrder((int) $id, $sorting_value);
265  }
266 
267  $this->tpl->setOnScreenMessage('success', $this->lng->txt('saved_successfully'));
268  $this->showUnitsOfCategory();
269  }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
+ Here is the call graph for this function:

◆ saveUnit()

ilUnitConfigurationGUI::saveUnit ( )
protected

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

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

271  : void
272  {
273  if (!$this->isCRUDContext()) {
274  $this->showUnitsOfCategory();
275  return;
276  }
277 
278  $category = $this->getCategoryById($this->request->int('category_id'));
279  $unit = $this->repository->getUnit($this->request->int('unit_id'));
280 
281  if ($this->repository->isUnitInUse($unit->getId())) {
282  $this->showUnitModificationForm();
283  return;
284  }
285 
286  $this->initUnitForm($category, $unit);
287  if ($this->unit_form->checkInput()) {
288  $unit->setUnit($this->unit_form->getInput('unit_title'));
289  $unit->setFactor((float) $this->unit_form->getInput('factor'));
290  $unit->setBaseUnit((int) $this->unit_form->getInput('base_unit') !== $unit->getId() ? (int) $this->unit_form->getInput('base_unit') : 0);
291  $unit->setCategory($category->getId());
292  $this->repository->saveUnit($unit);
293 
294  $this->tpl->setOnScreenMessage('success', $this->lng->txt('saved_successfully'));
295  $this->showUnitsOfCategory();
296  return;
297  }
298 
299  $this->unit_form->setValuesByPost();
300 
301  $this->tpl->setContent($this->unit_form->getHtml());
302  }
getCategoryById(int $id, bool $for_CRUD=true)
initUnitForm(assFormulaQuestionUnitCategory $category=null, assFormulaQuestionUnit $unit=null)
+ Here is the call graph for this function:

◆ showUnitCategories()

ilUnitConfigurationGUI::showUnitCategories ( array  $categories)
abstractprotected

Referenced by __construct(), and initUnitForm().

+ Here is the caller graph for this function:

◆ showUnitCategoryCreationForm()

ilUnitConfigurationGUI::showUnitCategoryCreationForm ( )
protected

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

References getDefaultCommand(), initUnitCategoryForm(), and isCRUDContext().

728  : void
729  {
730  if (!$this->isCRUDContext()) {
731  $this->{$this->getDefaultCommand()}();
732  return;
733  }
734 
735  $this->initUnitCategoryForm();
736 
737  $this->tpl->setContent($this->unit_cat_form->getHtml());
738  }
initUnitCategoryForm(assFormulaQuestionUnitCategory $cat=null)
+ Here is the call graph for this function:

◆ showUnitCategoryModificationForm()

ilUnitConfigurationGUI::showUnitCategoryModificationForm ( )
protected

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

References getCategoryById(), getDefaultCommand(), initUnitCategoryForm(), and isCRUDContext().

769  : void
770  {
771  if (!$this->isCRUDContext()) {
772  $this->{$this->getDefaultCommand()}();
773  return;
774  }
775 
776  $category = $this->getCategoryById($this->request->int('category_id'));
777 
778  $this->initUnitCategoryForm($category);
779  $this->unit_cat_form->setValuesByArray([
780  'category_name' => $category->getCategory()
781  ]);
782 
783  $this->tpl->setContent($this->unit_cat_form->getHtml());
784  }
initUnitCategoryForm(assFormulaQuestionUnitCategory $cat=null)
getCategoryById(int $id, bool $for_CRUD=true)
+ Here is the call graph for this function:

◆ showUnitCreationForm()

ilUnitConfigurationGUI::showUnitCreationForm ( )
protected

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

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

356  : void
357  {
358  if (!$this->isCRUDContext()) {
359  $this->showUnitsOfCategory();
360  return;
361  }
362 
363  $category = $this->getCategoryById($this->request->int('category_id'));
364 
365  $this->initUnitForm($category);
366  $this->unit_form->setValuesByArray([
367  'factor' => 1,
368  'unit_title' => $this->lng->txt('unit_placeholder')
369  ]);
370 
371  $this->tpl->setContent($this->unit_form->getHtml());
372  }
getCategoryById(int $id, bool $for_CRUD=true)
initUnitForm(assFormulaQuestionUnitCategory $category=null, assFormulaQuestionUnit $unit=null)
+ Here is the call graph for this function:

◆ showUnitModificationForm()

ilUnitConfigurationGUI::showUnitModificationForm ( )
protected

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

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

Referenced by saveUnit().

304  : void
305  {
306  if (!$this->isCRUDContext()) {
307  $this->showUnitsOfCategory();
308  return;
309  }
310 
311  $category = $this->getCategoryById($this->request->int('category_id'));
312  $unit = $this->repository->getUnit($this->request->int('unit_id'));
313 
314  $this->initUnitForm($category, $unit);
315  $this->unit_form->setValuesByArray([
316  'factor' => $unit->getFactor(),
317  'unit_title' => $unit->getUnit(),
318  'base_unit' => $unit->getBaseUnit() !== $unit->getId() ? $unit->getBaseUnit() : 0
319  ]);
320 
321  $this->tpl->setContent($this->unit_form->getHtml());
322  }
getCategoryById(int $id, bool $for_CRUD=true)
initUnitForm(assFormulaQuestionUnitCategory $category=null, assFormulaQuestionUnit $unit=null)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $ctrl

ilCtrlInterface ilUnitConfigurationGUI::$ctrl
protected

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

◆ $lng

ilLanguage ilUnitConfigurationGUI::$lng
protected

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

Referenced by __construct().

◆ $repository

ilUnitConfigurationRepository ilUnitConfigurationGUI::$repository
protected

◆ $request

ILIAS TestQuestionPool InternalRequestService ilUnitConfigurationGUI::$request
protected

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

◆ $tpl

ilGlobalTemplateInterface ilUnitConfigurationGUI::$tpl
protected

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

Referenced by __construct().

◆ $unit_cat_form

ilPropertyFormGUI ilUnitConfigurationGUI::$unit_cat_form = null
protected

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

Referenced by initUnitCategoryForm().

◆ $unit_form

ilPropertyFormGUI ilUnitConfigurationGUI::$unit_form = null
protected

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

Referenced by initUnitForm().


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