ILIAS  release_7 Revision v7.30-3-g800a261c036
ilBadgeImageTemplate Class Reference

Badge Template. More...

+ Collaboration diagram for ilBadgeImageTemplate:

Public Member Functions

 __construct ($a_id=null)
 Constructor. More...
 
 getId ()
 
 setTitle ($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 ($a_type_unique_id)
 

Protected Member Functions

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

Protected Attributes

 $db
 
 $id
 
 $title
 
 $image
 
 $types
 

Detailed Description

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

Constructor & Destructor Documentation

◆ __construct()

ilBadgeImageTemplate::__construct (   $a_id = null)

Constructor.

Parameters
int$a_id
Returns
self

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

29 {
30 global $DIC;
31
32 $this->db = $DIC->database();
33 if ($a_id) {
34 $this->read($a_id);
35 }
36 }
global $DIC
Definition: goto.php:24

References $DIC, and read().

+ Here is the call graph for this function:

Member Function Documentation

◆ create()

ilBadgeImageTemplate::create ( )

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

233 {
235
236 if ($this->getId()) {
237 return $this->update();
238 }
239
240 $id = $ilDB->nextId("badge_image_template");
241 $this->setId($id);
242
243 $fields = $this->getPropertiesForStorage();
244 $fields["id"] = array("integer", $id);
245
246 $ilDB->insert("badge_image_template", $fields);
247
248 $this->saveTypes();
249 }
global $ilDB

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

Referenced by update().

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

◆ delete()

ilBadgeImageTemplate::delete ( )

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

271 {
273
274 if (!$this->getId()) {
275 return;
276 }
277
278 $path = $this->getFilePath($this->getId());
279 ilUtil::delDir($path);
280
281 $ilDB->manipulate("DELETE FROM badge_image_template" .
282 " WHERE id = " . $ilDB->quote($this->getId(), "integer"));
283 }
getFilePath($a_id, $a_subdir=null)
Init file system storage.
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively

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

+ Here is the call graph for this function:

◆ getFilePath()

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

Init file system storage.

Parameters
type$a_id
type$a_subdir
Returns
string

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

170 {
171 $storage = new ilFSStorageBadgeImageTemplate($a_id);
172 $storage->create();
173
174 $path = $storage->getAbsolutePath() . "/";
175
176 if ($a_subdir) {
177 $path .= $a_subdir . "/";
178
179 if (!is_dir($path)) {
180 mkdir($path);
181 }
182 }
183
184 return $path;
185 }

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

+ Here is the caller graph for this function:

◆ getId()

ilBadgeImageTemplate::getId ( )

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

90 {
91 return $this->id;
92 }

References $id.

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

+ Here is the caller graph for this function:

◆ getImage()

ilBadgeImageTemplate::getImage ( )

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

References $image.

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

+ Here is the caller graph for this function:

◆ getImagePath()

ilBadgeImageTemplate::getImagePath ( )

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

150 {
151 if ($this->getId()) {
152 if (is_file($this->getFilePath($this->getId()) . "img" . $this->getId())) { // formerly (early 5.2 versino), images have been uploaded with no suffix
153 return $this->getFilePath($this->getId()) . "img" . $this->getId();
154 } else {
155 $suffix = strtolower(array_pop(explode(".", $this->getImage())));
156 return $this->getFilePath($this->getId()) . "img" . $this->getId() . "." . $suffix;
157 }
158 }
159 return "";
160 }

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

Referenced by ilObjBadgeAdministrationGUI\setImageTemplateFormValues().

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

◆ getInstances()

static ilBadgeImageTemplate::getInstances ( )
static

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

39 {
40 global $DIC;
41
42 $ilDB = $DIC->database();
43
44 $res = array();
45
46 $types = array();
47 $set = $ilDB->query("SELECT * FROM badge_image_templ_type");
48 while ($row = $ilDB->fetchAssoc($set)) {
49 $types[$row["tmpl_id"]][] = $row["type_id"];
50 }
51
52 $set = $ilDB->query("SELECT * FROM badge_image_template" .
53 " ORDER BY title");
54 while ($row = $ilDB->fetchAssoc($set)) {
55 $row["types"] = (array) $types[$row["id"]];
56
57 $obj = new self();
58 $obj->importDBRow($row);
59 $res[] = $obj;
60 }
61
62 return $res;
63 }
foreach($_POST as $key=> $value) $res

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

Referenced by ilBadgeImageTemplateTableGUI\getItems().

+ Here is the caller graph for this function:

◆ getInstancesByType()

static ilBadgeImageTemplate::getInstancesByType (   $a_type_unique_id)
static

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

66 {
67 $res = array();
68
69 foreach (self::getInstances() as $tmpl) {
70 if (!sizeof($tmpl->getTypes()) ||
71 in_array($a_type_unique_id, $tmpl->getTypes())) {
72 $res[] = $tmpl;
73 }
74 }
75
76 return $res;
77 }

References $res.

Referenced by ilBadgeManagementGUI\initBadgeForm().

+ Here is the caller graph for this function:

◆ getPropertiesForStorage()

ilBadgeImageTemplate::getPropertiesForStorage ( )
protected

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

286 {
287 return array(
288 "title" => array("text", $this->getTitle()),
289 "image" => array("text", $this->getImage())
290 );
291 }

References getImage(), and getTitle().

Referenced by create(), and update().

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

◆ getTitle()

ilBadgeImageTemplate::getTitle ( )

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

References $title.

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

+ Here is the caller graph for this function:

◆ getTypes()

ilBadgeImageTemplate::getTypes ( )

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

110 {
111 return (array) $this->types;
112 }

References $types.

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

+ Here is the caller graph for this function:

◆ importDBRow()

ilBadgeImageTemplate::importDBRow ( array  $a_row)
protected

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

225 {
226 $this->setId($a_row["id"]);
227 $this->setTitle($a_row["title"]);
228 $this->setImage($a_row["image"]);
229 $this->setTypes($a_row["types"]);
230 }

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

Referenced by read().

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

◆ read()

ilBadgeImageTemplate::read (   $a_id)
protected

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

193 {
195
196 $set = $ilDB->query("SELECT * FROM badge_image_template" .
197 " WHERE id = " . $ilDB->quote($a_id, "integer"));
198 if ($ilDB->numRows($set)) {
199 $row = $ilDB->fetchAssoc($set);
200 $row["types"] = $this->readTypes($a_id);
201 $this->importDBRow($row);
202 }
203 }

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

Referenced by __construct().

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

◆ readTypes()

ilBadgeImageTemplate::readTypes (   $a_id)
protected

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

206 {
208
209 $res = array();
210
211 $set = $ilDB->query("SELECT * FROM badge_image_templ_type" .
212 " WHERE tmpl_id = " . $ilDB->quote($a_id, "integer"));
213 while ($row = $ilDB->fetchAssoc($set)) {
214 $res[] = $row["type_id"];
215 }
216
217 if (!sizeof($res)) {
218 $res = null;
219 }
220
221 return $res;
222 }

References $db, $ilDB, and $res.

Referenced by read().

+ Here is the caller graph for this function:

◆ saveTypes()

ilBadgeImageTemplate::saveTypes ( )
protected

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

294 {
296
297 if ($this->getId()) {
298 $ilDB->manipulate("DELETE FROM badge_image_templ_type" .
299 " WHERE tmpl_id = " . $ilDB->quote($this->getId(), "integer"));
300
301 if ($this->getTypes()) {
302 foreach ($this->getTypes() as $type) {
303 $fields = array(
304 "tmpl_id" => array("integer", $this->getId()),
305 "type_id" => array("text", $type)
306 );
307 $ilDB->insert("badge_image_templ_type", $fields);
308 }
309 }
310 }
311 }
$type

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

Referenced by create(), and update().

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

◆ setId()

ilBadgeImageTemplate::setId (   $a_id)
protected

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

85 {
86 $this->id = (int) $a_id;
87 }

Referenced by create(), and importDBRow().

+ Here is the caller graph for this function:

◆ setImage()

ilBadgeImageTemplate::setImage (   $a_value)
protected

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

105 {
106 $this->image = trim($a_value);
107 }

Referenced by importDBRow(), and uploadImage().

+ Here is the caller graph for this function:

◆ setTitle()

ilBadgeImageTemplate::setTitle (   $a_value)

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

95 {
96 $this->title = trim($a_value);
97 }

Referenced by importDBRow().

+ Here is the caller graph for this function:

◆ setTypes()

ilBadgeImageTemplate::setTypes ( array  $types = null)

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

115 {
116 $this->types = is_array($types)
117 ? array_unique($types)
118 : null;
119 }

References $types.

Referenced by importDBRow().

+ Here is the caller graph for this function:

◆ update()

ilBadgeImageTemplate::update ( )

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

252 {
254
255 if (!$this->getId()) {
256 return $this->create();
257 }
258
259 $fields = $this->getPropertiesForStorage();
260
261 $ilDB->update(
262 "badge_image_template",
263 $fields,
264 array("id" => array("integer", $this->getId()))
265 );
266
267 $this->saveTypes();
268 }

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

Referenced by create(), 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)
Parameters
array$a_upload_meta
Exceptions
ilFileUtilsException

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

