ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilPersonalWorkspaceGUI.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
19 {
20  protected $tree; // [ilTree]
21  protected $node_id; // [int]
22 
26  public function __construct()
27  {
28  global $ilCtrl, $lng, $ilHelp;
29 
30  $lng->loadLanguageModule("wsp");
31 
32  $this->initTree();
33 
34  $ilCtrl->saveParameter($this, "wsp_id");
35 
36  $this->node_id = $_REQUEST["wsp_id"];
37  if(!$this->node_id)
38  {
39  $this->node_id = $this->tree->getRootId();
40  }
41  }
42 
46  public function executeCommand()
47  {
48  global $ilCtrl, $lng, $objDefinition, $tpl;
49 
50  $ilCtrl->setReturn($this, "render");
51  $cmd = $ilCtrl->getCmd();
52 
53  // new type
54  if($_REQUEST["new_type"])
55  {
56  $class_name = $objDefinition->getClassName($_REQUEST["new_type"]);
57 
58  // Only set the fixed cmdClass if the next class is different to
59  // the GUI class of the new object.
60  // An example:
61  // ilObjLinkResourceGUI tries to forward to ilLinkInputGUI (adding an internal link
62  // when creating a link resource)
63  // Without this fix, the cmdClass ilObjectCopyGUI would never be reached
64  if (strtolower($ilCtrl->getNextClass($this)) != strtolower("ilObj".$class_name."GUI"))
65  {
66  $ilCtrl->setCmdClass("ilObj".$class_name."GUI");
67  }
68  }
69 
70  // root node
71  $next_class = $ilCtrl->getNextClass();
72  if(!$next_class)
73  {
74  $node = $this->tree->getNodeData($this->node_id);
75  $next_class = "ilObj".$objDefinition->getClassName($node["type"])."GUI";
76  $ilCtrl->setCmdClass($next_class);
77  }
78 
79  // if we do this here the object can still change the breadcrumb
80  $this->renderLocator();
81 
82  if(($cmd == "" || $cmd == "render" || $cmd == "view") && !$_REQUEST["new_type"])
83  {
84  $this->renderToolbar();
85  }
86 
87  // current node
88  $class_path = $ilCtrl->lookupClassPath($next_class);
89  include_once($class_path);
90  $class_name = $ilCtrl->getClassForClasspath($class_path);
91  if($_REQUEST["new_type"])
92  {
93  $gui = new $class_name(null, ilObject2GUI::WORKSPACE_NODE_ID, $this->node_id);
94  $gui->setCreationMode();
95  }
96  else
97  {
98  $gui = new $class_name($this->node_id, ilObject2GUI::WORKSPACE_NODE_ID, false);
99  }
100  $ilCtrl->forwardCommand($gui);
101 
102  $this->renderBack();
103  $tpl->setLocator();
104  }
105 
109  protected function initTree()
110  {
111  global $ilUser;
112 
113  $user_id = $ilUser->getId();
114 
115  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
116  $this->tree = new ilWorkspaceTree($user_id);
117  if(!$this->tree->getRootId())
118  {
119  $this->tree->createTreeForUser($user_id);
120  }
121  }
122 
123  protected function renderBack()
124  {
125  global $lng, $ilTabs, $ilCtrl, $ilUser;
126 
127  $root = $this->tree->getNodeData($this->node_id);
128  if($root["type"] != "wfld" && $root["type"] != "wsrt")
129  {
130  // do not override existing back targets, e.g. public user profile gui
131  if(!$ilTabs->back_target)
132  {
133  $owner = $this->tree->lookupOwner($this->node_id);
134  // workspace
135  if($owner == $ilUser->getId())
136  {
137  $parent = $this->tree->getParentNodeData($this->node_id);
138  if($parent["wsp_id"])
139  {
140  if($parent["type"] == "wsrt")
141  {
142  $class = "ilobjworkspacerootfoldergui";
143  }
144  else
145  {
146  $class = "ilobjworkspacefoldergui";
147  }
148  $ilCtrl->setParameterByClass($class, "wsp_id", $parent["wsp_id"]);
149  $ilTabs->setBackTarget($lng->txt("back"),
150  $ilCtrl->getLinkTargetByClass($class, ""));
151  }
152  }
153  // "shared by others"
154  else
155  {
156  $ilCtrl->setParameterByClass("ilobjworkspacerootfoldergui", "wsp_id", "");
157  $ilCtrl->setParameterByClass("ilobjworkspacerootfoldergui", "user", $owner);
158  $ilTabs->setBackTarget($lng->txt("back"),
159  $ilCtrl->getLinkTargetByClass("ilobjworkspacerootfoldergui", "share"));
160  }
161  }
162  }
163  }
164 
168  protected function renderToolbar()
169  {
170  global $lng, $ilCtrl, $objDefinition, $tpl, $ilSetting;
171 
172  $settings_map = array("blog" => "blogs",
173  "file" => "files",
174  "tstv" => "certificates",
175  "excv" => "certificates",
176  "webr" => "links");
177 
178  $root = $this->tree->getNodeData($this->node_id);
179  $subtypes = $objDefinition->getCreatableSubObjects($root["type"], ilObjectDefinition::MODE_WORKSPACE);
180  if($subtypes)
181  {
182  // :TODO: permission checks?
183  $subobj = array();
184  foreach(array_keys($subtypes) as $type)
185  {
186  if(isset($settings_map[$type]) && $ilSetting->get("disable_wsp_".$settings_map[$type]))
187  {
188  continue;
189  }
190 
191  $class = $objDefinition->getClassName($type);
192 
193  $subobj[] = array("value" => $type,
194  "title" => $lng->txt("wsp_type_".$type),
195  "img" => ilObject::_getIcon("", "tiny", $type),
196  "alt" => $lng->txt("wsp_type_".$type));
197  }
198 
199  $subobj = ilUtil::sortArray($subobj, "title", 1);
200 
201  $lng->loadLanguageModule("cntr");
202  $tpl->setCreationSelector($ilCtrl->getFormAction($this),
203  $subobj, "create", $lng->txt("add"));
204  }
205  }
206 
210  protected function renderLocator()
211  {
212  global $lng, $ilCtrl, $ilLocator, $tpl, $objDefinition;
213 
214  $ilLocator->clearItems();
215 
216  // we have no path if shared item
217  $path = $this->tree->getPathFull($this->node_id);
218  if($path)
219  {
220  foreach($path as $node)
221  {
222  $obj_class = "ilObj".$objDefinition->getClassName($node["type"])."GUI";
223 
224  $ilCtrl->setParameter($this, "wsp_id", $node["wsp_id"]);
225 
226  switch($node["type"])
227  {
228  case "wsrt":
229  $ilLocator->addItem($lng->txt("wsp_personal_workspace"), $ilCtrl->getLinkTargetByClass($obj_class, "render"));
230  break;
231 
232  case "blog":
233  case $objDefinition->isContainer($node["type"]):
234  $ilLocator->addItem($node["title"], $ilCtrl->getLinkTargetByClass($obj_class, "render"));
235  break;
236 
237  default:
238  $ilLocator->addItem($node["title"], $ilCtrl->getLinkTargetByClass($obj_class, "edit"));
239  break;
240  }
241  }
242  }
243 
244  $ilCtrl->setParameter($this, "wsp_id", $this->node_id);
245  }
246 }
247 
248 ?>