28 protected int $id = 0;
53 $this->resource_storage =
$container->resourceStorage();
66 ?array $a_filter =
null
74 $sql =
"SELECT * FROM badge_badge" .
75 " WHERE parent_id = " .
$ilDB->quote($a_parent_id);
78 if ($a_filter[
"title"] ??
false) {
79 $sql .=
" AND " .
$ilDB->like(
"title",
"text",
"%" . trim($a_filter[
"title"]) .
"%");
81 if ($a_filter[
"type"] ??
false) {
82 $sql .=
" AND type_id = " .
$ilDB->quote($a_filter[
"type"],
"integer");
86 $set =
$ilDB->query($sql .
88 while ($row =
$ilDB->fetchAssoc($set)) {
90 $obj->importDBRow($row);
109 $set =
$ilDB->query(
"SELECT * FROM badge_badge" .
110 " WHERE type_id = " .
$ilDB->quote($a_type_id,
"text") .
112 while ($row =
$ilDB->fetchAssoc($set)) {
114 $obj->importDBRow($row);
121 public function clone(
int $target_parent_obj_id): void
123 $this->setParentId($target_parent_obj_id);
124 $this->setActive(
false);
126 if ($this->
getId()) {
127 if ($this->getImageRid()) {
129 $new_collection_id = $this->resource_storage->manage()->clone($current_collection_id);
131 $this->setImageRid($new_collection_id);
134 $this->log->warning(
'Please run the "Migration of files of badges to the resource storage service" job, before working with badges.');
141 if ($this->getTypeId()) {
143 return $handler->getTypeInstanceByUniqueId($this->getTypeId());
149 int $a_new_parent_id,
152 $this->setTitle($this->
getTitle() .
" " . $copy_suffix);
153 $this->setParentId($a_new_parent_id);
154 $this->setActive(
false);
156 if ($this->
getId()) {
158 $old_rid = $this->getImageRid();
160 if ($old_rid !==
null) {
162 $this->setImageRid($new_rid);
188 ?array $filter =
null
198 if ($filter[
'type']) {
201 if ($filter[
'title']) {
204 if ($filter[
'object']) {
208 $set =
$ilDB->query(
'SELECT bb.*, od.title parent_title, od.type parent_type' .
209 ' FROM badge_badge bb' .
210 ' INNER JOIN object_data od ON bb.parent_id = od.obj_id' .
213 while ($row =
$ilDB->fetchAssoc($set)) {
214 $row[
'deleted'] =
false;
218 $set =
$ilDB->query(
'SELECT bb.*, od.title parent_title, od.type parent_type' .
219 ' FROM badge_badge bb' .
220 ' INNER JOIN object_data_del od ON bb.parent_id = od.obj_id' .
223 while ($row =
$ilDB->fetchAssoc($set)) {
224 $row[
'deleted'] =
true;
235 public function setId(
int $a_id): void
247 $this->parent_id = $a_id;
252 return $this->parent_id;
257 $this->type_id = trim($a_id);
262 return $this->type_id;
267 $this->active = $a_value;
272 return $this->active;
277 $this->title = trim($a_value);
287 $this->desc = trim($a_value);
297 $this->criteria = trim($a_value);
302 return $this->criteria;
307 $this->valid = trim($a_value);
317 if (is_array($a_value) && !count($a_value)) {
320 $this->config = $a_value;
325 return $this->config;
330 if ($a_value !==
null) {
331 $this->image = trim($a_value);
347 $a_upload_meta[
"tmp_name"]) {
348 $this->setImage($a_upload_meta[
"name"]);
349 $path = $this->getImagePath();
356 throw BadgeException::moveUploadedBadgeImageFailed($this,
$e);
369 if (file_exists($a_file)) {
370 $this->setImage($a_name);
371 copy($a_file, $this->getImagePath());
375 throw BadgeException::uploadedBadgeImageFileNotFound($this);
380 bool $a_full_path =
true
383 $exp = explode(
".", $this->getImage());
384 $suffix = strtolower(array_pop($exp));
386 return $this->getFilePath($this->
getId()) .
"img" . $this->
getId() .
"." . $suffix;
389 return "img" . $this->
getId() .
"." . $suffix;
397 ?
string $a_subdir =
null
402 $path = $storage->getAbsolutePath() .
"/";
405 $path .= $a_subdir .
"/";
407 if (!is_dir(
$path)) {
420 protected function read(
int $a_id): void
424 $set =
$ilDB->query(
"SELECT * FROM badge_badge" .
425 " WHERE id = " .
$ilDB->quote($a_id,
"integer"));
426 if (
$ilDB->numRows($set)) {
427 $row =
$ilDB->fetchAssoc($set);
428 $this->importDBRow($row);
435 $this->setId($a_row[
"id"]);
436 $this->setParentId($a_row[
"parent_id"]);
437 $this->setTypeId($a_row[
"type_id"]);
438 $this->setActive($a_row[
"active"]);
439 $this->setTitle($a_row[
"title"]);
440 $this->setDescription($a_row[
"descr"]);
441 $this->setCriteria($a_row[
"crit"]);
442 $this->setImage($a_row[
"image"]);
443 $this->setImageRid($a_row[
"image_rid"]);
444 $this->setValid($a_row[
"valid"]);
445 $this->setConfiguration($a_row[
"conf"]
446 ? unserialize($a_row[
"conf"], [
"allowed_classes" =>
false])
454 if ($this->
getId()) {
462 $fields = $this->getPropertiesForStorage();
464 $fields[
"id"] = [
"integer",
$id];
465 $fields[
"parent_id"] = [
"integer", $this->getParentId()];
466 $fields[
"type_id"] = [
"text", $this->getTypeId()];
468 $ilDB->insert(
"badge_badge", $fields);
475 if (!$this->
getId()) {
480 $fields = $this->getPropertiesForStorage();
485 [
"id" => [
"integer", $this->
getId()]]
489 public function delete():
void
493 if (!$this->
getId()) {
497 if ($this->getImageRid()) {
500 }
catch (Exception
$e) {
501 $this->log->warning(sprintf(
'There was an exception, while deleting the badge with id %s. Exception: %s', $this->
getId(), $e->getMessage()));
505 $this->deleteStaticFiles();
509 $ilDB->manipulate(
"DELETE FROM badge_badge" .
510 " WHERE id = " .
$ilDB->quote($this->getId(),
"integer"));
519 "active" => [
"integer", $this->isActive()],
520 "title" => [
"text", $this->
getTitle()],
521 "descr" => [
"text", $this->getDescription()],
522 "crit" => [
"text", $this->getCriteria()],
523 "image" => [
"text", $this->getImage()],
524 "image_rid" => [
"text", $this->getImageRid()],
525 "valid" => [
"text", $this->getValid()],
527 "text", $this->getConfiguration() ? serialize($this->getConfiguration()) : null
550 if ($parent[
"type"]) {
551 $parent_type = $parent[
"type"];
552 $parent_title = $parent[
"title"];
558 "id" => $this->getParentId(),
559 "type" => $parent_type,
560 "title" => $parent_title,
561 "deleted" => $deleted
574 $json = new stdClass();
575 $json->{
"@context"} =
"https://w3id.org/openbadges/v1";
576 $json->type =
"BadgeClass";
577 $json->id = $a_base_url .
"class.json";
579 $json->description = $this->getDescription();
580 $json->image = $a_base_url .
"image." . $a_img_suffix;
581 $json->criteria = $a_base_url .
"criteria.txt";
606 ?
$lng->txt(
"badge_subtype_auto")
607 :
$lng->txt(
"badge_subtype_manual")) .
")";
612 return $this->image_rid;
617 $this->image_rid = $image_rid;
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Customizing of pimple-DIC for ILIAS.
Class ResourceIdentification.
static deleteByBadgeId(int $a_badge_id)
setCriteria(string $a_value)
clone(int $target_parent_obj_id)
uploadImage(array $a_upload_meta)
getFilePath(int $a_id, ?string $a_subdir=null)
static getInstancesByType(string $a_type_id)
getImagePath(bool $a_full_path=true)
copy(int $a_new_parent_id, string $copy_suffix)
prepareJson(string $a_base_url, string $a_img_suffix)
setTitle(string $a_value)
setImage(?string $a_value)
static getExtendedTypeCaption(ilBadgeType $a_type)
setValid(string $a_value)
static getObjectInstances(?array $filter=null)
setConfiguration(?array $a_value=null)
static getInstancesByParentId(int $a_parent_id, ?array $a_filter=null)
setImageRid(?string $image_rid)
setDescription(string $a_value)
getPropertiesForStorage()
importDBRow(array $a_row)
__construct(?int $a_id=null, ?Container $container=null)
Services $resource_storage
importImage(string $a_name, string $a_file)
Base class for ILIAS Exception handling.
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
Component logger with individual log levels by component id.
static get(int $a_object_id)
static _lookupType(int $id, bool $reference=false)
static _lookupTitle(int $obj_id)
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...
if(!file_exists('../ilias.ini.php'))