ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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  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 $DIC;
70  $ilHelp = $DIC['ilHelp'];
71 
72  $this->ctrl->saveParameter($this, self::REQUEST_PARAM_SUB_CONTEXT_ID);
73 
74  $ilHelp->setScreenIdComponent('qpl');
75  parent::executeCommand();
76  }
77 
81  protected function handleSubtabs()
82  {
86  global $DIC;
87  $ilTabs = $DIC['ilTabs'];
88 
89  $this->ctrl->setParameter($this, self::REQUEST_PARAM_SUB_CONTEXT_ID, $this->repository->getConsumerId());
90  $ilTabs->addSubTab('view_unit_ctx_local', $this->lng->txt('un_local_units'), $this->ctrl->getLinkTarget($this, 'showLocalUnitCategories'));
91  $this->ctrl->setParameter($this, self::REQUEST_PARAM_SUB_CONTEXT_ID, 0);
92  $ilTabs->addSubTab('view_unit_ctx_global', $this->lng->txt('un_global_units'), $this->ctrl->getLinkTarget($this, 'showGlobalUnitCategories'));
93  $this->ctrl->setParameter($this, self::REQUEST_PARAM_SUB_CONTEXT_ID, '');
94 
95  if ($this->isCRUDContext()) {
96  $ilTabs->activateSubTab('view_unit_ctx_local');
97  } else {
98  $ilTabs->activateSubTab('view_unit_ctx_global');
99  }
100  }
101 
105  protected function showLocalUnitCategories()
106  {
110  global $DIC;
111  $ilToolbar = $DIC['ilToolbar'];
112 
113  $ilToolbar->addButton($this->lng->txt('un_add_category'), $this->ctrl->getLinkTarget($this, 'showUnitCategoryCreationForm'));
114 
115  $repo = $this->repository;
116  $categories = array_filter(
117  $this->repository->getAllUnitCategories(),
118  function (assFormulaQuestionUnitCategory $category) use ($repo) {
119  return $category->getQuestionFi() == $repo->getConsumerId() ? true : false;
120  }
121  );
122  $data = array();
123  foreach ($categories as $category) {
127  $data[] = array(
128  'category_id' => $category->getId(),
129  'category' => $category->getDisplayString()
130  );
131  }
132 
133  $this->showUnitCategories($data);
134  }
135 
139  protected function showUnitCategories(array $categories)
140  {
141  require_once 'Modules/TestQuestionPool/classes/tables/class.ilLocalUnitCategoryTableGUI.php';
143  $table->setData($categories);
144 
145  $this->tpl->setContent($table->getHTML());
146  }
147 
151  protected function confirmImportGlobalCategory()
152  {
153  if (!isset($_GET['category_id'])) {
154  $this->showGlobalUnitCategories();
155  return;
156  }
157  $_POST['category_ids'] = array($_GET['category_id']);
158 
160  }
161 
165  protected function confirmImportGlobalCategories()
166  {
167  if (!isset($_POST['category_ids']) || !is_array($_POST['category_ids'])) {
168  $this->showGlobalUnitCategories();
169  return;
170  }
171 
172  // @todo: Confirmation Currently not implemented, so forward to import
173  $this->importGlobalCategories();
174  }
175 
179  protected function importGlobalCategories()
180  {
181  if ($this->isCRUDContext()) {
182  $this->{$this->getDefaultCommand()}();
183  return;
184  }
185 
186  if (!isset($_POST['category_ids']) || !is_array($_POST['category_ids'])) {
187  $this->showGlobalUnitCategories();
188  return;
189  }
190 
191  $i = 0;
192  foreach ($_POST['category_ids'] as $category_id) {
193  try {
194  $category = $this->repository->getUnitCategoryById((int) $category_id);
195  } catch (ilException $e) {
196  continue;
197  }
198 
199  // Copy admin-category to custom-category (with question_fi)
200  $new_cat_id = $this->repository->copyCategory($category->getId(), $this->repository->getConsumerId());
201 
202  // Copy units to custom_category
203  $this->repository->copyUnitsByCategories($category->getId(), $new_cat_id, $this->repository->getConsumerId());
204  ++$i;
205  }
206 
207  if ($i) {
208  ilUtil::sendSuccess($this->lng->txt('saved_successfully'), true);
209  }
210 
211  $this->ctrl->setParameter($this, 'question_fi', 0);
212  $this->ctrl->redirect($this, 'showLocalUnitCategories');
213  }
214 }
global $DIC
Definition: saml.php:7
$_GET["client_id"]
if(!array_key_exists('StateId', $_REQUEST)) $id
Class ilUnitConfigurationGUI .
repository()
Definition: repository.php:5
$i
Definition: disco.tpl.php:19
Class ilLocalUnitConfigurationGUI.
if(empty($password)) $table
Definition: pwgen.php:24
Class ilLocalUnitCategoryTableGUI.
$_POST["username"]
$data
Definition: bench.php:6