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