ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilPCFileListGUI.php
Go to the documentation of this file.
1 <?php
2 
26 {
27  protected string $requested_file_ref_id;
28  protected ilObjUser $user;
29  protected ilTabsGUI $tabs;
30  protected ilTree $tree;
32  protected ilSetting $settings;
33 
34  public function __construct(
35  ilPageObject $a_pg_obj,
36  ?ilPageContent $a_content_obj,
37  string $a_hier_id,
38  string $a_pc_id = ""
39  ) {
40  global $DIC;
41 
42  $this->user = $DIC->user();
43  $this->tabs = $DIC->tabs();
44  $this->ctrl = $DIC->ctrl();
45  $this->tpl = $DIC["tpl"];
46  $this->tree = $DIC->repositoryTree();
47  $this->lng = $DIC->language();
48  $this->toolbar = $DIC->toolbar();
49  $this->settings = $DIC->settings();
50  parent::__construct($a_pg_obj, $a_content_obj, $a_hier_id, $a_pc_id);
51  $this->setCharacteristics(array("FileListItem" => $this->lng->txt("cont_FileListItem")));
52  $this->requested_file_ref_id = $this->request->getString("file_ref_id");
53  }
54 
58  public function executeCommand(): void
59  {
60  // get next class that processes or forwards current command
61  $next_class = $this->ctrl->getNextClass($this);
62 
63  $this->getCharacteristicsOfCurrentStyle(["flist_li"]); // scorm-2004
64 
65  // get current command
66  $cmd = $this->ctrl->getCmd();
67 
68  switch ($next_class) {
69  default:
70  $this->$cmd();
71  break;
72  }
73  }
74 
78  public function insert(ilPropertyFormGUI $a_form = null): void
79  {
80  $ilTabs = $this->tabs;
82 
83  if (in_array($sub_command, ["insertNew", "insertFromRepository", "insertFromWorkspace"])) {
84  $this->edit_repo->setSubCmd($sub_command);
85  }
86 
87  if (($sub_command == "") && $this->edit_repo->getSubCmd() != "") {
88  $sub_command = $this->edit_repo->getSubCmd();
89  }
90 
91  switch ($sub_command) {
92  case "insertFromWorkspace":
93  $this->insertFromWorkspace();
94  break;
95 
96  case "insertFromRepository":
97  $this->insertFromRepository();
98  break;
99 
100  case "selectFile":
101  $this->selectFile();
102  break;
103 
104  default:
105  $this->setTabs();
106  $ilTabs->setSubTabActive("cont_new_file");
107 
108  $this->displayValidationError();
109 
110  if ($a_form != null) {
111  $form = $a_form;
112  } else {
113  $form = $this->initEditForm("create");
114  }
115  $this->tpl->setContent($form->getHTML());
116  break;
117  }
118  }
119 
120  public function selectFile(): void
121  {
122  $ilTabs = $this->tabs;
123  $this->setTabs();
124  $ilTabs->setSubTabActive("cont_file_from_repository");
125 
126  $this->displayValidationError();
127  $form = $this->initEditForm("select_file");
128 
129  $this->tpl->setContent($form->getHTML());
130  }
131 
135  public function insertFromRepository(string $a_cmd = "insert"): void
136  {
137  $ilTabs = $this->tabs;
138  $ilCtrl = $this->ctrl;
139  $tpl = $this->tpl;
140 
141  if ($a_cmd == "insert") {
142  $this->setTabs();
143  } else {
144  $this->setItemTabs($a_cmd);
145  }
146 
147  $ilTabs->setSubTabActive("cont_file_from_repository");
148  $ilCtrl->setParameter($this, "subCmd", "insertFromRepository");
149 
150  $exp = new ilPCFileItemFileSelectorGUI(
151  $this,
152  $a_cmd,
153  $this,
154  $a_cmd,
155  "file_ref_id"
156  );
157  if (!$exp->handleCommand()) {
158  $tpl->setContent($exp->getHTML());
159  }
160  }
161 
165  public function insertFromWorkspace(
166  string $a_cmd = "insert"
167  ): void {
168  $ilTabs = $this->tabs;
169  $ilCtrl = $this->ctrl;
170  $tpl = $this->tpl;
172 
173  if ($a_cmd == "insert") {
174  $this->setTabs();
175  } else {
176  $this->setItemTabs($a_cmd);
177  }
178 
179  $ilTabs->setSubTabActive("cont_file_from_workspace");
180 
181  $exp = new ilWorkspaceExplorerGUI($ilUser->getId(), $this, $a_cmd, $this, $a_cmd, "fl_wsp_id");
182  $ilCtrl->setParameter($this, "subCmd", "selectFile");
183  $exp->setCustomLinkTarget($ilCtrl->getLinkTarget($this, $a_cmd));
184  $ilCtrl->setParameter($this, "subCmd", "insertFromWorkspace");
185  $exp->setTypeWhiteList(array("wsrt", "wfld", "file"));
186  $exp->setSelectableTypes(array("file"));
187  if ($exp->handleCommand()) {
188  return;
189  }
190  $tpl->setContent($exp->getHTML());
191  }
192 
196  public function create(): void
197  {
198  global $DIC;
199 
200  $mode = ($this->requested_file_ref_id != "")
201  ? "select_file"
202  : "create";
203  $form = $this->initEditForm($mode);
204  if (!$form->checkInput()) {
205  $form->setValuesByPost();
206  $this->insert($form);
207  return;
208  }
209 
210  // from personal workspace
211  if (substr($this->requested_file_ref_id, 0, 4) == "wsp_") {
212  $fileObj = new ilObjFile(substr($this->requested_file_ref_id, 4), false);
213  }
214  // upload
215  elseif ($this->requested_file_ref_id == "") {
216  $fileObj = new ilObjFile();
217  $fileObj->setType("file");
218  $fileObj->setTitle($_FILES["file"]["name"]);
219  $fileObj->setDescription("");
220  $fileObj->setFileName($_FILES["file"]["name"]);
221  $fileObj->setMode("filelist");
222  $fileObj->create();
223  // upload file to filesystem
224 
225  $upload = $DIC->upload();
226  if ($upload->hasBeenProcessed() !== true) {
227  $upload->process();
228  }
229 
230  $fileObj->getUploadFile(
231  $_FILES["file"]["tmp_name"],
232  $_FILES["file"]["name"]
233  );
234  }
235  // from repository
236  else {
237  $fileObj = new ilObjFile($this->requested_file_ref_id);
238  }
239  $this->setCurrentTextLang($form->getInput("flst_language"));
240 
241  //echo "::".is_object($this->dom).":";
242  $this->content_obj = new ilPCFileList($this->getPage());
243  $this->content_obj->create($this->pg_obj, $this->hier_id, $this->pc_id);
244  $this->content_obj->setListTitle(
245  $form->getInput("flst_title"),
246  $form->getInput("flst_language")
247  );
248  $this->content_obj->appendItem(
249  $fileObj->getId(),
250  $fileObj->getFileName(),
251  $fileObj->getFileType()
252  );
253 
254  $this->updated = $this->pg_obj->update();
255  if ($this->updated === true) {
256  $this->afterCreation();
257  } else {
258  $this->insert();
259  }
260  }
261 
262  public function afterCreation(): void
263  {
264  $this->pg_obj->stripHierIDs();
265  $this->pg_obj->addHierIDs();
266  $this->ctrl->setParameter($this, "hier_id", $this->content_obj->readHierId());
267  $this->ctrl->setParameter($this, "pc_id", $this->content_obj->readPCId());
268  $this->ctrl->redirect($this, "editFiles");
269  }
270 
274  public function edit(): void
275  {
276  $this->setTabs(false);
277 
278  $form = $this->initEditForm();
279  $this->tpl->setContent($form->getHTML());
280  }
281 
285  public function initEditForm(string $a_mode = "edit"): ilPropertyFormGUI
286  {
287  $lng = $this->lng;
288  $ilCtrl = $this->ctrl;
290 
291  $ti = null;
292  $si = null;
293  $form = new ilPropertyFormGUI();
294 
295  if ($a_mode != "add_file") {
296  // title
297  $ti = new ilTextInputGUI($lng->txt("title"), "flst_title");
298  $ti->setMaxLength(80);
299  $ti->setSize(40);
300  $form->addItem($ti);
301 
302  // language
304  $si = new ilSelectInputGUI($lng->txt("language"), "flst_language");
305  $si->setOptions($lang);
306  $form->addItem($si);
307  }
308 
309  if (in_array($a_mode, array("create", "add_file"))) {
310  // file
311  $fi = new ilFileInputGUI($lng->txt("file"), "file");
312  $fi->setRequired(true);
313  $form->addItem($fi);
314  } elseif (in_array($a_mode, array("select_file"))) {
315  // file
316  $ne = new ilNonEditableValueGUI($lng->txt("file"), "");
317 
318  $file_ref_id = (int) $this->requested_file_ref_id;
319  $fl_wsp_id = $this->request->getInt("fl_wsp_id");
320 
321  if ($file_ref_id > 0) {
322  $file_obj = new ilObjFile($file_ref_id);
323  if (is_object($file_obj)) {
324  // ref id as hidden input
325  $hi = new ilHiddenInputGUI("file_ref_id");
326  $hi->setValue($file_ref_id);
327  $form->addItem($hi);
328 
329  $ne->setValue($file_obj->getTitle());
330  }
331  } elseif ($fl_wsp_id > 0) {
332  // we need the object id for the instance
333  $tree = new ilWorkspaceTree($ilUser->getId());
334  $node = $tree->getNodeData($fl_wsp_id);
335 
336  $file_obj = new ilObjFile($node["obj_id"], false);
337  if (is_object($file_obj)) {
338  // ref id as hidden input
339  $hi = new ilHiddenInputGUI("file_ref_id");
340  $hi->setValue("wsp_" . (int) $node["obj_id"]);
341  $form->addItem($hi);
342 
343  $ne->setValue($file_obj->getTitle());
344  }
345  $this->tpl->parseCurrentBlock();
346  }
347 
348  $form->addItem($ne);
349  }
350 
351 
352  switch ($a_mode) {
353  case "edit":
354  $ti->setValue($this->content_obj->getListTitle());
355  $si->setValue($this->content_obj->getLanguage());
356  $form->addCommandButton("saveProperties", $lng->txt("save"));
357  $form->addCommandButton("cancelUpdate", $lng->txt("cancel"));
358  $form->setTitle($lng->txt("cont_edit_file_list_properties"));
359  break;
360 
361  case "create":
362  case "select_file":
363  if ($this->getCurrentTextLang() != "") {
364  $s_lang = $this->getCurrentTextLang();
365  } else {
366  $s_lang = $ilUser->getLanguage();
367  }
368  $si->setValue($s_lang);
369  $form->addCommandButton("create_flst", $lng->txt("save"));
370  $form->addCommandButton("cancelCreate", $lng->txt("cancel"));
371  $form->setTitle($lng->txt("cont_insert_file_list"));
372  break;
373 
374  case "add_file":
375  $form->addCommandButton("insertNewFileItem", $lng->txt("save"));
376  $form->addCommandButton("editFiles", $lng->txt("cancel"));
377  $form->setTitle($lng->txt("cont_insert_file_item"));
378  break;
379  }
380 
381  $form->setFormAction($ilCtrl->getFormAction($this));
382 
383  return $form;
384  }
385 
386 
390  public function saveProperties(): void
391  {
392  $form = $this->initEditForm("edit");
393  $form->checkInput();
394  $this->content_obj->setListTitle(
395  $form->getInput("flst_title"),
396  $form->getInput("flst_language")
397  );
398  $this->updated = $this->pg_obj->update();
399  if ($this->updated === true) {
400  $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
401  } else {
402  $this->pg_obj->addHierIDs();
403  $this->edit();
404  }
405  }
406 
410  public function editFiles(): void
411  {
412  $tpl = $this->tpl;
413  $ilToolbar = $this->toolbar;
414  $ilCtrl = $this->ctrl;
415  $lng = $this->lng;
416 
417  $this->setTabs(false);
418 
419  $ilToolbar->addButton(
420  $lng->txt("cont_add_file"),
421  $ilCtrl->getLinkTarget($this, "addFileItem")
422  );
423 
425  $fl = $this->content_obj;
426  $table_gui = new ilPCFileListTableGUI($this, "editFiles", $fl);
427  $tpl->setContent($table_gui->getHTML());
428  }
429 
433  public function setTabs(bool $a_create = true): void
434  {
435  $ilTabs = $this->tabs;
436  $ilCtrl = $this->ctrl;
437  $lng = $this->lng;
439 
440  if ($a_create) {
441  $cmd = "insert";
442 
443  $ilCtrl->setParameter($this, "subCmd", "insertNew");
444  $ilTabs->addSubTabTarget(
445  "cont_new_file",
446  $ilCtrl->getLinkTarget($this, $cmd),
447  $cmd
448  );
449 
450  $ilCtrl->setParameter($this, "subCmd", "insertFromRepository");
451  $ilTabs->addSubTabTarget(
452  "cont_file_from_repository",
453  $ilCtrl->getLinkTarget($this, $cmd),
454  $cmd
455  );
456  $ilCtrl->setParameter($this, "subCmd", "");
457 
458  if (!$ilSetting->get("disable_personal_workspace") &&
459  !$ilSetting->get("disable_wsp_files")) {
460  $ilCtrl->setParameter($this, "subCmd", "insertFromWorkspace");
461  $ilTabs->addSubTabTarget(
462  "cont_file_from_workspace",
463  $ilCtrl->getLinkTarget($this, $cmd),
464  $cmd
465  );
466  $ilCtrl->setParameter($this, "subCmd", "");
467  }
468  } else {
469  $ilTabs->setBackTarget(
470  $lng->txt("pg"),
471  $this->ctrl->getParentReturn($this)
472  );
473 
474  $ilTabs->addTarget(
475  "cont_ed_edit_files",
476  $ilCtrl->getLinkTarget($this, "editFiles"),
477  "editFiles",
478  get_class($this)
479  );
480 
481  $ilTabs->addTarget(
482  "cont_ed_edit_prop",
483  $ilCtrl->getLinkTarget($this, "edit"),
484  "edit",
485  get_class($this)
486  );
487  }
488  }
489 
494  public function addFileItem(): void
495  {
496  $ilCtrl = $this->ctrl;
497 
498  $files = $this->content_obj->getFileList();
499 
500  if (count($files) >= 1) {
501  $ilCtrl->setParameterByClass(
502  "ilpcfileitemgui",
503  "hier_id",
504  $files[count($files) - 1]["hier_id"]
505  );
506  $ilCtrl->setParameterByClass(
507  "ilpcfileitemgui",
508  "pc_id",
509  $files[count($files) - 1]["pc_id"]
510  );
511  $ilCtrl->redirectByClass("ilpcfileitemgui", "newItemAfter");
512  } else {
513  $ilCtrl->redirect($this, "newFileItem");
514  }
515  }
516 
520  public function deleteFileItem(): void
521  {
522  $ilCtrl = $this->ctrl;
523 
524  $fid = $this->request->getIntArray("fid");
525  if (count($fid) > 0) {
526  $this->content_obj->deleteFileItems(array_keys($fid));
527  }
528  $this->updated = $this->pg_obj->update();
529  $ilCtrl->redirect($this, "editFiles");
530  }
531 
535  public function savePositions(): void
536  {
537  $ilCtrl = $this->ctrl;
538 
539  $pos = $this->request->getIntArray("position");
540  if (count($pos) > 0) {
541  $this->content_obj->savePositions($pos);
542  }
543  $this->updated = $this->pg_obj->update();
544  $ilCtrl->redirect($this, "editFiles");
545  }
546 
550  public function savePositionsAndClasses(): void
551  {
552  $ilCtrl = $this->ctrl;
553 
554  $pos = $this->request->getIntArray("position");
555  $class = $this->request->getStringArray("class");
556  if (count($pos) > 0) {
557  $this->content_obj->savePositions($pos);
558  }
559  if (count($class) > 0) {
560  $this->content_obj->saveStyleClasses($class);
561  }
562  $this->updated = $this->pg_obj->update();
563  $ilCtrl->redirect($this, "editFiles");
564  }
565 
569  public function checkStyleSelection(): bool
570  {
571  // check whether there is more than one style class
572  $chars = $this->getCharacteristics();
573 
574  $classes = $this->content_obj->getAllClasses();
575  if (count($chars) > 1) {
576  return true;
577  }
578  foreach ($classes as $class) {
579  if ($class != "" && $class != "FileListItem") {
580  return true;
581  }
582  }
583  return false;
584  }
585 
586  //
587  //
588  // New file item
589  //
590  //
591 
595  public function newFileItem(): void
596  {
597  $ilTabs = $this->tabs;
598 
600  if (in_array($sub_command, ["insertNew", "insertFromRepository", "insertFromWorkspace"])) {
601  $this->edit_repo->setSubCmd($sub_command);
602  }
603 
604  if (($sub_command == "") && $this->edit_repo->getSubCmd() != "") {
605  $sub_command = $this->edit_repo->getSubCmd();
606  }
607 
608  switch ($sub_command) {
609  case "insertFromWorkspace":
610  $this->insertFromWorkspace("newFileItem");
611  break;
612 
613  case "insertFromRepository":
614  $this->insertFromRepository("newFileItem");
615  break;
616 
617  case "selectFile":
618  $this->insertNewFileItem($this->requested_file_ref_id);
619  break;
620 
621  default:
622  $this->setItemTabs("newFileItem");
623  $ilTabs->setSubTabActive("cont_new_file");
624 
625  $this->displayValidationError();
626 
627  $form = $this->initEditForm("add_file");
628  $this->tpl->setContent($form->getHTML());
629  break;
630  }
631  }
632 
636  public function insertNewFileItem(int $a_file_ref_id = 0): void
637  {
639 
640  $fl_wsp_id = $this->request->getInt("fl_wsp_id");
641 
642  // from personal workspace
643  if ($fl_wsp_id > 0) {
644  // we need the object id for the instance
645  $tree = new ilWorkspaceTree($ilUser->getId());
646  $node = $tree->getNodeData($fl_wsp_id);
647 
648  $file_obj = new ilObjFile($node["obj_id"], false);
649  }
650  // upload
651  elseif ($a_file_ref_id == 0) {
652  $file_obj = $this->createFileItem();
653  }
654  // from repository
655  else {
656  $file_obj = new ilObjFile($a_file_ref_id);
657  }
658  if (is_object($file_obj)) {
659  $this->content_obj->appendItem(
660  $file_obj->getId(),
661  $file_obj->getTitle(),
662  $file_obj->getFileType()
663  );
664  $this->updated = $this->pg_obj->update();
665  if ($this->updated === true) {
666  //$this->ctrl->returnToParent($this, "jump".$this->hier_id);
667  $this->ctrl->redirect($this, "editFiles");
668  }
669  }
670 
671  $this->newFileItem();
672  }
673 
677  public function createFileItem(): ?ilObjFile
678  {
679  global $DIC;
680 
681  $lng = $this->lng;
682 
683  if ($_FILES["file"]["name"] == "") {
684  throw new ilCOPageFileHandlingException($lng->txt("upload_error_file_not_found"));
685  }
686 
687  $form = $this->initEditForm();
688  // see #22541
689  // $form->checkInput();
690 
691  $fileObj = new ilObjFile();
692  $fileObj->setType("file");
693  $fileObj->setTitle($_FILES["file"]["name"]);
694  $fileObj->setDescription("");
695  $fileObj->setFileName($_FILES["file"]["name"]);
696  $fileObj->setMode("filelist");
697  $fileObj->create();
698  // upload file to filesystem
699 
700  $upload = $DIC->upload();
701  if ($upload->hasBeenProcessed() !== true) {
702  $upload->process();
703  }
704 
705  $fileObj->getUploadFile(
706  $_FILES["file"]["tmp_name"],
707  $_FILES["file"]["name"]
708  );
709 
710  return $fileObj;
711  }
712 
713 
717  public function setItemTabs(string $a_cmd = ""): void
718  {
719  $ilTabs = $this->tabs;
720  $ilCtrl = $this->ctrl;
722 
723  $ilTabs->addTarget(
724  "cont_back",
725  $this->ctrl->getParentReturn($this),
726  "",
727  ""
728  );
729 
730  if ($a_cmd != "") {
731  $ilCtrl->setParameter($this, "subCmd", "insertNew");
732  $ilTabs->addSubTabTarget(
733  "cont_new_file",
734  $ilCtrl->getLinkTarget($this, $a_cmd),
735  $a_cmd
736  );
737 
738  $ilCtrl->setParameter($this, "subCmd", "insertFromRepository");
739  $ilTabs->addSubTabTarget(
740  "cont_file_from_repository",
741  $ilCtrl->getLinkTarget($this, $a_cmd),
742  $a_cmd
743  );
744  $ilCtrl->setParameter($this, "subCmd", "");
745 
746  if (!$ilSetting->get("disable_personal_workspace") &&
747  !$ilSetting->get("disable_wsp_files")) {
748  $ilCtrl->setParameter($this, "subCmd", "insertFromWorkspace");
749  $ilTabs->addSubTabTarget(
750  "cont_file_from_workspace",
751  $ilCtrl->getLinkTarget($this, $a_cmd),
752  $a_cmd
753  );
754  $ilCtrl->setParameter($this, "subCmd", "");
755  }
756  }
757  }
758 }
edit()
edit properties form
newFileItem()
New file item (called, if there is no file item in an existing)
getNodeData(int $a_node_id, ?int $a_tree_pk=null)
get all information of a node.
getCharacteristicsOfCurrentStyle(array $a_type)
Get characteristics of current style and call setCharacteristics, if style is given.
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...
redirect(object $a_gui_obj, string $a_cmd=null, string $a_anchor=null, bool $is_async=false)
__construct(ilPageObject $a_pg_obj, ?ilPageContent $a_content_obj, string $a_hier_id, string $a_pc_id="")
createFileItem()
insert new file item
setTabs(bool $a_create=true)
Set Tabs.
deleteFileItem()
Delete file items from list.
This class represents a file property in a property form.
insertFromRepository(string $a_cmd="insert")
Insert file from repository.
insertFromWorkspace(string $a_cmd="insert")
Insert file from personal workspace.
setParameterByClass(string $a_class, string $a_parameter, $a_value)
setCharacteristics(array $a_chars)
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
insertNewFileItem(int $a_file_ref_id=0)
insert new file item after another item
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
User Interface for Editing of Page Content Objects (Paragraphs, Tables, ...)
executeCommand()
execute command
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.
Class ilPageObject Handles PageObjects of ILIAS Learning Modules (see ILIAS DTD)
Class ilObjFile.
Explorer for selecting a personal workspace item.
ilGlobalTemplateInterface $tpl
setItemTabs(string $a_cmd="")
output tabs
setCurrentTextLang(string $lang_key)
setRequired(bool $a_required)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$lang
Definition: xapiexit.php:26
checkStyleSelection()
Checks whether style selection shoudl be available or not.
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 $ilSetting
Definition: privfeed.php:17
__construct(Container $dic, ilPlugin $plugin)
$ilUser
Definition: imgupload.php:34
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
initEditForm(string $a_mode="edit")
Init edit form.
create()
create new file list in dom and update page in db
insert(ilPropertyFormGUI $a_form=null)
insert new file list form
saveProperties()
save table properties in db and return to page edit screen
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
savePositionsAndClasses()
Save positions of file items and style classes.
addFileItem()
Add file item.
savePositions()
Save positions of file items.