ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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
25 private $storage;
29 private $stakeholder;
30
31
35 public function __construct()
36 {
38 $this->storage = new Services();
39 $this->stakeholder = new ilMMStorageStakeholder();
40 }
41
42
46 protected function getUploadResult() : HandlerResultInterface
47 {
48 $this->upload->process();
52 $array = $this->upload->getResults();
53 $result = end($array);
54 if ($result instanceof UploadResult && $result->isOK()) {
55 $i = $this->storage->upload($result, $this->stakeholder);
56 $status = HandlerResultInterface::STATUS_OK;
57 $identifier = $i->serialize();
58 $message = 'Upload ok';
59 } else {
60 $status = HandlerResultInterface::STATUS_FAILED;
61 $identifier = '';
62 $message = $result->getStatus()->getMessage();
63 }
64
65 return new BasicHandlerResult($this->getFileIdentifierParameterName(), $status, $identifier, $message);
66 }
67
68
69 protected function getRemoveResult(string $identifier) : HandlerResultInterface
70 {
71 $id = $this->storage->find($identifier);
72 if ($id !== null) {
73 $this->storage->remove($id);
74
75 return new BasicHandlerResult($this->getFileIdentifierParameterName(), HandlerResultInterface::STATUS_OK, $identifier, 'file deleted');
76 } else {
77 return new BasicHandlerResult($this->getFileIdentifierParameterName(), HandlerResultInterface::STATUS_FAILED, $identifier, 'file not found');
78 }
79 }
80
81
82 protected function getInfoResult(string $identifier) : FileInfoResult
83 {
84 $id = $this->storage->find($identifier);
85 if ($id === null) {
86 return new BasicFileInfoResult($this->getFileIdentifierParameterName(), 'unknown', 'unknown', 0, 'unknown');
87 }
88 $r = $this->storage->getRevision($id)->getInformation();
89
90 return new BasicFileInfoResult($this->getFileIdentifierParameterName(), $identifier, $r->getTitle(), $r->getSize(), $r->getMimeType());
91 }
92
93
94 public function getInfoForExistingFiles(array $file_ids) : array
95 {
96 $infos = [];
97 foreach ($file_ids as $file_id) {
98 $id = $this->storage->find($file_id);
99 if ($id === null) {
100 continue;
101 }
102 $r = $this->storage->getRevision($id)->getInformation();
103
104 $infos[] = new BasicFileInfoResult($this->getFileIdentifierParameterName(), $file_id, $r->getTitle(), $r->getSize(), $r->getMimeType());
105 }
106
107 return $infos;
108 }
109}
$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.
$i
Definition: metadata.php:24
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
Class ilAsqQuestionAuthoringFactory.
$message
Definition: xapiexit.php:14