ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilLocalUnitConfigurationGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once 'Modules/TestQuestionPool/classes/class.ilUnitConfigurationGUI.php';
5
10{
11 const REQUEST_PARAM_SUB_CONTEXT_ID = 'question_fi';
12
16 protected function getDefaultCommand()
17 {
18 return 'showLocalUnitCategories';
19 }
20
25 {
26 if ($this->isCRUDContext()) {
27 return 'showLocalUnitCategories';
28 } else {
29 return 'showGlobalUnitCategories';
30 }
31 }
32
36 public function isCRUDContext()
37 {
38 if (!isset($_GET[self::REQUEST_PARAM_SUB_CONTEXT_ID]) || $_GET[self::REQUEST_PARAM_SUB_CONTEXT_ID] == $this->repository->getConsumerId()) {
39 return true;
40 } else {
41 return false;
42 }
43 }
44
48 public function getUniqueId()
49 {
50 $id = $this->repository->getConsumerId();
51 if ($this->isCRUDContext()) {
52 $id .= '_local';
53 } else {
54 $id .= '_global';
55 }
56
57 return $id;
58 }
59
60
64 public function executeCommand()
65 {
69 global $ilHelp;
70
71 $this->ctrl->saveParameter($this, self::REQUEST_PARAM_SUB_CONTEXT_ID);
72
73 $ilHelp->setScreenIdComponent('qpl');
74 parent::executeCommand();
75 }
76
80 protected function handleSubtabs()
81 {
85 global $ilTabs;
86
87 $this->ctrl->setParameter($this, self::REQUEST_PARAM_SUB_CONTEXT_ID, $this->repository->getConsumerId());
88 $ilTabs->addSubTab('view_unit_ctx_local', $this->lng->txt('un_local_units'), $this->ctrl->getLinkTarget($this, 'showLocalUnitCategories'));
89 $this->ctrl->setParameter($this, self::REQUEST_PARAM_SUB_CONTEXT_ID, 0);
90 $ilTabs->addSubTab('view_unit_ctx_global', $this->lng->txt('un_global_units'), $this->ctrl->getLinkTarget($this, 'showGlobalUnitCategories'));
91 $this->ctrl->setParameter($this, self::REQUEST_PARAM_SUB_CONTEXT_ID, '');
92
93 if ($this->isCRUDContext()) {
94 $ilTabs->activateSubTab('view_unit_ctx_local');
95 } else {
96 $ilTabs->activateSubTab('view_unit_ctx_global');
97 }
98 }
99
103 protected function showLocalUnitCategories()
104 {
108 global $ilToolbar;
109
110 $ilToolbar->addButton($this->lng->txt('un_add_category'), $this->ctrl->getLinkTarget($this, 'showUnitCategoryCreationForm'));
111
112 $repo = $this->repository;
113 $categories = array_filter(
114 $this->repository->getAllUnitCategories(),
115 function (assFormulaQuestionUnitCategory $category) use ($repo) {
116 return $category->getQuestionFi() == $repo->getConsumerId() ? true : false;
117 }
118 );
119 $data = array();
120 foreach ($categories as $category) {
124 $data[] = array(
125 'category_id' => $category->getId(),
126 'category' => $category->getDisplayString()
127 );
128 }
129
130 $this->showUnitCategories($data);
131 }
132
136 protected function showUnitCategories(array $categories)
137 {
138 require_once 'Modules/TestQuestionPool/classes/tables/class.ilLocalUnitCategoryTableGUI.php';
140 $table->setData($categories);
141
142 $this->tpl->setContent($table->getHTML());
143 }
144
148 protected function confirmImportGlobalCategory()
149 {
150 if (!isset($_GET['category_id'])) {
151 $this->showGlobalUnitCategories();
152 return;
153 }
154 $_POST['category_ids'] = array($_GET['category_id']);
155
157 }
158
162 protected function confirmImportGlobalCategories()
163 {
164 if (!isset($_POST['category_ids']) || !is_array($_POST['category_ids'])) {
165 $this->showGlobalUnitCategories();
166 return;
167 }
168
169 // @todo: Confirmation Currently not implemented, so forward to import
170 $this->importGlobalCategories();
171 }
172
176 protected function importGlobalCategories()
177 {
178 if ($this->isCRUDContext()) {
179 $this->{$this->getDefaultCommand()}();
180 return;
181 }
182
183 if (!isset($_POST['category_ids']) || !is_array($_POST['category_ids'])) {
184 $this->showGlobalUnitCategories();
185 return;
186 }
187
188 $i = 0;
189 foreach ($_POST['category_ids'] as $category_id) {
190 try {
191 $category = $this->repository->getUnitCategoryById((int) $category_id);
192 } catch (ilException $e) {
193 continue;
194 }
195
196 // Copy admin-category to custom-category (with question_fi)
197 $new_cat_id = $this->repository->copyCategory($category->getId(), $this->repository->getConsumerId());
198
199 // Copy units to custom_category
200 $this->repository->copyUnitsByCategories($category->getId(), $new_cat_id, $this->repository->getConsumerId());
201 ++$i;
202 }
203
204 if ($i) {
205 ilUtil::sendSuccess($this->lng->txt('saved_successfully'), true);
206 }
207
208 $this->ctrl->setParameter($this, 'question_fi', 0);
209 $this->ctrl->redirect($this, 'showLocalUnitCategories');
210 }
211}
$_GET["client_id"]
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
Base class for ILIAS Exception handling.
Class ilLocalUnitCategoryTableGUI.
Class ilLocalUnitConfigurationGUI.
Class ilUnitConfigurationGUI @abstract.
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
$i
Definition: disco.tpl.php:19
if(!array_key_exists('StateId', $_REQUEST)) $id
if(empty($password)) $table
Definition: pwgen.php:24