ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
class.ilMDTechnical.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
27 class ilMDTechnical extends ilMDBase
28 {
29  private string $size = '';
30  private string $installation_remarks = '';
32  private string $other_platform_requirements = '';
34  private string $duration = '';
35 
39  public function getPossibleSubelements(): array
40  {
41  $subs['Format'] = 'meta_format';
42  $subs['Location'] = 'meta_location';
43  if (!$this->getOrCompositeIds()) {
44  $subs['Requirement'] = 'meta_requirement';
45  }
46  if (!$this->getRequirementIds()) {
47  $subs['OrComposite'] = 'meta_or_composite';
48  }
49 
50  return $subs;
51  }
52 
53  // Methods for child objects (Format, Location, Requirement OrComposite)
54 
58  public function getFormatIds(): array
59  {
60  return ilMDFormat::_getIds($this->getRBACId(), $this->getObjId());
61  }
62 
63  public function getFormat(int $a_format_id): ?ilMDFormat
64  {
65  if (!$a_format_id) {
66  return null;
67  }
68  $for = new ilMDFormat($this->getRBACId(), $a_format_id);
69  $for->setMetaId($a_format_id);
70 
71  return $for;
72  }
73 
74  public function addFormat(): ilMDFormat
75  {
76  $for = new ilMDFormat($this->getRBACId(), $this->getObjId(), $this->getObjType());
77 
78  return $for;
79  }
80 
84  public function getLocationIds(): array
85  {
86  return ilMDLocation::_getIds($this->getRBACId(), $this->getObjId(), $this->getMetaId(), 'meta_technical');
87  }
88 
89  public function getLocation(int $a_location_id): ?ilMDLocation
90  {
91  if (!$a_location_id) {
92  return null;
93  }
94  $loc = new ilMDLocation();
95  $loc->setMetaId($a_location_id);
96 
97  return $loc;
98  }
99 
100  public function addLocation(): ilMDLocation
101  {
102  $loc = new ilMDLocation($this->getRBACId(), $this->getObjId(), $this->getObjType());
103  $loc->setParentId($this->getMetaId());
104  $loc->setParentType('meta_technical');
105 
106  return $loc;
107  }
108 
112  public function getRequirementIds(): array
113  {
114  return ilMDRequirement::_getIds($this->getRBACId(), $this->getObjId(), $this->getMetaId(), 'meta_technical');
115  }
116 
117  public function getRequirement(int $a_requirement_id): ?ilMDRequirement
118  {
119  if (!$a_requirement_id) {
120  return null;
121  }
122  $rec = new ilMDRequirement();
123  $rec->setMetaId($a_requirement_id);
124 
125  return $rec;
126  }
127 
128  public function addRequirement(): ilMDRequirement
129  {
130  $rec = new ilMDRequirement($this->getRBACId(), $this->getObjId(), $this->getObjType());
131  $rec->setParentId($this->getMetaId());
132  $rec->setParentType('meta_technical');
133 
134  return $rec;
135  }
136 
140  public function getOrCompositeIds(): array
141  {
142  return ilMDOrComposite::_getIds($this->getRBACId(), $this->getObjId(), $this->getMetaId(), 'meta_technical');
143  }
144 
145  public function getOrComposite(int $a_or_composite_id): ?ilMDOrComposite
146  {
147  if (!$a_or_composite_id) {
148  return null;
149  }
150  $orc = new ilMDOrComposite($this->getRBACId(), $this->getObjId(), $this->getObjType());
151  $orc->setOrCompositeId($a_or_composite_id);
152  $orc->setParentId($this->getMetaId());
153  $orc->setParentType('meta_technical');
154 
155  return $orc;
156  }
157 
158  public function addOrComposite(): ilMDOrComposite
159  {
160  $orc = new ilMDOrComposite($this->getRBACId(), $this->getObjId(), $this->getObjType());
161  $orc->setParentId($this->getMetaId());
162  $orc->setParentType('meta_technical');
163 
164  return $orc;
165  }
166 
167  // SET/GET
168  public function setSize(string $a_size): void
169  {
170  $this->size = $a_size;
171  }
172 
173  public function getSize(): string
174  {
175  return $this->size;
176  }
177 
178  public function setInstallationRemarks(string $a_val): void
179  {
180  $this->installation_remarks = $a_val;
181  }
182 
183  public function getInstallationRemarks(): string
184  {
186  }
187 
188  public function setInstallationRemarksLanguage(ilMDLanguageItem $lng_obj): void
189  {
190  $this->installation_remarks_language = $lng_obj;
191  }
192 
194  {
195  return is_object($this->installation_remarks_language) ? $this->installation_remarks_language : null;
196  }
197 
198  public function getInstallationRemarksLanguageCode(): string
199  {
200  return is_object($this->installation_remarks_language) ? $this->installation_remarks_language->getLanguageCode() : '';
201  }
202 
203  public function setOtherPlatformRequirements(string $a_val): void
204  {
205  $this->other_platform_requirements = $a_val;
206  }
207 
208  public function getOtherPlatformRequirements(): string
209  {
211  }
212 
214  {
215  $this->other_platform_requirements_language = $lng_obj;
216  }
217 
219  {
220  return is_object($this->other_platform_requirements_language) ? $this->other_platform_requirements_language : null;
221  }
222 
224  {
225  return is_object($this->other_platform_requirements_language)
226  ? $this->other_platform_requirements_language->getLanguageCode()
227  : '';
228  }
229 
230  public function setDuration(string $a_val): void
231  {
232  $this->duration = $a_val;
233  }
234 
235  public function getDuration(): string
236  {
237  return $this->duration;
238  }
239 
240  public function save(): int
241  {
242  $fields = $this->__getFields();
243  $fields['meta_technical_id'] = array('integer', $next_id = $this->db->nextId('il_meta_technical'));
244 
245  if ($this->db->insert('il_meta_technical', $fields)) {
246  $this->setMetaId($next_id);
247  return $this->getMetaId();
248  }
249  return 0;
250  }
251 
252  public function update(): bool
253  {
254  return $this->getMetaId() && $this->db->update(
255  'il_meta_technical',
256  $this->__getFields(),
257  array("meta_technical_id" => array('integer', $this->getMetaId()))
258  );
259  }
260 
261  public function delete(): bool
262  {
263  if ($this->getMetaId()) {
264  $query = "DELETE FROM il_meta_technical " .
265  "WHERE meta_technical_id = " . $this->db->quote($this->getMetaId(), 'integer');
266  $res = $this->db->manipulate($query);
267 
268  foreach ($this->getFormatIds() as $id) {
269  $for = $this->getFormat($id);
270  $for->delete();
271  }
272 
273  foreach ($this->getLocationIds() as $id) {
274  $loc = $this->getLocation($id);
275  $loc->delete();
276  }
277  foreach ($this->getRequirementIds() as $id) {
278  $req = $this->getRequirement($id);
279  $req->delete();
280  }
281  foreach ($this->getOrCompositeIds() as $id) {
282  $orc = $this->getOrComposite($id);
283  $orc->delete();
284  }
285 
286  return true;
287  }
288  return false;
289  }
290 
294  public function __getFields(): array
295  {
296  return array(
297  'rbac_id' => array('integer', $this->getRBACId()),
298  'obj_id' => array('integer', $this->getObjId()),
299  'obj_type' => array('text', $this->getObjType()),
300  't_size' => array('text', $this->getSize()),
301  'ir' => array('text', $this->getInstallationRemarks()),
302  'ir_language' => array('text', $this->getInstallationRemarksLanguageCode()),
303  'opr' => array('text', $this->getOtherPlatformRequirements()),
304  'opr_language' => array('text', $this->getOtherPlatformRequirementsLanguageCode()),
305  'duration' => array('text', $this->getDuration())
306  );
307  }
308 
309  public function read(): bool
310  {
311  if ($this->getMetaId()) {
312  $query = "SELECT * FROM il_meta_technical " .
313  "WHERE meta_technical_id = " . $this->db->quote($this->getMetaId(), 'integer') . " ";
314 
315  $res = $this->db->query($query);
316  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
317  $this->setRBACId((int) $row->rbac_id);
318  $this->setObjId((int) $row->obj_id);
319  $this->setObjType($row->obj_type);
320  $this->setSize($row->t_size ?? '');
321  $this->setInstallationRemarks($row->ir ?? '');
322  $this->setInstallationRemarksLanguage(new ilMDLanguageItem($row->ir_language ?? ''));
323  $this->setOtherPlatformRequirements($row->opr ?? '');
324  $this->setOtherPlatformRequirementsLanguage(new ilMDLanguageItem($row->opr_language ?? ''));
325  $this->setDuration($row->duration ?? '');
326  }
327  return true;
328  }
329  return false;
330  }
331 
332  public function toXML(ilXmlWriter $writer): void
333  {
334  $writer->xmlStartTag('Technical');
335 
336  // Format
337  foreach ($this->getFormatIds() as $id) {
338  $for = $this->getFormat($id);
339  $for->toXML($writer);
340  }
341 
342  // Size
343  if ($this->getSize() !== '') {
344  $writer->xmlElement('Size', null, $this->getSize());
345  }
346 
347  // Location
348  foreach ($this->getLocationIds() as $id) {
349  $loc = $this->getLocation($id);
350  $loc->toXML($writer);
351  }
352 
353  // Requirement
354  foreach ($this->getRequirementIds() as $id) {
355  $req = $this->getRequirement($id);
356  $req->toXML($writer);
357  }
358 
359  // OrComposite
360  foreach ($this->getOrCompositeIds() as $id) {
361  $orc = $this->getOrComposite($id);
362  $orc->toXML($writer);
363  }
364 
365  // InstallationRemarks
366  if ($this->getInstallationRemarks() !== '') {
367  $writer->xmlElement(
368  'InstallationRemarks',
369  array(
370  'Language' => $this->getInstallationRemarksLanguageCode() ?: 'en'
371  ),
372  $this->getInstallationRemarks()
373  );
374  }
375 
376  // OtherPlatformRequirements
377  if ($this->getOtherPlatformRequirements() !== '') {
378  $writer->xmlElement(
379  'OtherPlatformRequirements',
380  array(
381  'Language' => $this->getOtherPlatformRequirementsLanguageCode() ?: 'en'
382  ),
384  );
385  }
386  // Duration
387  if ($this->getDuration() !== '') {
388  $writer->xmlElement('Duration', null, $this->getDuration());
389  }
390 
391  $writer->xmlEndTag('Technical');
392  }
393 
394  public static function _getId(int $a_rbac_id, int $a_obj_id): int
395  {
396  global $DIC;
397 
398  $ilDB = $DIC->database();
399 
400  $query = "SELECT meta_technical_id FROM il_meta_technical " .
401  "WHERE rbac_id = " . $ilDB->quote($a_rbac_id, 'integer') . " " .
402  "AND obj_id = " . $ilDB->quote($a_obj_id, 'integer');
403 
404  $res = $ilDB->query($query);
405  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
406  return (int) $row->meta_technical_id;
407  }
408  return 0;
409  }
410 }
ilMDLanguageItem $other_platform_requirements_language
setDuration(string $a_val)
$res
Definition: ltiservices.php:69
getOrComposite(int $a_or_composite_id)
static _getId(int $a_rbac_id, int $a_obj_id)
setOtherPlatformRequirementsLanguage(ilMDLanguageItem $lng_obj)
getOtherPlatformRequirementsLanguageCode()
setRBACId(int $a_id)
toXML(ilXmlWriter $writer)
setOtherPlatformRequirements(string $a_val)
getFormat(int $a_format_id)
catch(\Exception $e) $req
Definition: xapiproxy.php:78
xmlEndTag(string $tag)
Writes an endtag.
setSize(string $a_size)
setInstallationRemarksLanguage(ilMDLanguageItem $lng_obj)
setObjId(int $a_id)
static _getIds(int $a_rbac_id, int $a_obj_id, int $a_parent_id, string $a_parent_type, int $a_or_composite_id=0)
getLocation(int $a_location_id)
static _getIds(int $a_rbac_id, int $a_obj_id, int $a_parent_id, string $a_parent_type)
global $DIC
Definition: shib_login.php:25
getRequirement(int $a_requirement_id)
setInstallationRemarks(string $a_val)
static _getIds(int $a_rbac_id, int $a_obj_id)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:24
xmlStartTag(string $tag, ?array $attrs=null, bool $empty=false, bool $encode=true, bool $escape=true)
Writes a starttag.
static _getIds(int $a_rbac_id, int $a_obj_id, int $a_parent_id, string $a_parent_type, int $a_or_composite_id=0)
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)
ilMDLanguageItem $installation_remarks_language
setObjType(string $a_type)
string $other_platform_requirements