ILIAS  release_8 Revision v8.24
class.ilMDTaxon.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
26class ilMDTaxon extends ilMDBase
27{
28 private string $taxon = '';
30 private string $taxon_id = '';
31
32 // SET/GET
33 public function setTaxon(string $a_taxon): void
34 {
35 $this->taxon = $a_taxon;
36 }
37
38 public function getTaxon(): string
39 {
40 return $this->taxon;
41 }
42
43 public function setTaxonLanguage(ilMDLanguageItem $lng_obj): void
44 {
45 $this->taxon_language = $lng_obj;
46 }
47
49 {
50 return is_object($this->taxon_language) ? $this->taxon_language : null;
51 }
52
53 public function getTaxonLanguageCode(): string
54 {
55 return is_object($this->taxon_language) ? $this->taxon_language->getLanguageCode() : '';
56 }
57
58 public function setTaxonId(string $a_taxon_id): void
59 {
60 $this->taxon_id = $a_taxon_id;
61 }
62
63 public function getTaxonId(): string
64 {
65 return $this->taxon_id;
66 }
67
68 public function save(): int
69 {
70 $fields = $this->__getFields();
71 $fields['meta_taxon_id'] = array('integer', $next_id = $this->db->nextId('il_meta_taxon'));
72
73 if ($this->db->insert('il_meta_taxon', $fields)) {
74 $this->setMetaId($next_id);
75 return $this->getMetaId();
76 }
77 return 0;
78 }
79
80 public function update(): bool
81 {
82 return $this->getMetaId() && $this->db->update(
83 'il_meta_taxon',
84 $this->__getFields(),
85 array("meta_taxon_id" => array('integer', $this->getMetaId()))
86 );
87 }
88
89 public function delete(): bool
90 {
91 if ($this->getMetaId()) {
92 $query = "DELETE FROM il_meta_taxon " .
93 "WHERE meta_taxon_id = " . $this->db->quote($this->getMetaId(), 'integer');
94
95 $this->db->query($query);
96
97 return true;
98 }
99 return false;
100 }
101
105 public function __getFields(): array
106 {
107 return array(
108 'rbac_id' => array('integer', $this->getRBACId()),
109 'obj_id' => array('integer', $this->getObjId()),
110 'obj_type' => array('text', $this->getObjType()),
111 'parent_type' => array('text', $this->getParentType()),
112 'parent_id' => array('integer', $this->getParentId()),
113 'taxon' => array('text', $this->getTaxon()),
114 'taxon_language' => array('text', $this->getTaxonLanguageCode()),
115 'taxon_id' => array('text', $this->getTaxonId())
116 );
117 }
118
119 public function read(): bool
120 {
121 if ($this->getMetaId()) {
122 $query = "SELECT * FROM il_meta_taxon " .
123 "WHERE meta_taxon_id = " . $this->db->quote($this->getMetaId(), 'integer');
124
125 $res = $this->db->query($query);
126 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
127 $this->setRBACId((int) $row->rbac_id);
128 $this->setObjId((int) $row->obj_id);
129 $this->setObjType($row->obj_type);
130 $this->setParentId((int) $row->parent_id);
131 $this->setParentType($row->parent_type);
132 $this->setTaxon($row->taxon ?? '');
133 $this->taxon_language = new ilMDLanguageItem($row->taxon_language ?? '');
134 $this->setTaxonId($row->taxon_id ?? '');
135 }
136 }
137 return true;
138 }
139
140 public function toXML(ilXmlWriter $writer): void
141 {
142 $random = new \ilRandom();
143 $writer->xmlElement(
144 'Taxon',
145 array(
146 'Language' => $this->getTaxonLanguageCode() ?: 'en',
147 'Id' => $this->getTaxonId() ?: ("ID" . $random->int())
148 ),
149 $this->getTaxon()
150 );
151 }
152
153 // STATIC
154
158 public static function _getIds(int $a_rbac_id, int $a_obj_id, int $a_parent_id, string $a_parent_type): array
159 {
160 global $DIC;
161
162 $ilDB = $DIC->database();
163
164 $query = "SELECT meta_taxon_id FROM il_meta_taxon " .
165 "WHERE rbac_id = " . $ilDB->quote($a_rbac_id, 'integer') . " " .
166 "AND obj_id = " . $ilDB->quote($a_obj_id, 'integer') . " " .
167 "AND parent_id = " . $ilDB->quote($a_parent_id, 'integer') . " " .
168 "AND parent_type = " . $ilDB->quote($a_parent_type, 'text');
169
170 $res = $ilDB->query($query);
171 $ids = [];
172 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
173 $ids[] = (int) $row->meta_taxon_id;
174 }
175 return $ids;
176 }
177}
setObjType(string $a_type)
setParentType(string $a_parent_type)
setObjId(int $a_id)
setMetaId(int $a_meta_id, bool $a_read_data=true)
setRBACId(int $a_id)
setParentId(int $a_id)
setTaxonLanguage(ilMDLanguageItem $lng_obj)
setTaxonId(string $a_taxon_id)
toXML(ilXmlWriter $writer)
setTaxon(string $a_taxon)
static _getIds(int $a_rbac_id, int $a_obj_id, int $a_parent_id, string $a_parent_type)
string $taxon_id
ilMDLanguageItem $taxon_language
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