ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 
12 {
16  protected $error;
17 
21  protected $tabs_gui;
22 
26  protected $access;
27 
31  protected $tree;
32 
36  protected $user;
37 
41  protected $help;
42 
46  protected $parent_ref_id;
47 
51  protected $item_id;
52 
56  protected $tpl;
57 
61  protected $ctrl;
62 
66  protected $lng;
67 
71  protected $timing_mode = null;
72 
76  protected $activation = null;
77 
83  public function __construct($a_ref_id, $a_item_id)
84  {
85  global $DIC;
86 
87  $this->tpl = $DIC->ui()->mainTemplate();
88  $this->ctrl = $DIC->ctrl();
89  $this->lng = $DIC->language();
90  $this->lng->loadLanguageModule('crs');
91 
92  $this->error = $DIC['ilErr'];
93  $this->tabs_gui = $DIC->tabs();
94  $this->access = $DIC->access();
95  $this->tree = $DIC->repositoryTree();
96  $this->user = $DIC->user();
97  $this->help = $DIC["ilHelp"];
98 
99 
100  $this->parent_ref_id = $a_ref_id;
101  $this->item_id = $a_item_id;
102 
103  $this->ctrl->saveParameter($this, 'item_id');
104  }
105 
110  public function executeCommand()
111  {
112  $tpl = $this->tpl;
113 
114  $this->__setTabs();
115 
116  $cmd = $this->ctrl->getCmd();
117 
118  // Check if item id is given and valid
119  if (!$this->item_id) {
120  ilUtil::sendFailure($this->lng->txt("crs_no_item_id_given"), true);
121  $this->ctrl->returnToParent($this);
122  }
123 
124  $tpl->getStandardTemplate();
125 
126  switch ($this->ctrl->getNextClass($this)) {
127  case 'ilconditionhandlergui':
128  // preconditions for single course items
129  $this->ctrl->saveParameter($this, 'item_id', $_GET['item_id']);
130  $new_gui = new ilConditionHandlerGUI($this, (int) $_GET['item_id']);
131  $this->ctrl->forwardCommand($new_gui);
132  $this->tabs_gui->setTabActive('preconditions');
133  break;
134 
135  default:
136  $this->initTimingMode();
137  $this->initItem();
138  $this->tabs_gui->setTabActive('timings');
139  if (!$cmd) {
140  $cmd = 'edit';
141  }
142  $this->$cmd();
143  $this->tabs_gui->setTabActive('timings');
144  break;
145  }
146 
147  $tpl->show();
148  }
149 
153  public function getItemId()
154  {
155  return $this->item_id;
156  }
157 
158  public function getTimingMode()
159  {
160  return $this->timing_mode;
161  }
162 
167  public function getParentId()
168  {
169  return $this->parent_ref_id;
170  }
171 
176  public function getActivation()
177  {
178  return $this->activation;
179  }
180 
181 
185  public function cancel()
186  {
187  $this->ctrl->setParameterByClass('ilrepositorygui', 'ref_id', $this->parent_ref_id);
188  $this->ctrl->redirectByClass('ilrepositorygui');
189  }
190 
197  public function edit(ilPropertyFormGUI $form = null)
198  {
200  $ilAccess = $this->access;
201  $tpl = $this->tpl;
202 
203  // #19997 - see ilObjectListGUI::insertTimingsCommand()
204  if (
205  !$ilAccess->checkAccess('write', '', $this->parent_ref_id) &&
206  !$ilAccess->checkAccess('write', '', $this->getItemId())) {
207  $ilErr->raiseError($this->lng->txt('permission_denied'), $ilErr->MESSAGE);
208  }
209 
210  if (!$form instanceof ilPropertyFormGUI) {
211  // show edit warning if timings are on
212  if ($GLOBALS['tree']->checkForParentType($this->getParentId(), 'crs')) {
213  if ($this->getActivation()->getTimingType() == ilObjectActivation::TIMINGS_PRESETTING) {
214  ilUtil::sendInfo($this->lng->txt('crs_timings_warning_timing_exists'));
215  }
216  }
217 
218  $form = $this->initFormEdit();
219  }
220  $tpl->setContent($form->getHTML());
221  }
222 
229  protected function initFormEdit()
230  {
231  $tree = $this->tree;
232 
233  $form = new ilPropertyFormGUI();
234  $form->setFormAction($this->ctrl->getFormAction($this));
235 
237  $form->setTitle($title . ': ' . $this->lng->txt('crs_edit_timings'));
238 
239 
240  $availability = new ilCheckboxInputGUI($this->lng->txt('crs_timings_availability_enabled'), 'availability');
241  $availability->setValue(1);
242  $availability->setChecked($this->getActivation()->getTimingType() == ilObjectActivation::TIMINGS_ACTIVATION);
243 
244  $start = new ilDateTimeInputGUI($this->lng->txt('crs_timings_start'), 'timing_start');
245  $start->setDate(new ilDateTime($this->getActivation()->getTimingStart(), IL_CAL_UNIX));
246  $start->setShowTime(true);
247  $availability->addSubItem($start);
248 
249  $end = new ilDateTimeInputGUI($this->lng->txt('crs_timings_end'), 'timing_end');
250  $end->setDate(new ilDateTime($this->getActivation()->getTimingEnd(), IL_CAL_UNIX));
251  $end->setShowTime(true);
252  $availability->addSubItem($end);
253 
254  $isv = new ilCheckboxInputGUI($this->lng->txt('crs_timings_visibility_short'), 'visible');
255  $isv->setInfo($this->lng->txt('crs_timings_visibility'));
256  $isv->setValue(1);
257  $isv->setChecked((bool) $this->getActivation()->enabledVisible());
258  $availability->addSubItem($isv);
259 
260 
261  $form->addItem($availability);
262 
263  $form->addCommandButton('update', $this->lng->txt('save'));
264  $form->addCommandButton('cancel', $this->lng->txt('cancel'));
265 
266  return $form;
267  }
268 
275  public function update()
276  {
278  $ilAccess = $this->access;
279  $tpl = $this->tpl;
281 
282  // #19997 - see ilObjectListGUI::insertTimingsCommand()
283  if (
284  !$ilAccess->checkAccess('write', '', $this->parent_ref_id) &&
285  !$ilAccess->checkAccess('write', '', $this->getItemId())) {
286  $ilErr->raiseError($this->lng->txt('permission_denied'), $ilErr->MESSAGE);
287  }
288 
289  $form = $this->initFormEdit();
290  if ($form->checkInput()) {
291  $valid = true;
293  $activation->read($this->getItemId());
294 
295  if ($form->getInput('availability')) {
296  $this->getActivation()->setTimingType(ilObjectActivation::TIMINGS_ACTIVATION);
297 
298  $timing_start = $form->getItemByPostVar('timing_start')->getDate();
299  $timing_end = $form->getItemByPostVar('timing_end')->getDate();
300 
301  if ($timing_start && $timing_end && ilDateTime::_after($timing_start, $timing_end)) {
302  $form->getItemByPostVar('timing_start')->setAlert($this->lng->txt('crs_timing_err_start_end'));
303  $form->getItemByPostVar('timing_end')->setAlert($this->lng->txt('crs_timing_err_start_end'));
304  $valid = false;
305  }
306 
307  $this->getActivation()->setTimingStart($timing_start ? $timing_start->get(IL_CAL_UNIX) : null);
308  $this->getActivation()->setTimingEnd($timing_end ? $timing_end->get(IL_CAL_UNIX) : null);
309 
310  $this->getActivation()->toggleVisible((bool) $form->getInput('visible'));
311  } elseif ($this->getActivation()->getTimingType() != ilObjectActivation::TIMINGS_PRESETTING) {
313  }
314 
315  if ($valid) {
316  $this->getActivation()->update($this->getItemId(), $this->getParentId());
317  ilUtil::sendSuccess($this->lng->txt('settings_saved'), true);
318  $this->ctrl->redirect($this, "edit");
319  } else {
320  ilUtil::sendFailure($this->lng->txt('form_input_not_valid'));
321  }
322  }
323 
324  $form->setValuesByPost();
325  $this->edit($form);
326  }
327 
331  protected function __setTabs()
332  {
334  $ilHelp = $this->help;
335 
336  $this->tabs_gui->clearTargets();
337 
338  $ilHelp->setScreenIdComponent("obj");
339 
340  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $this->parent_ref_id);
341  $back_link = $ilCtrl->getLinkTargetByClass("ilrepositorygui", "");
342  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $_GET["ref_id"]);
343  $this->tabs_gui->setBackTarget($this->lng->txt('btn_back'), $back_link);
344 
345  $this->tabs_gui->addTarget(
346  "timings",
347  $this->ctrl->getLinkTarget($this, 'edit'),
348  "edit",
349  get_class($this)
350  );
351 
352  $this->ctrl->setParameterByClass('ilconditionhandlergui', 'item_id', $this->item_id);
353  $this->tabs_gui->addTarget(
354  "preconditions",
355  $this->ctrl->getLinkTargetByClass('ilConditionHandlerGUI', 'listConditions'),
356  "",
357  "ilConditionHandlerGUI"
358  );
359  return true;
360  }
361 
365  protected function initTimingMode()
366  {
367  // Check for parent course and if available read timing mode (abs | rel)
368  $crs_ref_id = $GLOBALS['tree']->checkForParentType(
369  $this->parent_ref_id,
370  'crs'
371  );
372  $crs_obj_id = ilObject::_lookupObjId($crs_ref_id);
373 
374  if ($crs_obj_id) {
375  $this->timing_mode = ilObjCourse::lookupTimingMode($crs_obj_id);
376  } else {
378  }
379  }
380 
384  protected function initItem()
385  {
386  $this->activation = new ilObjectActivation();
387  $this->getActivation()->read($this->item_id, $this->getParentId());
388  }
389 }
class ilConditionHandlerGUI
This class represents a property form user interface.
global $DIC
Definition: saml.php:7
$_GET["client_id"]
static _after(ilDateTime $start, ilDateTime $end, $a_compare_field='', $a_tz='')
compare two dates and check start is after end This method does not consider tz offsets.
__construct($a_ref_id, $a_item_id)
ilObjectActivationGUI constructor.
$valid
This class represents a checkbox property in a property form.
static _lookupTitle($a_id)
lookup object title
static lookupTimingMode($a_obj_id)
const IL_CAL_UNIX
user()
Definition: user.php:4
$ilErr
Definition: raiseError.php:18
Class ilObjectActivationGUI.
This class represents a date/time property in a property form.
global $ilCtrl
Definition: ilias.php:18
$start
Definition: bench.php:8
cancel()
cancel action handler
setInfo($a_info)
Set Information Text.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
if(isset($_POST['submit'])) $form
static _lookupObjId($a_id)
setValue($a_value)
Set Value.
Date and time handling
$ilUser
Definition: imgupload.php:18
initTimingMode()
Init type of timing mode.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
Class ilObjectActivation.
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.
edit(ilPropertyFormGUI $form=null)
edit timings