ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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
24include_once('./Services/Object/classes/class.ilObjectGUI.php');
25
36{
38
39 const MODE_CREATE = 1;
40 const MODE_EDIT = 2;
41
45 protected $tabs;
46
50 protected $locator;
51
55 protected $user;
56
60 protected $access;
61
65 protected $error;
66
70 protected $settings;
71
72
73 protected $existing_objects = array();
74
78 protected $target_type;
82 protected $reference_type;
83
87 protected $form;
88
93 public function __construct($a_data, $a_id, $a_call_by_reference = true, $a_prepare_output = true)
94 {
95 global $DIC;
96
97 $this->lng = $DIC->language();
98 $this->ctrl = $DIC->ctrl();
99 $this->tabs = $DIC->tabs();
100 $this->locator = $DIC["ilLocator"];
101 $this->user = $DIC->user();
102 $this->access = $DIC->access();
103 $this->error = $DIC["ilErr"];
104 $this->settings = $DIC->settings();
105 $lng = $DIC->language();
106 parent::__construct($a_data, $a_id, $a_call_by_reference, $a_prepare_output);
107
108 $lng->loadLanguageModule('objref');
109 }
110
119 public function executeCommand()
120 {
122 $ilTabs = $this->tabs;
123
124
125 if (isset($_GET['creation_mode']) && $_GET['creation_mode'] == self::MODE_CREATE) {
126 $this->setCreationMode(true);
127 }
128
129 $next_class = $ilCtrl->getNextClass($this);
130 $cmd = $ilCtrl->getCmd();
131
132 $this->prepareOutput();
133
134 switch ($next_class) {
135 case "ilpropertyformgui":
136 $form = $this->initForm($this->creation_mode ? self::MODE_CREATE : self::MODE_EDIT);
137 $this->ctrl->forwardCommand($form);
138 break;
139
140 case 'ilpermissiongui':
141 $ilTabs->setTabActive('perm_settings');
142 include_once("Services/AccessControl/classes/class.ilPermissionGUI.php");
143 $ilCtrl->forwardCommand(new ilPermissionGUI($this));
144 break;
145
146 default:
147 if (!$cmd || $cmd == 'view') {
148 $cmd = "edit";
149 }
150 $cmd .= "Object";
151 $this->$cmd();
152 break;
153 }
154 return true;
155 }
159 protected function addLocatorItems()
160 {
161 $ilLocator = $this->locator;
162
163 if ($this->object instanceof ilObject) {
164 $ilLocator->addItem($this->object->getPresentationTitle(), $this->ctrl->getLinkTarget($this));
165 }
166 }
167
172 public function redirectObject()
173 {
175
176 $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $this->object->getTargetRefId());
177 $ilCtrl->redirectByClass("ilrepositorygui", "");
178 }
179
185 public function createObject()
186 {
188 $ilAccess = $this->access;
191
192 $new_type = $_REQUEST["new_type"];
193 if (!$ilAccess->checkAccess("create_" . $this->getReferenceType(), '', $_GET["ref_id"], $new_type)) {
194 $ilErr->raiseError($this->lng->txt("permission_denied"), $ilErr->MESSAGE);
195 }
196 $form = $this->initForm(self::MODE_CREATE);
197 $this->tpl->setContent($form->getHTML());
198 }
199
200
208 public function saveObject()
209 {
210 $ilAccess = $this->access;
211
212 if (!(int) $_REQUEST['target_id']) {
213 ilUtil::sendFailure($this->lng->txt('select_one'));
214 $this->createObject();
215 return false;
216 }
217 if (!$ilAccess->checkAccess('visible', '', (int) $_REQUEST['target_id'])) {
218 ilUtil::sendFailure($this->lng->txt('permission_denied'));
219 $this->createObject();
220 return false;
221 }
222
223 parent::saveObject();
224 }
225
226 protected function initCreateForm($a_new_type)
227 {
228 return $this->initForm(self::MODE_CREATE);
229 }
230
234 protected function afterSave(ilObject $a_new_object)
235 {
236 $target_obj_id = ilObject::_lookupObjId((int) $this->form->getInput('target_id'));
237 $a_new_object->setTargetId($target_obj_id);
238
239 $a_new_object->setTitleType($this->form->getInput('title_type'));
240 if ($this->form->getInput('title_type') == ilContainerReference::TITLE_TYPE_CUSTOM) {
241 $a_new_object->setTitle($this->form->getInput('title'));
242 }
243
244 $a_new_object->update();
245
246 ilUtil::sendSuccess($this->lng->txt("object_added"), true);
247 $this->ctrl->setParameter($this, 'ref_id', $a_new_object->getRefId());
248 $this->ctrl->setParameter($this, 'creation_mode', 0);
249 $this->ctrl->redirect($this, 'firstEdit');
250 }
251
255 protected function firstEditObject()
256 {
257 $this->editObject();
258 }
259
260 public function editReferenceObject()
261 {
262 $this->editObject();
263 }
264
270 public function editObject(ilPropertyFormGUI $form = null)
271 {
272 global $DIC;
273
274 $main_tpl = $DIC->ui()->mainTemplate();
275
276 $ilTabs = $this->tabs;
277
278 $ilTabs->setTabActive('settings');
279
280 if (!$form instanceof ilPropertyFormGUI) {
281 $form = $this->initForm();
282 }
283 $main_tpl->setContent($form->getHTML());
284 }
285
291 protected function initForm($a_mode = self::MODE_EDIT)
292 {
293 include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
294 include_once './Services/ContainerReference/classes/class.ilContainerReference.php';
295 $form = new ilPropertyFormGUI();
296
297 if ($a_mode == self::MODE_CREATE) {
298 $form->setTitle($this->lng->txt($this->getReferenceType() . '_new'));
299
300 $this->ctrl->setParameter($this, 'creation_mode', $a_mode);
301 $this->ctrl->setParameter($this, 'new_type', $_REQUEST['new_type']);
302 } else {
303 $form->setTitle($this->lng->txt('edit'));
304 }
305
306 $form->setFormAction($this->ctrl->getFormAction($this));
307 if ($a_mode == self::MODE_CREATE) {
308 $form->addCommandButton('save', $this->lng->txt('create'));
309 $form->addCommandButton('cancel', $this->lng->txt('cancel'));
310 } else {
311 $form->addCommandButton('update', $this->lng->txt('save'));
312 }
313
314 // title type
315 $ttype = new ilRadioGroupInputGUI($this->lng->txt('title'), 'title_type');
316 if ($a_mode == self::MODE_EDIT) {
317 $ttype->setValue($this->object->getTitleType());
318 } else {
320 }
321
322 $reuse = new ilRadioOption($this->lng->txt('objref_reuse_title'));
324 $ttype->addOption($reuse);
325
326 $custom = new ilRadioOption($this->lng->txt('objref_custom_title'));
328
329 // title
330 $title = new ilTextInputGUI($this->lng->txt('title'), 'title');
331 $title->setSize(min(40, ilObject::TITLE_LENGTH));
332 $title->setMaxLength(ilObject::TITLE_LENGTH);
333 $title->setRequired(true);
334
335 if ($a_mode == self::MODE_EDIT) {
336 $title->setValue($this->object->getTitle());
337 }
338
339 $custom->addSubItem($title);
340 $ttype->addOption($custom);
341 $form->addItem($ttype);
342
343 include_once("./Services/Form/classes/class.ilRepositorySelector2InputGUI.php");
344 $repo = new ilRepositorySelector2InputGUI($this->lng->txt("objref_edit_ref"), "target_id");
345 //$repo->setParent($this);
346 $repo->setRequired(true);
347 $repo->getExplorerGUI()->setSelectableTypes(array($this->getTargetType()));
348 $repo->getExplorerGUI()->setTypeWhiteList(
349 array_merge(
350 array($this->getTargetType()),
351 array("root", "cat", "grp", "fold", "crs")
352 )
353 );
354 $repo->setInfo($this->lng->txt($this->getReferenceType() . '_edit_info'));
355
356 if ($a_mode == self::MODE_EDIT) {
357 $repo->getExplorerGUI()->setPathOpen($this->object->getTargetRefId());
358 $repo->setValue($this->object->getTargetRefId());
359 }
360
361 $form->addItem($repo);
362 $this->form = $form;
363 return $form;
364 }
365
366
372 {
373 global $DIC;
374
375 $ok = true;
376 $access = $DIC->access();
377
378 $this->object->setTitleType($form->getInput('title_type'));
379 if ($form->getInput('title_type') == ilContainerReference::TITLE_TYPE_CUSTOM) {
380 $this->object->setTitle($form->getInput('title'));
381 }
382
383 // check access
384 if (
385 !$access->checkAccess('visible', '', (int) $form->getInput('target_id'))
386 ) {
387 $ok = false;
388 $form->getItemByPostVar('target_id')->setAlert($this->lng->txt('permission_denied'));
389 }
390 // check target type
391 if (ilObject::_lookupType($form->getInput('target_id'), true) != $this->target_type) {
392 $ok = false;
393 $form->getItemByPostVar('target_id')->setAlert(
394 $this->lng->txt('objref_failure_target_type') .
395 ': ' .
396 $this->lng->txt('obj_' . $this->target_type)
397 );
398 }
399
400 $this->object->setTargetId(
401 \ilObject::_lookupObjId((int) $form->getInput('target_id'))
402 );
403
404 return $ok;
405 }
406
407
411 public function updateObject()
412 {
413 $this->checkPermission('write');
414
415 $ilAccess = $this->access;
416 $form = $this->initForm();
417 if (
418 $form->checkInput() &&
419 $this->loadPropertiesFromSettingsForm($form)
420 ) {
421 $this->object->update();
422 ilUtil::sendSuccess($this->lng->txt('settings_saved'), true);
423 $this->ctrl->redirect($this, 'edit');
424 }
425 $form->setValuesByPost();
426 ilUtil::sendFailure($this->lng->txt('err_check_input'));
427 $this->editObject($form);
428 return true;
429 }
430
437 public function getTargetType()
438 {
439 return $this->target_type;
440 }
441
448 public function getReferenceType()
449 {
451 }
452
459 public function getTabs()
460 {
461 global $DIC;
462
463 $ilHelp = $DIC['ilHelp'];
464 $ilHelp->setScreenIdComponent($this->getReferenceType());
465
466 if ($this->access->checkAccess('write', '', $this->object->getRefId())) {
467 $this->tabs_gui->addTarget(
468 "settings",
469 $this->ctrl->getLinkTarget($this, "edit"),
470 array(),
471 ""
472 );
473 }
474 if ($this->access->checkAccess('edit_permission', '', $this->object->getRefId())) {
475 $this->tabs_gui->addTarget(
476 "perm_settings",
477 $this->ctrl->getLinkTargetByClass(array(get_class($this),'ilpermissiongui'), "perm"),
478 array("perm","info","owner"),
479 'ilpermissiongui'
480 );
481 }
482 }
483
487 public function getId()
488 {
489 return $this->obj_id;
490 }
491}
user()
Definition: user.php:4
$_GET["client_id"]
An exception for terminatinating execution or to throw for unit testing.
error($a_errmsg)
set error message @access public
firstEditObject()
show edit screen without info message
initForm($a_mode=self::MODE_EDIT)
Init title form.
editObject(ilPropertyFormGUI $form=null)
edit title
__construct($a_data, $a_id, $a_call_by_reference=true, $a_prepare_output=true)
Constructor.
loadPropertiesFromSettingsForm(\ilPropertyFormGUI $form)
initCreateForm($a_new_type)
Init object creation form.
Class ilObjectGUI Basic methods of all Output classes.
checkPermission($a_perm, $a_cmd="", $a_type="", $a_ref_id=null)
Check permission and redirect on error.
prepareOutput($a_show_subobjects=true)
prepare output
editObject()
edit object
setCreationMode($a_mode=true)
if true, a creation screen is displayed the current $_GET[ref_id] don't belong to the current class!...
Class ilObject Basic functions for all objects.
static _lookupObjId($a_id)
const TITLE_LENGTH
max length of object title
update()
update object in db
setTitle($a_title)
set object title
getRefId()
get reference id @access public
static _lookupType($a_id, $a_reference=false)
lookup object type
New PermissionGUI (extends from old ilPermission2GUI) RBAC related output.
This class represents a property form user interface.
getInput($a_post_var, $ensureValidation=true)
Returns the value of a HTTP-POST variable, identified by the passed id.
This class represents a property in a property form.
This class represents an option in a radio group.
This class represents a text property in a property form.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
global $ilCtrl
Definition: ilias.php:18
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $ilSetting
Definition: privfeed.php:17
settings()
Definition: settings.php:2
$ilUser
Definition: imgupload.php:18
$DIC
Definition: xapitoken.php:46