ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilMMUploadHandlerGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
26use ILIAS\FileUpload\Handler\HandlerResult as HandlerResultInterface;
28
37{
41 private $storage;
42 private \ilMMStorageStakeholder $stakeholder;
43
44
48 public function __construct()
49 {
50 global $DIC;
52 $this->storage = $DIC['resource_storage'];
53 $this->stakeholder = new ilMMStorageStakeholder();
54 }
55
56
60 protected function getUploadResult(): HandlerResultInterface
61 {
62 $this->upload->process();
66 $array = $this->upload->getResults();
67 $result = end($array);
68 if ($result instanceof UploadResult && $result->isOK()) {
69 $i = $this->storage->manage()->upload($result, $this->stakeholder);
70 $status = HandlerResultInterface::STATUS_OK;
71 $identifier = $i->serialize();
72 $message = 'Upload ok';
73 } else {
74 $status = HandlerResultInterface::STATUS_FAILED;
75 $identifier = '';
76 $message = $result->getStatus()->getMessage();
77 }
78
79 return new BasicHandlerResult($this->getFileIdentifierParameterName(), $status, $identifier, $message);
80 }
81
82
83 protected function getRemoveResult(string $identifier): HandlerResultInterface
84 {
85 $id = $this->storage->manage()->find($identifier);
86 if ($id !== null) {
87 $this->storage->manage()->remove($id, $this->stakeholder);
88
89 return new BasicHandlerResult($this->getFileIdentifierParameterName(), HandlerResultInterface::STATUS_OK, $identifier, 'file deleted');
90 }
91 return new BasicHandlerResult($this->getFileIdentifierParameterName(), HandlerResultInterface::STATUS_FAILED, $identifier, 'file not found');
92 }
93
94
95 public function getInfoResult(string $identifier): ?FileInfoResult
96 {
97 $id = $this->storage->manage()->find($identifier);
98 if ($id === null) {
99 return new BasicFileInfoResult($this->getFileIdentifierParameterName(), 'unknown', 'unknown', 0, 'unknown');
100 }
101 $r = $this->storage->manage()->getCurrentRevision($id)->getInformation();
102
103 return new BasicFileInfoResult($this->getFileIdentifierParameterName(), $identifier, $r->getTitle(), $r->getSize(), $r->getMimeType());
104 }
105
106
107 public function getInfoForExistingFiles(array $file_ids): array
108 {
109 $infos = [];
110 foreach ($file_ids as $file_id) {
111 $id = $this->storage->manage()->find($file_id);
112 if ($id === null) {
113 continue;
114 }
115 $r = $this->storage->manage()->getCurrentRevision($id)->getInformation();
116
117 $infos[] = new BasicFileInfoResult($this->getFileIdentifierParameterName(), $file_id, $r->getTitle(), $r->getSize(), $r->getMimeType());
118 }
119
120 return $infos;
121 }
122}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Class ilMMStorageStakeholder.
Class ilMMUploadHandlerGUI.
getInfoResult(string $identifier)
ilMMStorageStakeholder $stakeholder
getInfoForExistingFiles(array $file_ids)
getRemoveResult(string $identifier)
__construct()
ilUIDemoFileUploadHandlerGUI constructor.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26
$message
Definition: xapiexit.php:31