3 declare(strict_types=1);
27 protected \ILIAS\TestQuestionPool\InternalRequestService
$request;
38 $lng = $DIC->language();
39 $ilCtrl = $DIC->ctrl();
40 $tpl = $DIC->ui()->mainTemplate();
41 $this->request = $DIC->testQuestionPool()->internal()->request();
45 $this->
ctrl = $ilCtrl;
48 $this->
lng->loadLanguageModule(
'assessment');
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);
85 case 'confirmImportGlobalCategories':
86 $category_ids = $this->request->raw(
'category_ids');
87 $this->$cmd($category_ids);
99 if (!$this->request->isset(
'unit_id')) {
100 $this->showUnitsOfCategory();
115 $this->showUnitsOfCategory();
119 $unit_ids = $unit_ids ?? $this->request->getUnitIds();
120 if (count($unit_ids) === 0) {
121 $this->showUnitsOfCategory();
125 $this->
ctrl->setParameter($this,
'category_id', $this->request->int(
'category_id'));
127 $confirmation->setFormAction($this->
ctrl->getFormAction($this,
'deleteUnits'));
128 $confirmation->setConfirm($this->
lng->txt(
'confirm'),
'deleteUnits');
129 $confirmation->setCancel($this->
lng->txt(
'cancel'),
'showUnitsOfCategory');
133 foreach ($unit_ids as $unit_id) {
135 $unit = $this->
repository->getUnit((
int) $unit_id);
140 if ($check_result = $this->
repository->checkDeleteUnit($unit->getId())) {
141 $errors[] = $unit->getDisplayString() .
' - ' . $check_result;
145 $confirmation->addItem(
'unit_ids[]', (
string) $unit->getId(), $unit->getDisplayString());
155 $error_message = array_map(
static function (
string $message):
string {
156 return '<li>' . $message .
'</li>';
158 if ($num_errors === 1) {
159 $this->tpl->setOnScreenMessage(
161 $this->
lng->txt(
'un_unit_deletion_errors_f_s') .
'<ul>' . implode(
'', $error_message) .
'<ul>' 164 $this->tpl->setOnScreenMessage(
166 $this->
lng->txt(
'un_unit_deletion_errors_f') .
'<ul>' . implode(
'', $error_message) .
'<ul>' 171 if ($num_to_confirm) {
172 if ($num_to_confirm === 1) {
173 $confirmation->setHeaderText($this->
lng->txt(
'un_sure_delete_units_s'));
175 $confirmation->setHeaderText($this->
lng->txt(
'un_sure_delete_units'));
178 $this->tpl->setContent($confirmation->getHTML());
180 $this->showUnitsOfCategory();
187 $this->showUnitsOfCategory();
191 $unit_ids = $this->request->getUnitIds();
192 if (count($unit_ids) === 0) {
193 $this->showUnitsOfCategory();
199 foreach ($unit_ids as $unit_id) {
206 $check_result = $this->
repository->deleteUnit($unit->getId());
207 if (!is_null($check_result)) {
208 $errors[] = $unit->getDisplayString() .
' - ' . $check_result;
221 $error_message = array_map(
static function (
string $message):
string {
222 return '<li>' . $message .
'</li>';
224 if ($num_errors === 1) {
225 $this->tpl->setOnScreenMessage(
227 $this->
lng->txt(
'un_unit_deletion_errors_p_s') .
'<ul>' . implode(
'', $error_message) .
'<ul>' 230 $this->tpl->setOnScreenMessage(
232 $this->
lng->txt(
'un_unit_deletion_errors_p') .
'<ul>' . implode(
'', $error_message) .
'<ul>' 238 if ($num_deleted === 1) {
239 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'un_deleted_units_s'));
241 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'un_deleted_units'));
245 $this->showUnitsOfCategory();
251 $this->showUnitsOfCategory();
255 if (!$this->request->isset(
'sequence') || !is_array($this->request->raw(
'sequence'))) {
256 $this->showUnitsOfCategory();
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;
267 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'saved_successfully'));
268 $this->showUnitsOfCategory();
274 $this->showUnitsOfCategory();
278 $category = $this->
getCategoryById($this->request->int(
'category_id'));
279 $unit = $this->
repository->getUnit($this->request->int(
'unit_id'));
281 if ($this->
repository->isUnitInUse($unit->getId())) {
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());
294 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'saved_successfully'));
295 $this->showUnitsOfCategory();
299 $this->unit_form->setValuesByPost();
301 $this->tpl->setContent($this->unit_form->getHtml());
307 $this->showUnitsOfCategory();
311 $category = $this->
getCategoryById($this->request->int(
'category_id'));
312 $unit = $this->
repository->getUnit($this->request->int(
'unit_id'));
315 $this->unit_form->setValuesByArray([
316 'factor' => $unit->getFactor(),
317 'unit_title' => $unit->getUnit(),
318 'base_unit' => $unit->getBaseUnit() !== $unit->getId() ? $unit->getBaseUnit() : 0
321 $this->tpl->setContent($this->unit_form->getHtml());
327 $this->showUnitsOfCategory();
331 $category = $this->
getCategoryById($this->request->int(
'category_id'));
334 if ($this->unit_form->checkInput()) {
336 $unit->setUnit($this->unit_form->getInput(
'unit_title'));
337 $unit->setCategory($category->getId());
341 $unit->setBaseUnit((
int) $this->unit_form->getInput(
'base_unit'));
342 $unit->setFactor((
float) $this->unit_form->getInput(
'factor'));
346 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'saved_successfully'));
347 $this->showUnitsOfCategory();
351 $this->unit_form->setValuesByPost();
353 $this->tpl->setContent($this->unit_form->getHtml());
359 $this->showUnitsOfCategory();
363 $category = $this->
getCategoryById($this->request->int(
'category_id'));
366 $this->unit_form->setValuesByArray([
368 'unit_title' => $this->
lng->txt(
'unit_placeholder')
371 $this->tpl->setContent($this->unit_form->getHtml());
382 $unit_in_use =
false;
387 $this->unit_form =
new ilPropertyFormGUI();
390 $title->setDisabled($unit_in_use);
391 $title->setRequired(
true);
392 $this->unit_form->addItem($title);
395 $items = $this->
repository->getCategorizedUnits();
398 $new_category =
false;
399 foreach ($items as $item) {
402 $unit->
getId() === $item->getId()
408 if ($category_name !== $item->getDisplayString()) {
409 $new_category =
true;
410 $category_name = $item->getDisplayString();
415 $options[$item->getId()] = $item->getDisplayString() . ($new_category ?
' (' . $category_name .
')' :
'');
416 $new_category =
false;
418 $baseunit->setDisabled($unit_in_use);
419 $baseunit->setOptions([0 => $this->
lng->txt(
'no_selection')] + $options);
420 $this->unit_form->addItem($baseunit);
425 $factor->setMinValue(0);
426 $factor->allowDecimals(
true);
427 $factor->setDisabled($unit_in_use);
428 $this->unit_form->addItem($factor);
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'));
436 $this->
ctrl->setParameter($this,
'unit_id', $unit->getId());
438 $this->unit_form->setFormAction($this->
ctrl->getFormAction($this,
'showUnitsOfCategory'));
440 $this->unit_form->addCommandButton(
'saveUnit', $this->
lng->txt(
'save'));
441 $this->unit_form->setFormAction($this->
ctrl->getFormAction($this,
'saveUnit'));
443 $this->unit_form->setTitle(sprintf(
444 $this->
lng->txt(
'un_sel_cat_sel_unit'),
445 $category->getDisplayString(),
446 $unit->getDisplayString()
449 $this->
ctrl->clearParameterByClass(get_class($this),
'category_id');
451 $this->unit_form->addCommandButton(
'showUnitsOfCategory', $this->
lng->txt(
'cancel'));
455 protected function showUnitsOfCategory():
void 459 $ilToolbar = $DIC->toolbar();
461 $category = $this->
getCategoryById($this->request->int(
'category_id'),
false);
463 $this->tpl->addJavaScript(
"./Services/JavaScript/js/Basic.js");
464 $this->tpl->addJavaScript(
"./Services/Form/js/Form.js");
465 $this->
lng->loadLanguageModule(
'form');
467 $ilToolbar->addButton(
468 $this->
lng->txt(
'back'),
472 $this->
ctrl->setParameterByClass(get_class($this),
'category_id', $category->getId());
473 $ilToolbar->addButton(
474 $this->
lng->txt(
'un_add_unit'),
475 $this->
ctrl->getLinkTarget($this,
'showUnitCreationForm')
477 $this->
ctrl->clearParameterByClass(get_class($this),
'category_id');
479 $table =
new ilUnitTableGUI($this,
'showUnitsOfCategory', $category);
480 $units = $this->
repository->loadUnitsForCategory($category->getId());
482 foreach ($units as $unit) {
485 'unit_id' => $unit->getId(),
486 'unit' => $unit->getUnit(),
487 'baseunit' => $unit->getBaseunitTitle(),
488 'baseunit_id' => $unit->getBaseUnit(),
489 'factor' => $unit->getFactor(),
490 'sequence' => $unit->getSequence(),
493 $table->setData(
$data);
495 $this->tpl->setContent($table->getHTML());
498 protected function showGlobalUnitCategories():
void 500 $categories = array_filter(
503 return !$category->getQuestionFi() ? true :
false;
507 foreach ($categories as $category) {
510 'category_id' => $category->getId(),
511 'category' => $category->getDisplayString()
520 if (!$this->request->isset(
'category_id')) {
540 $category_ids = $category_ids ?? $this->request->getUnitCategoryIds();
541 if (count($category_ids) === 0) {
547 $confirmation->setFormAction($this->
ctrl->getFormAction($this,
'deleteCategories'));
548 $confirmation->setConfirm($this->
lng->txt(
'confirm'),
'deleteCategories');
553 foreach ($category_ids as $category_id) {
555 $category = $this->
repository->getUnitCategoryById($category_id);
560 if (!$this->
repository->isCRUDAllowed($category_id)) {
561 $errors[] = $category->getDisplayString() .
' - ' . $this->
lng->txt(
'change_adm_categories_not_allowed');
565 $possible_error = $this->
repository->checkDeleteCategory($category_id);
566 if (is_string($possible_error) && $possible_error !==
'') {
567 $errors[] = $category->getDisplayString() .
' - ' . $possible_error;
571 $confirmation->addItem(
'category_ids[]', (
string) $category->getId(), $category->getDisplayString());
578 $error_message = array_map(
static function (
string $message):
string {
579 return '<li>' . $message .
'</li>';
581 if ($num_errors === 1) {
582 $this->tpl->setOnScreenMessage(
584 $this->
lng->txt(
'un_cat_deletion_errors_f_s') .
'<ul>' . implode(
'', $error_message) .
'<ul>' 587 $this->tpl->setOnScreenMessage(
589 $this->
lng->txt(
'un_cat_deletion_errors_f') .
'<ul>' . implode(
'', $error_message) .
'<ul>' 594 if ($num_to_confirm) {
595 if ($num_to_confirm === 1) {
596 $confirmation->setHeaderText($this->
lng->txt(
'un_sure_delete_categories_s'));
598 $confirmation->setHeaderText($this->
lng->txt(
'un_sure_delete_categories'));
601 $this->tpl->setContent($confirmation->getHTML());
614 $category_ids = $this->request->getUnitCategoryIds();
615 if (count($category_ids) === 0) {
622 foreach ($category_ids as $category_id) {
624 $category = $this->
repository->getUnitCategoryById($category_id);
629 if (!$this->
repository->isCRUDAllowed($category_id)) {
630 $errors[] = $category->getDisplayString() .
' - ' . $this->
lng->txt(
'change_adm_categories_not_allowed');
634 $possible_error = $this->
repository->deleteCategory($category_id);
635 if (is_string($possible_error) && $possible_error !==
'') {
636 $errors[] = $category->getDisplayString() .
' - ' . $possible_error;
646 $error_message = array_map(
static function (
string $message):
string {
647 return '<li>' . $message .
'</li>';
649 if ($num_errors === 1) {
650 $this->tpl->setOnScreenMessage(
652 $this->
lng->txt(
'un_cat_deletion_errors_p_s') .
'<ul>' . implode(
'', $error_message) .
'<ul>' 655 $this->tpl->setOnScreenMessage(
657 $this->
lng->txt(
'un_cat_deletion_errors_p') .
'<ul>' . implode(
'', $error_message) .
'<ul>' 663 if ($num_deleted === 1) {
664 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'un_deleted_categories_s'));
666 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'un_deleted_categories'));
679 $this->unit_cat_form =
new ilPropertyFormGUI();
682 $title->setRequired(
true);
683 $this->unit_cat_form->addItem($title);
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'));
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()));
708 if ($this->unit_cat_form->checkInput()) {
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'));
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'));
723 $this->unit_cat_form->setValuesByPost();
725 $this->tpl->setContent($this->unit_cat_form->getHtml());
737 $this->tpl->setContent($this->unit_cat_form->getHtml());
747 $category = $this->
getCategoryById($this->request->int(
'category_id'));
750 if ($this->unit_cat_form->checkInput()) {
752 $category->setCategory($this->unit_cat_form->getInput(
'category_name'));
754 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'saved_successfully'));
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'));
764 $this->unit_cat_form->setValuesByPost();
766 $this->tpl->setContent($this->unit_cat_form->getHtml());
776 $category = $this->
getCategoryById($this->request->int(
'category_id'));
779 $this->unit_cat_form->setValuesByArray([
780 'category_name' => $category->getCategory()
783 $this->tpl->setContent($this->unit_cat_form->getHtml());
ilPropertyFormGUI $unit_form
getUnitCategoryOverviewCommand()
initUnitCategoryForm(assFormulaQuestionUnitCategory $cat=null)
showUnitCategoryModificationForm()
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...
ilPropertyFormGUI $unit_cat_form
showUnitCategories(array $categories)
getCategoryById(int $id, bool $for_CRUD=true)
initUnitForm(assFormulaQuestionUnitCategory $category=null, assFormulaQuestionUnit $unit=null)
ilUnitConfigurationRepository $repository
confirmDeleteUnits(array $unit_ids=null)
checkPermissions(string $cmd)
showUnitModificationForm()
confirmDeleteCategories(array $category_ids=null)
showUnitCategoryCreationForm()
__construct(ilUnitConfigurationRepository $repository)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ilGlobalTemplateInterface $tpl
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ILIAS TestQuestionPool InternalRequestService $request