ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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 $this->upload->process();
91
92 $result_array = $this->upload->getResults();
93 $result = end($result_array);
94
95 if (!($result instanceof UploadResult) || !$result->isOK()) {
96 return new BasicHandlerResult(
98 HandlerResult::STATUS_FAILED,
99 '',
100 $result->getStatus()->getMessage()
101 );
102 }
103
104 $status = HandlerResult::STATUS_OK;
105 $message = "file upload OK";
106 if ($this->rid === null) {
107 $i = $this->storage->manage()->upload($result, $this->stakeholder);
108 } else {
109 $i = $this->rid;
110 $this->storage->manage()->replaceWithUpload(
111 $i,
112 $result,
113 $this->stakeholder
114 );
115 }
116
117 $this->storage->flavours()->ensure($i, $this->flavour);
118
119 return new BasicHandlerResult(
121 $status,
122 $i->serialize(),
124 );
125 }
126
127 protected function getRemoveResult(string $identifier): HandlerResult
128 {
129 if ($this->has_access === false) {
130 return $this->getAccessFailureResult(
132 $identifier,
133 $this->language
134 );
135 }
136
137 return new BasicHandlerResult(
139 HandlerResult::STATUS_OK,
140 $identifier,
141 "We just don't do anything here."
142 );
143 }
144
145 public function getInfoResult(string $identifier): ?FileInfoResult
146 {
147 if (null !== ($id = $this->storage->manage()->find($identifier))) {
148 $revision = $this->storage->manage()->getCurrentRevision($id)->getInformation();
149 $title = $revision->getTitle();
150 $size = $revision->getSize();
151 $mime = $revision->getMimeType();
152 } else {
153 $title = $mime = 'unknown';
154 $size = 0;
155 }
156
157 return new BasicFileInfoResult(
159 $identifier,
160 $title,
161 $size,
162 $mime
163 );
164 }
165
169 public function getInfoForExistingFiles(array $file_ids): array
170 {
171 $info_results = [];
172 foreach ($file_ids as $identifier) {
173 $info_results[] = $this->getInfoResult($identifier);
174 }
175
176 return $info_results;
177 }
178}
$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
$message
Definition: xapiexit.php:31