ILIAS  release_8 Revision v8.23
class.ilMDLocation.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
26 class ilMDLocation extends ilMDBase
27 {
28  private string $location = '';
29  private string $location_type = '';
30 
31  // SET/GET
32  public function setLocation(string $a_location): void
33  {
34  $this->location = $a_location;
35  }
36 
37  public function getLocation(): string
38  {
39  return $this->location;
40  }
41 
42  public function setLocationType(string $a_location_type): void
43  {
44  $this->location_type = $a_location_type;
45  }
46 
47  public function getLocationType(): string
48  {
49  return $this->location_type;
50  }
51 
52  public function save(): int
53  {
54  $fields = $this->__getFields();
55  $fields['meta_location_id'] = array('integer', $next_id = $this->db->nextId('il_meta_location'));
56 
57  if ($this->db->insert('il_meta_location', $fields)) {
58  $this->setMetaId($next_id);
59  return $this->getMetaId();
60  }
61  return 0;
62  }
63 
64  public function update(): bool
65  {
66  return $this->getMetaId() && $this->db->update(
67  'il_meta_location',
68  $this->__getFields(),
69  array("meta_location_id" => array('integer', $this->getMetaId()))
70  );
71  }
72 
73  public function delete(): bool
74  {
75  if ($this->getMetaId()) {
76  $query = "DELETE FROM il_meta_location " .
77  "WHERE meta_location_id = " . $this->db->quote($this->getMetaId(), 'integer');
78  $res = $this->db->manipulate($query);
79 
80  return true;
81  }
82  return false;
83  }
84 
88  public function __getFields(): array
89  {
90  return array(
91  'rbac_id' => array('integer', $this->getRBACId()),
92  'obj_id' => array('integer', $this->getObjId()),
93  'obj_type' => array('text', $this->getObjType()),
94  'parent_type' => array('text', $this->getParentType()),
95  'parent_id' => array('integer', $this->getParentId()),
96  'location' => array('text', $this->getLocation()),
97  'location_type' => array('text', $this->getLocationType())
98  );
99  }
100 
101  public function read(): bool
102  {
103  if ($this->getMetaId()) {
104  $query = "SELECT * FROM il_meta_location " .
105  "WHERE meta_location_id = " . $this->db->quote($this->getMetaId(), 'integer');
106 
107  $res = $this->db->query($query);
108  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
109  $this->setRBACId((int) $row->rbac_id);
110  $this->setObjId((int) $row->obj_id);
111  $this->setObjType($row->obj_type);
112  $this->setParentId((int) $row->parent_id);
113  $this->setParentType($row->parent_type);
114  $this->setLocation($row->location ?? '');
115  $this->setLocationType($row->location_type ?? '');
116  }
117  }
118  return true;
119  }
120 
121  public function toXML(ilXmlWriter $writer): void
122  {
123  $writer->xmlElement(
124  'Location',
125  array(
126  'Type' => $this->getLocationType() ?: 'LocalFile'
127  ),
128  $this->getLocation()
129  );
130  }
131 
132  // STATIC
133 
137  public static function _getIds(int $a_rbac_id, int $a_obj_id, int $a_parent_id, string $a_parent_type): array
138  {
139  global $DIC;
140 
141  $ilDB = $DIC->database();
142 
143  $query = "SELECT meta_location_id FROM il_meta_location " .
144  "WHERE rbac_id = " . $ilDB->quote($a_rbac_id, 'integer') . " " .
145  "AND obj_id = " . $ilDB->quote($a_obj_id, 'integer') . " " .
146  "AND parent_id = " . $ilDB->quote($a_parent_id, 'integer') . " " .
147  "AND parent_type = " . $ilDB->quote($a_parent_type, 'text');
148 
149  $res = $ilDB->query($query);
150  $ids = [];
151  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
152  $ids[] = (int) $row->meta_location_id;
153  }
154  return $ids;
155  }
156 }
$res
Definition: ltiservices.php:69
setLocationType(string $a_location_type)
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)
global $DIC
Definition: feed.php:28
setObjId(int $a_id)
static _getIds(int $a_rbac_id, int $a_obj_id, int $a_parent_id, string $a_parent_type)
$query
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)
setLocation(string $a_location)