41 $this->record_id = $a_record_id;
60 if(isset(self::$instances[$a_record_id]))
62 return self::$instances[$a_record_id];
78 $query =
"SELECT DISTINCT(amr.record_id) FROM adv_md_record amr ".
79 "JOIN adv_mdf_definition amfd ON amr.record_id = amfd.record_id ".
80 "WHERE searchable = 1 AND active = 1 ";
85 $records[] = self::_getInstanceByRecordId(
$row->record_id);
100 static $title_cache =
array();
102 if(isset($title_cache[$a_record_id]))
104 return $title_cache[$a_record_id];
109 $query =
"SELECT title FROM adv_md_record ".
110 "WHERE record_id = ".$ilDB->quote($a_record_id ,
'integer').
" ";
114 return $title_cache[$a_record_id] =
$row->title;
129 $query =
"SELECT record_id FROM adv_md_record ".
130 "WHERE import_id = ".$ilDB->quote($a_ilias_id ,
'text').
" ";
134 return $row->record_id;
147 global $objDefinition,
$lng;
150 $amet_types = $objDefinition->getAdvancedMetaDataTypes();
152 foreach ($amet_types as $at)
156 $text = $lng->txt(
"obj_".$at[
"obj_type"]);
157 if ($at[
"sub_type"] !=
"")
159 $lng->loadLanguageModule($at[
"obj_type"]);
160 $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 ";
234 $query =
"SELECT * FROM adv_md_record_objs WHERE sub_type=".$ilDB->quote(
"-",
"text");
257 if ($a_sub_type ==
"")
262 $query =
"SELECT amro.record_id record_id FROM adv_md_record_objs amro ".
263 "JOIN adv_md_record amr ON amr.record_id = amro.record_id ".
265 "AND obj_type = ".$ilDB->quote($a_obj_type ,
'text').
" ".
266 "AND sub_type = ".$ilDB->quote($a_sub_type ,
'text');
270 $query .=
" AND optional =".$ilDB->quote(1,
'integer');
274 $query .=
"ORDER by parent_obj DESC, record_id";
279 $records[] = self::_getInstanceByRecordId(
$row->record_id);
296 if ($a_sub_type ==
"")
302 include_once
'Services/Container/classes/class.ilContainer.php';
303 include_once
'Services/Object/classes/class.ilObjectServiceSettingsGUI.php';
310 foreach(self::_getActivatedRecordsByObjectType($a_obj_type, $a_sub_type) as $record)
312 foreach($record->getAssignedObjectTypes() as $item)
314 if($record->getParentObject())
317 if($record->getParentObject() != $a_obj_id)
322 else if(!$config_setting)
328 if($item[
'obj_type'] == $a_obj_type &&
329 $item[
'sub_type'] == $a_sub_type)
331 if($item[
'optional'])
333 $optional[] = $record->getRecordId();
335 $records[$record->getRecordId()] = $record;
342 if(!$config_setting && !in_array($a_sub_type,
array(
"orgu_type",
"prg_type")))
348 $selected = self::getObjRecSelection($a_obj_id, $a_sub_type);
352 if(!in_array($record_id, $selected))
398 $query =
"DELETE FROM adv_md_record ".
399 "WHERE record_id = ".$ilDB->quote($a_record_id ,
'integer').
" ";
402 $query =
"DELETE FROM adv_md_record_objs ".
403 "WHERE record_id = ".$ilDB->quote($a_record_id ,
'integer').
" ";
414 public function delete()
430 $next_id = $ilDB->nextId(
'adv_md_record');
432 $query =
"INSERT INTO adv_md_record (record_id,import_id,active,title,description,parent_obj) ".
434 $ilDB->quote($next_id,
'integer').
", ".
435 $this->db->quote($this->
getImportId(),
'text').
", ".
436 $this->db->quote($this->
isActive() ,
'integer').
", ".
437 $this->db->quote($this->
getTitle() ,
'text').
", ".
442 $this->record_id = $next_id;
447 $query =
"UPDATE adv_md_record ".
449 "WHERE record_id = ".$this->db->quote($this->record_id ,
'integer').
" ";
457 $query =
"INSERT INTO adv_md_record_objs (record_id,obj_type,sub_type,optional) ".
459 $this->db->quote($this->
getRecordId() ,
'integer').
", ".
460 $this->db->quote($type[
"obj_type"] ,
'text').
", ".
461 $this->db->quote($type[
"sub_type"] ,
'text').
", ".
462 $this->db->quote($type[
"optional"] ,
'integer').
" ".
478 $query =
"UPDATE adv_md_record ".
479 "SET active = ".$this->db->quote($this->
isActive() ,
'integer').
", ".
480 "title = ".$this->db->quote($this->
getTitle() ,
'text').
", ".
481 "description = ".$this->db->quote($this->
getDescription() ,
'text').
" ".
482 "WHERE record_id = ".$this->db->quote($this->
getRecordId() ,
'integer').
" ";
486 $query =
"DELETE FROM adv_md_record_objs ".
487 "WHERE record_id = ".$this->db->quote($this->
getRecordId() ,
'integer').
" ";
493 $query =
"INSERT INTO adv_md_record_objs (record_id,obj_type,sub_type,optional) ".
495 $this->db->quote($this->
getRecordId() ,
'integer').
", ".
496 $this->db->quote($type[
"obj_type"] ,
'text').
", ".
497 $this->db->quote($type[
"sub_type"] ,
'text').
", ".
498 $this->db->quote($type[
"optional"] ,
'integer').
" ".
539 $this->active = $a_active;
562 $this->title = $a_title;
585 $this->description = $a_description;
608 $this->import_id = $a_id_string;
631 $this->obj_types = $a_obj_types;
643 $this->obj_types[] =
array(
644 "obj_type"=>$a_obj_type,
645 "sub_type"=>$a_sub_type,
646 "optional"=>(
bool)$a_optional
658 return $this->obj_types ? $this->obj_types :
array();
671 if ($t[
"obj_type"] == $a_obj_type &&
672 $t[
"sub_type"] == $a_sub_type)
682 $this->parent_obj = $a_obj_id;
708 $optional =
array(
"optional"=>$obj_type[
"optional"]);
709 if ($obj_type[
"sub_type"] ==
"")
711 $writer->
xmlElement(
'ObjectType',$optional,$obj_type[
"obj_type"]);
715 $writer->
xmlElement(
'ObjectType',$optional,$obj_type[
"obj_type"].
":".$obj_type[
"sub_type"]);
719 include_once(
'Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
722 $definition->toXML($writer);
738 $query =
"SELECT * FROM adv_md_record ".
739 "WHERE record_id = ".$this->db->quote($this->
getRecordId() ,
'integer').
" ";
749 $query =
"SELECT * FROM adv_md_record_objs ".
750 "WHERE record_id = ".$this->db->quote($this->
getRecordId() ,
'integer').
" ";
754 $this->obj_types[] =
array(
755 "obj_type" =>
$row->obj_type,
756 "sub_type" =>
$row->sub_type,
757 "optional" => (
bool)
$row->optional
770 return 'il_'.IL_INST_ID.
'_adv_md_record_'.$this->
getRecordId();
794 if ($a_sub_type ==
"")
799 if((
bool)$a_delete_before)
801 $ilDB->manipulate(
"DELETE FROM adv_md_obj_rec_select WHERE ".
802 " obj_id = ".$ilDB->quote($a_obj_id,
"integer").
803 " AND sub_type = ".$ilDB->quote($a_sub_type,
"text"));
806 if (is_array($a_records))
808 foreach ($a_records as
$r)
812 $ilDB->manipulate(
"INSERT INTO adv_md_obj_rec_select ".
813 "(obj_id, rec_id, sub_type) VALUES (".
814 $ilDB->quote($a_obj_id,
"integer").
",".
815 $ilDB->quote($r,
"integer").
",".
816 $ilDB->quote($a_sub_type,
"text").
833 if ($a_sub_type ==
"")
839 $set = $ilDB->query(
$r =
"SELECT * FROM adv_md_obj_rec_select ".
840 " WHERE obj_id = ".$ilDB->quote($a_obj_id,
"integer").
841 " AND sub_type = ".$ilDB->quote($a_sub_type,
"text")
843 while ($rec = $ilDB->fetchAssoc($set))
845 $recs[] = $rec[
"rec_id"];
857 public function _clone(
array &$a_fields_map, $a_parent_obj_id = null)
859 $new_obj =
new self();
860 $new_obj->setActive($this->
isActive());
861 $new_obj->setTitle($this->
getTitle());
863 $new_obj->setParentObject($a_parent_obj_id
869 include_once(
'Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
872 $new_def = $definition->_clone($new_obj->getRecordId());
873 $a_fields_map[$definition->getFieldId()] = $new_def->getFieldId();
890 $sel = array_intersect(
897 foreach(self::_getRecords() as $record)
900 if($record->getParentObject())
906 if(!$record->isActive())
912 foreach($record->getAssignedObjectTypes() as $item)
914 if($item[
"obj_type"] == $obj_type &&
915 $item[
"sub_type"] == $a_sub_type)
918 if(!$item[
"optional"])
920 $res[] = $record->getRecordId();
923 else if(in_array($record->getRecordId(), $sel))
925 $res[] = $record->getRecordId();
static _getRecords()
Get records.
static getSharedRecords($a_obj1_id, $a_obj2_id, $a_sub_type="-")
Get shared records.
getDescription()
get description
setActive($a_active)
Set active.
xmlStartTag($tag, $attrs=NULL, $empty=FALSE, $encode=TRUE, $escape=TRUE)
Writes a starttag.
xmlElement($tag, $attrs=NULL, $data=Null, $encode=TRUE, $escape=TRUE)
Writes a basic element (no children, just textual content)
static _getActiveSearchableRecords()
Get active searchable records.
appendAssignedObjectType($a_obj_type, $a_sub_type, $a_optional=false)
append assigned object types
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.
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.
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...
static _getSelectedRecordsByObject($a_obj_type, $a_obj_id, $a_sub_type="")
Get selected records by object.
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.
static _lookupContainerSetting($a_id, $a_keyword, $a_default_value=NULL)
Lookup a container setting.
setTitle($a_title)
Set title.
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 _lookupRecordIdByImportId($a_ilias_id)
Lookup record Id by import id.
generateImportId()
generate unique record id