19 declare(strict_types=1);
40 $this->
lng = $DIC->language();
41 $this->
ctrl = $DIC->ctrl();
42 $this->tpl = $DIC->ui()->mainTemplate();
44 $local_dic = QuestionPoolDIC::dic();
45 $this->request = $local_dic[
'request_data_collector'];
47 $this->
lng->loadLanguageModule(
'assessment');
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);
84 case 'confirmImportGlobalCategories':
85 $category_ids = $this->request->raw(
'category_ids');
86 $this->$cmd($category_ids);
98 if (!$this->request->isset(
'unit_id')) {
99 $this->showUnitsOfCategory();
114 $this->showUnitsOfCategory();
118 $unit_ids = $unit_ids ?? $this->request->getUnitIds();
119 if (count($unit_ids) === 0) {
120 $this->showUnitsOfCategory();
124 $this->
ctrl->setParameter($this,
'category_id', $this->request->int(
'category_id'));
126 $confirmation->setFormAction($this->
ctrl->getFormAction($this,
'deleteUnits'));
127 $confirmation->setConfirm($this->
lng->txt(
'confirm'),
'deleteUnits');
128 $confirmation->setCancel($this->
lng->txt(
'cancel'),
'showUnitsOfCategory');
132 foreach ($unit_ids as $unit_id) {
134 $unit = $this->
repository->getUnit((
int) $unit_id);
139 if ($check_result = $this->
repository->checkDeleteUnit($unit->getId())) {
140 $errors[] = $unit->getDisplayString() .
' - ' . $check_result;
144 $confirmation->addItem(
'unit_ids[]', (
string) $unit->getId(), $unit->getDisplayString());
152 $num_errors = count($errors);
155 return '<li>' . $message .
'</li>';
157 if ($num_errors === 1) {
158 $this->tpl->setOnScreenMessage(
160 $this->
lng->txt(
'un_unit_deletion_errors_f_s') .
'<ul>' . implode(
'', $error_message) .
'<ul>' 163 $this->tpl->setOnScreenMessage(
165 $this->
lng->txt(
'un_unit_deletion_errors_f') .
'<ul>' . implode(
'', $error_message) .
'<ul>' 170 if ($num_to_confirm) {
171 if ($num_to_confirm === 1) {
172 $confirmation->setHeaderText($this->
lng->txt(
'un_sure_delete_units_s'));
174 $confirmation->setHeaderText($this->
lng->txt(
'un_sure_delete_units'));
177 $this->tpl->setContent($confirmation->getHTML());
179 $this->showUnitsOfCategory();
186 $this->showUnitsOfCategory();
190 $unit_ids = $this->request->getUnitIds();
191 if (count($unit_ids) === 0) {
192 $this->showUnitsOfCategory();
198 foreach ($unit_ids as $unit_id) {
205 $check_result = $this->
repository->deleteUnit($unit->getId());
206 if (!is_null($check_result)) {
207 $errors[] = $unit->getDisplayString() .
' - ' . $check_result;
218 $num_errors = count($errors);
221 return '<li>' . $message .
'</li>';
223 if ($num_errors === 1) {
224 $this->tpl->setOnScreenMessage(
226 $this->
lng->txt(
'un_unit_deletion_errors_p_s') .
'<ul>' . implode(
'', $error_message) .
'<ul>' 229 $this->tpl->setOnScreenMessage(
231 $this->
lng->txt(
'un_unit_deletion_errors_p') .
'<ul>' . implode(
'', $error_message) .
'<ul>' 237 if ($num_deleted === 1) {
238 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'un_deleted_units_s'));
240 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'un_deleted_units'));
244 $this->showUnitsOfCategory();
250 $this->showUnitsOfCategory();
254 if (!$this->request->isset(
'sequence') || !is_array($this->request->raw(
'sequence'))) {
255 $this->showUnitsOfCategory();
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;
266 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'saved_successfully'));
267 $this->showUnitsOfCategory();
273 $this->showUnitsOfCategory();
277 $category = $this->
getCategoryById($this->request->int(
'category_id'));
278 $unit = $this->
repository->getUnit($this->request->int(
'unit_id'));
280 if ($this->
repository->isUnitInUse($unit->getId())) {
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());
293 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'saved_successfully'));
294 $this->showUnitsOfCategory();
298 $this->unit_form->setValuesByPost();
300 $this->tpl->setContent($this->unit_form->getHtml());
306 $this->showUnitsOfCategory();
310 $category = $this->
getCategoryById($this->request->int(
'category_id'));
311 $unit = $this->
repository->getUnit($this->request->int(
'unit_id'));
314 $this->unit_form->setValuesByArray([
315 'factor' => $unit->getFactor(),
316 'unit_title' => $unit->getUnit(),
317 'base_unit' => $unit->getBaseUnit() !== $unit->getId() ? $unit->getBaseUnit() : 0
320 $this->tpl->setContent($this->unit_form->getHtml());
326 $this->showUnitsOfCategory();
330 $category = $this->
getCategoryById($this->request->int(
'category_id'));
333 if ($this->unit_form->checkInput()) {
335 $unit->setUnit($this->unit_form->getInput(
'unit_title'));
336 $unit->setCategory($category->getId());
340 $unit->setBaseUnit((
int) $this->unit_form->getInput(
'base_unit'));
341 $unit->setFactor((
float) $this->unit_form->getInput(
'factor'));
345 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'saved_successfully'));
346 $this->showUnitsOfCategory();
350 $this->unit_form->setValuesByPost();
352 $this->tpl->setContent($this->unit_form->getHtml());
358 $this->showUnitsOfCategory();
362 $category = $this->
getCategoryById($this->request->int(
'category_id'));
365 $this->unit_form->setValuesByArray([
367 'unit_title' => $this->
lng->txt(
'unit_placeholder')
370 $this->tpl->setContent($this->unit_form->getHtml());
381 $unit_in_use =
false;
386 $this->unit_form =
new ilPropertyFormGUI();
389 $title->setDisabled($unit_in_use);
390 $title->setRequired(
true);
391 $this->unit_form->addItem($title);
394 $items = $this->
repository->getCategorizedUnits();
397 $new_category =
false;
398 foreach ($items as $item) {
401 $unit->
getId() === $item->getId()
407 if ($category_name !== $item->getDisplayString()) {
408 $new_category =
true;
409 $category_name = $item->getDisplayString();
414 $options[$item->getId()] = $item->getDisplayString() . ($new_category ?
' (' . $category_name .
')' :
'');
415 $new_category =
false;
417 $baseunit->setDisabled($unit_in_use);
418 $baseunit->setOptions([0 => $this->
lng->txt(
'no_selection')] + $options);
419 $this->unit_form->addItem($baseunit);
424 $factor->setMinValue(0);
425 $factor->allowDecimals(
true);
426 $factor->setDisabled($unit_in_use);
427 $this->unit_form->addItem($factor);
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'));
435 $this->
ctrl->setParameter($this,
'unit_id', $unit->getId());
437 $this->unit_form->setFormAction($this->
ctrl->getFormAction($this,
'showUnitsOfCategory'));
439 $this->unit_form->addCommandButton(
'saveUnit', $this->
lng->txt(
'save'));
440 $this->unit_form->setFormAction($this->
ctrl->getFormAction($this,
'saveUnit'));
442 $this->unit_form->setTitle(sprintf(
443 $this->
lng->txt(
'un_sel_cat_sel_unit'),
444 $category->getDisplayString(),
445 $unit->getDisplayString()
448 $this->
ctrl->clearParameterByClass(get_class($this),
'category_id');
450 $this->unit_form->addCommandButton(
'showUnitsOfCategory', $this->
lng->txt(
'cancel'));
454 protected function showUnitsOfCategory():
void 458 $ilToolbar = $DIC->toolbar();
460 $category = $this->
getCategoryById($this->request->int(
'category_id'),
false);
462 $this->tpl->addJavaScript(
"assets/js/Basic.js");
463 $this->tpl->addJavaScript(
"assets/js/Form.js");
464 $this->
lng->loadLanguageModule(
'form');
466 $ilToolbar->addButton(
467 $this->
lng->txt(
'back'),
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')
476 $this->
ctrl->clearParameterByClass(get_class($this),
'category_id');
478 $table =
new ilUnitTableGUI($this,
'showUnitsOfCategory', $category);
479 $units = $this->
repository->loadUnitsForCategory($category->getId());
481 foreach ($units as $unit) {
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(),
492 $table->setData(
$data);
494 $this->tpl->setContent($table->getHTML());
497 protected function showGlobalUnitCategories():
void 499 $categories = array_filter(
502 return !$category->getQuestionFi() ? true :
false;
506 foreach ($categories as $category) {
509 'category_id' => $category->getId(),
510 'category' => $category->getDisplayString()
519 if (!$this->request->isset(
'category_id')) {
539 $category_ids = $category_ids ?? $this->request->getUnitCategoryIds();
540 if (count($category_ids) === 0) {
546 $confirmation->setFormAction($this->
ctrl->getFormAction($this,
'deleteCategories'));
547 $confirmation->setConfirm($this->
lng->txt(
'confirm'),
'deleteCategories');
552 foreach ($category_ids as $category_id) {
554 $category = $this->
repository->getUnitCategoryById($category_id);
559 if (!$this->
repository->isCRUDAllowed($category_id)) {
560 $errors[] = $category->getDisplayString() .
' - ' . $this->
lng->txt(
'change_adm_categories_not_allowed');
564 $possible_error = $this->
repository->checkDeleteCategory($category_id);
565 if (is_string($possible_error) && $possible_error !==
'') {
566 $errors[] = $category->getDisplayString() .
' - ' . $possible_error;
570 $confirmation->addItem(
'category_ids[]', (
string) $category->getId(), $category->getDisplayString());
575 $num_errors = count($errors);
578 return '<li>' . $message .
'</li>';
580 if ($num_errors === 1) {
581 $this->tpl->setOnScreenMessage(
583 $this->
lng->txt(
'un_cat_deletion_errors_f_s') .
'<ul>' . implode(
'', $error_message) .
'<ul>' 586 $this->tpl->setOnScreenMessage(
588 $this->
lng->txt(
'un_cat_deletion_errors_f') .
'<ul>' . implode(
'', $error_message) .
'<ul>' 593 if ($num_to_confirm) {
594 if ($num_to_confirm === 1) {
595 $confirmation->setHeaderText($this->
lng->txt(
'un_sure_delete_categories_s'));
597 $confirmation->setHeaderText($this->
lng->txt(
'un_sure_delete_categories'));
600 $this->tpl->setContent($confirmation->getHTML());
613 $category_ids = $this->request->getUnitCategoryIds();
614 if (count($category_ids) === 0) {
621 foreach ($category_ids as $category_id) {
623 $category = $this->
repository->getUnitCategoryById($category_id);
628 if (!$this->
repository->isCRUDAllowed($category_id)) {
629 $errors[] = $category->getDisplayString() .
' - ' . $this->
lng->txt(
'change_adm_categories_not_allowed');
633 $possible_error = $this->
repository->deleteCategory($category_id);
634 if (is_string($possible_error) && $possible_error !==
'') {
635 $errors[] = $category->getDisplayString() .
' - ' . $possible_error;
643 $num_errors = count($errors);
646 return '<li>' . $message .
'</li>';
648 if ($num_errors === 1) {
649 $this->tpl->setOnScreenMessage(
651 $this->
lng->txt(
'un_cat_deletion_errors_p_s') .
'<ul>' . implode(
'', $error_message) .
'<ul>' 654 $this->tpl->setOnScreenMessage(
656 $this->
lng->txt(
'un_cat_deletion_errors_p') .
'<ul>' . implode(
'', $error_message) .
'<ul>' 662 if ($num_deleted === 1) {
663 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'un_deleted_categories_s'));
665 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'un_deleted_categories'));
678 $this->unit_cat_form =
new ilPropertyFormGUI();
681 $title->setRequired(
true);
682 $this->unit_cat_form->addItem($title);
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'));
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()));
707 if ($this->unit_cat_form->checkInput()) {
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'));
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'));
722 $this->unit_cat_form->setValuesByPost();
724 $this->tpl->setContent($this->unit_cat_form->getHtml());
736 $this->tpl->setContent($this->unit_cat_form->getHtml());
746 $category = $this->
getCategoryById($this->request->int(
'category_id'));
749 if ($this->unit_cat_form->checkInput()) {
751 $category->setCategory($this->unit_cat_form->getInput(
'category_name'));
753 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'saved_successfully'));
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'));
763 $this->unit_cat_form->setValuesByPost();
765 $this->tpl->setContent($this->unit_cat_form->getHtml());
775 $category = $this->
getCategoryById($this->request->int(
'category_id'));
778 $this->unit_cat_form->setValuesByArray([
779 'category_name' => $category->getCategory()
782 $this->tpl->setContent($this->unit_cat_form->getHtml());
ilPropertyFormGUI $unit_form
getUnitCategoryOverviewCommand()
showUnitCategoryModificationForm()
repository()
description: > Example for rendering a repository card
Class ilUnitConfigurationRepository.
initUnitCategoryForm(?assFormulaQuestionUnitCategory $cat=null)
Class ilUnitConfigurationGUI.
initUnitForm(?assFormulaQuestionUnitCategory $category=null, ?assFormulaQuestionUnit $unit=null)
ilPropertyFormGUI $unit_cat_form
RequestDataCollector $request
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
__construct(protected ilUnitConfigurationRepository $repository)
checkPermissions(string $cmd)
showUnitModificationForm()
showUnitCategoryCreationForm()
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
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