ILIAS  release_8 Revision v8.24
ilBadge Class Reference
+ Collaboration diagram for ilBadge:

Public Member Functions

 __construct (int $a_id=null)
 
 clone (int $target_parent_obj_id)
 
 getTypeInstance ()
 
 copy (int $a_new_parent_id)
 
 getId ()
 
 setParentId (int $a_id)
 
 getParentId ()
 
 setTypeId (string $a_id)
 
 getTypeId ()
 
 setActive (bool $a_value)
 
 isActive ()
 
 setTitle (string $a_value)
 
 getTitle ()
 
 setDescription (string $a_value)
 
 getDescription ()
 
 setCriteria (string $a_value)
 
 getCriteria ()
 
 setValid (string $a_value)
 
 getValid ()
 
 setConfiguration (array $a_value=null)
 
 getConfiguration ()
 
 getImage ()
 
 uploadImage (array $a_upload_meta)
 
 importImage (string $a_name, string $a_file)
 
 getImagePath (bool $a_full_path=true)
 
 create ()
 
 update ()
 
 delete ()
 
 getParentMeta ()
 
 deleteStaticFiles ()
 

Static Public Member Functions

static getInstancesByParentId (int $a_parent_id, array $a_filter=null)
 
static getInstancesByType (string $a_type_id)
 
static getObjectInstances (array $a_filter=null)
 
static getExtendedTypeCaption (ilBadgeType $a_type)
 

Protected Member Functions

 setId (int $a_id)
 
 setImage (string $a_value)
 
 getFilePath (int $a_id, string $a_subdir=null)
 
 read (int $a_id)
 
 importDBRow (array $a_row)
 
 getPropertiesForStorage ()
 
 prepareJson (string $a_base_url, string $a_img_suffix)
 

Protected Attributes

ilLanguage $lng
 
ilDBInterface $db
 
int $id = 0
 
int $parent_id = 0
 
string $type_id = ""
 
bool $active = false
 
string $title = ""
 
string $desc = ""
 
string $image = ""
 
string $valid = ""
 
array $config = null
 
string $criteria = ""
 

Detailed Description

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.ilBadge.php.

Constructor & Destructor Documentation

◆ __construct()

ilBadge::__construct ( int  $a_id = null)

Definition at line 40 of file class.ilBadge.php.

42 {
43 global $DIC;
44
45 $this->lng = $DIC->language();
46 $this->db = $DIC->database();
47 if ($a_id) {
48 $this->read($a_id);
49 }
50 }
read(int $a_id)
global $DIC
Definition: feed.php:28

References $DIC, ILIAS\Repository\lng(), and read().

+ Here is the call graph for this function:

Member Function Documentation

◆ clone()

ilBadge::clone ( int  $target_parent_obj_id)

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

115 : void
116 {
117 $this->setParentId($target_parent_obj_id);
118 $this->setActive(false);
119
120 if ($this->getId()) {
121 $img = $this->getImagePath();
122
123 $this->setId(0);
124 $this->create();
125
126 if ($img) {
127 // see uploadImage()
128 copy($img, $this->getImagePath());
129 }
130 }
131 }
setId(int $a_id)
getImagePath(bool $a_full_path=true)
setActive(bool $a_value)
setParentId(int $a_id)
copy(int $a_new_parent_id)
$img
Definition: imgupload.php:83

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

+ Here is the call graph for this function:

◆ copy()

ilBadge::copy ( int  $a_new_parent_id)

Definition at line 142 of file class.ilBadge.php.

144 : void {
146
147 $this->setTitle($this->getTitle() . " " . $lng->txt("copy_of_suffix"));
148 $this->setParentId($a_new_parent_id);
149 $this->setActive(false);
150
151 if ($this->getId()) {
152 $img = $this->getImagePath();
153
154 $this->setId(0);
155 $this->create();
156
157 if ($img) {
158 // see uploadImage()
159 copy($img, $this->getImagePath());
160 }
161 }
162 }
ilLanguage $lng
setTitle(string $a_value)
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...

◆ create()

ilBadge::create ( )

Definition at line 431 of file class.ilBadge.php.

431 : void
432 {
434
435 if ($this->getId()) {
436 $this->update();
437 return;
438 }
439
440 $id = $ilDB->nextId("badge_badge");
441 $this->setId($id);
442
443 $fields = $this->getPropertiesForStorage();
444
445 $fields["id"] = ["integer", $id];
446 $fields["parent_id"] = ["integer", $this->getParentId()];
447 $fields["type_id"] = ["text", $this->getTypeId()];
448
449 $ilDB->insert("badge_badge", $fields);
450 }
ilDBInterface $db
getPropertiesForStorage()

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

