ILIAS  release_8 Revision v8.24
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.

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

References $DIC, and read().

+ Here is the call graph for this function:

Member Function Documentation

◆ create()

ilBadgeImageTemplate::create ( )

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

245 : void
246 {
248
249 if ($this->getId()) {
250 $this->update();
251 return;
252 }
253
254 $id = $ilDB->nextId("badge_image_template");
255 $this->setId($id);
256
257 $fields = $this->getPropertiesForStorage();
258 $fields["id"] = array("integer", $id);
259
260 $ilDB->insert("badge_image_template", $fields);
261
262 $this->saveTypes();
263 }

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

+ Here is the call graph for this function:

◆ delete()

ilBadgeImageTemplate::delete ( )

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

285 : void
286 {
288
289 if (!$this->getId()) {
290 return;
291 }
292
293 $path = $this->getFilePath($this->getId());
295
296 $ilDB->manipulate("DELETE FROM badge_image_template" .
297 " WHERE id = " . $ilDB->quote($this->getId(), "integer"));
298 }
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:32

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 181 of file class.ilBadgeImageTemplate.php.

184 : string {
185 $storage = new ilFSStorageBadgeImageTemplate($a_id);
186 $storage->create();
187
188 $path = $storage->getAbsolutePath() . "/";
189
190 if ($a_subdir) {
191 $path .= $a_subdir . "/";
192
193 if (!is_dir($path)) {
194 mkdir($path);
195 }
196 }
197
198 return $path;
199 }
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 100 of file class.ilBadgeImageTemplate.php.

100 : int
101 {
102 return $this->id;
103 }

References $id.

Referenced by getImagePath(), and uploadImage().

+ Here is the caller graph for this function:

◆ getImage()

ilBadgeImageTemplate::getImage ( )

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

135 : string
136 {
137 return $this->image;
138 }

References $image.

Referenced by getImagePath().

+ Here is the caller graph for this function:

◆ getImagePath()

ilBadgeImageTemplate::getImagePath ( )

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

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

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

+ Here is the call graph for this function:

◆ getInstances()

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

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

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

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

Referenced by ilBadgeImageTemplateTableGUI\getItems().

+ Here is the caller graph for this function:

◆ getInstancesByType()

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

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

77 : array
78 {
79 $res = [];
80
81 foreach (self::getInstances() as $tmpl) {
82 if (!count($tmpl->getTypes()) || in_array($a_type_unique_id, $tmpl->getTypes(), true)) {
83 $res[] = $tmpl;
84 }
85 }
86
87 return $res;
88 }

References $res.

◆ getPropertiesForStorage()

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

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

303 : array
304 {
305 return [
306 "title" => ["text", $this->getTitle()],
307 "image" => ["text", $this->getImage()]
308 ];
309 }

◆ getTitle()

ilBadgeImageTemplate::getTitle ( )

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

110 : string
111 {
112 return $this->title;
113 }

References $title.

◆ getTypes()

ilBadgeImageTemplate::getTypes ( )
Returns
string[]

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

123 : ?array
124 {
125 return $this->types;
126 }

References $types.

Referenced by ilObjBadgeAdministrationGUI\setImageTemplateFormValues().

+ Here is the caller graph for this function:

◆ importDBRow()

ilBadgeImageTemplate::importDBRow ( array  $a_row)
protected

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

237 : void
238 {
239 $this->setId($a_row["id"]);
240 $this->setTitle($a_row["title"]);
241 $this->setImage($a_row["image"]);
242 $this->setTypes($a_row["types"]);
243 }

◆ read()

ilBadgeImageTemplate::read ( int  $a_id)
protected

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

206 : void
207 {
209
210 $set = $ilDB->query("SELECT * FROM badge_image_template" .
211 " WHERE id = " . $ilDB->quote($a_id, "integer"));
212 if ($ilDB->numRows($set)) {
213 $row = $ilDB->fetchAssoc($set);
214 $row["types"] = $this->readTypes($a_id);
215 $this->importDBRow($row);
216 }
217 }

References $ilDB.

Referenced by __construct().

+ Here is the caller graph for this function:

◆ readTypes()

ilBadgeImageTemplate::readTypes ( int  $a_id)
protected

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

219 : ?array
220 {
222
223 $res = array();
224
225 $set = $ilDB->query("SELECT * FROM badge_image_templ_type WHERE tmpl_id = " . $ilDB->quote($a_id, "integer"));
226 while ($row = $ilDB->fetchAssoc($set)) {
227 $res[] = $row["type_id"];
228 }
229
230 if (!count($res)) {
231 $res = null;
232 }
233
234 return $res;
235 }

References $ilDB, and $res.

◆ saveTypes()

ilBadgeImageTemplate::saveTypes ( )
protected

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

311 : void
312 {
314
315 if ($this->getId()) {
316 $ilDB->manipulate("DELETE FROM badge_image_templ_type" .
317 " WHERE tmpl_id = " . $ilDB->quote($this->getId(), "integer"));
318
319 if ($this->getTypes()) {
320 foreach ($this->getTypes() as $type) {
321 $fields = array(
322 "tmpl_id" => array("integer", $this->getId()),
323 "type_id" => array("text", $type)
324 );
325 $ilDB->insert("badge_image_templ_type", $fields);
326 }
327 }
328 }
329 }
$type

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

+ Here is the call graph for this function:

◆ setId()

ilBadgeImageTemplate::setId ( int  $a_id)
protected

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

95 : void
96 {
97 $this->id = $a_id;
98 }

◆ setImage()

ilBadgeImageTemplate::setImage ( string  $a_value)
protected

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

115 : void
116 {
117 $this->image = trim($a_value);
118 }

Referenced by uploadImage().

+ Here is the caller graph for this function:

◆ setTitle()

ilBadgeImageTemplate::setTitle ( string  $a_value)

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

105 : void
106 {
107 $this->title = trim($a_value);
108 }

◆ setTypes()

ilBadgeImageTemplate::setTypes ( array  $types = null)

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

128 : void
129 {
130 $this->types = is_array($types)
131 ? array_unique($types)
132 : null;
133 }

References $types.

◆ update()

ilBadgeImageTemplate::update ( )

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

265 : void
266 {
268
269 if (!$this->getId()) {
270 $this->create();
271 return;
272 }
273
274 $fields = $this->getPropertiesForStorage();
275
276 $ilDB->update(
277 "badge_image_template",
278 $fields,
279 array("id" => array("integer", $this->getId()))
280 );
281
282 $this->saveTypes();
283 }

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

Referenced by 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 144 of file class.ilBadgeImageTemplate.php.

144 : void
145 {
146 if ($this->getId() &&
147 $a_upload_meta["tmp_name"]) {
148 $path = $this->getFilePath($this->getId());
149
150
151 $filename = ilFileUtils::getValidFilename($a_upload_meta["name"]);
152
153 $exp = explode(".", $filename);
154 $suffix = strtolower(array_pop($exp));
155 $tgt = $path . "img" . $this->getId() . "." . $suffix;
156
157 if (ilFileUtils::moveUploadedFile($a_upload_meta["tmp_name"], "img" . $this->getId() . "." . $suffix, $tgt)) {
158 $this->setImage($filename);
159 $this->update();
160 }
161 }
162 }
$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 26 of file class.ilBadgeImageTemplate.php.

◆ $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 getInstances(), getTypes(), and setTypes().


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