ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
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;
30  protected ilSetting $settings;
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  {
70  $lng = $this->lng;
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  {
150  $lng = $this->lng;
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;
182  $tpl = $this->tpl;
183 
184  $this->setTabs($a_cmd);
185  $ilTabs->setSubTabActive("cont_file_from_repository");
186  $ilCtrl->setParameter($this, "subCmd", "insertFromRepository");
187 
188  $exp = new ilPCFileItemFileSelectorGUI(
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;
207  $tpl = $this->tpl;
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  {
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->ctrl->returnToParent($this, "jump" . $this->hier_id);
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  {
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->ctrl->returnToParent($this, "jump" . $this->hier_id);
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->addTarget(
357  "cont_back",
358  $this->ctrl->getParentReturn($this),
359  "",
360  ""
361  );
362 
363  if ($a_cmd != "") {
364  $ilCtrl->setParameter($this, "subCmd", "insertNew");
365  $ilTabs->addSubTabTarget(
366  "cont_new_file",
367  $ilCtrl->getLinkTarget($this, $a_cmd),
368  $a_cmd
369  );
370 
371  $ilCtrl->setParameter($this, "subCmd", "insertFromRepository");
372  $ilTabs->addSubTabTarget(
373  "cont_file_from_repository",
374  $ilCtrl->getLinkTarget($this, $a_cmd),
375  $a_cmd
376  );
377  $ilCtrl->setParameter($this, "subCmd", "");
378 
379  if (!$ilSetting->get("disable_personal_workspace") &&
380  !$ilSetting->get("disable_wsp_files")) {
381  $ilCtrl->setParameter($this, "subCmd", "insertFromWorkspace");
382  $ilTabs->addSubTabTarget(
383  "cont_file_from_workspace",
384  $ilCtrl->getLinkTarget($this, $a_cmd),
385  $a_cmd
386  );
387  $ilCtrl->setParameter($this, "subCmd", "");
388  }
389  }
390  }
391 
395  public function moveItemDown(): void
396  {
397  $this->content_obj->moveItemDown();
398  $this->updateAndReturn();
399  }
400 
404  public function moveItemUp(): void
405  {
406  $this->content_obj->moveItemUp();
407  $this->updateAndReturn();
408  }
409 
413  public function cancelAddFile(): void
414  {
415  $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
416  }
417 }
$res
Definition: ltiservices.php:69
deleteItem()
delete a list item
getNodeData(int $a_node_id, ?int $a_tree_pk=null)
get all information of a node.
insertFromWorkspace(string $a_cmd="insert")
Insert file from personal workspace.
moveItemUp()
move list item up
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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...
insertNewItemAfter(int $a_file_ref_id=0)
insert new file item after another item
This class represents a file property in a property form.
newItemBefore()
insert new list item before current one
setTabs(string $a_cmd="")
output tabs
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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
User Interface for Editing of Page Content Objects (Paragraphs, Tables, ...)
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.
moveItemDown()
move list item down
Class ilPageObject Handles PageObjects of ILIAS Learning Modules (see ILIAS DTD)
Class ilObjFile.
Explorer for selecting a personal workspace item.
ilGlobalTemplateInterface $tpl
newFileItem()
insert new file item
insertNewItemBefore(int $a_file_ref_id=0)
insert new list item before current one
setRequired(bool $a_required)
cancelAddFile()
Cancel adding a file.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(ilPageObject $a_pg_obj, ?ilPageContent $a_content_obj, string $a_hier_id, string $a_pc_id="")
initAddFileForm(bool $a_before=true)
Init add file form.
global $ilSetting
Definition: privfeed.php:17
__construct(Container $dic, ilPlugin $plugin)
newItemAfter()
insert new list item after current one
$ilUser
Definition: imgupload.php:34
insertFromRepository(string $a_cmd)
Insert file from repository.