ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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

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

25 {
26 if($a_id)
27 {
28 $this->read($a_id);
29 }
30 }

References read().

+ Here is the call graph for this function:

Member Function Documentation

◆ create()

ilBadgeImageTemplate::create ( )

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

242 {
243 global $ilDB;
244
245 if($this->getId())
246 {
247 return $this->update();
248 }
249
250 $id = $ilDB->nextId("badge_image_template");
251 $this->setId($id);
252
253 $fields = $this->getPropertiesForStorage();
254 $fields["id"] = array("integer", $id);
255
256 $ilDB->insert("badge_image_template", $fields);
257
258 $this->saveTypes();
259 }
global $ilDB

References $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 279 of file class.ilBadgeImageTemplate.php.

280 {
281 global $ilDB;
282
283 if(!$this->getId())
284 {
285 return;
286 }
287
288 $path = $this->getFilePath($this->getId());
290
291 $ilDB->manipulate("DELETE FROM badge_image_template".
292 " WHERE id = ".$ilDB->quote($this->getId(), "integer"));
293 }
$path
Definition: aliased.php:25
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 $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 172 of file class.ilBadgeImageTemplate.php.

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

References $path.

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

+ Here is the caller graph for this function:

◆ getId()

ilBadgeImageTemplate::getId ( )

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

86 {
87 return $this->id;
88 }

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

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

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

33 {
34 global $ilDB;
35
36 $res = array();
37
38 $types = array();
39 $set = $ilDB->query("SELECT * FROM badge_image_templ_type");
40 while($row = $ilDB->fetchAssoc($set))
41 {
42 $types[$row["tmpl_id"]][] = $row["type_id"];
43 }
44
45 $set = $ilDB->query("SELECT * FROM badge_image_template".
46 " ORDER BY title");
47 while($row = $ilDB->fetchAssoc($set))
48 {
49 $row["types"] = (array)$types[$row["id"]];
50
51 $obj = new self();
52 $obj->importDBRow($row);
53 $res[] = $obj;
54 }
55
56 return $res;
57 }

References $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 59 of file class.ilBadgeImageTemplate.php.

60 {
61 $res = array();
62
63 foreach(self::getInstances() as $tmpl)
64 {
65 if(!sizeof($tmpl->getTypes()) ||
66 in_array($a_type_unique_id, $tmpl->getTypes()))
67 {
68 $res[] = $tmpl;
69 }
70 }
71
72 return $res;
73 }

References $res.

Referenced by ilBadgeManagementGUI\initBadgeForm().

+ Here is the caller graph for this function:

◆ getPropertiesForStorage()

ilBadgeImageTemplate::getPropertiesForStorage ( )
protected

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

296 {
297 return array(
298 "title" => array("text", $this->getTitle()),
299 "image" => array("text", $this->getImage())
300 );
301 }

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

106 {
107 return (array)$this->types;
108 }

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

234 {
235 $this->setId($a_row["id"]);
236 $this->setTitle($a_row["title"]);
237 $this->setImage($a_row["image"]);
238 $this->setTypes($a_row["types"]);
239 }

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

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

References $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 212 of file class.ilBadgeImageTemplate.php.

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

References $ilDB, $res, and $row.

Referenced by read().

+ Here is the caller graph for this function:

◆ saveTypes()

ilBadgeImageTemplate::saveTypes ( )
protected

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

304 {
305 global $ilDB;
306
307 if($this->getId())
308 {
309 $ilDB->manipulate("DELETE FROM badge_image_templ_type".
310 " WHERE tmpl_id = ".$ilDB->quote($this->getId(), "integer"));
311
312 if($this->getTypes())
313 {
314 foreach($this->getTypes() as $type)
315 {
316 $fields = array(
317 "tmpl_id" => array("integer", $this->getId()),
318 "type_id" => array("text", $type)
319 );
320 $ilDB->insert("badge_image_templ_type", $fields);
321 }
322 }
323 }
324 }

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

81 {
82 $this->id = (int)$a_id;
83 }

Referenced by create(), and importDBRow().

+ Here is the caller graph for this function:

◆ setImage()

ilBadgeImageTemplate::setImage (   $a_value)
protected

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

101 {
102 $this->image = trim($a_value);
103 }

Referenced by importDBRow(), and uploadImage().

+ Here is the caller graph for this function:

◆ setTitle()

ilBadgeImageTemplate::setTitle (   $a_value)

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

91 {
92 $this->title = trim($a_value);
93 }

Referenced by importDBRow().

+ Here is the caller graph for this function:

◆ setTypes()

ilBadgeImageTemplate::setTypes ( array  $types = null)

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

111 {
112 $this->types = is_array($types)
113 ? array_unique($types)
114 : null;
115 }

References $types.

Referenced by importDBRow().

+ Here is the caller graph for this function:

◆ update()

ilBadgeImageTemplate::update ( )

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

262 {
263 global $ilDB;
264
265 if(!$this->getId())
266 {
267 return $this->create();
268 }
269
270 $fields = $this->getPropertiesForStorage();
271
272 $ilDB->update("badge_image_template", $fields,
273 array("id"=>array("integer", $this->getId()))
274 );
275
276 $this->saveTypes();
277 }

References $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 126 of file class.ilBadgeImageTemplate.php.

127 {
128 if($this->getId() &&
129 $a_upload_meta["tmp_name"])
130 {
131 $path = $this->getFilePath($this->getId());
132
133
134 include_once("./Services/Utilities/classes/class.ilFileUtils.php");
135 $filename = ilFileUtils::getValidFilename($a_upload_meta["name"]);
136
137 $suffix = strtolower(array_pop(explode(".", $filename)));
138 $tgt = $path."img".$this->getId().".".$suffix;
139
140 if(ilUtil::moveUploadedFile($a_upload_meta["tmp_name"], "img".$this->getId().".".$suffix, $tgt))
141 {
142 $this->setImage($filename);
143 $this->update();
144 }
145 }
146 }
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, $path, getFilePath(), getId(), ilFileUtils\getValidFilename(), ilUtil\moveUploadedFile(), setImage(), and update().

+ Here is the call graph for this function:

Field Documentation

◆ $id

ilBadgeImageTemplate::$id
protected

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

Referenced by create(), and getId().

◆ $image

ilBadgeImageTemplate::$image
protected

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

Referenced by getImage().

◆ $title

ilBadgeImageTemplate::$title
protected

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

Referenced by getTitle().

◆ $types

ilBadgeImageTemplate::$types
protected

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

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


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