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);
80 if(!is_array($this->defs))
110 include_once
"Services/ADT/classes/class.ilADTFactory.php";
113 $adt_group_db = $factory->getDBBridgeForInstance($this->
getADTGroup());
116 "obj_id" => array(
"integer", $this->obj_id),
117 "sub_type" => array(
"text", $this->sub_type),
118 "sub_id" => array(
"integer", $this->sub_id)
120 $adt_group_db->setPrimary($primary);
121 $adt_group_db->setTable(
"adv_md_values");
124 foreach($adt_group_db->getElements() as $element)
126 if($element->getADT()->getType() ==
"MultiEnum")
128 $element->setFakeSingle(
true);
132 $this->active_record = $factory->getActiveRecordByTypeInstance($adt_group_db);
133 $this->active_record->setElementIdColumn(
"field_id",
"integer");
147 include_once
"Services/ADT/classes/class.ilADTFactory.php";
167 if(is_array($this->disabled))
169 return in_array($a_element_id, $this->disabled);
183 $this->disabled = array();
188 foreach($tmp as $element_id =>
$data)
190 if(
$data[
"disabled"])
192 $this->disabled[] = $element_id;
203 public function write(array $a_additional_data = null)
220 array(
"field_id"=>array(
"integer", $a_field_id)),
234 array(
"obj_id"=>array(
"integer", $a_obj_id)));
256 array(
"obj_id"=>array(
"integer", $a_obj_ids)));
261 self::$preload_obj_records = array();
265 " FROM adv_md_record_objs amro".
266 " JOIN adv_md_record amr ON (amr.record_id = amro.record_id)".
267 " WHERE active = ".$ilDB->quote(1,
"integer");
268 $set = $ilDB->query(
$query);
269 while(
$row = $ilDB->fetchAssoc($set))
271 self::$preload_obj_records[
$row[
"obj_type"]][] = array($row[
"record_id"], $row[
"optional"]);
279 if(isset(self::$preload_obj_records[$a_type]))
281 foreach(self::$preload_obj_records[$a_type] as $item)
289 include_once
"Services/AdvancedMetaData/classes/class.ilAdvancedMDRecord.php";
292 if($record->getRecordId() == $item[0])
325 public static function _cloneValues($a_source_id,$a_target_id,$a_sub_type = null,$a_source_sub_id = null,$a_target_sub_id=null)
329 $source_primary = array(
"obj_id"=>array(
"integer", $a_source_id));
330 $target_primary = array(
"obj_id"=>array(
"integer", $a_target_id));
337 $source_primary[
"sub_type"] = array(
"text", $a_sub_type);
338 $source_primary[
"sub_id"] = array(
"integer", $a_source_sub_id);
339 $target_primary[
"sub_type"] = array(
"text", $a_sub_type);
340 $target_primary[
"sub_id"] = array(
"integer", $a_target_sub_id);
347 "obj_id" =>
"integer",
348 "sub_type" =>
"text",
349 "sub_id" =>
"integer",
350 "field_id" =>
"integer" 354 array(
"disabled"=>
"integer"));
358 $ilLog->write(__METHOD__.
': No advanced meta data found.');
362 $ilLog->write(__METHOD__.
': Start cloning advanced meta data.');
377 self::preloadByObjIds(array($a_obj_id));
380 foreach($values_records as $values_record)
382 $defs = $values_record->getDefinitions();
383 foreach($values_record->getADTGroup()->getElements() as $element_id => $element)
385 $def =
$defs[$element_id];
388 if(!$element->isNull())
390 $value = $def->getValueForXML($element);
395 array(
'id' => $def->getImportId()),
401 $a_xml_writer->
xmlEndTag(
'AdvancedMetaData');
415 static public function queryForRecords($a_obj_id, $a_subtype, $a_records, $a_obj_id_key, $a_obj_subid_key, array $a_amet_filter = null)
419 if (!is_array($a_obj_id))
421 $a_obj_id = array($a_obj_id);
424 $sub_obj_ids = array();
425 foreach($a_records as $rec)
427 $sub_obj_ids[] = $rec[$a_obj_subid_key];
434 "obj_id" => array(
"integer", $a_obj_id),
435 "sub_type" => array(
"text", $a_subtype),
436 "sub_id" => array(
"integer", $sub_obj_ids)
439 $record_groups = array();
441 foreach($a_records as $rec)
444 $sub_id = $rec[$a_obj_subid_key];
456 $record_groups[
$record_id]->setTable(
"adv_md_values");
461 "obj_id" => array(
"integer",
$obj_id),
462 "sub_type" => array(
"text", $a_subtype),
463 "sub_id" => array(
"integer",
$sub_id)
467 foreach($record_groups[$record_id]->getElements() as $element)
469 if($element->getADT()->getType() ==
"MultiEnum")
471 $element->setFakeSingle(
true);
485 foreach($a_amet_filter as $field_id => $element)
489 if(!$element->isInCondition(
$adt_group->getElement($field_id)))
498 foreach(
$adt_group->getElements() as $element_id => $element)
500 if(!$element->isNull())
504 $rec[
"md_".$element_id] = $pb->getSortable();
505 $rec[
"md_".$element_id.
"_presentation"] = $pb;
510 $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 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 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.
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.
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
getDefinitions()
Get record field definitions.