3 declare(strict_types=1);
    49         $this->db = $DIC->database();
    50         $this->record_id = $a_record_id;
    59         if (isset(self::$instances[$a_record_id])) {
    60             return self::$instances[$a_record_id];
    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 ";
    82             $records[] = self::_getInstanceByRecordId((
int) $row->record_id);
    89         static $title_cache = array();
    91         if (isset($title_cache[$a_record_id])) {
    92             return $title_cache[$a_record_id];
    99         $query = 
"SELECT title FROM adv_md_record " .
   100             "WHERE record_id = " . 
$ilDB->quote($a_record_id, 
'integer') . 
" ";
   104         return $title_cache[$a_record_id] = (string) $row->title;
   111         $ilDB = $DIC[
'ilDB'];
   113         $query = 
"SELECT record_id FROM adv_md_record " .
   114             "WHERE import_id = " . 
$ilDB->quote($a_ilias_id, 
'text') . 
" ";
   117             return (
int) $row->record_id;
   131         $objDefinition = $DIC[
'objDefinition'];
   136         $amet_types = $objDefinition->getAdvancedMetaDataTypes();
   143         foreach ($amet_types as $at) {
   144             if (in_array($at[
"obj_type"], $filter)) {
   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"]);
   154                     $at[
"sub_type"] = 
"-";
   174         $ilDB = $DIC[
'ilDB'];
   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 " .
   182             $obj_types[] = (string) $row->obj_type;
   198         $ilDB = $DIC[
'ilDB'];
   200         $query = 
"SELECT record_id FROM adv_md_record ORDER BY gpos ";
   218         $ilDB = $DIC[
'ilDB'];
   221         $query = 
"SELECT * FROM adv_md_record_objs WHERE sub_type=" . 
$ilDB->quote(
"-", 
"text");
   224             $records[(string) $row->obj_type][] = self::_getInstanceByRecordId((
int) $row->record_id);
   230             $records = array_diff_key($records, array_flip($filter));
   242         string $a_sub_type = 
"",
   243         bool $a_only_optional = 
false   247         $ilDB = $DIC[
'ilDB'];
   249         if ($a_sub_type == 
"") {
   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');
   260         if ($a_only_optional) {
   261             $query .= 
" AND optional =" . 
$ilDB->quote(1, 
'integer');
   265         $query .= 
"ORDER by parent_obj DESC, record_id";
   269             $records[] = self::_getInstanceByRecordId((
int) $row->record_id);
   284         string $a_sub_type = 
"",
   285         bool $is_ref_id = 
true   289         if ($a_sub_type == 
"") {
   293         $a_obj_id = $is_ref_id
   305         foreach (self::_getActivatedRecordsByObjectType($a_obj_type, $a_sub_type) as $record) {
   307             if ($is_ref_id && self::isFilteredByScope($a_id, $record->getScopes())) {
   310             foreach ($record->getAssignedObjectTypes() as $item) {
   311                 if ($record->getParentObject()) {
   313                     if ($record->getParentObject() != $a_obj_id) {
   316                     elseif (!$config_setting) {
   321                 if ($item[
'obj_type'] == $a_obj_type &&
   322                     $item[
'sub_type'] == $a_sub_type) {
   323                     if ($item[
'optional']) {
   324                         $optional[] = $record->getRecordId();
   326                     $records[$record->getRecordId()] = $record;
   332             if (!$config_setting && !in_array($a_sub_type, array(
"orgu_type", 
"prg_type"))) { 
   335                 $selected = self::getObjRecSelection($a_obj_id, $a_sub_type);
   337             foreach ($optional as $record_id) {
   338                 if (!in_array($record_id, $selected)) {
   339                     unset($records[$record_id]);
   345         $records = $orderings->sortRecords($records, $a_obj_id);
   357         $tree = 
$GLOBALS[
'DIC']->repositoryTree();
   358         $logger = 
$GLOBALS[
'DIC']->logger()->amet();
   360         if (!count($scopes)) {
   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.');
   370                 $logger->debug(
'Node is child node. No scope restrictions.');
   374         $logger->info(
'Scope filter matches.');
   379     public static function _delete($a_record_id): void
   383         $ilDB = $DIC[
'ilDB'];
   390         $query = 
"DELETE FROM adv_md_record " .
   391             "WHERE record_id = " . 
$ilDB->quote($a_record_id, 
'integer') . 
" ";
   394         $query = 
"DELETE FROM adv_md_record_objs " .
   395             "WHERE record_id = " . 
$ilDB->quote($a_record_id, 
'integer') . 
" ";
   409         $this->language_default = $language_code;
   417     public function delete(): 
void   430         $this->scope_enabled = $a_stat;
   438         $this->scopes = $a_scopes;
   456         foreach ($this->scopes as 
$scope) {
   457             $ref_ids[] = $scope->getRefId();
   466         $ilDB = $DIC[
'ilDB'];
   469         $next_id = 
$ilDB->nextId(
'adv_md_record');
   471         $query = 
"INSERT INTO adv_md_record (record_id,import_id,active,title,description,parent_obj,lang_default) " .
   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') . 
", " .
   482         $this->record_id = $next_id;
   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') . 
" ";
   494             $ilDB = $DIC[
'ilDB'];
   495             $query = 
"INSERT INTO adv_md_record_objs (record_id,obj_type,sub_type,optional) " .
   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') . 
" " .
   515         $ilDB = $DIC[
'ilDB'];
   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') . 
", " .
   523             "WHERE record_id = " . $this->db->quote($this->
getRecordId(), 
'integer') . 
" ";
   527         $query = 
"DELETE FROM adv_md_record_objs " .
   528             "WHERE record_id = " . $this->db->quote($this->
getRecordId(), 
'integer') . 
" ";
   533             $query = 
"INSERT INTO adv_md_record_objs (record_id,obj_type,sub_type,optional) " .
   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') . 
" " .
   559         $this->global_position = $position;
   574         $this->active = $a_active;
   584         $this->title = $a_title;
   594         $this->description = $a_description;
   604         $this->import_id = $a_id_string;
   618         $this->obj_types = $a_obj_types;
   623         $this->obj_types[] = array(
   624             "obj_type" => $a_obj_type,
   625             "sub_type" => $a_sub_type,
   626             "optional" => $a_optional
   641             if ($t[
"obj_type"] == $a_obj_type &&
   642                 $t[
"sub_type"] == $a_sub_type) {
   651         $this->parent_obj = $a_obj_id;
   673         $translations->toXML($writer);
   676             $optional = array(
"optional" => $obj_type[
"optional"]);
   677             if ($obj_type[
"sub_type"] == 
"") {
   678                 $writer->
xmlElement(
'ObjectType', $optional, $obj_type[
"obj_type"]);
   680                 $writer->
xmlElement(
'ObjectType', $optional, $obj_type[
"obj_type"] . 
":" . $obj_type[
"sub_type"]);
   697             $definition->toXML($writer);
   704         $query = 
"SELECT * FROM adv_md_record " .
   705             "WHERE record_id = " . $this->db->quote($this->
getRecordId(), 
'integer') . 
" ";
   706         $res = $this->db->query($query);
   710             $this->
setTitle((
string) $row->title);
   716         $query = 
"SELECT * FROM adv_md_record_objs " .
   717             "WHERE record_id = " . $this->db->quote($this->
getRecordId(), 
'integer') . 
" ";
   718         $res = $this->db->query($query);
   720             $this->obj_types[] = array(
   721                 "obj_type" => (
string) $row->obj_type,
   722                 "sub_type" => (
string) $row->sub_type,
   723                 "optional" => (
bool) $row->optional
   727         $query = 
'SELECT scope_id FROM adv_md_record_scope ' .
   729         $res = $this->db->query($query);
   730         $this->scope_enabled = 
false;
   733             $this->scope_enabled = 
true;
   761         string $a_sub_type = 
"",
   762         array $a_records = null,
   763         bool $a_delete_before = 
true   767         $ilDB = $DIC[
'ilDB'];
   769         if ($a_sub_type == 
"") {
   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"));
   779         if (is_array($a_records)) {
   780             foreach ($a_records as 
$r) {
   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") .
   800         $ilDB = $DIC[
'ilDB'];
   802         $ilDB->manipulate(
"DELETE FROM adv_md_obj_rec_select WHERE " .
   803             " obj_id = " . 
$ilDB->quote($a_obj_id, 
"integer"));
   816         $ilDB = $DIC[
'ilDB'];
   818         if ($a_sub_type == 
"") {
   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")
   828         while ($rec = 
$ilDB->fetchAssoc($set)) {
   829             $recs[] = (
int) $rec[
"rec_id"];
   836         $new_obj = 
new self();
   838         $new_obj->setTitle($this->
getTitle());
   840         $new_obj->setParentObject($a_parent_obj_id
   847             $new_def = $definition->_clone($new_obj->getRecordId());
   848             $a_fields_map[$definition->getFieldId()] = $new_def->getFieldId();
   852         $record_translation->cloneRecord($new_obj->getRecordId());
   857     public static function getSharedRecords(
int $a_obj1_id, 
int $a_obj2_id, 
string $a_sub_type = 
"-"): array
   860         $sel = array_intersect(
   867         foreach (self::_getRecords() as $record) {
   869             if ($record->getParentObject()) {
   874             if (!$record->isActive()) {
   879             foreach ($record->getAssignedObjectTypes() as $item) {
   880                 if ($item[
"obj_type"] == $obj_type &&
   881                     $item[
"sub_type"] == $a_sub_type) {
   883                     if (!$item[
"optional"]) {
   884                         $res[] = $record->getRecordId();
   886                     elseif (in_array($record->getRecordId(), $sel)) {
   887                         $res[] = $record->getRecordId();
 __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. 
 
setScopes(array $a_scopes)
 
setParentObject(int $a_obj_id)
 
static _getRecords()
Get records  public. 
 
static ecsConfigured()
Checks if an ecs server is configured. 
 
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. 
 
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. 
 
sort()
 description: > Example for rendering a Sort Glyph. 
 
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)
 
setGlobalPosition(int $position)
 
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. 
 
_clone(array &$a_fields_map, int $a_parent_obj_id=null)
 
setTitle(string $a_title)
 
setActive(bool $a_active)
 
setDescription(string $a_description)
 
setDefaultLanguage(string $language_code)
 
static _getAllRecordsByObjectType()
Get records by obj_type Note: this returns only records with no sub types! 
 
static deleteByRecordId(int $a_record_id)
 
enableScope(bool $a_stat)
 
setImportId(string $a_id_string)
 
static deleteObjRecSelection(int $a_obj_id)
Delete repository object record selection. 
 
setRecordId(int $record_id)
 
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 
 
static getInstanceByRecordId(int $record_id)