1<?php
2
3/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5/**
6* GUI class for personal workspace
7*
8* @author Jörg Lützenkirchen <luetzenkirchen@leifos.com>
9* @version $Id: class.ilPersonalDesktopGUI.php 26976 2010-12-16 13:24:38Z akill $
10*
11* @ilCtrl_Calls ilPersonalWorkspaceGUI: ilObjWorkspaceRootFolderGUI, ilObjWorkspaceFolderGUI
12* @ilCtrl_Calls ilPersonalWorkspaceGUI: ilObjectCopyGUI, ilObjFileGUI, ilObjBlogGUI
13* @ilCtrl_Calls ilPersonalWorkspaceGUI: ilObjTestVerificationGUI, ilObjExerciseVerificationGUI
14* @ilCtrl_Calls ilPersonalWorkspaceGUI: ilObjLinkResourceGUI, ilObjCourseVerificationGUI
15* @ilCtrl_Calls ilPersonalWorkspaceGUI: ilObjSCORMVerificationGUI
16*
17* @ingroup ServicesPersonalWorkspace
18*/
19class ilPersonalWorkspaceGUI
20{
21    /**
22     * @var ilCtrl
23     */
24    protected $ctrl;
25
26    /**
27     * @var ilLanguage
28     */
29    protected $lng;
30
31    /**
32     * @var ilHelpGUI
33     */
34    protected $help;
35
36    /**
37     * @var ilObjectDefinition
38     */
39    protected $obj_definition;
40
41    /**
42     * @var ilTemplate
43     */
44    protected $tpl;
45
46    /**
47     * @var ilMainMenuGUI
48     */
49    protected $main_menu;
50
51    /**
52     * @var ilObjUser
53     */
54    protected $user;
55
56    /**
57     * @var ilTabsGUI
58     */
59    protected $tabs;
60
61    /**
62     * @var ilLocatorGUI
63     */
64    protected $locator;
65
66    /**
67     * @var ilTree
68     */
69    protected $tree;
70    protected $node_id; // [int]
71
72    /**
73     * constructor
74     */
75    public function __construct()
76    {
77        global $DIC;
78
79        $this->ctrl = $DIC->ctrl();
80        $this->lng = $DIC->language();
81        $this->help = $DIC["ilHelp"];
82        $this->obj_definition = $DIC["objDefinition"];
83        $this->tpl = $DIC["tpl"];
84        $this->main_menu = $DIC["ilMainMenu"];
85        $this->user = $DIC->user();
86        $this->tabs = $DIC->tabs();
87        $this->locator = $DIC["ilLocator"];
88        $ilCtrl = $DIC->ctrl();
89        $lng = $DIC->language();
90        $ilHelp = $DIC["ilHelp"];
91
92        $lng->loadLanguageModule("wsp");
93
94        $this->initTree();
95
96        $ilCtrl->saveParameter($this, "wsp_id");
97
98        $this->node_id = (int) $_REQUEST["wsp_id"];
99        if (!$this->node_id || !$this->tree->isInTree($this->node_id)) {
100            $this->node_id = $this->tree->getRootId();
101        }
102    }
103
104    /**
105     * execute command
106     */
107    public function executeCommand()
108    {
109        $ilCtrl = $this->ctrl;
110        $objDefinition = $this->obj_definition;
111        $tpl = $this->tpl;
112        $ilMainMenu = $this->main_menu;
113
114        $ilCtrl->setReturn($this, "render");
115        $cmd = $ilCtrl->getCmd();
116
117        // new type
118        if ($_REQUEST["new_type"]) {
119            $class_name = $objDefinition->getClassName($_REQUEST["new_type"]);
120
121            // Only set the fixed cmdClass if the next class is different to
122            // the GUI class of the new object.
123            // An example:
124            // ilObjLinkResourceGUI tries to forward to ilLinkInputGUI (adding an internal link
125            // when creating a link resource)
126            // Without this fix, the cmdClass ilObjectCopyGUI would never be reached
127            if (strtolower($ilCtrl->getNextClass($this)) != strtolower("ilObj" . $class_name . "GUI")) {
128                $ilCtrl->setCmdClass("ilObj" . $class_name . "GUI");
129            }
130        }
131
132        // root node
133        $next_class = $ilCtrl->getNextClass();
134        if (!$next_class) {
135            $node = $this->tree->getNodeData($this->node_id);
136            $next_class = "ilObj" . $objDefinition->getClassName($node["type"]) . "GUI";
137            $ilCtrl->setCmdClass($next_class);
138        }
139
140        //  if we do this here the object can still change the breadcrumb
141        $this->renderLocator();
142
143        // current node
144        $class_path = $ilCtrl->lookupClassPath($next_class);
145        include_once($class_path);
146        $class_name = $ilCtrl->getClassForClasspath($class_path);
147        if ($_REQUEST["new_type"]) {
148            $gui = new $class_name(null, ilObject2GUI::WORKSPACE_NODE_ID, $this->node_id);
149            $gui->setCreationMode();
150        } else {
151            $gui = new $class_name($this->node_id, ilObject2GUI::WORKSPACE_NODE_ID, false);
152        }
153        $ilCtrl->forwardCommand($gui);
154
155        if ($ilMainMenu->getMode() == ilMainMenuGUI::MODE_FULL) {
156            $this->renderBack();
157        }
158
159        $tpl->setLocator();
160    }
161
162    /**
163     * Init personal tree
164     */
165    protected function initTree()
166    {
167        $ilUser = $this->user;
168
169        $user_id = $ilUser->getId();
170
171        include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
172        $this->tree = new ilWorkspaceTree($user_id);
173        if (!$this->tree->getRootId()) {
174            $this->tree->createTreeForUser($user_id);
175        }
176    }
177
178    protected function renderBack()
179    {
180        $lng = $this->lng;
181        $ilTabs = $this->tabs;
182        $ilCtrl = $this->ctrl;
183        $ilUser = $this->user;
184
185        $root = $this->tree->getNodeData($this->node_id);
186        if ($root["type"] != "wfld" && $root["type"] != "wsrt") {
187            // do not override existing back targets, e.g. public user profile gui
188            if (!$ilTabs->back_target) {
189                $owner = $this->tree->lookupOwner($this->node_id);
190                // workspace
191                if ($owner == $ilUser->getId()) {
192                    $parent = $this->tree->getParentNodeData($this->node_id);
193                    if ($parent["wsp_id"]) {
194                        if ($parent["type"] == "wsrt") {
195                            $class = "ilobjworkspacerootfoldergui";
196                        } else {
197                            $class = "ilobjworkspacefoldergui";
198                        }
199                        $ilCtrl->setParameterByClass($class, "wsp_id", $parent["wsp_id"]);
200                        $ilTabs->setBackTarget(
201                            $lng->txt("back"),
202                            $ilCtrl->getLinkTargetByClass($class, "")
203                        );
204                    }
205                }
206                // "shared by others"
207                else {
208                    $ilCtrl->setParameterByClass("ilobjworkspacerootfoldergui", "wsp_id", "");
209                    $ilCtrl->setParameterByClass("ilobjworkspacerootfoldergui", "user", $owner);
210                    $ilTabs->setBackTarget(
211                        $lng->txt("back"),
212                        $ilCtrl->getLinkTargetByClass("ilobjworkspacerootfoldergui", "share")
213                    );
214                }
215            }
216        }
217    }
218
219    /**
220     * Build locator for current node
221     */
222    protected function renderLocator()
223    {
224        $lng = $this->lng;
225        $ilCtrl = $this->ctrl;
226        $ilLocator = $this->locator;
227        $tpl = $this->tpl;
228        $objDefinition = $this->obj_definition;
229
230        $ilLocator->clearItems();
231
232        // we have no path if shared item
233        $path = $this->tree->getPathFull($this->node_id);
234        if ($path) {
235            foreach ($path as $node) {
236                $obj_class = "ilObj" . $objDefinition->getClassName($node["type"]) . "GUI";
237
238                $ilCtrl->setParameter($this, "wsp_id", $node["wsp_id"]);
239
240                switch ($node["type"]) {
241                    case "wsrt":
242                        $ilLocator->addItem($lng->txt("wsp_personal_workspace"), $ilCtrl->getLinkTargetByClass($obj_class, "render"));
243                        break;
244
245                    case "blog":
246                    case $objDefinition->isContainer($node["type"]):
247                        $ilLocator->addItem($node["title"], $ilCtrl->getLinkTargetByClass($obj_class, "render"));
248                        break;
249
250                    default:
251                        $ilLocator->addItem($node["title"], $ilCtrl->getLinkTargetByClass($obj_class, "edit"));
252                        break;
253                }
254            }
255        }
256
257        $ilCtrl->setParameter($this, "wsp_id", $this->node_id);
258    }
259}
260