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;
64 foreach ($refs as $ref_id) {
65 include_once
"Services/AdvancedMetaData/classes/class.ilAdvancedMDRecord.php";
67 $id = $record->getRecordId();
70 $res[
$id] =
new self(
$id, $a_obj_id, $a_sub_type, $a_sub_id);
86 $this->obj_id = (int) $a_obj_id;
87 $this->sub_type = $a_sub_type ? $a_sub_type :
"-";
88 $this->sub_id = (int) $a_sub_id;
91 $this->active_record = null;
101 if (!is_array($this->defs)) {
114 if (!$this->adt_group instanceof
ilADTGroup) {
128 include_once
"Services/ADT/classes/class.ilADTFactory.php";
134 "obj_id" =>
array(
"integer", $this->obj_id),
135 "sub_type" =>
array(
"text", $this->sub_type),
136 "sub_id" =>
array(
"integer", $this->sub_id)
138 $adt_group_db->setPrimary($primary);
139 $adt_group_db->setTable(
"adv_md_values");
142 foreach ($adt_group_db->getElements() as $element) {
143 if ($element->getADT()->getType() ==
"MultiEnum") {
144 $element->setFakeSingle(
true);
148 $this->active_record =
$factory->getActiveRecordByTypeInstance($adt_group_db);
149 $this->active_record->setElementIdColumn(
"field_id",
"integer");
163 include_once
"Services/ADT/classes/class.ilADTFactory.php";
183 if (is_array($this->disabled)) {
184 return in_array($a_element_id, $this->disabled);
198 $this->disabled =
array();
202 foreach ($tmp as $element_id =>
$data) {
203 if (
$data[
"disabled"]) {
204 $this->disabled[] = $element_id;
232 array(
"field_id"=>
array(
"integer", $a_field_id)),
276 self::$preload_obj_records =
array();
279 $query =
"SELECT amro.*" .
280 " FROM adv_md_record_objs amro" .
281 " JOIN adv_md_record amr ON (amr.record_id = amro.record_id)" .
282 " WHERE active = " . $ilDB->quote(1,
"integer");
283 $set = $ilDB->query(
$query);
284 while (
$row = $ilDB->fetchAssoc($set)) {
285 self::$preload_obj_records[
$row[
"obj_type"]][] =
array($row[
"record_id"], $row[
"optional"]);
293 if (isset(self::$preload_obj_records[
$a_type])) {
294 foreach (self::$preload_obj_records[$a_type] as $item) {
300 include_once
"Services/AdvancedMetaData/classes/class.ilAdvancedMDRecord.php";
302 if ($record->getRecordId() == $item[0]) {
333 public static function _cloneValues($a_source_id, $a_target_id, $a_sub_type = null, $a_source_sub_id = null, $a_target_sub_id=null)
340 include_once
"Services/AdvancedMetaData/classes/class.ilAdvancedMDRecord.php";
341 $new_records = $fields_map =
array();
344 if ($record->getParentObject() == $a_source_id) {
346 if ($a_source_id != $a_target_id) {
347 $new_records[$record->getRecordId()] = $record->_clone($tmp, $a_target_id);
349 $new_records[$record->getRecordId()] = $record->getRecordId();
351 $fields_map[$record->getRecordId()] = $tmp;
360 $target_sel =
array();
363 if (array_key_exists($record_id, $new_records)) {
364 $record_id = $new_records[
$record_id]->getRecordId();
373 $source_primary =
array(
"obj_id"=>
array(
"integer", $a_source_id));
374 $target_primary =
array(
"obj_id"=>
array(
"integer", $a_target_id));
380 $source_primary[
"sub_type"] =
array(
"text", $a_sub_type);
381 $source_primary[
"sub_id"] =
array(
"integer", $a_source_sub_id);
382 $target_primary[
"sub_type"] =
array(
"text", $a_sub_type);
383 $target_primary[
"sub_id"] =
array(
"integer", $a_target_sub_id);
390 "obj_id" =>
"integer",
391 "sub_type" =>
"text",
392 "sub_id" =>
"integer",
393 "field_id" =>
"integer" 397 array(
"disabled"=>
"integer")
403 foreach ($fields_map as $source_record_id => $fields) {
405 if (array_key_exists($source_record_id, $new_records)) {
406 foreach ($fields as $source_field_id => $target_field_id) {
408 $del_target_primary = $target_primary;
409 $del_target_primary[
"field_id"] =
array(
"integer", $source_field_id);
413 $fix_source_primary = $source_primary;
414 $fix_source_primary[
"field_id"] =
array(
"integer", $source_field_id);
415 $fix_target_primary = $target_primary;
416 $fix_target_primary[
"field_id"] =
array(
"integer", $target_field_id);
420 "obj_id" =>
"integer",
421 "sub_type" =>
"text",
422 "sub_id" =>
"integer",
423 "field_id" =>
"integer" 427 array(
"disabled"=>
"integer")
434 $ilLog->write(__METHOD__ .
': No advanced meta data found.');
436 $ilLog->write(__METHOD__ .
': Start cloning advanced meta data.');
451 self::preloadByObjIds(
array($a_obj_id));
454 foreach ($values_records as $values_record) {
455 $defs = $values_record->getDefinitions();
456 foreach ($values_record->getADTGroup()->getElements() as $element_id => $element) {
460 if (!$element->isNull()) {
461 $value =
$def->getValueForXML($element);
472 $a_xml_writer->
xmlEndTag(
'AdvancedMetaData');
486 public static function queryForRecords($adv_rec_obj_ref_id, $adv_rec_obj_type, $adv_rec_obj_subtype, $a_obj_id, $a_subtype, $a_records, $a_obj_id_key, $a_obj_subid_key,
array $a_amet_filter = null)
490 if (!is_array($a_obj_id)) {
491 $a_obj_id =
array($a_obj_id);
494 $sub_obj_ids =
array();
495 foreach ($a_records as $rec) {
496 $sub_obj_ids[] = $rec[$a_obj_subid_key];
504 "obj_id" =>
array(
"integer", $a_obj_id),
505 "sub_type" =>
array(
"text", $a_subtype),
506 "sub_id" =>
array(
"integer", $sub_obj_ids)
510 $record_groups =
array();
512 foreach ($a_records as $rec) {
514 $sub_id = $rec[$a_obj_subid_key];
524 $record_groups[
$record_id]->setTable(
"adv_md_values");
530 "sub_type" =>
array(
"text", $a_subtype),
535 foreach ($record_groups[$record_id]->getElements() as $element) {
536 if ($element->getADT()->getType() ==
"MultiEnum") {
537 $element->setFakeSingle(
true);
549 if ($a_amet_filter) {
550 foreach ($a_amet_filter as $field_id => $element) {
552 if (!$element->isInCondition(
$adt_group->getElement($field_id))) {
559 foreach (
$adt_group->getElements() as $element_id => $element) {
560 if (!$element->isNull()) {
563 $rec[
"md_" . $element_id] = $pb->getSortable();
564 $rec[
"md_" . $element_id .
"_presentation"] = $pb;
566 $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.
xmlStartTag($tag, $attrs=null, $empty=false, $encode=true, $escape=true)
Writes a starttag.
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.
if(!array_key_exists('StateId', $_REQUEST)) $id
static getADTGroupForDefinitions(array $a_defs)
Init ADTGroup for definitions.
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.
static _getAllReferences($a_id)
get all reference ids of object
xmlEndTag($tag)
Writes an endtag.
static _deleteByObjId($a_obj_id)
Delete by objekt id.
static _getSelectedRecordsByObject($a_obj_type, $a_ref_id, $a_sub_type="")
Get selected records by object.
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.
foreach($_POST as $key=> $value) $res
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.
Create styles array
The data for the language used.
static _lookupType($a_id, $a_reference=false)
lookup object type
xmlElement($tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
isDisabled($a_element_id)
Is element disabled?
write(array $a_additional_data=null)
Write record values.
static preloadedRead($a_type, $a_obj_id)
static $preload_obj_records
static getObjRecSelection($a_obj_id, $a_sub_type="")
Get repository object record selection.
static queryForRecords($adv_rec_obj_ref_id, $adv_rec_obj_type, $adv_rec_obj_subtype, $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.
getDefinitions()
Get record field definitions.