ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilAdvancedMDRecord.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
6 
13 {
14  private static $instances = [];
15 
16  protected int $record_id;
17  protected int $global_position = 0;
18 
19  protected string $import_id = '';
20  protected bool $active = false;
21  protected string $title = '';
22  protected string $description = '';
23  protected string $language_default = '';
24 
28  protected array $obj_types = array();
29  protected int $parent_obj = 0;
30  protected bool $scope_enabled = false;
34  protected array $scopes = [];
35 
36  protected ilDBInterface $db;
37 
45  public function __construct(int $a_record_id = 0)
46  {
47  global $DIC;
48 
49  $this->db = $DIC->database();
50  $this->record_id = $a_record_id;
51 
52  if ($this->getRecordId()) {
53  $this->read();
54  }
55  }
56 
57  public static function _getInstanceByRecordId(int $a_record_id): ilAdvancedMDRecord
58  {
59  if (isset(self::$instances[$a_record_id])) {
60  return self::$instances[$a_record_id];
61  }
62  return self::$instances[$a_record_id] = new ilAdvancedMDRecord($a_record_id);
63  }
64 
69  public static function _getActiveSearchableRecords(): array
70  {
71  global $DIC;
72 
73  $ilDB = $DIC['ilDB'];
74 
75  $query = "SELECT DISTINCT(amr.record_id) FROM adv_md_record amr " .
76  "JOIN adv_mdf_definition amfd ON amr.record_id = amfd.record_id " .
77  "WHERE searchable = 1 AND active = 1 ";
78 
79  $res = $ilDB->query($query);
80  $records = [];
81  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
82  $records[] = self::_getInstanceByRecordId((int) $row->record_id);
83  }
84  return $records;
85  }
86 
87  public static function _lookupTitle(int $a_record_id): string
88  {
89  static $title_cache = array();
90 
91  if (isset($title_cache[$a_record_id])) {
92  return $title_cache[$a_record_id];
93  }
94 
95  global $DIC;
96 
97  $ilDB = $DIC['ilDB'];
98 
99  $query = "SELECT title FROM adv_md_record " .
100  "WHERE record_id = " . $ilDB->quote($a_record_id, 'integer') . " ";
101  $res = $ilDB->query($query);
102  $row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT);
103 
104  return $title_cache[$a_record_id] = (string) $row->title;
105  }
106 
107  public static function _lookupRecordIdByImportId(string $a_ilias_id): int
108  {
109  global $DIC;
110 
111  $ilDB = $DIC['ilDB'];
112 
113  $query = "SELECT record_id FROM adv_md_record " .
114  "WHERE import_id = " . $ilDB->quote($a_ilias_id, 'text') . " ";
115  $res = $ilDB->query($query);
116  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
117  return (int) $row->record_id;
118  }
119  return 0;
120  }
121 
127  public static function _getAssignableObjectTypes(bool $a_include_text = false): array
128  {
129  global $DIC;
130 
131  $objDefinition = $DIC['objDefinition'];
132  $lng = $DIC['lng'];
133 
134  $types = array();
135  $filter = array();
136  $amet_types = $objDefinition->getAdvancedMetaDataTypes();
137 
139  $filter = array_merge($filter, ilECSUtils::getPossibleRemoteTypes(false));
140  $filter[] = 'rtst';
141  }
142 
143  foreach ($amet_types as $at) {
144  if (in_array($at["obj_type"], $filter)) {
145  continue;
146  }
147 
148  if ($a_include_text) {
149  $text = $lng->txt("obj_" . $at["obj_type"]);
150  if ($at["sub_type"] != "") {
151  $lng->loadLanguageModule($at["obj_type"]);
152  $text .= ": " . $lng->txt($at["obj_type"] . "_" . $at["sub_type"]);
153  } else {
154  $at["sub_type"] = "-";
155  }
156  $at["text"] = $text;
157  }
158 
159  $types[] = $at;
160  }
161 
162  sort($types);
163  return $types;
164  }
165 
170  public static function _getActivatedObjTypes(): array
171  {
172  global $DIC;
173 
174  $ilDB = $DIC['ilDB'];
175 
176  $query = "SELECT DISTINCT(obj_type) FROM adv_md_record_objs amo " .
177  "JOIN adv_md_record amr ON amo.record_id = amr.record_id " .
178  "WHERE active = 1 ";
179  $res = $ilDB->query($query);
180  $obj_types = [];
181  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
182  $obj_types[] = (string) $row->obj_type;
183  }
184  return $obj_types;
185  }
186 
194  public static function _getRecords(): array
195  {
196  global $DIC;
197 
198  $ilDB = $DIC['ilDB'];
199 
200  $query = "SELECT record_id FROM adv_md_record ORDER BY gpos ";
201  $res = $ilDB->query($query);
202  $records = [];
203  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
204  $records[] = ilAdvancedMDRecord::_getInstanceByRecordId((int) $row->record_id);
205  }
206  return $records;
207  }
208 
214  public static function _getAllRecordsByObjectType(): array
215  {
216  global $DIC;
217 
218  $ilDB = $DIC['ilDB'];
219 
220  $records = [];
221  $query = "SELECT * FROM adv_md_record_objs WHERE sub_type=" . $ilDB->quote("-", "text");
222  $res = $ilDB->query($query);
223  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
224  $records[(string) $row->obj_type][] = self::_getInstanceByRecordId((int) $row->record_id);
225  }
226  // #13359 hide ecs if not configured
228  $filter = ilECSUtils::getPossibleRemoteTypes(false);
229  $filter[] = 'rtst';
230  $records = array_diff_key($records, array_flip($filter));
231  }
232 
233  return $records;
234  }
235 
240  public static function _getActivatedRecordsByObjectType(
241  string $a_obj_type,
242  string $a_sub_type = "",
243  bool $a_only_optional = false
244  ): array {
245  global $DIC;
246 
247  $ilDB = $DIC['ilDB'];
248 
249  if ($a_sub_type == "") {
250  $a_sub_type = "-";
251  }
252 
253  $records = [];
254  $query = "SELECT amro.record_id record_id FROM adv_md_record_objs amro " .
255  "JOIN adv_md_record amr ON amr.record_id = amro.record_id " .
256  "WHERE active = 1 " .
257  "AND obj_type = " . $ilDB->quote($a_obj_type, 'text') . " " .
258  "AND sub_type = " . $ilDB->quote($a_sub_type, 'text');
259 
260  if ($a_only_optional) {
261  $query .= " AND optional =" . $ilDB->quote(1, 'integer');
262  }
263 
264  // #16428
265  $query .= "ORDER by parent_obj DESC, record_id";
266 
267  $res = $ilDB->query($query);
268  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
269  $records[] = self::_getInstanceByRecordId((int) $row->record_id);
270  }
271  return $records;
272  }
273 
281  public static function _getSelectedRecordsByObject(
282  string $a_obj_type,
283  int $a_id,
284  string $a_sub_type = "",
285  bool $is_ref_id = true
286  ): array {
287  $records = array();
288 
289  if ($a_sub_type == "") {
290  $a_sub_type = "-";
291  }
292 
293  $a_obj_id = $is_ref_id
294  ? ilObject::_lookupObjId($a_id)
295  : $a_id;
296 
297  // object-wide metadata configuration setting
298  $config_setting = ilContainer::_lookupContainerSetting(
299  $a_obj_id,
301  ''
302  );
303 
304  $optional = array();
305  foreach (self::_getActivatedRecordsByObjectType($a_obj_type, $a_sub_type) as $record) {
306  // check scope
307  if ($is_ref_id && self::isFilteredByScope($a_id, $record->getScopes())) {
308  continue;
309  }
310  foreach ($record->getAssignedObjectTypes() as $item) {
311  if ($record->getParentObject()) {
312  // only matching local records
313  if ($record->getParentObject() != $a_obj_id) {
314  continue;
315  } // if object-wide setting is off, ignore local records
316  elseif (!$config_setting) {
317  continue;
318  }
319  }
320 
321  if ($item['obj_type'] == $a_obj_type &&
322  $item['sub_type'] == $a_sub_type) {
323  if ($item['optional']) {
324  $optional[] = $record->getRecordId();
325  }
326  $records[$record->getRecordId()] = $record;
327  }
328  }
329  }
330 
331  if ($optional) {
332  if (!$config_setting && !in_array($a_sub_type, array("orgu_type", "prg_type"))) { //#16925 + #17777
333  $selected = array();
334  } else {
335  $selected = self::getObjRecSelection($a_obj_id, $a_sub_type);
336  }
337  foreach ($optional as $record_id) {
338  if (!in_array($record_id, $selected)) {
339  unset($records[$record_id]);
340  }
341  }
342  }
343 
344  $orderings = new ilAdvancedMDRecordObjectOrderings();
345  $records = $orderings->sortRecords($records, $a_obj_id);
346 
347  return $records;
348  }
349 
355  public static function isFilteredByScope($a_ref_id, array $scopes): bool
356  {
357  $tree = $GLOBALS['DIC']->repositoryTree();
358  $logger = $GLOBALS['DIC']->logger()->amet();
359 
360  if (!count($scopes)) {
361  return false;
362  }
363  foreach ($scopes as $scope) {
364  $logger->debug('Comparing: ' . $a_ref_id . ' with: ' . $scope->getRefId());
365  if ($scope->getRefId() == $a_ref_id) {
366  $logger->debug('Elements are equal. No scope restrictions.');
367  return false;
368  }
369  if ($tree->getRelation($scope->getRefId(), $a_ref_id) == ilTree::RELATION_PARENT) {
370  $logger->debug('Node is child node. No scope restrictions.');
371  return false;
372  }
373  }
374  $logger->info('Scope filter matches.');
375 
376  return true;
377  }
378 
379  public static function _delete($a_record_id): void
380  {
381  global $DIC;
382 
383  $ilDB = $DIC['ilDB'];
384 
385  // Delete fields
386  foreach (ilAdvancedMDFieldDefinition::getInstancesByRecordId($a_record_id) as $field) {
387  $field->delete();
388  }
389 
390  $query = "DELETE FROM adv_md_record " .
391  "WHERE record_id = " . $ilDB->quote($a_record_id, 'integer') . " ";
392  $res = $ilDB->manipulate($query);
393 
394  $query = "DELETE FROM adv_md_record_objs " .
395  "WHERE record_id = " . $ilDB->quote($a_record_id, 'integer') . " ";
396  $res = $ilDB->manipulate($query);
397  }
398 
399  protected function setRecordId(int $record_id): void
400  {
401  $this->record_id = $record_id;
402  }
403 
407  public function setDefaultLanguage(string $language_code): void
408  {
409  $this->language_default = $language_code;
410  }
411 
412  public function getDefaultLanguage(): string
413  {
415  }
416 
417  public function delete(): void
418  {
421  }
422 
423  public function enabledScope(): bool
424  {
425  return $this->scope_enabled;
426  }
427 
428  public function enableScope(bool $a_stat): void
429  {
430  $this->scope_enabled = $a_stat;
431  }
432 
436  public function setScopes(array $a_scopes): void
437  {
438  $this->scopes = $a_scopes;
439  }
440 
445  public function getScopes(): array
446  {
447  return $this->scopes;
448  }
449 
453  public function getScopeRefIds(): array
454  {
455  $ref_ids = [];
456  foreach ($this->scopes as $scope) {
457  $ref_ids[] = $scope->getRefId();
458  }
459  return $ref_ids;
460  }
461 
462  public function save(): void
463  {
464  global $DIC;
465 
466  $ilDB = $DIC['ilDB'];
467 
468  // Save import id if given
469  $next_id = $ilDB->nextId('adv_md_record');
470 
471  $query = "INSERT INTO adv_md_record (record_id,import_id,active,title,description,parent_obj,lang_default) " .
472  "VALUES(" .
473  $ilDB->quote($next_id, 'integer') . ", " .
474  $this->db->quote($this->getImportId(), 'text') . ", " .
475  $this->db->quote($this->isActive(), 'integer') . ", " .
476  $this->db->quote($this->getTitle(), 'text') . ", " .
477  $this->db->quote($this->getDescription(), 'text') . ", " .
478  $this->db->quote($this->getParentObject(), 'integer') . ", " .
479  $this->db->quote($this->getDefaultLanguage(), ilDBConstants::T_TEXT) .
480  ")";
481  $res = $ilDB->manipulate($query);
482  $this->record_id = $next_id;
483 
484  if (!strlen($this->getImportId())) {
485  // set import id to default value
486  $query = "UPDATE adv_md_record " .
487  "SET import_id = " . $this->db->quote($this->generateImportId(), 'text') . " " .
488  "WHERE record_id = " . $this->db->quote($this->record_id, 'integer') . " ";
489  $res = $ilDB->manipulate($query);
490  }
491 
492  foreach ($this->getAssignedObjectTypes() as $type) {
493  global $DIC;
494  $ilDB = $DIC['ilDB'];
495  $query = "INSERT INTO adv_md_record_objs (record_id,obj_type,sub_type,optional) " .
496  "VALUES( " .
497  $this->db->quote($this->getRecordId(), 'integer') . ", " .
498  $this->db->quote($type["obj_type"], 'text') . ", " .
499  $this->db->quote($type["sub_type"], 'text') . ", " .
500  $this->db->quote($type["optional"], 'integer') . " " .
501  ")";
502  $res = $ilDB->manipulate($query);
503  }
504 
505  foreach ($this->getScopes() as $scope) {
506  $scope->setRecordId($this->getRecordId());
507  $scope->save();
508  }
509  }
510 
511  public function update(): void
512  {
513  global $DIC;
514 
515  $ilDB = $DIC['ilDB'];
516 
517  $query = "UPDATE adv_md_record " .
518  "SET active = " . $this->db->quote($this->isActive(), 'integer') . ", " .
519  "title = " . $this->db->quote($this->getTitle(), 'text') . ", " .
520  "description = " . $this->db->quote($this->getDescription(), 'text') . ", " .
521  'gpos = ' . $this->db->quote($this->getGlobalPosition(), 'integer') . ', ' .
522  'lang_default = ' . $this->db->quote($this->getDefaultLanguage(), ilDBConstants::T_TEXT) . ' ' .
523  "WHERE record_id = " . $this->db->quote($this->getRecordId(), 'integer') . " ";
524  $res = $ilDB->manipulate($query);
525 
526  // Delete assignments
527  $query = "DELETE FROM adv_md_record_objs " .
528  "WHERE record_id = " . $this->db->quote($this->getRecordId(), 'integer') . " ";
529  $res = $ilDB->manipulate($query);
530 
531  // Insert assignments
532  foreach ($this->getAssignedObjectTypes() as $type) {
533  $query = "INSERT INTO adv_md_record_objs (record_id,obj_type,sub_type,optional) " .
534  "VALUES ( " .
535  $this->db->quote($this->getRecordId(), 'integer') . ", " .
536  $this->db->quote($type["obj_type"], 'text') . ", " .
537  $this->db->quote($type["sub_type"], 'text') . ", " .
538  $this->db->quote($type["optional"], 'integer') . " " .
539  ")";
540  $res = $ilDB->manipulate($query);
541  }
543  foreach ($this->getScopes() as $scope) {
544  $scope->setRecordId($this->getRecordId());
545  $scope->save();
546  }
547  }
548 
549  public function validate(): bool
550  {
551  if (!strlen($this->getTitle())) {
552  return false;
553  }
554  return true;
555  }
556 
557  public function setGlobalPosition(int $position): void
558  {
559  $this->global_position = $position;
560  }
561 
562  public function getGlobalPosition(): int
563  {
564  return $this->global_position;
565  }
566 
567  public function getRecordId(): int
568  {
569  return $this->record_id;
570  }
571 
572  public function setActive(bool $a_active): void
573  {
574  $this->active = $a_active;
575  }
576 
577  public function isActive(): bool
578  {
579  return $this->active;
580  }
581 
582  public function setTitle(string $a_title): void
583  {
584  $this->title = $a_title;
585  }
586 
587  public function getTitle(): string
588  {
589  return $this->title;
590  }
591 
592  public function setDescription(string $a_description): void
593  {
594  $this->description = $a_description;
595  }
596 
597  public function getDescription(): string
598  {
599  return $this->description;
600  }
601 
602  public function setImportId(string $a_id_string): void
603  {
604  $this->import_id = $a_id_string;
605  }
606 
607  public function getImportId(): string
608  {
609  return $this->import_id;
610  }
611 
616  public function setAssignedObjectTypes(array $a_obj_types): void
617  {
618  $this->obj_types = $a_obj_types;
619  }
620 
621  public function appendAssignedObjectType(string $a_obj_type, string $a_sub_type, bool $a_optional = false): void
622  {
623  $this->obj_types[] = array(
624  "obj_type" => $a_obj_type,
625  "sub_type" => $a_sub_type,
626  "optional" => $a_optional
627  );
628  }
629 
633  public function getAssignedObjectTypes(): array
634  {
635  return $this->obj_types;
636  }
637 
638  public function isAssignedObjectType(string $a_obj_type, string $a_sub_type): bool
639  {
640  foreach ($this->getAssignedObjectTypes() as $t) {
641  if ($t["obj_type"] == $a_obj_type &&
642  $t["sub_type"] == $a_sub_type) {
643  return true;
644  }
645  }
646  return false;
647  }
648 
649  public function setParentObject(int $a_obj_id): void
650  {
651  $this->parent_obj = $a_obj_id;
652  }
653 
654  public function getParentObject(): int
655  {
656  return $this->parent_obj;
657  }
658 
664  public function toXML(ilXmlWriter $writer): void
665  {
666  $writer->xmlStartTag('Record', array('active' => $this->isActive() ? 1 : 0,
667  'id' => $this->generateImportId()
668  ));
669  $writer->xmlElement('Title', null, $this->getTitle());
670  $writer->xmlElement('Description', null, $this->getDescription());
671 
673  $translations->toXML($writer);
674 
675  foreach ($this->getAssignedObjectTypes() as $obj_type) {
676  $optional = array("optional" => $obj_type["optional"]);
677  if ($obj_type["sub_type"] == "") {
678  $writer->xmlElement('ObjectType', $optional, $obj_type["obj_type"]);
679  } else {
680  $writer->xmlElement('ObjectType', $optional, $obj_type["obj_type"] . ":" . $obj_type["sub_type"]);
681  }
682  }
683 
684  // scopes
685  if (count($this->getScopeRefIds())) {
686  $writer->xmlStartTag('Scope');
687  }
688  foreach ($this->getScopeRefIds() as $ref_id) {
690  $writer->xmlElement('ScopeEntry', ['id' => 'il_' . IL_INST_ID . '_' . $type . '_' . $ref_id]);
691  }
692  if (count($this->getScopeRefIds())) {
693  $writer->xmlEndTag('Scope');
694  }
695 
696  foreach (ilAdvancedMDFieldDefinition::getInstancesByRecordId($this->getRecordId()) as $definition) {
697  $definition->toXML($writer);
698  }
699  $writer->xmlEndTag('Record');
700  }
701 
702  private function read(): void
703  {
704  $query = "SELECT * FROM adv_md_record " .
705  "WHERE record_id = " . $this->db->quote($this->getRecordId(), 'integer') . " ";
706  $res = $this->db->query($query);
707  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
708  $this->setImportId((string) $row->import_id);
709  $this->setActive((bool) $row->active);
710  $this->setTitle((string) $row->title);
711  $this->setDescription((string) $row->description);
712  $this->setParentObject((int) $row->parent_obj);
713  $this->setGlobalPosition((int) $row->gpos);
714  $this->setDefaultLanguage((string) $row->lang_default);
715  }
716  $query = "SELECT * FROM adv_md_record_objs " .
717  "WHERE record_id = " . $this->db->quote($this->getRecordId(), 'integer') . " ";
718  $res = $this->db->query($query);
719  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
720  $this->obj_types[] = array(
721  "obj_type" => (string) $row->obj_type,
722  "sub_type" => (string) $row->sub_type,
723  "optional" => (bool) $row->optional
724  );
725  }
726 
727  $query = 'SELECT scope_id FROM adv_md_record_scope ' .
728  'WHERE record_id = ' . $this->db->quote($this->record_id, ilDBConstants::T_INTEGER);
729  $res = $this->db->query($query);
730  $this->scope_enabled = false;
731  $this->scopes = [];
732  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
733  $this->scope_enabled = true;
734  $this->scopes[] = new ilAdvancedMDRecordScope((int) $row->scope_id);
735  }
736  }
737 
741  protected function generateImportId(): string
742  {
743  return 'il_' . IL_INST_ID . '_adv_md_record_' . $this->getRecordId();
744  }
745 
746  public function __destruct()
747  {
748  unset(self::$instances[$this->getRecordId()]);
749  }
750 
759  public static function saveObjRecSelection(
760  int $a_obj_id,
761  string $a_sub_type = "",
762  array $a_records = null,
763  bool $a_delete_before = true
764  ): void {
765  global $DIC;
766 
767  $ilDB = $DIC['ilDB'];
768 
769  if ($a_sub_type == "") {
770  $a_sub_type = "-";
771  }
772 
773  if ($a_delete_before) {
774  $ilDB->manipulate("DELETE FROM adv_md_obj_rec_select WHERE " .
775  " obj_id = " . $ilDB->quote($a_obj_id, "integer") .
776  " AND sub_type = " . $ilDB->quote($a_sub_type, "text"));
777  }
778 
779  if (is_array($a_records)) {
780  foreach ($a_records as $r) {
781  if ($r > 0) {
782  $ilDB->manipulate("INSERT INTO adv_md_obj_rec_select " .
783  "(obj_id, rec_id, sub_type) VALUES (" .
784  $ilDB->quote($a_obj_id, "integer") . "," .
785  $ilDB->quote($r, "integer") . "," .
786  $ilDB->quote($a_sub_type, "text") .
787  ")");
788  }
789  }
790  }
791  }
792 
796  public static function deleteObjRecSelection(int $a_obj_id): void
797  {
798  global $DIC;
799 
800  $ilDB = $DIC['ilDB'];
801 
802  $ilDB->manipulate("DELETE FROM adv_md_obj_rec_select WHERE " .
803  " obj_id = " . $ilDB->quote($a_obj_id, "integer"));
804  }
805 
812  public static function getObjRecSelection(int $a_obj_id, string $a_sub_type = ""): array
813  {
814  global $DIC;
815 
816  $ilDB = $DIC['ilDB'];
817 
818  if ($a_sub_type == "") {
819  $a_sub_type = "-";
820  }
821 
822  $recs = array();
823  $set = $ilDB->query(
824  $r = "SELECT * FROM adv_md_obj_rec_select " .
825  " WHERE obj_id = " . $ilDB->quote($a_obj_id, "integer") .
826  " AND sub_type = " . $ilDB->quote($a_sub_type, "text")
827  );
828  while ($rec = $ilDB->fetchAssoc($set)) {
829  $recs[] = (int) $rec["rec_id"];
830  }
831  return $recs;
832  }
833 
834  public function _clone(array &$a_fields_map, int $a_parent_obj_id = null): ilAdvancedMDRecord
835  {
836  $new_obj = new self();
837  $new_obj->setActive($this->isActive());
838  $new_obj->setTitle($this->getTitle());
839  $new_obj->setDescription($this->getDescription());
840  $new_obj->setParentObject($a_parent_obj_id
841  ?: $this->getParentObject());
842  $new_obj->setAssignedObjectTypes($this->getAssignedObjectTypes());
843  $new_obj->setDefaultLanguage($this->getDefaultLanguage());
844  $new_obj->save();
845 
846  foreach (ilAdvancedMDFieldDefinition::getInstancesByRecordId($this->getRecordId()) as $definition) {
847  $new_def = $definition->_clone($new_obj->getRecordId());
848  $a_fields_map[$definition->getFieldId()] = $new_def->getFieldId();
849  }
850 
852  $record_translation->cloneRecord($new_obj->getRecordId());
853 
854  return $new_obj;
855  }
856 
857  public static function getSharedRecords(int $a_obj1_id, int $a_obj2_id, string $a_sub_type = "-"): array
858  {
859  $obj_type = ilObject::_lookupType($a_obj1_id);
860  $sel = array_intersect(
861  ilAdvancedMDRecord::getObjRecSelection($a_obj1_id, $a_sub_type),
862  ilAdvancedMDRecord::getObjRecSelection($a_obj2_id, $a_sub_type)
863  );
864 
865  $res = array();
866 
867  foreach (self::_getRecords() as $record) {
868  // local records cannot be shared
869  if ($record->getParentObject()) {
870  continue;
871  }
872 
873  // :TODO: inactive records can be ignored?
874  if (!$record->isActive()) {
875  continue;
876  }
877 
878  // parse assigned types
879  foreach ($record->getAssignedObjectTypes() as $item) {
880  if ($item["obj_type"] == $obj_type &&
881  $item["sub_type"] == $a_sub_type) {
882  // mandatory
883  if (!$item["optional"]) {
884  $res[] = $record->getRecordId();
885  } // optional
886  elseif (in_array($record->getRecordId(), $sel)) {
887  $res[] = $record->getRecordId();
888  }
889  }
890  }
891  }
892 
893  return $res;
894  }
895 }
__construct(int $a_record_id=0)
Singleton constructor To create an array of new records (without saving them) call the constructor di...
Scope restrictions for advanced md records.
$res
Definition: ltiservices.php:69
$scope
Definition: ltiregstart.php:53
const IL_INST_ID
Definition: constants.php:40
static _getRecords()
Get records public.
$type
static ecsConfigured()
Checks if an ecs server is configured.
$lng
static _getActivatedRecordsByObjectType(string $a_obj_type, string $a_sub_type="", bool $a_only_optional=false)
Get activated records by object type.
static saveObjRecSelection(int $a_obj_id, string $a_sub_type="", array $a_records=null, bool $a_delete_before=true)
Save repository object record selection.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const RELATION_PARENT
static _getSelectedRecordsByObject(string $a_obj_type, int $a_id, string $a_sub_type="", bool $is_ref_id=true)
static getSharedRecords(int $a_obj1_id, int $a_obj2_id, string $a_sub_type="-")
static _getActiveSearchableRecords()
Get active searchable records.
static _getAssignableObjectTypes(bool $a_include_text=false)
Get assignable object type public.
static getInstancesByRecordId( $a_record_id, $a_only_searchable=false, string $language='')
Get definitions by record id.
static isFilteredByScope($a_ref_id, array $scopes)
Check if a given ref id is not filtered by scope restriction.
static getPossibleRemoteTypes(bool $a_with_captions=false)
Get all possible remote object types.
static _lookupContainerSetting(int $a_id, string $a_keyword, string $a_default_value=null)
static _lookupObjId(int $ref_id)
xmlEndTag(string $tag)
Writes an endtag.
static _delete($a_record_id)
isAssignedObjectType(string $a_obj_type, string $a_sub_type)
global $DIC
Definition: feed.php:28
static getObjRecSelection(int $a_obj_id, string $a_sub_type="")
Get repository object record selection.
static _getInstanceByRecordId(int $a_record_id)
static _lookupRecordIdByImportId(string $a_ilias_id)
appendAssignedObjectType(string $a_obj_type, string $a_sub_type, bool $a_optional=false)
toXML(ilXmlWriter $writer)
To Xml.
$ref_id
Definition: ltiauth.php:67
_clone(array &$a_fields_map, int $a_parent_obj_id=null)
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
setDescription(string $a_description)
setDefaultLanguage(string $language_code)
$query
static _getAllRecordsByObjectType()
Get records by obj_type Note: this returns only records with no sub types!
static deleteByRecordId(int $a_record_id)
setImportId(string $a_id_string)
static deleteObjRecSelection(int $a_obj_id)
Delete repository object record selection.
setAssignedObjectTypes(array $a_obj_types)
static _lookupTitle(int $a_record_id)
xmlStartTag(string $tag, ?array $attrs=null, bool $empty=false, bool $encode=true, bool $escape=true)
Writes a starttag.
static _getActivatedObjTypes()
get activated obj types
xmlElement(string $tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
static _lookupType(int $id, bool $reference=false)
generateImportId()
generate unique record id