29 protected int $id = 0;
45 $this->
lng = $DIC->language();
46 $this->db = $DIC->database();
58 array $a_filter = null
62 $ilDB = $DIC->database();
66 $sql =
"SELECT * FROM badge_badge" .
67 " WHERE parent_id = " .
$ilDB->quote($a_parent_id);
70 if ($a_filter[
"title"] ??
false) {
71 $sql .=
" AND " .
$ilDB->like(
"title",
"text",
"%" . trim($a_filter[
"title"]) .
"%");
73 if ($a_filter[
"type"] ??
false) {
74 $sql .=
" AND type_id = " .
$ilDB->quote($a_filter[
"type"],
"integer");
78 $set =
$ilDB->query($sql .
80 while ($row =
$ilDB->fetchAssoc($set)) {
82 $obj->importDBRow($row);
97 $ilDB = $DIC->database();
101 $set =
$ilDB->query(
"SELECT * FROM badge_badge" .
102 " WHERE type_id = " .
$ilDB->quote($a_type_id,
"text") .
104 while ($row =
$ilDB->fetchAssoc($set)) {
106 $obj->importDBRow($row);
113 public function clone(
int $target_parent_obj_id): void
118 if ($this->
getId()) {
149 if ($this->
getId()) {
167 array $a_filter = null
171 $ilDB = $DIC->database();
177 if ($a_filter[
"type"]) {
178 $where .=
" AND bb.type_id = " .
$ilDB->quote($a_filter[
"type"],
"text");
180 if ($a_filter[
"title"]) {
181 $where .=
" AND " .
$ilDB->like(
"bb.title",
"text",
"%" . $a_filter[
"title"] .
"%");
183 if ($a_filter[
"object"]) {
184 $where .=
" AND " .
$ilDB->like(
"od.title",
"text",
"%" . $a_filter[
"object"] .
"%");
187 $set =
$ilDB->query(
"SELECT bb.*, od.title parent_title, od.type parent_type" .
188 " FROM badge_badge bb" .
189 " JOIN object_data od ON (bb.parent_id = od.obj_id)" .
190 " WHERE od.type <> " .
$ilDB->quote(
"bdga",
"text") .
192 while ($row =
$ilDB->fetchAssoc($set)) {
196 $set =
$ilDB->query(
"SELECT bb.*, od.title parent_title, od.type parent_type" .
197 " FROM badge_badge bb" .
198 " JOIN object_data_del od ON (bb.parent_id = od.obj_id)" .
199 " WHERE od.type <> " .
$ilDB->quote(
"bdga",
"text") .
201 while ($row =
$ilDB->fetchAssoc($set)) {
202 $row[
"deleted"] =
true;
206 foreach ($raw as $row) {
218 protected function setId(
int $a_id): void
230 $this->parent_id = $a_id;
240 $this->type_id = trim($a_id);
250 $this->active = $a_value;
260 $this->title = trim($a_value);
270 $this->desc = trim($a_value);
280 $this->criteria = trim($a_value);
290 $this->valid = trim($a_value);
300 if (is_array($a_value) && !count($a_value)) {
303 $this->config = $a_value;
313 $this->image = trim($a_value);
327 if ($this->
getId() &&
328 $a_upload_meta[
"tmp_name"]) {
329 $this->
setImage($a_upload_meta[
"name"]);
337 throw BadgeException::moveUploadedBadgeImageFailed($this, $e);
350 if (file_exists($a_file)) {
356 throw BadgeException::uploadedBadgeImageFileNotFound($this);
361 bool $a_full_path =
true 363 if ($this->
getId()) {
364 $exp = explode(
".", $this->
getImage());
365 $suffix = strtolower(array_pop($exp));
370 return "img" . $this->
getId() .
"." . $suffix;
377 string $a_subdir = null
382 $path = $storage->getAbsolutePath() .
"/";
385 $path .= $a_subdir .
"/";
387 if (!is_dir(
$path)) {
400 protected function read(
int $a_id): void
404 $set =
$ilDB->query(
"SELECT * FROM badge_badge" .
405 " WHERE id = " .
$ilDB->quote($a_id,
"integer"));
406 if (
$ilDB->numRows($set)) {
407 $row =
$ilDB->fetchAssoc($set);
415 $this->
setId($a_row[
"id"]);
425 ? unserialize($a_row[
"conf"], [
"allowed_classes" =>
false])
433 if ($this->
getId()) {
438 $id =
$ilDB->nextId(
"badge_badge");
443 $fields[
"id"] = [
"integer",
$id];
444 $fields[
"parent_id"] = [
"integer", $this->
getParentId()];
445 $fields[
"type_id"] = [
"text", $this->
getTypeId()];
447 $ilDB->insert(
"badge_badge", $fields);
454 if (!$this->
getId()) {
464 [
"id" => [
"integer", $this->
getId()]]
468 public function delete():
void 472 if (!$this->
getId()) {
484 $ilDB->manipulate(
"DELETE FROM badge_badge" .
485 " WHERE id = " .
$ilDB->quote($this->getId(),
"integer"));
494 "active" => [
"integer", $this->
isActive()],
495 "title" => [
"text", $this->
getTitle()],
498 "image" => [
"text", $this->
getImage()],
499 "valid" => [
"text", $this->
getValid()],
524 if ($parent[
"type"]) {
525 $parent_type = $parent[
"type"];
526 $parent_title = $parent[
"title"];
533 "type" => $parent_type,
534 "title" => $parent_title,
535 "deleted" => $deleted
549 $json->{
"@context"} =
"https://w3id.org/openbadges/v1";
550 $json->type =
"BadgeClass";
551 $json->id = $a_base_url .
"class.json";
554 $json->image = $a_base_url .
"image." . $a_img_suffix;
555 $json->criteria = $a_base_url .
"criteria.txt";
576 $lng = $DIC->language();
580 ?
$lng->
txt(
"badge_subtype_auto")
581 :
$lng->
txt(
"badge_subtype_manual")) .
")";
getPropertiesForStorage()
uploadImage(array $a_upload_meta)
static getInstancesByType(string $a_type_id)
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...
prepareJson(string $a_base_url, string $a_img_suffix)
importImage(string $a_name, string $a_file)
static getObjectInstances(array $a_filter=null)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setValid(string $a_value)
setTitle(string $a_value)
clone(int $target_parent_obj_id)
setImage(string $a_value)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setDescription(string $a_value)
static _lookupTitle(int $obj_id)
static getExtendedTypeCaption(ilBadgeType $a_type)
static delDir(string $a_dir, bool $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
getFilePath(int $a_id, string $a_subdir=null)
static getInstancesByParentId(int $a_parent_id, array $a_filter=null)
getImagePath(bool $a_full_path=true)
static moveUploadedFile(string $a_file, string $a_name, string $a_target, bool $a_raise_errors=true, string $a_mode="move_uploaded")
move uploaded file
setCriteria(string $a_value)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setConfiguration(array $a_value=null)
static deleteByBadgeId(int $a_badge_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(int $a_id=null)
static get(int $a_object_id)
static _lookupType(int $id, bool $reference=false)
importDBRow(array $a_row)
copy(int $a_new_parent_id)