ILIAS  release_4-4 Revision
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  {
75  $this->ctrl->saveParameter($this, self::REQUEST_PARAM_SUB_CONTEXT_ID);
76 
77  parent::executeCommand();
78  }
79 
83  protected function handleSubtabs()
84  {
88  global $ilTabs;
89 
90  $this->ctrl->setParameter($this, self::REQUEST_PARAM_SUB_CONTEXT_ID, $this->repository->getConsumerId());
91  $ilTabs->addSubTab('view_unit_ctx_local', $this->lng->txt('un_local_units'), $this->ctrl->getLinkTarget($this, 'showLocalUnitCategories'));
92  $this->ctrl->setParameter($this, self::REQUEST_PARAM_SUB_CONTEXT_ID, 0);
93  $ilTabs->addSubTab('view_unit_ctx_global', $this->lng->txt('un_global_units'), $this->ctrl->getLinkTarget($this, 'showGlobalUnitCategories'));
94  $this->ctrl->setParameter($this, self::REQUEST_PARAM_SUB_CONTEXT_ID, '');
95 
96  if($this->isCRUDContext())
97  {
98  $ilTabs->activateSubTab('view_unit_ctx_local');
99  }
100  else
101  {
102  $ilTabs->activateSubTab('view_unit_ctx_global');
103  }
104  }
105 
109  protected function showLocalUnitCategories()
110  {
114  global $ilToolbar;
115 
116  $ilToolbar->addButton($this->lng->txt('un_add_category'), $this->ctrl->getLinkTarget($this, 'showUnitCategoryCreationForm'));
117 
118  $repo = $this->repository;
119  $categories = array_filter(
120  $this->repository->getAllUnitCategories(),
121  function(assFormulaQuestionUnitCategory $category) use ($repo) {
122  return $category->getQuestionFi() == $repo->getConsumerId() ? true : false;
123  }
124  );
125  $data = array();
126  foreach($categories as $category)
127  {
131  $data[] = array(
132  'category_id' => $category->getId(),
133  'category' => $category->getDisplayString()
134  );
135  }
136 
137  $this->showUnitCategories($data);
138  }
139 
143  protected function showUnitCategories(array $categories)
144  {
145  require_once 'Modules/TestQuestionPool/classes/tables/class.ilLocalUnitCategoryTableGUI.php';
146  $table = new ilLocalUnitCategoryTableGUI($this, $this->getUnitCategoryOverviewCommand());
147  $table->setData($categories);
148 
149  $this->tpl->setContent($table->getHTML());
150  }
151 
155  protected function confirmImportGlobalCategory()
156  {
157  if(!isset($_GET['category_id']))
158  {
159  $this->showGlobalUnitCategories();
160  return;
161  }
162  $_POST['category_ids'] = array($_GET['category_id']);
163 
165  }
166 
170  protected function confirmImportGlobalCategories()
171  {
172  if(!isset($_POST['category_ids']) || !is_array($_POST['category_ids']))
173  {
174  $this->showGlobalUnitCategories();
175  return;
176  }
177 
178  // @todo: Confirmation Currently not implemented, so forward to import
179  $this->importGlobalCategories();
180  }
181 
185  protected function importGlobalCategories()
186  {
187  if($this->isCRUDContext())
188  {
189  $this->{$this->getDefaultCommand()}();
190  return;
191  }
192 
193  if(!isset($_POST['category_ids']) || !is_array($_POST['category_ids']))
194  {
195  $this->showGlobalUnitCategories();
196  return;
197  }
198 
199  $i = 0;
200  foreach($_POST['category_ids'] as $category_id)
201  {
202  try
203  {
204  $category = $this->repository->getUnitCategoryById((int)$category_id);
205  }
206  catch(ilException $e)
207  {
208  continue;
209  }
210 
211  // Copy admin-category to custom-category (with question_fi)
212  $new_cat_id = $this->repository->copyCategory($category->getId(), $this->repository->getConsumerId());
213 
214  // Copy units to custom_category
215  $this->repository->copyUnitsByCategories($category->getId(), $new_cat_id, $this->repository->getConsumerId());
216  ++$i;
217  }
218 
219  if($i)
220  {
221  ilUtil::sendSuccess($this->lng->txt('saved_successfully'), true);
222  }
223 
224  $this->ctrl->setParameter($this, 'question_fi', 0);
225  $this->ctrl->redirect($this, 'showLocalUnitCategories');
226  }
227 }
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
Base class for ILIAS Exception handling.
$_POST['username']
Definition: cron.php:12
$_GET["client_id"]
Class ilUnitConfigurationGUI .
while($lm_rec=$ilDB->fetchAssoc($lm_set)) $data
Class ilLocalUnitConfigurationGUI.
Class ilLocalUnitCategoryTableGUI.