29 protected int $id = 0;
45 $this->
lng = $DIC->language();
46 $this->db =
$DIC->database();
59 array $a_filter =
null
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);
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
117 $this->setParentId($target_parent_obj_id);
118 $this->setActive(
false);
120 if ($this->
getId()) {
121 $img = $this->getImagePath();
128 copy(
$img, $this->getImagePath());
135 if ($this->getTypeId()) {
137 return $handler->getTypeInstanceByUniqueId($this->getTypeId());
147 $this->setTitle($this->getTitle() .
" " .
$lng->txt(
"copy_of_suffix"));
148 $this->setParentId($a_new_parent_id);
149 $this->setActive(
false);
151 if ($this->
getId()) {
152 $img = $this->getImagePath();
159 copy(
$img, $this->getImagePath());
169 array $a_filter =
null
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;
237 return $this->parent_id;
242 $this->type_id = trim($a_id);
247 return $this->type_id;
252 $this->active = $a_value;
257 return $this->active;
262 $this->title = trim($a_value);
272 $this->desc = trim($a_value);
282 $this->criteria = trim($a_value);
287 return $this->criteria;
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);
330 $a_upload_meta[
"tmp_name"]) {
331 $this->setImage($a_upload_meta[
"name"]);
332 $path = $this->getImagePath();
339 throw BadgeException::moveUploadedBadgeImageFailed($this,
$e);
352 if (file_exists($a_file)) {
353 $this->setImage($a_name);
354 copy($a_file, $this->getImagePath());
358 throw BadgeException::uploadedBadgeImageFileNotFound($this);
363 bool $a_full_path =
true
366 $exp = explode(
".", $this->getImage());
367 $suffix = strtolower(array_pop($exp));
369 return $this->getFilePath($this->
getId()) .
"img" . $this->
getId() .
"." . $suffix;
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);
410 $this->importDBRow($row);
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])
435 if ($this->
getId()) {
443 $fields = $this->getPropertiesForStorage();
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()) {
461 $fields = $this->getPropertiesForStorage();
466 [
"id" => [
"integer", $this->
getId()]]
470 public function delete():
void
474 if (!$this->
getId()) {
478 if (file_exists($this->getImagePath())) {
479 unlink($this->getImagePath());
482 $this->deleteStaticFiles();
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()],
498 "descr" => [
"text", $this->getDescription()],
499 "crit" => [
"text", $this->getCriteria()],
500 "image" => [
"text", $this->getImage()],
501 "valid" => [
"text", $this->getValid()],
503 "text", $this->getConfiguration() ? serialize($this->getConfiguration()) : null
526 if ($parent[
"type"]) {
527 $parent_type = $parent[
"type"];
528 $parent_title = $parent[
"title"];
534 "id" => $this->getParentId(),
535 "type" => $parent_type,
536 "title" => $parent_title,
537 "deleted" => $deleted
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";
582 ?
$lng->txt(
"badge_subtype_auto")
583 :
$lng->txt(
"badge_subtype_manual")) .
")";
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
static deleteByBadgeId(int $a_badge_id)
setCriteria(string $a_value)
setConfiguration(array $a_value=null)
clone(int $target_parent_obj_id)
uploadImage(array $a_upload_meta)
__construct(int $a_id=null)
static getInstancesByType(string $a_type_id)
getImagePath(bool $a_full_path=true)
static getInstancesByParentId(int $a_parent_id, array $a_filter=null)
prepareJson(string $a_base_url, string $a_img_suffix)
setTitle(string $a_value)
static getExtendedTypeCaption(ilBadgeType $a_type)
setValid(string $a_value)
setImage(string $a_value)
copy(int $a_new_parent_id)
getFilePath(int $a_id, string $a_subdir=null)
setDescription(string $a_value)
getPropertiesForStorage()
importDBRow(array $a_row)
static getObjectInstances(array $a_filter=null)
importImage(string $a_name, string $a_file)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static delDir(string $a_dir, bool $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
static moveUploadedFile(string $a_file, string $a_name, string $a_target, bool $a_raise_errors=true, string $a_mode="move_uploaded")
move uploaded file
static get(int $a_object_id)
static _lookupType(int $id, bool $reference=false)
static _lookupTitle(int $obj_id)
if(!file_exists(getcwd() . '/ilias.ini.php'))
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...