ILIAS  trunk Revision v12.0_alpha-16-g3e876e53c80
class.ilMailFormUploadHandlerGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
26use ILIAS\FileUpload\Handler\HandlerResult as HandlerResultInterface;
30
32{
35 private readonly ilLanguage $lng;
36
37 public function __construct()
38 {
39 global $DIC;
41 $this->storage = $DIC->resourceStorage();
42 $this->stakeholder = new ilMailAttachmentStakeholder();
43 $this->lng = $DIC->language();
44 }
45
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->manage()->upload($result, $this->stakeholder);
56 $status = HandlerResultInterface::STATUS_OK;
57 $identifier = $i->serialize();
58 $message = $this->lng->txt('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 protected function getRemoveResult(string $identifier): HandlerResultInterface
69 {
70 $id = $this->storage->manage()->find($identifier);
71 if ($id !== null) {
72 $this->storage->manage()->remove($id, $this->stakeholder);
73 return new BasicHandlerResult($this->getFileIdentifierParameterName(), HandlerResultInterface::STATUS_OK, $identifier, 'file deleted');
74 }
75
76 return new BasicHandlerResult($this->getFileIdentifierParameterName(), HandlerResultInterface::STATUS_FAILED, $identifier, 'file not found');
77 }
78
79 public function getInfoResult(string $identifier): FileInfoResult
80 {
81 $id = $this->storage->manage()->find($identifier);
82 if ($id === null) {
83 return new BasicFileInfoResult($this->getFileIdentifierParameterName(), 'unknown', 'unknown', 0, 'unknown');
84 }
85 $r = $this->storage->manage()->getCurrentRevision($id)->getInformation();
86
87 return new BasicFileInfoResult($this->getFileIdentifierParameterName(), $identifier, $r->getTitle(), $r->getSize(), $r->getMimeType());
88 }
89
90 public function getInfoForExistingFiles(array $file_ids): array
91 {
92 $infos = [];
93 foreach ($file_ids as $file_id) {
94 $id = $this->storage->manage()->find($file_id);
95 if ($id === null) {
96 continue;
97 }
98 $r = $this->storage->manage()->getCurrentRevision($id)->getInformation();
99
100 $infos[] = new BasicFileInfoResult($this->getFileIdentifierParameterName(), $file_id, $r->getTitle(), $r->getSize(), $r->getMimeType());
101 }
102
103 return $infos;
104 }
105
106 public function getInlineConsumer(string $identifier): InlineConsumer
107 {
108 return $this->storage->consume()->inline(new ResourceIdentification($identifier));
109 }
110
111 public function removeFileForIdentifier(string $identifier): HandlerResultInterface
112 {
113 return $this->getRemoveResult($identifier);
114 }
115
116 public function getStreamConsumer(string $identifier): FileStreamConsumer
117 {
118 return $this->storage->consume()->stream(new ResourceIdentification($identifier));
119 }
120}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
language handling
readonly ilMailAttachmentStakeholder $stakeholder
__construct()
ilUIDemoFileUploadHandlerGUI constructor.
readonly ILIAS ResourceStorage Services $storage
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26