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