ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilLTIConsumeProviderIcon.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2019 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5
15{
16 const MAX_ICON_SIZE = 32;
17
18 protected static $RELATIVE_DIRECTORY_PATH = [
19 'lti_data', 'provider_icon'
20 ];
21
22 protected static $SUPPORTED_FILE_EXTENSIONS = [
23 'png', 'jpg', 'jpeg'
24 ];
25
29 protected $providerId;
30
34 protected $filename;
35
42 public function __construct(int $providerId, string $filename = '')
43 {
44 global $DIC; /* @var \ILIAS\DI\Container $DIC */
45
46 $this->providerId = $providerId;
47 $this->filename = $filename;
48
50 }
51
52 public function buildFilename($fileExtension)
53 {
54 return "{$this->providerId}.{$fileExtension}";
55 }
56
60 public function getFilename() : string
61 {
62 return $this->filename;
63 }
64
68 public function setFilename(string $filename)
69 {
70 $this->filename = $filename;
71 }
72
76 public function getRelativeDirectory()
77 {
78 return implode(DIRECTORY_SEPARATOR, self::$RELATIVE_DIRECTORY_PATH);
79 }
80
84 public function getRelativeFilePath()
85 {
86 return implode(DIRECTORY_SEPARATOR, [
87 $this->getRelativeDirectory(), $this->getFilename()
88 ]);
89 }
90
94 public function getAbsoluteFilePath()
95 {
96 return implode(DIRECTORY_SEPARATOR, [
98 ]);
99 }
100
105 {
106 global $DIC; /* @var \ILIAS\DI\Container $DIC */
107
108 if (!$DIC->filesystem()->web()->has($this->getRelativeDirectory())) {
109 $DIC->filesystem()->web()->createDir($this->getRelativeDirectory());
110 }
111 }
112
116 public function exists()
117 {
118 global $DIC; /* @var \ILIAS\DI\Container $DIC */
119
120 if (!strlen($this->getFilename())) {
121 return false;
122 }
123
124 return $DIC->filesystem()->web()->has($this->getRelativeFilePath());
125 }
126
131 protected function delete()
132 {
133 global $DIC; /* @var \ILIAS\DI\Container $DIC */
134
135 if ($DIC->filesystem()->web()->has($this->getRelativeFilePath())) {
136 $DIC->filesystem()->web()->delete($this->getRelativeFilePath());
137 }
138
139 $this->setFilename('');
140 }
141
142 protected function convert()
143 {
144 // convert to square with same side length (optimal for tile view)
145
146 list($width, $height, $type, $attr) = getimagesize($this->getAbsoluteFilePath());
147 $minSize = min($width, $height);
148
149 if (self::MAX_ICON_SIZE) {
150 $minSize = min($minSize, self::MAX_ICON_SIZE);
151 }
152
153 $convertCmd = "{$this->getAbsoluteFilePath()}[0]";
154 $convertCmd .= " -geometry {$minSize}x{$minSize}^ -gravity center";
155 $convertCmd .= " -extent {$minSize}x{$minSize}";
156 $convertCmd .= " {$this->getAbsoluteFilePath()}";
157
158 ilUtil::execConvert($convertCmd);
159 }
160
167 protected function save(string $uploadFile)
168 {
169 global $DIC; /* @var \ILIAS\DI\Container $DIC */
170
171 if ($DIC->upload()->hasUploads()) {
172 if (!$DIC->upload()->hasBeenProcessed()) {
173 $DIC->upload()->process();
174 }
175
176 /* @var \ILIAS\FileUpload\DTO\UploadResult $result */
177
178 $results = $DIC->upload()->getResults();
179
180 if (isset($results[$uploadFile])) {
181 $result = $results[$uploadFile];
182
183 if ($result->getStatus() == \ILIAS\FileUpload\DTO\ProcessingStatus::OK) {
184 $fileExtentsion = pathinfo($result->getName(), PATHINFO_EXTENSION);
185 $this->setFilename($this->buildFilename($fileExtentsion));
186
187 $DIC->upload()->moveOneFileTo(
188 $result,
189 $this->getRelativeDirectory(),
190 \ILIAS\FileUpload\Location::WEB,
191 $this->getFileName(),
192 true
193 );
194
195 $this->convert();
196 }
197 }
198 }
199 }
200
208 {
209 if ($fileInput->getDeletionFlag()) {
210 $this->delete();
211 }
212
213 // ilImageFileInputGUI does NOT come with a set value that could be fetched with
214 // $fileInput->getValue(). Instead ilImageFileInputGUI provides upload info in $_POST.
215 $fileData = $_POST[$fileInput->getPostVar()];
216
217 if ($fileData['tmp_name']) {
218 $this->save($fileData['tmp_name']);
219 }
220 }
221
225 public static function getSupportedFileExtensions()
226 {
228 }
229}
$result
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
getPostVar()
Get Post Variable.
This class represents an image file property in a property form.
getDeletionFlag()
Get deletion flag.
handleUploadInputSubission(ilImageFileInputGUI $fileInput)
__construct(int $providerId, string $filename='')
ilLTIConsumeProviderIcon constructor.
static getWebspaceDir($mode="filesystem")
get webspace directory
static execConvert($args)
execute convert command
Class ChatMainBarProvider \MainMenu\Provider.
$type
$results
$DIC
Definition: xapitoken.php:46