ILIAS  release_8 Revision v8.24
class.ilObjFileUploadHandlerGUI.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
28
34{
37 private array $class_path = [self::class];
38
39 public function __construct()
40 {
41 global $DIC;
42
43 $this->storage = $DIC->resourceStorage();
44 $this->stakeholder = new ilObjFileStakeholder($DIC->user()->getId());
45
47 }
48
52 public function getUploadURL(): string
53 {
54 return $this->ctrl->getLinkTargetByClass($this->class_path, self::CMD_UPLOAD, null, true);
55 }
56
60 public function getExistingFileInfoURL(): string
61 {
62 return $this->ctrl->getLinkTargetByClass($this->class_path, self::CMD_INFO, null, true);
63 }
64
69 public function getFileRemovalURL(): string
70 {
71 return $this->ctrl->getLinkTargetByClass($this->class_path, self::CMD_REMOVE, null, true);
72 }
73
78 protected function getUploadResult(): HandlerResult
79 {
80 $this->upload->register(new ilCountPDFPagesPreProcessors());
81 $this->upload->process();
82
83 $result_array = $this->upload->getResults();
84 $result = end($result_array);
85
86 if ($result instanceof UploadResult && $result->isOK()) {
87 $identifier = $this->storage->manage()->upload($result, $this->stakeholder)->serialize();
88 $status = HandlerResult::STATUS_OK;
89 $message = "file upload OK";
90 } else {
91 $identifier = '';
92 $status = HandlerResult::STATUS_FAILED;
93 $message = $result->getStatus()->getMessage();
94 }
95
96 return new BasicHandlerResult($this->getFileIdentifierParameterName(), $status, $identifier, $message);
97 }
98
103 protected function getRemoveResult(string $identifier): HandlerResult
104 {
105 if (null !== ($id = $this->storage->manage()->find($identifier))) {
106 $this->storage->manage()->remove($id, $this->stakeholder);
107 $status = HandlerResult::STATUS_OK;
108 $message = "file removal OK";
109 } else {
110 $status = HandlerResult::STATUS_OK;
111 $message = "file with identifier '$identifier' doesn't exist, nothing to do.";
112 }
113
114 return new BasicHandlerResult($this->getFileIdentifierParameterName(), $status, $identifier, $message);
115 }
116
121 public function getInfoResult(string $identifier): ?FileInfoResult
122 {
123 if (null !== ($id = $this->storage->manage()->find($identifier))) {
124 $revision = $this->storage->manage()->getCurrentRevision($id)->getInformation();
125 $title = $revision->getTitle();
126 $size = $revision->getSize();
127 $mime = $revision->getMimeType();
128 } else {
129 $title = $mime = 'unknown';
130 $size = 0;
131 }
132
133 return new BasicFileInfoResult($this->getFileIdentifierParameterName(), $identifier, $title, $size, $mime);
134 }
135
140 public function getInfoForExistingFiles(array $file_ids): array
141 {
142 $info_results = [];
143 foreach ($file_ids as $identifier) {
144 $info_results[] = $this->getInfoResult($identifier);
145 }
146
147 return $info_results;
148 }
149}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Class ilCountPDFPagesPreProcessors.
Class ilObjFileStakeholder.
getFileRemovalURL()
overrides parent method in order to provide an async URL.
__construct()
ilUIDemoFileUploadHandlerGUI constructor.
global $DIC
Definition: feed.php:28
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$message
Definition: xapiexit.php:32