ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 {
17  protected $error;
18 
22  protected $tabs;
23 
27  protected $access;
28 
32  protected $tree;
33 
37  protected $user;
38 
42  protected $help;
43 
44  protected $parent_ref_id;
45  protected $item_id;
46  protected $tpl;
47  protected $ctrl;
48  protected $lng;
49 
54  public function __construct($a_ref_id, $a_item_id)
55  {
56  global $DIC;
57 
58  $this->tpl = $DIC["tpl"];
59  $this->ctrl = $DIC->ctrl();
60  $this->lng = $DIC->language();
61  $this->error = $DIC["ilErr"];
62  $this->tabs = $DIC->tabs();
63  $this->access = $DIC->access();
64  $this->tree = $DIC->repositoryTree();
65  $this->user = $DIC->user();
66  $this->help = $DIC["ilHelp"];
67  $tpl = $DIC["tpl"];
68  $ilCtrl = $DIC->ctrl();
69  $lng = $DIC->language();
70  $ilErr = $DIC["ilErr"];
71  $ilTabs = $DIC->tabs();
72 
73  $this->tpl =&$tpl;
74  $this->ctrl =&$ilCtrl;
75  $this->lng =&$lng;
76  $this->lng->loadLanguageModule('crs');
77  $this->err =&$ilErr;
78  $this->tabs_gui =&$ilTabs;
79 
80  $this->parent_ref_id = $a_ref_id;
81  $this->item_id = $a_item_id;
82  $this->ctrl->saveParameter($this, 'item_id');
83  }
84 
85  public function executeCommand()
86  {
87  $tpl = $this->tpl;
88 
89  $this->__setTabs();
90 
91  $cmd = $this->ctrl->getCmd();
92 
93  // Check if item id is given and valid
94  if (!$this->item_id) {
95  ilUtil::sendFailure($this->lng->txt("crs_no_item_id_given"), true);
96  $this->ctrl->returnToParent($this);
97  }
98 
99  $tpl->getStandardTemplate();
100 
101  switch ($this->ctrl->getNextClass($this)) {
102  case 'ilconditionhandlergui':
103  // preconditions for single course items
104  include_once './Services/AccessControl/classes/class.ilConditionHandlerGUI.php';
105  $this->ctrl->saveParameter($this, 'item_id', $_GET['item_id']);
106  $new_gui = new ilConditionHandlerGUI($this, (int) $_GET['item_id']);
107  $this->ctrl->forwardCommand($new_gui);
108  $this->tabs_gui->setTabActive('preconditions');
109  break;
110 
111  default:
112  $this->tabs_gui->setTabActive('timings');
113  if (!$cmd) {
114  $cmd = 'edit';
115  }
116  $this->$cmd();
117  $this->tabs_gui->setTabActive('timings');
118  break;
119  }
120 
121  $tpl->show();
122  }
123 
124  public function getItemId()
125  {
126  return $this->item_id;
127  }
128 
129  public function cancel()
130  {
131  $this->ctrl->setParameterByClass('ilrepositorygui', 'ref_id', $this->parent_ref_id);
132  $this->ctrl->redirectByClass('ilrepositorygui');
133  }
134 
141  public function edit()
142  {
144  $ilAccess = $this->access;
145  $tpl = $this->tpl;
146 
147  // #19997 - see ilObjectListGUI::insertTimingsCommand()
148  if (!$ilAccess->checkAccess('write', '', $this->parent_ref_id) &&
149  !$ilAccess->checkAccess('write', '', $this->getItemId())) {
150  $ilErr->raiseError($this->lng->txt('permission_denied'), $ilErr->MESSAGE);
151  }
152 
153  $this->initFormEdit();
154  $this->getValues();
155 
156  $tpl->setContent($this->form->getHTML());
157  }
158 
165  protected function initFormEdit()
166  {
167  $tree = $this->tree;
168 
169  include_once "Services/Object/classes/class.ilObjectActivation.php";
170 
171  include_once('./Services/Form/classes/class.ilPropertyFormGUI.php');
172  $this->form = new ilPropertyFormGUI();
173  $this->form->setFormAction($this->ctrl->getFormAction($this));
174 
176  $this->form->setTitle($title . ': ' . $this->lng->txt('crs_edit_timings'));
177 
178  $timings = new ilRadioGroupInputGUI($this->lng->txt('timings'), 'timing_type');
179 
180  // opt deactivated
181  $dea = new ilRadioOption($this->lng->txt('crs_timings_disabled'), ilObjectActivation::TIMINGS_DEACTIVATED);
182  $dea->setInfo($this->lng->txt('crs_timings_disabled_info'));
183  $timings->addOption($dea);
184 
185  // Visiblity
186  $vis = new ilRadioOption($this->lng->txt('crs_timings_availability_enabled'), ilObjectActivation::TIMINGS_ACTIVATION);
187  #$vis->setInfo($this->lng->txt('crs_timings_visibility'));
188 
189  $start = new ilDateTimeInputGUI($this->lng->txt('crs_timings_start'), 'timing_start');
190  $start->setRequired(true);
191  $start->setShowTime(true);
192  $vis->addSubItem($start);
193 
194  $end = new ilDateTimeInputGUI($this->lng->txt('crs_timings_end'), 'timing_end');
195  $end->setRequired(true);
196  $end->setShowTime(true);
197  $vis->addSubItem($end);
198 
199  $isv = new ilCheckboxInputGUI($this->lng->txt('crs_timings_visibility_short'), 'visible');
200  $isv->setInfo($this->lng->txt('crs_timings_visibility'));
201  $isv->setValue(1);
202  $vis->addSubItem($isv);
203 
204  $timings->addOption($vis);
205 
206  // Timings
207  $tim = new ilRadioOption($this->lng->txt('crs_timings_presetting'), ilObjectActivation::TIMINGS_PRESETTING);
208  $tim->setInfo($this->lng->txt('crs_item_presetting_info'));
209 
210  $start = new ilDateTimeInputGUI($this->lng->txt('crs_timings_sug_begin'), 'sug_start');
211  $start->setRequired(true);
212  $tim->addSubItem($start);
213 
214  $end = new ilDateTimeInputGUI($this->lng->txt('crs_timings_sug_end'), 'sug_end');
215  $end->setRequired(true);
216  $tim->addSubItem($end);
217 
218  if ($tree->checkForParentType($this->parent_ref_id, 'crs')) {
219  $cha = new ilCheckboxInputGUI($this->lng->txt('crs_timings_changeable'), 'changeable');
220  $tim->addSubItem($cha);
221 
222  $start = new ilDateTimeInputGUI($this->lng->txt('crs_timings_early_begin'), 'early_start');
223  $start->setRequired(true);
224  $tim->addSubItem($start);
225 
226  $late = new ilDateTimeInputGUI($this->lng->txt('crs_timings_short_limit_start_end'), 'late_end');
227  $late->setRequired(true);
228  $tim->addSubItem($late);
229  }
230 
231 
232  $timings->addOption($tim);
233 
234  $this->form->addItem($timings);
235 
236  $this->form->addCommandButton('update', $this->lng->txt('save'));
237  $this->form->addCommandButton('cancel', $this->lng->txt('cancel'));
238  }
239 
246  protected function getValues()
247  {
249 
250  include_once "Services/Object/classes/class.ilObjectActivation.php";
251  $item_data = ilObjectActivation::getItem($this->getItemId());
252 
253  $data = array();
254 
255  if (!$item_data) {
257  } else {
258  $data['timing_type'] = $item_data['timing_type'];
259  $data['visible'] = $item_data['visible'];
260  $data['changeable'] = $item_data['changeable'];
261 
262  $map = array(
263  'timing_start' => 'timing_start'
264  ,'timing_end' => 'timing_end'
265  ,'sug_start' => 'suggestion_start'
266  ,'sug_end' => 'suggestion_end'
267  ,'early_start' => 'earliest_start'
268  ,'late_end' => 'latest_end'
269  );
270  foreach ($map as $data_key => $item_key) {
271  $data[$data_key] = null;
272 
273  // #14531
274  if ($item_data[$item_key]) {
275  $data[$data_key] = new ilDateTime($item_data[$item_key], IL_CAL_UNIX);
276  }
277  }
278  }
279 
280  $this->form->setValuesByArray($data);
281  }
282 
289  public function update()
290  {
292  $ilAccess = $this->access;
293  $tpl = $this->tpl;
295 
296  // #19997 - see ilObjectListGUI::insertTimingsCommand()
297  if (!$ilAccess->checkAccess('write', '', $this->parent_ref_id) &&
298  !$ilAccess->checkAccess('write', '', $this->getItemId())) {
299  $ilErr->raiseError($this->lng->txt('permission_denied'), $ilErr->MESSAGE);
300  }
301 
302  $this->initFormEdit();
303  if ($this->form->checkInput()) {
304  include_once "Services/Object/classes/class.ilObjectActivation.php";
305  $activation = new ilObjectActivation();
306 
307  $activation->setTimingType($this->form->getInput('timing_type'));
308 
309  $date = $this->form->getItemByPostVar('timing_start')->getDate();
310  $activation->setTimingStart($date ? $date->get(IL_CAL_UNIX) : null);
311 
312  $date = $this->form->getItemByPostVar('timing_end')->getDate();
313  $activation->setTimingEnd($date ? $date->get(IL_CAL_UNIX) : null);
314 
315  $date = $this->form->getItemByPostVar('sug_start')->getDate();
316  $activation->setSuggestionStart($date ? $date->get(IL_CAL_UNIX) : null);
317 
318  $date = $this->form->getItemByPostVar('sug_end')->getDate();
319  $activation->setSuggestionEnd($date ? $date->get(IL_CAL_UNIX) : null);
320 
321  $date = null;
322  $item = $this->form->getItemByPostVar('early_start');
323  if ($item) {
324  $date = $item->getDate();
325  }
326  $activation->setEarliestStart($date ? $date->get(IL_CAL_UNIX) : null);
327 
328  $date = null;
329  $item = $this->form->getItemByPostVar('late_end');
330  if ($item) {
331  $date = $item->getDate();
332  }
333  $activation->setLatestEnd($date ? $date->get(IL_CAL_UNIX) : null);
334 
335  $activation->toggleVisible((bool) $this->form->getInput('visible'));
336  $activation->toggleChangeable((bool) $this->form->getInput('changeable'));
337 
338  if (!$activation->validateActivation()) {
339  ilUtil::sendFailure($ilErr->getMessage());
340  $this->form->setValuesByPost();
341  $tpl->setContent($this->form->getHTML());
342  return false;
343  } else {
344  $activation->update($this->getItemId());
345  ilUtil::sendSuccess($this->lng->txt('settings_saved'), true);
346  $this->ctrl->redirect($this, "edit");
347  }
348  } else {
349  $this->form->setValuesByPost();
350  $tpl->setContent($this->form->getHTML());
351  }
352  }
353 
354  public function __setTabs()
355  {
357  $ilHelp = $this->help;
358 
359  $this->tabs_gui->clearTargets();
360 
361  $ilHelp->setScreenIdComponent("obj");
362 
363  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $this->parent_ref_id);
364  $back_link = $ilCtrl->getLinkTargetByClass("ilrepositorygui", "");
365  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $_GET["ref_id"]);
366  $this->tabs_gui->setBackTarget($this->lng->txt('btn_back'), $back_link);
367 
368  $this->tabs_gui->addTarget(
369  "timings",
370  $this->ctrl->getLinkTarget($this, 'edit'),
371  "edit",
372  get_class($this)
373  );
374 
375  $this->ctrl->setParameterByClass('ilconditionhandlergui', 'item_id', $this->item_id);
376  $this->tabs_gui->addTarget(
377  "preconditions",
378  $this->ctrl->getLinkTargetByClass('ilConditionHandlerGUI', 'listConditions'),
379  "",
380  "ilConditionHandlerGUI"
381  );
382  return true;
383  }
384 }
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
global $ilErr
Definition: raiseError.php:16
This class represents an option in a radio group.
class ilConditionHandlerGUI
This class represents a property form user interface.
global $DIC
Definition: saml.php:7
$_GET["client_id"]
__construct($a_ref_id, $a_item_id)
Constructor public.
static getItem($a_ref_id)
Get item data.
$end
Definition: saml1-acs.php:18
This class represents a checkbox property in a property form.
static _lookupTitle($a_id)
lookup object title
const IL_CAL_UNIX
setInfo($a_info)
Set Info.
user()
Definition: user.php:4
Class ilObjectActivationGUI.
This class represents a date/time property in a property form.
global $ilCtrl
Definition: ilias.php:18
setInfo($a_info)
Set Information Text.
This class represents a property in a property form.
addSubItem($a_item)
Add Subitem.
static _lookupObjId($a_id)
Date and time handling
$ilUser
Definition: imgupload.php:18
Create styles array
The data for the language used.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
Class ilObjectActivation.
setRequired($a_required)
Set Required.