19declare(strict_types=1);
41 $this->
lng = $DIC->language();
42 $this->
ctrl = $DIC->ctrl();
43 $this->tpl =
$DIC->ui()->mainTemplate();
44 $this->
access = $DIC->access();
46 $local_dic = QuestionPoolDIC::dic();
47 $this->request = $local_dic[
'request_data_collector'];
49 $this->
lng->loadLanguageModule(
'assessment');
64 $category = $this->
repository->getUnitCategoryById($id);
65 if ($for_CRUD && $category->getQuestionFi() !== $this->repository->getConsumerId()) {
66 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'change_adm_categories_not_allowed'),
true);
79 if (!$this->
access->checkAccess(
'read',
'', $this->request->getRefId())) {
80 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'permission_denied'),
true);
85 if (in_array($cmd, [
'showUnitCategories',
'showUnitsOfCategory',
'showGlobalUnitCategories'],
true)) {
89 if ($this->
access->checkAccess(
'write',
'', $this->request->getRefId())) {
93 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'permission_denied'),
true);
102 'confirmImportGlobalCategories' => $this->$cmd($this->request->getUnitCategoryIds()),
103 default => $this->$cmd(),
111 if (!$this->request->isset(
'unit_id')) {
112 $this->showUnitsOfCategory();
127 $this->showUnitsOfCategory();
131 $unit_ids = $unit_ids ?? $this->request->getUnitIds();
132 if (count($unit_ids) === 0) {
133 $this->showUnitsOfCategory();
137 $this->
ctrl->setParameter($this,
'category_id', $this->request->int(
'category_id'));
139 $confirmation->setFormAction($this->
ctrl->getFormAction($this,
'deleteUnits'));
140 $confirmation->setConfirm($this->
lng->txt(
'confirm'),
'deleteUnits');
141 $confirmation->setCancel($this->
lng->txt(
'cancel'),
'showUnitsOfCategory');
145 foreach ($unit_ids as $unit_id) {
147 $unit = $this->
repository->getUnit((
int) $unit_id);
152 if ($check_result = $this->
repository->checkDeleteUnit($unit->getId())) {
153 $errors[] = $unit->getDisplayString() .
' - ' . $check_result;
157 $confirmation->addItem(
'unit_ids[]', (
string) $unit->getId(), $unit->getDisplayString());
165 $num_errors = count($errors);
167 $error_message = array_map(
static function (
string $message):
string {
168 return '<li>' . $message .
'</li>';
170 if ($num_errors === 1) {
171 $this->tpl->setOnScreenMessage(
173 $this->
lng->txt(
'un_unit_deletion_errors_f_s') .
'<ul>' . implode(
'', $error_message) .
'<ul>'
176 $this->tpl->setOnScreenMessage(
178 $this->
lng->txt(
'un_unit_deletion_errors_f') .
'<ul>' . implode(
'', $error_message) .
'<ul>'
183 if ($num_to_confirm) {
184 if ($num_to_confirm === 1) {
185 $confirmation->setHeaderText($this->
lng->txt(
'un_sure_delete_units_s'));
187 $confirmation->setHeaderText($this->
lng->txt(
'un_sure_delete_units'));
190 $this->tpl->setContent($confirmation->getHTML());
192 $this->showUnitsOfCategory();
199 $this->showUnitsOfCategory();
203 $unit_ids = $this->request->getUnitIds();
204 if (count($unit_ids) === 0) {
205 $this->showUnitsOfCategory();
211 foreach ($unit_ids as $unit_id) {
218 $check_result = $this->
repository->deleteUnit($unit->getId());
219 if (!is_null($check_result)) {
220 $errors[] = $unit->getDisplayString() .
' - ' . $check_result;
231 $num_errors = count($errors);
233 $error_message = array_map(
static function (
string $message):
string {
234 return '<li>' . $message .
'</li>';
236 if ($num_errors === 1) {
237 $this->tpl->setOnScreenMessage(
239 $this->
lng->txt(
'un_unit_deletion_errors_p_s') .
'<ul>' . implode(
'', $error_message) .
'<ul>'
242 $this->tpl->setOnScreenMessage(
244 $this->
lng->txt(
'un_unit_deletion_errors_p') .
'<ul>' . implode(
'', $error_message) .
'<ul>'
250 if ($num_deleted === 1) {
251 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'un_deleted_units_s'));
253 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'un_deleted_units'));
257 $this->showUnitsOfCategory();
263 $this->showUnitsOfCategory();
267 if (!$this->request->isset(
'sequence') || !is_array($this->request->raw(
'sequence'))) {
268 $this->showUnitsOfCategory();
272 $sequences = $this->request->raw(
'sequence');
273 foreach ($sequences as
$id => $sequence) {
274 $sorting_value = str_replace(
',',
'.', $sequence);
275 $sorting_value = (
int) $sorting_value * 100;
279 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'saved_successfully'));
280 $this->showUnitsOfCategory();
286 $this->showUnitsOfCategory();
290 $category = $this->
getCategoryById($this->request->int(
'category_id'));
291 $unit = $this->
repository->getUnit($this->request->int(
'unit_id'));
293 if ($this->
repository->isUnitInUse($unit->getId())) {
299 if ($this->unit_form->checkInput()) {
300 $unit->setUnit($this->unit_form->getInput(
'unit_title'));
301 $unit->setFactor((
float) $this->unit_form->getInput(
'factor'));
302 $unit->setBaseUnit((
int) $this->unit_form->getInput(
'base_unit') !== $unit->getId() ? (
int) $this->unit_form->getInput(
'base_unit') : 0);
303 $unit->setCategory($category->getId());
306 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'saved_successfully'));
307 $this->showUnitsOfCategory();
311 $this->unit_form->setValuesByPost();
313 $this->tpl->setContent($this->unit_form->getHtml());
319 $this->showUnitsOfCategory();
323 $category = $this->
getCategoryById($this->request->int(
'category_id'));
324 $unit = $this->
repository->getUnit($this->request->int(
'unit_id'));
327 $this->unit_form->setValuesByArray([
328 'factor' => $unit->getFactor(),
329 'unit_title' => $unit->getUnit(),
330 'base_unit' => $unit->getBaseUnit() !== $unit->getId() ? $unit->getBaseUnit() : 0
333 $this->tpl->setContent($this->unit_form->getHtml());
339 $this->showUnitsOfCategory();
343 $category = $this->
getCategoryById($this->request->int(
'category_id'));
346 if ($this->unit_form->checkInput()) {
348 $unit->setUnit($this->unit_form->getInput(
'unit_title'));
349 $unit->setCategory($category->getId());
353 $unit->setBaseUnit((
int) $this->unit_form->getInput(
'base_unit'));
354 $unit->setFactor((
float) $this->unit_form->getInput(
'factor'));
358 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'saved_successfully'));
359 $this->showUnitsOfCategory();
363 $this->unit_form->setValuesByPost();
365 $this->tpl->setContent($this->unit_form->getHtml());
371 $this->showUnitsOfCategory();
375 $category = $this->
getCategoryById($this->request->int(
'category_id'));
378 $this->unit_form->setValuesByArray([
380 'unit_title' => $this->
lng->txt(
'unit_placeholder')
383 $this->tpl->setContent($this->unit_form->getHtml());
394 $unit_in_use =
false;
402 $title->setDisabled($unit_in_use);
403 $title->setRequired(
true);
404 $this->unit_form->addItem($title);
407 $items = $this->
repository->getCategorizedUnits();
410 $new_category =
false;
411 foreach ($items as $item) {
414 $unit->
getId() === $item->getId()
420 if ($category_name !== $item->getDisplayString()) {
421 $new_category =
true;
422 $category_name = $item->getDisplayString();
427 $options[$item->getId()] = $item->getDisplayString() . ($new_category ?
' (' . $category_name .
')' :
'');
428 $new_category =
false;
430 $baseunit->setDisabled($unit_in_use);
431 $baseunit->setOptions([0 => $this->
lng->txt(
'no_selection')] +
$options);
432 $this->unit_form->addItem($baseunit);
435 $factor->setRequired(
true);
437 $factor->setMinValue(0);
438 $factor->allowDecimals(
true);
439 $factor->setDisabled($unit_in_use);
440 $this->unit_form->addItem($factor);
442 $this->
ctrl->setParameterByClass(get_class($this),
'category_id', $this->request->int(
'category_id'));
443 if (
null === $unit) {
444 $this->unit_form->setTitle($this->
lng->txt(
'new_unit'));
445 $this->unit_form->setFormAction($this->
ctrl->getFormAction($this,
'addUnit'));
446 $this->unit_form->addCommandButton(
'addUnit', $this->
lng->txt(
'save'));
448 $this->
ctrl->setParameter($this,
'unit_id', $unit->getId());
450 $this->unit_form->setFormAction($this->
ctrl->getFormAction($this,
'showUnitsOfCategory'));
452 $this->unit_form->addCommandButton(
'saveUnit', $this->
lng->txt(
'save'));
453 $this->unit_form->setFormAction($this->
ctrl->getFormAction($this,
'saveUnit'));
455 $this->unit_form->setTitle(sprintf(
456 $this->
lng->txt(
'un_sel_cat_sel_unit'),
457 $category->getDisplayString(),
458 $unit->getDisplayString()
461 $this->
ctrl->clearParameterByClass(get_class($this),
'category_id');
463 $this->unit_form->addCommandButton(
'showUnitsOfCategory', $this->
lng->txt(
'cancel'));
467 protected function showUnitsOfCategory(): void
471 $ilToolbar =
$DIC->toolbar();
473 $category = $this->getCategoryById($this->request->int(
'category_id'),
false);
475 $this->tpl->addJavaScript(
"assets/js/Basic.js");
476 $this->tpl->addJavaScript(
"assets/js/Form.js");
477 $this->
lng->loadLanguageModule(
'form');
479 $ilToolbar->addButton(
480 $this->
lng->txt(
'back'),
481 $this->ctrl->getLinkTarget($this, $this->getUnitCategoryOverviewCommand())
483 if ($this->isCRUDContext() && $this->
access->checkAccess(
'write',
'', $this->request->getRefId())) {
484 $this->
ctrl->setParameterByClass(get_class($this),
'category_id', $category->getId());
485 $ilToolbar->addButton(
486 $this->
lng->txt(
'un_add_unit'),
487 $this->ctrl->getLinkTarget($this,
'showUnitCreationForm')
489 $this->
ctrl->clearParameterByClass(get_class($this),
'category_id');
491 $table =
new ilUnitTableGUI($this,
'showUnitsOfCategory', $category);
492 $units = $this->
repository->loadUnitsForCategory($category->getId());
494 foreach ($units as $unit) {
497 'unit_id' => $unit->getId(),
498 'unit' => $unit->getSanitizedUnit(),
499 'baseunit' => $unit->getSanitizedBaseunitTitle(),
500 'baseunit_id' => $unit->getBaseUnit(),
501 'factor' => $unit->getFactor(),
502 'sequence' => $unit->getSequence(),
505 $table->setData(
$data);
507 $this->tpl->setContent($table->getHTML());
510 protected function showGlobalUnitCategories(): void
512 $categories = array_filter(
519 foreach ($categories as $category) {
522 'category_id' => $category->getId(),
523 'category' => $category->getDisplayString()
527 $this->showUnitCategories(
$data);
532 if (!$this->request->isset(
'category_id')) {
533 $this->{$this->getUnitCategoryOverviewCommand()}();
537 $this->confirmDeleteCategories([$this->request->int(
'category_id')]);
547 if (!$this->isCRUDContext()) {
548 $this->{$this->getDefaultCommand()}();
552 $category_ids = $category_ids ?? $this->request->getUnitCategoryIds();
553 if (count($category_ids) === 0) {
554 $this->{$this->getUnitCategoryOverviewCommand()}();
559 $confirmation->setFormAction($this->
ctrl->getFormAction($this,
'deleteCategories'));
560 $confirmation->setConfirm($this->
lng->txt(
'confirm'),
'deleteCategories');
561 $confirmation->setCancel($this->
lng->txt(
'cancel'), $this->getUnitCategoryOverviewCommand());
565 foreach ($category_ids as $category_id) {
567 $category = $this->
repository->getUnitCategoryById($category_id);
572 if (!$this->
repository->isCRUDAllowed($category_id)) {
573 $errors[] = $category->getDisplayString() .
' - ' . $this->
lng->txt(
'change_adm_categories_not_allowed');
577 $possible_error = $this->
repository->checkDeleteCategory($category_id);
578 if (is_string($possible_error) && $possible_error !==
'') {
579 $errors[] = $category->getDisplayString() .
' - ' . $possible_error;
583 $confirmation->addItem(
'category_ids[]', (
string) $category->getId(), $category->getDisplayString());
588 $num_errors = count($errors);
590 $error_message = array_map(
static function (
string $message):
string {
591 return '<li>' . $message .
'</li>';
593 if ($num_errors === 1) {
594 $this->tpl->setOnScreenMessage(
596 $this->
lng->txt(
'un_cat_deletion_errors_f_s') .
'<ul>' . implode(
'', $error_message) .
'<ul>'
599 $this->tpl->setOnScreenMessage(
601 $this->
lng->txt(
'un_cat_deletion_errors_f') .
'<ul>' . implode(
'', $error_message) .
'<ul>'
606 if ($num_to_confirm) {
607 if ($num_to_confirm === 1) {
608 $confirmation->setHeaderText($this->
lng->txt(
'un_sure_delete_categories_s'));
610 $confirmation->setHeaderText($this->
lng->txt(
'un_sure_delete_categories'));
613 $this->tpl->setContent($confirmation->getHTML());
615 $this->{$this->getUnitCategoryOverviewCommand()}();
621 if (!$this->isCRUDContext()) {
622 $this->{$this->getDefaultCommand()}();
626 $category_ids = $this->request->getUnitCategoryIds();
627 if (count($category_ids) === 0) {
628 $this->{$this->getUnitCategoryOverviewCommand()}();
634 foreach ($category_ids as $category_id) {
636 $category = $this->
repository->getUnitCategoryById($category_id);
641 if (!$this->
repository->isCRUDAllowed($category_id)) {
642 $errors[] = $category->getDisplayString() .
' - ' . $this->
lng->txt(
'change_adm_categories_not_allowed');
646 $possible_error = $this->
repository->deleteCategory($category_id);
647 if (is_string($possible_error) && $possible_error !==
'') {
648 $errors[] = $category->getDisplayString() .
' - ' . $possible_error;
656 $num_errors = count($errors);
658 $error_message = array_map(
static function (
string $message):
string {
659 return '<li>' . $message .
'</li>';
661 if ($num_errors === 1) {
662 $this->tpl->setOnScreenMessage(
664 $this->
lng->txt(
'un_cat_deletion_errors_p_s') .
'<ul>' . implode(
'', $error_message) .
'<ul>'
667 $this->tpl->setOnScreenMessage(
669 $this->
lng->txt(
'un_cat_deletion_errors_p') .
'<ul>' . implode(
'', $error_message) .
'<ul>'
675 if ($num_deleted === 1) {
676 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'un_deleted_categories_s'));
678 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'un_deleted_categories'));
682 $this->{$this->getUnitCategoryOverviewCommand()}();
688 return $this->unit_cat_form;
694 $title->setRequired(
true);
695 $this->unit_cat_form->addItem($title);
698 $this->unit_cat_form->setTitle($this->
lng->txt(
'new_category'));
699 $this->unit_cat_form->setFormAction($this->
ctrl->getFormAction($this,
'addCategory'));
700 $this->unit_cat_form->addCommandButton(
'addCategory', $this->
lng->txt(
'save'));
702 $this->
ctrl->setParameter($this,
'category_id', $cat->getId());
703 $this->unit_cat_form->addCommandButton(
'saveCategory', $this->
lng->txt(
'save'));
704 $this->unit_cat_form->setFormAction($this->
ctrl->getFormAction($this,
'saveCategory'));
705 $this->unit_cat_form->setTitle(sprintf($this->
lng->txt(
'selected_category'), $cat->getDisplayString()));
708 $this->unit_cat_form->addCommandButton($this->getUnitCategoryOverviewCommand(), $this->
lng->txt(
'cancel'));
709 return $this->unit_cat_form;
714 if (!$this->isCRUDContext()) {
715 $this->{$this->getDefaultCommand()}();
719 $this->initUnitCategoryForm();
720 if ($this->unit_cat_form->checkInput()) {
723 $category->setCategory($this->unit_cat_form->getInput(
'category_name'));
724 $this->
repository->saveNewUnitCategory($category);
725 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'saved_successfully'));
727 $this->{$this->getUnitCategoryOverviewCommand()}();
730 $this->unit_cat_form->getItemByPostVar(
'category_name')->setAlert($this->
lng->txt($e->getMessage()));
731 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'form_input_not_valid'));
735 $this->unit_cat_form->setValuesByPost();
737 $this->tpl->setContent($this->unit_cat_form->getHtml());
742 if (!$this->isCRUDContext()) {
743 $this->{$this->getDefaultCommand()}();
747 $this->initUnitCategoryForm();
749 $this->tpl->setContent($this->unit_cat_form->getHtml());
754 if (!$this->isCRUDContext()) {
755 $this->{$this->getDefaultCommand()}();
759 $category = $this->getCategoryById($this->request->int(
'category_id'));
761 $this->initUnitCategoryForm($category);
762 if ($this->unit_cat_form->checkInput()) {
764 $category->setCategory($this->unit_cat_form->getInput(
'category_name'));
766 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'saved_successfully'));
768 $this->{$this->getUnitCategoryOverviewCommand()}();
771 $this->unit_cat_form->getItemByPostVar(
'category_name')->setAlert($this->
lng->txt($e->getMessage()));
772 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'form_input_not_valid'));
776 $this->unit_cat_form->setValuesByPost();
778 $this->tpl->setContent($this->unit_cat_form->getHtml());
783 if (!$this->isCRUDContext()) {
784 $this->{$this->getDefaultCommand()}();
788 $category = $this->getCategoryById($this->request->int(
'category_id'));
790 $this->initUnitCategoryForm($category);
791 $this->unit_cat_form->setValuesByArray([
792 'category_name' => $category->getCategory()
795 $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.
static getStartingPointAsUrl()
Interface ilAccessHandler This interface combines all available interfaces which can be called via gl...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
if(!file_exists('../ilias.ini.php'))