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').
" ".
517 $ilErr->setMessage(
'fill_out_all_required_fields');
543 $this->active = $a_active;
566 $this->title = $a_title;
589 $this->description = $a_description;
612 $this->import_id = $a_id_string;
635 $this->obj_types = $a_obj_types;
647 $this->obj_types[] = array(
648 "obj_type"=>$a_obj_type,
649 "sub_type"=>$a_sub_type,
650 "optional"=>(
bool)$a_optional
662 return $this->obj_types ? $this->obj_types : array();
675 if ($t[
"obj_type"] == $a_obj_type &&
676 $t[
"sub_type"] == $a_sub_type)
686 $this->parent_obj = $a_obj_id;
712 $optional = array(
"optional"=>$obj_type[
"optional"]);
713 if ($obj_type[
"sub_type"] ==
"")
715 $writer->
xmlElement(
'ObjectType',$optional,$obj_type[
"obj_type"]);
719 $writer->
xmlElement(
'ObjectType',$optional,$obj_type[
"obj_type"].
":".$obj_type[
"sub_type"]);
723 include_once(
'Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
726 $definition->toXML($writer);
742 $query =
"SELECT * FROM adv_md_record ".
743 "WHERE record_id = ".$this->db->quote($this->
getRecordId() ,
'integer').
" ";
753 $query =
"SELECT * FROM adv_md_record_objs ".
754 "WHERE record_id = ".$this->db->quote($this->
getRecordId() ,
'integer').
" ";
758 $this->obj_types[] = array(
759 "obj_type" =>
$row->obj_type,
760 "sub_type" =>
$row->sub_type,
761 "optional" => (
bool)
$row->optional
774 return 'il_'.IL_INST_ID.
'_adv_md_record_'.$this->
getRecordId();
794 static function saveObjRecSelection($a_obj_id, $a_sub_type =
"", array $a_records = null, $a_delete_before =
true)
798 if ($a_sub_type ==
"")
803 if((
bool)$a_delete_before)
805 $ilDB->manipulate(
"DELETE FROM adv_md_obj_rec_select WHERE ".
806 " obj_id = ".$ilDB->quote($a_obj_id,
"integer").
807 " AND sub_type = ".$ilDB->quote($a_sub_type,
"text"));
810 if (is_array($a_records))
812 foreach ($a_records as
$r)
816 $ilDB->manipulate(
"INSERT INTO adv_md_obj_rec_select ".
817 "(obj_id, rec_id, sub_type) VALUES (".
818 $ilDB->quote($a_obj_id,
"integer").
",".
819 $ilDB->quote($r,
"integer").
",".
820 $ilDB->quote($a_sub_type,
"text").
837 if ($a_sub_type ==
"")
843 $set = $ilDB->query(
$r =
"SELECT * FROM adv_md_obj_rec_select ".
844 " WHERE obj_id = ".$ilDB->quote($a_obj_id,
"integer").
845 " AND sub_type = ".$ilDB->quote($a_sub_type,
"text")
847 while ($rec = $ilDB->fetchAssoc($set))
849 $recs[] = $rec[
"rec_id"];
static _getRecords()
Get 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.
const DB_FETCHMODE_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.
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 Write error message to ilErr.
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 _getActivatedRecordsByObjectType($a_obj_type, $a_sub_type="", $a_only_optional=false)
Get activated records by object type.
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
_lookupContainerSetting($a_id, $a_keyword, $a_default_value=NULL)
Lookup a container setting.
static _getActivatedObjTypes()
get activated obj types
isAssignedObjectType($a_obj_type, $a_sub_type)
Is assigned object type?
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