ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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
42 protected $existing_objects = array();
43
45 protected $target_type;
47 protected $reference_type;
49 protected $form;
50
55 public function __construct($a_data, $a_id, $a_call_by_reference = true, $a_prepare_output = true)
56 {
57 global $lng;
58 parent::__construct($a_data, $a_id,$a_call_by_reference,$a_prepare_output);
59
60 $lng->loadLanguageModule('objref');
61 }
62
71 public function executeCommand()
72 {
73 global $ilCtrl,$ilTabs;
74
75
76 if(isset($_GET['creation_mode']) && $_GET['creation_mode'] == self::MODE_CREATE)
77 {
78 $this->setCreationMode(true);
79 }
80
81 $next_class = $ilCtrl->getNextClass($this);
82 $cmd = $ilCtrl->getCmd();
83
84 $this->prepareOutput();
85
86 switch($next_class)
87 {
88 case "ilpropertyformgui":
89 $form = $this->initForm($this->creation_mode ? self::MODE_CREATE : self::MODE_EDIT);
90 $this->ctrl->forwardCommand($form);
91 break;
92
93 case 'ilpermissiongui':
94 $ilTabs->setTabActive('perm_settings');
95 include_once("Services/AccessControl/classes/class.ilPermissionGUI.php");
96 $ilCtrl->forwardCommand(new ilPermissionGUI($this));
97 break;
98
99 default:
100 if(!$cmd || $cmd == 'view')
101 {
102 $cmd = "edit";
103 }
104 $cmd .= "Object";
105 $this->$cmd();
106 break;
107 }
108 return true;
109 }
110
115 protected function addLocatorItems()
116 {
117 global $ilLocator;
118
119 if($this->object instanceof ilObject)
120 {
121 $ilLocator->addItem($this->object->getPresentationTitle(),$this->ctrl->getLinkTarget($this));
122 }
123 }
124
129 public function redirectObject()
130 {
131 global $ilCtrl;
132
133 $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $this->object->getTargetRefId());
134 $ilCtrl->redirectByClass("ilrepositorygui", "");
135 }
136
142 public function createObject()
143 {
144 global $ilUser,$ilAccess,$ilErr,$ilSetting;
145
146 $new_type = $_REQUEST["new_type"];
147 if(!$ilAccess->checkAccess("create_".$this->getReferenceType(),'',$_GET["ref_id"], $new_type))
148 {
149 $ilErr->raiseError($this->lng->txt("permission_denied"),$ilErr->MESSAGE);
150 }
151 $form = $this->initForm(self::MODE_CREATE);
152 $this->tpl->setContent($form->getHTML());
153 }
154
155
163 public function saveObject()
164 {
165 global $ilAccess;
166
167 if(!(int) $_REQUEST['target_id'])
168 {
169 ilUtil::sendFailure($this->lng->txt('select_one'));
170 $this->createObject();
171 return false;
172 }
173 if(!$ilAccess->checkAccess('visible','',(int) $_REQUEST['target_id']))
174 {
175 ilUtil::sendFailure($this->lng->txt('permission_denied'));
176 $this->createObject();
177 return false;
178 }
179
180 parent::saveObject();
181 }
182
183 protected function initCreateForm($a_new_type)
184 {
185 return $this->initForm(self::MODE_CREATE);
186 }
187
191 protected function afterSave(ilObject $a_new_object)
192 {
193 $target_obj_id = ilObject::_lookupObjId((int) $this->form->getInput('target_id'));
194 $a_new_object->setTargetId($target_obj_id);
195
196 $a_new_object->setTitleType($this->form->getInput('title_type'));
197 if($this->form->getInput('title_type') == ilContainerReference::TITLE_TYPE_CUSTOM)
198 {
199 $a_new_object->setTitle($this->form->getInput('title'));
200 }
201
202 $a_new_object->update();
203
204 ilUtil::sendSuccess($this->lng->txt("object_added"), true);
205 $this->ctrl->setParameter($this,'ref_id',$a_new_object->getRefId());
206 $this->ctrl->setParameter($this,'creation_mode',0);
207 $this->ctrl->redirect($this,'firstEdit');
208 }
209
213 protected function firstEditObject()
214 {
215 $this->editObject();
216 }
217
218 public function editReferenceObject()
219 {
220 $this->editObject();
221 }
222
228 public function editObject(ilPropertyFormGUI $form = null)
229 {
230 global $ilTabs;
231
232 $ilTabs->setTabActive('settings');
233
234 if(!$form instanceof ilPropertyFormGUI)
235 {
236 $form = $this->initForm();
237 }
238 $GLOBALS['tpl']->setContent($form->getHTML());
239 }
240
246 protected function initForm($a_mode = self::MODE_EDIT)
247 {
248 include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
249 include_once './Services/ContainerReference/classes/class.ilContainerReference.php';
250 $form = new ilPropertyFormGUI();
251
252 if ($a_mode == self::MODE_CREATE) {
253 $form->setTitle($this->lng->txt($this->getReferenceType(). '_new' ));
254
255 $this->ctrl->setParameter($this, 'creation_mode', $a_mode);
256 $this->ctrl->setParameter($this, 'new_type', $_REQUEST['new_type']);
257 }
258 else
259 {
260 $form->setTitle($this->lng->txt('edit'));
261 }
262
263 $form->setFormAction($this->ctrl->getFormAction($this));
264 if ($a_mode == self::MODE_CREATE)
265 {
266 $form->addCommandButton('save', $this->lng->txt('create'));
267 $form->addCommandButton('cancel', $this->lng->txt('cancel'));
268 }
269 else
270 {
271 $form->addCommandButton('update', $this->lng->txt('save'));
272 }
273
274 // title type
275 $ttype = new ilRadioGroupInputGUI($this->lng->txt('title'), 'title_type');
276 if ($a_mode == self::MODE_EDIT)
277 {
278 $ttype->setValue($this->object->getTitleType());
279 }
280 else
281 {
283 }
284
285 $reuse = new ilRadioOption($this->lng->txt('objref_reuse_title'));
287 $ttype->addOption($reuse);
288
289 $custom = new ilRadioOption($this->lng->txt('objref_custom_title'));
291
292 // title
293 $title = new ilTextInputGUI($this->lng->txt('title'),'title');
294 $title->setSize(min(40, ilObject::TITLE_LENGTH));
295 $title->setMaxLength(ilObject::TITLE_LENGTH);
296 $title->setRequired(true);
297
298 if($a_mode == self::MODE_EDIT)
299 {
300 $title->setValue($this->object->getTitle());
301 }
302
303 $custom->addSubItem($title);
304 $ttype->addOption($custom);
305 $form->addItem($ttype);
306
307 include_once("./Services/Form/classes/class.ilRepositorySelector2InputGUI.php");
308 $repo = new ilRepositorySelector2InputGUI($this->lng->txt("objref_edit_ref"), "target_id");
309 //$repo->setParent($this);
310 $repo->setRequired(true);
311 $repo->getExplorerGUI()->setSelectableTypes(array($this->getTargetType()));
312 $repo->getExplorerGUI()->setTypeWhiteList(array_merge(
313 array($this->getTargetType()),
314 array("root", "cat", "grp", "fold", "crs"))
315 );
316 $repo->setInfo($this->lng->txt($this->getReferenceType().'_edit_info'));
317
318 if($a_mode == self::MODE_EDIT)
319 {
320 $repo->getExplorerGUI()->setPathOpen($this->object->getTargetRefId());
321 $repo->setValue($this->object->getTargetRefId());
322 }
323
324 $form->addItem($repo);
325 $this->form = $form;
326 return $form;
327 }
328
332 public function updateObject()
333 {
334 global $ilAccess;
335 $form = $this->initForm();
336 if($form->checkInput())
337 {
338 $this->object->setTitleType($form->getInput('title_type'));
339 if($form->getInput('title_type') == ilContainerReference::TITLE_TYPE_CUSTOM)
340 {
341 $this->object->setTitle($form->getInput('title'));
342 }
343
344 if(!$ilAccess->checkAccess('visible','',(int) $form->getInput('target_id')) ||
345 ilObject::_lookupType($form->getInput('target_id'), true) != $this->target_type)
346 {
347 ilUtil::sendFailure($this->lng->txt('permission_denied'));
348 $this->editObject();
349 return false;
350 }
351 $this->checkPermission('write');
352
353 $target_obj_id = ilObject::_lookupObjId((int) $form->getInput('target_id'));
354 $this->object->setTargetId($target_obj_id);
355
356
357 $this->object->update();
358 ilUtil::sendSuccess($this->lng->txt('settings_saved'), true);
359 $this->ctrl->redirect($this,'edit');
360 }
361 $form->setValuesByPost();
362 ilUtil::sendFailure($this->lng->txt('err_check_input'));
363 $this->editObject($form);
364 return true;
365 }
366
373 public function getTargetType()
374 {
375 return $this->target_type;
376 }
377
384 public function getReferenceType()
385 {
387 }
388
392 public function getId()
393 {
394 return $this->obj_id;
395 }
396
397}
398?>
$_GET["client_id"]
An exception for terminatinating execution or to throw for unit testing.
firstEditObject()
show edit screen without info message
initForm($a_mode=self::MODE_EDIT)
Init title form.
addLocatorItems()
Add locator item @global ilLocatorGUI $ilLocator.
editObject(ilPropertyFormGUI $form=null)
edit title
__construct($a_data, $a_id, $a_call_by_reference=true, $a_prepare_output=true)
Constructor.
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.
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 sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
global $ilCtrl
Definition: ilias.php:18
global $ilSetting
Definition: privfeed.php:17
global $ilErr
Definition: raiseError.php:16
$cmd
Definition: sahs_server.php:35
$ilUser
Definition: imgupload.php:18