28 protected int $id = 0;
53 $this->resource_storage =
$container->resourceStorage();
66 ?array $a_filter =
null 70 $ilDB = $DIC->database();
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);
105 $ilDB = $DIC->database();
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
126 if ($this->
getId()) {
129 $new_collection_id = $this->resource_storage->manage()->clone($current_collection_id);
134 $this->log->warning(
'Please run the "Migration of files of badges to the resource storage service" job, before working with badges.');
149 int $a_new_parent_id,
156 if ($this->
getId()) {
160 if ($old_rid !==
null) {
188 ?array $filter =
null 192 $ilDB = $DIC->database();
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;
257 $this->type_id = trim($a_id);
267 $this->active = $a_value;
277 $this->title = trim($a_value);
287 $this->desc = trim($a_value);
297 $this->criteria = trim($a_value);
307 $this->valid = trim($a_value);
317 if (is_array($a_value) && !count($a_value)) {
320 $this->config = $a_value;
330 if ($a_value !==
null) {
331 $this->image = trim($a_value);
346 if ($this->
getId() &&
347 $a_upload_meta[
"tmp_name"]) {
348 $this->
setImage($a_upload_meta[
"name"]);
356 throw BadgeException::moveUploadedBadgeImageFailed($this, $e);
369 if (file_exists($a_file)) {
375 throw BadgeException::uploadedBadgeImageFileNotFound($this);
380 bool $a_full_path =
true 382 if ($this->
getId()) {
383 $exp = explode(
".", $this->
getImage());
384 $suffix = strtolower(array_pop($exp));
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);
435 $this->
setId($a_row[
"id"]);
446 ? unserialize($a_row[
"conf"], [
"allowed_classes" =>
false])
454 if ($this->
getId()) {
459 $id =
$ilDB->nextId(
"badge_badge");
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()) {
485 [
"id" => [
"integer", $this->
getId()]]
489 public function delete():
void 493 if (!$this->
getId()) {
501 $this->log->warning(sprintf(
'There was an exception, while deleting the badge with id %s. Exception: %s', $this->
getId(), $e->getMessage()));
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()],
523 "image" => [
"text", $this->
getImage()],
525 "valid" => [
"text", $this->
getValid()],
550 if ($parent[
"type"]) {
551 $parent_type = $parent[
"type"];
552 $parent_title = $parent[
"title"];
559 "type" => $parent_type,
560 "title" => $parent_title,
561 "deleted" => $deleted
575 $json->{
"@context"} =
"https://w3id.org/openbadges/v1";
576 $json->type =
"BadgeClass";
577 $json->id = $a_base_url .
"class.json";
580 $json->image = $a_base_url .
"image." . $a_img_suffix;
581 $json->criteria = $a_base_url .
"criteria.txt";
602 $lng = $DIC->language();
606 ?
$lng->txt(
"badge_subtype_auto")
607 :
$lng->txt(
"badge_subtype_manual")) .
")";
getPropertiesForStorage()
uploadImage(array $a_upload_meta)
static getInstancesByType(string $a_type_id)
getFilePath(int $a_id, ?string $a_subdir=null)
static getInstancesByParentId(int $a_parent_id, ?array $a_filter=null)
__construct(?int $a_id=null, ?Container $container=null)
prepareJson(string $a_base_url, string $a_img_suffix)
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...
setValid(string $a_value)
setTitle(string $a_value)
Customizing of pimple-DIC for ILIAS.
clone(int $target_parent_obj_id)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
setImage(?string $a_value)
setDescription(string $a_value)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _lookupTitle(int $obj_id)
static getExtendedTypeCaption(ilBadgeType $a_type)
Class ResourceIdentification.
setConfiguration(?array $a_value=null)
static delDir(string $a_dir, bool $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
getImagePath(bool $a_full_path=true)
copy(int $a_new_parent_id, string $copy_suffix)
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)
static deleteByBadgeId(int $a_badge_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getObjectInstances(?array $filter=null)
static get(int $a_object_id)
static _lookupType(int $id, bool $reference=false)
importDBRow(array $a_row)
setImageRid(?string $image_rid)
Services $resource_storage