ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilMMUploadHandlerGUI.php
Go to the documentation of this file.
1<?php
2
8use ILIAS\FileUpload\Handler\HandlerResult as HandlerResultInterface;
10use ILIAS\UI\Component\Input\Field\HandlerResult;
11
20{
21 public const MAX_FILE_SIZE = 2 * 1024 * 1024;
25 private $storage;
29 private $stakeholder;
30
31
35 public function __construct()
36 {
37 global $DIC;
39 $this->storage = $DIC['resource_storage'];
40 $this->stakeholder = new ilMMStorageStakeholder();
41 }
42
43
47 protected function getUploadResult() : HandlerResultInterface
48 {
49 $this->upload->process();
53 $array = $this->upload->getResults();
54 $result = end($array);
55 if ($result instanceof UploadResult && $result->isOK()) {
56 $i = $this->storage->manage()->upload($result, $this->stakeholder);
57 $status = HandlerResultInterface::STATUS_OK;
58 $identifier = $i->serialize();
59 $message = 'Upload ok';
60 } else {
61 $status = HandlerResultInterface::STATUS_FAILED;
62 $identifier = '';
63 $message = $result->getStatus()->getMessage();
64 }
65
66 return new BasicHandlerResult($this->getFileIdentifierParameterName(), $status, $identifier, $message);
67 }
68
69
70 protected function getRemoveResult(string $identifier) : HandlerResultInterface
71 {
72 $id = $this->storage->manage()->find($identifier);
73 if ($id !== null) {
74 $this->storage->manage()->remove($id, $this->stakeholder);
75
76 return new BasicHandlerResult($this->getFileIdentifierParameterName(), HandlerResultInterface::STATUS_OK, $identifier, 'file deleted');
77 } else {
78 return new BasicHandlerResult($this->getFileIdentifierParameterName(), HandlerResultInterface::STATUS_FAILED, $identifier, 'file not found');
79 }
80 }
81
82
83 protected function getInfoResult(string $identifier) : FileInfoResult
84 {
85 $id = $this->storage->manage()->find($identifier);
86 if ($id === null) {
87 return new BasicFileInfoResult($this->getFileIdentifierParameterName(), 'unknown', 'unknown', 0, 'unknown');
88 }
89 $r = $this->storage->manage()->getCurrentRevision($id)->getInformation();
90
91 return new BasicFileInfoResult($this->getFileIdentifierParameterName(), $identifier, $r->getTitle(), $r->getSize(), $r->getMimeType());
92 }
93
94
95 public function getInfoForExistingFiles(array $file_ids) : array
96 {
97 $infos = [];
98 foreach ($file_ids as $file_id) {
99 $id = $this->storage->manage()->find($file_id);
100 if ($id === null) {
101 continue;
102 }
103 $r = $this->storage->manage()->getCurrentRevision($id)->getInformation();
104
105 $infos[] = new BasicFileInfoResult($this->getFileIdentifierParameterName(), $file_id, $r->getTitle(), $r->getSize(), $r->getMimeType());
106 }
107
108 return $infos;
109 }
110}
$result
An exception for terminatinating execution or to throw for unit testing.
Class ilMMStorageStakeholder.
Class ilMMUploadHandlerGUI.
getInfoResult(string $identifier)
getInfoForExistingFiles(array $file_ids)
getRemoveResult(string $identifier)
__construct()
ilUIDemoFileUploadHandlerGUI constructor.
global $DIC
Definition: goto.php:24
$i
Definition: metadata.php:24
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$message
Definition: xapiexit.php:14