ILIAS  trunk Revision v12.0_alpha-1540-g00f839d5fa1
class.TileImageUploadHandlerGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21use ILIAS\ILIASObject\Properties\UploadSecurityFunctionsTrait;
25use ILIAS\ResourceStorage\Services as ResourceStorageServices;
33
39{
40 use UploadSecurityFunctionsTrait;
41
42 protected \ilLanguage $language;
43 protected ResourceStorageServices $storage;
46
47 protected ?ResourceIdentification $rid = null;
48 protected bool $has_access = false;
49
50 public function __construct(
51 protected ?TileImage $tile_image = null
52 ) {
54 global $DIC;
55 $this->language = $DIC->language();
56
57 $ref_id = null;
58 if ($DIC->http()->wrapper()->query()->has('ref_id')) {
59 $transformation = $DIC->refinery()->kindlyTo()->int();
60 $ref_id = $DIC->http()->wrapper()->query()->retrieve('ref_id', $transformation);
61 }
62
63 $this->has_access = $this->getAccess(
64 $ref_id,
65 $DIC->access()
66 );
67
68 if ($DIC->http()->wrapper()->post()->has('rid')) {
69 $id = $DIC->http()->wrapper()->post()->retrieve(
70 'rid',
71 $DIC->refinery()->to()->string()
72 );
73 $this->rid = $DIC->resourceStorage()->manage()->find($id);
74 }
75
76 $DIC->ctrl()->setParameterByClass(self::class, 'ref_id', $ref_id);
77
78 $this->storage = $DIC->resourceStorage();
79 $this->stakeholder = new Stakeholder();
80 $this->flavour = new FlavourDefinition();
81
83 }
84
88 protected function getUploadResult(): HandlerResult
89 {
90 if ($this->has_access === false) {
91 return $this->getAccessFailureResult(
93 '',
94 $this->language
95 );
96 }
97
98 $this->upload->process();
99
100 $result_array = $this->upload->getResults();
101 $result = end($result_array);
102
103 if (!($result instanceof UploadResult)
104 || !in_array($result->getMimeType(), TileImage::SUPPORTED_MIME_TYPES)
105 || !$result->isOK()) {
106 return new BasicHandlerResult(
108 HandlerResult::STATUS_FAILED,
109 '',
110 $result->getStatus()->getMessage()
111 );
112 }
113
114 $status = HandlerResult::STATUS_OK;
115 $message = "file upload OK";
116 if ($this->rid === null) {
117 $i = $this->storage->manage()->upload($result, $this->stakeholder);
118 } else {
119 $i = $this->rid;
120 $this->storage->manage()->replaceWithUpload(
121 $i,
122 $result,
123 $this->stakeholder
124 );
125 }
126
127 $this->storage->flavours()->ensure($i, $this->flavour);
128
129 return new BasicHandlerResult(
131 $status,
132 $i->serialize(),
133 $message
134 );
135 }
136
137 protected function getRemoveResult(string $identifier): HandlerResult
138 {
139 if ($this->has_access === false) {
140 return $this->getAccessFailureResult(
142 $identifier,
143 $this->language
144 );
145 }
146
147 return new BasicHandlerResult(
149 HandlerResult::STATUS_OK,
150 $identifier,
151 "We just don't do anything here."
152 );
153 }
154
155 public function getInfoResult(string $identifier): ?FileInfoResult
156 {
157 if (null !== ($id = $this->storage->manage()->find($identifier))) {
158 $revision = $this->storage->manage()->getCurrentRevision($id)->getInformation();
159 $title = $revision->getTitle();
160 $size = $revision->getSize();
161 $mime = $revision->getMimeType();
162 } else {
163 $title = $mime = 'unknown';
164 $size = 0;
165 }
166
167 return new BasicFileInfoResult(
169 $identifier,
170 $title,
171 $size,
172 $mime
173 );
174 }
175
179 public function getInfoForExistingFiles(array $file_ids): array
180 {
181 $info_results = [];
182 foreach ($file_ids as $identifier) {
183 $info_results[] = $this->getInfoResult($identifier);
184 }
185
186 return $info_results;
187 }
188}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$ref_id
Definition: ltiauth.php:66
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26