4 require_once
'Services/Form/classes/class.ilPropertyFormGUI.php';
62 $this->lng->loadLanguageModule(
'assessment');
102 if ($for_CRUD && $category->getQuestionFi() != $this->
repository->getConsumerId()) {
128 $this->ctrl->saveParameter($this,
'category_id');
131 $nextClass = $this->ctrl->getNextClass($this);
132 switch ($nextClass) {
147 if (!isset(
$_GET[
'unit_id'])) {
148 $this->showUnitsOfCategory();
162 $this->showUnitsOfCategory();
166 if (!isset(
$_POST[
'unit_ids']) || !is_array(
$_POST[
'unit_ids'])) {
167 $this->showUnitsOfCategory();
171 require_once
'Services/Utilities/classes/class.ilConfirmationGUI.php';
173 $confirmation->setFormAction($this->ctrl->getFormAction($this,
'deleteUnits'));
174 $confirmation->setConfirm($this->lng->txt(
'confirm'),
'deleteUnits');
175 $confirmation->setCancel($this->lng->txt(
'cancel'),
'showUnitsOfCategory');
179 foreach (
$_POST[
'unit_ids'] as $unit_id) {
181 $unit = $this->
repository->getUnit((
int) $unit_id);
186 if ($check_result = $this->
repository->checkDeleteUnit($unit->getId())) {
187 $errors[] = $unit->getDisplayString() .
' - ' . $check_result;
191 $confirmation->addItem(
'unit_ids[]', $unit->getId(), $unit->getDisplayString());
201 $error_message = array_map(
function (
$message) {
204 if ($num_errors == 1) {
205 ilUtil::sendFailure($this->lng->txt(
'un_unit_deletion_errors_f_s') .
'<ul>' . implode(
'', $error_message) .
'<ul>');
207 ilUtil::sendFailure($this->lng->txt(
'un_unit_deletion_errors_f') .
'<ul>' . implode(
'', $error_message) .
'<ul>');
211 if ($num_to_confirm) {
212 if ($num_to_confirm == 1) {
213 $confirmation->setHeaderText($this->lng->txt(
'un_sure_delete_units_s'));
215 $confirmation->setHeaderText($this->lng->txt(
'un_sure_delete_units'));
218 $this->tpl->setContent($confirmation->getHTML());
220 $this->showUnitsOfCategory();
230 $this->showUnitsOfCategory();
234 if (!is_array(
$_POST[
'unit_ids']) || !
$_POST[
'unit_ids']) {
235 $this->showUnitsOfCategory();
241 foreach (
$_POST[
'unit_ids'] as $unit_id) {
243 $unit = $this->
repository->getUnit((
int) $unit_id);
248 $check_result = $this->
repository->deleteUnit($unit->getId());
249 if (!is_null($check_result)) {
250 $errors[] = $unit->getDisplayString() .
' - ' . $check_result;
263 $error_message = array_map(
function (
$message) {
266 if ($num_errors == 1) {
267 ilUtil::sendFailure($this->lng->txt(
'un_unit_deletion_errors_p_s') .
'<ul>' . implode(
'', $error_message) .
'<ul>');
269 ilUtil::sendFailure($this->lng->txt(
'un_unit_deletion_errors_p') .
'<ul>' . implode(
'', $error_message) .
'<ul>');
274 if ($num_deleted == 1) {
275 ilUtil::sendSuccess($this->lng->txt(
'un_deleted_units_s'));
277 ilUtil::sendSuccess($this->lng->txt(
'un_deleted_units'));
281 $this->showUnitsOfCategory();
290 $this->showUnitsOfCategory();
294 if (!isset(
$_POST[
'sequence']) || !is_array(
$_POST[
'sequence'])) {
295 $this->showUnitsOfCategory();
299 foreach (
$_POST[
'sequence'] as
$id => $sequence) {
300 $sorting_value = str_replace(
',',
'.', $sequence);
301 $sorting_value = (int) $sorting_value * 100;
305 ilUtil::sendSuccess($this->lng->txt(
'saved_successfully'));
306 $this->showUnitsOfCategory();
316 $this->showUnitsOfCategory();
321 $unit = $this->
repository->getUnit((
int) $_GET[
'unit_id']);
323 if ($this->
repository->isUnitInUse($unit->getId())) {
328 $this->initUnitForm($category, $unit);
329 if ($this->unit_form->checkInput()) {
330 $unit->setUnit($this->unit_form->getInput(
'unit_title'));
331 $unit->setFactor((
float) $this->unit_form->getInput(
'factor'));
332 $unit->setBaseUnit((
int) $this->unit_form->getInput(
'base_unit') != $unit->getId() ? (int) $this->unit_form->getInput(
'base_unit') : 0);
333 $unit->setCategory($category->getId());
335 ilUtil::sendSuccess($this->lng->txt(
'saved_successfully'));
336 $this->showUnitsOfCategory();
339 $this->unit_form->setValuesByPost();
342 $this->tpl->setContent($this->unit_form->getHtml());
351 $this->showUnitsOfCategory();
356 $unit = $this->
repository->getUnit((
int) $_GET[
'unit_id']);
358 $this->initUnitForm($category, $unit);
359 $this->unit_form->setValuesByArray(array(
360 'factor' => $unit->getFactor(),
361 'unit_title' => $unit->getUnit(),
362 'base_unit' => ($unit->getBaseUnit() != $unit->getId() ? $unit->getBaseUnit() : 0)
365 $this->tpl->setContent($this->unit_form->getHtml());
374 $this->showUnitsOfCategory();
380 $this->initUnitForm($category);
381 if ($this->unit_form->checkInput()) {
383 $unit->setUnit($this->unit_form->getInput(
'unit_title'));
384 $unit->setCategory($category->getId());
388 $unit->setBaseUnit((
int) $this->unit_form->getInput(
'base_unit'));
389 $unit->setFactor((
float) $this->unit_form->getInput(
'factor'));
393 ilUtil::sendSuccess($this->lng->txt(
'saved_successfully'));
394 $this->showUnitsOfCategory();
398 $this->unit_form->setValuesByPost();
400 $this->tpl->setContent($this->unit_form->getHtml());
409 $this->showUnitsOfCategory();
415 $this->initUnitForm($category);
416 $this->unit_form->setValuesByArray(array(
418 'unit_title' => $this->lng->txt(
'unit_placeholder')
421 $this->tpl->setContent($this->unit_form->getHtml());
435 $unit_in_use =
false;
440 $this->unit_form =
new ilPropertyFormGUI();
443 $title->setDisabled($unit_in_use);
444 $title->setRequired(
true);
445 $this->unit_form->addItem(
$title);
448 $items = $this->
repository->getCategorizedUnits();
451 $new_category =
false;
452 foreach ((array) $items as $item) {
455 $unit->
getId() == $item->getId()
464 if ($category_name != $item->getDisplayString()) {
465 $new_category =
true;
466 $category_name = $item->getDisplayString();
470 $options[$item->getId()] = $item->getDisplayString() . ($new_category ?
' (' . $category_name .
')' :
'');
471 $new_category =
false;
473 $baseunit->setDisabled($unit_in_use);
474 $baseunit->setOptions(array(0 => $this->lng->txt(
'no_selection')) +
$options);
475 $this->unit_form->addItem($baseunit);
480 $factor->setMinValue(0);
481 $factor->allowDecimals(
true);
482 $factor->setDisabled($unit_in_use);
483 $this->unit_form->addItem($factor);
485 if (null === $unit) {
486 $this->unit_form->setTitle($this->lng->txt(
'new_unit'));
487 $this->unit_form->setFormAction($this->ctrl->getFormAction($this,
'addUnit'));
488 $this->unit_form->addCommandButton(
'addUnit', $this->lng->txt(
'save'));
490 $this->ctrl->setParameter($this,
'unit_id', $unit->getId());
492 $this->unit_form->setFormAction($this->ctrl->getFormAction($this,
'showUnitsOfCategory'));
494 $this->unit_form->addCommandButton(
'saveUnit', $this->lng->txt(
'save'));
495 $this->unit_form->setFormAction($this->ctrl->getFormAction($this,
'saveUnit'));
497 $this->unit_form->setTitle(sprintf($this->lng->txt(
'un_sel_cat_sel_unit'), $category->getDisplayString(), $unit->getDisplayString()));
500 $this->unit_form->addCommandButton(
'showUnitsOfCategory', $this->lng->txt(
'cancel'));
507 protected function showUnitsOfCategory()
513 $ilToolbar = $DIC[
'ilToolbar'];
517 $this->tpl->addJavaScript(
"./Services/JavaScript/js/Basic.js");
518 $this->tpl->addJavaScript(
"./Services/Form/js/Form.js");
519 $this->lng->loadLanguageModule(
'form');
521 require_once
'Modules/TestQuestionPool/classes/tables/class.ilUnitTableGUI.php';
524 $ilToolbar->addButton($this->lng->txt(
'un_add_unit'), $this->ctrl->getLinkTarget($this,
'showUnitCreationForm'));
527 $units = $this->
repository->loadUnitsForCategory($category->getId());
529 foreach ($units as $unit) {
534 'unit_id' => $unit->getId(),
535 'unit' => $unit->getUnit(),
536 'baseunit' => $unit->getBaseunitTitle(),
537 'baseunit_id' => $unit->getBaseUnit(),
538 'factor' => $unit->getFactor(),
539 'sequence' => $unit->getSequence(),
544 $this->tpl->setContent(
$table->getHTML());
550 protected function showGlobalUnitCategories()
552 $categories = array_filter(
555 return !$category->getQuestionFi() ? true :
false;
559 foreach ($categories as $category) {
564 'category_id' => $category->getId(),
565 'category' => $category->getDisplayString()
577 if (!isset(
$_GET[
'category_id'])) {
581 $_POST[
'category_ids'] = array(
$_GET[
'category_id']);
596 if (!isset(
$_POST[
'category_ids']) || !is_array(
$_POST[
'category_ids'])) {
601 require_once
'Services/Utilities/classes/class.ilConfirmationGUI.php';
603 $confirmation->setFormAction($this->ctrl->getFormAction($this,
'deleteCategories'));
604 $confirmation->setConfirm($this->lng->txt(
'confirm'),
'deleteCategories');
609 foreach (
$_POST[
'category_ids'] as $category_id) {
611 $category = $this->
repository->getUnitCategoryById((
int) $category_id);
616 if (!$this->
repository->isCRUDAllowed((
int) $category_id)) {
617 $errors[] = $category->getDisplayString() .
' - ' . $this->lng->txt(
'change_adm_categories_not_allowed');
621 $possible_error = $this->
repository->checkDeleteCategory($category_id);
622 if (strlen($possible_error)) {
623 $errors[] = $category->getDisplayString() .
' - ' . $possible_error;
627 $confirmation->addItem(
'category_ids[]', $category->getId(), $category->getDisplayString());
634 $error_message = array_map(
function (
$message) {
637 if ($num_errors == 1) {
638 ilUtil::sendFailure($this->lng->txt(
'un_cat_deletion_errors_f_s') .
'<ul>' . implode(
'', $error_message) .
'<ul>');
640 ilUtil::sendFailure($this->lng->txt(
'un_cat_deletion_errors_f') .
'<ul>' . implode(
'', $error_message) .
'<ul>');
644 if ($num_to_confirm) {
645 if ($num_to_confirm == 1) {
646 $confirmation->setHeaderText($this->lng->txt(
'un_sure_delete_categories_s'));
648 $confirmation->setHeaderText($this->lng->txt(
'un_sure_delete_categories'));
651 $this->tpl->setContent($confirmation->getHTML());
667 if (!is_array(
$_POST[
'category_ids']) || !
$_POST[
'category_ids']) {
674 foreach (
$_POST[
'category_ids'] as $category_id) {
676 $category = $this->
repository->getUnitCategoryById((
int) $category_id);
681 if (!$this->
repository->isCRUDAllowed((
int) $category_id)) {
682 $errors[] = $category->getDisplayString() .
' - ' . $this->lng->txt(
'change_adm_categories_not_allowed');
686 $possible_error = $this->
repository->deleteCategory($category_id);
687 if (strlen($possible_error)) {
688 $errors[] = $category->getDisplayString() .
' - ' . $possible_error;
698 $error_message = array_map(
function (
$message) {
701 if ($num_errors == 1) {
702 ilUtil::sendFailure($this->lng->txt(
'un_cat_deletion_errors_p_s') .
'<ul>' . implode(
'', $error_message) .
'<ul>');
704 ilUtil::sendFailure($this->lng->txt(
'un_cat_deletion_errors_p') .
'<ul>' . implode(
'', $error_message) .
'<ul>');
709 if ($num_deleted == 1) {
710 ilUtil::sendSuccess($this->lng->txt(
'un_deleted_categories_s'));
712 ilUtil::sendSuccess($this->lng->txt(
'un_deleted_categories'));
729 $this->unit_cat_form =
new ilPropertyFormGUI();
732 $title->setRequired(
true);
733 $this->unit_cat_form->addItem(
$title);
736 $this->unit_cat_form->setTitle($this->lng->txt(
'new_category'));
737 $this->unit_cat_form->setFormAction($this->ctrl->getFormAction($this,
'addCategory'));
738 $this->unit_cat_form->addCommandButton(
'addCategory', $this->lng->txt(
'save'));
740 $this->ctrl->setParameter($this,
'category_id', $cat->getId());
741 $this->unit_cat_form->addCommandButton(
'saveCategory', $this->lng->txt(
'save'));
742 $this->unit_cat_form->setFormAction($this->ctrl->getFormAction($this,
'saveCategory'));
743 $this->unit_cat_form->setTitle(sprintf($this->lng->txt(
'selected_category'), $cat->getDisplayString()));
761 if ($this->unit_cat_form->checkInput()) {
764 $category->setCategory($this->unit_cat_form->getInput(
'category_name'));
765 $this->
repository->saveNewUnitCategory($category);
766 ilUtil::sendSuccess($this->lng->txt(
'saved_successfully'));
771 $this->unit_cat_form->getItemByPostVar(
'category_name')->setAlert($this->lng->txt($e->getMessage()));
776 $this->unit_cat_form->setValuesByPost();
778 $this->tpl->setContent($this->unit_cat_form->getHtml());
793 $this->tpl->setContent($this->unit_cat_form->getHtml());
809 if ($this->unit_cat_form->checkInput()) {
811 $category->setCategory($this->unit_cat_form->getInput(
'category_name'));
813 ilUtil::sendSuccess($this->lng->txt(
'saved_successfully'));
818 $this->unit_cat_form->getItemByPostVar(
'category_name')->setAlert($this->lng->txt($e->getMessage()));
823 $this->unit_cat_form->setValuesByPost();
825 $this->tpl->setContent($this->unit_cat_form->getHtml());
841 $this->unit_cat_form->setValuesByArray(array(
842 'category_name' => $category->getCategory()
845 $this->tpl->setContent($this->unit_cat_form->getHtml());
getCategoryById($id, $for_CRUD=true)
getUnitCategoryOverviewCommand()
initUnitCategoryForm(assFormulaQuestionUnitCategory $cat=null)
showUnitCategoryModificationForm()
if(!array_key_exists('StateId', $_REQUEST)) $id
Class ilUnitConfigurationRepository.
Class ilUnitConfigurationGUI .
showUnitCategories(array $categories)
catch(Exception $e) $message
confirmDeleteCategories()
This class represents a text property in a property form.
showUnitModificationForm()
addUnit()
Adds a new unit.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
showUnitCategoryCreationForm()
if(empty($password)) $table
Confirmation screen class.