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()) {
125 $this->ctrl->saveParameter($this,
'category_id');
128 $nextClass = $this->ctrl->getNextClass($this);
129 switch ($nextClass) {
144 if (!isset(
$_GET[
'unit_id'])) {
145 $this->showUnitsOfCategory();
159 $this->showUnitsOfCategory();
163 if (!isset(
$_POST[
'unit_ids']) || !is_array(
$_POST[
'unit_ids'])) {
164 $this->showUnitsOfCategory();
168 require_once
'Services/Utilities/classes/class.ilConfirmationGUI.php';
170 $confirmation->setFormAction($this->ctrl->getFormAction($this,
'deleteUnits'));
171 $confirmation->setConfirm($this->lng->txt(
'confirm'),
'deleteUnits');
172 $confirmation->setCancel($this->lng->txt(
'cancel'),
'showUnitsOfCategory');
176 foreach (
$_POST[
'unit_ids'] as $unit_id) {
178 $unit = $this->repository->getUnit((
int) $unit_id);
183 if ($check_result = $this->repository->checkDeleteUnit($unit->getId())) {
184 $errors[] = $unit->getDisplayString() .
' - ' . $check_result;
188 $confirmation->addItem(
'unit_ids[]', $unit->getId(), $unit->getDisplayString());
198 $error_message = array_map(
function (
$message) {
201 if ($num_errors == 1) {
202 ilUtil::sendFailure($this->lng->txt(
'un_unit_deletion_errors_f_s') .
'<ul>' . implode(
'', $error_message) .
'<ul>');
204 ilUtil::sendFailure($this->lng->txt(
'un_unit_deletion_errors_f') .
'<ul>' . implode(
'', $error_message) .
'<ul>');
208 if ($num_to_confirm) {
209 if ($num_to_confirm == 1) {
210 $confirmation->setHeaderText($this->lng->txt(
'un_sure_delete_units_s'));
212 $confirmation->setHeaderText($this->lng->txt(
'un_sure_delete_units'));
215 $this->tpl->setContent($confirmation->getHTML());
217 $this->showUnitsOfCategory();
227 $this->showUnitsOfCategory();
231 if (!is_array(
$_POST[
'unit_ids']) || !
$_POST[
'unit_ids']) {
232 $this->showUnitsOfCategory();
238 foreach (
$_POST[
'unit_ids'] as $unit_id) {
240 $unit = $this->repository->getUnit((
int) $unit_id);
245 $check_result = $this->repository->deleteUnit($unit->getId());
246 if (!is_null($check_result)) {
247 $errors[] = $unit->getDisplayString() .
' - ' . $check_result;
260 $error_message = array_map(
function (
$message) {
263 if ($num_errors == 1) {
264 ilUtil::sendFailure($this->lng->txt(
'un_unit_deletion_errors_p_s') .
'<ul>' . implode(
'', $error_message) .
'<ul>');
266 ilUtil::sendFailure($this->lng->txt(
'un_unit_deletion_errors_p') .
'<ul>' . implode(
'', $error_message) .
'<ul>');
271 if ($num_deleted == 1) {
278 $this->showUnitsOfCategory();
287 $this->showUnitsOfCategory();
291 if (!isset(
$_POST[
'sequence']) || !is_array(
$_POST[
'sequence'])) {
292 $this->showUnitsOfCategory();
296 foreach (
$_POST[
'sequence'] as
$id => $sequence) {
297 $sorting_value = str_replace(
',',
'.', $sequence);
298 $sorting_value = (int) $sorting_value * 100;
299 $this->repository->saveUnitOrder((
int)
$id, $sorting_value);
303 $this->showUnitsOfCategory();
313 $this->showUnitsOfCategory();
318 $unit = $this->repository->getUnit((
int) $_GET[
'unit_id']);
320 if ($this->repository->isUnitInUse($unit->getId())) {
325 $this->initUnitForm($category, $unit);
326 if ($this->unit_form->checkInput()) {
327 $unit->setUnit($this->unit_form->getInput(
'unit_title'));
328 $unit->setFactor((
float) $this->unit_form->getInput(
'factor'));
329 $unit->setBaseUnit((
int) $this->unit_form->getInput(
'base_unit') != $unit->getId() ? (int) $this->unit_form->getInput(
'base_unit') : 0);
330 $unit->setCategory($category->getId());
331 $this->repository->saveUnit($unit);
333 $this->showUnitsOfCategory();
336 $this->unit_form->setValuesByPost();
339 $this->tpl->setContent($this->unit_form->getHtml());
348 $this->showUnitsOfCategory();
353 $unit = $this->repository->getUnit((
int) $_GET[
'unit_id']);
355 $this->initUnitForm($category, $unit);
356 $this->unit_form->setValuesByArray(
array(
357 'factor' => $unit->getFactor(),
358 'unit_title' => $unit->getUnit(),
359 'base_unit' => ($unit->getBaseUnit() != $unit->getId() ? $unit->getBaseUnit() : 0)
362 $this->tpl->setContent($this->unit_form->getHtml());
371 $this->showUnitsOfCategory();
377 $this->initUnitForm($category);
378 if ($this->unit_form->checkInput()) {
380 $unit->setUnit($this->unit_form->getInput(
'unit_title'));
381 $unit->setCategory($category->getId());
383 $this->repository->createNewUnit($unit);
385 $unit->setBaseUnit((
int) $this->unit_form->getInput(
'base_unit'));
386 $unit->setFactor((
float) $this->unit_form->getInput(
'factor'));
388 $this->repository->saveUnit($unit);
391 $this->showUnitsOfCategory();
395 $this->unit_form->setValuesByPost();
397 $this->tpl->setContent($this->unit_form->getHtml());
406 $this->showUnitsOfCategory();
412 $this->initUnitForm($category);
413 $this->unit_form->setValuesByArray(
array(
415 'unit_title' => $this->lng->txt(
'unit_placeholder')
418 $this->tpl->setContent($this->unit_form->getHtml());
432 $unit_in_use =
false;
437 $this->unit_form =
new ilPropertyFormGUI();
440 $title->setDisabled($unit_in_use);
441 $title->setRequired(
true);
442 $this->unit_form->addItem(
$title);
445 $items = $this->repository->getCategorizedUnits();
448 $new_category =
false;
449 foreach ((
array) $items as $item) {
452 $unit->
getId() == $item->getId()
461 if ($category_name != $item->getDisplayString()) {
462 $new_category =
true;
463 $category_name = $item->getDisplayString();
467 $options[$item->getId()] = $item->getDisplayString() . ($new_category ?
' (' . $category_name .
')' :
'');
468 $new_category =
false;
470 $baseunit->setDisabled($unit_in_use);
471 $baseunit->setOptions(
array(0 => $this->lng->txt(
'no_selection')) +
$options);
472 $this->unit_form->addItem($baseunit);
477 $factor->setMinValue(0);
478 $factor->allowDecimals(
true);
479 $factor->setDisabled($unit_in_use);
480 $this->unit_form->addItem($factor);
482 if (null === $unit) {
483 $this->unit_form->setTitle($this->lng->txt(
'new_unit'));
484 $this->unit_form->setFormAction($this->ctrl->getFormAction($this,
'addUnit'));
485 $this->unit_form->addCommandButton(
'addUnit', $this->lng->txt(
'save'));
487 $this->ctrl->setParameter($this,
'unit_id', $unit->getId());
489 $this->unit_form->setFormAction($this->ctrl->getFormAction($this,
'showUnitsOfCategory'));
491 $this->unit_form->addCommandButton(
'saveUnit', $this->lng->txt(
'save'));
492 $this->unit_form->setFormAction($this->ctrl->getFormAction($this,
'saveUnit'));
494 $this->unit_form->setTitle(sprintf($this->lng->txt(
'un_sel_cat_sel_unit'), $category->getDisplayString(), $unit->getDisplayString()));
497 $this->unit_form->addCommandButton(
'showUnitsOfCategory', $this->lng->txt(
'cancel'));
504 protected function showUnitsOfCategory()
513 $this->tpl->addJavaScript(
"./Services/JavaScript/js/Basic.js");
514 $this->tpl->addJavaScript(
"./Services/Form/js/Form.js");
515 $this->lng->loadLanguageModule(
'form');
517 require_once
'Modules/TestQuestionPool/classes/tables/class.ilUnitTableGUI.php';
520 $ilToolbar->addButton($this->lng->txt(
'un_add_unit'), $this->ctrl->getLinkTarget($this,
'showUnitCreationForm'));
523 $units = $this->repository->loadUnitsForCategory($category->getId());
525 foreach ($units as $unit) {
530 'unit_id' => $unit->getId(),
531 'unit' => $unit->getUnit(),
532 'baseunit' => $unit->getBaseunitTitle(),
533 'baseunit_id' => $unit->getBaseUnit(),
534 'factor' => $unit->getFactor(),
535 'sequence' => $unit->getSequence(),
540 $this->tpl->setContent(
$table->getHTML());
546 protected function showGlobalUnitCategories()
548 $categories = array_filter(
549 $this->repository->getAllUnitCategories(),
551 return !$category->getQuestionFi() ? true :
false;
555 foreach ($categories as $category) {
560 'category_id' => $category->getId(),
561 'category' => $category->getDisplayString()
573 if (!isset(
$_GET[
'category_id'])) {
592 if (!isset(
$_POST[
'category_ids']) || !is_array(
$_POST[
'category_ids'])) {
597 require_once
'Services/Utilities/classes/class.ilConfirmationGUI.php';
599 $confirmation->setFormAction($this->ctrl->getFormAction($this,
'deleteCategories'));
600 $confirmation->setConfirm($this->lng->txt(
'confirm'),
'deleteCategories');
605 foreach (
$_POST[
'category_ids'] as $category_id) {
607 $category = $this->repository->getUnitCategoryById((
int) $category_id);
612 if (!$this->repository->isCRUDAllowed((
int) $category_id)) {
613 $errors[] = $category->getDisplayString() .
' - ' . $this->lng->txt(
'change_adm_categories_not_allowed');
617 $possible_error = $this->repository->checkDeleteCategory($category_id);
618 if (strlen($possible_error)) {
619 $errors[] = $category->getDisplayString() .
' - ' . $possible_error;
623 $confirmation->addItem(
'category_ids[]', $category->getId(), $category->getDisplayString());
630 $error_message = array_map(
function (
$message) {
633 if ($num_errors == 1) {
634 ilUtil::sendFailure($this->lng->txt(
'un_cat_deletion_errors_f_s') .
'<ul>' . implode(
'', $error_message) .
'<ul>');
636 ilUtil::sendFailure($this->lng->txt(
'un_cat_deletion_errors_f') .
'<ul>' . implode(
'', $error_message) .
'<ul>');
640 if ($num_to_confirm) {
641 if ($num_to_confirm == 1) {
642 $confirmation->setHeaderText($this->lng->txt(
'un_sure_delete_categories_s'));
644 $confirmation->setHeaderText($this->lng->txt(
'un_sure_delete_categories'));
647 $this->tpl->setContent($confirmation->getHTML());
663 if (!is_array(
$_POST[
'category_ids']) || !
$_POST[
'category_ids']) {
670 foreach (
$_POST[
'category_ids'] as $category_id) {
672 $category = $this->repository->getUnitCategoryById((
int) $category_id);
677 if (!$this->repository->isCRUDAllowed((
int) $category_id)) {
678 $errors[] = $category->getDisplayString() .
' - ' . $this->lng->txt(
'change_adm_categories_not_allowed');
682 $possible_error = $this->repository->deleteCategory($category_id);
683 if (strlen($possible_error)) {
684 $errors[] = $category->getDisplayString() .
' - ' . $possible_error;
694 $error_message = array_map(
function (
$message) {
697 if ($num_errors == 1) {
698 ilUtil::sendFailure($this->lng->txt(
'un_cat_deletion_errors_p_s') .
'<ul>' . implode(
'', $error_message) .
'<ul>');
700 ilUtil::sendFailure($this->lng->txt(
'un_cat_deletion_errors_p') .
'<ul>' . implode(
'', $error_message) .
'<ul>');
705 if ($num_deleted == 1) {
725 $this->unit_cat_form =
new ilPropertyFormGUI();
728 $title->setRequired(
true);
729 $this->unit_cat_form->addItem(
$title);
732 $this->unit_cat_form->setTitle($this->lng->txt(
'new_category'));
733 $this->unit_cat_form->setFormAction($this->ctrl->getFormAction($this,
'addCategory'));
734 $this->unit_cat_form->addCommandButton(
'addCategory', $this->lng->txt(
'save'));
736 $this->ctrl->setParameter($this,
'category_id', $cat->getId());
737 $this->unit_cat_form->addCommandButton(
'saveCategory', $this->lng->txt(
'save'));
738 $this->unit_cat_form->setFormAction($this->ctrl->getFormAction($this,
'saveCategory'));
739 $this->unit_cat_form->setTitle(sprintf($this->lng->txt(
'selected_category'), $cat->getDisplayString()));
757 if ($this->unit_cat_form->checkInput()) {
760 $category->setCategory($this->unit_cat_form->getInput(
'category_name'));
761 $this->repository->saveNewUnitCategory($category);
767 $this->unit_cat_form->getItemByPostVar(
'category_name')->setAlert($this->lng->txt($e->getMessage()));
772 $this->unit_cat_form->setValuesByPost();
774 $this->tpl->setContent($this->unit_cat_form->getHtml());
789 $this->tpl->setContent($this->unit_cat_form->getHtml());
805 if ($this->unit_cat_form->checkInput()) {
807 $category->setCategory($this->unit_cat_form->getInput(
'category_name'));
808 $this->repository->saveCategory($category);
814 $this->unit_cat_form->getItemByPostVar(
'category_name')->setAlert($this->lng->txt($e->getMessage()));
819 $this->unit_cat_form->setValuesByPost();
821 $this->tpl->setContent($this->unit_cat_form->getHtml());
837 $this->unit_cat_form->setValuesByArray(
array(
838 'category_name' => $category->getCategory()
841 $this->tpl->setContent($this->unit_cat_form->getHtml());
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
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.
Create styles array
The data for the language used.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
showUnitCategoryCreationForm()
if(empty($password)) $table
if(!isset($_REQUEST['ReturnTo'])) if(!isset($_REQUEST['AuthId'])) $options
Confirmation screen class.