ILIAS  release_4-3 Revision
 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 'ilconditionhandlerinterface':
61  // preconditions for single course items
62  include_once './Services/AccessControl/classes/class.ilConditionHandlerInterface.php';
63  $this->ctrl->saveParameter($this,'item_id',$_GET['item_id']);
64  $new_gui =& new ilConditionHandlerInterface($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  {
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  $start = new ilDateTime($item_data['timing_start'],IL_CAL_UNIX);
221  $data['timing_start']['date'] = $start->get(IL_CAL_FKT_DATE,'Y-m-d',$ilUser->getTimeZone());
222  $data['timing_start']['time'] = $start->get(IL_CAL_FKT_DATE,'H:i:s',$ilUser->getTimeZone());
223 
224  $end = new ilDateTime($item_data['timing_end'],IL_CAL_UNIX);
225  $data['timing_end']['date'] = $end->get(IL_CAL_FKT_DATE,'Y-m-d',$ilUser->getTimeZone());
226  $data['timing_end']['time'] = $end->get(IL_CAL_FKT_DATE,'H:i:s',$ilUser->getTimeZone());
227 
228  $start = new ilDate(date('Y-m-d',$item_data['suggestion_start']),IL_CAL_DATE);
229  $data['sug_start']['date'] = $start->get(IL_CAL_FKT_DATE,'Y-m-d','UTC');
230 
231  $end = new ilDate(date('Y-m-d',$item_data['suggestion_end']),IL_CAL_DATE);
232  $data['sug_end']['date'] = $end->get(IL_CAL_FKT_DATE,'Y-m-d','UTC');
233 
234  $start = new ilDate(date('Y-m-d',$item_data['earliest_start']),IL_CAL_DATE);
235  $data['early_start']['date'] = $start->get(IL_CAL_FKT_DATE,'Y-m-d','UTC');
236 
237  $end = new ilDate(date('Y-m-d',$item_data['latest_end']),IL_CAL_DATE);
238  $data['late_end']['date'] = $end->get(IL_CAL_FKT_DATE,'Y-m-d','UTC');
239  }
240 
241  $this->form->setValuesByArray($data);
242  }
243 
250  public function update()
251  {
252  global $ilErr,$ilAccess,$tpl,$ilUser;
253 
254  // #19997 - see ilObjectListGUI::insertTimingsCommand()
255  if(!$ilAccess->checkAccess('write','',$this->parent_ref_id) &&
256  !$ilAccess->checkAccess('write','',$this->getItemId()))
257  {
258  $ilErr->raiseError($this->lng->txt('permission_denied'),$ilErr->MESSAGE);
259  }
260 
261  $this->initFormEdit();
262  if($this->form->checkInput())
263  {
264  include_once "Services/Object/classes/class.ilObjectActivation.php";
265  $activation = new ilObjectActivation();
266 
267  $activation->setTimingType($this->form->getInput('timing_type'));
268 
269  $date = $this->form->getInput('timing_start');
270  $date = new ilDateTime($date['date'].' '.$date['time'],IL_CAL_DATETIME,$ilUser->getTimeZone());
271  $activation->setTimingStart($date->get(IL_CAL_UNIX));
272 
273  $date = $this->form->getInput('timing_end');
274  $date = new ilDateTime($date['date'].' '.$date['time'],IL_CAL_DATETIME,$ilUser->getTimeZone());
275  $activation->setTimingEnd($date->get(IL_CAL_UNIX));
276 
277  $date = $this->form->getInput('sug_start');
278  $date = new ilDate($date['date'],IL_CAL_DATE);
279  $activation->setSuggestionStart($date->get(IL_CAL_UNIX));
280 
281  $date = $this->form->getInput('sug_end');
282  $date = new ilDate($date['date'],IL_CAL_DATE);
283  $activation->setSuggestionEnd($date->get(IL_CAL_UNIX));
284 
285  $date = $this->form->getInput('early_start');
286  $date = new ilDate($date['date'],IL_CAL_DATE);
287  $activation->setEarliestStart($date->get(IL_CAL_UNIX));
288 
289  $date = $this->form->getInput('late_end');
290  $date = new ilDate($date['date'],IL_CAL_DATE);
291  $activation->setLatestEnd($date->get(IL_CAL_UNIX));
292 
293  $activation->toggleVisible((bool) $this->form->getInput('visible'));
294  $activation->toggleChangeable((bool) $this->form->getInput('changeable'));
295 
296  if(!$activation->validateActivation())
297  {
298  ilUtil::sendFailure($ilErr->getMessage());
299  $this->form->setValuesByPost();
300  $tpl->setContent($this->form->getHTML());
301  return false;
302  }
303  else
304  {
305  $activation->update($this->getItemId());
306  ilUtil::sendSuccess($this->lng->txt('settings_saved'), true);
307  $this->ctrl->redirect($this, "edit");
308  }
309  }
310  else
311  {
312  $this->form->setValuesByPost();
313  $tpl->setContent($this->form->getHTML());
314  }
315  }
316 
317  function __setTabs()
318  {
319  global $ilCtrl;
320 
321  $this->tabs_gui->clearTargets();
322 
323  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $this->parent_ref_id);
324  $back_link = $ilCtrl->getLinkTargetByClass("ilrepositorygui", "");
325  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $_GET["ref_id"]);
326  $this->tabs_gui->setBackTarget($this->lng->txt('btn_back'), $back_link);
327 
328  $this->tabs_gui->addTarget("timings",
329  $this->ctrl->getLinkTarget($this,'edit'),
330  "edit", get_class($this));
331 
332  $this->ctrl->setParameterByClass('ilconditionhandlerinterface','item_id',$this->item_id);
333  $this->tabs_gui->addTarget("preconditions",
334  $this->ctrl->getLinkTargetByClass('ilConditionHandlerInterface','listConditions'),
335  "", "ilConditionHandlerInterface");
336  return true;
337  }
338 }
339 
340 ?>