ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
ilBadgeImageTemplate Class Reference
+ Collaboration diagram for ilBadgeImageTemplate:

Public Member Functions

 __construct (?int $a_id=null)
 
 getId ()
 
 setTitle (string $a_value)
 
 getTitle ()
 
 getTypes ()
 
 setTypes (?array $types=null)
 
 getImage ()
 
 uploadImage (array $a_upload_meta)
 
 processImageUpload (ilBadgeImageTemplate $badge)
 
 getImagePath ()
 
 create ()
 
 update ()
 
 delete ()
 
 getImageRid ()
 
 setImageRid (?string $image_rid=null)
 
 getImageFromResourceId (int $size=ilBadgeImage::IMAGE_SIZE_XS)
 

Static Public Member Functions

static getInstances ()
 
static getInstancesByType (string $a_type_unique_id)
 

Protected Member Functions

 setId (int $a_id)
 
 setImage (?string $a_value)
 
 getFilePath (int $a_id, ?string $a_subdir=null)
 Init file system storage. More...
 
 read (int $a_id)
 
 readTypes (int $a_id)
 
 importDBRow (array $a_row)
 
 getPropertiesForStorage ()
 
 saveTypes ()
 

Protected Attributes

ilDBInterface $db
 
int $id = 0
 
string $title = ""
 
string $image = ""
 
string $image_rid = ""
 
array $types = null
 
Services $resource_storage
 
FileUpload $upload_service
 
ilGlobalTemplateInterface $main_template
 

Detailed Description

Definition at line 25 of file class.ilBadgeImageTemplate.php.

Constructor & Destructor Documentation

◆ __construct()

ilBadgeImageTemplate::__construct ( ?int  $a_id = null)

Definition at line 38 of file class.ilBadgeImageTemplate.php.

39 {
40 global $DIC;
41
42 $this->resource_storage = $DIC->resourceStorage();
43 $this->upload_service = $DIC->upload();
44 $this->main_template = $DIC->ui()->mainTemplate();
45 $this->db = $DIC->database();
46 if ($a_id) {
47 $this->read($a_id);
48 }
49 }
global $DIC
Definition: shib_login.php:26

References $DIC, and read().

+ Here is the call graph for this function:

Member Function Documentation

◆ create()

ilBadgeImageTemplate::create ( )

Definition at line 283 of file class.ilBadgeImageTemplate.php.

283 : void
284 {
286
287 if ($this->getId()) {
288 $this->update();
289 return;
290 }
291
292 $id = $ilDB->nextId("badge_image_template");
293 $this->setId($id);
294
295 $fields = $this->getPropertiesForStorage();
296 $fields["id"] = array("integer", $id);
297
298 $ilDB->insert("badge_image_template", $fields);
299
300 $this->saveTypes();
301 }

References $id, $ilDB, and ILIAS\Survey\Mode\getId().

+ Here is the call graph for this function:

◆ delete()

ilBadgeImageTemplate::delete ( )

Definition at line 323 of file class.ilBadgeImageTemplate.php.

