27 protected int $id = 0;
49 $this->resource_storage =
$container->resourceStorage();
50 $this->log =
$container->logger()->forComponent(
'badge');
61 ?array $a_filter =
null
69 $sql =
'SELECT * FROM badge_badge' .
70 ' WHERE parent_id = ' .
$ilDB->quote($a_parent_id);
73 if ($a_filter[
'title'] ??
false) {
74 $sql .=
' AND ' .
$ilDB->like(
'title',
'text',
'%' . trim($a_filter[
'title']) .
'%');
76 if ($a_filter[
'type'] ??
false) {
77 $sql .=
' AND type_id = ' .
$ilDB->quote($a_filter[
'type'],
'integer');
81 $set =
$ilDB->query($sql .
83 while ($row =
$ilDB->fetchAssoc($set)) {
85 $obj->importDBRow($row);
104 $set =
$ilDB->query(
'SELECT * FROM badge_badge' .
105 ' WHERE type_id = ' .
$ilDB->quote($a_type_id,
'text') .
107 while ($row =
$ilDB->fetchAssoc($set)) {
109 $obj->importDBRow($row);
116 public function clone(
int $target_parent_obj_id): void
118 $this->setParentId($target_parent_obj_id);
119 $this->setActive(
false);
121 if (!$this->
getId()) {
125 $image_rid = $this->getImageRid();
127 if ($image_rid !==
null) {
129 $this->setImageRid($cloned_rid);
136 if ($this->getTypeId()) {
139 return $handler->getTypeInstanceByUniqueId($this->getTypeId());
146 int $a_new_parent_id,
149 $this->setTitle($this->
getTitle() .
' ' . $copy_suffix);
150 $this->setParentId($a_new_parent_id);
151 $this->setActive(
false);
153 if ($this->
getId()) {
155 $old_rid = $this->getImageRid();
157 if ($old_rid !==
null) {
159 $this->setImageRid($new_rid);
184 ?array $filter =
null
194 if ($filter[
'type']) {
197 if ($filter[
'title']) {
200 if ($filter[
'object']) {
204 $set =
$ilDB->query(
'SELECT bb.*, od.title parent_title, od.type parent_type' .
205 ' FROM badge_badge bb' .
206 ' INNER JOIN object_data od ON bb.parent_id = od.obj_id' .
209 while ($row =
$ilDB->fetchAssoc($set)) {
210 $row[
'deleted'] =
false;
214 $set =
$ilDB->query(
'SELECT bb.*, od.title parent_title, od.type parent_type' .
215 ' FROM badge_badge bb' .
216 ' INNER JOIN object_data_del od ON bb.parent_id = od.obj_id' .
219 while ($row =
$ilDB->fetchAssoc($set)) {
220 $row[
'deleted'] =
true;
231 public function setId(
int $a_id): void
243 $this->parent_id = $a_id;
248 return $this->parent_id;
253 $this->type_id = trim($a_id);
258 return $this->type_id;
263 $this->active = $a_value;
268 return $this->active;
273 $this->title = trim($a_value);
283 $this->desc = trim($a_value);
293 $this->criteria = trim($a_value);
298 return $this->criteria;
303 $this->valid = trim($a_value);
313 if (is_array($a_value) && !count($a_value)) {
316 $this->config = $a_value;
321 return $this->config;
328 protected function read(
int $a_id): void
332 $set =
$ilDB->query(
'SELECT * FROM badge_badge' .
333 ' WHERE id = ' .
$ilDB->quote($a_id,
'integer'));
334 if (
$ilDB->numRows($set)) {
335 $row =
$ilDB->fetchAssoc($set);
336 $this->importDBRow($row);
343 $this->setId($a_row[
'id']);
344 $this->setParentId($a_row[
'parent_id']);
345 $this->setTypeId($a_row[
'type_id']);
346 $this->setActive($a_row[
'active']);
347 $this->setTitle($a_row[
'title']);
348 $this->setDescription($a_row[
'descr']);
349 $this->setCriteria($a_row[
'crit']);
350 $this->setImageRid($a_row[
'image_rid']);
351 $this->setValid($a_row[
'valid']);
352 $this->setConfiguration($a_row[
'conf']
353 ? unserialize($a_row[
'conf'], [
'allowed_classes' =>
false])
361 if ($this->
getId()) {
370 $fields = $this->getPropertiesForStorage();
372 $fields[
'id'] = [
'integer',
$id];
373 $fields[
'parent_id'] = [
'integer', $this->getParentId()];
374 $fields[
'type_id'] = [
'text', $this->getTypeId()];
376 $ilDB->insert(
'badge_badge', $fields);
383 if (!$this->
getId()) {
389 $fields = $this->getPropertiesForStorage();
394 [
'id' => [
'integer', $this->
getId()]]
398 public function delete():
void
402 if (!$this->
getId()) {
406 if ($this->getImageRid()) {
409 }
catch (Exception
$e) {
410 $this->log->warning(sprintf(
'There was an exception, while deleting the badge with id %s. Exception: %s', $this->
getId(), $e->getMessage()));
414 $this->deleteStaticFiles();
418 $ilDB->manipulate(
'DELETE FROM badge_badge' .
419 ' WHERE id = ' .
$ilDB->quote($this->getId(),
'integer'));
428 'active' => [
'integer', $this->isActive()],
429 'title' => [
'text', $this->
getTitle()],
430 'descr' => [
'text', $this->getDescription()],
431 'crit' => [
'text', $this->getCriteria()],
432 'image_rid' => [
'text', $this->getImageRid()],
433 'valid' => [
'text', $this->getValid()],
435 'text', $this->getConfiguration() ? serialize($this->getConfiguration()) : null
457 if ($parent[
'type']) {
458 $parent_type = $parent[
'type'];
459 $parent_title = $parent[
'title'];
465 'id' => $this->getParentId(),
466 'type' => $parent_type,
467 'title' => $parent_title,
468 'deleted' => $deleted
480 $json = new stdClass();
481 $json->{
'@context'} =
'https://w3id.org/openbadges/v1';
482 $json->type =
'BadgeClass';
483 $json->id = $a_base_url .
'class.json';
485 $json->description = $this->getDescription();
486 $json->image = $a_base_url .
'image.' . $a_img_suffix;
487 $json->criteria = $a_base_url .
'criteria.txt';
511 ?
$lng->txt(
'badge_subtype_auto')
512 :
$lng->txt(
'badge_subtype_manual')) .
')';
518 if ($this->image_rid ===
null || $this->image_rid ===
'' || $this->image_rid ===
'-') {
522 return $this->image_rid;
527 $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)
static getInstancesByType(string $a_type_id)
copy(int $a_new_parent_id, string $copy_suffix)
prepareJson(string $a_base_url, string $a_img_suffix)
setTitle(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
static delDir(string $a_dir, bool $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
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...
foreach($_POST as $key=> $value) $res