ILIAS  release_8 Revision v8.24
class.ilMDGeneral.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
27class ilMDGeneral extends ilMDBase
28{
30
31 private string $coverage = '';
32 private string $structure = '';
33 private string $title = '';
35
39 public function getPossibleSubelements(): array
40 {
41 $subs['Keyword'] = 'meta_keyword';
42 $subs['Language'] = 'meta_language';
43 $subs['Identifier'] = 'meta_identifier';
44 $subs['Description'] = 'meta_description';
45
46 return $subs;
47 }
48
49 // Subelements (Identifier, Language, Description, Keyword)
50
54 public function getIdentifierIds(): array
55 {
56 return ilMDIdentifier::_getIds($this->getRBACId(), $this->getObjId(), (int) $this->getMetaId(), 'meta_general');
57 }
58
59 public function getIdentifier(int $a_identifier_id): ?ilMDIdentifier
60 {
61 if (!$a_identifier_id) {
62 return null;
63 }
64 $ide = new ilMDIdentifier();
65 $ide->setMetaId($a_identifier_id);
66
67 return $ide;
68 }
69
70 public function addIdentifier(): ilMDIdentifier
71 {
72 $ide = new ilMDIdentifier($this->getRBACId(), $this->getObjId(), $this->getObjType());
73 $ide->setParentId($this->getMetaId());
74 $ide->setParentType('meta_general');
75
76 return $ide;
77 }
78
82 public function getLanguageIds(): array
83 {
84 return ilMDLanguage::_getIds($this->getRBACId(), $this->getObjId(), (int) $this->getMetaId(), 'meta_general');
85 }
86
87 public function getLanguage(int $a_language_id): ?ilMDLanguage
88 {
89 if (!$a_language_id) {
90 return null;
91 }
92 $lan = new ilMDLanguage();
93 $lan->setMetaId($a_language_id);
94
95 return $lan;
96 }
97
98 public function addLanguage(): ilMDLanguage
99 {
100 $lan = new ilMDLanguage($this->getRBACId(), $this->getObjId(), $this->getObjType());
101 $lan->setParentId($this->getMetaId());
102 $lan->setParentType('meta_general');
103
104 return $lan;
105 }
106
110 public function getDescriptionIds(): array
111 {
112 return ilMDDescription::_getIds($this->getRBACId(), $this->getObjId(), (int) $this->getMetaId(), 'meta_general');
113 }
114
115 public function getDescription(int $a_description_id): ?ilMDDescription
116 {
117 if (!$a_description_id) {
118 return null;
119 }
120 $des = new ilMDDescription();
121 $des->setMetaId($a_description_id);
122
123 return $des;
124 }
125
127 {
128 $des = new ilMDDescription($this->getRBACId(), $this->getObjId(), $this->getObjType());
129 $des->setParentId($this->getMetaId());
130 $des->setParentType('meta_general');
131
132 return $des;
133 }
134
138 public function getKeywordIds(): array
139 {
140 return ilMDKeyword::_getIds($this->getRBACId(), $this->getObjId(), (int) $this->getMetaId(), 'meta_general');
141 }
142
143 public function getKeyword(int $a_keyword_id): ?ilMDKeyword
144 {
145 if (!$a_keyword_id) {
146 return null;
147 }
148 $key = new ilMDKeyword();
149 $key->setMetaId($a_keyword_id);
150
151 return $key;
152 }
153
154 public function addKeyword(): ilMDKeyword
155 {
156 $key = new ilMDKeyword($this->getRBACId(), $this->getObjId(), $this->getObjType());
157 $key->setParentId($this->getMetaId());
158 $key->setParentType('meta_general');
159
160 return $key;
161 }
162
163 // SET/GET
164 public function setStructure(string $a_structure): bool
165 {
166 switch ($a_structure) {
167 case 'Atomic':
168 case 'Collection':
169 case 'Networked':
170 case 'Hierarchical':
171 case 'Linear':
172 $this->structure = $a_structure;
173 return true;
174
175 default:
176 return false;
177 }
178 }
179
180 public function getStructure(): string
181 {
182 return $this->structure;
183 }
184
185 public function setTitle(string $a_title): void
186 {
187 $this->title = $a_title;
188 }
189
190 public function getTitle(): string
191 {
192 return $this->title;
193 }
194
195 public function setTitleLanguage(ilMDLanguageItem $lng_obj): void
196 {
197 $this->title_language = $lng_obj;
198 }
199
201 {
202 return is_object($this->title_language) ? $this->title_language : null;
203 }
204
205 public function getTitleLanguageCode(): string
206 {
207 return is_object($this->title_language) ? $this->title_language->getLanguageCode() : '';
208 }
209
210 public function setCoverage(string $a_coverage): void
211 {
212 $this->coverage = $a_coverage;
213 }
214
215 public function getCoverage(): string
216 {
217 return $this->coverage;
218 }
219
220 public function setCoverageLanguage(ilMDLanguageItem $lng_obj): void
221 {
222 $this->coverage_language = $lng_obj;
223 }
224
226 {
227 return is_object($this->coverage_language) ? $this->coverage_language : null;
228 }
229
230 public function getCoverageLanguageCode(): string
231 {
232 return is_object($this->coverage_language) ? $this->coverage_language->getLanguageCode() : '';
233 }
234
235 public function save(): int
236 {
237 $fields = $this->__getFields();
238 $fields['meta_general_id'] = array('integer', $next_id = $this->db->nextId('il_meta_general'));
239
240 $this->log->debug("Insert General " . print_r($fields, true));
241 $this->log->logStack(ilLogLevel::DEBUG);
242 //ilUtil::printBacktrace(10);
243
244 if ($this->db->insert('il_meta_general', $fields)) {
245 $this->setMetaId($next_id);
246 return $this->getMetaId();
247 }
248 return 0;
249 }
250
251 public function update(): bool
252 {
253 return $this->getMetaId() && $this->db->update(
254 'il_meta_general',
255 $this->__getFields(),
256 array("meta_general_id" => array('integer', $this->getMetaId()))
257 );
258 }
259
260 public function delete(): bool
261 {
262 if (!$this->getMetaId()) {
263 return false;
264 }
265 // Identifier
266 foreach ($this->getIdentifierIds() as $id) {
267 $ide = $this->getIdentifier($id);
268 $ide->delete();
269 }
270
271 // Language
272 foreach ($this->getLanguageIds() as $id) {
273 $lan = $this->getLanguage($id);
274 $lan->delete();
275 }
276
277 // Description
278 foreach ($this->getDescriptionIds() as $id) {
279 $des = $this->getDescription($id);
280 $des->delete();
281 }
282
283 // Keyword
284 foreach ($this->getKeywordIds() as $id) {
285 $key = $this->getKeyword($id);
286 $key->delete();
287 }
288
289 if ($this->getMetaId()) {
290 $query = "DELETE FROM il_meta_general " .
291 "WHERE meta_general_id = " . $this->db->quote($this->getMetaId(), 'integer');
292 $res = $this->db->manipulate($query);
293 return true;
294 }
295
296 return false;
297 }
298
302 public function __getFields(): array
303 {
304 return array(
305 'rbac_id' => array('integer', $this->getRBACId()),
306 'obj_id' => array('integer', $this->getObjId()),
307 'obj_type' => array('text', $this->getObjType()),
308 'general_structure' => array('text', $this->getStructure()),
309 'title' => array('text', $this->getTitle()),
310 'title_language' => array('text', $this->getTitleLanguageCode()),
311 'coverage' => array('text', $this->getCoverage()),
312 'coverage_language' => array('text', $this->getCoverageLanguageCode())
313 );
314 }
315
316 public function read(): bool
317 {
318 if ($this->getMetaId()) {
319 $query = "SELECT * FROM il_meta_general " .
320 "WHERE meta_general_id = " . $this->db->quote($this->getMetaId(), 'integer');
321
322 $res = $this->db->query($query);
323 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
324 $this->setRBACId((int) $row->rbac_id);
325 $this->setObjId((int) $row->obj_id);
326 $this->setObjType((string) $row->obj_type);
327 $this->setStructure((string) $row->general_structure);
328 $this->setTitle((string) $row->title);
329 $this->setTitleLanguage(new ilMDLanguageItem($row->title_language ?? ''));
330 $this->setCoverage((string) $row->coverage);
331 $this->setCoverageLanguage(new ilMDLanguageItem($row->coverage_language ?? ''));
332 }
333 }
334 return true;
335 }
336
337 public function toXML(ilXmlWriter $writer): void
338 {
339 $writer->xmlStartTag('General', array(
340 'Structure' => $this->getStructure() ?: 'Atomic'
341 ));
342
343 // Identifier
344 $first = true;
345 $identifiers = $this->getIdentifierIds();
346 foreach ($identifiers as $id) {
347 $ide = $this->getIdentifier($id);
348 $ide->setExportMode($this->getExportMode());
349 $ide->toXML($writer);
350 $first = false;
351 }
352 if (!count($identifiers)) {
353 $ide = new ilMDIdentifier(
354 $this->getRBACId(),
355 $this->getObjId(),
356 $this->getObjType()
357 ); // added type, alex, 31 Oct 2007
358 $ide->setExportMode(true);
359 $ide->toXML($writer);
360 }
361
362 // Title
363 $writer->xmlElement(
364 'Title',
365 array(
366 'Language' => $this->getTitleLanguageCode() ?: 'en'
367 ),
368 $this->getTitle()
369 );
370
371 // Language
372 $languages = $this->getLanguageIds();
373 foreach ($languages as $id) {
374 $lan = $this->getLanguage($id);
375 $lan->toXML($writer);
376 }
377
378 // Description
379 $descriptions = $this->getDescriptionIds();
380 foreach ($descriptions as $id) {
381 $des = $this->getDescription($id);
382 $des->toXML($writer);
383 }
384 if (!count($descriptions)) {
385 // Default
386
387 $des = new ilMDDescription($this->getRBACId(), $this->getObjId());
388 $des->toXML($writer);
389 }
390
391 // Keyword
392 $keywords = $this->getKeywordIds();
393 foreach ($keywords as $id) {
394 $key = $this->getKeyword($id);
395 $key->toXML($writer);
396 }
397 if (!count($keywords)) {
398 // Default
399
400 $key = new ilMDKeyword($this->getRBACId(), $this->getObjId());
401 $key->toXML($writer);
402 }
403
404 // Copverage
405 if ($this->getCoverage() !== '') {
406 $writer->xmlElement(
407 'Coverage',
408 array(
409 'Language' => $this->getCoverageLanguageCode() ?: 'en'
410 ),
411 $this->getCoverage()
412 );
413 }
414 $writer->xmlEndTag('General');
415 }
416
417 // STATIC
418 public static function _getId(int $a_rbac_id, int $a_obj_id): int
419 {
420 global $DIC;
421
422 $ilDB = $DIC->database();
423
424 $query = "SELECT meta_general_id FROM il_meta_general " .
425 "WHERE rbac_id = " . $ilDB->quote($a_rbac_id, 'integer') . " " .
426 "AND obj_id = " . $ilDB->quote($a_obj_id, 'integer');
427
428 $res = $ilDB->query($query);
429 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
430 return (int) $row->meta_general_id;
431 }
432 return 0;
433 }
434}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
setObjType(string $a_type)
setObjId(int $a_id)
setMetaId(int $a_meta_id, bool $a_read_data=true)
setRBACId(int $a_id)
static _getIds(int $a_rbac_id, int $a_obj_id, int $a_parent_id, string $a_parent_type)
setTitle(string $a_title)
ilMDLanguageItem $coverage_language
getIdentifier(int $a_identifier_id)
ilMDLanguageItem $title_language
setCoverageLanguage(ilMDLanguageItem $lng_obj)
setStructure(string $a_structure)
getLanguage(int $a_language_id)
static _getId(int $a_rbac_id, int $a_obj_id)
setTitleLanguage(ilMDLanguageItem $lng_obj)
setCoverage(string $a_coverage)
getKeyword(int $a_keyword_id)
toXML(ilXmlWriter $writer)
getDescription(int $a_description_id)
static _getIds(int $a_rbac_id, int $a_obj_id, int $a_parent_id, string $a_parent_type)
static _getIds(int $a_rbac_id, int $a_obj_id, int $a_parent_id, string $a_parent_type)
static _getIds(int $a_rbac_id, int $a_obj_id, int $a_parent_id, string $a_parent_type)
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)
xmlEndTag(string $tag)
Writes an endtag.
xmlStartTag(string $tag, ?array $attrs=null, bool $empty=false, bool $encode=true, bool $escape=true)
Writes a starttag.
global $DIC
Definition: feed.php:28
$res
Definition: ltiservices.php:69
string $key
Consumer key/client ID value.
Definition: System.php:193
$query