ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilMDRequirement.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
27 {
28  private int $or_composite_id = 0;
29  private string $operating_system_name = '';
30  private string $operating_system_minimum_version = '';
31  private string $operating_system_maximum_version = '';
32  private string $browser_name = '';
33  private string $browser_minimum_version = '';
34  private string $browser_maximum_version = '';
35 
36  // SET/GET
37  public function setOrCompositeId(int $a_or_composite_id): void
38  {
39  $this->or_composite_id = $a_or_composite_id;
40  }
41 
42  public function getOrCompositeId(): int
43  {
45  }
46 
47  public function setOperatingSystemName(string $a_val): bool
48  {
49  switch ($a_val) {
50  case 'PC-DOS':
51  case 'MS-Windows':
52  case 'MacOS':
53  case 'Unix':
54  case 'Multi-OS':
55  case 'None':
56  $this->operating_system_name = $a_val;
57  return true;
58 
59  default:
60  return false;
61  }
62  }
63 
64  public function getOperatingSystemName(): string
65  {
67  }
68 
69  public function setOperatingSystemMinimumVersion(string $a_val): void
70  {
71  $this->operating_system_minimum_version = $a_val;
72  }
73 
74  public function getOperatingSystemMinimumVersion(): string
75  {
77  }
78 
79  public function setOperatingSystemMaximumVersion(string $a_val): void
80  {
81  $this->operating_system_maximum_version = $a_val;
82  }
83 
84  public function getOperatingSystemMaximumVersion(): string
85  {
87  }
88 
89  public function setBrowserName(string $a_val): bool
90  {
91  switch ($a_val) {
92  case 'Any':
93  case 'NetscapeCommunicator':
94  case 'MS-InternetExplorer':
95  case 'Opera':
96  case 'Amaya':
97  case 'Mozilla':
98  $this->browser_name = $a_val;
99  return true;
100 
101  default:
102  return false;
103  }
104  }
105 
106  public function getBrowserName(): string
107  {
108  return $this->browser_name;
109  }
110 
111  public function setBrowserMinimumVersion(string $a_val): void
112  {
113  $this->browser_minimum_version = $a_val;
114  }
115 
116  public function getBrowserMinimumVersion(): string
117  {
119  }
120 
121  public function setBrowserMaximumVersion(string $a_val): void
122  {
123  $this->browser_maximum_version = $a_val;
124  }
125 
126  public function getBrowserMaximumVersion(): string
127  {
129  }
130 
131  public function save(): int
132  {
133  $fields = $this->__getFields();
134  $fields['meta_requirement_id'] = array('integer', $next_id = $this->db->nextId('il_meta_requirement'));
135 
136  if ($this->db->insert('il_meta_requirement', $fields)) {
137  $this->setMetaId($next_id);
138  return $this->getMetaId();
139  }
140  return 0;
141  }
142 
143  public function update(): bool
144  {
145  return $this->getMetaId() && $this->db->update(
146  'il_meta_requirement',
147  $this->__getFields(),
148  array("meta_requirement_id" => array('integer', $this->getMetaId()))
149  );
150  }
151 
152  public function delete(): bool
153  {
154  if ($this->getMetaId()) {
155  $query = "DELETE FROM il_meta_requirement " .
156  "WHERE meta_requirement_id = " . $this->db->quote($this->getMetaId(), 'integer');
157  $res = $this->db->manipulate($query);
158  return true;
159  }
160  return false;
161  }
162 
166  public function __getFields(): array
167  {
168  return array(
169  'rbac_id' => array('integer', $this->getRBACId()),
170  'obj_id' => array('integer', $this->getObjId()),
171  'obj_type' => array('text', $this->getObjType()),
172  'parent_type' => array('text', $this->getParentType()),
173  'parent_id' => array('integer', $this->getParentId()),
174  'operating_system_name' => array('text', $this->getOperatingSystemName()),
175  'os_min_version' => array('text', $this->getOperatingSystemMinimumVersion()),
176  'os_max_version' => array('text', $this->getOperatingSystemMaximumVersion()),
177  'browser_name' => array('text', $this->getBrowserName()),
178  'browser_minimum_version' => array('text', $this->getBrowserMinimumVersion()),
179  'browser_maximum_version' => array('text', $this->getBrowserMaximumVersion()),
180  'or_composite_id' => array('integer', $this->getOrCompositeId())
181  );
182  }
183 
184  public function read(): bool
185  {
186  if ($this->getMetaId()) {
187  $query = "SELECT * FROM il_meta_requirement " .
188  "WHERE meta_requirement_id = " . $this->db->quote($this->getMetaId(), 'integer');
189 
190  $res = $this->db->query($query);
191  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
192  $this->setRBACId((int) $row->rbac_id);
193  $this->setObjId((int) $row->obj_id);
194  $this->setObjType($row->obj_type);
195  $this->setParentId((int) $row->parent_id);
196  $this->setParentType($row->parent_type);
197  $this->setOperatingSystemName($row->operating_system_name ?? '');
198  $this->setOperatingSystemMinimumVersion($row->os_min_version ?? '');
199  $this->setOperatingSystemMaximumVersion($row->os_max_version ?? '');
200  $this->setBrowserName($row->browser_name ?? '');
201  $this->setBrowserMinimumVersion($row->browser_minimum_version ?? '');
202  $this->setBrowserMaximumVersion($row->browser_maximum_version ?? '');
203  $this->setOrCompositeId((int) $row->or_composite_id);
204  }
205  }
206  return true;
207  }
208 
209  /*
210  * XML Export of all meta data
211  * @param object (xml writer) see class.ilMD2XML.php
212  *
213  */
214  public function toXML(ilXmlWriter $writer): void
215  {
216  $writer->xmlStartTag('Requirement');
217  $writer->xmlStartTag('Type');
218 
219  if ($this->getOperatingSystemName() !== '') {
220  $writer->xmlElement('OperatingSystem', array(
221  'Name' => $this->getOperatingSystemName() ?: 'None',
222  'MinimumVersion' => $this->getOperatingSystemMinimumVersion(),
223  'MaximumVersion' => $this->getOperatingSystemMaximumVersion()
224  ));
225  }
226  if ($this->getBrowserName() !== '') {
227  $writer->xmlElement('Browser', array(
228  'Name' => $this->getBrowserName() ?: 'Any',
229  'MinimumVersion' => $this->getBrowserMinimumVersion(),
230  'MaximumVersion' => $this->getBrowserMaximumVersion()
231  ));
232  }
233  $writer->xmlEndTag('Type');
234  $writer->xmlEndTag('Requirement');
235  }
236 
237  // STATIC
238 
242  public static function _getIds(
243  int $a_rbac_id,
244  int $a_obj_id,
245  int $a_parent_id,
246  string $a_parent_type,
247  int $a_or_composite_id = 0
248  ): array {
249  global $DIC;
250 
251  $ilDB = $DIC->database();
252 
253  $query = "SELECT meta_requirement_id FROM il_meta_requirement " .
254  "WHERE rbac_id = " . $ilDB->quote($a_rbac_id, 'integer') . " " .
255  "AND obj_id = " . $ilDB->quote($a_obj_id, 'integer') . " " .
256  "AND parent_id = " . $ilDB->quote($a_parent_id, 'integer') . " " .
257  "AND parent_type = " . $ilDB->quote($a_parent_type, 'text') . " " .
258  "AND or_composite_id = " . $ilDB->quote($a_or_composite_id, 'integer');
259 
260  $res = $ilDB->query($query);
261  $ids = [];
262  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
263  $ids[] = (int) $row->meta_requirement_id;
264  }
265  return $ids;
266  }
267 }
$res
Definition: ltiservices.php:69
setOperatingSystemMaximumVersion(string $a_val)
setOrCompositeId(int $a_or_composite_id)
toXML(ilXmlWriter $writer)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setRBACId(int $a_id)
string $operating_system_maximum_version
xmlEndTag(string $tag)
Writes an endtag.
setBrowserMinimumVersion(string $a_val)
global $DIC
Definition: feed.php:28
setObjId(int $a_id)
setOperatingSystemMinimumVersion(string $a_val)
string $operating_system_minimum_version
static _getIds(int $a_rbac_id, int $a_obj_id, int $a_parent_id, string $a_parent_type, int $a_or_composite_id=0)
setBrowserName(string $a_val)
setBrowserMaximumVersion(string $a_val)
$query
setParentId(int $a_id)
setOperatingSystemName(string $a_val)
xmlStartTag(string $tag, ?array $attrs=null, bool $empty=false, bool $encode=true, bool $escape=true)
Writes a starttag.
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)