ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilMDAnnotation.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
26 class ilMDAnnotation extends ilMDBase
27 {
28  private string $entity = '';
29  private string $date = '';
30  private string $description = '';
32 
33  // SET/GET
34  public function setEntity(string $a_entity): void
35  {
36  $this->entity = $a_entity;
37  }
38 
39  public function getEntity(): string
40  {
41  return $this->entity;
42  }
43 
44  public function setDate(string $a_date): void
45  {
46  $this->date = $a_date;
47  }
48 
49  public function getDate(): string
50  {
51  return $this->date;
52  }
53 
54  public function setDescription(string $a_desc): void
55  {
56  $this->description = $a_desc;
57  }
58 
59  public function getDescription(): string
60  {
61  return $this->description;
62  }
63 
64  public function setDescriptionLanguage(ilMDLanguageItem $lng_obj): void
65  {
66  $this->description_language = $lng_obj;
67  }
68 
70  {
72  }
73 
74  public function getDescriptionLanguageCode(): string
75  {
76  if (is_object($this->description_language)) {
77  return $this->description_language->getLanguageCode();
78  }
79  return '';
80  }
81 
82  public function save(): int
83  {
84  $fields = $this->__getFields();
85  $fields['meta_annotation_id'] = array('integer', $next_id = $this->db->nextId('il_meta_annotation'));
86 
87  if ($this->db->insert('il_meta_annotation', $fields)) {
88  $this->setMetaId($next_id);
89  return $this->getMetaId();
90  }
91  return 0;
92  }
93 
94  public function update(): bool
95  {
96  return $this->getMetaId() && $this->db->update(
97  'il_meta_annotation',
98  $this->__getFields(),
99  array("meta_annotation_id" => array('integer', $this->getMetaId()))
100  );
101  }
102 
103  public function delete(): bool
104  {
105  if ($this->getMetaId()) {
106  $query = "DELETE FROM il_meta_annotation " .
107  "WHERE meta_annotation_id = " . $this->db->quote($this->getMetaId(), 'integer');
108  $res = $this->db->manipulate($query);
109 
110  return true;
111  }
112  return false;
113  }
114 
118  public function __getFields(): array
119  {
120  return array(
121  'rbac_id' => array('integer', $this->getRBACId()),
122  'obj_id' => array('integer', $this->getObjId()),
123  'obj_type' => array('text', $this->getObjType()),
124  'entity' => array('clob', $this->getEntity()),
125  'a_date' => array('clob', $this->getDate()),
126  'description' => array('clob', $this->getDescription()),
127  'description_language' => array('text', $this->getDescriptionLanguageCode())
128  );
129  }
130 
131  public function read(): bool
132  {
133  if ($this->getMetaId()) {
134  $query = "SELECT * FROM il_meta_annotation " .
135  "WHERE meta_annotation_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->setEntity($row->entity ?? '');
143  $this->setDate($row->a_date ?? '');
144  $this->setDescription($row->description ?? '');
145  $this->description_language = new ilMDLanguageItem($row->description_language ?? '');
146  }
147  }
148  return true;
149  }
150 
151  public function toXML(ilXmlWriter $writer): void
152  {
153  $writer->xmlStartTag('Annotation');
154  $writer->xmlElement('Entity', null, $this->getEntity());
155  $writer->xmlElement('Date', null, $this->getDate());
156  $writer->xmlElement(
157  'Description',
158  array(
159  'Language' => $this->getDescriptionLanguageCode() ?: 'en'
160  ),
161  $this->getDescription()
162  );
163  $writer->xmlEndTag('Annotation');
164  }
165 
166  // STATIC
167 
171  public static function _getIds(int $a_rbac_id, int $a_obj_id): array
172  {
173  global $DIC;
174 
175  $ilDB = $DIC['ilDB'];
176 
177  $query = "SELECT meta_annotation_id FROM il_meta_annotation " .
178  "WHERE rbac_id = " . $ilDB->quote($a_rbac_id, 'integer') . " " .
179  "AND obj_id = " . $ilDB->quote($a_obj_id, 'integer');
180 
181  $res = $ilDB->query($query);
182  $ids = [];
183  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
184  $ids[] = (int) $row->meta_annotation_id;
185  }
186  return $ids;
187  }
188 }
$res
Definition: ltiservices.php:69
static _getIds(int $a_rbac_id, int $a_obj_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ilMDLanguageItem $description_language
setEntity(string $a_entity)
setRBACId(int $a_id)
xmlEndTag(string $tag)
Writes an endtag.
global $DIC
Definition: feed.php:28
setObjId(int $a_id)
setDate(string $a_date)
$query
toXML(ilXmlWriter $writer)
setDescription(string $a_desc)
setDescriptionLanguage(ilMDLanguageItem $lng_obj)
xmlStartTag(string $tag, ?array $attrs=null, bool $empty=false, bool $encode=true, bool $escape=true)
Writes a starttag.
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)