ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilObjFileUploadDropzone.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
24 
29 {
32 
36  protected ilLanguage $language;
37  protected ilAccess $access;
38  protected UIServices $ui;
39  protected \ILIAS\Refinery\Factory $refinery;
40 
41  protected int $target_ref_id;
42  protected ?string $content;
43 
44  public function __construct(int $target_ref_id, string $content = null)
45  {
46  global $DIC;
47 
48  $this->definition = $DIC['objDefinition'];
49  $this->language = $DIC->language();
50  $this->language->loadLanguageModule('file');
51  $this->access = $DIC->access();
52  $this->ctrl = $DIC->ctrl();
53  $this->ui = $DIC->ui();
54  $this->refinery = $DIC->refinery();
55 
56  $this->upload_handler = new ilObjFileUploadHandlerGUI();
57  $this->target_ref_id = $target_ref_id;
58  $this->content = $content;
59  }
60 
61  private function isCopyrightSelectionActive(): bool
62  {
63  static $active;
64  if ($active === null) {
65  $active = ilMDSettings::_getInstance()->isCopyrightSelectionActive();
66  }
67  return $active;
68  }
69 
70  public function getDropzone(): FileDropzone
71  {
72  $this->ctrl->setParameterByClass(
73  ilObjFileGUI::class,
74  'ref_id',
75  $this->target_ref_id
76  );
77  $this->ctrl->setParameterByClass(
78  ilObjFileGUI::class,
79  'new_type',
81  );
82  $this->ctrl->setParameterByClass(
83  ilObjFileGUI::class,
86  );
87 
88  // Generate POST-URL
89  $post_url = $this->ctrl->getFormActionByClass(
90  [ilRepositoryGUI::class, ilObjFileGUI::class],
92  );
93  // reset new_type again
94  $this->ctrl->clearParameterByClass(ilObjFileGUI::class, 'new_type');
95 
96  // add input for copyright selection if enabled in the metadata settings
97  $additional_input = null;
98  if ($this->isCopyrightSelectionActive()) {
99  $additional_input = $this->getCopyrightSelectionInput('set_license_for_all_files');
100  }
101 
103  $dropzone = $this->ui->factory()->dropzone()->file()->wrapper(
104  $this->language->txt('upload_files'),
105  $post_url,
106  $this->ui->factory()->legacy($this->content ?? ''),
107  $this->ui->factory()->input()->field()->file(
108  $this->upload_handler,
109  $this->language->txt('upload_files'),
110  null,
111  $this->ui->factory()->input()->field()->group([
112  ilObjFileGUI::PARAM_TITLE => $this->ui->factory()->input()->field()->text(
113  $this->language->txt('title')
115  $this->getEmptyStringToNullTransformation()
116  ),
117  ilObjFileGUI::PARAM_DESCRIPTION => $this->ui->factory()->input()->field()->textarea(
118  $this->language->txt('description')
120  $this->getEmptyStringToNullTransformation()
121  ),
122  ])
123  )->withRequired(
124  true
125  )->withMaxFiles(
127  ),
128  $additional_input
129  )->withSubmitLabel(
130  $this->language->txt('upload_files')
131  );
132 
133  return $dropzone;
134  }
135 
136  public function isUploadAllowed(string $obj_type): bool
137  {
138  if ($this->definition->isContainer($obj_type) && $obj_type !== "orgu") {
139  return $this->access->checkAccess('create_file', '', $this->target_ref_id, 'file');
140  }
141 
142  return false;
143  }
144 
145  public function getDropzoneHtml(): string
146  {
147  return $this->ui->renderer()->render($this->getDropzone());
148  }
149 
150  protected function getUIFactory(): ILIAS\UI\Factory
151  {
152  return $this->ui->factory();
153  }
154 
155  protected function getLanguage(): \ilLanguage
156  {
157  return $this->language;
158  }
159 
160  protected function getRefinery(): \ILIAS\Refinery\Factory
161  {
162  return $this->refinery;
163  }
164 }
trait ilObjFileCopyrightInput
Class ChatMainBarProvider .
const OBJECT_TYPE
global $DIC
Definition: feed.php:28
parses the objects.xml it handles the xml-description of all ilias objects
Provides fluid interface to RBAC services.
Definition: UIServices.php:23
__construct(int $target_ref_id, string $content=null)
trait ilObjFileTransformation
const UPLOAD_ORIGIN_DROPZONE