ILIAS  trunk Revision v11.0_alpha-1811-gd2d5443e411
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilMDTaxonPath.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
27 class ilMDTaxonPath extends ilMDBase
28 {
29  private string $source = '';
31 
32  // METHODS OF CHILD OBJECTS (Taxon)
33 
37  public function getTaxonIds(): array
38  {
39  if (!$this->getMetaId()) {
40  return [];
41  }
42  return ilMDTaxon::_getIds($this->getRBACId(), $this->getObjId(), $this->getMetaId(), 'meta_taxon_path');
43  }
44 
45  public function getTaxon(int $a_taxon_id): ?ilMDTaxon
46  {
47  if (!$a_taxon_id) {
48  return null;
49  }
50  $tax = new ilMDTaxon();
51  $tax->setMetaId($a_taxon_id);
52 
53  return $tax;
54  }
55 
56  public function addTaxon(): ilMDTaxon
57  {
58  $tax = new ilMDTaxon($this->getRBACId(), $this->getObjId(), $this->getObjType());
59  $tax->setParentId($this->getMetaId());
60  $tax->setParentType('meta_taxon_path');
61 
62  return $tax;
63  }
64 
65  // SET/GET
66  public function setSource(string $a_source): void
67  {
68  $this->source = $a_source;
69  }
70 
71  public function getSource(): string
72  {
73  return $this->source;
74  }
75 
76  public function setSourceLanguage(ilMDLanguageItem $lng_obj): void
77  {
78  $this->source_language = $lng_obj;
79  }
80 
81  public function getSourceLanguage(): ?ilMDLanguageItem
82  {
83  return is_object($this->source_language) ? $this->source_language : null;
84  }
85 
86  public function getSourceLanguageCode(): string
87  {
88  return is_object($this->source_language) ? $this->source_language->getLanguageCode() : '';
89  }
90 
91  public function save(): int
92  {
93  $fields = $this->__getFields();
94  $fields['meta_taxon_path_id'] = array('integer', $next_id = $this->db->nextId('il_meta_taxon_path'));
95 
96  if ($this->db->insert('il_meta_taxon_path', $fields)) {
97  $this->setMetaId($next_id);
98  return $this->getMetaId();
99  }
100  return 0;
101  }
102 
103  public function update(): bool
104  {
105  return $this->getMetaId() && $this->db->update(
106  'il_meta_taxon_path',
107  $this->__getFields(),
108  array("meta_taxon_path_id" => array('integer', $this->getMetaId()))
109  );
110  }
111 
112  public function delete(): bool
113  {
114  if ($this->getMetaId()) {
115  $query = "DELETE FROM il_meta_taxon_path " .
116  "WHERE meta_taxon_path_id = " . $this->db->quote($this->getMetaId(), 'integer');
117  $res = $this->db->manipulate($query);
118 
119  foreach ($this->getTaxonIds() as $id) {
120  $tax = $this->getTaxon($id);
121  $tax->delete();
122  }
123 
124  return true;
125  }
126  return false;
127  }
128 
132  public function __getFields(): array
133  {
134  return array(
135  'rbac_id' => array('integer', $this->getRBACId()),
136  'obj_id' => array('integer', $this->getObjId()),
137  'obj_type' => array('text', $this->getObjType()),
138  'parent_type' => array('text', $this->getParentType()),
139  'parent_id' => array('integer', $this->getParentId()),
140  'source' => array('text', $this->getSource()),
141  'source_language' => array('text', $this->getSourceLanguageCode())
142  );
143  }
144 
145  public function read(): bool
146  {
147  if ($this->getMetaId()) {
148  $query = "SELECT * FROM il_meta_taxon_path " .
149  "WHERE meta_taxon_path_id = " . $this->db->quote($this->getMetaId(), 'integer');
150 
151  $res = $this->db->query($query);
152  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
153  $this->setRBACId((int) $row->rbac_id);
154  $this->setObjId((int) $row->obj_id);
155  $this->setObjType($row->obj_type);
156  $this->setParentId((int) $row->parent_id);
157  $this->setParentType($row->parent_type);
158  $this->setSource($row->source ?? '');
159  $this->source_language = new ilMDLanguageItem($row->source_language ?? '');
160  }
161  }
162  return true;
163  }
164 
165  public function toXML(ilXmlWriter $writer): void
166  {
167  $writer->xmlStartTag('TaxonPath');
168 
169  $writer->xmlElement(
170  'Source',
171  array(
172  'Language' => $this->getSourceLanguageCode() ?: 'en'
173  ),
174  $this->getSource()
175  );
176 
177  // Taxon
178  $taxs = $this->getTaxonIds();
179  foreach ($taxs as $id) {
180  $tax = $this->getTaxon($id);
181  $tax->toXML($writer);
182  }
183  if (!count($taxs)) {
184  $tax = new ilMDTaxon($this->getRBACId(), $this->getObjId());
185  $tax->toXML($writer);
186  }
187 
188  $writer->xmlEndTag('TaxonPath');
189  }
190 
194  public static function _getIds(int $a_rbac_id, int $a_obj_id, int $a_parent_id, string $a_parent_type): array
195  {
196  global $DIC;
197 
198  $ilDB = $DIC->database();
199 
200  $query = "SELECT meta_taxon_path_id FROM il_meta_taxon_path " .
201  "WHERE rbac_id = " . $ilDB->quote($a_rbac_id, 'integer') . " " .
202  "AND obj_id = " . $ilDB->quote($a_obj_id, 'integer') . " " .
203  "AND parent_id = " . $ilDB->quote($a_parent_id, 'integer') . " " .
204  "AND parent_type = " . $ilDB->quote($a_parent_type, 'text');
205 
206  $res = $ilDB->query($query);
207  $ids = [];
208  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
209  $ids[] = (int) $row->meta_taxon_path_id;
210  }
211  return $ids;
212  }
213 }
$res
Definition: ltiservices.php:66
static _getIds(int $a_rbac_id, int $a_obj_id, int $a_parent_id, string $a_parent_type)
static _getIds(int $a_rbac_id, int $a_obj_id, int $a_parent_id, string $a_parent_type)
setRBACId(int $a_id)
xmlEndTag(string $tag)
Writes an endtag.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
setObjId(int $a_id)
ilMDLanguageItem $source_language
global $DIC
Definition: shib_login.php:22
setParentId(int $a_id)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
xmlStartTag(string $tag, ?array $attrs=null, bool $empty=false, bool $encode=true, bool $escape=true)
Writes a starttag.
setParentType(string $a_parent_type)
setSource(string $a_source)
setSourceLanguage(ilMDLanguageItem $lng_obj)
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)
getTaxon(int $a_taxon_id)
setObjType(string $a_type)
toXML(ilXmlWriter $writer)