ILIAS  release_4-4 Revision
All Data Structures Namespaces Files Functions Variables Modules 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  protected $obj_settings;
23  protected $obj_lp;
24 
25  function __construct($a_mode,$a_ref_id)
26  {
27  parent::__construct($a_mode,$a_ref_id);
28 
29  $this->obj_settings = new ilLPObjSettings($this->getObjId());
30 
31  include_once './Services/Object/classes/class.ilObjectLP.php';
32  $this->obj_lp = ilObjectLP::getInstance($this->getObjId());
33  }
34 
38  function &executeCommand()
39  {
40  switch($this->ctrl->getNextClass())
41  {
42  default:
43  $cmd = $this->__getDefaultCommand();
44  $this->$cmd();
45 
46  }
47  return true;
48  }
49 
53  protected function show()
54  {
55  global $ilHelp;
56 
57  $ilHelp->setSubScreenId("trac_settings");
58 
59  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.lp_obj_settings.html','Services/Tracking');
60 
61  $form = $this->initFormSettings();
62  $this->tpl->setVariable('PROP_FORM',$form->getHTML());
63  $this->tpl->setVariable('COLLECTION_TABLE',$this->getTableByMode());
64  }
65 
66 
72  protected function initFormSettings()
73  {
74  include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
75  $form = new ilPropertyFormGUI();
76  $form->setTitle($this->lng->txt('tracking_settings'));
77  $form->setFormAction($this->ctrl->getFormAction($this));
78 
79  // Mode
80  $mod = new ilRadioGroupInputGUI($this->lng->txt('trac_mode'), 'modus');
81  $mod->setRequired(true);
82  $mod->setValue($this->obj_lp->getCurrentMode());
83  $form->addItem($mod);
84 
85  foreach($this->obj_lp->getValidModes() as $mode_key)
86  {
87  $opt = new ilRadioOption(
88  $this->obj_lp->getModeText($mode_key),
89  $mode_key,
90  $this->obj_lp->getModeInfoText($mode_key)
91  );
92  $opt->setValue($mode_key);
93  $mod->addOption($opt);
94 
95  // :TODO: Subitem for visits ?!
96  if($mode_key == ilLPObjSettings::LP_MODE_VISITS)
97  {
98  $vis = new ilNumberInputGUI($this->lng->txt('trac_visits'), 'visits');
99  $vis->setSize(3);
100  $vis->setMaxLength(4);
101  $vis->setInfo(sprintf($this->lng->txt('trac_visits_info'),
103  $vis->setRequired(true);
104  $vis->setValue($this->obj_settings->getVisits());
105  $opt->addSubItem($vis);
106  }
107  }
108 
109  $form->addCommandButton('saveSettings', $this->lng->txt('save'));
110 
111  return $form;
112  }
113 
118  protected function saveSettings()
119  {
120  $form = $this->initFormSettings();
121  if($form->checkInput())
122  {
123  // anything changed?
124 
125  // mode
126  $new_mode = (int)$form->getInput('modus');
127  $old_mode = $this->obj_lp->getCurrentMode();
128  $mode_changed = ($old_mode != $new_mode);
129 
130  // visits
131  $new_visits = null;
132  $visits_changed = null;
133  if($new_mode == ilLPObjSettings::LP_MODE_VISITS)
134  {
135  $new_visits = (int)$form->getInput('visits');
136  $old_visits = $this->obj_settings->getVisits();
137  $visits_changed = ($old_visits != $new_visits);
138  }
139 
140  if($mode_changed)
141  {
142  // delete existing collection
143  $collection = $this->obj_lp->getCollectionInstance();
144  if($collection)
145  {
146  $collection->delete();
147  }
148  }
149 
150  $refresh_lp = ($mode_changed || $visits_changed);
151 
152  // has to be done before LP refresh!
153  $this->obj_lp->resetCaches();
154 
155  $this->obj_settings->setMode($new_mode);
156  $this->obj_settings->setVisits($new_visits);
157  $this->obj_settings->update($refresh_lp);
158 
159  if($mode_changed && $this->obj_lp->getCollectionInstance())
160  {
161  ilUtil::sendInfo($this->lng->txt('trac_edit_collection'), true);
162  }
163  ilUtil::sendSuccess($this->lng->txt('trac_settings_saved'), true);
164  $this->ctrl->redirect($this, 'show');
165  }
166 
167  $form->setValuesByPost();
168  ilUtil::sendFailure($this->lng->txt('err_check_input'));
169 
170  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.lp_obj_settings.html','Services/Tracking');
171  $this->tpl->setVariable('PROP_FORM',$form->getHTML());
172  $this->tpl->setVariable('COLLECTION_TABLE',$this->getTableByMode());
173  }
174 
178  protected function getTableByMode()
179  {
180  $collection = $this->obj_lp->getCollectionInstance();
181  if($collection && $collection->hasSelectableItems())
182  {
183  include_once "Services/Tracking/classes/repository_statistics/class.ilLPCollectionSettingsTableGUI.php";
184  $table = new ilLPCollectionSettingsTableGUI($this, 'show', $this->getRefId(), $this->obj_lp->getCurrentMode());
185  $table->parse($collection);
186  return $table->getHTML();
187  }
188  }
189 
194  protected function assign()
195  {
196  if(!$_POST['item_ids'])
197  {
198  ilUtil::sendFailure($this->lng->txt('select_one'),true);
199  $this->ctrl->redirect($this,'show');
200  }
201  if(count($_POST['item_ids']))
202  {
203  $collection = $this->obj_lp->getCollectionInstance();
204  if($collection && $collection->hasSelectableItems())
205  {
206  $collection->activateEntries($_POST['item_ids']);
207  }
208 
209  // #15045 - has to be done before LP refresh!
210  $this->obj_lp->resetCaches();
211 
212  // refresh learning progress
213  include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
215  }
216  ilUtil::sendSuccess($this->lng->txt('trac_settings_saved'),true);
217  $this->ctrl->redirect($this,'show');
218  }
219 
224  protected function deassign()
225  {
226  if(!$_POST['item_ids'])
227  {
228  ilUtil::sendFailure($this->lng->txt('select_one'),true);
229  $this->ctrl->redirect($this,'show');
230  return false;
231  }
232  if(count($_POST['item_ids']))
233  {
234  $collection = $this->obj_lp->getCollectionInstance();
235  if($collection && $collection->hasSelectableItems())
236  {
237  $collection->deactivateEntries($_POST['item_ids']);
238  }
239 
240  // #15045 - has to be done before LP refresh!
241  $this->obj_lp->resetCaches();
242 
243  // refresh learning progress
244  include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
246  }
247  ilUtil::sendSuccess($this->lng->txt('trac_settings_saved'),true);
248  $this->ctrl->redirect($this,'show');
249  }
250 
254  protected function groupMaterials()
255  {
256  if(!count((array) $_POST['item_ids']))
257  {
258  ilUtil::sendFailure($this->lng->txt('select_one'),true);
259  $this->ctrl->redirect($this,'show');
260  }
261 
262  $collection = $this->obj_lp->getCollectionInstance();
263  if($collection && $collection->hasSelectableItems())
264  {
265  // Assign new grouping id
266  $collection->createNewGrouping((array)$_POST['item_ids']);
267 
268  // refresh learning progress
269  include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
271  }
272 
273  ilUtil::sendSuccess($this->lng->txt('trac_settings_saved'),true);
274  $this->ctrl->redirect($this,'show');
275  }
276 
280  protected function releaseMaterials()
281  {
282  if(!count((array) $_POST['item_ids']))
283  {
284  ilUtil::sendFailure($this->lng->txt('select_one'),true);
285  $this->ctrl->redirect($this,'show');
286  }
287 
288  $collection = $this->obj_lp->getCollectionInstance();
289  if($collection && $collection->hasSelectableItems())
290  {
291  $collection->releaseGrouping((array)$_POST['item_ids']);
292 
293  // refresh learning progress
294  include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
296  }
297 
298  ilUtil::sendSuccess($this->lng->txt('trac_settings_saved'),true);
299  $this->ctrl->redirect($this,'show');
300  }
301 
305  protected function saveObligatoryMaterials()
306  {
307  if(!is_array((array) $_POST['grp']))
308  {
309  ilUtil::sendFailure($this->lng->txt('select_one'),true);
310  $this->ctrl->redirect($this,'show');
311  }
312 
313  try {
314 
315  $collection = $this->obj_lp->getCollectionInstance();
316  if($collection && $collection->hasSelectableItems())
317  {
318  $collection->saveObligatoryMaterials((array)$_POST['grp']);
319 
320  // refresh learning progress
321  include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
323  }
324 
325  ilUtil::sendSuccess($this->lng->txt('settings_saved'), true);
326  $this->ctrl->redirect($this,'show');
327  }
328  catch(UnexpectedValueException $e) {
329  ilUtil::sendFailure($this->lng->txt('trac_grouped_material_obligatory_err'), true);
330  ilUtil::sendInfo($this->lng->txt('err_check_input'),true);
331  $this->ctrl->redirect($this,'show');
332  }
333  }
334 
335  protected function updateTLT()
336  {
337  include_once "Services/MetaData/classes/class.ilMD.php";
338  foreach($_POST['tlt'] as $item_id => $item)
339  {
340  $md_obj = new ilMD($this->getObjId(),$item_id,'st');
341  if(!is_object($md_section = $md_obj->getEducational()))
342  {
343  $md_section = $md_obj->addEducational();
344  $md_section->save();
345  }
346  $md_section->setPhysicalTypicalLearningTime((int)$item['mo'],
347  (int)$item['d'],(int)$item['h'],(int)$item['m'],0);
348  $md_section->update();
349  }
350 
351  // refresh learning progress
352  include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
354 
355  ilUtil::sendSuccess($this->lng->txt('settings_saved'), true);
356  $this->ctrl->redirect($this,'show');
357  }
358 }
359 ?>
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
This class represents an option in a radio group.
saveSettings()
Save learning progress settings.
$_POST['username']
Definition: cron.php:12
This class represents a property form user interface.
deassign()
save mterial assignment
show()
Show settings tables.
$cmd
Definition: sahs_server.php:35
Class ilLPListOfSettingsGUI.
initFormSettings()
Init property form.
parse(ilLPCollection $a_collection)
Read and parse items.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
This class represents a property in a property form.
setValue($a_value)
Set Value.
This class represents a number property in a property form.
saveObligatoryMaterials()
Save obligatory state per grouped materials.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
assign()
Save material assignment.
setSize($a_size)
Set Size.
getTableByMode()
Get tables by mode.
_refreshStatus($a_obj_id, $a_users=null)
Set dirty.
static getInstance($a_obj_id)
setRequired($a_required)
Set Required.