ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjectActivationGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
13 {
14  protected $parent_ref_id;
15  protected $item_id;
16  protected $tpl;
17  protected $ctrl;
18  protected $lng;
19 
24  function __construct($a_ref_id,$a_item_id)
25  {
26  global $tpl,$ilCtrl,$lng,$ilErr,$ilTabs;
27 
28  $this->tpl =& $tpl;
29  $this->ctrl =& $ilCtrl;
30  $this->lng =& $lng;
31  $this->lng->loadLanguageModule('crs');
32  $this->err =& $ilErr;
33  $this->tabs_gui =& $ilTabs;
34 
35  $this->parent_ref_id = $a_ref_id;
36  $this->item_id = $a_item_id;
37  $this->ctrl->saveParameter($this,'item_id');
38 
39  }
40 
41  function executeCommand()
42  {
43  global $tpl;
44 
45  $this->__setTabs();
46 
47  $cmd = $this->ctrl->getCmd();
48 
49  // Check if item id is given and valid
50  if(!$this->item_id)
51  {
52  ilUtil::sendFailure($this->lng->txt("crs_no_item_id_given"),true);
53  $this->ctrl->returnToParent($this);
54  }
55 
56  $tpl->getStandardTemplate();
57 
58  switch($this->ctrl->getNextClass($this))
59  {
60  case 'ilconditionhandlergui':
61  // preconditions for single course items
62  include_once './Services/AccessControl/classes/class.ilConditionHandlerGUI.php';
63  $this->ctrl->saveParameter($this,'item_id',$_GET['item_id']);
64  $new_gui =& new ilConditionHandlerGUI($this,(int) $_GET['item_id']);
65  $this->ctrl->forwardCommand($new_gui);
66  $this->tabs_gui->setTabActive('preconditions');
67  break;
68 
69  default:
70  $this->tabs_gui->setTabActive('timings');
71  if(!$cmd)
72  {
73  $cmd = 'edit';
74  }
75  $this->$cmd();
76  $this->tabs_gui->setTabActive('timings');
77  break;
78  }
79 
80  $tpl->show();
81  }
82 
83  function getItemId()
84  {
85  return $this->item_id;
86  }
87 
88  function cancel()
89  {
90  $this->ctrl->setParameterByClass('ilrepositorygui', 'ref_id', $this->parent_ref_id);
91  $this->ctrl->redirectByClass('ilrepositorygui');
92  }
93 
100  public function edit()
101  {
102  global $ilErr,$ilAccess,$tpl;
103 
104  // #19997 - see ilObjectListGUI::insertTimingsCommand()
105  if(!$ilAccess->checkAccess('write','',$this->parent_ref_id) &&
106  !$ilAccess->checkAccess('write','',$this->getItemId()))
107  {
108  $ilErr->raiseError($this->lng->txt('permission_denied'),$ilErr->MESSAGE);
109  }
110 
111  $this->initFormEdit();
112  $this->getValues();
113 
114  $tpl->setContent($this->form->getHTML());
115  }
116 
123  protected function initFormEdit()
124  {
125  global $tree;
126 
127  include_once "Services/Object/classes/class.ilObjectActivation.php";
128 
129  include_once('./Services/Form/classes/class.ilPropertyFormGUI.php');
130  $this->form = new ilPropertyFormGUI();
131  $this->form->setFormAction($this->ctrl->getFormAction($this));
132 
134  $this->form->setTitle($title.': '.$this->lng->txt('crs_edit_timings'));
135 
136  $timings = new ilRadioGroupInputGUI($this->lng->txt('timings'),'timing_type');
137 
138  // opt deactivated
139  $dea = new ilRadioOption($this->lng->txt('crs_timings_disabled'),ilObjectActivation::TIMINGS_DEACTIVATED);
140  $dea->setInfo($this->lng->txt('crs_timings_disabled_info'));
141  $timings->addOption($dea);
142 
143  // Visiblity
144  $vis = new ilRadioOption($this->lng->txt('crs_timings_availability_enabled'),ilObjectActivation::TIMINGS_ACTIVATION);
145  #$vis->setInfo($this->lng->txt('crs_timings_visibility'));
146 
147  $start = new ilDateTimeInputGUI($this->lng->txt('crs_timings_start'),'timing_start');
148  $start->setShowTime(true);
149  #$start->setMinuteStepSize(5);
150  $vis->addSubItem($start);
151 
152  $end = new ilDateTimeInputGUI($this->lng->txt('crs_timings_end'),'timing_end');
153  $end->setShowTime(true);
154  #$end->setMinuteStepSize(5);
155  $vis->addSubItem($end);
156 
157  $isv = new ilCheckboxInputGUI($this->lng->txt('crs_timings_visibility_short'),'visible');
158  $isv->setInfo($this->lng->txt('crs_timings_visibility'));
159  $isv->setValue(1);
160  $vis->addSubItem($isv);
161 
162  $timings->addOption($vis);
163 
164  // Timings
165  $tim = new ilRadioOption($this->lng->txt('crs_timings_presetting'),ilObjectActivation::TIMINGS_PRESETTING);
166  $tim->setInfo($this->lng->txt('crs_item_presetting_info'));
167 
168  $start = new ilDateTimeInputGUI($this->lng->txt('crs_timings_sug_begin'),'sug_start');
169  $tim->addSubItem($start);
170 
171  $end = new ilDateTimeInputGUI($this->lng->txt('crs_timings_sug_end'),'sug_end');
172  $tim->addSubItem($end);
173 
174  if ($tree->checkForParentType($this->parent_ref_id,'crs'))
175  {
176  $cha = new ilCheckboxInputGUI($this->lng->txt('crs_timings_changeable'),'changeable');
177  $tim->addSubItem($cha);
178 
179  $start = new ilDateTimeInputGUI($this->lng->txt('crs_timings_early_begin'),'early_start');
180  $tim->addSubItem($start);
181 
182  $late = new ilDateTimeInputGUI($this->lng->txt('crs_timings_short_limit_start_end'),'late_end');
183  $tim->addSubItem($late);
184  }
185 
186 
187  $timings->addOption($tim);
188 
189  $this->form->addItem($timings);
190 
191  $this->form->addCommandButton('update',$this->lng->txt('save'));
192  $this->form->addCommandButton('cancel',$this->lng->txt('cancel'));
193  }
194 
201  protected function getValues()
202  {
203  global $ilUser;
204 
205  include_once "Services/Object/classes/class.ilObjectActivation.php";
206  $item_data = ilObjectActivation::getItem($this->getItemId());
207 
208  $data = array();
209 
210  if(!$item_data)
211  {
212  $data['timing_type'] = ilObjectActivation::TIMINGS_DEACTIVATED;
213  }
214  else
215  {
216  $data['timing_type'] = $item_data['timing_type'];
217  $data['visible'] = $item_data['visible'];
218  $data['changeable'] = $item_data['changeable'];
219 
220  // #14531
221  if($item_data['timing_start'] < 1)
222  {
223  $item_data['timing_start'] = time();
224  }
225  if($item_data['timing_end'] < 1)
226  {
227  $item_data['timing_end'] = time();
228  }
229 
230  $start = new ilDateTime($item_data['timing_start'],IL_CAL_UNIX);
231  $data['timing_start']['date'] = $start->get(IL_CAL_FKT_DATE,'Y-m-d',$ilUser->getTimeZone());
232  $data['timing_start']['time'] = $start->get(IL_CAL_FKT_DATE,'H:i:s',$ilUser->getTimeZone());
233 
234  $end = new ilDateTime($item_data['timing_end'],IL_CAL_UNIX);
235  $data['timing_end']['date'] = $end->get(IL_CAL_FKT_DATE,'Y-m-d',$ilUser->getTimeZone());
236  $data['timing_end']['time'] = $end->get(IL_CAL_FKT_DATE,'H:i:s',$ilUser->getTimeZone());
237 
238  $start = new ilDate(date('Y-m-d',$item_data['suggestion_start']),IL_CAL_DATE);
239  $data['sug_start']['date'] = $start->get(IL_CAL_FKT_DATE,'Y-m-d','UTC');
240 
241  $end = new ilDate(date('Y-m-d',$item_data['suggestion_end']),IL_CAL_DATE);
242  $data['sug_end']['date'] = $end->get(IL_CAL_FKT_DATE,'Y-m-d','UTC');
243 
244  $start = new ilDate(date('Y-m-d',$item_data['earliest_start']),IL_CAL_DATE);
245  $data['early_start']['date'] = $start->get(IL_CAL_FKT_DATE,'Y-m-d','UTC');
246 
247  $end = new ilDate(date('Y-m-d',$item_data['latest_end']),IL_CAL_DATE);
248  $data['late_end']['date'] = $end->get(IL_CAL_FKT_DATE,'Y-m-d','UTC');
249  }
250 
251  $this->form->setValuesByArray($data);
252  }
253 
260  public function update()
261  {
262  global $ilErr,$ilAccess,$tpl,$ilUser;
263 
264  // #19997 - see ilObjectListGUI::insertTimingsCommand()
265  if(!$ilAccess->checkAccess('write','',$this->parent_ref_id) &&
266  !$ilAccess->checkAccess('write','',$this->getItemId()))
267  {
268  $ilErr->raiseError($this->lng->txt('permission_denied'),$ilErr->MESSAGE);
269  }
270 
271  $this->initFormEdit();
272  if($this->form->checkInput())
273  {
274  include_once "Services/Object/classes/class.ilObjectActivation.php";
275  $activation = new ilObjectActivation();
276 
277  $activation->setTimingType($this->form->getInput('timing_type'));
278 
279  $date = $this->form->getInput('timing_start');
280  $date = new ilDateTime($date['date'].' '.$date['time'],IL_CAL_DATETIME,$ilUser->getTimeZone());
281  $activation->setTimingStart($date->get(IL_CAL_UNIX));
282 
283  $date = $this->form->getInput('timing_end');
284  $date = new ilDateTime($date['date'].' '.$date['time'],IL_CAL_DATETIME,$ilUser->getTimeZone());
285  $activation->setTimingEnd($date->get(IL_CAL_UNIX));
286 
287  $date = $this->form->getInput('sug_start');
288  $date = new ilDate($date['date'],IL_CAL_DATE);
289  $activation->setSuggestionStart($date->get(IL_CAL_UNIX));
290 
291  $date = $this->form->getInput('sug_end');
292  $date = new ilDate($date['date'],IL_CAL_DATE);
293  $activation->setSuggestionEnd($date->get(IL_CAL_UNIX));
294 
295  $date = $this->form->getInput('early_start');
296  $date = new ilDate($date['date'],IL_CAL_DATE);
297  $activation->setEarliestStart($date->get(IL_CAL_UNIX));
298 
299  $date = $this->form->getInput('late_end');
300  $date = new ilDate($date['date'],IL_CAL_DATE);
301  $activation->setLatestEnd($date->get(IL_CAL_UNIX));
302 
303  $activation->toggleVisible((bool) $this->form->getInput('visible'));
304  $activation->toggleChangeable((bool) $this->form->getInput('changeable'));
305 
306  if(!$activation->validateActivation())
307  {
308  ilUtil::sendFailure($ilErr->getMessage());
309  $this->form->setValuesByPost();
310  $tpl->setContent($this->form->getHTML());
311  return false;
312  }
313  else
314  {
315  $activation->update($this->getItemId());
316  ilUtil::sendSuccess($this->lng->txt('settings_saved'), true);
317  $this->ctrl->redirect($this, "edit");
318  }
319  }
320  else
321  {
322  $this->form->setValuesByPost();
323  $tpl->setContent($this->form->getHTML());
324  }
325  }
326 
327  function __setTabs()
328  {
329  global $ilCtrl, $ilHelp;
330 
331  $this->tabs_gui->clearTargets();
332 
333  $ilHelp->setScreenIdComponent("obj");
334 
335  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $this->parent_ref_id);
336  $back_link = $ilCtrl->getLinkTargetByClass("ilrepositorygui", "");
337  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $_GET["ref_id"]);
338  $this->tabs_gui->setBackTarget($this->lng->txt('btn_back'), $back_link);
339 
340  $this->tabs_gui->addTarget("timings",
341  $this->ctrl->getLinkTarget($this,'edit'),
342  "edit", get_class($this));
343 
344  $this->ctrl->setParameterByClass('ilconditionhandlergui','item_id',$this->item_id);
345  $this->tabs_gui->addTarget("preconditions",
346  $this->ctrl->getLinkTargetByClass('ilConditionHandlerGUI','listConditions'),
347  "", "ilConditionHandlerGUI");
348  return true;
349  }
350 }
351 
352 ?>