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