4 include_once
"Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php";
39 public function __construct($a_record_id, $a_obj_id, $a_sub_type =
"-", $a_sub_id = 0)
41 $this->record_id = (int)$a_record_id;
42 $this->obj_id = (int)$a_obj_id;
43 $this->sub_type = $a_sub_type ? $a_sub_type :
"-";
44 $this->sub_id = (int)$a_sub_id;
63 include_once
"Services/AdvancedMetaData/classes/class.ilAdvancedMDRecord.php";
66 $id = $record->getRecordId();
67 $res[$id] =
new self($id, $a_obj_id, $a_sub_type, $a_sub_id);
82 $this->obj_id = (int)$a_obj_id;
83 $this->sub_type = $a_sub_type ? $a_sub_type :
"-";
84 $this->sub_id = (int)$a_sub_id;
87 $this->active_record = null;
97 if(!is_array($this->defs))
127 include_once
"Services/ADT/classes/class.ilADTFactory.php";
130 $adt_group_db = $factory->getDBBridgeForInstance($this->
getADTGroup());
133 "obj_id" =>
array(
"integer", $this->obj_id),
134 "sub_type" =>
array(
"text", $this->sub_type),
135 "sub_id" =>
array(
"integer", $this->sub_id)
137 $adt_group_db->setPrimary($primary);
138 $adt_group_db->setTable(
"adv_md_values");
141 foreach($adt_group_db->getElements() as $element)
143 if($element->getADT()->getType() ==
"MultiEnum")
145 $element->setFakeSingle(
true);
149 $this->active_record = $factory->getActiveRecordByTypeInstance($adt_group_db);
150 $this->active_record->setElementIdColumn(
"field_id",
"integer");
164 include_once
"Services/ADT/classes/class.ilADTFactory.php";
184 if(is_array($this->disabled))
186 return in_array($a_element_id, $this->disabled);
200 $this->disabled =
array();
205 foreach($tmp as $element_id =>
$data)
207 if(
$data[
"disabled"])
209 $this->disabled[] = $element_id;
237 array(
"field_id"=>
array(
"integer", $a_field_id)),
251 array(
"obj_id"=>
array(
"integer", $a_obj_id)));
273 array(
"obj_id"=>
array(
"integer", $a_obj_ids)));
278 self::$preload_obj_records =
array();
282 " FROM adv_md_record_objs amro".
283 " JOIN adv_md_record amr ON (amr.record_id = amro.record_id)".
284 " WHERE active = ".$ilDB->quote(1,
"integer");
285 $set = $ilDB->query(
$query);
286 while(
$row = $ilDB->fetchAssoc($set))
288 self::$preload_obj_records[
$row[
"obj_type"]][] =
array($row[
"record_id"], $row[
"optional"]);
296 if(isset(self::$preload_obj_records[
$a_type]))
298 foreach(self::$preload_obj_records[$a_type] as $item)
306 include_once
"Services/AdvancedMetaData/classes/class.ilAdvancedMDRecord.php";
309 if($record->getRecordId() == $item[0])
342 public static function _cloneValues($a_source_id,$a_target_id,$a_sub_type = null,$a_source_sub_id = null,$a_target_sub_id=null)
349 include_once
"Services/AdvancedMetaData/classes/class.ilAdvancedMDRecord.php";
350 $new_records = $fields_map =
array();
354 if($record->getParentObject() == $a_source_id)
357 if($a_source_id != $a_target_id)
359 $new_records[$record->getRecordId()] = $record->_clone($tmp, $a_target_id);
363 $new_records[$record->getRecordId()] = $record->getRecordId();
365 $fields_map[$record->getRecordId()] = $tmp;
375 $target_sel =
array();
379 if(array_key_exists($record_id, $new_records))
381 $record_id = $new_records[
$record_id]->getRecordId();
390 $source_primary =
array(
"obj_id"=>
array(
"integer", $a_source_id));
391 $target_primary =
array(
"obj_id"=>
array(
"integer", $a_target_id));
398 $source_primary[
"sub_type"] =
array(
"text", $a_sub_type);
399 $source_primary[
"sub_id"] =
array(
"integer", $a_source_sub_id);
400 $target_primary[
"sub_type"] =
array(
"text", $a_sub_type);
401 $target_primary[
"sub_id"] =
array(
"integer", $a_target_sub_id);
408 "obj_id" =>
"integer",
409 "sub_type" =>
"text",
410 "sub_id" =>
"integer",
411 "field_id" =>
"integer" 415 array(
"disabled"=>
"integer"));
420 foreach($fields_map as $source_record_id => $fields)
423 if(array_key_exists($source_record_id, $new_records))
425 foreach($fields as $source_field_id => $target_field_id)
428 $del_target_primary = $target_primary;
429 $del_target_primary[
"field_id"] =
array(
"integer", $source_field_id);
433 $fix_source_primary = $source_primary;
434 $fix_source_primary[
"field_id"] =
array(
"integer", $source_field_id);
435 $fix_target_primary = $target_primary;
436 $fix_target_primary[
"field_id"] =
array(
"integer", $target_field_id);
440 "obj_id" =>
"integer",
441 "sub_type" =>
"text",
442 "sub_id" =>
"integer",
443 "field_id" =>
"integer" 447 array(
"disabled"=>
"integer"));
454 $ilLog->write(__METHOD__.
': No advanced meta data found.');
458 $ilLog->write(__METHOD__.
': Start cloning advanced meta data.');
473 self::preloadByObjIds(
array($a_obj_id));
476 foreach($values_records as $values_record)
478 $defs = $values_record->getDefinitions();
479 foreach($values_record->getADTGroup()->getElements() as $element_id => $element)
481 $def =
$defs[$element_id];
484 if(!$element->isNull())
486 $value = $def->getValueForXML($element);
491 array(
'id' => $def->getImportId()),
497 $a_xml_writer->
xmlEndTag(
'AdvancedMetaData');
511 static public function queryForRecords($a_obj_id, $a_subtype, $a_records, $a_obj_id_key, $a_obj_subid_key,
array $a_amet_filter = null)
515 if (!is_array($a_obj_id))
517 $a_obj_id =
array($a_obj_id);
520 $sub_obj_ids =
array();
521 foreach($a_records as $rec)
523 $sub_obj_ids[] = $rec[$a_obj_subid_key];
530 "obj_id" =>
array(
"integer", $a_obj_id),
531 "sub_type" =>
array(
"text", $a_subtype),
532 "sub_id" =>
array(
"integer", $sub_obj_ids)
535 $record_groups =
array();
537 foreach($a_records as $rec)
540 $sub_id = $rec[$a_obj_subid_key];
552 $record_groups[
$record_id]->setTable(
"adv_md_values");
558 "sub_type" =>
array(
"text", $a_subtype),
563 foreach($record_groups[$record_id]->getElements() as $element)
565 if($element->getADT()->getType() ==
"MultiEnum")
567 $element->setFakeSingle(
true);
581 foreach($a_amet_filter as $field_id => $element)
585 if(!$element->isInCondition(
$adt_group->getElement($field_id)))
594 foreach(
$adt_group->getElements() as $element_id => $element)
596 if(!$element->isNull())
600 $rec[
"md_".$element_id] = $pb->getSortable();
601 $rec[
"md_".$element_id.
"_presentation"] = $pb;
606 $rec[
"md_".$element_id] = null;
getType()
Get type (from class/instance)
static getInstancesForObjectId($a_obj_id, $a_obj_type=null, $a_sub_type="-", $a_sub_id=0)
Get instances for given object id.
ADT Active Record by type helper class.
static _getRecords()
Get records.
static initActiveRecordByType()
Init active record by type.
static preloadByObjIds(array $a_obj_ids)
Preload list gui data.
xmlStartTag($tag, $attrs=NULL, $empty=FALSE, $encode=TRUE, $escape=TRUE)
Writes a starttag.
static getADTGroupForDefinitions(array $a_defs)
Init ADTGroup for definitions.
xmlElement($tag, $attrs=NULL, $data=Null, $encode=TRUE, $escape=TRUE)
Writes a basic element (no children, just textual content)
static _appendXMLByObjId(ilXmlWriter $a_xml_writer, $a_obj_id)
Get xml of object values.
static _deleteByFieldId($a_field_id, ilADT $a_adt)
Delete values by field_id.
static getInstance()
Get singleton.
static preloadByPrimary($a_table, array $a_primary)
Read values by (partial) primary key.
static saveObjRecSelection($a_obj_id, $a_sub_type="", array $a_records=null, $a_delete_before=true)
Save repository object record selection.
static cloneByPrimary($a_table, array $a_primary_def, array $a_source_primary, array $a_target_primary, array $a_additional=null)
Clone values by (partial) primary key.
xmlEndTag($tag)
Writes an endtag.
static _deleteByObjId($a_obj_id)
Delete by objekt id.
setActiveRecordPrimary($a_obj_id, $a_sub_type="-", $a_sub_id=0)
Set the primary values for active record.
static findByObjectId($a_obj_id)
Find all entries for object (regardless of sub-type/sub-id)
static getInstancesByRecordId($a_record_id, $a_only_searchable=false)
Get definitions by record id.
static _cloneValues($a_source_id, $a_target_id, $a_sub_type=null, $a_source_sub_id=null, $a_target_sub_id=null)
Clone Advanced Meta Data.
getActiveRecord()
Init ADT DB Bridge (aka active record helper class)
static deleteByPrimary($a_table, array $a_primary, $a_type=null)
Delete values by (partial) primary key.
__construct($a_record_id, $a_obj_id, $a_sub_type="-", $a_sub_id=0)
Constructor.
static readByPrimary($a_table, array $a_primary, $a_type=null)
Read directly.
getADTGroup()
Init ADT group for current record.
static _getSelectedRecordsByObject($a_obj_type, $a_obj_id, $a_sub_type="")
Get selected records by object.
Create styles array
The data for the language used.
static _lookupType($a_id, $a_reference=false)
lookup object type
isDisabled($a_element_id)
Is element disabled?
write(array $a_additional_data=null)
Write record values.
static queryForRecords($a_obj_id, $a_subtype, $a_records, $a_obj_id_key, $a_obj_subid_key, array $a_amet_filter=null)
Query data for given object records.
static preloadedRead($a_type, $a_obj_id)
static $preload_obj_records
static getObjRecSelection($a_obj_id, $a_sub_type="")
Get repository object record selection.
getDefinitions()
Get record field definitions.