43 $this->lng = $DIC->language();
44 $this->db = $DIC->database();
54 $ilDB = $DIC->database();
58 $sql =
"SELECT * FROM badge_badge" .
59 " WHERE parent_id = " .
$ilDB->quote($a_parent_id);
62 if ($a_filter[
"title"]) {
63 $sql .=
" AND " .
$ilDB->like(
"title",
"text",
"%" . trim($a_filter[
"title"]) .
"%");
65 if ($a_filter[
"type"]) {
66 $sql .=
" AND type_id = " .
$ilDB->quote($a_filter[
"type"],
"integer");
70 $set =
$ilDB->query($sql .
72 while ($row =
$ilDB->fetchAssoc($set)) {
74 $obj->importDBRow($row);
85 $ilDB = $DIC->database();
89 $set =
$ilDB->query(
"SELECT * FROM badge_badge" .
90 " WHERE type_id = " .
$ilDB->quote($a_type_id) .
92 while ($row =
$ilDB->fetchAssoc($set)) {
94 $obj->importDBRow($row);
101 public function clone(
int $target_parent_obj_id) : void
106 if ($this->
getId()) {
123 return $handler->getTypeInstanceByUniqueId($this->
getTypeId());
127 public function copy($a_new_parent_id)
135 if ($this->
getId()) {
152 $ilDB = $DIC->database();
154 $res = $raw = array();
158 if ($a_filter[
"type"]) {
159 $where .=
" AND bb.type_id = " .
$ilDB->quote($a_filter[
"type"],
"text");
161 if ($a_filter[
"title"]) {
162 $where .=
" AND " .
$ilDB->like(
"bb.title",
"text",
"%" . $a_filter[
"title"] .
"%");
164 if ($a_filter[
"object"]) {
165 $where .=
" AND " .
$ilDB->like(
"od.title",
"text",
"%" . $a_filter[
"object"] .
"%");
168 $set =
$ilDB->query(
"SELECT bb.*, od.title parent_title, od.type parent_type" .
169 " FROM badge_badge bb" .
170 " JOIN object_data od ON (bb.parent_id = od.obj_id)" .
171 " WHERE od.type <> " .
$ilDB->quote(
"bdga",
"text") .
173 while ($row =
$ilDB->fetchAssoc($set)) {
177 $set =
$ilDB->query(
"SELECT bb.*, od.title parent_title, od.type parent_type" .
178 " FROM badge_badge bb" .
179 " JOIN object_data_del od ON (bb.parent_id = od.obj_id)" .
180 " WHERE od.type <> " .
$ilDB->quote(
"bdga",
"text") .
182 while ($row =
$ilDB->fetchAssoc($set)) {
183 $row[
"deleted"] =
true;
187 foreach ($raw as $row) {
203 $this->
id = (int) $a_id;
213 $this->parent_id = (int) $a_id;
223 $this->type_id = trim($a_id);
233 $this->active = (bool) $a_value;
243 $this->title = trim($a_value);
253 $this->desc = trim($a_value);
263 $this->criteria = trim($a_value);
273 $this->valid = trim($a_value);
283 if (is_array($a_value) &&
287 $this->config = $a_value;
297 $this->image = trim($a_value);
311 if ($this->
getId() &&
312 $a_upload_meta[
"tmp_name"]) {
313 $this->
setImage($a_upload_meta[
"name"]);
324 if (file_exists($a_file)) {
334 if ($this->
getId()) {
335 $suffix = strtolower(array_pop(explode(
".", $this->
getImage())));
339 return "img" . $this->
getId() .
"." . $suffix;
356 $path = $storage->getAbsolutePath() .
"/";
359 $path .= $a_subdir .
"/";
361 if (!is_dir($path)) {
378 $set =
$ilDB->query(
"SELECT * FROM badge_badge" .
379 " WHERE id = " .
$ilDB->quote($a_id,
"integer"));
380 if (
$ilDB->numRows($set)) {
381 $row =
$ilDB->fetchAssoc($set);
388 $this->
setId($a_row[
"id"]);
398 ? unserialize($a_row[
"conf"])
406 if ($this->
getId()) {
415 $fields[
"id"] = array(
"integer",
$id);
416 $fields[
"parent_id"] = array(
"integer", $this->
getParentId());
417 $fields[
"type_id"] = array(
"text", $this->
getTypeId());
419 $ilDB->insert(
"badge_badge", $fields);
426 if (!$this->
getId()) {
435 array(
"id" => array(
"integer", $this->
getId()))
439 public function delete()
443 if (!$this->
getId()) {
455 $ilDB->manipulate(
"DELETE FROM badge_badge" .
456 " WHERE id = " .
$ilDB->quote($this->getId(),
"integer"));
462 "active" => array(
"integer", $this->
isActive()),
463 "title" => array(
"text", $this->
getTitle()),
466 "image" => array(
"text", $this->
getImage()),
467 "valid" => array(
"text", $this->
getValid()),
488 if ($parent[
"type"]) {
489 $parent_type = $parent[
"type"];
490 $parent_title = $parent[
"title"];
497 "type" => $parent_type,
498 "title" => $parent_title,
499 "deleted" => $deleted
511 $json->{
"@context"} =
"https://w3id.org/openbadges/v1";
512 $json->type =
"BadgeClass";
513 $json->id = $a_base_url .
"class.json";
516 $json->image = $a_base_url .
"image." . $a_img_suffix;
517 $json->criteria = $a_base_url .
"criteria.txt";
527 $base_url = ILIAS_HTTP_PATH . substr($path, 1);
529 if (!file_exists($path .
"class.json")) {
530 $img_suffix = array_pop(explode(
".", $this->
getImage()));
532 $json = json_encode($this->
prepareJson($base_url, $img_suffix));
533 file_put_contents($path .
"class.json", $json);
538 file_put_contents($path .
"criteria.txt", $this->
getCriteria());
541 return $base_url .
"class.json";
557 $lng = $DIC->language();
561 ?
$lng->txt(
"badge_subtype_auto")
562 :
$lng->txt(
"badge_subtype_manual")) .
")";
getPropertiesForStorage()
uploadImage(array $a_upload_meta)
getImagePath($a_full_path=true)
static getObjectInstances(array $a_filter=null)
static _lookupTitle($a_id)
lookup object title
getFilePath($a_id, $a_subdir=null)
Init file system storage.
clone(int $target_parent_obj_id)
static getInstancesByParentId($a_parent_id, array $a_filter=null)
foreach($_POST as $key=> $value) $res
static getExtendedTypeCaption(ilBadgeType $a_type)
static moveUploadedFile($a_file, $a_name, $a_target, $a_raise_errors=true, $a_mode="move_uploaded")
move uploaded file
__construct($a_id=null)
Constructor.
static deleteByBadgeId($a_badge_id)
static _lookupType($a_id, $a_reference=false)
lookup object type
importImage($a_name, $a_file)
setConfiguration(array $a_value=null)
importDBRow(array $a_row)
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
static getInstancesByType($a_type_id)
prepareJson($a_base_url, $a_img_suffix)
static getInstance()
Constructor.