1<?php
2
3/* Copyright (c) 1998-2019 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5/**
6 * Workspace content renderer
7 *
8 * @author @leifos.de
9 * @ingroup
10 */
11class ilWorkspaceContentGUI
12{
13    /**
14     * @var int
15     */
16    protected $current_node;
17
18    /**
19     * @var bool
20     */
21    protected $admin;
22
23    /**
24     * @var object
25     */
26    protected $access_handler;
27
28    /**
29     * @var \ILIAS\DI\UIServices
30     */
31    protected $ui;
32
33    /**
34     * @var ilLanguage
35     */
36    protected $lng;
37
38    /**
39     * @var ilObjUser
40     */
41    protected $user;
42
43    /**
44     * @var ilObjectDefinition
45     */
46    protected $obj_definition;
47
48    /**
49     * @var ilCtrl
50     */
51    protected $ctrl;
52
53    /**
54     * @var ilWorkspaceFolderSorting
55     */
56    protected $folder_sorting;
57
58    /**
59     * Constructor
60     */
61    public function __construct(
62        $object_gui,
63        int $node_id,
64        bool $admin,
65        $access_handler,
66        \ILIAS\DI\UIServices $ui,
67        ilLanguage $lng,
68        ilObjUser $user,
69        ilObjectDefinition $obj_definition,
70        ilCtrl $ctrl,
71        ilWorkspaceFolderUserSettings $user_folder_settings
72    ) {
73        $this->current_node = $node_id;
74        $this->admin = $admin;
75        $this->access_handler = $access_handler;
76        $this->object_gui = $object_gui;
77        $this->ui = $ui;
78        $this->lng = $lng;
79        $this->user = $user;
80        $this->obj_definition = $obj_definition;
81        $this->ctrl = $ctrl;
82        $this->user_folder_settings = $user_folder_settings;
83
84        $this->folder_sorting = new ilWorkspaceFolderSorting();
85    }
86
87    /**
88     * Render
89     */
90    public function render()
91    {
92        $html = "";
93        $first = true;
94        foreach ($this->getItems() as $i) {
95            if ($first) {
96                $first = false;
97            } else {
98                $html .= $this->ui->renderer()->render($this->ui->factory()->divider()->horizontal());
99            }
100            $html .= $this->getItemHTML($i);
101        }
102
103        if ($this->admin) {
104            $tpl = new ilTemplate("tpl.admin_container.html", true, true, "Modules/WorkspaceFolder");
105            $tpl->setVariable("ITEMS", $html);
106            $tpl->setVariable("TXT_SELECT_ALL", $this->lng->txt("select_all"));
107            $html = $tpl->get();
108        }
109
110
111        // output sortation
112        $tree = new ilWorkspaceTree($this->user->getId());
113        $parent_id = $tree->getParentId($this->object_gui->ref_id);
114        $parent_effective = ($parent_id > 0)
115            ? $this->user_folder_settings->getEffectiveSortation($parent_id)
116            : 0;
117        $selected = $this->user_folder_settings->getSortation($this->object_gui->object->getId());
118        $sort_options = $this->folder_sorting->getOptionsByType($this->object_gui->object->getType(), $selected, $parent_effective);
119        $sortation = $this->ui->factory()->viewControl()->sortation($sort_options)
120            ->withTargetURL($this->ctrl->getLinkTarget($this->object_gui, "setSortation"), 'sortation')
121            ->withLabel($this->lng->txt("wfld_sortation"));
122
123
124        if ($first) {
125            return "";
126        }
127
128        $leg = $this->ui->factory()->legacy($html);
129
130        $panel = $this->ui->factory()->panel()->standard($this->lng->txt("content"), [$leg]);
131
132        if (method_exists($panel, "withViewControls")) {
133            $panel = $panel->withViewControls(array($sortation));
134        }
135
136
137
138        return $this->ui->renderer()->render($panel);
139    }
140
141    /**
142     *
143     */
144    protected function getItems()
145    {
146        $user = $this->user;
147
148        include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
149        $tree = new ilWorkspaceTree($user->getId());
150        $nodes = $tree->getChilds($this->current_node, "title");
151
152        if (sizeof($nodes)) {
153            include_once("./Services/Object/classes/class.ilObjectListGUIPreloader.php");
154            $preloader = new ilObjectListGUIPreloader(ilObjectListGUI::CONTEXT_WORKSPACE);
155            foreach ($nodes as $node) {
156                $preloader->addItem($node["obj_id"], $node["type"]);
157            }
158            $preloader->preload();
159            unset($preloader);
160        }
161
162        $this->shared_objects = $this->access_handler->getObjectsIShare();
163
164        $nodes = $this->folder_sorting->sortNodes($nodes, $this->user_folder_settings->getEffectiveSortation($this->object_gui->ref_id));
165
166        return $nodes;
167    }
168
169    /**
170     * Get item HTML
171     *
172     * @param
173     * @return
174     */
175    protected function getItemHTML($node)
176    {
177        $objDefinition = $this->obj_definition;
178        $ilCtrl = $this->ctrl;
179        //bug ilCertificateVerificationClassMap in 6 beta was cmiv instead of cmxv
180        if ($node["type"] == "cmiv") {
181            return "";
182        }
183
184        $class = $objDefinition->getClassName($node["type"]);
185        $location = $objDefinition->getLocation($node["type"]);
186        $full_class = "ilObj" . $class . "ListGUI";
187
188        include_once($location . "/class." . $full_class . ".php");
189        $item_list_gui = new $full_class(ilObjectListGUI::CONTEXT_WORKSPACE);
190
191        $item_list_gui->setDetailsLevel(ilObjectListGUI::DETAILS_ALL);
192        $item_list_gui->enableDelete(true);
193        $item_list_gui->enableCut(true);
194        $item_list_gui->enableSubscribe(false);
195        $item_list_gui->enableLink(false);
196        $item_list_gui->enablePath(false);
197        $item_list_gui->enableLinkedPath(false);
198        $item_list_gui->enableSearchFragments(true);
199        $item_list_gui->enableRelevance(false);
200        $item_list_gui->enableIcon(true);
201        $item_list_gui->enableTimings(false);
202        $item_list_gui->enableCheckbox($this->admin);
203        // $item_list_gui->setSeparateCommands(true);
204
205        $item_list_gui->enableNotes(true);
206        $item_list_gui->enableCopy($objDefinition->allowCopy($node["type"]));
207
208        if ($node["type"] == "file") {
209            $item_list_gui->enableRepositoryTransfer(true);
210        }
211
212        $item_list_gui->setContainerObject($this->object_gui);
213
214        if (in_array($node["type"], array("file", "blog"))) {
215            // add "share" link
216            $ilCtrl->setParameterByClass("ilworkspaceaccessgui", "wsp_id", $node["wsp_id"]);
217            $share_link = $ilCtrl->getLinkTargetByClass(array("ilObj" . $class . "GUI", "ilworkspaceaccessgui"), "share");
218            $item_list_gui->addCustomCommand($share_link, "wsp_permissions");
219
220            // show "shared" status
221            if (in_array($node["obj_id"], $this->shared_objects)) {
222                $item_list_gui->addCustomProperty($this->lng->txt("status"), $this->lng->txt("wsp_status_shared"), true, true);
223            }
224        }
225
226        $html = $item_list_gui->getListItemHTML(
227            $node["wsp_id"],
228            $node["obj_id"],
229            $node["title"],
230            $node["description"]
231        );
232
233        return $html;
234    }
235}
236