ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjItemGroupGUI.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 include_once("./Services/Object/classes/class.ilObject2GUI.php");
6 include_once("./Modules/ItemGroup/classes/class.ilObjItemGroup.php");
7 
21 {
25  protected function afterConstructor()
26  {
27  global $lng;
28 
29  $lng->loadLanguageModule("itgr");
30 
31  $this->ctrl->saveParameter($this, array("ref_id"));
32  }
33 
37  final function getType()
38  {
39  return "itgr";
40  }
41 
45  function executeCommand()
46  {
47  global $ilTabs, $lng, $ilAccess, $tpl, $ilCtrl, $ilLocator;
48 
49  $next_class = $this->ctrl->getNextClass($this);
50  $cmd = $this->ctrl->getCmd();
51 
52  switch($next_class)
53  {
54  case 'ilinfoscreengui':
55  $this->prepareOutput();
56  $this->addHeaderAction();
57  $this->infoScreen();
58  break;
59 
60  case 'ilpermissiongui':
61  $this->prepareOutput();
62  $ilTabs->activateTab("perm_settings");
63  $this->addHeaderAction();
64  include_once("Services/AccessControl/classes/class.ilPermissionGUI.php");
65  $perm_gui =& new ilPermissionGUI($this);
66  $ret = $this->ctrl->forwardCommand($perm_gui);
67  break;
68 
69  case "ilcommonactiondispatchergui":
70  include_once("Services/Object/classes/class.ilCommonActionDispatcherGUI.php");
72  $this->ctrl->forwardCommand($gui);
73  break;
74 
75  default:
76  $cmd = $this->ctrl->getCmd("listMaterials");
77  $this->prepareOutput();
78  $this->addHeaderAction();
79  $this->$cmd();
80  break;
81  }
82  }
83 
90  public function addLocatorItems()
91  {
92  global $ilLocator, $ilAccess;
93 
94  if (is_object($this->object) && $ilAccess->checkAccess("write", "", $this->object->getRefId()))
95  {
96  $ilLocator->addItem($this->object->getTitle(), $this->ctrl->getLinkTarget($this, "listMaterials"), "", $_GET["ref_id"]);
97  }
98  }
99 
100  protected function initCreationForms($a_new_type)
101  {
102  $forms = array(self::CFORM_NEW => $this->initCreateForm($a_new_type)
103  );
104 
105  return $forms;
106  }
107 
111  protected function afterSave(ilObject $a_new_object)
112  {
113  global $ilCtrl;
114 
115  ilUtil::sendSuccess($this->lng->txt("object_added"), true);
116  $ilCtrl->redirect($this, "listMaterials");
117  }
118 
126  public function listMaterials()
127  {
128  global $tree, $objDefinition, $ilTabs, $tpl, $ilAccess;
129 
130  $this->checkPermission("write");
131 
132  $ilTabs->activateTab("materials");
133 
134  // add new item
135  $parent_node = $tree->getNodeData($tree->getParentId($this->object->getRefId()));
136  $subtypes = $objDefinition->getCreatableSubObjects($parent_node['type'], ilObjectDefinition::MODE_REPOSITORY);
137  if($subtypes)
138  {
139  $subobj = array();
140  foreach($subtypes as $type => $sub_item)
141  {
142  if (!in_array($type, array("itgr", "sess")))
143  {
144  // #9950
145  if ($ilAccess->checkAccess("create_".$type, "", $parent_node["child"], $parent_node["type"]))
146  {
147  // #10787
148  $title = $this->lng->txt('obj_'.$type);
149  if ($sub_item["plugin"])
150  {
151  include_once("./Services/Component/classes/class.ilPlugin.php");
152  $title = ilPlugin::lookupTxt("rep_robj", $type, "obj_".$type);
153  }
154 
155  $subobj[] = array('value' => $type,
156  'title' => $title,
157  'img' => ilObject::_getIcon('', 'tiny', $type),
158  'alt' => $title);
159  }
160  }
161  }
162 
163  if(sizeof($subobj))
164  {
165  // add new object to parent container instead
166  $this->ctrl->setParameter($this, 'ref_id', $parent_node["child"]);
167  // $this->ctrl->setParameter($this, 'crtptrefid', $parent_node["child"]);
168  // force after creation callback
169  $this->ctrl->setParameter($this, 'crtcb', $this->object->getRefId());
170 
171  $this->lng->loadLanguageModule('cntr');
172  $this->tpl->setCreationSelector($this->ctrl->getFormAction($this),
173  $subobj, 'create', $this->lng->txt('add'));
174 
175  $this->ctrl->setParameter($this, 'ref_id', $this->object->getRefId());
176  // $this->ctrl->setParameter($this, 'crtptrefid', '');
177  $this->ctrl->setParameter($this, 'crtcb', '');
178  }
179  }
180 
181  include_once("./Modules/ItemGroup/classes/class.ilItemGroupItemsTableGUI.php");
182  $tab = new ilItemGroupItemsTableGUI($this, "listMaterials");
183  $tpl->setContent($tab->getHTML());
184  }
185 
189  public function saveItemAssignment()
190  {
191  global $ilCtrl;
192 
193  $this->checkPermission("write");
194 
195  include_once './Modules/ItemGroup/classes/class.ilItemGroupItems.php';
196 
197  $item_group_items = new ilItemGroupItems($this->object->getRefId());
198  $items = is_array($_POST['items'])
199  ? $_POST['items']
200  : array();
201  $items = ilUtil::stripSlashesArray($items);
202  $item_group_items->setItems($items);
203  $item_group_items->update();
204 
205  ilUtil::sendSuccess($this->lng->txt('msg_obj_modified'), true);
206  $ilCtrl->redirect($this, "listMaterials");
207  }
208 
209 
213  function getTemplate()
214  {
215  $this->tpl->getStandardTemplate();
216  }
217 
218 
222  function setTabs()
223  {
224  global $ilAccess, $ilTabs, $ilCtrl, $ilHelp, $lng, $tree;
225 
226  $ilHelp->setScreenIdComponent("itgr");
227 
228  $parent_ref_id = $tree->getParentId($this->object->getRefId());
229  $parent_obj_id = ilObject::_lookupObjId($parent_ref_id);
230  $parent_type = ilObject::_lookupType($parent_obj_id);
231 
232  include_once("./Services/Link/classes/class.ilLink.php");
233  $ilTabs->setBackTarget(
234  $lng->txt('obj_'.$parent_type),
235  ilLink::_getLink($parent_ref_id), "_top");
236 
237  if ($ilAccess->checkAccess("write", "", $this->object->getRefId()))
238  {
239  $ilTabs->addTab('materials',
240  $lng->txt('itgr_materials'),
241  $this->ctrl->getLinkTarget($this, 'listMaterials'));
242 
243  $ilTabs->addTab('settings',
244  $lng->txt('settings'),
245  $this->ctrl->getLinkTarget($this, 'edit'));
246  }
247 
248  if ($ilAccess->checkAccess("edit_permission", "", $this->object->getRefId()))
249  {
250  $ilTabs->addTab("perm_settings",
251  $lng->txt('perm_settings'),
252  $this->ctrl->getLinkTargetByClass(array(get_class($this),'ilpermissiongui'), "perm")
253  );
254  }
255  }
256 
257 
261  function _goto($a_target)
262  {
263  global $ilAccess, $ilErr, $lng, $tree;
264 
265  $targets = explode('_',$a_target);
266  $ref_id = $targets[0];
267  $par_id = $tree->getParentId($ref_id);
268 
269  if ($ilAccess->checkAccess("read", "", $par_id))
270  {
271  include_once("./Services/Link/classes/class.ilLink.php");
273  exit;
274  }
275  else if ($ilAccess->checkAccess("read", "", ROOT_FOLDER_ID))
276  {
277  ilUtil::sendFailure(sprintf($lng->txt("msg_no_perm_read_item"),
280  }
281 
282  $ilErr->raiseError($lng->txt("msg_no_perm_read"), $ilErr->FATAL);
283  }
284 
288  function gotoParent()
289  {
290  global $ilAccess, $ilErr, $lng, $tree;
291 
292  $ref_id = $this->object->getRefId();
293  $par_id = $tree->getParentId($ref_id);
294 
295  if ($ilAccess->checkAccess("read", "", $par_id))
296  {
297  include_once("./Services/Link/classes/class.ilLink.php");
299  exit;
300  }
301  }
302 
308  public function afterSaveCallback(ilObject $a_obj)
309  {
310  // add new object to materials
311  include_once './Modules/ItemGroup/classes/class.ilItemGroupItems.php';
312  $items = new ilItemGroupItems($this->object->getRefId());
313  $items->addItem($a_obj->getRefId());
314  $items->update();
315  }
316 
317 }
318 ?>