ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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
Version
$Id:$

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

Constructor & Destructor Documentation

◆ __construct()

ilBadgeImageTemplate::__construct (   $a_id = null)

Constructor.

Parameters
int$a_id
Returns
self

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

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

References $DIC, and read().

+ Here is the call graph for this function:

Member Function Documentation

◆ create()

ilBadgeImageTemplate::create ( )

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

236 {
238
239 if ($this->getId()) {
240 return $this->update();
241 }
242
243 $id = $ilDB->nextId("badge_image_template");
244 $this->setId($id);
245
246 $fields = $this->getPropertiesForStorage();
247 $fields["id"] = array("integer", $id);
248
249 $ilDB->insert("badge_image_template", $fields);
250
251 $this->saveTypes();
252 }
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 273 of file class.ilBadgeImageTemplate.php.

274 {
276
277 if (!$this->getId()) {
278 return;
279 }
280
281 $path = $this->getFilePath($this->getId());
283
284 $ilDB->manipulate("DELETE FROM badge_image_template" .
285 " WHERE id = " . $ilDB->quote($this->getId(), "integer"));
286 }
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, $path, 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 171 of file class.ilBadgeImageTemplate.php.

172 {
173 include_once "Services/Badge/classes/class.ilFSStorageBadgeImageTemplate.php";
174 $storage = new ilFSStorageBadgeImageTemplate($a_id);
175 $storage->create();
176
177 $path = $storage->getAbsolutePath() . "/";
178
179 if ($a_subdir) {
180 $path .= $a_subdir . "/";
181
182 if (!is_dir($path)) {
183 mkdir($path);
184 }
185 }
186
187 return $path;
188 }

References $path.

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

+ Here is the caller graph for this function:

◆ getId()

ilBadgeImageTemplate::getId ( )

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

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

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

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

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

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

References $DIC, $ilDB, $res, $row, 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 66 of file class.ilBadgeImageTemplate.php.

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

References $res.

Referenced by ilBadgeManagementGUI\initBadgeForm().

+ Here is the caller graph for this function:

◆ getPropertiesForStorage()

ilBadgeImageTemplate::getPropertiesForStorage ( )
protected

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

289 {
290 return array(
291 "title" => array("text", $this->getTitle()),
292 "image" => array("text", $this->getImage())
293 );
294 }

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

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

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

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

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

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

References $db, $ilDB, $row, 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 208 of file class.ilBadgeImageTemplate.php.

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

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

Referenced by read().

+ Here is the caller graph for this function:

◆ saveTypes()

ilBadgeImageTemplate::saveTypes ( )
protected

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

297 {
299
300 if ($this->getId()) {
301 $ilDB->manipulate("DELETE FROM badge_image_templ_type" .
302 " WHERE tmpl_id = " . $ilDB->quote($this->getId(), "integer"));
303
304 if ($this->getTypes()) {
305 foreach ($this->getTypes() as $type) {
306 $fields = array(
307 "tmpl_id" => array("integer", $this->getId()),
308 "type_id" => array("text", $type)
309 );
310 $ilDB->insert("badge_image_templ_type", $fields);
311 }
312 }
313 }
314 }
$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 85 of file class.ilBadgeImageTemplate.php.

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

Referenced by create(), and importDBRow().

+ Here is the caller graph for this function:

◆ setImage()

ilBadgeImageTemplate::setImage (   $a_value)
protected

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

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

Referenced by importDBRow(), and uploadImage().

+ Here is the caller graph for this function:

◆ setTitle()

ilBadgeImageTemplate::setTitle (   $a_value)

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

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

Referenced by importDBRow().

+ Here is the caller graph for this function:

◆ setTypes()

ilBadgeImageTemplate::setTypes ( array  $types = null)

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

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

References $types.

Referenced by importDBRow().

+ Here is the caller graph for this function:

◆ update()

ilBadgeImageTemplate::update ( )

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

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

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

132 {
133 if ($this->getId() &&
134 $a_upload_meta["tmp_name"]) {
135 $path = $this->getFilePath($this->getId());
136
137
138 include_once("./Services/Utilities/classes/class.ilFileUtils.php");
139 $filename = ilFileUtils::getValidFilename($a_upload_meta["name"]);
140
141 $suffix = strtolower(array_pop(explode(".", $filename)));
142 $tgt = $path . "img" . $this->getId() . "." . $suffix;
143
144 if (ilUtil::moveUploadedFile($a_upload_meta["tmp_name"], "img" . $this->getId() . "." . $suffix, $tgt)) {
145 $this->setImage($filename);
146 $this->update();
147 }
148 }
149 }
static getValidFilename($a_filename)
Get valid filename.

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

+ Here is the call graph for this function:

Field Documentation

◆ $db

ilBadgeImageTemplate::$db
protected

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

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

◆ $id

ilBadgeImageTemplate::$id
protected

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

Referenced by create(), and getId().

◆ $image

ilBadgeImageTemplate::$image
protected

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

Referenced by getImage().

◆ $title

ilBadgeImageTemplate::$title
protected

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

Referenced by getTitle().

◆ $types

ilBadgeImageTemplate::$types
protected

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

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


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