131 {
132 if ($this->getId() &&
133 $a_upload_meta["tmp_name"]) {
134 $path = $this->getFilePath($this->getId());
135
136
137 $filename = ilFileUtils::getValidFilename($a_upload_meta["name"]);
138
139 $suffix = strtolower(array_pop(explode(".", $filename)));
140 $tgt = $path . "img" . $this->getId() . "." . $suffix;
141
142 if (ilUtil::moveUploadedFile($a_upload_meta["tmp_name"], "img" . $this->getId() . "." . $suffix, $tgt)) {
143 $this->setImage($filename);
144 $this->update();
145 }
146 }
147 }
$filename
Definition: buildRTE.php:89
static getValidFilename($a_filename)
Get valid filename.
static moveUploadedFile($a_file, $a_name, $a_target, $a_raise_errors=true, $a_mode="move_uploaded")
move uploaded file

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

+ Here is the call graph for this function:

Field Documentation

◆ $db

ilBadgeImageTemplate::$db
protected

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

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

◆ $id

ilBadgeImageTemplate::$id
protected

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

Referenced by create(), and getId().

◆ $image

ilBadgeImageTemplate::$image
protected

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

Referenced by getImage().

◆ $title

ilBadgeImageTemplate::$title
protected

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

Referenced by getTitle().

◆ $types

ilBadgeImageTemplate::$types
protected

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

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


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