ILIAS  release_8 Revision v8.24
class.ilMDFormat.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
27class ilMDFormat extends ilMDBase
28{
29 private string $format = '';
30
31 // SET/_GET
32 public function setFormat(string $a_format): void
33 {
34 $this->format = $a_format;
35 }
36
37 public function getFormat(): string
38 {
39 return $this->format;
40 }
41
42 public function save(): int
43 {
44 $fields = $this->__getFields();
45 $fields['meta_format_id'] = array('integer', $next_id = $this->db->nextId('il_meta_format'));
46
47 if ($this->db->insert('il_meta_format', $fields)) {
48 $this->setMetaId($next_id);
49 return $this->getMetaId();
50 }
51 return 0;
52 }
53
54 public function update(): bool
55 {
56 return $this->getMetaId() && $this->db->update(
57 'il_meta_format',
58 $this->__getFields(),
59 array("meta_format_id" => array('integer', $this->getMetaId()))
60 );
61 }
62
63 public function delete(): bool
64 {
65 if ($this->getMetaId()) {
66 $query = "DELETE FROM il_meta_format " .
67 "WHERE meta_format_id = " . $this->db->quote($this->getMetaId(), 'integer');
68 $res = $this->db->manipulate($query);
69
70 return true;
71 }
72 return false;
73 }
74
78 public function __getFields(): array
79 {
80 return array(
81 'rbac_id' => array('integer', $this->getRBACId()),
82 'obj_id' => array('integer', $this->getObjId()),
83 'obj_type' => array('text', $this->getObjType()),
84 'format' => array('text', $this->getFormat())
85 );
86 }
87
88 public function read(): bool
89 {
90 if ($this->getMetaId()) {
91 $query = "SELECT * FROM il_meta_format " .
92 "WHERE meta_format_id = " . $this->db->quote($this->getMetaId(), 'integer');
93
94 $res = $this->db->query($query);
95 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
96 $this->setRBACId((int) $row->rbac_id);
97 $this->setObjId((int) $row->obj_id);
98 $this->setObjType($row->obj_type);
99 $this->setFormat($row->format ?? '');
100 }
101 }
102 return true;
103 }
104
105 public function toXML(ilXmlWriter $writer): void
106 {
107 if ($this->getFormat()) {
108 $writer->xmlElement('Format', null, $this->getFormat());
109 }
110 }
111
112 // STATIC
113
117 public static function _getIds(int $a_rbac_id, int $a_obj_id): array
118 {
119 global $DIC;
120
121 $ilDB = $DIC->database();
122
123 $query = "SELECT meta_format_id FROM il_meta_format " .
124 "WHERE rbac_id = " . $ilDB->quote($a_rbac_id, 'integer') . " " .
125 "AND obj_id = " . $ilDB->quote($a_obj_id, 'integer');
126
127 $res = $ilDB->query($query);
128 $ids = [];
129 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
130 $ids[] = (int) $row->meta_format_id;
131 }
132 return $ids;
133 }
134}
setObjType(string $a_type)
setObjId(int $a_id)
setMetaId(int $a_meta_id, bool $a_read_data=true)
setRBACId(int $a_id)
setFormat(string $a_format)
static _getIds(int $a_rbac_id, int $a_obj_id)
toXML(ilXmlWriter $writer)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
xmlElement(string $tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
global $DIC
Definition: feed.php:28
$res
Definition: ltiservices.php:69
$query