ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilContainerReferenceGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 include_once('./Services/Object/classes/class.ilObjectGUI.php');
25 
36 {
40  protected $tabs;
41 
45  protected $locator;
46 
50  protected $user;
51 
55  protected $access;
56 
60  protected $error;
61 
65  protected $settings;
66 
68 
69  const MODE_CREATE = 1;
70  const MODE_EDIT = 2;
71 
72  protected $existing_objects = array();
73 
75  protected $target_type;
77  protected $reference_type;
79  protected $form;
80 
85  public function __construct($a_data, $a_id, $a_call_by_reference = true, $a_prepare_output = true)
86  {
87  global $DIC;
88 
89  $this->lng = $DIC->language();
90  $this->ctrl = $DIC->ctrl();
91  $this->tabs = $DIC->tabs();
92  $this->locator = $DIC["ilLocator"];
93  $this->user = $DIC->user();
94  $this->access = $DIC->access();
95  $this->error = $DIC["ilErr"];
96  $this->settings = $DIC->settings();
97  $lng = $DIC->language();
98  parent::__construct($a_data, $a_id, $a_call_by_reference, $a_prepare_output);
99 
100  $lng->loadLanguageModule('objref');
101  }
102 
111  public function executeCommand()
112  {
114  $ilTabs = $this->tabs;
115 
116 
117  if (isset($_GET['creation_mode']) && $_GET['creation_mode'] == self::MODE_CREATE) {
118  $this->setCreationMode(true);
119  }
120 
121  $next_class = $ilCtrl->getNextClass($this);
122  $cmd = $ilCtrl->getCmd();
123 
124  $this->prepareOutput();
125 
126  switch ($next_class) {
127  case "ilpropertyformgui":
128  $form = $this->initForm($this->creation_mode ? self::MODE_CREATE : self::MODE_EDIT);
129  $this->ctrl->forwardCommand($form);
130  break;
131 
132  case 'ilpermissiongui':
133  $ilTabs->setTabActive('perm_settings');
134  include_once("Services/AccessControl/classes/class.ilPermissionGUI.php");
135  $ilCtrl->forwardCommand(new ilPermissionGUI($this));
136  break;
137 
138  default:
139  if (!$cmd || $cmd == 'view') {
140  $cmd = "edit";
141  }
142  $cmd .= "Object";
143  $this->$cmd();
144  break;
145  }
146  return true;
147  }
148 
153  protected function addLocatorItems()
154  {
155  $ilLocator = $this->locator;
156 
157  if ($this->object instanceof ilObject) {
158  $ilLocator->addItem($this->object->getPresentationTitle(), $this->ctrl->getLinkTarget($this));
159  }
160  }
161 
166  public function redirectObject()
167  {
169 
170  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $this->object->getTargetRefId());
171  $ilCtrl->redirectByClass("ilrepositorygui", "");
172  }
173 
179  public function createObject()
180  {
182  $ilAccess = $this->access;
185 
186  $new_type = $_REQUEST["new_type"];
187  if (!$ilAccess->checkAccess("create_" . $this->getReferenceType(), '', $_GET["ref_id"], $new_type)) {
188  $ilErr->raiseError($this->lng->txt("permission_denied"), $ilErr->MESSAGE);
189  }
190  $form = $this->initForm(self::MODE_CREATE);
191  $this->tpl->setContent($form->getHTML());
192  }
193 
194 
202  public function saveObject()
203  {
204  $ilAccess = $this->access;
205 
206  if (!(int) $_REQUEST['target_id']) {
207  ilUtil::sendFailure($this->lng->txt('select_one'));
208  $this->createObject();
209  return false;
210  }
211  if (!$ilAccess->checkAccess('visible', '', (int) $_REQUEST['target_id'])) {
212  ilUtil::sendFailure($this->lng->txt('permission_denied'));
213  $this->createObject();
214  return false;
215  }
216 
217  parent::saveObject();
218  }
219 
220  protected function initCreateForm($a_new_type)
221  {
222  return $this->initForm(self::MODE_CREATE);
223  }
224 
228  protected function afterSave(ilObject $a_new_object)
229  {
230  $target_obj_id = ilObject::_lookupObjId((int) $this->form->getInput('target_id'));
231  $a_new_object->setTargetId($target_obj_id);
232 
233  $a_new_object->setTitleType($this->form->getInput('title_type'));
234  if ($this->form->getInput('title_type') == ilContainerReference::TITLE_TYPE_CUSTOM) {
235  $a_new_object->setTitle($this->form->getInput('title'));
236  }
237 
238  $a_new_object->update();
239 
240  ilUtil::sendSuccess($this->lng->txt("object_added"), true);
241  $this->ctrl->setParameter($this, 'ref_id', $a_new_object->getRefId());
242  $this->ctrl->setParameter($this, 'creation_mode', 0);
243  $this->ctrl->redirect($this, 'firstEdit');
244  }
245 
249  protected function firstEditObject()
250  {
251  $this->editObject();
252  }
253 
254  public function editReferenceObject()
255  {
256  $this->editObject();
257  }
258 
264  public function editObject(ilPropertyFormGUI $form = null)
265  {
266  $ilTabs = $this->tabs;
267 
268  $ilTabs->setTabActive('settings');
269 
270  if (!$form instanceof ilPropertyFormGUI) {
271  $form = $this->initForm();
272  }
273  $GLOBALS['tpl']->setContent($form->getHTML());
274  }
275 
281  protected function initForm($a_mode = self::MODE_EDIT)
282  {
283  include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
284  include_once './Services/ContainerReference/classes/class.ilContainerReference.php';
285  $form = new ilPropertyFormGUI();
286 
287  if ($a_mode == self::MODE_CREATE) {
288  $form->setTitle($this->lng->txt($this->getReferenceType() . '_new'));
289 
290  $this->ctrl->setParameter($this, 'creation_mode', $a_mode);
291  $this->ctrl->setParameter($this, 'new_type', $_REQUEST['new_type']);
292  } else {
293  $form->setTitle($this->lng->txt('edit'));
294  }
295 
296  $form->setFormAction($this->ctrl->getFormAction($this));
297  if ($a_mode == self::MODE_CREATE) {
298  $form->addCommandButton('save', $this->lng->txt('create'));
299  $form->addCommandButton('cancel', $this->lng->txt('cancel'));
300  } else {
301  $form->addCommandButton('update', $this->lng->txt('save'));
302  }
303 
304  // title type
305  $ttype = new ilRadioGroupInputGUI($this->lng->txt('title'), 'title_type');
306  if ($a_mode == self::MODE_EDIT) {
307  $ttype->setValue($this->object->getTitleType());
308  } else {
309  $ttype->setValue(ilContainerReference::TITLE_TYPE_REUSE);
310  }
311 
312  $reuse = new ilRadioOption($this->lng->txt('objref_reuse_title'));
314  $ttype->addOption($reuse);
315 
316  $custom = new ilRadioOption($this->lng->txt('objref_custom_title'));
318 
319  // title
320  $title = new ilTextInputGUI($this->lng->txt('title'), 'title');
321  $title->setSize(min(40, ilObject::TITLE_LENGTH));
322  $title->setMaxLength(ilObject::TITLE_LENGTH);
323  $title->setRequired(true);
324 
325  if ($a_mode == self::MODE_EDIT) {
326  $title->setValue($this->object->getTitle());
327  }
328 
329  $custom->addSubItem($title);
330  $ttype->addOption($custom);
331  $form->addItem($ttype);
332 
333  include_once("./Services/Form/classes/class.ilRepositorySelector2InputGUI.php");
334  $repo = new ilRepositorySelector2InputGUI($this->lng->txt("objref_edit_ref"), "target_id");
335  //$repo->setParent($this);
336  $repo->setRequired(true);
337  $repo->getExplorerGUI()->setSelectableTypes(array($this->getTargetType()));
338  $repo->getExplorerGUI()->setTypeWhiteList(
339  array_merge(
340  array($this->getTargetType()),
341  array("root", "cat", "grp", "fold", "crs")
342  )
343  );
344  $repo->setInfo($this->lng->txt($this->getReferenceType() . '_edit_info'));
345 
346  if ($a_mode == self::MODE_EDIT) {
347  $repo->getExplorerGUI()->setPathOpen($this->object->getTargetRefId());
348  $repo->setValue($this->object->getTargetRefId());
349  }
350 
351  $form->addItem($repo);
352  $this->form = $form;
353  return $form;
354  }
355 
359  public function updateObject()
360  {
361  $ilAccess = $this->access;
362  $form = $this->initForm();
363  if ($form->checkInput()) {
364  $this->object->setTitleType($form->getInput('title_type'));
365  if ($form->getInput('title_type') == ilContainerReference::TITLE_TYPE_CUSTOM) {
366  $this->object->setTitle($form->getInput('title'));
367  }
368 
369  if (!$ilAccess->checkAccess('visible', '', (int) $form->getInput('target_id')) ||
370  ilObject::_lookupType($form->getInput('target_id'), true) != $this->target_type) {
371  ilUtil::sendFailure($this->lng->txt('permission_denied'));
372  $this->editObject();
373  return false;
374  }
375  $this->checkPermission('write');
376 
377  $target_obj_id = ilObject::_lookupObjId((int) $form->getInput('target_id'));
378  $this->object->setTargetId($target_obj_id);
379 
380 
381  $this->object->update();
382  ilUtil::sendSuccess($this->lng->txt('settings_saved'), true);
383  $this->ctrl->redirect($this, 'edit');
384  }
385  $form->setValuesByPost();
386  ilUtil::sendFailure($this->lng->txt('err_check_input'));
387  $this->editObject($form);
388  return true;
389  }
390 
397  public function getTargetType()
398  {
399  return $this->target_type;
400  }
401 
408  public function getReferenceType()
409  {
410  return $this->reference_type;
411  }
412 
416  public function getId()
417  {
418  return $this->obj_id;
419  }
420 }
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
This class represents an option in a radio group.
This class represents a property form user interface.
initForm($a_mode=self::MODE_EDIT)
Init title form.
global $DIC
Definition: saml.php:7
const TITLE_LENGTH
max length of object title
$_GET["client_id"]
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
setCreationMode($a_mode=true)
if true, a creation screen is displayed the current $_GET[ref_id] don&#39;t belong to the current class! ...
user()
Definition: user.php:4
setTitle($a_title)
set object title
global $ilCtrl
Definition: ilias.php:18
prepareOutput($a_show_subobjects=true)
prepare output
editObject(ilPropertyFormGUI $form=null)
edit title
This class represents a property in a property form.
setValue($a_value)
Set Value.
__construct($a_data, $a_id, $a_call_by_reference=true, $a_prepare_output=true)
Constructor.
Class ilObjectGUI Basic methods of all Output classes.
static _lookupObjId($a_id)
This class represents a text property in a property form.
$ilUser
Definition: imgupload.php:18
editObject()
edit object
Create styles array
The data for the language used.
static _lookupType($a_id, $a_reference=false)
lookup object type
addLocatorItems()
Add locator item ilLocatorGUI $ilLocator.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
settings()
Definition: settings.php:2
firstEditObject()
show edit screen without info message
Create new PHPExcel object
obj_idprivate
global $ilSetting
Definition: privfeed.php:17
getRefId()
get reference id public
checkPermission($a_perm, $a_cmd="", $a_type="", $a_ref_id=null)
Check permission and redirect on error.
New PermissionGUI (extends from old ilPermission2GUI) RBAC related output.
update()
update object in db
setRequired($a_required)
Set Required.