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