ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilAdvancedMDRecord.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
27{
28 private static $instances = [];
29
30 protected int $record_id;
31 protected int $global_position = 0;
32
33 protected string $import_id = '';
34 protected bool $active = false;
35 protected string $title = '';
36 protected string $description = '';
37 protected string $language_default = '';
38
42 protected array $obj_types = array();
43 protected int $parent_obj = 0;
44 protected bool $scope_enabled = false;
48 protected array $scopes = [];
49
50 protected ilDBInterface $db;
51
59 public function __construct(int $a_record_id = 0)
60 {
61 global $DIC;
62
63 $this->db = $DIC->database();
64 $this->record_id = $a_record_id;
65
66 if ($this->getRecordId()) {
67 $this->read();
68 }
69 }
70
71 public static function _getInstanceByRecordId(int $a_record_id): ilAdvancedMDRecord
72 {
73 if (isset(self::$instances[$a_record_id])) {
74 return self::$instances[$a_record_id];
75 }
76 return self::$instances[$a_record_id] = new ilAdvancedMDRecord($a_record_id);
77 }
78
83 public static function _getActiveSearchableRecords(): array
84 {
85 global $DIC;
86
87 $ilDB = $DIC['ilDB'];
88
89 $query = "SELECT DISTINCT(amr.record_id) FROM adv_md_record amr " .
90 "JOIN adv_mdf_definition amfd ON amr.record_id = amfd.record_id " .
91 "WHERE searchable = 1 AND active = 1 ";
92
93 $res = $ilDB->query($query);
94 $records = [];
95 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
96 $records[] = self::_getInstanceByRecordId((int) $row->record_id);
97 }
98 return $records;
99 }
100
101 public static function _lookupTitle(int $a_record_id): string
102 {
103 static $title_cache = array();
104
105 if (isset($title_cache[$a_record_id])) {
106 return $title_cache[$a_record_id];
107 }
108
109 global $DIC;
110
111 $ilDB = $DIC['ilDB'];
112
113 $query = "SELECT title FROM adv_md_record " .
114 "WHERE record_id = " . $ilDB->quote($a_record_id, 'integer') . " ";
115 $res = $ilDB->query($query);
116 $row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT);
117
118 return $title_cache[$a_record_id] = (string) $row->title;
119 }
120
121 public static function _lookupRecordIdByImportId(string $a_ilias_id): int
122 {
123 global $DIC;
124
125 $ilDB = $DIC['ilDB'];
126
127 $query = "SELECT record_id FROM adv_md_record " .
128 "WHERE import_id = " . $ilDB->quote($a_ilias_id, 'text') . " ";
129 $res = $ilDB->query($query);
130 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
131 return (int) $row->record_id;
132 }
133 return 0;
134 }
135
141 public static function _getAssignableObjectTypes(bool $a_include_text = false): array
142 {
143 global $DIC;
144
145 $objDefinition = $DIC['objDefinition'];
146 $lng = $DIC['lng'];
147
148 $types = array();
149 $filter = array();
150 $amet_types = $objDefinition->getAdvancedMetaDataTypes();
151
153 $filter = array_merge($filter, ilECSUtils::getPossibleRemoteTypes(false));
154 $filter[] = 'rtst';
155 }
156
157 foreach ($amet_types as $at) {
158 if (in_array($at["obj_type"], $filter)) {
159 continue;
160 }
161
162 if ($a_include_text) {
163 $text = $lng->txt("obj_" . $at["obj_type"]);
164 if ($at["sub_type"] != "") {
165 $lng->loadLanguageModule($at["obj_type"]);
166 $text .= ": " . $lng->txt($at["obj_type"] . "_" . $at["sub_type"]);
167 } else {
168 $at["sub_type"] = "-";
169 }
170 $at["text"] = $text;
171 }
172
173 $types[] = $at;
174 }
175
176 sort($types);
177 return $types;
178 }
179
184 public static function _getActivatedObjTypes(): array
185 {
186 global $DIC;
187
188 $ilDB = $DIC['ilDB'];
189
190 $query = "SELECT DISTINCT(obj_type) FROM adv_md_record_objs amo " .
191 "JOIN adv_md_record amr ON amo.record_id = amr.record_id " .
192 "WHERE active = 1 ";
193 $res = $ilDB->query($query);
194 $obj_types = [];
195 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
196 $obj_types[] = (string) $row->obj_type;
197 }
198 return $obj_types;
199 }
200
208 public static function _getRecords(): array
209 {
210 global $DIC;
211
212 $ilDB = $DIC['ilDB'];
213
214 $query = "SELECT record_id FROM adv_md_record ORDER BY gpos ";
215 $res = $ilDB->query($query);
216 $records = [];
217 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
218 $records[] = ilAdvancedMDRecord::_getInstanceByRecordId((int) $row->record_id);
219 }
220 return $records;
221 }
222
228 public static function _getAllRecordsByObjectType(): array
229 {
230 global $DIC;
231
232 $ilDB = $DIC['ilDB'];
233
234 $records = [];
235 $query = "SELECT * FROM adv_md_record_objs WHERE sub_type=" . $ilDB->quote("-", "text");
236 $res = $ilDB->query($query);
237 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
238 $records[(string) $row->obj_type][] = self::_getInstanceByRecordId((int) $row->record_id);
239 }
240 // #13359 hide ecs if not configured
242 $filter = ilECSUtils::getPossibleRemoteTypes(false);
243 $filter[] = 'rtst';
244 $records = array_diff_key($records, array_flip($filter));
245 }
246
247 return $records;
248 }
249
254 public static function _getActivatedRecordsByObjectType(
255 string $a_obj_type,
256 string $a_sub_type = "",
257 bool $a_only_optional = false
258 ): array {
259 global $DIC;
260
261 $ilDB = $DIC['ilDB'];
262
263 if ($a_sub_type == "") {
264 $a_sub_type = "-";
265 }
266
267 $records = [];
268 $query = "SELECT amro.record_id record_id FROM adv_md_record_objs amro " .
269 "JOIN adv_md_record amr ON amr.record_id = amro.record_id " .
270 "WHERE active = 1 " .
271 "AND obj_type = " . $ilDB->quote($a_obj_type, 'text') . " " .
272 "AND sub_type = " . $ilDB->quote($a_sub_type, 'text');
273
274 if ($a_only_optional) {
275 $query .= " AND optional =" . $ilDB->quote(1, 'integer');
276 }
277
278 // #16428
279 $query .= "ORDER by parent_obj DESC, record_id";
280
281 $res = $ilDB->query($query);
282 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
283 $records[] = self::_getInstanceByRecordId((int) $row->record_id);
284 }
285 return $records;
286 }
287
295 public static function _getSelectedRecordsByObject(
296 string $a_obj_type,
297 int $a_id,
298 string $a_sub_type = "",
299 bool $is_ref_id = true
300 ): array {
301 $records = array();
302
303 if ($a_sub_type == "") {
304 $a_sub_type = "-";
305 }
306
307 $a_obj_id = $is_ref_id
309 : $a_id;
310
311 // object-wide metadata configuration setting
312 $config_setting = ilContainer::_lookupContainerSetting(
313 $a_obj_id,
315 ''
316 );
317
318 $optional = array();
319 foreach (self::_getActivatedRecordsByObjectType($a_obj_type, $a_sub_type) as $record) {
320 // check scope
321 if ($is_ref_id && self::isFilteredByScope($a_id, $record->getScopes())) {
322 continue;
323 }
324 foreach ($record->getAssignedObjectTypes() as $item) {
325 if ($record->getParentObject()) {
326 // only matching local records
327 if ($record->getParentObject() != $a_obj_id) {
328 continue;
329 } // if object-wide setting is off, ignore local records
330 elseif (!$config_setting) {
331 continue;
332 }
333 }
334
335 if ($item['obj_type'] == $a_obj_type &&
336 $item['sub_type'] == $a_sub_type) {
337 if ($item['optional']) {
338 $optional[] = $record->getRecordId();
339 }
340 $records[$record->getRecordId()] = $record;
341 }
342 }
343 }
344
345 if ($optional) {
346 if (!$config_setting && !in_array($a_sub_type, array("orgu_type", "prg_type"))) { //#16925 + #17777
347 $selected = array();
348 } else {
349 $selected = self::getObjRecSelection($a_obj_id, $a_sub_type);
350 }
351 foreach ($optional as $record_id) {
352 if (!in_array($record_id, $selected)) {
353 unset($records[$record_id]);
354 }
355 }
356 }
357
358 $orderings = new ilAdvancedMDRecordObjectOrderings();
359 $records = $orderings->sortRecords($records, $a_obj_id);
360
361 return $records;
362 }
363
369 public static function isFilteredByScope($a_ref_id, array $scopes): bool
370 {
371 $tree = $GLOBALS['DIC']->repositoryTree();
372 $logger = $GLOBALS['DIC']->logger()->amet();
373
374 if (!count($scopes)) {
375 return false;
376 }
377 foreach ($scopes as $scope) {
378 $logger->debug('Comparing: ' . $a_ref_id . ' with: ' . $scope->getRefId());
379 if ($scope->getRefId() == $a_ref_id) {
380 $logger->debug('Elements are equal. No scope restrictions.');
381 return false;
382 }
383 if ($tree->getRelation($scope->getRefId(), $a_ref_id) == ilTree::RELATION_PARENT) {
384 $logger->debug('Node is child node. No scope restrictions.');
385 return false;
386 }
387 }
388 $logger->info('Scope filter matches.');
389
390 return true;
391 }
392
393 public static function _delete($a_record_id): void
394 {
395 global $DIC;
396
397 $ilDB = $DIC['ilDB'];
398
399 // Delete fields
400 foreach (ilAdvancedMDFieldDefinition::getInstancesByRecordId($a_record_id) as $field) {
401 $field->delete();
402 }
403
404 $query = "DELETE FROM adv_md_record " .
405 "WHERE record_id = " . $ilDB->quote($a_record_id, 'integer') . " ";
406 $res = $ilDB->manipulate($query);
407
408 $query = "DELETE FROM adv_md_record_objs " .
409 "WHERE record_id = " . $ilDB->quote($a_record_id, 'integer') . " ";
410 $res = $ilDB->manipulate($query);
411 }
412
413 protected function setRecordId(int $record_id): void
414 {
415 $this->record_id = $record_id;
416 }
417
421 public function setDefaultLanguage(string $language_code): void
422 {
423 $this->language_default = $language_code;
424 }
425
426 public function getDefaultLanguage(): string
427 {
428 return $this->language_default;
429 }
430
431 public function delete(): void
432 {
433 ilAdvancedMDRecord::_delete($this->getRecordId());
434 ilAdvancedMDRecordScope::deleteByRecordId($this->getRecordId());
435 }
436
437 public function enabledScope(): bool
438 {
439 return $this->scope_enabled;
440 }
441
442 public function enableScope(bool $a_stat): void
443 {
444 $this->scope_enabled = $a_stat;
445 }
446
450 public function setScopes(array $a_scopes): void
451 {
452 $this->scopes = $a_scopes;
453 }
454
459 public function getScopes(): array
460 {
461 return $this->scopes;
462 }
463
467 public function getScopeRefIds(): array
468 {
469 $ref_ids = [];
470 foreach ($this->scopes as $scope) {
471 $ref_ids[] = $scope->getRefId();
472 }
473 return $ref_ids;
474 }
475
476 public function save(): void
477 {
478 global $DIC;
479
480 $ilDB = $DIC['ilDB'];
481
482 // Save import id if given
483 $next_id = $ilDB->nextId('adv_md_record');
484
485 $query = "INSERT INTO adv_md_record (record_id,import_id,active,title,description,parent_obj,lang_default) " .
486 "VALUES(" .
487 $ilDB->quote($next_id, 'integer') . ", " .
488 $this->db->quote($this->getImportId(), 'text') . ", " .
489 $this->db->quote($this->isActive(), 'integer') . ", " .
490 $this->db->quote($this->getTitle(), 'text') . ", " .
491 $this->db->quote($this->getDescription(), 'text') . ", " .
492 $this->db->quote($this->getParentObject(), 'integer') . ", " .
493 $this->db->quote($this->getDefaultLanguage(), ilDBConstants::T_TEXT) .
494 ")";
495 $res = $ilDB->manipulate($query);
496 $this->record_id = $next_id;
497
498 if (!strlen($this->getImportId())) {
499 // set import id to default value
500 $query = "UPDATE adv_md_record " .
501 "SET import_id = " . $this->db->quote($this->generateImportId(), 'text') . " " .
502 "WHERE record_id = " . $this->db->quote($this->record_id, 'integer') . " ";
503 $res = $ilDB->manipulate($query);
504 }
505
506 foreach ($this->getAssignedObjectTypes() as $type) {
507 global $DIC;
508 $ilDB = $DIC['ilDB'];
509 $query = "INSERT INTO adv_md_record_objs (record_id,obj_type,sub_type,optional) " .
510 "VALUES( " .
511 $this->db->quote($this->getRecordId(), 'integer') . ", " .
512 $this->db->quote($type["obj_type"], 'text') . ", " .
513 $this->db->quote($type["sub_type"], 'text') . ", " .
514 $this->db->quote($type["optional"], 'integer') . " " .
515 ")";
516 $res = $ilDB->manipulate($query);
517 }
518
519 foreach ($this->getScopes() as $scope) {
520 $scope->setRecordId($this->getRecordId());
521 $scope->save();
522 }
523 }
524
525 public function update(): void
526 {
527 global $DIC;
528
529 $ilDB = $DIC['ilDB'];
530
531 $query = "UPDATE adv_md_record " .
532 "SET active = " . $this->db->quote($this->isActive(), 'integer') . ", " .
533 "title = " . $this->db->quote($this->getTitle(), 'text') . ", " .
534 "description = " . $this->db->quote($this->getDescription(), 'text') . ", " .
535 'gpos = ' . $this->db->quote($this->getGlobalPosition(), 'integer') . ', ' .
536 'lang_default = ' . $this->db->quote($this->getDefaultLanguage(), ilDBConstants::T_TEXT) . ' ' .
537 "WHERE record_id = " . $this->db->quote($this->getRecordId(), 'integer') . " ";
538 $res = $ilDB->manipulate($query);
539
540 // Delete assignments
541 $query = "DELETE FROM adv_md_record_objs " .
542 "WHERE record_id = " . $this->db->quote($this->getRecordId(), 'integer') . " ";
543 $res = $ilDB->manipulate($query);
544
545 // Insert assignments
546 foreach ($this->getAssignedObjectTypes() as $type) {
547 $query = "INSERT INTO adv_md_record_objs (record_id,obj_type,sub_type,optional) " .
548 "VALUES ( " .
549 $this->db->quote($this->getRecordId(), 'integer') . ", " .
550 $this->db->quote($type["obj_type"], 'text') . ", " .
551 $this->db->quote($type["sub_type"], 'text') . ", " .
552 $this->db->quote($type["optional"], 'integer') . " " .
553 ")";
554 $res = $ilDB->manipulate($query);
555 }
556 ilAdvancedMDRecordScope::deleteByRecordId($this->getRecordId());
557 foreach ($this->getScopes() as $scope) {
558 $scope->setRecordId($this->getRecordId());
559 $scope->save();
560 }
561 }
562
563 public function validate(): bool
564 {
565 if (!strlen($this->getTitle())) {
566 return false;
567 }
568 return true;
569 }
570
571 public function setGlobalPosition(int $position): void
572 {
573 $this->global_position = $position;
574 }
575
576 public function getGlobalPosition(): int
577 {
578 return $this->global_position;
579 }
580
581 public function getRecordId(): int
582 {
583 return $this->record_id;
584 }
585
586 public function setActive(bool $a_active): void
587 {
588 $this->active = $a_active;
589 }
590
591 public function isActive(): bool
592 {
593 return $this->active;
594 }
595
596 public function setTitle(string $a_title): void
597 {
598 $this->title = $a_title;
599 }
600
601 public function getTitle(): string
602 {
603 return $this->title;
604 }
605
606 public function setDescription(string $a_description): void
607 {
608 $this->description = $a_description;
609 }
610
611 public function getDescription(): string
612 {
613 return $this->description;
614 }
615
616 public function setImportId(string $a_id_string): void
617 {
618 $this->import_id = $a_id_string;
619 }
620
621 public function getImportId(): string
622 {
623 return $this->import_id;
624 }
625
630 public function setAssignedObjectTypes(array $a_obj_types): void
631 {
632 $this->obj_types = $a_obj_types;
633 }
634
635 public function appendAssignedObjectType(string $a_obj_type, string $a_sub_type, bool $a_optional = false): void
636 {
637 $this->obj_types[] = array(
638 "obj_type" => $a_obj_type,
639 "sub_type" => $a_sub_type,
640 "optional" => $a_optional
641 );
642 }
643
647 public function getAssignedObjectTypes(): array
648 {
649 return $this->obj_types;
650 }
651
652 public function isAssignedObjectType(string $a_obj_type, string $a_sub_type): bool
653 {
654 foreach ($this->getAssignedObjectTypes() as $t) {
655 if ($t["obj_type"] == $a_obj_type &&
656 $t["sub_type"] == $a_sub_type) {
657 return true;
658 }
659 }
660 return false;
661 }
662
663 public function setParentObject(int $a_obj_id): void
664 {
665 $this->parent_obj = $a_obj_id;
666 }
667
668 public function getParentObject(): int
669 {
670 return $this->parent_obj;
671 }
672
678 public function toXML(ilXmlWriter $writer): void
679 {
680 $writer->xmlStartTag('Record', array('active' => $this->isActive() ? 1 : 0,
681 'id' => $this->generateImportId()
682 ));
683 $writer->xmlElement('Title', null, $this->getTitle());
684 $writer->xmlElement('Description', null, $this->getDescription());
685
686 $translations = ilAdvancedMDRecordTranslations::getInstanceByRecordId($this->getRecordId());
687 $translations->toXML($writer);
688
689 foreach ($this->getAssignedObjectTypes() as $obj_type) {
690 $optional = array("optional" => $obj_type["optional"]);
691 if ($obj_type["sub_type"] == "") {
692 $writer->xmlElement('ObjectType', $optional, $obj_type["obj_type"]);
693 } else {
694 $writer->xmlElement('ObjectType', $optional, $obj_type["obj_type"] . ":" . $obj_type["sub_type"]);
695 }
696 }
697
698 // scopes
699 if (count($this->getScopeRefIds())) {
700 $writer->xmlStartTag('Scope');
701 }
702 foreach ($this->getScopeRefIds() as $ref_id) {
704 $writer->xmlElement('ScopeEntry', ['id' => 'il_' . IL_INST_ID . '_' . $type . '_' . $ref_id]);
705 }
706 if (count($this->getScopeRefIds())) {
707 $writer->xmlEndTag('Scope');
708 }
709
710 foreach (ilAdvancedMDFieldDefinition::getInstancesByRecordId($this->getRecordId()) as $definition) {
711 $definition->toXML($writer);
712 }
713 $writer->xmlEndTag('Record');
714 }
715
716 private function read(): void
717 {
718 $query = "SELECT * FROM adv_md_record " .
719 "WHERE record_id = " . $this->db->quote($this->getRecordId(), 'integer') . " ";
720 $res = $this->db->query($query);
721 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
722 $this->setImportId((string) $row->import_id);
723 $this->setActive((bool) $row->active);
724 $this->setTitle((string) $row->title);
725 $this->setDescription((string) $row->description);
726 $this->setParentObject((int) $row->parent_obj);
727 $this->setGlobalPosition((int) $row->gpos);
728 $this->setDefaultLanguage((string) $row->lang_default);
729 }
730 $query = "SELECT * FROM adv_md_record_objs " .
731 "WHERE record_id = " . $this->db->quote($this->getRecordId(), 'integer') . " ";
732 $res = $this->db->query($query);
733 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
734 $this->obj_types[] = array(
735 "obj_type" => (string) $row->obj_type,
736 "sub_type" => (string) $row->sub_type,
737 "optional" => (bool) $row->optional
738 );
739 }
740
741 $query = 'SELECT scope_id FROM adv_md_record_scope ' .
742 'WHERE record_id = ' . $this->db->quote($this->record_id, ilDBConstants::T_INTEGER);
743 $res = $this->db->query($query);
744 $this->scope_enabled = false;
745 $this->scopes = [];
746 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
747 $this->scope_enabled = true;
748 $this->scopes[] = new ilAdvancedMDRecordScope((int) $row->scope_id);
749 }
750 }
751
755 protected function generateImportId(): string
756 {
757 return 'il_' . IL_INST_ID . '_adv_md_record_' . $this->getRecordId();
758 }
759
760 public function __destruct()
761 {
762 unset(self::$instances[$this->getRecordId()]);
763 }
764
773 public static function saveObjRecSelection(
774 int $a_obj_id,
775 string $a_sub_type = "",
776 ?array $a_records = null,
777 bool $a_delete_before = true
778 ): void {
779 global $DIC;
780
781 $ilDB = $DIC['ilDB'];
782
783 if ($a_sub_type == "") {
784 $a_sub_type = "-";
785 }
786
787 if ($a_delete_before) {
788 $ilDB->manipulate("DELETE FROM adv_md_obj_rec_select WHERE " .
789 " obj_id = " . $ilDB->quote($a_obj_id, "integer") .
790 " AND sub_type = " . $ilDB->quote($a_sub_type, "text"));
791 }
792
793 if (is_array($a_records)) {
794 foreach ($a_records as $r) {
795 if ($r > 0) {
796 $ilDB->manipulate("INSERT INTO adv_md_obj_rec_select " .
797 "(obj_id, rec_id, sub_type) VALUES (" .
798 $ilDB->quote($a_obj_id, "integer") . "," .
799 $ilDB->quote($r, "integer") . "," .
800 $ilDB->quote($a_sub_type, "text") .
801 ")");
802 }
803 }
804 }
805 }
806
810 public static function deleteObjRecSelection(int $a_obj_id): void
811 {
812 global $DIC;
813
814 $ilDB = $DIC['ilDB'];
815
816 $ilDB->manipulate("DELETE FROM adv_md_obj_rec_select WHERE " .
817 " obj_id = " . $ilDB->quote($a_obj_id, "integer"));
818 }
819
826 public static function getObjRecSelection(int $a_obj_id, string $a_sub_type = ""): array
827 {
828 global $DIC;
829
830 $ilDB = $DIC['ilDB'];
831
832 if ($a_sub_type == "") {
833 $a_sub_type = "-";
834 }
835
836 $recs = array();
837 $set = $ilDB->query(
838 $r = "SELECT * FROM adv_md_obj_rec_select " .
839 " WHERE obj_id = " . $ilDB->quote($a_obj_id, "integer") .
840 " AND sub_type = " . $ilDB->quote($a_sub_type, "text")
841 );
842 while ($rec = $ilDB->fetchAssoc($set)) {
843 $recs[] = (int) $rec["rec_id"];
844 }
845 return $recs;
846 }
847
848 public function _clone(array &$a_fields_map, ?int $a_parent_obj_id = null): ilAdvancedMDRecord
849 {
850 $new_obj = new self();
851 $new_obj->setActive($this->isActive());
852 $new_obj->setTitle($this->getTitle());
853 $new_obj->setDescription($this->getDescription());
854 $new_obj->setParentObject($a_parent_obj_id
855 ?: $this->getParentObject());
856 $new_obj->setAssignedObjectTypes($this->getAssignedObjectTypes());
857 $new_obj->setDefaultLanguage($this->getDefaultLanguage());
858 $new_obj->save();
859
860 foreach (ilAdvancedMDFieldDefinition::getInstancesByRecordId($this->getRecordId()) as $definition) {
861 $new_def = $definition->_clone($new_obj->getRecordId());
862 $a_fields_map[$definition->getFieldId()] = $new_def->getFieldId();
863 }
864
865 $record_translation = ilAdvancedMDRecordTranslations::getInstanceByRecordId($this->getRecordId());
866 $record_translation->cloneRecord($new_obj->getRecordId());
867
868 return $new_obj;
869 }
870
871 public static function getSharedRecords(int $a_obj1_id, int $a_obj2_id, string $a_sub_type = "-"): array
872 {
873 $obj_type = ilObject::_lookupType($a_obj1_id);
874 $sel = array_intersect(
875 ilAdvancedMDRecord::getObjRecSelection($a_obj1_id, $a_sub_type),
876 ilAdvancedMDRecord::getObjRecSelection($a_obj2_id, $a_sub_type)
877 );
878
879 $res = array();
880
881 foreach (self::_getRecords() as $record) {
882 // local records cannot be shared
883 if ($record->getParentObject()) {
884 continue;
885 }
886
887 // :TODO: inactive records can be ignored?
888 if (!$record->isActive()) {
889 continue;
890 }
891
892 // parse assigned types
893 foreach ($record->getAssignedObjectTypes() as $item) {
894 if ($item["obj_type"] == $obj_type &&
895 $item["sub_type"] == $a_sub_type) {
896 // mandatory
897 if (!$item["optional"]) {
898 $res[] = $record->getRecordId();
899 } // optional
900 elseif (in_array($record->getRecordId(), $sel)) {
901 $res[] = $record->getRecordId();
902 }
903 }
904 }
905 }
906
907 return $res;
908 }
909}
static getInstancesByRecordId( $a_record_id, $a_only_searchable=false, string $language='')
Get definitions by record id.
Scope restrictions for advanced md records.
static deleteByRecordId(int $a_record_id)
static _lookupTitle(int $a_record_id)
isAssignedObjectType(string $a_obj_type, string $a_sub_type)
static getSharedRecords(int $a_obj1_id, int $a_obj2_id, string $a_sub_type="-")
setImportId(string $a_id_string)
static deleteObjRecSelection(int $a_obj_id)
Delete repository object record selection.
setDescription(string $a_description)
toXML(ilXmlWriter $writer)
To Xml.
generateImportId()
generate unique record id
setAssignedObjectTypes(array $a_obj_types)
static _getAllRecordsByObjectType()
Get records by obj_type Note: this returns only records with no sub types!
static _getInstanceByRecordId(int $a_record_id)
static _getAssignableObjectTypes(bool $a_include_text=false)
Get assignable object type @access public.
static _getActivatedObjTypes()
get activated obj types
static getObjRecSelection(int $a_obj_id, string $a_sub_type="")
Get repository object record selection.
static _delete($a_record_id)
setDefaultLanguage(string $language_code)
static _getActivatedRecordsByObjectType(string $a_obj_type, string $a_sub_type="", bool $a_only_optional=false)
Get activated records by object type.
static _getSelectedRecordsByObject(string $a_obj_type, int $a_id, string $a_sub_type="", bool $is_ref_id=true)
static _getRecords()
Get records @access public.
_clone(array &$a_fields_map, ?int $a_parent_obj_id=null)
__construct(int $a_record_id=0)
Singleton constructor To create an array of new records (without saving them) call the constructor di...
appendAssignedObjectType(string $a_obj_type, string $a_sub_type, bool $a_optional=false)
static saveObjRecSelection(int $a_obj_id, string $a_sub_type="", ?array $a_records=null, bool $a_delete_before=true)
Save repository object record selection.
static isFilteredByScope($a_ref_id, array $scopes)
Check if a given ref id is not filtered by scope restriction.
static _lookupRecordIdByImportId(string $a_ilias_id)
static _getActiveSearchableRecords()
Get active searchable records.
static _lookupContainerSetting(int $a_id, string $a_keyword, ?string $a_default_value=null)
static ecsConfigured()
Checks if an ecs server is configured.
static getPossibleRemoteTypes(bool $a_with_captions=false)
Get all possible remote object types.
static _lookupType(int $id, bool $reference=false)
static _lookupObjId(int $ref_id)
const RELATION_PARENT
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.
const IL_INST_ID
Definition: constants.php:40
Interface ilDBInterface.
$ref_id
Definition: ltiauth.php:66
$scope
Definition: ltiregstart.php:51
$res
Definition: ltiservices.php:69
$scopes
Definition: ltitoken.php:96
global $lng
Definition: privfeed.php:31
global $DIC
Definition: shib_login.php:26
$GLOBALS["DIC"]
Definition: wac.php:54