19declare(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 'confirmImportGlobalCategories' => $this->$cmd($this->request->getUnitCategoryIds()),
85 default => $this->$cmd(),
93 if (!$this->request->isset(
'unit_id')) {
94 $this->showUnitsOfCategory();
109 $this->showUnitsOfCategory();
113 $unit_ids = $unit_ids ?? $this->request->getUnitIds();
114 if (count($unit_ids) === 0) {
115 $this->showUnitsOfCategory();
119 $this->
ctrl->setParameter($this,
'category_id', $this->request->int(
'category_id'));
121 $confirmation->setFormAction($this->
ctrl->getFormAction($this,
'deleteUnits'));
122 $confirmation->setConfirm($this->
lng->txt(
'confirm'),
'deleteUnits');
123 $confirmation->setCancel($this->
lng->txt(
'cancel'),
'showUnitsOfCategory');
127 foreach ($unit_ids as $unit_id) {
129 $unit = $this->
repository->getUnit((
int) $unit_id);
134 if ($check_result = $this->
repository->checkDeleteUnit($unit->getId())) {
135 $errors[] = $unit->getDisplayString() .
' - ' . $check_result;
139 $confirmation->addItem(
'unit_ids[]', (
string) $unit->getId(), $unit->getDisplayString());
147 $num_errors = count($errors);
149 $error_message = array_map(
static function (
string $message):
string {
150 return '<li>' . $message .
'</li>';
152 if ($num_errors === 1) {
153 $this->tpl->setOnScreenMessage(
155 $this->
lng->txt(
'un_unit_deletion_errors_f_s') .
'<ul>' . implode(
'', $error_message) .
'<ul>'
158 $this->tpl->setOnScreenMessage(
160 $this->
lng->txt(
'un_unit_deletion_errors_f') .
'<ul>' . implode(
'', $error_message) .
'<ul>'
165 if ($num_to_confirm) {
166 if ($num_to_confirm === 1) {
167 $confirmation->setHeaderText($this->
lng->txt(
'un_sure_delete_units_s'));
169 $confirmation->setHeaderText($this->
lng->txt(
'un_sure_delete_units'));
172 $this->tpl->setContent($confirmation->getHTML());
174 $this->showUnitsOfCategory();
181 $this->showUnitsOfCategory();
185 $unit_ids = $this->request->getUnitIds();
186 if (count($unit_ids) === 0) {
187 $this->showUnitsOfCategory();
193 foreach ($unit_ids as $unit_id) {
200 $check_result = $this->
repository->deleteUnit($unit->getId());
201 if (!is_null($check_result)) {
202 $errors[] = $unit->getDisplayString() .
' - ' . $check_result;
213 $num_errors = count($errors);
215 $error_message = array_map(
static function (
string $message):
string {
216 return '<li>' . $message .
'</li>';
218 if ($num_errors === 1) {
219 $this->tpl->setOnScreenMessage(
221 $this->
lng->txt(
'un_unit_deletion_errors_p_s') .
'<ul>' . implode(
'', $error_message) .
'<ul>'
224 $this->tpl->setOnScreenMessage(
226 $this->
lng->txt(
'un_unit_deletion_errors_p') .
'<ul>' . implode(
'', $error_message) .
'<ul>'
232 if ($num_deleted === 1) {
233 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'un_deleted_units_s'));
235 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'un_deleted_units'));
239 $this->showUnitsOfCategory();
245 $this->showUnitsOfCategory();
249 if (!$this->request->isset(
'sequence') || !is_array($this->request->raw(
'sequence'))) {
250 $this->showUnitsOfCategory();
254 $sequences = $this->request->raw(
'sequence');
255 foreach ($sequences as
$id => $sequence) {
256 $sorting_value = str_replace(
',',
'.', $sequence);
257 $sorting_value = (
int) $sorting_value * 100;
261 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'saved_successfully'));
262 $this->showUnitsOfCategory();
268 $this->showUnitsOfCategory();
272 $category = $this->
getCategoryById($this->request->int(
'category_id'));
273 $unit = $this->
repository->getUnit($this->request->int(
'unit_id'));
275 if ($this->
repository->isUnitInUse($unit->getId())) {
281 if ($this->unit_form->checkInput()) {
282 $unit->setUnit($this->unit_form->getInput(
'unit_title'));
283 $unit->setFactor((
float) $this->unit_form->getInput(
'factor'));
284 $unit->setBaseUnit((
int) $this->unit_form->getInput(
'base_unit') !== $unit->getId() ? (
int) $this->unit_form->getInput(
'base_unit') : 0);
285 $unit->setCategory($category->getId());
288 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'saved_successfully'));
289 $this->showUnitsOfCategory();
293 $this->unit_form->setValuesByPost();
295 $this->tpl->setContent($this->unit_form->getHtml());
301 $this->showUnitsOfCategory();
305 $category = $this->
getCategoryById($this->request->int(
'category_id'));
306 $unit = $this->
repository->getUnit($this->request->int(
'unit_id'));
309 $this->unit_form->setValuesByArray([
310 'factor' => $unit->getFactor(),
311 'unit_title' => $unit->getUnit(),
312 'base_unit' => $unit->getBaseUnit() !== $unit->getId() ? $unit->getBaseUnit() : 0
315 $this->tpl->setContent($this->unit_form->getHtml());
321 $this->showUnitsOfCategory();
325 $category = $this->
getCategoryById($this->request->int(
'category_id'));
328 if ($this->unit_form->checkInput()) {
330 $unit->setUnit($this->unit_form->getInput(
'unit_title'));
331 $unit->setCategory($category->getId());
335 $unit->setBaseUnit((
int) $this->unit_form->getInput(
'base_unit'));
336 $unit->setFactor((
float) $this->unit_form->getInput(
'factor'));
340 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'saved_successfully'));
341 $this->showUnitsOfCategory();
345 $this->unit_form->setValuesByPost();
347 $this->tpl->setContent($this->unit_form->getHtml());
353 $this->showUnitsOfCategory();
357 $category = $this->
getCategoryById($this->request->int(
'category_id'));
360 $this->unit_form->setValuesByArray([
362 'unit_title' => $this->
lng->txt(
'unit_placeholder')
365 $this->tpl->setContent($this->unit_form->getHtml());
376 $unit_in_use =
false;
384 $title->setDisabled($unit_in_use);
385 $title->setRequired(
true);
386 $this->unit_form->addItem($title);
389 $items = $this->
repository->getCategorizedUnits();
392 $new_category =
false;
393 foreach ($items as $item) {
396 $unit->
getId() === $item->getId()
402 if ($category_name !== $item->getDisplayString()) {
403 $new_category =
true;
404 $category_name = $item->getDisplayString();
409 $options[$item->getId()] = $item->getDisplayString() . ($new_category ?
' (' . $category_name .
')' :
'');
410 $new_category =
false;
412 $baseunit->setDisabled($unit_in_use);
413 $baseunit->setOptions([0 => $this->
lng->txt(
'no_selection')] +
$options);
414 $this->unit_form->addItem($baseunit);
417 $factor->setRequired(
true);
419 $factor->setMinValue(0);
420 $factor->allowDecimals(
true);
421 $factor->setDisabled($unit_in_use);
422 $this->unit_form->addItem($factor);
424 $this->
ctrl->setParameterByClass(get_class($this),
'category_id', $this->request->int(
'category_id'));
425 if (
null === $unit) {
426 $this->unit_form->setTitle($this->
lng->txt(
'new_unit'));
427 $this->unit_form->setFormAction($this->
ctrl->getFormAction($this,
'addUnit'));
428 $this->unit_form->addCommandButton(
'addUnit', $this->
lng->txt(
'save'));
430 $this->
ctrl->setParameter($this,
'unit_id', $unit->getId());
432 $this->unit_form->setFormAction($this->
ctrl->getFormAction($this,
'showUnitsOfCategory'));
434 $this->unit_form->addCommandButton(
'saveUnit', $this->
lng->txt(
'save'));
435 $this->unit_form->setFormAction($this->
ctrl->getFormAction($this,
'saveUnit'));
437 $this->unit_form->setTitle(sprintf(
438 $this->
lng->txt(
'un_sel_cat_sel_unit'),
439 $category->getDisplayString(),
440 $unit->getDisplayString()
443 $this->
ctrl->clearParameterByClass(get_class($this),
'category_id');
445 $this->unit_form->addCommandButton(
'showUnitsOfCategory', $this->
lng->txt(
'cancel'));
449 protected function showUnitsOfCategory(): void
453 $ilToolbar =
$DIC->toolbar();
455 $category = $this->getCategoryById($this->request->int(
'category_id'),
false);
457 $this->tpl->addJavaScript(
"assets/js/Basic.js");
458 $this->tpl->addJavaScript(
"assets/js/Form.js");
459 $this->
lng->loadLanguageModule(
'form');
461 $ilToolbar->addButton(
462 $this->
lng->txt(
'back'),
463 $this->ctrl->getLinkTarget($this, $this->getUnitCategoryOverviewCommand())
465 if ($this->isCRUDContext()) {
466 $this->
ctrl->setParameterByClass(get_class($this),
'category_id', $category->getId());
467 $ilToolbar->addButton(
468 $this->
lng->txt(
'un_add_unit'),
469 $this->ctrl->getLinkTarget($this,
'showUnitCreationForm')
471 $this->
ctrl->clearParameterByClass(get_class($this),
'category_id');
473 $table =
new ilUnitTableGUI($this,
'showUnitsOfCategory', $category);
474 $units = $this->
repository->loadUnitsForCategory($category->getId());
476 foreach ($units as $unit) {
479 'unit_id' => $unit->getId(),
480 'unit' => $unit->getSanitizedUnit(),
481 'baseunit' => $unit->getSanitizedBaseunitTitle(),
482 'baseunit_id' => $unit->getBaseUnit(),
483 'factor' => $unit->getFactor(),
484 'sequence' => $unit->getSequence(),
487 $table->setData(
$data);
489 $this->tpl->setContent($table->getHTML());
492 protected function showGlobalUnitCategories(): void
494 $categories = array_filter(
501 foreach ($categories as $category) {
504 'category_id' => $category->getId(),
505 'category' => $category->getDisplayString()
509 $this->showUnitCategories(
$data);
514 if (!$this->request->isset(
'category_id')) {
515 $this->{$this->getUnitCategoryOverviewCommand()}();
519 $this->confirmDeleteCategories([$this->request->int(
'category_id')]);
529 if (!$this->isCRUDContext()) {
530 $this->{$this->getDefaultCommand()}();
534 $category_ids = $category_ids ?? $this->request->getUnitCategoryIds();
535 if (count($category_ids) === 0) {
536 $this->{$this->getUnitCategoryOverviewCommand()}();
541 $confirmation->setFormAction($this->
ctrl->getFormAction($this,
'deleteCategories'));
542 $confirmation->setConfirm($this->
lng->txt(
'confirm'),
'deleteCategories');
543 $confirmation->setCancel($this->
lng->txt(
'cancel'), $this->getUnitCategoryOverviewCommand());
547 foreach ($category_ids as $category_id) {
549 $category = $this->
repository->getUnitCategoryById($category_id);
554 if (!$this->
repository->isCRUDAllowed($category_id)) {
555 $errors[] = $category->getDisplayString() .
' - ' . $this->
lng->txt(
'change_adm_categories_not_allowed');
559 $possible_error = $this->
repository->checkDeleteCategory($category_id);
560 if (is_string($possible_error) && $possible_error !==
'') {
561 $errors[] = $category->getDisplayString() .
' - ' . $possible_error;
565 $confirmation->addItem(
'category_ids[]', (
string) $category->getId(), $category->getDisplayString());
570 $num_errors = count($errors);
572 $error_message = array_map(
static function (
string $message):
string {
573 return '<li>' . $message .
'</li>';
575 if ($num_errors === 1) {
576 $this->tpl->setOnScreenMessage(
578 $this->
lng->txt(
'un_cat_deletion_errors_f_s') .
'<ul>' . implode(
'', $error_message) .
'<ul>'
581 $this->tpl->setOnScreenMessage(
583 $this->
lng->txt(
'un_cat_deletion_errors_f') .
'<ul>' . implode(
'', $error_message) .
'<ul>'
588 if ($num_to_confirm) {
589 if ($num_to_confirm === 1) {
590 $confirmation->setHeaderText($this->
lng->txt(
'un_sure_delete_categories_s'));
592 $confirmation->setHeaderText($this->
lng->txt(
'un_sure_delete_categories'));
595 $this->tpl->setContent($confirmation->getHTML());
597 $this->{$this->getUnitCategoryOverviewCommand()}();
603 if (!$this->isCRUDContext()) {
604 $this->{$this->getDefaultCommand()}();
608 $category_ids = $this->request->getUnitCategoryIds();
609 if (count($category_ids) === 0) {
610 $this->{$this->getUnitCategoryOverviewCommand()}();
616 foreach ($category_ids as $category_id) {
618 $category = $this->
repository->getUnitCategoryById($category_id);
623 if (!$this->
repository->isCRUDAllowed($category_id)) {
624 $errors[] = $category->getDisplayString() .
' - ' . $this->
lng->txt(
'change_adm_categories_not_allowed');
628 $possible_error = $this->
repository->deleteCategory($category_id);
629 if (is_string($possible_error) && $possible_error !==
'') {
630 $errors[] = $category->getDisplayString() .
' - ' . $possible_error;
638 $num_errors = count($errors);
640 $error_message = array_map(
static function (
string $message):
string {
641 return '<li>' . $message .
'</li>';
643 if ($num_errors === 1) {
644 $this->tpl->setOnScreenMessage(
646 $this->
lng->txt(
'un_cat_deletion_errors_p_s') .
'<ul>' . implode(
'', $error_message) .
'<ul>'
649 $this->tpl->setOnScreenMessage(
651 $this->
lng->txt(
'un_cat_deletion_errors_p') .
'<ul>' . implode(
'', $error_message) .
'<ul>'
657 if ($num_deleted === 1) {
658 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'un_deleted_categories_s'));
660 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'un_deleted_categories'));
664 $this->{$this->getUnitCategoryOverviewCommand()}();
670 return $this->unit_cat_form;
676 $title->setRequired(
true);
677 $this->unit_cat_form->addItem($title);
680 $this->unit_cat_form->setTitle($this->
lng->txt(
'new_category'));
681 $this->unit_cat_form->setFormAction($this->
ctrl->getFormAction($this,
'addCategory'));
682 $this->unit_cat_form->addCommandButton(
'addCategory', $this->
lng->txt(
'save'));
684 $this->
ctrl->setParameter($this,
'category_id', $cat->getId());
685 $this->unit_cat_form->addCommandButton(
'saveCategory', $this->
lng->txt(
'save'));
686 $this->unit_cat_form->setFormAction($this->
ctrl->getFormAction($this,
'saveCategory'));
687 $this->unit_cat_form->setTitle(sprintf($this->
lng->txt(
'selected_category'), $cat->getDisplayString()));
690 $this->unit_cat_form->addCommandButton($this->getUnitCategoryOverviewCommand(), $this->
lng->txt(
'cancel'));
691 return $this->unit_cat_form;
696 if (!$this->isCRUDContext()) {
697 $this->{$this->getDefaultCommand()}();
701 $this->initUnitCategoryForm();
702 if ($this->unit_cat_form->checkInput()) {
705 $category->setCategory($this->unit_cat_form->getInput(
'category_name'));
706 $this->
repository->saveNewUnitCategory($category);
707 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'saved_successfully'));
709 $this->{$this->getUnitCategoryOverviewCommand()}();
712 $this->unit_cat_form->getItemByPostVar(
'category_name')->setAlert($this->
lng->txt($e->getMessage()));
713 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'form_input_not_valid'));
717 $this->unit_cat_form->setValuesByPost();
719 $this->tpl->setContent($this->unit_cat_form->getHtml());
724 if (!$this->isCRUDContext()) {
725 $this->{$this->getDefaultCommand()}();
729 $this->initUnitCategoryForm();
731 $this->tpl->setContent($this->unit_cat_form->getHtml());
736 if (!$this->isCRUDContext()) {
737 $this->{$this->getDefaultCommand()}();
741 $category = $this->getCategoryById($this->request->int(
'category_id'));
743 $this->initUnitCategoryForm($category);
744 if ($this->unit_cat_form->checkInput()) {
746 $category->setCategory($this->unit_cat_form->getInput(
'category_name'));
748 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'saved_successfully'));
750 $this->{$this->getUnitCategoryOverviewCommand()}();
753 $this->unit_cat_form->getItemByPostVar(
'category_name')->setAlert($this->
lng->txt($e->getMessage()));
754 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'form_input_not_valid'));
758 $this->unit_cat_form->setValuesByPost();
760 $this->tpl->setContent($this->unit_cat_form->getHtml());
765 if (!$this->isCRUDContext()) {
766 $this->{$this->getDefaultCommand()}();
770 $category = $this->getCategoryById($this->request->int(
'category_id'));
772 $this->initUnitCategoryForm($category);
773 $this->unit_cat_form->setValuesByArray([
774 'category_name' => $category->getCategory()
777 $this->tpl->setContent($this->unit_cat_form->getHtml());
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Base class for ILIAS Exception handling.
This class represents a text property in a property form.
Class ilUnitConfigurationGUI.
showUnitCategories(array $categories)
initUnitCategoryForm(?assFormulaQuestionUnitCategory $cat=null)
getCategoryById(int $id, bool $for_CRUD=true)
initUnitForm(?assFormulaQuestionUnitCategory $category=null, ?assFormulaQuestionUnit $unit=null)
confirmDeleteUnits(?array $unit_ids=null)
showUnitCategoryCreationForm()
ilGlobalTemplateInterface $tpl
showUnitModificationForm()
confirmDeleteCategories(?array $category_ids=null)
ilPropertyFormGUI $unit_cat_form
getUnitCategoryOverviewCommand()
showUnitCategoryModificationForm()
__construct(protected ilUnitConfigurationRepository $repository)
ilPropertyFormGUI $unit_form
RequestDataCollector $request
checkPermissions(string $cmd)
Class ilUnitConfigurationRepository.
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...
if(!file_exists('../ilias.ini.php'))