29 protected int $id = 0;
45 $this->
lng = $DIC->language();
46 $this->db = $DIC->database();
59 array $a_filter = null
63 $ilDB = $DIC->database();
67 $sql =
"SELECT * FROM badge_badge" .
68 " WHERE parent_id = " .
$ilDB->quote($a_parent_id);
71 if ($a_filter[
"title"] ??
false) {
72 $sql .=
" AND " .
$ilDB->like(
"title",
"text",
"%" . trim($a_filter[
"title"]) .
"%");
74 if ($a_filter[
"type"] ??
false) {
75 $sql .=
" AND type_id = " .
$ilDB->quote($a_filter[
"type"],
"integer");
79 $set =
$ilDB->query($sql .
81 while ($row =
$ilDB->fetchAssoc($set)) {
83 $obj->importDBRow($row);
99 $ilDB = $DIC->database();
103 $set =
$ilDB->query(
"SELECT * FROM badge_badge" .
104 " WHERE type_id = " .
$ilDB->quote($a_type_id,
"text") .
106 while ($row =
$ilDB->fetchAssoc($set)) {
108 $obj->importDBRow($row);
115 public function clone(
int $target_parent_obj_id): void
120 if ($this->
getId()) {
137 return $handler->getTypeInstanceByUniqueId($this->
getTypeId());
151 if ($this->
getId()) {
169 array $a_filter = null
173 $ilDB = $DIC->database();
179 if ($a_filter[
"type"]) {
180 $where .=
" AND bb.type_id = " .
$ilDB->quote($a_filter[
"type"],
"text");
182 if ($a_filter[
"title"]) {
183 $where .=
" AND " .
$ilDB->like(
"bb.title",
"text",
"%" . $a_filter[
"title"] .
"%");
185 if ($a_filter[
"object"]) {
186 $where .=
" AND " .
$ilDB->like(
"od.title",
"text",
"%" . $a_filter[
"object"] .
"%");
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") .
194 while ($row =
$ilDB->fetchAssoc($set)) {
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") .
203 while ($row =
$ilDB->fetchAssoc($set)) {
204 $row[
"deleted"] =
true;
208 foreach ($raw as $row) {
220 protected function setId(
int $a_id): void
232 $this->parent_id = $a_id;
242 $this->type_id = trim($a_id);
252 $this->active = $a_value;
262 $this->title = trim($a_value);
272 $this->desc = trim($a_value);
282 $this->criteria = trim($a_value);
292 $this->valid = trim($a_value);
302 if (is_array($a_value) && !count($a_value)) {
305 $this->config = $a_value;
315 $this->image = trim($a_value);
329 if ($this->
getId() &&
330 $a_upload_meta[
"tmp_name"]) {
331 $this->
setImage($a_upload_meta[
"name"]);
339 throw BadgeException::moveUploadedBadgeImageFailed($this, $e);
352 if (file_exists($a_file)) {
358 throw BadgeException::uploadedBadgeImageFileNotFound($this);
363 bool $a_full_path =
true 365 if ($this->
getId()) {
366 $exp = explode(
".", $this->
getImage());
367 $suffix = strtolower(array_pop($exp));
372 return "img" . $this->
getId() .
"." . $suffix;
379 string $a_subdir = null
384 $path = $storage->getAbsolutePath() .
"/";
387 $path .= $a_subdir .
"/";
389 if (!is_dir(
$path)) {
402 protected function read(
int $a_id): void
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);
417 $this->
setId($a_row[
"id"]);
427 ? unserialize($a_row[
"conf"], [
"allowed_classes" =>
false])
435 if ($this->
getId()) {
440 $id =
$ilDB->nextId(
"badge_badge");
445 $fields[
"id"] = [
"integer",
$id];
446 $fields[
"parent_id"] = [
"integer", $this->
getParentId()];
447 $fields[
"type_id"] = [
"text", $this->
getTypeId()];
449 $ilDB->insert(
"badge_badge", $fields);
456 if (!$this->
getId()) {
466 [
"id" => [
"integer", $this->
getId()]]
470 public function delete():
void 474 if (!$this->
getId()) {
486 $ilDB->manipulate(
"DELETE FROM badge_badge" .
487 " WHERE id = " .
$ilDB->quote($this->getId(),
"integer"));
496 "active" => [
"integer", $this->
isActive()],
497 "title" => [
"text", $this->
getTitle()],
500 "image" => [
"text", $this->
getImage()],
501 "valid" => [
"text", $this->
getValid()],
526 if ($parent[
"type"]) {
527 $parent_type = $parent[
"type"];
528 $parent_title = $parent[
"title"];
535 "type" => $parent_type,
536 "title" => $parent_title,
537 "deleted" => $deleted
551 $json->{
"@context"} =
"https://w3id.org/openbadges/v1";
552 $json->type =
"BadgeClass";
553 $json->id = $a_base_url .
"class.json";
556 $json->image = $a_base_url .
"image." . $a_img_suffix;
557 $json->criteria = $a_base_url .
"criteria.txt";
578 $lng = $DIC->language();
582 ?
$lng->
txt(
"badge_subtype_auto")
583 :
$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)