5 include_once
'./Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordScope.php';
58 $this->record_id = $a_record_id;
77 if (isset(self::$instances[$a_record_id])) {
78 return self::$instances[$a_record_id];
96 $query =
"SELECT DISTINCT(amr.record_id) FROM adv_md_record amr " .
97 "JOIN adv_mdf_definition amfd ON amr.record_id = amfd.record_id " .
98 "WHERE searchable = 1 AND active = 1 ";
102 $records[] = self::_getInstanceByRecordId(
$row->record_id);
117 static $title_cache = array();
119 if (isset($title_cache[$a_record_id])) {
120 return $title_cache[$a_record_id];
125 $ilDB = $DIC[
'ilDB'];
127 $query =
"SELECT title FROM adv_md_record " .
128 "WHERE record_id = " .
$ilDB->quote($a_record_id,
'integer') .
" ";
132 return $title_cache[$a_record_id] =
$row->title;
147 $ilDB = $DIC[
'ilDB'];
149 $query =
"SELECT record_id FROM adv_md_record " .
150 "WHERE import_id = " .
$ilDB->quote($a_ilias_id,
'text') .
" ";
153 return $row->record_id;
168 $objDefinition = $DIC[
'objDefinition'];
173 $amet_types = $objDefinition->getAdvancedMetaDataTypes();
180 foreach ($amet_types as $at) {
181 if (in_array($at[
"obj_type"], $filter)) {
185 if ($a_include_text) {
186 $text =
$lng->txt(
"obj_" . $at[
"obj_type"]);
187 if ($at[
"sub_type"] !=
"") {
188 $lng->loadLanguageModule($at[
"obj_type"]);
189 $text .=
": " .
$lng->txt($at[
"obj_type"] .
"_" . $at[
"sub_type"]);
191 $at[
"sub_type"] =
"-";
215 $ilDB = $DIC[
'ilDB'];
217 $query =
"SELECT DISTINCT(obj_type) FROM adv_md_record_objs amo " .
218 "JOIN adv_md_record amr ON amo.record_id = amr.record_id " .
240 $ilDB = $DIC[
'ilDB'];
242 $query =
"SELECT record_id FROM adv_md_record ORDER BY gpos ";
262 $ilDB = $DIC[
'ilDB'];
266 $query =
"SELECT * FROM adv_md_record_objs WHERE sub_type=" .
$ilDB->quote(
"-",
"text");
294 $ilDB = $DIC[
'ilDB'];
298 if ($a_sub_type ==
"") {
302 $query =
"SELECT amro.record_id record_id FROM adv_md_record_objs amro " .
303 "JOIN adv_md_record amr ON amr.record_id = amro.record_id " .
304 "WHERE active = 1 " .
305 "AND obj_type = " .
$ilDB->quote($a_obj_type,
'text') .
" " .
306 "AND sub_type = " .
$ilDB->quote($a_sub_type,
'text');
308 if ($a_only_optional) {
309 $query .=
" AND optional =" .
$ilDB->quote(1,
'integer');
313 $query .=
"ORDER by parent_obj DESC, record_id";
317 $records[] = self::_getInstanceByRecordId(
$row->record_id);
335 if ($a_sub_type ==
"") {
342 include_once
'Services/Container/classes/class.ilContainer.php';
343 include_once
'Services/Object/classes/class.ilObjectServiceSettingsGUI.php';
351 foreach (self::_getActivatedRecordsByObjectType($a_obj_type, $a_sub_type) as $record) {
353 if (self::isFilteredByScope($a_ref_id, $record->getScopes())) {
357 foreach ($record->getAssignedObjectTypes() as $item) {
358 if ($record->getParentObject()) {
360 if ($record->getParentObject() != $a_obj_id) {
364 elseif (!$config_setting) {
369 if ($item[
'obj_type'] == $a_obj_type &&
370 $item[
'sub_type'] == $a_sub_type) {
371 if ($item[
'optional']) {
372 $optional[] = $record->getRecordId();
374 $records[$record->getRecordId()] = $record;
380 if (!$config_setting && !in_array($a_sub_type, array(
"orgu_type",
"prg_type"))) {
383 $selected = self::getObjRecSelection($a_obj_id, $a_sub_type);
386 if (!in_array($record_id, $selected)) {
407 $logger =
$GLOBALS[
'DIC']->logger()->amet();
409 if (!count($scopes)) {
410 $logger->debug(
'No md scope restrictions.');
413 foreach ($scopes as $scope) {
414 $logger->debug(
'Comparing: ' . $a_ref_id .
' with: ' . $scope->getRefId());
415 if ($scope->getRefId() == $a_ref_id) {
416 $logger->debug(
'Elements are equal. No scope restrictions.');
420 $logger->debug(
'Node is child node. No scope restrictions.');
424 $logger->info(
'Scope filter matches.');
442 $ilDB = $DIC[
'ilDB'];
449 $query =
"DELETE FROM adv_md_record " .
450 "WHERE record_id = " .
$ilDB->quote($a_record_id,
'integer') .
" ";
453 $query =
"DELETE FROM adv_md_record_objs " .
454 "WHERE record_id = " .
$ilDB->quote($a_record_id,
'integer') .
" ";
465 public function delete()
486 $this->scope_enabled = $a_stat;
495 $this->scopes = $a_scopes;
514 foreach ($this->scopes as $scope) {
515 $ref_ids[] = $scope->getRefId();
530 $ilDB = $DIC[
'ilDB'];
533 $next_id =
$ilDB->nextId(
'adv_md_record');
535 $query =
"INSERT INTO adv_md_record (record_id,import_id,active,title,description,parent_obj) " .
537 $ilDB->quote($next_id,
'integer') .
", " .
538 $this->db->quote($this->
getImportId(),
'text') .
", " .
539 $this->db->quote($this->
isActive(),
'integer') .
", " .
540 $this->db->quote($this->
getTitle(),
'text') .
", " .
545 $this->record_id = $next_id;
549 $query =
"UPDATE adv_md_record " .
550 "SET import_id = " . $this->db->quote($this->
generateImportId(),
'text') .
" " .
551 "WHERE record_id = " . $this->db->quote($this->record_id,
'integer') .
" ";
558 $ilDB = $DIC[
'ilDB'];
560 $query =
"INSERT INTO adv_md_record_objs (record_id,obj_type,sub_type,optional) " .
562 $this->db->quote($this->
getRecordId(),
'integer') .
", " .
563 $this->db->quote($type[
"obj_type"],
'text') .
", " .
564 $this->db->quote($type[
"sub_type"],
'text') .
", " .
565 $this->db->quote($type[
"optional"],
'integer') .
" " .
586 $ilDB = $DIC[
'ilDB'];
588 $query =
"UPDATE adv_md_record " .
589 "SET active = " . $this->db->quote($this->
isActive(),
'integer') .
", " .
590 "title = " . $this->db->quote($this->
getTitle(),
'text') .
", " .
591 "description = " . $this->db->quote($this->
getDescription(),
'text') .
", " .
593 "WHERE record_id = " . $this->db->quote($this->
getRecordId(),
'integer') .
" ";
597 $query =
"DELETE FROM adv_md_record_objs " .
598 "WHERE record_id = " . $this->db->quote($this->
getRecordId(),
'integer') .
" ";
603 $query =
"INSERT INTO adv_md_record_objs (record_id,obj_type,sub_type,optional) " .
605 $this->db->quote($this->
getRecordId(),
'integer') .
", " .
606 $this->db->quote($type[
"obj_type"],
'text') .
", " .
607 $this->db->quote($type[
"sub_type"],
'text') .
", " .
608 $this->db->quote($type[
"optional"],
'integer') .
" " .
639 $this->global_position = $position;
671 $this->active = $a_active;
694 $this->title = $a_title;
717 $this->description = $a_description;
740 $this->import_id = $a_id_string;
763 $this->obj_types = $a_obj_types;
775 $this->obj_types[] = array(
776 "obj_type" => $a_obj_type,
777 "sub_type" => $a_sub_type,
778 "optional" => (
bool) $a_optional
790 return $this->obj_types ? $this->obj_types : array();
802 if ($t[
"obj_type"] == $a_obj_type &&
803 $t[
"sub_type"] == $a_sub_type) {
812 $this->parent_obj = $a_obj_id;
837 $optional = array(
"optional" => $obj_type[
"optional"]);
838 if ($obj_type[
"sub_type"] ==
"") {
839 $writer->
xmlElement(
'ObjectType', $optional, $obj_type[
"obj_type"]);
841 $writer->
xmlElement(
'ObjectType', $optional, $obj_type[
"obj_type"] .
":" . $obj_type[
"sub_type"]);
851 $writer->
xmlElement(
'ScopeEntry', [
'id' =>
'il_' . IL_INST_ID .
'_' .
$type .
'_' . $ref_id]);
858 include_once(
'Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
860 $definition->toXML($writer);
876 $ilDB = $DIC[
'ilDB'];
878 $query =
"SELECT * FROM adv_md_record " .
879 "WHERE record_id = " . $this->db->quote($this->
getRecordId(),
'integer') .
" ";
889 $query =
"SELECT * FROM adv_md_record_objs " .
890 "WHERE record_id = " . $this->db->quote($this->
getRecordId(),
'integer') .
" ";
893 $this->obj_types[] = array(
894 "obj_type" =>
$row->obj_type,
895 "sub_type" =>
$row->sub_type,
896 "optional" => (
bool)
$row->optional
900 $query =
'SELECT scope_id FROM adv_md_record_scope ' .
901 'WHERE record_id = ' .
$ilDB->quote($this->record_id);
903 $this->scope_enabled =
false;
906 $this->scope_enabled =
true;
919 return 'il_' . IL_INST_ID .
'_adv_md_record_' . $this->
getRecordId();
942 public static function saveObjRecSelection($a_obj_id, $a_sub_type =
"", array $a_records = null, $a_delete_before =
true)
946 $ilDB = $DIC[
'ilDB'];
948 if ($a_sub_type ==
"") {
952 if ((
bool) $a_delete_before) {
953 $ilDB->manipulate(
"DELETE FROM adv_md_obj_rec_select WHERE " .
954 " obj_id = " .
$ilDB->quote($a_obj_id,
"integer") .
955 " AND sub_type = " .
$ilDB->quote($a_sub_type,
"text"));
958 if (is_array($a_records)) {
959 foreach ($a_records as
$r) {
961 $ilDB->manipulate(
"INSERT INTO adv_md_obj_rec_select " .
962 "(obj_id, rec_id, sub_type) VALUES (" .
963 $ilDB->quote($a_obj_id,
"integer") .
"," .
964 $ilDB->quote($r,
"integer") .
"," .
965 $ilDB->quote($a_sub_type,
"text") .
982 $ilDB = $DIC[
'ilDB'];
984 if ($a_sub_type ==
"") {
990 $r =
"SELECT * FROM adv_md_obj_rec_select " .
991 " WHERE obj_id = " .
$ilDB->quote($a_obj_id,
"integer") .
992 " AND sub_type = " .
$ilDB->quote($a_sub_type,
"text")
994 while ($rec =
$ilDB->fetchAssoc($set)) {
995 $recs[] = $rec[
"rec_id"];
1007 public function _clone(array &$a_fields_map, $a_parent_obj_id = null)
1009 $new_obj =
new self();
1010 $new_obj->setActive($this->
isActive());
1011 $new_obj->setTitle($this->
getTitle());
1013 $new_obj->setParentObject($a_parent_obj_id
1019 include_once(
'Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
1021 $new_def = $definition->_clone($new_obj->getRecordId());
1022 $a_fields_map[$definition->getFieldId()] = $new_def->getFieldId();
1039 $sel = array_intersect(
1046 foreach (self::_getRecords() as $record) {
1048 if ($record->getParentObject()) {
1053 if (!$record->isActive()) {
1058 foreach ($record->getAssignedObjectTypes() as $item) {
1059 if ($item[
"obj_type"] == $obj_type &&
1060 $item[
"sub_type"] == $a_sub_type) {
1062 if (!$item[
"optional"]) {
1063 $res[] = $record->getRecordId();
1066 elseif (in_array($record->getRecordId(), $sel)) {
1067 $res[] = $record->getRecordId();
Scope restrictions for advanced md records.
static deleteByRecordI($a_record_id)
delete by record id
setScopes(array $a_scopes)
Set scopes.
xmlStartTag($tag, $attrs=null, $empty=false, $encode=true, $escape=true)
Writes a starttag.
static getPossibleRemoteTypes($a_with_captions=false)
Get all possible remote object types.
static _getRecords()
Get records.
static ecsConfigured()
Checks if an ecs server is configured.
getScopeRefIds()
Get scope gef_ids.
static getSharedRecords($a_obj1_id, $a_obj2_id, $a_sub_type="-")
Get shared records.
getDescription()
get description
setActive($a_active)
Set active.
static _getActiveSearchableRecords()
Get active searchable records.
appendAssignedObjectType($a_obj_type, $a_sub_type, $a_optional=false)
append assigned object types
static isFilteredByScope($a_ref_id, array $scopes)
Check if a given ref id is not filtered by scope restriction.
static saveObjRecSelection($a_obj_id, $a_sub_type="", array $a_records=null, $a_delete_before=true)
Save repository object record selection.
xmlEndTag($tag)
Writes an endtag.
static _getSelectedRecordsByObject($a_obj_type, $a_ref_id, $a_sub_type="")
Get selected records by object.
isActive()
Check if record is active.
setDescription($a_description)
set description
static _delete($a_record_id)
Delete record and all related data.
setGlobalPosition(int $position)
Set global position.
toXML(ilXmlWriter $writer)
To Xml.
static _getInstanceByRecordId($a_record_id)
Get instance by record id.
static getInstancesByRecordId($a_record_id, $a_only_searchable=false)
Get definitions by record id.
enableScope($a_stat)
Enable scope restrictions.
foreach($_POST as $key=> $value) $res
static _lookupObjId($a_id)
getRecordId()
Get record id.
__construct($a_record_id=0)
Singleton constructor To create an array of new records (without saving them) call the constructor di...
validate()
Validate settings.
getAssignedObjectTypes()
Get assigned object types.
static _getAllRecordsByObjectType()
Get records by obj_type Note: this returns only records with no sub types! public.
setImportId($a_id_string)
set import id
static _lookupTitle($a_record_id)
Lookup title.
static _lookupType($a_id, $a_reference=false)
lookup object type
static _getActivatedRecordsByObjectType($a_obj_type, $a_sub_type="", $a_only_optional=false)
Get activated records by object type.
xmlElement($tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
setTitle($a_title)
Set title.
enabledScope()
Is scope enabled.
read()
read record and assiged object types
static _getAssignableObjectTypes($a_include_text=false)
Get assignable object type.
setAssignedObjectTypes($a_obj_types)
Set assigned object types.
getImportId()
get import id
static _getActivatedObjTypes()
get activated obj types
isAssignedObjectType($a_obj_type, $a_sub_type)
Is assigned object type?
_clone(array &$a_fields_map, $a_parent_obj_id=null)
Clone record.
setParentObject($a_obj_id)
static getObjRecSelection($a_obj_id, $a_sub_type="")
Get repository object record selection.
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.
static _lookupContainerSetting($a_id, $a_keyword, $a_default_value=null)
Lookup a container setting.
static _lookupRecordIdByImportId($a_ilias_id)
Lookup record Id by import id.
generateImportId()
generate unique record id