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