19declare(strict_types=1);
63 $this->db =
$DIC->database();
64 $this->record_id = $a_record_id;
73 if (isset(self::$instances[$a_record_id])) {
74 return self::$instances[$a_record_id];
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 ";
103 static $title_cache = array();
105 if (isset($title_cache[$a_record_id])) {
106 return $title_cache[$a_record_id];
113 $query =
"SELECT title FROM adv_md_record " .
114 "WHERE record_id = " .
$ilDB->quote($a_record_id,
'integer') .
" ";
118 return $title_cache[$a_record_id] = (string) $row->title;
127 $query =
"SELECT record_id FROM adv_md_record " .
128 "WHERE import_id = " .
$ilDB->quote($a_ilias_id,
'text') .
" ";
131 return (
int) $row->record_id;
145 $objDefinition =
$DIC[
'objDefinition'];
150 $amet_types = $objDefinition->getAdvancedMetaDataTypes();
157 foreach ($amet_types as $at) {
158 if (in_array($at[
"obj_type"], $filter)) {
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"]);
168 $at[
"sub_type"] =
"-";
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 " .
214 $query =
"SELECT record_id FROM adv_md_record ORDER BY gpos ";
235 $query =
"SELECT * FROM adv_md_record_objs WHERE sub_type=" .
$ilDB->quote(
"-",
"text");
238 $records[(string) $row->obj_type][] = self::_getInstanceByRecordId((
int) $row->record_id);
244 $records = array_diff_key($records, array_flip($filter));
256 string $a_sub_type =
"",
257 bool $a_only_optional =
false
263 if ($a_sub_type ==
"") {
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');
274 if ($a_only_optional) {
275 $query .=
" AND optional =" .
$ilDB->quote(1,
'integer');
279 $query .=
"ORDER by parent_obj DESC, record_id";
298 string $a_sub_type =
"",
299 bool $is_ref_id =
true
303 if ($a_sub_type ==
"") {
307 $a_obj_id = $is_ref_id
319 foreach (self::_getActivatedRecordsByObjectType($a_obj_type, $a_sub_type) as $record) {
321 if ($is_ref_id && self::isFilteredByScope($a_id, $record->getScopes())) {
324 foreach ($record->getAssignedObjectTypes() as $item) {
325 if ($record->getParentObject()) {
327 if ($record->getParentObject() != $a_obj_id) {
330 elseif (!$config_setting) {
335 if ($item[
'obj_type'] == $a_obj_type &&
336 $item[
'sub_type'] == $a_sub_type) {
337 if ($item[
'optional']) {
338 $optional[] = $record->getRecordId();
340 $records[$record->getRecordId()] = $record;
346 if (!$config_setting && !in_array($a_sub_type, array(
"orgu_type",
"prg_type"))) {
349 $selected = self::getObjRecSelection($a_obj_id, $a_sub_type);
351 foreach ($optional as $record_id) {
352 if (!in_array($record_id, $selected)) {
353 unset($records[$record_id]);
359 $records = $orderings->sortRecords($records, $a_obj_id);
371 $tree =
$GLOBALS[
'DIC']->repositoryTree();
372 $logger =
$GLOBALS[
'DIC']->logger()->amet();
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.');
384 $logger->debug(
'Node is child node. No scope restrictions.');
388 $logger->info(
'Scope filter matches.');
393 public static function _delete($a_record_id): void
404 $query =
"DELETE FROM adv_md_record " .
405 "WHERE record_id = " .
$ilDB->quote($a_record_id,
'integer') .
" ";
408 $query =
"DELETE FROM adv_md_record_objs " .
409 "WHERE record_id = " .
$ilDB->quote($a_record_id,
'integer') .
" ";
415 $this->record_id = $record_id;
423 $this->language_default = $language_code;
428 return $this->language_default;
431 public function delete():
void
439 return $this->scope_enabled;
444 $this->scope_enabled = $a_stat;
452 $this->scopes = $a_scopes;
470 foreach ($this->scopes as
$scope) {
471 $ref_ids[] =
$scope->getRefId();
483 $next_id =
$ilDB->nextId(
'adv_md_record');
485 $query =
"INSERT INTO adv_md_record (record_id,import_id,active,title,description,parent_obj,lang_default) " .
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') .
", " .
496 $this->record_id = $next_id;
498 if (!strlen($this->getImportId())) {
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') .
" ";
506 foreach ($this->getAssignedObjectTypes() as $type) {
509 $query =
"INSERT INTO adv_md_record_objs (record_id,obj_type,sub_type,optional) " .
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') .
" " .
519 foreach ($this->getScopes() as
$scope) {
520 $scope->setRecordId($this->getRecordId());
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') .
', ' .
537 "WHERE record_id = " . $this->db->quote($this->getRecordId(),
'integer') .
" ";
541 $query =
"DELETE FROM adv_md_record_objs " .
542 "WHERE record_id = " . $this->db->quote($this->getRecordId(),
'integer') .
" ";
546 foreach ($this->getAssignedObjectTypes() as $type) {
547 $query =
"INSERT INTO adv_md_record_objs (record_id,obj_type,sub_type,optional) " .
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') .
" " .
557 foreach ($this->getScopes() as
$scope) {
558 $scope->setRecordId($this->getRecordId());
573 $this->global_position = $position;
578 return $this->global_position;
583 return $this->record_id;
588 $this->active = $a_active;
593 return $this->active;
598 $this->title = $a_title;
608 $this->description = $a_description;
613 return $this->description;
618 $this->import_id = $a_id_string;
623 return $this->import_id;
632 $this->obj_types = $a_obj_types;
637 $this->obj_types[] = array(
638 "obj_type" => $a_obj_type,
639 "sub_type" => $a_sub_type,
640 "optional" => $a_optional
649 return $this->obj_types;
654 foreach ($this->getAssignedObjectTypes() as $t) {
655 if ($t[
"obj_type"] == $a_obj_type &&
656 $t[
"sub_type"] == $a_sub_type) {
665 $this->parent_obj = $a_obj_id;
670 return $this->parent_obj;
680 $writer->
xmlStartTag(
'Record', array(
'active' => $this->isActive() ? 1 : 0,
681 'id' => $this->generateImportId()
684 $writer->
xmlElement(
'Description',
null, $this->getDescription());
687 $translations->toXML($writer);
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"]);
694 $writer->
xmlElement(
'ObjectType', $optional, $obj_type[
"obj_type"] .
":" . $obj_type[
"sub_type"]);
699 if (count($this->getScopeRefIds())) {
702 foreach ($this->getScopeRefIds() as
$ref_id) {
706 if (count($this->getScopeRefIds())) {
711 $definition->toXML($writer);
718 $query =
"SELECT * FROM adv_md_record " .
719 "WHERE record_id = " . $this->db->quote($this->getRecordId(),
'integer') .
" ";
720 $res = $this->db->query($query);
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);
730 $query =
"SELECT * FROM adv_md_record_objs " .
731 "WHERE record_id = " . $this->db->quote($this->getRecordId(),
'integer') .
" ";
732 $res = $this->db->query($query);
734 $this->obj_types[] = array(
735 "obj_type" => (
string) $row->obj_type,
736 "sub_type" => (
string) $row->sub_type,
737 "optional" => (
bool) $row->optional
741 $query =
'SELECT scope_id FROM adv_md_record_scope ' .
743 $res = $this->db->query($query);
744 $this->scope_enabled =
false;
747 $this->scope_enabled =
true;
757 return 'il_' .
IL_INST_ID .
'_adv_md_record_' . $this->getRecordId();
762 unset(self::$instances[$this->getRecordId()]);
775 string $a_sub_type =
"",
776 ?array $a_records =
null,
777 bool $a_delete_before =
true
783 if ($a_sub_type ==
"") {
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"));
793 if (is_array($a_records)) {
794 foreach ($a_records as $r) {
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") .
816 $ilDB->manipulate(
"DELETE FROM adv_md_obj_rec_select WHERE " .
817 " obj_id = " .
$ilDB->quote($a_obj_id,
"integer"));
832 if ($a_sub_type ==
"") {
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")
842 while ($rec =
$ilDB->fetchAssoc($set)) {
843 $recs[] = (
int) $rec[
"rec_id"];
850 $new_obj =
new self();
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());
861 $new_def = $definition->_clone($new_obj->getRecordId());
862 $a_fields_map[$definition->getFieldId()] = $new_def->getFieldId();
866 $record_translation->cloneRecord($new_obj->getRecordId());
871 public static function getSharedRecords(
int $a_obj1_id,
int $a_obj2_id,
string $a_sub_type =
"-"): array
874 $sel = array_intersect(
881 foreach (self::_getRecords() as $record) {
883 if ($record->getParentObject()) {
888 if (!$record->isActive()) {
893 foreach ($record->getAssignedObjectTypes() as $item) {
894 if ($item[
"obj_type"] == $obj_type &&
895 $item[
"sub_type"] == $a_sub_type) {
897 if (!$item[
"optional"]) {
898 $res[] = $record->getRecordId();
900 elseif (in_array($record->getRecordId(), $sel)) {
901 $res[] = $record->getRecordId();
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 getInstanceByRecordId(int $record_id)
static _lookupTitle(int $a_record_id)
isAssignedObjectType(string $a_obj_type, string $a_sub_type)
enableScope(bool $a_stat)
static getSharedRecords(int $a_obj1_id, int $a_obj2_id, string $a_sub_type="-")
setImportId(string $a_id_string)
setParentObject(int $a_obj_id)
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!
setTitle(string $a_title)
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.
setGlobalPosition(int $position)
_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...
setRecordId(int $record_id)
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.
setActive(bool $a_active)
setScopes(array $a_scopes)
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)
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.