ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilMDDescription.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
27 {
28  private string $description = '';
30 
31  // SET/GET
32  public function setDescription(string $a_description): void
33  {
34  $this->description = $a_description;
35  }
36 
37  public function getDescription(): string
38  {
39  return $this->description;
40  }
41 
42  public function setDescriptionLanguage(ilMDLanguageItem $lng_obj): void
43  {
44  $this->description_language = $lng_obj;
45  }
46 
48  {
49  return is_object($this->description_language) ? $this->description_language : null;
50  }
51 
52  public function getDescriptionLanguageCode(): string
53  {
54  return is_object($this->description_language) ? $this->description_language->getLanguageCode() : '';
55  }
56 
57  public function save(): int
58  {
59  $fields = $this->__getFields();
60  $fields['meta_description_id'] = array('integer', $next_id = $this->db->nextId('il_meta_description'));
61 
62  if ($this->db->insert('il_meta_description', $fields)) {
63  $this->setMetaId($next_id);
64  return $this->getMetaId();
65  }
66  return 0;
67  }
68 
69  public function update(): bool
70  {
71  return $this->getMetaId() && $this->db->update(
72  'il_meta_description',
73  $this->__getFields(),
74  array("meta_description_id" => array('integer', $this->getMetaId()))
75  );
76  }
77 
78  public function delete(): bool
79  {
80  if ($this->getMetaId()) {
81  $query = "DELETE FROM il_meta_description " .
82  "WHERE meta_description_id = " . $this->db->quote($this->getMetaId(), 'integer');
83  $res = $this->db->manipulate($query);
84 
85  return true;
86  }
87  return false;
88  }
89 
93  public function __getFields(): array
94  {
95  return array(
96  'rbac_id' => array('integer', $this->getRBACId()),
97  'obj_id' => array('integer', $this->getObjId()),
98  'obj_type' => array('text', $this->getObjType()),
99  'parent_type' => array('text', $this->getParentType()),
100  'parent_id' => array('integer', $this->getParentId()),
101  'description' => array('clob', $this->getDescription()),
102  'description_language' => array('text', $this->getDescriptionLanguageCode())
103  );
104  }
105 
106  public function read(): bool
107  {
108  if ($this->getMetaId()) {
109  $query = "SELECT * FROM il_meta_description " .
110  "WHERE meta_description_id = " . $this->db->quote($this->getMetaId(), 'integer');
111 
112  $res = $this->db->query($query);
113  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
114  $this->setRBACId((int) $row->rbac_id);
115  $this->setObjId((int) $row->obj_id);
116  $this->setObjType($row->obj_type ?? '');
117  $this->setParentId((int) $row->parent_id);
118  $this->setParentType($row->parent_type ?? '');
119  $this->setDescription($row->description ?? '');
120  $this->setDescriptionLanguage(new ilMDLanguageItem($row->description_language ?? ''));
121  }
122  }
123  return true;
124  }
125 
126  public function toXML(ilXmlWriter $writer): void
127  {
128  $writer->xmlElement(
129  'Description',
130  array(
131  'Language' => $this->getDescriptionLanguageCode() ?: 'en'
132  ),
133  $this->getDescription()
134  );
135  }
136 
137  // STATIC
138 
142  public static function _getIds(int $a_rbac_id, int $a_obj_id, int $a_parent_id, string $a_parent_type): array
143  {
144  global $DIC;
145 
146  $ilDB = $DIC->database();
147 
148  $query = "SELECT meta_description_id FROM il_meta_description " .
149  "WHERE rbac_id = " . $ilDB->quote($a_rbac_id, ilDBConstants::T_INTEGER) . " " .
150  "AND obj_id = " . $ilDB->quote($a_obj_id, ilDBConstants::T_INTEGER) . " " .
151  "AND parent_id = " . $ilDB->quote($a_parent_id, ilDBConstants::T_INTEGER) . " " .
152  "AND parent_type = " . $ilDB->quote($a_parent_type, ilDBConstants::T_INTEGER) . " " .
153  "ORDER BY meta_description_id";
154 
155  $res = $ilDB->query($query);
156  $ids = [];
157  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
158  $ids[] = (int) $row->meta_description_id;
159  }
160  return $ids;
161  }
162 }
$res
Definition: ltiservices.php:69
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _getIds(int $a_rbac_id, int $a_obj_id, int $a_parent_id, string $a_parent_type)
setRBACId(int $a_id)
setDescriptionLanguage(ilMDLanguageItem $lng_obj)
toXML(ilXmlWriter $writer)
global $DIC
Definition: feed.php:28
setObjId(int $a_id)
ilMDLanguageItem $description_language
setDescription(string $a_description)
setParentId(int $a_id)
setParentType(string $a_parent_type)
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)