ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 
4 require_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  {
28  return 'showLocalUnitCategories';
29  }
30  else
31  {
32  return 'showGlobalUnitCategories';
33  }
34  }
35 
39  public function isCRUDContext()
40  {
41  if(!isset($_GET[self::REQUEST_PARAM_SUB_CONTEXT_ID]) || $_GET[self::REQUEST_PARAM_SUB_CONTEXT_ID] == $this->repository->getConsumerId())
42  {
43  return true;
44  }
45  else
46  {
47  return false;
48  }
49  }
50 
54  public function getUniqueId()
55  {
56  $id = $this->repository->getConsumerId();
57  if($this->isCRUDContext())
58  {
59  $id .= '_local';
60  }
61  else
62  {
63  $id .= '_global';
64  }
65 
66  return $id;
67  }
68 
69 
73  public function executeCommand()
74  {
78  global $ilHelp;
79 
80  $this->ctrl->saveParameter($this, self::REQUEST_PARAM_SUB_CONTEXT_ID);
81 
82  $ilHelp->setScreenIdComponent('qpl');
83  parent::executeCommand();
84  }
85 
89  protected function handleSubtabs()
90  {
94  global $ilTabs;
95 
96  $this->ctrl->setParameter($this, self::REQUEST_PARAM_SUB_CONTEXT_ID, $this->repository->getConsumerId());
97  $ilTabs->addSubTab('view_unit_ctx_local', $this->lng->txt('un_local_units'), $this->ctrl->getLinkTarget($this, 'showLocalUnitCategories'));
98  $this->ctrl->setParameter($this, self::REQUEST_PARAM_SUB_CONTEXT_ID, 0);
99  $ilTabs->addSubTab('view_unit_ctx_global', $this->lng->txt('un_global_units'), $this->ctrl->getLinkTarget($this, 'showGlobalUnitCategories'));
100  $this->ctrl->setParameter($this, self::REQUEST_PARAM_SUB_CONTEXT_ID, '');
101 
102  if($this->isCRUDContext())
103  {
104  $ilTabs->activateSubTab('view_unit_ctx_local');
105  }
106  else
107  {
108  $ilTabs->activateSubTab('view_unit_ctx_global');
109  }
110  }
111 
115  protected function showLocalUnitCategories()
116  {
120  global $ilToolbar;
121 
122  $ilToolbar->addButton($this->lng->txt('un_add_category'), $this->ctrl->getLinkTarget($this, 'showUnitCategoryCreationForm'));
123 
124  $repo = $this->repository;
125  $categories = array_filter(
126  $this->repository->getAllUnitCategories(),
127  function(assFormulaQuestionUnitCategory $category) use ($repo) {
128  return $category->getQuestionFi() == $repo->getConsumerId() ? true : false;
129  }
130  );
131  $data = array();
132  foreach($categories as $category)
133  {
137  $data[] = array(
138  'category_id' => $category->getId(),
139  'category' => $category->getDisplayString()
140  );
141  }
142 
143  $this->showUnitCategories($data);
144  }
145 
149  protected function showUnitCategories(array $categories)
150  {
151  require_once 'Modules/TestQuestionPool/classes/tables/class.ilLocalUnitCategoryTableGUI.php';
152  $table = new ilLocalUnitCategoryTableGUI($this, $this->getUnitCategoryOverviewCommand());
153  $table->setData($categories);
154 
155  $this->tpl->setContent($table->getHTML());
156  }
157 
161  protected function confirmImportGlobalCategory()
162  {
163  if(!isset($_GET['category_id']))
164  {
165  $this->showGlobalUnitCategories();
166  return;
167  }
168  $_POST['category_ids'] = array($_GET['category_id']);
169 
171  }
172 
176  protected function confirmImportGlobalCategories()
177  {
178  if(!isset($_POST['category_ids']) || !is_array($_POST['category_ids']))
179  {
180  $this->showGlobalUnitCategories();
181  return;
182  }
183 
184  // @todo: Confirmation Currently not implemented, so forward to import
185  $this->importGlobalCategories();
186  }
187 
191  protected function importGlobalCategories()
192  {
193  if($this->isCRUDContext())
194  {
195  $this->{$this->getDefaultCommand()}();
196  return;
197  }
198 
199  if(!isset($_POST['category_ids']) || !is_array($_POST['category_ids']))
200  {
201  $this->showGlobalUnitCategories();
202  return;
203  }
204 
205  $i = 0;
206  foreach($_POST['category_ids'] as $category_id)
207  {
208  try
209  {
210  $category = $this->repository->getUnitCategoryById((int)$category_id);
211  }
212  catch(ilException $e)
213  {
214  continue;
215  }
216 
217  // Copy admin-category to custom-category (with question_fi)
218  $new_cat_id = $this->repository->copyCategory($category->getId(), $this->repository->getConsumerId());
219 
220  // Copy units to custom_category
221  $this->repository->copyUnitsByCategories($category->getId(), $new_cat_id, $this->repository->getConsumerId());
222  ++$i;
223  }
224 
225  if($i)
226  {
227  ilUtil::sendSuccess($this->lng->txt('saved_successfully'), true);
228  }
229 
230  $this->ctrl->setParameter($this, 'question_fi', 0);
231  $this->ctrl->redirect($this, 'showLocalUnitCategories');
232  }
233 }
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
Base class for ILIAS Exception handling.
$_GET["client_id"]
Class ilUnitConfigurationGUI .
Create styles array
The data for the language used.
Class ilLocalUnitConfigurationGUI.
Class ilLocalUnitCategoryTableGUI.
$_POST["username"]