5 include_once
'./Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordScope.php';
50 $this->record_id = $a_record_id;
69 if (isset(self::$instances[$a_record_id])) {
70 return self::$instances[$a_record_id];
86 $query =
"SELECT DISTINCT(amr.record_id) FROM adv_md_record amr " .
87 "JOIN adv_mdf_definition amfd ON amr.record_id = amfd.record_id " .
88 "WHERE searchable = 1 AND active = 1 ";
92 $records[] = self::_getInstanceByRecordId(
$row->record_id);
107 static $title_cache =
array();
109 if (isset($title_cache[$a_record_id])) {
110 return $title_cache[$a_record_id];
115 $query =
"SELECT title FROM adv_md_record " .
116 "WHERE record_id = " . $ilDB->quote($a_record_id,
'integer') .
" ";
120 return $title_cache[$a_record_id] =
$row->title;
135 $query =
"SELECT record_id FROM adv_md_record " .
136 "WHERE import_id = " . $ilDB->quote($a_ilias_id,
'text') .
" ";
139 return $row->record_id;
152 global $objDefinition,
$lng;
155 $amet_types = $objDefinition->getAdvancedMetaDataTypes();
157 foreach ($amet_types as $at) {
158 if ($a_include_text) {
159 $text = $lng->txt(
"obj_" . $at[
"obj_type"]);
160 if ($at[
"sub_type"] !=
"") {
161 $lng->loadLanguageModule($at[
"obj_type"]);
162 $text.=
": " . $lng->txt($at[
"obj_type"] .
"_" . $at[
"sub_type"]);
164 $at[
"sub_type"] =
"-";
188 $query =
"SELECT DISTINCT(obj_type) FROM adv_md_record_objs amo " .
189 "JOIN adv_md_record amr ON amo.record_id = amr.record_id " .
211 $query =
"SELECT record_id FROM adv_md_record ";
233 $query =
"SELECT * FROM adv_md_record_objs WHERE sub_type=" . $ilDB->quote(
"-",
"text");
256 if ($a_sub_type ==
"") {
260 $query =
"SELECT amro.record_id record_id FROM adv_md_record_objs amro " .
261 "JOIN adv_md_record amr ON amr.record_id = amro.record_id " .
262 "WHERE active = 1 " .
263 "AND obj_type = " . $ilDB->quote($a_obj_type,
'text') .
" " .
264 "AND sub_type = " . $ilDB->quote($a_sub_type,
'text');
266 if ($a_only_optional) {
267 $query .=
" AND optional =" . $ilDB->quote(1,
'integer');
271 $query .=
"ORDER by parent_obj DESC, record_id";
275 $records[] = self::_getInstanceByRecordId(
$row->record_id);
293 if ($a_sub_type ==
"") {
300 include_once
'Services/Container/classes/class.ilContainer.php';
301 include_once
'Services/Object/classes/class.ilObjectServiceSettingsGUI.php';
309 foreach (self::_getActivatedRecordsByObjectType($a_obj_type, $a_sub_type) as $record) {
311 if (self::isFilteredByScope($a_ref_id, $record->getScopes())) {
315 foreach ($record->getAssignedObjectTypes() as $item) {
316 if ($record->getParentObject()) {
318 if ($record->getParentObject() != $a_obj_id) {
322 elseif (!$config_setting) {
327 if ($item[
'obj_type'] == $a_obj_type &&
328 $item[
'sub_type'] == $a_sub_type) {
329 if ($item[
'optional']) {
330 $optional[] = $record->getRecordId();
332 $records[$record->getRecordId()] = $record;
338 if (!$config_setting && !in_array($a_sub_type,
array(
"orgu_type",
"prg_type"))) {
341 $selected = self::getObjRecSelection($a_obj_id, $a_sub_type);
344 if (!in_array($record_id, $selected)) {
360 $tree =
$GLOBALS[
'DIC']->repositoryTree();
361 $logger =
$GLOBALS[
'DIC']->logger()->amet();
363 if (!count($scopes)) {
364 $logger->debug(
'No md scope restrictions.');
367 foreach ($scopes as $scope) {
368 $logger->debug(
'Comparing: ' . $a_ref_id .
' with: ' . $scope->getRefId());
369 if ($scope->getRefId() == $a_ref_id) {
370 $logger->debug(
'Elements are equal. No scope restrictions.');
374 $logger->debug(
'Node is child node. No scope restrictions.');
378 $logger->info(
'Scope filter matches.');
401 $query =
"DELETE FROM adv_md_record " .
402 "WHERE record_id = " . $ilDB->quote($a_record_id,
'integer') .
" ";
405 $query =
"DELETE FROM adv_md_record_objs " .
406 "WHERE record_id = " . $ilDB->quote($a_record_id,
'integer') .
" ";
417 public function delete()
438 $this->scope_enabled = $a_stat;
447 $this->scopes = $a_scopes;
466 foreach ($this->scopes as $scope) {
467 $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) " .
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') .
", " .
495 $this->record_id = $next_id;
499 $query =
"UPDATE adv_md_record " .
500 "SET import_id = " . $this->db->quote($this->
generateImportId(),
'text') .
" " .
501 "WHERE record_id = " . $this->db->quote($this->record_id,
'integer') .
" ";
508 $query =
"INSERT INTO adv_md_record_objs (record_id,obj_type,sub_type,optional) " .
510 $this->db->quote($this->
getRecordId(),
'integer') .
", " .
511 $this->db->quote($type[
"obj_type"],
'text') .
", " .
512 $this->db->quote($type[
"sub_type"],
'text') .
", " .
513 $this->db->quote($type[
"optional"],
'integer') .
" " .
534 $query =
"UPDATE adv_md_record " .
535 "SET active = " . $this->db->quote($this->
isActive(),
'integer') .
", " .
536 "title = " . $this->db->quote($this->
getTitle(),
'text') .
", " .
537 "description = " . $this->db->quote($this->
getDescription(),
'text') .
" " .
538 "WHERE record_id = " . $this->db->quote($this->
getRecordId(),
'integer') .
" ";
542 $query =
"DELETE FROM adv_md_record_objs " .
543 "WHERE record_id = " . $this->db->quote($this->
getRecordId(),
'integer') .
" ";
548 $query =
"INSERT INTO adv_md_record_objs (record_id,obj_type,sub_type,optional) " .
550 $this->db->quote($this->
getRecordId(),
'integer') .
", " .
551 $this->db->quote($type[
"obj_type"],
'text') .
", " .
552 $this->db->quote($type[
"sub_type"],
'text') .
", " .
553 $this->db->quote($type[
"optional"],
'integer') .
" " .
598 $this->active = $a_active;
621 $this->title = $a_title;
644 $this->description = $a_description;
667 $this->import_id = $a_id_string;
690 $this->obj_types = $a_obj_types;
702 $this->obj_types[] =
array(
703 "obj_type"=>$a_obj_type,
704 "sub_type"=>$a_sub_type,
705 "optional"=>(
bool) $a_optional
717 return $this->obj_types ? $this->obj_types :
array();
729 if ($t[
"obj_type"] == $a_obj_type &&
730 $t[
"sub_type"] == $a_sub_type) {
739 $this->parent_obj = $a_obj_id;
764 $optional =
array(
"optional"=>$obj_type[
"optional"]);
765 if ($obj_type[
"sub_type"] ==
"") {
766 $writer->
xmlElement(
'ObjectType', $optional, $obj_type[
"obj_type"]);
768 $writer->
xmlElement(
'ObjectType', $optional, $obj_type[
"obj_type"] .
":" . $obj_type[
"sub_type"]);
778 $writer->
xmlElement(
'ScopeEntry', [
'id' =>
'il_' . IL_INST_ID .
'_' .
$type .
'_' . $ref_id]);
785 include_once(
'Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
787 $definition->toXML($writer);
803 $query =
"SELECT * FROM adv_md_record " .
804 "WHERE record_id = " . $this->db->quote($this->
getRecordId(),
'integer') .
" ";
813 $query =
"SELECT * FROM adv_md_record_objs " .
814 "WHERE record_id = " . $this->db->quote($this->
getRecordId(),
'integer') .
" ";
817 $this->obj_types[] =
array(
818 "obj_type" =>
$row->obj_type,
819 "sub_type" =>
$row->sub_type,
820 "optional" => (
bool)
$row->optional
824 $query =
'SELECT scope_id FROM adv_md_record_scope ' .
825 'WHERE record_id = ' . $ilDB->quote($this->record_id);
827 $this->scope_enabled =
false;
830 $this->scope_enabled =
true;
843 return 'il_' . IL_INST_ID .
'_adv_md_record_' . $this->
getRecordId();
867 if ($a_sub_type ==
"") {
871 if ((
bool) $a_delete_before) {
872 $ilDB->manipulate(
"DELETE FROM adv_md_obj_rec_select WHERE " .
873 " obj_id = " . $ilDB->quote($a_obj_id,
"integer") .
874 " AND sub_type = " . $ilDB->quote($a_sub_type,
"text"));
877 if (is_array($a_records)) {
878 foreach ($a_records as
$r) {
880 $ilDB->manipulate(
"INSERT INTO adv_md_obj_rec_select " .
881 "(obj_id, rec_id, sub_type) VALUES (" .
882 $ilDB->quote($a_obj_id,
"integer") .
"," .
883 $ilDB->quote($r,
"integer") .
"," .
884 $ilDB->quote($a_sub_type,
"text") .
901 if ($a_sub_type ==
"") {
907 $r =
"SELECT * FROM adv_md_obj_rec_select " .
908 " WHERE obj_id = " . $ilDB->quote($a_obj_id,
"integer") .
909 " AND sub_type = " . $ilDB->quote($a_sub_type,
"text")
911 while ($rec = $ilDB->fetchAssoc($set)) {
912 $recs[] = $rec[
"rec_id"];
924 public function _clone(
array &$a_fields_map, $a_parent_obj_id = null)
926 $new_obj =
new self();
927 $new_obj->setActive($this->
isActive());
928 $new_obj->setTitle($this->
getTitle());
930 $new_obj->setParentObject($a_parent_obj_id
936 include_once(
'Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
938 $new_def = $definition->_clone($new_obj->getRecordId());
939 $a_fields_map[$definition->getFieldId()] = $new_def->getFieldId();
956 $sel = array_intersect(
963 foreach (self::_getRecords() as $record) {
965 if ($record->getParentObject()) {
970 if (!$record->isActive()) {
975 foreach ($record->getAssignedObjectTypes() as $item) {
976 if ($item[
"obj_type"] == $obj_type &&
977 $item[
"sub_type"] == $a_sub_type) {
979 if (!$item[
"optional"]) {
980 $res[] = $record->getRecordId();
983 elseif (in_array($record->getRecordId(), $sel)) {
984 $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 _getRecords()
Get records.
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.
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
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.
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.
Create styles array
The data for the language used.
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.
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