ILIAS  trunk Revision v11.0_alpha-1723-g8e69f309bab
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilMDTypicalAgeRange.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
28 {
29  private string $typical_age_range = '';
31  private string $typical_age_range_minimum = '';
32  private string $typical_age_range_maximum = '';
33 
34  // SET/GET
35  public function setTypicalAgeRange(string $a_typical_age_range): void
36  {
37  $this->typical_age_range = $a_typical_age_range;
38  }
39 
40  public function getTypicalAgeRange(): string
41  {
43  }
44 
45  public function setTypicalAgeRangeLanguage(ilMDLanguageItem $lng_obj): void
46  {
47  $this->typical_age_range_language = $lng_obj;
48  }
49 
51  {
52  return is_object($this->typical_age_range_language) ? $this->typical_age_range_language : null;
53  }
54 
55  public function getTypicalAgeRangeLanguageCode(): string
56  {
57  return is_object($this->typical_age_range_language) ? $this->typical_age_range_language->getLanguageCode() : '';
58  }
59 
60  public function setTypicalAgeRangeMinimum(string $a_min): void
61  {
62  $this->typical_age_range_minimum = $a_min;
63  }
64 
65  public function getTypicalAgeRangeMinimum(): string
66  {
68  }
69 
70  public function setTypicalAgeRangeMaximum(string $a_max): void
71  {
72  $this->typical_age_range_maximum = $a_max;
73  }
74 
75  public function getTypicalAgeRangeMaximum(): string
76  {
78  }
79 
80  public function save(): int
81  {
82  $fields = $this->__getFields();
83  $fields['meta_tar_id'] = array('integer', $next_id = $this->db->nextId('il_meta_tar'));
84 
85  if ($this->db->insert('il_meta_tar', $fields)) {
86  $this->setMetaId($next_id);
87  return $this->getMetaId();
88  }
89  return 0;
90  }
91 
92  public function update(): bool
93  {
94  $this->__parseTypicalAgeRange();
95 
96  return $this->getMetaId() && $this->db->update(
97  'il_meta_tar',
98  $this->__getFields(),
99  array("meta_tar_id" => array('integer', $this->getMetaId()))
100  );
101  }
102 
103  public function delete(): bool
104  {
105  if ($this->getMetaId()) {
106  $query = "DELETE FROM il_meta_tar " .
107  "WHERE meta_tar_id = " . $this->db->quote($this->getMetaId(), 'integer');
108  $res = $this->db->manipulate($query);
109  return true;
110  }
111  return false;
112  }
113 
117  public function __getFields(): array
118  {
119  return array(
120  'rbac_id' => array('integer', $this->getRBACId()),
121  'obj_id' => array('integer', $this->getObjId()),
122  'obj_type' => array('text', $this->getObjType()),
123  'parent_type' => array('text', $this->getParentType()),
124  'parent_id' => array('integer', $this->getParentId()),
125  'typical_age_range' => array('text', $this->getTypicalAgeRange()),
126  'tar_language' => array('text', $this->getTypicalAgeRangeLanguageCode()),
127  'tar_min' => array('text', $this->getTypicalAgeRangeMinimum()),
128  'tar_max' => array('text', $this->getTypicalAgeRangeMaximum())
129  );
130  }
131 
132  public function read(): bool
133  {
134  if ($this->getMetaId()) {
135  $query = "SELECT * FROM il_meta_tar " .
136  "WHERE meta_tar_id = " . $this->db->quote($this->getMetaId(), 'integer');
137 
138  $res = $this->db->query($query);
139  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
140  $this->setRBACId((int) $row->rbac_id);
141  $this->setObjId((int) $row->obj_id);
142  $this->setObjType($row->obj_type);
143  $this->setParentId((int) $row->parent_id);
144  $this->setParentType((string) $row->parent_type);
145  $this->setTypicalAgeRange((string) $row->typical_age_range);
146  $this->setTypicalAgeRangeLanguage(new ilMDLanguageItem($row->tar_language ?? ''));
147  $this->setTypicalAgeRangeMinimum((string) $row->tar_min);
148  $this->setTypicalAgeRangeMaximum((string) $row->tar_max);
149  }
150  }
151  return true;
152  }
153 
154  public function toXML(ilXmlWriter $writer): void
155  {
156  $writer->xmlElement(
157  'TypicalAgeRange',
158  array(
159  'Language' => $this->getTypicalAgeRangeLanguageCode() ?: 'en'
160  ),
161  $this->getTypicalAgeRange()
162  );
163  }
164 
165  // STATIC
166 
170  public static function _getIds(int $a_rbac_id, int $a_obj_id, int $a_parent_id, string $a_parent_type): array
171  {
172  global $DIC;
173 
174  $ilDB = $DIC->database();
175 
176  $query = "SELECT meta_tar_id FROM il_meta_tar " .
177  "WHERE rbac_id = " . $ilDB->quote($a_rbac_id, 'integer') . " " .
178  "AND obj_id = " . $ilDB->quote($a_obj_id, 'integer') . " " .
179  "AND parent_id = " . $ilDB->quote($a_parent_id, 'integer') . " " .
180  "AND parent_type = " . $ilDB->quote($a_parent_type, 'text');
181 
182  $res = $ilDB->query($query);
183  $ids = [];
184  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
185  $ids[] = (int) $row->meta_tar_id;
186  }
187 
188  return $ids;
189  }
190 
191  // PRIVATE
192  public function __parseTypicalAgeRange(): bool
193  {
194  if (preg_match("/\s*(\d*)\s*(-?)\s*(\d*)/", $this->getTypicalAgeRange(), $matches)) {
195  if (!$matches[2] and !$matches[3]) {
196  $min = $max = $matches[1];
197  } elseif ($matches[2] and !$matches[3]) {
198  $min = $matches[1];
199  $max = 99;
200  } else {
201  $min = $matches[1];
202  $max = $matches[3];
203  }
204  $this->setTypicalAgeRangeMaximum((string) $max);
205  $this->setTypicalAgeRangeMinimum((string) $min);
206 
207  return true;
208  }
209 
210  if (!$this->getTypicalAgeRange()) {
211  $this->setTypicalAgeRangeMinimum('-1');
212  $this->setTypicalAgeRangeMaximum('-1');
213  }
214 
215  return true;
216  }
217 }
$res
Definition: ltiservices.php:66
setTypicalAgeRangeMaximum(string $a_max)
setRBACId(int $a_id)
ilMDLanguageItem $typical_age_range_language
setTypicalAgeRange(string $a_typical_age_range)
setTypicalAgeRangeLanguage(ilMDLanguageItem $lng_obj)
static _getIds(int $a_rbac_id, int $a_obj_id, int $a_parent_id, string $a_parent_type)
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)
setTypicalAgeRangeMinimum(string $a_min)