ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
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.

References $DIC, and read().

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
+ Here is the call graph for this function:

Member Function Documentation

◆ create()

ilBadgeImageTemplate::create ( )

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

References $db, $ilDB, getId(), getPropertiesForStorage(), saveTypes(), setId(), and update().

Referenced by update().

281  : void
282  {
283  $ilDB = $this->db;
284 
285  if ($this->getId()) {
286  $this->update();
287  return;
288  }
289 
290  $id = $ilDB->nextId("badge_image_template");
291  $this->setId($id);
292 
293  $fields = $this->getPropertiesForStorage();
294  $fields["id"] = array("integer", $id);
295 
296  $ilDB->insert("badge_image_template", $fields);
297 
298  $this->saveTypes();
299  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ delete()

ilBadgeImageTemplate::delete ( )

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

References $db, $ilDB, $path, ilFileUtils\delDir(), getFilePath(), and getId().

321  : void
322  {
323  $ilDB = $this->db;
324 
325  if (!$this->getId()) {
326  return;
327  }
328 
329  $path = $this->getFilePath($this->getId());
331 
332  $ilDB->manipulate("DELETE FROM badge_image_template" .
333  " WHERE id = " . $ilDB->quote($this->getId(), "integer"));
334  }
$path
Definition: ltiservices.php:29
static delDir(string $a_dir, bool $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
getFilePath(int $a_id, ?string $a_subdir=null)
Init file system storage.
+ 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 212 of file class.ilBadgeImageTemplate.php.

References $path.

Referenced by delete(), getImagePath(), and uploadImage().

215  : string {
216  $storage = new ilFSStorageBadgeImageTemplate($a_id);
217  $storage->create();
218 
219  $path = $storage->getAbsolutePath() . "/";
220 
221  if ($a_subdir) {
222  $path .= $a_subdir . "/";
223 
224  if (!is_dir($path)) {
225  mkdir($path);
226  }
227  }
228 
229  return $path;
230  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$path
Definition: ltiservices.php:29
+ Here is the caller graph for this function:

◆ getId()

ilBadgeImageTemplate::getId ( )

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

References $id.

Referenced by create(), delete(), getImagePath(), saveTypes(), update(), and uploadImage().

107  : int
108  {
109  return $this->id;
110  }
+ Here is the caller graph for this function:

◆ getImage()

ilBadgeImageTemplate::getImage ( )

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

References $image.

Referenced by getImageFromResourceId(), getImagePath(), getPropertiesForStorage(), and ilObjBadgeAdministrationGUI\setImageTemplateFormValues().

144  : string
145  {
146  return $this->image;
147  }
+ Here is the caller graph for this function:

◆ getImageFromResourceId()

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

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

References getImage(), getImagePath(), getImageRid(), null, and ilWACSignedPath\signFile().

Referenced by ilObjBadgeAdministrationGUI\setImageTemplateFormValues().

380  : string {
381  $image_src = '';
382 
383  if ($this->getImageRid()) {
384  $identification = $this->resource_storage->manage()->find($this->getImageRid());
385  if ($identification !== null) {
386  $flavour = $this->resource_storage->flavours()->get($identification, new ilBadgePictureDefinition());
387  $urls = $this->resource_storage->consume()->flavourUrls($flavour)->getURLsAsArray();
388  if (count($urls) === ilBadgeImage::IMAGE_URL_COUNT && isset($urls[$size])) {
389  $image_src = $urls[$size];
390  }
391  }
392  } elseif ($this->getImage()) {
393  $image_src = ilWACSignedPath::signFile($this->getImagePath());
394  }
395 
396  return $image_src;
397  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
static signFile(string $path_to_file)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getImagePath()

ilBadgeImageTemplate::getImagePath ( )

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

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

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

195  : string
196  {
197  if ($this->getId()) {
198  if (is_file($this->getFilePath($this->getId()) . "img" . $this->getId())) { // formerly (early 5.2 versino), images have been uploaded with no suffix
199  return $this->getFilePath($this->getId()) . "img" . $this->getId();
200  }
201 
202  $exp = explode(".", $this->getImage());
203  $suffix = strtolower(array_pop($exp));
204  return $this->getFilePath($this->getId()) . "img" . $this->getId() . "." . $suffix;
205  }
206  return "";
207  }
getFilePath(int $a_id, ?string $a_subdir=null)
Init file system storage.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getImageRid()

ilBadgeImageTemplate::getImageRid ( )

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

References $image_rid.

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

368  : ?string
369  {
370  return $this->image_rid;
371  }
+ Here is the caller graph for this function:

◆ getInstances()

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

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

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

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

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:66
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
global $DIC
Definition: shib_login.php:26
+ 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.

References $res.

Referenced by ilBadgeManagementGUI\initBadgeForm().

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  }
$res
Definition: ltiservices.php:66
+ Here is the caller graph for this function:

◆ getPropertiesForStorage()

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

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

References getImage(), getImageRid(), and getTitle().

Referenced by create(), and update().

339  : array
340  {
341  return [
342  "title" => ["text", $this->getTitle()],
343  "image" => ["text", $this->getImage()],
344  "image_rid" => ["text", $this->getImageRid()]
345  ];
346  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getTitle()

ilBadgeImageTemplate::getTitle ( )

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

References $title.

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

117  : string
118  {
119  return $this->title;
120  }
+ Here is the caller graph for this function:

◆ getTypes()

ilBadgeImageTemplate::getTypes ( )
Returns
string[]

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

References $types.

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

132  : ?array
133  {
134  return $this->types;
135  }
+ Here is the caller graph for this function:

◆ importDBRow()

ilBadgeImageTemplate::importDBRow ( array  $a_row)
protected

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

References setId(), setImage(), setImageRid(), setTitle(), and setTypes().

Referenced by read().

268  : void
269  {
270  $this->setId($a_row["id"]);
271  $this->setTitle($a_row["title"]);
272  if (isset($a_row["image"])) {
273  $this->setImage($a_row["image"]);
274  }
275  if (isset($a_row["image_rid"])) {
276  $this->setImageRid($a_row["image_rid"]);
277  }
278  $this->setTypes($a_row["types"]);
279  }
setImageRid(?string $image_rid=null)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ processImageUpload()

ilBadgeImageTemplate::processImageUpload ( ilBadgeImageTemplate  $badge)

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

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

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  $this->resource_storage->manage()->remove(new ResourceIdentification($badge->getImageRid()), new ilBadgeFileStakeholder());
183  $stakeholder = new ilBadgeFileStakeholder();
184  $identification = $this->resource_storage->manage()->upload($array_result, $stakeholder);
185  $this->resource_storage->flavours()->ensure($identification, new \ilBadgePictureDefinition());
186  $badge->setImageRid($identification);
187  $badge->update();
188  }
189  }
190  } catch (IllegalStateException $e) {
191  $this->main_template->setOnScreenMessage('failure', $e->getMessage(), true);
192  }
193  }
setImageRid(?string $image_rid=null)
+ Here is the call graph for this function:

