ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ilBadgeImageTemplate Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ 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)
 
 getImagePath ()
 
 create ()
 
 update ()
 
 delete ()
 

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 = ""
 
array $types = null
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning Badge Template

Author
Jörg Lützenkirchen luetz.nosp@m.enki.nosp@m.rchen.nosp@m.@lei.nosp@m.fos.c.nosp@m.om

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

Constructor & Destructor Documentation

◆ __construct()

ilBadgeImageTemplate::__construct ( int  $a_id = null)

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

References $DIC, and read().

34  {
35  global $DIC;
36 
37  $this->db = $DIC->database();
38  if ($a_id) {
39  $this->read($a_id);
40  }
41  }
global $DIC
Definition: feed.php:28
+ Here is the call graph for this function:

Member Function Documentation

◆ create()

ilBadgeImageTemplate::create ( )

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

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

Referenced by update().

244  : void
245  {
246  $ilDB = $this->db;
247 
248  if ($this->getId()) {
249  $this->update();
250  return;
251  }
252 
253  $id = $ilDB->nextId("badge_image_template");
254  $this->setId($id);
255 
256  $fields = $this->getPropertiesForStorage();
257  $fields["id"] = array("integer", $id);
258 
259  $ilDB->insert("badge_image_template", $fields);
260 
261  $this->saveTypes();
262  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ delete()

ilBadgeImageTemplate::delete ( )

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

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

Referenced by ilBadgeManagementGUI\saveBadge().

284  : void
285  {
286  $ilDB = $this->db;
287 
288  if (!$this->getId()) {
289  return;
290  }
291 
292  $path = $this->getFilePath($this->getId());
294 
295  $ilDB->manipulate("DELETE FROM badge_image_template" .
296  " WHERE id = " . $ilDB->quote($this->getId(), "integer"));
297  }
$path
Definition: ltiservices.php:32
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
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getFilePath()

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

Init file system storage.

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

References $path.

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

183  : string {
184  $storage = new ilFSStorageBadgeImageTemplate($a_id);
185  $storage->create();
186 
187  $path = $storage->getAbsolutePath() . "/";
188 
189  if ($a_subdir) {
190  $path .= $a_subdir . "/";
191 
192  if (!is_dir($path)) {
193  mkdir($path);
194  }
195  }
196 
197  return $path;
198  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$path
Definition: ltiservices.php:32
+ Here is the caller graph for this function:

◆ getId()

ilBadgeImageTemplate::getId ( )

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

References $id.

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

99  : int
100  {
101  return $this->id;
102  }
+ Here is the caller graph for this function:

◆ getImage()

ilBadgeImageTemplate::getImage ( )

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

References $image.

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

134  : string
135  {
136  return $this->image;
137  }
+ Here is the caller graph for this function:

◆ getImagePath()

ilBadgeImageTemplate::getImagePath ( )

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

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

Referenced by ilObjBadgeAdministrationGUI\setImageTemplateFormValues().

163  : string
164  {
165  if ($this->getId()) {
166  if (is_file($this->getFilePath($this->getId()) . "img" . $this->getId())) { // formerly (early 5.2 versino), images have been uploaded with no suffix
167  return $this->getFilePath($this->getId()) . "img" . $this->getId();
168  }
169 
170  $exp = explode(".", $this->getImage());
171  $suffix = strtolower(array_pop($exp));
172  return $this->getFilePath($this->getId()) . "img" . $this->getId() . "." . $suffix;
173  }
174  return "";
175  }
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:

◆ getInstances()

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

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

References $DIC, $ilDB, and $res.

Referenced by ilBadgeImageTemplateTableGUI\getItems().

46  : array
47  {
48  global $DIC;
49 
50  $ilDB = $DIC->database();
51 
52  $res = array();
53 
54  $types = array();
55  $set = $ilDB->query("SELECT * FROM badge_image_templ_type");
56  while ($row = $ilDB->fetchAssoc($set)) {
57  $types[$row["tmpl_id"]][] = $row["type_id"];
58  }
59 
60  $set = $ilDB->query("SELECT * FROM badge_image_template" .
61  " ORDER BY title");
62  while ($row = $ilDB->fetchAssoc($set)) {
63  $row["types"] = (array) ($types[$row["id"]] ?? null);
64 
65  $obj = new self();
66  $obj->importDBRow($row);
67  $res[] = $obj;
68  }
69 
70  return $res;
71  }
$res
Definition: ltiservices.php:69
global $DIC
Definition: feed.php:28
+ Here is the caller graph for this function:

◆ getInstancesByType()

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

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

References $res.

Referenced by ilBadgeManagementGUI\initBadgeForm().

76  : array
77  {
78  $res = [];
79 
80  foreach (self::getInstances() as $tmpl) {
81  if (!count($tmpl->getTypes()) || in_array($a_type_unique_id, $tmpl->getTypes(), true)) {
82  $res[] = $tmpl;
83  }
84  }
85 
86  return $res;
87  }
$res
Definition: ltiservices.php:69
+ Here is the caller graph for this function:

◆ getPropertiesForStorage()

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

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

References getImage(), and getTitle().

Referenced by create(), and update().

302  : array
303  {
304  return [
305  "title" => ["text", $this->getTitle()],
306  "image" => ["text", $this->getImage()]
307  ];
308  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getTitle()

ilBadgeImageTemplate::getTitle ( )

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

References $title.

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

109  : string
110  {
111  return $this->title;
112  }
+ Here is the caller graph for this function:

◆ getTypes()

ilBadgeImageTemplate::getTypes ( )
Returns
string[]

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

References $types.

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

122  : ?array
123  {
124  return $this->types;
125  }
+ Here is the caller graph for this function:

◆ importDBRow()

ilBadgeImageTemplate::importDBRow ( array  $a_row)
protected

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

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

Referenced by read().

236  : void
237  {
238  $this->setId($a_row["id"]);
239  $this->setTitle($a_row["title"]);
240  $this->setImage($a_row["image"]);
241  $this->setTypes($a_row["types"]);
242  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ read()

ilBadgeImageTemplate::read ( int  $a_id)
protected

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

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

Referenced by __construct().

205  : void
206  {
207  $ilDB = $this->db;
208 
209  $set = $ilDB->query("SELECT * FROM badge_image_template" .
210  " WHERE id = " . $ilDB->quote($a_id, "integer"));
211  if ($ilDB->numRows($set)) {
212  $row = $ilDB->fetchAssoc($set);
213  $row["types"] = $this->readTypes($a_id);
214  $this->importDBRow($row);
215  }
216  }
+ 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 218 of file class.ilBadgeImageTemplate.php.

References $db, $ilDB, and $res.

Referenced by read().

218  : ?array
219  {
220  $ilDB = $this->db;
221 
222  $res = array();
223 
224  $set = $ilDB->query("SELECT * FROM badge_image_templ_type WHERE tmpl_id = " . $ilDB->quote($a_id, "integer"));
225  while ($row = $ilDB->fetchAssoc($set)) {
226  $res[] = $row["type_id"];
227  }
228 
229  if (!count($res)) {
230  $res = null;
231  }
232 
233  return $res;
234  }
$res
Definition: ltiservices.php:69
+ Here is the caller graph for this function:

◆ saveTypes()

ilBadgeImageTemplate::saveTypes ( )
protected

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

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

Referenced by create(), and update().

310  : void
311  {
312  $ilDB = $this->db;
313 
314  if ($this->getId()) {
315  $ilDB->manipulate("DELETE FROM badge_image_templ_type" .
316  " WHERE tmpl_id = " . $ilDB->quote($this->getId(), "integer"));
317 
318  if ($this->getTypes()) {
319  foreach ($this->getTypes() as $type) {
320  $fields = array(
321  "tmpl_id" => array("integer", $this->getId()),
322  "type_id" => array("text", $type)
323  );
324  $ilDB->insert("badge_image_templ_type", $fields);
325  }
326  }
327  }
328  }
+ 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 94 of file class.ilBadgeImageTemplate.php.

Referenced by create(), and importDBRow().

94  : void
95  {
96  $this->id = $a_id;
97  }
+ Here is the caller graph for this function:

◆ setImage()

ilBadgeImageTemplate::setImage ( string  $a_value)
protected

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

Referenced by importDBRow(), and uploadImage().

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

◆ setTitle()

ilBadgeImageTemplate::setTitle ( string  $a_value)

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

Referenced by importDBRow().

104  : void
105  {
106  $this->title = trim($a_value);
107  }
+ Here is the caller graph for this function:

◆ setTypes()

ilBadgeImageTemplate::setTypes ( array  $types = null)

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

Referenced by importDBRow().

127  : void
128  {
129  $this->types = is_array($types)
130  ? array_unique($types)
131  : null;
132  }
+ Here is the caller graph for this function:

◆ update()

ilBadgeImageTemplate::update ( )

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

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

Referenced by create(), and uploadImage().

264  : void
265  {
266  $ilDB = $this->db;
267 
268  if (!$this->getId()) {
269  $this->create();
270  return;
271  }
272 
273  $fields = $this->getPropertiesForStorage();
274 
275  $ilDB->update(
276  "badge_image_template",
277  $fields,
278  array("id" => array("integer", $this->getId()))
279  );
280 
281  $this->saveTypes();
282  }
+ 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 143 of file class.ilBadgeImageTemplate.php.

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

143  : void
144  {
145  if ($this->getId() &&
146  $a_upload_meta["tmp_name"]) {
147  $path = $this->getFilePath($this->getId());
148 
149 
150  $filename = ilFileUtils::getValidFilename($a_upload_meta["name"]);
151 
152  $exp = explode(".", $filename);
153  $suffix = strtolower(array_pop($exp));
154  $tgt = $path . "img" . $this->getId() . "." . $suffix;
155 
156  if (ilFileUtils::moveUploadedFile($a_upload_meta["tmp_name"], "img" . $this->getId() . "." . $suffix, $tgt)) {
157  $this->setImage($filename);
158  $this->update();
159  }
160  }
161  }
static getValidFilename(string $a_filename)
$path
Definition: ltiservices.php:32
getFilePath(int $a_id, string $a_subdir=null)
Init file system storage.
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
+ Here is the call graph for this function:

Field Documentation

◆ $db

ilDBInterface ilBadgeImageTemplate::$db
protected

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

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

◆ $id

int ilBadgeImageTemplate::$id = 0
protected

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

Referenced by getId().

◆ $image

string ilBadgeImageTemplate::$image = ""
protected

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

Referenced by getImage().

◆ $title

string ilBadgeImageTemplate::$title = ""
protected

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

Referenced by getTitle().

◆ $types

array ilBadgeImageTemplate::$types = null
protected

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

Referenced by getTypes().


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