323 : void
324 {
326
327 if (!$this->getId()) {
328 return;
329 }
330
331 $path = $this->getFilePath($this->getId());
333
334 $ilDB->manipulate("DELETE FROM badge_image_template" .
335 " WHERE id = " . $ilDB->quote($this->getId(), "integer"));
336 }
getFilePath(int $a_id, ?string $a_subdir=null)
Init file system storage.
static delDir(string $a_dir, bool $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
$path
Definition: ltiservices.php:30

References $ilDB, $path, ilFileUtils\delDir(), and ILIAS\Survey\Mode\getId().

+ Here is the call graph for this function:

◆ getFilePath()

ilBadgeImageTemplate::getFilePath ( int  $a_id,
?string  $a_subdir = null 
)
protected

Init file system storage.

Definition at line 214 of file class.ilBadgeImageTemplate.php.

217 : string {
218 $storage = new ilFSStorageBadgeImageTemplate($a_id);
219 $storage->create();
220
221 $path = $storage->getAbsolutePath() . "/";
222
223 if ($a_subdir) {
224 $path .= $a_subdir . "/";
225
226 if (!is_dir($path)) {
227 mkdir($path);
228 }
229 }
230
231 return $path;
232 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

References $path.

Referenced by getImagePath(), and uploadImage().

+ Here is the caller graph for this function:

◆ getId()

ilBadgeImageTemplate::getId ( )

Definition at line 107 of file class.ilBadgeImageTemplate.php.

107 : int
108 {
109 return $this->id;
110 }

References $id.

Referenced by getImagePath(), and uploadImage().

+ Here is the caller graph for this function:

◆ getImage()

ilBadgeImageTemplate::getImage ( )

Definition at line 144 of file class.ilBadgeImageTemplate.php.

144 : string
145 {
146 return $this->image;
147 }

References $image.

Referenced by getImagePath().

+ Here is the caller graph for this function:

◆ getImageFromResourceId()

ilBadgeImageTemplate::getImageFromResourceId ( int  $size = ilBadgeImage::IMAGE_SIZE_XS)

Definition at line 380 of file class.ilBadgeImageTemplate.php.

382 : string {
383 $image_src = '';
384
385 if ($this->getImageRid()) {
386 $identification = $this->resource_storage->manage()->find($this->getImageRid());
387 if ($identification !== null) {
388 $flavour = $this->resource_storage->flavours()->get($identification, new ilBadgePictureDefinition());
389 $urls = $this->resource_storage->consume()->flavourUrls($flavour)->getURLsAsArray();
390 if (count($urls) === ilBadgeImage::IMAGE_URL_COUNT && isset($urls[$size])) {
391 $image_src = $urls[$size];
392 }
393 }
394 } elseif ($this->getImage()) {
395 $image_src = ilWACSignedPath::signFile($this->getImagePath());
396 }
397
398 return $image_src;
399 }
static signFile(string $path_to_file)

Referenced by ilObjBadgeAdministrationGUI\setImageTemplateFormValues().

+ Here is the caller graph for this function:

◆ getImagePath()

ilBadgeImageTemplate::getImagePath ( )

Definition at line 197 of file class.ilBadgeImageTemplate.php.

197 : string
198 {
199 if ($this->getId()) {
200 if (is_file($this->getFilePath($this->getId()) . "img" . $this->getId())) { // formerly (early 5.2 versino), images have been uploaded with no suffix
201 return $this->getFilePath($this->getId()) . "img" . $this->getId();
202 }
203
204 $exp = explode(".", $this->getImage());
205 $suffix = strtolower(array_pop($exp));
206 return $this->getFilePath($this->getId()) . "img" . $this->getId() . "." . $suffix;
207 }
208 return "";
209 }

References getFilePath(), getId(), and getImage().

+ Here is the call graph for this function:

◆ getImageRid()

ilBadgeImageTemplate::getImageRid ( )

Definition at line 370 of file class.ilBadgeImageTemplate.php.

370 : ?string
371 {
372 return $this->image_rid;
373 }

Referenced by processImageUpload(), and ilObjBadgeAdministrationGUI\setImageTemplateFormValues().

+ Here is the caller graph for this function:

◆ getInstances()

static ilBadgeImageTemplate::getInstances ( )
static
Returns
self[]

Definition at line 54 of file class.ilBadgeImageTemplate.php.

54 : array
55 {
56 global $DIC;
57
58 $ilDB = $DIC->database();
59
60 $res = array();
61
62 $types = array();
63 $set = $ilDB->query("SELECT * FROM badge_image_templ_type");
64 while ($row = $ilDB->fetchAssoc($set)) {
65 $types[$row["tmpl_id"]][] = $row["type_id"];
66 }
67
68 $set = $ilDB->query("SELECT * FROM badge_image_template" .
69 " ORDER BY title");
70 while ($row = $ilDB->fetchAssoc($set)) {
71 $row["types"] = (array) ($types[$row["id"]] ?? null);
72
73 $obj = new self();
74 $obj->importDBRow($row);
75 $res[] = $obj;
76 }
77
78 return $res;
79 }
$res
Definition: ltiservices.php:69

References $DIC, $ilDB, $res, and $types.

Referenced by ilObjBadgeAdministrationGUI\confirmDeleteImageTemplates(), ilObjBadgeAdministrationGUI\deleteImageTemplates(), ILIAS\Badge\ilBadgeImageTemplateTableGUI\getRecords(), and ILIAS\Badge\ilBadgeImageTemplateTableGUI\renderTable().

+ Here is the caller graph for this function:

◆ getInstancesByType()

static ilBadgeImageTemplate::getInstancesByType ( string  $a_type_unique_id)
static
Returns
self[]

Definition at line 84 of file class.ilBadgeImageTemplate.php.

84 : array
85 {
86 $res = [];
87
88 foreach (self::getInstances() as $tmpl) {
89 if (!count($tmpl->getTypes()) || in_array($a_type_unique_id, $tmpl->getTypes(), true)) {
90 $res[] = $tmpl;
91 }
92 }
93
94 return $res;
95 }

References $res.

◆ getPropertiesForStorage()

ilBadgeImageTemplate::getPropertiesForStorage ( )
protected
Returns
array<string, array>

Definition at line 341 of file class.ilBadgeImageTemplate.php.

341 : array
342 {
343 return [
344 "title" => ["text", $this->getTitle()],
345 "image" => ["text", $this->getImage()],
346 "image_rid" => ["text", $this->getImageRid()]
347 ];
348 }

References ILIAS\GlobalScreen\Scope\Footer\Factory\getTitle().

+ Here is the call graph for this function:

◆ getTitle()

ilBadgeImageTemplate::getTitle ( )

Definition at line 117 of file class.ilBadgeImageTemplate.php.

117 : string
118 {
119 return $this->title;
120 }

References $title.

◆ getTypes()

ilBadgeImageTemplate::getTypes ( )
Returns
string[]

Definition at line 132 of file class.ilBadgeImageTemplate.php.

132 : ?array
133 {
134 return $this->types;
135 }

References $types.

◆ importDBRow()

ilBadgeImageTemplate::importDBRow ( array  $a_row)
protected

Definition at line 270 of file class.ilBadgeImageTemplate.php.

270 : void
271 {
272 $this->setId($a_row["id"]);
273 $this->setTitle($a_row["title"]);
274 if (isset($a_row["image"])) {
275 $this->setImage($a_row["image"]);
276 }
277 if (isset($a_row["image_rid"])) {
278 $this->setImageRid($a_row["image_rid"]);
279 }
280 $this->setTypes($a_row["types"]);
281 }
setImageRid(?string $image_rid=null)

◆ processImageUpload()

ilBadgeImageTemplate::processImageUpload ( ilBadgeImageTemplate  $badge)

Definition at line 172 of file class.ilBadgeImageTemplate.php.

172 : void
173 {
174 try {
175 if (!$this->upload_service->hasBeenProcessed()) {
176 $this->upload_service->process();
177 }
178 if ($this->upload_service->hasUploads()) {
179 $array_result = $this->upload_service->getResults();
180 $array_result = array_pop($array_result);
181 if ($array_result->getName() !== '') {
182 if ($badge->getImageRid()) {
183 $this->resource_storage->manage()->remove(new ResourceIdentification($badge->getImageRid()), new ilBadgeFileStakeholder());
184 }
185 $stakeholder = new ilBadgeFileStakeholder();
186 $identification = $this->resource_storage->manage()->upload($array_result, $stakeholder);
187 $this->resource_storage->flavours()->ensure($identification, new \ilBadgePictureDefinition());
188 $badge->setImageRid($identification);
189 $badge->update();
190 }
191 }
192 } catch (IllegalStateException $e) {
193 $this->main_template->setOnScreenMessage('failure', $e->getMessage(), true);
194 }
195 }

References Vendor\Package\$e, getImageRid(), setImageRid(), and update().

+ Here is the call graph for this function:

◆ read()

ilBadgeImageTemplate::read ( int  $a_id)
protected

Definition at line 239 of file class.ilBadgeImageTemplate.php.

239 : void
240 {
242
243 $set = $ilDB->query("SELECT * FROM badge_image_template" .
244 " WHERE id = " . $ilDB->quote($a_id, "integer"));
245 if ($ilDB->numRows($set)) {
246 $row = $ilDB->fetchAssoc($set);
247 $row["types"] = $this->readTypes($a_id);
248 $this->importDBRow($row);
249 }
250 }

References $ilDB.

Referenced by __construct().

+ Here is the caller graph for this function:

◆ readTypes()

ilBadgeImageTemplate::readTypes ( int  $a_id)
protected

Definition at line 252 of file class.ilBadgeImageTemplate.php.

252 : ?array
253 {
255
256 $res = array();
257
258 $set = $ilDB->query("SELECT * FROM badge_image_templ_type WHERE tmpl_id = " . $ilDB->quote($a_id, "integer"));
259 while ($row = $ilDB->fetchAssoc($set)) {
260 $res[] = $row["type_id"];
261 }
262
263 if (!count($res)) {
264 $res = null;
265 }
266
267 return $res;
268 }

References $ilDB, and $res.

◆ saveTypes()

ilBadgeImageTemplate::saveTypes ( )
protected

Definition at line 350 of file class.ilBadgeImageTemplate.php.

350 : void
351 {
353
354 if ($this->getId()) {
355 $ilDB->manipulate("DELETE FROM badge_image_templ_type" .
356 " WHERE tmpl_id = " . $ilDB->quote($this->getId(), "integer"));
357
358 if ($this->getTypes()) {
359 foreach ($this->getTypes() as $type) {
360 $fields = array(
361 "tmpl_id" => array("integer", $this->getId()),
362 "type_id" => array("text", $type)
363 );
364 $ilDB->insert("badge_image_templ_type", $fields);
365 }
366 }
367 }
368 }

References $ilDB, and ILIAS\Survey\Mode\getId().

+ Here is the call graph for this function:

◆ setId()

ilBadgeImageTemplate::setId ( int  $a_id)
protected

Definition at line 102 of file class.ilBadgeImageTemplate.php.

102 : void
103 {
104 $this->id = $a_id;
105 }

◆ setImage()

ilBadgeImageTemplate::setImage ( ?string  $a_value)
protected

Definition at line 122 of file class.ilBadgeImageTemplate.php.

122 : void
123 {
124 if ($a_value !== null) {
125 $this->image = trim($a_value);
126 }
127 }

Referenced by uploadImage().

+ Here is the caller graph for this function:

◆ setImageRid()

ilBadgeImageTemplate::setImageRid ( ?string  $image_rid = null)

Definition at line 375 of file class.ilBadgeImageTemplate.php.

375 : void
376 {
377 $this->image_rid = $image_rid;
378 }

Referenced by processImageUpload().

+ Here is the caller graph for this function:

◆ setTitle()

ilBadgeImageTemplate::setTitle ( string  $a_value)

Definition at line 112 of file class.ilBadgeImageTemplate.php.

112 : void
113 {
114 $this->title = trim($a_value);
115 }

◆ setTypes()

ilBadgeImageTemplate::setTypes ( ?array  $types = null)

Definition at line 137 of file class.ilBadgeImageTemplate.php.

137 : void
138 {
139 $this->types = is_array($types)
140 ? array_unique($types)
141 : null;
142 }

References $types.

◆ update()

ilBadgeImageTemplate::update ( )

Definition at line 303 of file class.ilBadgeImageTemplate.php.

303 : void
304 {
306
307 if (!$this->getId()) {
308 $this->create();
309 return;
310 }
311
312 $fields = $this->getPropertiesForStorage();
313
314 $ilDB->update(
315 "badge_image_template",
316 $fields,
317 array("id" => array("integer", $this->getId()))
318 );
319
320 $this->saveTypes();
321 }

References $ilDB, and ILIAS\Survey\Mode\getId().

Referenced by processImageUpload(), and uploadImage().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ uploadImage()

ilBadgeImageTemplate::uploadImage ( array  $a_upload_meta)
Exceptions
ilException
ilFileUtilsException

Definition at line 153 of file class.ilBadgeImageTemplate.php.

153 : void
154 {
155 if ($this->getId() &&
156 $a_upload_meta["tmp_name"]) {
157 $path = $this->getFilePath($this->getId());
158
159 $filename = ilFileUtils::getValidFilename($a_upload_meta["name"]);
160
161 $exp = explode(".", $filename);
162 $suffix = strtolower(array_pop($exp));
163 $tgt = $path . "img" . $this->getId() . "." . $suffix;
164
165 if (ilFileUtils::moveUploadedFile($a_upload_meta["tmp_name"], "img" . $this->getId() . "." . $suffix, $tgt)) {
166 $this->setImage($filename);
167 $this->update();
168 }
169 }
170 }
$filename
Definition: buildRTE.php:78
static getValidFilename(string $a_filename)
static moveUploadedFile(string $a_file, string $a_name, string $a_target, bool $a_raise_errors=true, string $a_mode="move_uploaded")
move uploaded file

References $filename, $path, getFilePath(), getId(), ilFileUtils\getValidFilename(), ilFileUtils\moveUploadedFile(), setImage(), and update().

+ Here is the call graph for this function:

Field Documentation

◆ $db

ilDBInterface ilBadgeImageTemplate::$db
protected

Definition at line 27 of file class.ilBadgeImageTemplate.php.

◆ $id

int ilBadgeImageTemplate::$id = 0
protected

Definition at line 28 of file class.ilBadgeImageTemplate.php.

Referenced by getId().

◆ $image

string ilBadgeImageTemplate::$image = ""
protected

Definition at line 30 of file class.ilBadgeImageTemplate.php.

Referenced by getImage().

◆ $image_rid

string ilBadgeImageTemplate::$image_rid = ""
protected

Definition at line 31 of file class.ilBadgeImageTemplate.php.

◆ $main_template

ilGlobalTemplateInterface ilBadgeImageTemplate::$main_template
protected

Definition at line 36 of file class.ilBadgeImageTemplate.php.

◆ $resource_storage

Services ilBadgeImageTemplate::$resource_storage
protected

Definition at line 34 of file class.ilBadgeImageTemplate.php.

◆ $title

string ilBadgeImageTemplate::$title = ""
protected

Definition at line 29 of file class.ilBadgeImageTemplate.php.

Referenced by getTitle().

◆ $types

array ilBadgeImageTemplate::$types = null
protected

Definition at line 33 of file class.ilBadgeImageTemplate.php.

Referenced by getInstances(), getTypes(), and setTypes().

◆ $upload_service

FileUpload ilBadgeImageTemplate::$upload_service
protected

Definition at line 35 of file class.ilBadgeImageTemplate.php.


The documentation for this class was generated from the following file: