ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilPCFileItemGUI.php
Go to the documentation of this file.
1<?php
2
25{
27 protected ilTabsGUI $tabs;
28 protected ilObjUser $user;
29 protected ilTree $tree;
31
32
33 public function __construct(
34 ilPageObject $a_pg_obj,
35 ?ilPageContent $a_content_obj,
36 string $a_hier_id,
37 string $a_pc_id = ""
38 ) {
39 global $DIC;
40
41 $this->lng = $DIC->language();
42 $this->tabs = $DIC->tabs();
43 $this->ctrl = $DIC->ctrl();
44 $this->user = $DIC->user();
45 $this->tpl = $DIC["tpl"];
46 $this->tree = $DIC->repositoryTree();
47 $this->settings = $DIC->settings();
48 parent::__construct($a_pg_obj, $a_content_obj, $a_hier_id, $a_pc_id);
49 }
50
51 public function executeCommand(): void
52 {
53 // get next class that processes or forwards current command
54 $next_class = $this->ctrl->getNextClass($this);
55
56 // get current command
57 $cmd = $this->ctrl->getCmd();
58 switch ($next_class) {
59 default:
60 $this->$cmd();
61 break;
62 }
63 }
64
68 public function newFileItem(): bool
69 {
71
72 if ($_FILES["file"]["name"] == "") {
73 throw new ilCOPageFileHandlingException($lng->txt("upload_error_file_not_found"));
74 }
75
76 $form = $this->initAddFileForm();
77 $form->checkInput();
78
79 $fileObj = new ilObjFile();
80 $fileObj->setType("file");
81 $fileObj->setTitle($_FILES["file"]["name"]);
82 $fileObj->setDescription("");
83 $fileObj->setFileName($_FILES["file"]["name"]);
84 $fileObj->setMode("filelist");
85 $fileObj->create();
86 // upload file to filesystem
87 global $DIC;
88 $upload = $DIC->upload();
89 if ($upload->hasBeenProcessed() !== true) {
90 $upload->process();
91 }
92 $fileObj->getUploadFile(
93 $_FILES["file"]["tmp_name"],
94 $_FILES["file"]["name"]
95 );
96
97 $this->file_object = $fileObj;
98 return true;
99 }
100
101
105 public function newItemAfter(): void
106 {
107 $ilTabs = $this->tabs;
108
110
111 if (in_array($sub_command, ["insertNew", "insertFromRepository", "insertFromWorkspace"])) {
112 $this->edit_repo->setSubCmd($sub_command);
113 }
114
115 if (($sub_command == "") && $this->edit_repo->getSubCmd() != "") {
116 $sub_command = $this->edit_repo->getSubCmd();
117 }
118
119 switch ($sub_command) {
120 case "insertFromWorkspace":
121 $this->insertFromWorkspace("newItemAfter");
122 break;
123
124 case "insertFromRepository":
125 $this->insertFromRepository("newItemAfter");
126 break;
127
128 case "selectFile":
129 $this->insertNewItemAfter(
130 $this->request->getInt("file_ref_id")
131 );
132 break;
133
134 default:
135 $this->setTabs("newItemAfter");
136 $ilTabs->setSubTabActive("cont_new_file");
137
138 $this->displayValidationError();
139 $form = $this->initAddFileForm(false);
140 $this->tpl->setContent($form->getHTML());
141 break;
142 }
143 }
144
148 public function initAddFileForm(bool $a_before = true): ilPropertyFormGUI
149 {
151 $ilCtrl = $this->ctrl;
152
153 $form = new ilPropertyFormGUI();
154
155 // file
156 $fi = new ilFileInputGUI($lng->txt("file"), "file");
157 $fi->setRequired(true);
158 $form->addItem($fi);
159
160 if ($a_before) {
161 $form->addCommandButton("insertNewItemBefore", $lng->txt("save"));
162 } else {
163 $form->addCommandButton("insertNewItemAfter", $lng->txt("save"));
164 }
165 $form->addCommandButton("cancelAddFile", $lng->txt("cancel"));
166
167 $form->setTitle($lng->txt("cont_insert_file_item"));
168
169 $form->setFormAction($ilCtrl->getFormAction($this));
170
171 return $form;
172 }
173
174
178 public function insertFromRepository(string $a_cmd): void
179 {
180 $ilTabs = $this->tabs;
181 $ilCtrl = $this->ctrl;
183
184 $this->setTabs($a_cmd);
185 $ilTabs->setSubTabActive("cont_file_from_repository");
186 $ilCtrl->setParameter($this, "subCmd", "insertFromRepository");
187
189 $this,
190 $a_cmd,
191 $this,
192 $a_cmd,
193 "file_ref_id"
194 );
195 if (!$exp->handleCommand()) {
196 $tpl->setContent($exp->getHTML());
197 }
198 }
199
203 public function insertFromWorkspace(string $a_cmd = "insert"): void
204 {
205 $ilTabs = $this->tabs;
206 $ilCtrl = $this->ctrl;
208
209 $this->setTabs($a_cmd);
210 $ilTabs->setSubTabActive("cont_file_from_workspace");
211
212 $exp = new ilWorkspaceExplorerGUI($this->user->getId(), $this, $a_cmd, $this, $a_cmd, "fl_wsp_id");
213 $ilCtrl->setParameter($this, "subCmd", "selectFile");
214 $exp->setCustomLinkTarget($ilCtrl->getLinkTarget($this, $a_cmd));
215 $ilCtrl->setParameter($this, "subCmd", "insertFromWorkspace");
216 $exp->setTypeWhiteList(array("wsrt", "wfld", "file"));
217 $exp->setSelectableTypes(array("file"));
218 if ($exp->handleCommand()) {
219 return;
220 }
221 $tpl->setContent($exp->getHTML());
222 }
223
227 public function insertNewItemAfter(int $a_file_ref_id = 0): void
228 {
229 $ilUser = $this->user;
230
231 $fl_wsp_id = $this->request->getInt("fl_wsp_id");
232
233 $res = true;
234 if ($fl_wsp_id > 0) {
235 // we need the object id for the instance
236 $tree = new ilWorkspaceTree($ilUser->getId());
237 $node = $tree->getNodeData($fl_wsp_id);
238
239 $this->file_object = new ilObjFile($node["obj_id"], false);
240 } elseif ($a_file_ref_id == 0) {
241 $res = $this->newFileItem();
242 } else {
243 $this->file_object = new ilObjFile($a_file_ref_id);
244 }
245 if ($res) {
246 $this->content_obj->newItemAfter(
247 $this->file_object->getId(),
248 $this->file_object->getFileName(),
249 $this->file_object->getFileType()
250 );
251 $this->updated = $this->pg_obj->update();
252 if ($this->updated === true) {
253 $this->redirectToFileList();
254 }
255 }
256
257 $this->newItemAfter();
258 }
259
263 public function newItemBefore(): void
264 {
265 $ilTabs = $this->tabs;
266
268
269 if (in_array($sub_command, ["insertNew", "insertFromRepository", "insertFromWorkspace"])) {
270 $this->edit_repo->setSubCmd($sub_command);
271 }
272
273 if (($sub_command == "") && $this->edit_repo->getSubCmd() != "") {
274 $sub_command = $this->edit_repo->getSubCmd();
275 }
276
277 switch ($sub_command) {
278 case "insertFromWorkspace":
279 $this->insertFromWorkspace("newItemBefore");
280 break;
281
282 case "insertFromRepository":
283 $this->insertFromRepository("newItemBefore");
284 break;
285
286 case "selectFile":
287 $this->insertNewItemBefore(
288 $this->request->getInt("file_ref_id")
289 );
290 break;
291
292 default:
293 $this->setTabs("newItemBefore");
294 $ilTabs->setSubTabActive("cont_new_file");
295
296 $this->displayValidationError();
297 $form = $this->initAddFileForm(true);
298 $this->tpl->setContent($form->getHTML());
299 }
300 }
301
305 public function insertNewItemBefore(int $a_file_ref_id = 0): void
306 {
307 $ilUser = $this->user;
308
309 $res = true;
310
311 $fl_wsp_id = $this->request->getInt("fl_wsp_id");
312 if ($fl_wsp_id > 0) {
313 // we need the object id for the instance
314 $tree = new ilWorkspaceTree($ilUser->getId());
315 $node = $tree->getNodeData($fl_wsp_id);
316
317 $this->file_object = new ilObjFile($node["obj_id"], false);
318 } elseif ($a_file_ref_id == 0) {
319 $res = $this->newFileItem();
320 } else {
321 $this->file_object = new ilObjFile($a_file_ref_id);
322 }
323 if ($res) {
324 $this->content_obj->newItemBefore(
325 $this->file_object->getId(),
326 $this->file_object->getTitle(),
327 $this->file_object->getFileType()
328 );
329 $this->updated = $this->pg_obj->update();
330 if ($this->updated === true) {
331 $this->redirectToFileList();
332 }
333 }
334
335 $this->newItemBefore();
336 }
337
341 public function deleteItem(): void
342 {
343 $this->content_obj->deleteItem();
344 $this->updateAndReturn();
345 }
346
350 public function setTabs(string $a_cmd = ""): void
351 {
352 $ilTabs = $this->tabs;
353 $ilCtrl = $this->ctrl;
355
356 $ilTabs->setBackTarget(
357 $this->lng->txt("back"),
358 $this->ctrl->getLinkTarget($this, "redirectToFileList")
359 );
360
361 if ($a_cmd != "") {
362 $ilCtrl->setParameter($this, "subCmd", "insertNew");
363 $ilTabs->addSubTabTarget(
364 "cont_new_file",
365 $ilCtrl->getLinkTarget($this, $a_cmd),
366 $a_cmd
367 );
368
369 $ilCtrl->setParameter($this, "subCmd", "insertFromRepository");
370 $ilTabs->addSubTabTarget(
371 "cont_file_from_repository",
372 $ilCtrl->getLinkTarget($this, $a_cmd),
373 $a_cmd
374 );
375 $ilCtrl->setParameter($this, "subCmd", "");
376
377 if (!$ilSetting->get("disable_personal_workspace") &&
378 !$ilSetting->get("disable_wsp_files")) {
379 $ilCtrl->setParameter($this, "subCmd", "insertFromWorkspace");
380 $ilTabs->addSubTabTarget(
381 "cont_file_from_workspace",
382 $ilCtrl->getLinkTarget($this, $a_cmd),
383 $a_cmd
384 );
385 $ilCtrl->setParameter($this, "subCmd", "");
386 }
387 }
388 }
389
393 public function moveItemDown(): void
394 {
395 $this->content_obj->moveItemDown();
396 $this->updateAndReturn();
397 }
398
402 public function moveItemUp(): void
403 {
404 $this->content_obj->moveItemUp();
405 $this->updateAndReturn();
406 }
407
411 public function cancelAddFile(): void
412 {
413 $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
414 }
415
416 public function redirectToFileList(): void
417 {
418 $this->pg_obj->stripHierIDs();
419 $this->pg_obj->addHierIDs();
420 $this->ctrl->setParameterByClass(ilPCFileListGUI::class, "pc_id", $this->content_obj->getListPCId());
421 $this->ctrl->redirectByClass(ilPCFileListGUI::class, "editFiles");
422 }
423
424}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class represents a file property in a property form.
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
Class ilObjFile.
User class.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
cancelAddFile()
Cancel adding a file.
insertFromRepository(string $a_cmd)
Insert file from repository.
initAddFileForm(bool $a_before=true)
Init add file form.
newItemBefore()
insert new list item before current one
newItemAfter()
insert new list item after current one
insertFromWorkspace(string $a_cmd="insert")
Insert file from personal workspace.
insertNewItemBefore(int $a_file_ref_id=0)
insert new list item before current one
moveItemDown()
move list item down
newFileItem()
insert new file item
setTabs(string $a_cmd="")
output tabs
deleteItem()
delete a list item
moveItemUp()
move list item up
insertNewItemAfter(int $a_file_ref_id=0)
insert new file item after another item
__construct(ilPageObject $a_pg_obj, ?ilPageContent $a_content_obj, string $a_hier_id, string $a_pc_id="")
User Interface for Editing of Page Content Objects (Paragraphs, Tables, ...)
ilGlobalTemplateInterface $tpl
Content object of ilPageObject (see ILIAS DTD).
Class ilPageObject Handles PageObjects of ILIAS Learning Modules (see ILIAS DTD)
This class represents a property form user interface.
ILIAS Setting Class.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
getNodeData(int $a_node_id, ?int $a_tree_pk=null)
get all information of a node.
Explorer for selecting a personal workspace item.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setContent(string $a_html)
Sets content for standard template.
$res
Definition: ltiservices.php:69
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $ilSetting
Definition: privfeed.php:31
global $DIC
Definition: shib_login.php:26