+ Here is the call graph for this function:

◆ delete()

ilBadge::delete ( )

Definition at line 470 of file class.ilBadge.php.

470 : void
471 {
473
474 if (!$this->getId()) {
475 return;
476 }
477
478 if (file_exists($this->getImagePath())) {
479 unlink($this->getImagePath());
480 }
481
482 $this->deleteStaticFiles();
483
485
486 $ilDB->manipulate("DELETE FROM badge_badge" .
487 " WHERE id = " . $ilDB->quote($this->getId(), "integer"));
488 }
static deleteByBadgeId(int $a_badge_id)
deleteStaticFiles()

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

+ Here is the call graph for this function:

◆ deleteStaticFiles()

ilBadge::deleteStaticFiles ( )

Definition at line 564 of file class.ilBadge.php.

564 : void
565 {
566 // remove instance files
567 $path = ilBadgeHandler::getInstance()->getBadgePath($this);
568 if (is_dir($path)) {
570 }
571 }
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 $path, ilFileUtils\delDir(), and ilBadgeHandler\getInstance().

+ Here is the call graph for this function:

◆ getConfiguration()

ilBadge::getConfiguration ( )

Definition at line 308 of file class.ilBadge.php.

308 : ?array
309 {
310 return $this->config;
311 }
array $config

References $config.

Referenced by ilBadgeManagementGUI\setBadgeFormValues().

+ Here is the caller graph for this function:

◆ getCriteria()

ilBadge::getCriteria ( )

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

285 : string
286 {
287 return $this->criteria;
288 }
string $criteria

◆ getDescription()

ilBadge::getDescription ( )

Definition at line 275 of file class.ilBadge.php.

275 : string
276 {
277 return $this->desc;
278 }
string $desc

◆ getExtendedTypeCaption()

static ilBadge::getExtendedTypeCaption ( ilBadgeType  $a_type)
static

Definition at line 573 of file class.ilBadge.php.