◆ read()

ilBadgeImageTemplate::read ( int  $a_id)
protected

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

References $db, $ilDB, importDBRow(), and readTypes().

Referenced by __construct().

237  : void
238  {
239  $ilDB = $this->db;
240 
241  $set = $ilDB->query("SELECT * FROM badge_image_template" .
242  " WHERE id = " . $ilDB->quote($a_id, "integer"));
243  if ($ilDB->numRows($set)) {
244  $row = $ilDB->fetchAssoc($set);
245  $row["types"] = $this->readTypes($a_id);
246  $this->importDBRow($row);
247  }
248  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ readTypes()

ilBadgeImageTemplate::readTypes ( int  $a_id)
protected

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

References $db, $ilDB, $res, and null.

Referenced by read().

250  : ?array
251  {
252  $ilDB = $this->db;
253 
254  $res = array();
255 
256  $set = $ilDB->query("SELECT * FROM badge_image_templ_type WHERE tmpl_id = " . $ilDB->quote($a_id, "integer"));
257  while ($row = $ilDB->fetchAssoc($set)) {
258  $res[] = $row["type_id"];
259  }
260 
261  if (!count($res)) {
262  $res = null;
263  }
264 
265  return $res;
266  }
$res
Definition: ltiservices.php:66
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
+ Here is the caller graph for this function:

◆ saveTypes()

ilBadgeImageTemplate::saveTypes ( )
protected

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

References $db, $ilDB, getId(), and getTypes().

Referenced by create(), and update().

348  : void
349  {
350  $ilDB = $this->db;
351 
352  if ($this->getId()) {
353  $ilDB->manipulate("DELETE FROM badge_image_templ_type" .
354  " WHERE tmpl_id = " . $ilDB->quote($this->getId(), "integer"));
355 
356  if ($this->getTypes()) {
357  foreach ($this->getTypes() as $type) {
358  $fields = array(
359  "tmpl_id" => array("integer", $this->getId()),
360  "type_id" => array("text", $type)
361  );
362  $ilDB->insert("badge_image_templ_type", $fields);
363  }
364  }
365  }
366  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setId()

ilBadgeImageTemplate::setId ( int  $a_id)
protected

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

Referenced by create(), and importDBRow().

102  : void
103  {
104  $this->id = $a_id;
105  }
+ Here is the caller graph for this function:

◆ setImage()

ilBadgeImageTemplate::setImage ( ?string  $a_value)
protected

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

References null.

Referenced by importDBRow(), and uploadImage().

122  : void
123  {
124  if ($a_value !== null) {
125  $this->image = trim($a_value);
126  }
127  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
+ Here is the caller graph for this function:

◆ setImageRid()

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

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

References $image_rid.

Referenced by importDBRow(), and processImageUpload().

373  : void
374  {
375  $this->image_rid = $image_rid;
376  }
+ Here is the caller graph for this function:

◆ setTitle()

ilBadgeImageTemplate::setTitle ( string  $a_value)

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

Referenced by importDBRow().

112  : void
113  {
114  $this->title = trim($a_value);
115  }
+ Here is the caller graph for this function:

◆ setTypes()

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

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

References null.

Referenced by importDBRow().

137  : void
138  {
139  $this->types = is_array($types)
140  ? array_unique($types)
141  : null;
142  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
+ Here is the caller graph for this function:

◆ update()

ilBadgeImageTemplate::update ( )

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

References $db, $ilDB, create(), getId(), getPropertiesForStorage(), and saveTypes().

Referenced by create(), processImageUpload(), and uploadImage().

301  : void
302  {
303  $ilDB = $this->db;
304 
305  if (!$this->getId()) {
306  $this->create();
307  return;
308  }
309 
310  $fields = $this->getPropertiesForStorage();
311 
312  $ilDB->update(
313  "badge_image_template",
314  $fields,
315  array("id" => array("integer", $this->getId()))
316  );
317 
318  $this->saveTypes();
319  }
+ 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.

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

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  }
static getValidFilename(string $a_filename)
$path
Definition: ltiservices.php:29
static moveUploadedFile(string $a_file, string $a_name, string $a_target, bool $a_raise_errors=true, string $a_mode="move_uploaded")
move uploaded file
$filename
Definition: buildRTE.php:78
getFilePath(int $a_id, ?string $a_subdir=null)
Init file system storage.
+ Here is the call graph for this function:

Field Documentation

◆ $db

ilDBInterface ilBadgeImageTemplate::$db
protected

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

Referenced by create(), delete(), read(), readTypes(), saveTypes(), and update().

◆ $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.

Referenced by getImageRid(), and setImageRid().

◆ $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 getTypes().

◆ $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: