4 require_once
'Services/Form/classes/class.ilPropertyFormGUI.php';
59 $this->lng->loadLanguageModule(
'assessment');
98 $category = $this->repository->getUnitCategoryById($id);
99 if($for_CRUD && $category->getQuestionFi() != $this->repository->getConsumerId())
126 $this->ctrl->saveParameter($this,
'category_id');
129 $nextClass = $this->ctrl->getNextClass($this);
146 if(!isset(
$_GET[
'unit_id']))
148 $this->showUnitsOfCategory();
163 $this->showUnitsOfCategory();
167 if(!isset(
$_POST[
'unit_ids']) || !is_array(
$_POST[
'unit_ids']))
169 $this->showUnitsOfCategory();
173 require_once
'Services/Utilities/classes/class.ilConfirmationGUI.php';
175 $confirmation->setFormAction($this->ctrl->getFormAction($this,
'deleteUnits'));
176 $confirmation->setConfirm($this->lng->txt(
'confirm'),
'deleteUnits');
177 $confirmation->setCancel($this->lng->txt(
'cancel'),
'showUnitsOfCategory');
181 foreach(
$_POST[
'unit_ids'] as $unit_id)
185 $unit = $this->repository->getUnit((
int)$unit_id);
191 if($check_result = $this->repository->checkDeleteUnit($unit->getId()))
193 $errors[] = $unit->getDisplayString() .
' - ' . $check_result;
197 $confirmation->addItem(
'unit_ids[]', $unit->getId(), $unit->getDisplayString());
210 $error_message = array_map(
function ($message)
212 return '<li>' . $message .
'</li>';
216 ilUtil::sendFailure($this->lng->txt(
'un_unit_deletion_errors_f_s') .
'<ul>' . implode(
'', $error_message) .
'<ul>');
220 ilUtil::sendFailure($this->lng->txt(
'un_unit_deletion_errors_f') .
'<ul>' . implode(
'', $error_message) .
'<ul>');
226 if($num_to_confirm == 1)
228 $confirmation->setHeaderText($this->lng->txt(
'un_sure_delete_units_s'));
232 $confirmation->setHeaderText($this->lng->txt(
'un_sure_delete_units'));
235 $this->tpl->setContent($confirmation->getHTML());
239 $this->showUnitsOfCategory();
250 $this->showUnitsOfCategory();
254 if(!is_array(
$_POST[
'unit_ids']) || !
$_POST[
'unit_ids'])
256 $this->showUnitsOfCategory();
262 foreach(
$_POST[
'unit_ids'] as $unit_id)
266 $unit = $this->repository->getUnit((
int)$unit_id);
272 $check_result = $this->repository->deleteUnit($unit->getId());
273 if(!is_null($check_result))
275 $errors[] = $unit->getDisplayString() .
' - ' . $check_result;
291 $error_message = array_map(
function ($message)
293 return '<li>' . $message .
'</li>';
297 ilUtil::sendFailure($this->lng->txt(
'un_unit_deletion_errors_p_s') .
'<ul>' . implode(
'', $error_message) .
'<ul>');
301 ilUtil::sendFailure($this->lng->txt(
'un_unit_deletion_errors_p') .
'<ul>' . implode(
'', $error_message) .
'<ul>');
307 if($num_deleted == 1)
317 $this->showUnitsOfCategory();
327 $this->showUnitsOfCategory();
331 if(!isset(
$_POST[
'sequence']) || !is_array(
$_POST[
'sequence']))
333 $this->showUnitsOfCategory();
337 foreach(
$_POST[
'sequence'] as $id => $sequence)
339 $sorting_value = str_replace(
',',
'.', $sequence);
340 $sorting_value = (int)$sorting_value * 100;
341 $this->repository->saveUnitOrder((
int)$id, $sorting_value);
345 $this->showUnitsOfCategory();
356 $this->showUnitsOfCategory();
361 $unit = $this->repository->getUnit((
int)$_GET[
'unit_id']);
363 if($this->repository->isUnitInUse($unit->getId()))
369 $this->initUnitForm($category, $unit);
370 if($this->unit_form->checkInput())
372 $unit->setUnit($this->unit_form->getInput(
'unit_title'));
373 $unit->setFactor((
float)$this->unit_form->getInput(
'factor'));
374 $unit->setBaseUnit((
int)$this->unit_form->getInput(
'base_unit') != $unit->getId() ? (int)$this->unit_form->getInput(
'base_unit') : 0);
375 $unit->setCategory($category->getId());
376 $this->repository->saveUnit($unit);
378 $this->showUnitsOfCategory();
383 $this->unit_form->setValuesByPost();
386 $this->tpl->setContent($this->unit_form->getHtml());
396 $this->showUnitsOfCategory();
401 $unit = $this->repository->getUnit((
int)$_GET[
'unit_id']);
403 $this->initUnitForm($category, $unit);
404 $this->unit_form->setValuesByArray(array(
405 'factor' => $unit->getFactor(),
406 'unit_title' => $unit->getUnit(),
407 'base_unit' => ($unit->getBaseUnit() != $unit->getId() ? $unit->getBaseUnit() : 0)
410 $this->tpl->setContent($this->unit_form->getHtml());
420 $this->showUnitsOfCategory();
426 $this->initUnitForm($category);
427 if($this->unit_form->checkInput())
430 $unit->setUnit($this->unit_form->getInput(
'unit_title'));
431 $unit->setCategory($category->getId());
433 $this->repository->createNewUnit($unit);
435 $unit->setBaseUnit((
int)$this->unit_form->getInput(
'base_unit'));
436 $unit->setFactor((
float)$this->unit_form->getInput(
'factor'));
438 $this->repository->saveUnit($unit);
441 $this->showUnitsOfCategory();
445 $this->unit_form->setValuesByPost();
447 $this->tpl->setContent($this->unit_form->getHtml());
457 $this->showUnitsOfCategory();
463 $this->initUnitForm($category);
464 $this->unit_form->setValuesByArray(array(
466 'unit_title' => $this->lng->txt(
'unit_placeholder')
469 $this->tpl->setContent($this->unit_form->getHtml());
484 $unit_in_use =
false;
490 $this->unit_form =
new ilPropertyFormGUI();
492 $title =
new ilTextInputGUI($this->lng->txt(
'unit'),
'unit_title');
494 $title->setRequired(
true);
495 $this->unit_form->addItem($title);
498 $items = $this->repository->getCategorizedUnits();
501 $new_category =
false;
502 foreach((array)$items as $item)
506 $unit->
getId() == $item->getId()
517 if($category_name != $item->getDisplayString())
519 $new_category =
true;
520 $category_name = $item->getDisplayString();
524 $options[$item->getId()] = $item->getDisplayString() . ($new_category ?
' (' . $category_name .
')' :
'');
525 $new_category =
false;
527 $baseunit->setDisabled($unit_in_use);
528 $baseunit->setOptions(array(0 => $this->lng->txt(
'no_selection')) +
$options);
529 $this->unit_form->addItem($baseunit);
534 $factor->setMinValue(0);
535 $factor->allowDecimals(
true);
536 $factor->setDisabled($unit_in_use);
537 $this->unit_form->addItem($factor);
541 $this->unit_form->setTitle($this->lng->txt(
'new_unit'));
542 $this->unit_form->setFormAction($this->ctrl->getFormAction($this,
'addUnit'));
543 $this->unit_form->addCommandButton(
'addUnit', $this->lng->txt(
'save'));
547 $this->ctrl->setParameter($this,
'unit_id', $unit->getId());
550 $this->unit_form->setFormAction($this->ctrl->getFormAction($this,
'showUnitsOfCategory'));
554 $this->unit_form->addCommandButton(
'saveUnit', $this->lng->txt(
'save'));
555 $this->unit_form->setFormAction($this->ctrl->getFormAction($this,
'saveUnit'));
557 $this->unit_form->setTitle(sprintf($this->lng->txt(
'un_sel_cat_sel_unit'), $category->getDisplayString(), $unit->getDisplayString()));
560 $this->unit_form->addCommandButton(
'showUnitsOfCategory', $this->lng->txt(
'cancel'));
567 protected function showUnitsOfCategory()
576 $this->tpl->addJavaScript(
"./Services/JavaScript/js/Basic.js");
577 $this->tpl->addJavaScript(
"./Services/Form/js/Form.js");
578 $this->lng->loadLanguageModule(
'form');
580 require_once
'Modules/TestQuestionPool/classes/tables/class.ilUnitTableGUI.php';
584 $ilToolbar->addButton($this->lng->txt(
'un_add_unit'), $this->ctrl->getLinkTarget($this,
'showUnitCreationForm'));
586 $table =
new ilUnitTableGUI($this,
'showUnitsOfCategory', $category);
587 $units = $this->repository->loadUnitsForCategory($category->getId());
589 foreach($units as $unit)
595 'unit_id' => $unit->getId(),
596 'unit' => $unit->getUnit(),
597 'baseunit' => $unit->getBaseunitTitle(),
598 'baseunit_id' => $unit->getBaseUnit(),
599 'factor' => $unit->getFactor(),
600 'sequence' => $unit->getSequence(),
603 $table->setData($data);
605 $this->tpl->setContent($table->getHTML());
611 protected function showGlobalUnitCategories()
613 $categories = array_filter(
614 $this->repository->getAllUnitCategories(),
615 function (assFormulaQuestionUnitCategory $category)
617 return !$category->getQuestionFi() ?
true :
false;
621 foreach($categories as $category)
627 'category_id' => $category->getId(),
628 'category' => $category->getDisplayString()
640 if(!isset(
$_GET[
'category_id']))
645 $_POST[
'category_ids'] = array(
$_GET[
'category_id']);
661 if(!isset(
$_POST[
'category_ids']) || !is_array(
$_POST[
'category_ids']))
667 require_once
'Services/Utilities/classes/class.ilConfirmationGUI.php';
669 $confirmation->setFormAction($this->ctrl->getFormAction($this,
'deleteCategories'));
670 $confirmation->setConfirm($this->lng->txt(
'confirm'),
'deleteCategories');
675 foreach(
$_POST[
'category_ids'] as $category_id)
679 $category = $this->repository->getUnitCategoryById((
int)$category_id);
686 if(!$this->repository->isCRUDAllowed((
int)$category_id))
688 $errors[] = $category->getDisplayString() .
' - ' . $this->lng->txt(
'change_adm_categories_not_allowed');
692 $possible_error = $this->repository->checkDeleteCategory($category_id);
693 if(strlen($possible_error))
695 $errors[] = $category->getDisplayString() .
' - ' . $possible_error;
699 $confirmation->addItem(
'category_ids[]', $category->getId(), $category->getDisplayString());
707 $error_message = array_map(
function ($message)
709 return '<li>' . $message .
'</li>';
713 ilUtil::sendFailure($this->lng->txt(
'un_cat_deletion_errors_f_s') .
'<ul>' . implode(
'', $error_message) .
'<ul>');
717 ilUtil::sendFailure($this->lng->txt(
'un_cat_deletion_errors_f') .
'<ul>' . implode(
'', $error_message) .
'<ul>');
723 if($num_to_confirm == 1)
725 $confirmation->setHeaderText($this->lng->txt(
'un_sure_delete_categories_s'));
729 $confirmation->setHeaderText($this->lng->txt(
'un_sure_delete_categories'));
732 $this->tpl->setContent($confirmation->getHTML());
751 if(!is_array(
$_POST[
'category_ids']) || !
$_POST[
'category_ids'])
759 foreach(
$_POST[
'category_ids'] as $category_id)
763 $category = $this->repository->getUnitCategoryById((
int)$category_id);
770 if(!$this->repository->isCRUDAllowed((
int)$category_id))
772 $errors[] = $category->getDisplayString() .
' - ' . $this->lng->txt(
'change_adm_categories_not_allowed');
776 $possible_error = $this->repository->deleteCategory($category_id);
777 if(strlen($possible_error))
779 $errors[] = $category->getDisplayString() .
' - ' . $possible_error;
790 $error_message = array_map(
function ($message)
792 return '<li>' . $message .
'</li>';
796 ilUtil::sendFailure($this->lng->txt(
'un_cat_deletion_errors_p_s') .
'<ul>' . implode(
'', $error_message) .
'<ul>');
800 ilUtil::sendFailure($this->lng->txt(
'un_cat_deletion_errors_p') .
'<ul>' . implode(
'', $error_message) .
'<ul>');
806 if($num_deleted == 1)
825 if($this->unit_cat_form instanceof ilPropertyFormGUI)
830 $this->unit_cat_form =
new ilPropertyFormGUI();
832 $title =
new ilTextInputGUI($this->lng->txt(
'title'),
'category_name');
834 $this->unit_cat_form->addItem($title);
838 $this->unit_cat_form->setTitle($this->lng->txt(
'new_category'));
839 $this->unit_cat_form->setFormAction($this->ctrl->getFormAction($this,
'addCategory'));
840 $this->unit_cat_form->addCommandButton(
'addCategory', $this->lng->txt(
'save'));
844 $this->ctrl->setParameter($this,
'category_id', $cat->getId());
845 $this->unit_cat_form->addCommandButton(
'saveCategory', $this->lng->txt(
'save'));
846 $this->unit_cat_form->setFormAction($this->ctrl->getFormAction($this,
'saveCategory'));
847 $this->unit_cat_form->setTitle(sprintf($this->lng->txt(
'selected_category'), $cat->getDisplayString()));
866 if($this->unit_cat_form->checkInput())
870 $category =
new assFormulaQuestionUnitCategory();
871 $category->setCategory($this->unit_cat_form->getInput(
'category_name'));
872 $this->repository->saveNewUnitCategory($category);
880 $this->unit_cat_form->getItemByPostVar(
'category_name')->setAlert($this->lng->txt($e->getMessage()));
886 $this->unit_cat_form->setValuesByPost();
888 $this->tpl->setContent($this->unit_cat_form->getHtml());
904 $this->tpl->setContent($this->unit_cat_form->getHtml());
921 if($this->unit_cat_form->checkInput())
925 $category->setCategory($this->unit_cat_form->getInput(
'category_name'));
926 $this->repository->saveCategory($category);
934 $this->unit_cat_form->getItemByPostVar(
'category_name')->setAlert($this->lng->txt($e->getMessage()));
939 $this->unit_cat_form->setValuesByPost();
941 $this->tpl->setContent($this->unit_cat_form->getHtml());
958 $this->unit_cat_form->setValuesByArray(array(
959 'category_name' => $category->getCategory()
962 $this->tpl->setContent($this->unit_cat_form->getHtml());