ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 
152  protected function addLocatorItems()
153  {
154  $ilLocator = $this->locator;
155 
156  if ($this->object instanceof ilObject) {
157  $ilLocator->addItem($this->object->getPresentationTitle(), $this->ctrl->getLinkTarget($this));
158  }
159  }
160 
165  public function redirectObject()
166  {
168 
169  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $this->object->getTargetRefId());
170  $ilCtrl->redirectByClass("ilrepositorygui", "");
171  }
172 
178  public function createObject()
179  {
181  $ilAccess = $this->access;
184 
185  $new_type = $_REQUEST["new_type"];
186  if (!$ilAccess->checkAccess("create_" . $this->getReferenceType(), '', $_GET["ref_id"], $new_type)) {
187  $ilErr->raiseError($this->lng->txt("permission_denied"), $ilErr->MESSAGE);
188  }
189  $form = $this->initForm(self::MODE_CREATE);
190  $this->tpl->setContent($form->getHTML());
191  }
192 
193 
201  public function saveObject()
202  {
203  $ilAccess = $this->access;
204 
205  if (!(int) $_REQUEST['target_id']) {
206  ilUtil::sendFailure($this->lng->txt('select_one'));
207  $this->createObject();
208  return false;
209  }
210  if (!$ilAccess->checkAccess('visible', '', (int) $_REQUEST['target_id'])) {
211  ilUtil::sendFailure($this->lng->txt('permission_denied'));
212  $this->createObject();
213  return false;
214  }
215 
216  parent::saveObject();
217  }
218 
219  protected function initCreateForm($a_new_type)
220  {
221  return $this->initForm(self::MODE_CREATE);
222  }
223 
227  protected function afterSave(ilObject $a_new_object)
228  {
229  $target_obj_id = ilObject::_lookupObjId((int) $this->form->getInput('target_id'));
230  $a_new_object->setTargetId($target_obj_id);
231 
232  $a_new_object->setTitleType($this->form->getInput('title_type'));
233  if ($this->form->getInput('title_type') == ilContainerReference::TITLE_TYPE_CUSTOM) {
234  $a_new_object->setTitle($this->form->getInput('title'));
235  }
236 
237  $a_new_object->update();
238 
239  ilUtil::sendSuccess($this->lng->txt("object_added"), true);
240  $this->ctrl->setParameter($this, 'ref_id', $a_new_object->getRefId());
241  $this->ctrl->setParameter($this, 'creation_mode', 0);
242  $this->ctrl->redirect($this, 'firstEdit');
243  }
244 
248  protected function firstEditObject()
249  {
250  $this->editObject();
251  }
252 
253  public function editReferenceObject()
254  {
255  $this->editObject();
256  }
257 
263  public function editObject(ilPropertyFormGUI $form = null)
264  {
265  global $DIC;
266 
267  $main_tpl = $DIC->ui()->mainTemplate();
268 
269  $ilTabs = $this->tabs;
270 
271  $ilTabs->setTabActive('settings');
272 
273  if (!$form instanceof ilPropertyFormGUI) {
274  $form = $this->initForm();
275  }
276  $main_tpl->setContent($form->getHTML());
277  }
278 
284  protected function initForm($a_mode = self::MODE_EDIT)
285  {
286  include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
287  include_once './Services/ContainerReference/classes/class.ilContainerReference.php';
288  $form = new ilPropertyFormGUI();
289 
290  if ($a_mode == self::MODE_CREATE) {
291  $form->setTitle($this->lng->txt($this->getReferenceType() . '_new'));
292 
293  $this->ctrl->setParameter($this, 'creation_mode', $a_mode);
294  $this->ctrl->setParameter($this, 'new_type', $_REQUEST['new_type']);
295  } else {
296  $form->setTitle($this->lng->txt('edit'));
297  }
298 
299  $form->setFormAction($this->ctrl->getFormAction($this));
300  if ($a_mode == self::MODE_CREATE) {
301  $form->addCommandButton('save', $this->lng->txt('create'));
302  $form->addCommandButton('cancel', $this->lng->txt('cancel'));
303  } else {
304  $form->addCommandButton('update', $this->lng->txt('save'));
305  }
306 
307  // title type
308  $ttype = new ilRadioGroupInputGUI($this->lng->txt('title'), 'title_type');
309  if ($a_mode == self::MODE_EDIT) {
310  $ttype->setValue($this->object->getTitleType());
311  } else {
312  $ttype->setValue(ilContainerReference::TITLE_TYPE_REUSE);
313  }
314 
315  $reuse = new ilRadioOption($this->lng->txt('objref_reuse_title'));
317  $ttype->addOption($reuse);
318 
319  $custom = new ilRadioOption($this->lng->txt('objref_custom_title'));
321 
322  // title
323  $title = new ilTextInputGUI($this->lng->txt('title'), 'title');
324  $title->setSize(min(40, ilObject::TITLE_LENGTH));
325  $title->setMaxLength(ilObject::TITLE_LENGTH);
326  $title->setRequired(true);
327 
328  if ($a_mode == self::MODE_EDIT) {
329  $title->setValue($this->object->getTitle());
330  }
331 
332  $custom->addSubItem($title);
333  $ttype->addOption($custom);
334  $form->addItem($ttype);
335 
336  include_once("./Services/Form/classes/class.ilRepositorySelector2InputGUI.php");
337  $repo = new ilRepositorySelector2InputGUI($this->lng->txt("objref_edit_ref"), "target_id");
338  //$repo->setParent($this);
339  $repo->setRequired(true);
340  $repo->getExplorerGUI()->setSelectableTypes(array($this->getTargetType()));
341  $repo->getExplorerGUI()->setTypeWhiteList(
342  array_merge(
343  array($this->getTargetType()),
344  array("root", "cat", "grp", "fold", "crs")
345  )
346  );
347  $repo->setInfo($this->lng->txt($this->getReferenceType() . '_edit_info'));
348 
349  if ($a_mode == self::MODE_EDIT) {
350  $repo->getExplorerGUI()->setPathOpen($this->object->getTargetRefId());
351  $repo->setValue($this->object->getTargetRefId());
352  }
353 
354  $form->addItem($repo);
355  $this->form = $form;
356  return $form;
357  }
358 
362  public function updateObject()
363  {
364  $ilAccess = $this->access;
365  $form = $this->initForm();
366  if ($form->checkInput()) {
367  $this->object->setTitleType($form->getInput('title_type'));
368  if ($form->getInput('title_type') == ilContainerReference::TITLE_TYPE_CUSTOM) {
369  $this->object->setTitle($form->getInput('title'));
370  }
371 
372  if (!$ilAccess->checkAccess('visible', '', (int) $form->getInput('target_id')) ||
373  ilObject::_lookupType($form->getInput('target_id'), true) != $this->target_type) {
374  ilUtil::sendFailure($this->lng->txt('permission_denied'));
375  $this->editObject();
376  return false;
377  }
378  $this->checkPermission('write');
379 
380  $target_obj_id = ilObject::_lookupObjId((int) $form->getInput('target_id'));
381  $this->object->setTargetId($target_obj_id);
382 
383 
384  $this->object->update();
385  ilUtil::sendSuccess($this->lng->txt('settings_saved'), true);
386  $this->ctrl->redirect($this, 'edit');
387  }
388  $form->setValuesByPost();
389  ilUtil::sendFailure($this->lng->txt('err_check_input'));
390  $this->editObject($form);
391  return true;
392  }
393 
400  public function getTargetType()
401  {
402  return $this->target_type;
403  }
404 
411  public function getReferenceType()
412  {
413  return $this->reference_type;
414  }
415 
419  public function getId()
420  {
421  return $this->obj_id;
422  }
423 }
This class represents an option in a radio group.
settings()
Definition: settings.php:2
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"]
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
static _lookupType($a_id, $a_reference=false)
lookup object type
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
firstEditObject()
show edit screen without info message
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.