ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilLPListOfSettingsGUI.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 include_once './Services/Tracking/classes/class.ilLearningProgressBaseGUI.php';
6 include_once './Services/Tracking/classes/class.ilLPObjSettings.php';
7 
21 {
22  function ilLPListOfSettingsGUI($a_mode,$a_ref_id)
23  {
24  parent::ilLearningProgressBaseGUI($a_mode,$a_ref_id);
25 
26  $this->obj_settings = new ilLPObjSettings($this->getObjId());
27  }
28 
32  function &executeCommand()
33  {
34  switch($this->ctrl->getNextClass())
35  {
36  default:
37  $cmd = $this->__getDefaultCommand();
38  $this->$cmd();
39 
40  }
41  return true;
42  }
43 
47  protected function show()
48  {
49  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.lp_obj_settings.html','Services/Tracking');
50 
51  $form = $this->initFormSettings();
52  $this->tpl->setVariable('PROP_FORM',$form->getHTML());
53  $this->tpl->setVariable('COLLECTION_TABLE',$this->getTableByMode());
54  }
55 
56 
62  protected function initFormSettings()
63  {
64  include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
65  $form = new ilPropertyFormGUI();
66  $form->setTitle($this->lng->txt('tracking_settings'));
67  $form->setFormAction($this->ctrl->getFormAction($this));
68 
69  // Mode
70  $mod = new ilRadioGroupInputGUI($this->lng->txt('trac_mode'), 'modus');
71  $mod->setRequired(true);
72  $mod->setValue($this->obj_settings->getMode());
73  $form->addItem($mod);
74 
75  foreach($this->obj_settings->getValidModes() as $mode_key => $mode_name)
76  {
77  $opt = new ilRadioOption(
78  $mode_name,
79  $mode_key,
81  );
82  $opt->setValue($mode_key);
83  $mod->addOption($opt);
84 
85  // Subitem for vistits
86  if($mode_key == LP_MODE_VISITS)
87  {
88  $vis = new ilNumberInputGUI($this->lng->txt('trac_visits'), 'visits');
89  $vis->setSize(3);
90  $vis->setMaxLength(4);
91  $vis->setInfo(sprintf($this->lng->txt('trac_visits_info'),
93  $vis->setRequired(true);
94  $vis->setValue($this->obj_settings->getVisits());
95  $opt->addSubItem($vis);
96  }
97  }
98 
99  /*
100  // Info Active
101  $act = new ilCustomInputGUI($this->lng->txt('trac_activated'), '');
102  $img = new ilTemplate('tpl.obj_settings_img_row.html',true,true,'Services/Tracking');
103  $img->setVariable("IMG_SRC",
104  $activated = ilObjUserTracking::_enabledLearningProgress()
105  ? ilUtil::getImagePath('icon_ok.png')
106  : ilUtil::getImagePath('icon_not_ok.png')
107  );
108  $act->setHTML($img->get());
109  $form->addItem($act);
110 
111  // Info Anonymized
112  $ano = new ilCustomInputGUI($this->lng->txt('trac_anonymized'), '');
113  $img = new ilTemplate('tpl.obj_settings_img_row.html',true,true,'Services/Tracking');
114  $img->setVariable("IMG_SRC",
115  $anonymized = !ilObjUserTracking::_enabledUserRelatedData()
116  ? ilUtil::getImagePath('icon_ok.png')
117  : ilUtil::getImagePath('icon_not_ok.png')
118  );
119  $ano->setHTML($img->get());
120  $form->addItem($ano);
121  */
122 
123  $form->addCommandButton('saveSettings', $this->lng->txt('save'));
124 
125  return $form;
126  }
127 
132  protected function saveSettings()
133  {
134  $form = $this->initFormSettings();
135  if($form->checkInput())
136  {
137  $this->obj_settings->setMode((int) $form->getInput('modus'));
138  $this->obj_settings->setVisits($form->getInput('visits'));
139  $this->obj_settings->update();
140 
141  if($this->obj_settings->getMode() == LP_MODE_COLLECTION)
142  {
143  ilUtil::sendInfo($this->lng->txt('trac_edit_collection'),true);
144  }
145  ilUtil::sendSuccess($this->lng->txt('trac_settings_saved'),true);
146  $this->ctrl->redirect($this,'show');
147  }
148 
149  $form->setValuesByPost();
150  ilUtil::sendFailure($this->lng->txt('err_check_input'));
151 
152  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.lp_obj_settings.html','Services/Tracking');
153  $this->tpl->setVariable('PROP_FORM',$form->getHTML());
154  $this->tpl->setVariable('COLLECTION_TABLE',$this->getTableByMode());
155 
156  return;
157  }
158 
162  protected function getTableByMode()
163  {
164  include_once './Services/Tracking/classes/class.ilLPCollectionSettingsTableGUI.php';
165  switch($this->obj_settings->getMode())
166  {
167  case LP_MODE_COLLECTION:
169  case LP_MODE_SCORM:
170  $table = new ilLPCollectionSettingsTableGUI($this->getRefId(),$this,'show');
171  $table->setMode($this->obj_settings->getMode());
172  $table->parse();
173  return $table->getHTML();
174 
175 
176  default:
177  return '';
178  }
179  }
180 
181 
186  protected function assign()
187  {
188  if(!$_POST['item_ids'])
189  {
190  ilUtil::sendFailure($this->lng->txt('select_one'),true);
191  $this->ctrl->redirect($this,'show');
192  }
193  if(count($_POST['item_ids']))
194  {
195  include_once 'Services/Tracking/classes/class.ilLPCollections.php';
196  ilLPCollections::activate($this->getObjId(), $_POST['item_ids']);
197 
198  // refresh learning progress
199  include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
201  }
202  ilUtil::sendSuccess($this->lng->txt('trac_settings_saved'),true);
203  $this->ctrl->redirect($this,'show');
204  }
205 
210  protected function deassign()
211  {
212  if(!$_POST['item_ids'])
213  {
214  ilUtil::sendFailure($this->lng->txt('select_one'),true);
215  $this->ctrl->redirect($this,'show');
216  return false;
217  }
218  if(count($_POST['item_ids']))
219  {
220  include_once 'Services/Tracking/classes/class.ilLPCollections.php';
221  ilLPCollections::deactivate($this->getObjId(),$_POST['item_ids']);
222 
223  // refresh learning progress
224  include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
226  }
227  ilUtil::sendSuccess($this->lng->txt('trac_settings_saved'),true);
228  $this->ctrl->redirect($this,'show');
229  }
230 
234  protected function groupMaterials()
235  {
236  if(!count((array) $_POST['item_ids']))
237  {
238  ilUtil::sendFailure($this->lng->txt('select_one'),true);
239  $this->ctrl->redirect($this,'show');
240  }
241 
242  // Assign new grouping id
243  include_once './Services/Tracking/classes/class.ilLPCollections.php';
244  ilLPCollections::createNewGrouping($this->getObjId(),(array) $_POST['item_ids']);
245 
246  // refresh learning progress
247  include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
249 
250  ilUtil::sendSuccess($this->lng->txt('trac_settings_saved'),true);
251  $this->ctrl->redirect($this,'show');
252  }
253 
257  protected function releaseMaterials()
258  {
259  if(!count((array) $_POST['item_ids']))
260  {
261  ilUtil::sendFailure($this->lng->txt('select_one'),true);
262  $this->ctrl->redirect($this,'show');
263  }
264 
265  include_once './Services/Tracking/classes/class.ilLPCollections.php';
266  ilLPCollections::releaseGrouping($this->getObjId(), (array) $_POST['item_ids']);
267 
268  // refresh learning progress
269  include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
271 
272  ilUtil::sendSuccess($this->lng->txt('trac_settings_saved'),true);
273  $this->ctrl->redirect($this,'show');
274  }
275 
279  protected function saveObligatoryMaterials()
280  {
281  if(!is_array((array) $_POST['grp']))
282  {
283  ilUtil::sendFailure($this->lng->txt('select_one'),true);
284  $this->ctrl->redirect($this,'show');
285  }
286 
287  try {
288  include_once './Services/Tracking/classes/class.ilLPCollections.php';
289  ilLPCollections::saveObligatoryMaterials($this->getObjId(), (array) $_POST['grp']);
290 
291  // refresh learning progress
292  include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
294 
295  ilUtil::sendSuccess($this->lng->txt('settings_saved'), true);
296  $this->ctrl->redirect($this,'show');
297  }
298  catch(UnexpectedValueException $e) {
299  ilUtil::sendFailure($this->lng->txt('trac_grouped_material_obligatory_err'), true);
300  ilUtil::sendInfo($this->lng->txt('err_check_input'),true);
301  $this->ctrl->redirect($this,'show');
302  }
303 
304  }
305 }
306 ?>