575 : string {
576 global $DIC;
577
578 $lng = $DIC->language();
579
580 return $a_type->getCaption() . " (" .
581 ($a_type instanceof ilBadgeAuto
582 ? $lng->txt("badge_subtype_auto")
583 : $lng->txt("badge_subtype_manual")) . ")";
584 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

Referenced by ilObjectBadgeTableGUI\getItems(), ilBadgeTableGUI\getItems(), ilBadgeTableGUI\initFilter(), ilObjectBadgeTableGUI\initFilter(), and ilBadgeManagementGUI\listBadges().

+ Here is the caller graph for this function:

◆ getFilePath()

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

Definition at line 377 of file class.ilBadge.php.

380 : string {
381 $storage = new ilFSStorageBadge($a_id);
382 $storage->create();
383
384 $path = $storage->getAbsolutePath() . "/";
385
386 if ($a_subdir) {
387 $path .= $a_subdir . "/";
388
389 if (!is_dir($path)) {
390 mkdir($path);
391 }
392 }
393
394 return $path;
395 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

References $path.

◆ getId()

ilBadge::getId ( )

Definition at line 225 of file class.ilBadge.php.

225 : int
226 {
227 return $this->id;
228 }

References $id.

Referenced by ilBadgeHandler\countStaticBadgeInstances(), and ilBadgeHandler\getBadgePath().

+ Here is the caller graph for this function:

◆ getImage()

ilBadge::getImage ( )

Definition at line 318 of file class.ilBadge.php.

318 : string
319 {
320 return $this->image;
321 }
string $image

◆ getImagePath()

ilBadge::getImagePath ( bool  $a_full_path = true)

Definition at line 362 of file class.ilBadge.php.

364 : string {
365 if ($this->getId()) {
366 $exp = explode(".", $this->getImage());
367 $suffix = strtolower(array_pop($exp));
368 if ($a_full_path) {
369 return $this->getFilePath($this->getId()) . "img" . $this->getId() . "." . $suffix;
370 }
371
372 return "img" . $this->getId() . "." . $suffix;
373 }
374 return "";
375 }
getFilePath(int $a_id, string $a_subdir=null)

References ILIAS\Survey\Mode\getId().

+ Here is the call graph for this function:

◆ getInstancesByParentId()

static ilBadge::getInstancesByParentId ( int  $a_parent_id,
array  $a_filter = null 
)
static
Parameters
int$a_parent_id
array | null$a_filter
Returns
self[]

Definition at line 57 of file class.ilBadge.php.

60 : array {
61 global $DIC;
62
63 $ilDB = $DIC->database();
64
65 $res = [];
66
67 $sql = "SELECT * FROM badge_badge" .
68 " WHERE parent_id = " . $ilDB->quote($a_parent_id);
69
70 if ($a_filter) {
71 if ($a_filter["title"] ?? false) {
72 $sql .= " AND " . $ilDB->like("title", "text", "%" . trim($a_filter["title"]) . "%");
73 }
74 if ($a_filter["type"] ?? false) {
75 $sql .= " AND type_id = " . $ilDB->quote($a_filter["type"], "integer");
76 }
77 }
78
79 $set = $ilDB->query($sql .
80 " ORDER BY title");
81 while ($row = $ilDB->fetchAssoc($set)) {
82 $obj = new self();
83 $obj->importDBRow($row);
84 $res[] = $obj;
85 }
86
87 return $res;
88 }
$res
Definition: ltiservices.php:69

References $ilDB.

Referenced by ilObjCourse\cloneObject(), and ilBadgeTableGUI\getItems().

+ Here is the caller graph for this function:

◆ getInstancesByType()

static ilBadge::getInstancesByType ( string  $a_type_id)
static
Parameters
string$a_type_id
Returns
self[]

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

96 : array {
97 global $DIC;
98
99 $ilDB = $DIC->database();
100
101 $res = [];
102
103 $set = $ilDB->query("SELECT * FROM badge_badge" .
104 " WHERE type_id = " . $ilDB->quote($a_type_id, "text") .
105 " ORDER BY title");
106 while ($row = $ilDB->fetchAssoc($set)) {
107 $obj = new self();
108 $obj->importDBRow($row);
109 $res[] = $obj;
110 }
111
112 return $res;
113 }

References $res.

◆ getObjectInstances()

static ilBadge::getObjectInstances ( array  $a_filter = null)
static
Parameters
array<string,mixed>|null$a_filter
Returns
array[]

Definition at line 168 of file class.ilBadge.php.

170 : array {
171 global $DIC;
172
173 $ilDB = $DIC->database();
174
175 $res = $raw = [];
176
177 $where = "";
178
179 if ($a_filter["type"]) {
180 $where .= " AND bb.type_id = " . $ilDB->quote($a_filter["type"], "text");
181 }
182 if ($a_filter["title"]) {
183 $where .= " AND " . $ilDB->like("bb.title", "text", "%" . $a_filter["title"] . "%");
184 }
185 if ($a_filter["object"]) {
186 $where .= " AND " . $ilDB->like("od.title", "text", "%" . $a_filter["object"] . "%");
187 }
188
189 $set = $ilDB->query("SELECT bb.*, od.title parent_title, od.type parent_type" .
190 " FROM badge_badge bb" .
191 " JOIN object_data od ON (bb.parent_id = od.obj_id)" .
192 " WHERE od.type <> " . $ilDB->quote("bdga", "text") .
193 $where);
194 while ($row = $ilDB->fetchAssoc($set)) {
195 $raw[] = $row;
196 }
197
198 $set = $ilDB->query("SELECT bb.*, od.title parent_title, od.type parent_type" .
199 " FROM badge_badge bb" .
200 " JOIN object_data_del od ON (bb.parent_id = od.obj_id)" .
201 " WHERE od.type <> " . $ilDB->quote("bdga", "text") .
202 $where);
203 while ($row = $ilDB->fetchAssoc($set)) {
204 $row["deleted"] = true;
205 $raw[] = $row;
206 }
207
208 foreach ($raw as $row) {
209 $res[] = $row;
210 }
211
212 return $res;
213 }

References $ilDB.

Referenced by ilObjectBadgeTableGUI\getItems().

+ Here is the caller graph for this function:

◆ getParentId()

ilBadge::getParentId ( )

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

235 : int
236 {
237 return $this->parent_id;
238 }
int $parent_id

◆ getParentMeta()

ilBadge::getParentMeta ( )
Returns
array{id: int, type: string, title: string, deleted: bool}

Definition at line 516 of file class.ilBadge.php.

516 : array
517 {
518 $parent_type = ilObject::_lookupType($this->getParentId());
519 $parent_title = "";
520 if ($parent_type) {
521 $parent_title = ilObject::_lookupTitle($this->getParentId());
522 $deleted = false;
523 } else {
524 // already deleted?
525 $parent = ilObjectDataDeletionLog::get($this->getParentId());
526 if ($parent["type"]) {
527 $parent_type = $parent["type"];
528 $parent_title = $parent["title"];
529 }
530 $deleted = true;
531 }
532
533 return [
534 "id" => $this->getParentId(),
535 "type" => $parent_type,
536 "title" => $parent_title,
537 "deleted" => $deleted
538 ];
539 }
static _lookupType(int $id, bool $reference=false)
static _lookupTitle(int $obj_id)

References ilObject\_lookupTitle(), ilObject\_lookupType(), and ilObjectDataDeletionLog\get().

+ Here is the call graph for this function:

◆ getPropertiesForStorage()

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

Definition at line 493 of file class.ilBadge.php.

493 : array
494 {
495 return [
496 "active" => ["integer", $this->isActive()],
497 "title" => ["text", $this->getTitle()],
498 "descr" => ["text", $this->getDescription()],
499 "crit" => ["text", $this->getCriteria()],
500 "image" => ["text", $this->getImage()],
501 "valid" => ["text", $this->getValid()],
502 "conf" => [
503 "text", $this->getConfiguration() ? serialize($this->getConfiguration()) : null
504 ]
505 ];
506 }
getConfiguration()

◆ getTitle()

ilBadge::getTitle ( )

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

265 : string
266 {
267 return $this->title;
268 }
string $title

◆ getTypeId()

ilBadge::getTypeId ( )

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

245 : string
246 {
247 return $this->type_id;
248 }
string $type_id

◆ getTypeInstance()

ilBadge::getTypeInstance ( )

Definition at line 133 of file class.ilBadge.php.

133 : ?ilBadgeType
134 {
135 if ($this->getTypeId()) {
136 $handler = ilBadgeHandler::getInstance();
137 return $handler->getTypeInstanceByUniqueId($this->getTypeId());
138 }
139 return null;
140 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

References ilBadgeHandler\getInstance().

+ Here is the call graph for this function:

◆ getValid()

ilBadge::getValid ( )

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

295 : string
296 {
297 return $this->valid;
298 }
string $valid

References $valid.

◆ importDBRow()

ilBadge::importDBRow ( array  $a_row)
protected

Definition at line 414 of file class.ilBadge.php.

416 : void {
417 $this->setId($a_row["id"]);
418 $this->setParentId($a_row["parent_id"]);
419 $this->setTypeId($a_row["type_id"]);
420 $this->setActive($a_row["active"]);
421 $this->setTitle($a_row["title"]);
422 $this->setDescription($a_row["descr"]);
423 $this->setCriteria($a_row["crit"]);
424 $this->setImage($a_row["image"]);
425 $this->setValid($a_row["valid"]);
426 $this->setConfiguration($a_row["conf"]
427 ? unserialize($a_row["conf"], ["allowed_classes" => false])
428 : null);
429 }
setCriteria(string $a_value)
setConfiguration(array $a_value=null)
setValid(string $a_value)
setImage(string $a_value)
setDescription(string $a_value)
setTypeId(string $a_id)

◆ importImage()

ilBadge::importImage ( string  $a_name,
string  $a_file 
)
Exceptions
BadgeException

Definition at line 348 of file class.ilBadge.php.

351 : void {
352 if (file_exists($a_file)) {
353 $this->setImage($a_name);
354 copy($a_file, $this->getImagePath()); // #18280
355
356 $this->update();
357 } else {
358 throw BadgeException::uploadedBadgeImageFileNotFound($this);
359 }
360 }

◆ isActive()

ilBadge::isActive ( )

Definition at line 255 of file class.ilBadge.php.

255 : bool
256 {
257 return $this->active;
258 }
bool $active

◆ prepareJson()

ilBadge::prepareJson ( string  $a_base_url,
string  $a_img_suffix 
)
protected

Definition at line 546 of file class.ilBadge.php.

549 : stdClass {
550 $json = new stdClass();
551 $json->{"@context"} = "https://w3id.org/openbadges/v1";
552 $json->type = "BadgeClass";
553 $json->id = $a_base_url . "class.json";
554 $json->name = $this->getTitle();
555 $json->description = $this->getDescription();
556 $json->image = $a_base_url . "image." . $a_img_suffix;
557 $json->criteria = $a_base_url . "criteria.txt";
558 $json->issuer = ilBadgeHandler::getInstance()->getIssuerStaticUrl();
559
560 return $json;
561 }

◆ read()

ilBadge::read ( int  $a_id)
protected

Definition at line 402 of file class.ilBadge.php.

402 : void
403 {
405
406 $set = $ilDB->query("SELECT * FROM badge_badge" .
407 " WHERE id = " . $ilDB->quote($a_id, "integer"));
408 if ($ilDB->numRows($set)) {
409 $row = $ilDB->fetchAssoc($set);
410 $this->importDBRow($row);
411 }
412 }
importDBRow(array $a_row)

References $ilDB.

Referenced by __construct().

+ Here is the caller graph for this function:

◆ setActive()

ilBadge::setActive ( bool  $a_value)

Definition at line 250 of file class.ilBadge.php.

250 : void
251 {
252 $this->active = $a_value;
253 }

◆ setConfiguration()

ilBadge::setConfiguration ( array  $a_value = null)

Definition at line 300 of file class.ilBadge.php.

300 : void
301 {
302 if (is_array($a_value) && !count($a_value)) {
303 $a_value = null;
304 }
305 $this->config = $a_value;
306 }

◆ setCriteria()

ilBadge::setCriteria ( string  $a_value)

Definition at line 280 of file class.ilBadge.php.

280 : void
281 {
282 $this->criteria = trim($a_value);
283 }

◆ setDescription()

ilBadge::setDescription ( string  $a_value)

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

270 : void
271 {
272 $this->desc = trim($a_value);
273 }

◆ setId()

ilBadge::setId ( int  $a_id)
protected

Definition at line 220 of file class.ilBadge.php.

220 : void
221 {
222 $this->id = $a_id;
223 }

◆ setImage()

ilBadge::setImage ( string  $a_value)
protected

Definition at line 313 of file class.ilBadge.php.

313 : void
314 {
315 $this->image = trim($a_value);
316 }

◆ setParentId()

ilBadge::setParentId ( int  $a_id)

Definition at line 230 of file class.ilBadge.php.

230 : void
231 {
232 $this->parent_id = $a_id;
233 }

◆ setTitle()

ilBadge::setTitle ( string  $a_value)

Definition at line 260 of file class.ilBadge.php.

260 : void
261 {
262 $this->title = trim($a_value);
263 }

◆ setTypeId()

ilBadge::setTypeId ( string  $a_id)

Definition at line 240 of file class.ilBadge.php.

240 : void
241 {
242 $this->type_id = trim($a_id);
243 }

◆ setValid()

ilBadge::setValid ( string  $a_value)

Definition at line 290 of file class.ilBadge.php.

290 : void
291 {
292 $this->valid = trim($a_value);
293 }

◆ update()

ilBadge::update ( )

Definition at line 452 of file class.ilBadge.php.

452 : void
453 {
455
456 if (!$this->getId()) {
457 $this->create();
458 return;
459 }
460
461 $fields = $this->getPropertiesForStorage();
462
463 $ilDB->update(
464 "badge_badge",
465 $fields,
466 ["id" => ["integer", $this->getId()]]
467 );
468 }

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

+ Here is the call graph for this function:

◆ uploadImage()

ilBadge::uploadImage ( array  $a_upload_meta)
Exceptions
BadgeException

Definition at line 326 of file class.ilBadge.php.

328 : void {
329 if ($this->getId() &&
330 $a_upload_meta["tmp_name"]) {
331 $this->setImage($a_upload_meta["name"]);
332 $path = $this->getImagePath();
333
334 try {
335 if (ilFileUtils::moveUploadedFile($a_upload_meta['tmp_name'], $this->getImagePath(false), $path)) {
336 $this->update();
337 }
338 } catch (ilException $e) {
339 throw BadgeException::moveUploadedBadgeImageFailed($this, $e);
340 }
341
342 }
343 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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 Vendor\Package\$e, $path, and ilFileUtils\moveUploadedFile().

+ Here is the call graph for this function:

Field Documentation

◆ $active

bool ilBadge::$active = false
protected

Definition at line 32 of file class.ilBadge.php.

◆ $config

array ilBadge::$config = null
protected

Definition at line 37 of file class.ilBadge.php.

◆ $criteria

string ilBadge::$criteria = ""
protected

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

◆ $db

ilDBInterface ilBadge::$db
protected

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

◆ $desc

string ilBadge::$desc = ""
protected

Definition at line 34 of file class.ilBadge.php.

◆ $id

int ilBadge::$id = 0
protected

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

◆ $image

string ilBadge::$image = ""
protected

Definition at line 35 of file class.ilBadge.php.

◆ $lng

ilLanguage ilBadge::$lng
protected

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

◆ $parent_id

int ilBadge::$parent_id = 0
protected

Definition at line 30 of file class.ilBadge.php.

◆ $title

string ilBadge::$title = ""
protected

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

◆ $type_id

string ilBadge::$type_id = ""
protected

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

◆ $valid

string ilBadge::$valid = ""
protected

Definition at line 36 of file class.ilBadge.php.


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