4include_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) {
 
   70                $id = $record->getRecordId();
 
   73                    $res[
$id] = 
new self(
$id, $a_obj_id, $a_sub_type, $a_sub_id);
 
   89        $this->obj_id = (int) $a_obj_id;
 
   90        $this->sub_type = $a_sub_type ? $a_sub_type : 
"-";
 
   91        $this->sub_id = (int) $a_sub_id;
 
   94        $this->active_record = 
null;
 
  104        if (!is_array($this->defs)) {
 
  117        if (!$this->adt_group instanceof 
ilADTGroup) {
 
  131            include_once 
"Services/ADT/classes/class.ilADTFactory.php";
 
  137                "obj_id" => array(
"integer", $this->obj_id),
 
  138                "sub_type" => array(
"text", $this->sub_type),
 
  139                "sub_id" => array(
"integer", $this->sub_id)
 
  141            $adt_group_db->setPrimary($primary);
 
  142            $adt_group_db->setTable(
"adv_md_values");
 
  145            foreach ($adt_group_db->getElements() as $element) {
 
  146                if ($element->getADT()->getType() == 
"MultiEnum") {
 
  147                    $element->setFakeSingle(
true);
 
  151            $this->active_record = 
$factory->getActiveRecordByTypeInstance($adt_group_db);
 
  152            $this->active_record->setElementIdColumn(
"field_id", 
"integer");
 
  166        include_once 
"Services/ADT/classes/class.ilADTFactory.php";
 
  186        if (is_array($this->disabled)) {
 
  187            return in_array($a_element_id, $this->disabled);
 
  201        $this->disabled = array();
 
  205            foreach ($tmp as $element_id => 
$data) {
 
  206                if (
$data[
"disabled"]) {
 
  207                    $this->disabled[] = $element_id;
 
  218    public function write(array $a_additional_data = 
null)
 
  235            array(
"field_id" => array(
"integer", $a_field_id)),
 
  250            array(
"obj_id" => array(
"integer", $a_obj_id))
 
  275            array(
"obj_id" => array(
"integer", $a_obj_ids))
 
  281        self::$preload_obj_records = array();
 
  284        $query = 
"SELECT amro.*" .
 
  285            " FROM adv_md_record_objs amro" .
 
  286            " JOIN adv_md_record amr ON (amr.record_id = amro.record_id)" .
 
  287            " WHERE active = " . 
$ilDB->quote(1, 
"integer");
 
  290            self::$preload_obj_records[
$row[
"obj_type"]][] = array(
$row[
"record_id"], 
$row[
"optional"]);
 
  298        if (isset(self::$preload_obj_records[
$a_type])) {
 
  299            foreach (self::$preload_obj_records[
$a_type] as $item) {
 
  305                    include_once 
"Services/AdvancedMetaData/classes/class.ilAdvancedMDRecord.php";
 
  307                        if ($record->getRecordId() == $item[0]) {
 
  338    public static function _cloneValues($a_source_id, $a_target_id, $a_sub_type = 
null, $a_source_sub_id = 
null, $a_target_sub_id = 
null)
 
  347        include_once 
"Services/AdvancedMetaData/classes/class.ilAdvancedMDRecord.php";
 
  348        $new_records = $fields_map = array();
 
  351            if ($record->getParentObject() == $a_source_id) {
 
  353                if ($a_source_id != $a_target_id) {
 
  354                    $new_records[$record->getRecordId()] = $record->_clone($tmp, $a_target_id);
 
  356                    $new_records[$record->getRecordId()] = $record->getRecordId();
 
  358                $fields_map[$record->getRecordId()] = $tmp;
 
  367            $target_sel = array();
 
  370                if (array_key_exists(
$record_id, $new_records)) {
 
  380        $source_primary = array(
"obj_id" => array(
"integer", $a_source_id));
 
  381        $target_primary = array(
"obj_id" => array(
"integer", $a_target_id));
 
  387            $source_primary[
"sub_type"] = array(
"text", $a_sub_type);
 
  388            $source_primary[
"sub_id"] = array(
"integer", $a_source_sub_id);
 
  389            $target_primary[
"sub_type"] = array(
"text", $a_sub_type);
 
  390            $target_primary[
"sub_id"] = array(
"integer", $a_target_sub_id);
 
  397                "obj_id" => 
"integer",
 
  398                "sub_type" => 
"text",
 
  399                "sub_id" => 
"integer",
 
  400                "field_id" => 
"integer" 
  404            array(
"disabled" => 
"integer")
 
  410        foreach ($fields_map as $source_record_id => $fields) {
 
  412            if (array_key_exists($source_record_id, $new_records)) {
 
  413                foreach ($fields as $source_field_id => $target_field_id) {
 
  415                    $del_target_primary = $target_primary;
 
  416                    $del_target_primary[
"field_id"] = array(
"integer", $source_field_id);
 
  420                    $fix_source_primary = $source_primary;
 
  421                    $fix_source_primary[
"field_id"] = array(
"integer", $source_field_id);
 
  422                    $fix_target_primary = $target_primary;
 
  423                    $fix_target_primary[
"field_id"] = array(
"integer", $target_field_id);
 
  427                            "obj_id" => 
"integer",
 
  428                            "sub_type" => 
"text",
 
  429                            "sub_id" => 
"integer",
 
  430                            "field_id" => 
"integer" 
  434                        array(
"disabled" => 
"integer")
 
  441            $ilLog->write(__METHOD__ . 
': No advanced meta data found.');
 
  443            $ilLog->write(__METHOD__ . 
': Start cloning advanced meta data.');
 
  461        foreach ($values_records as $values_record) {
 
  462            $defs = $values_record->getDefinitions();
 
  463            foreach ($values_record->getADTGroup()->getElements() as $element_id => $element) {
 
  467                if (!$element->isNull()) {
 
  468                    $value = 
$def->getValueForXML($element);
 
  473                    array(
'id' => 
$def->getImportId()),
 
  479        $a_xml_writer->
xmlEndTag(
'AdvancedMetaData');
 
  493    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)
 
  497        if (!is_array($a_obj_id)) {
 
  498            $a_obj_id = array($a_obj_id);
 
  501        $sub_obj_ids = array();
 
  502        foreach ($a_records as $rec) {
 
  503            $sub_obj_ids[] = $rec[$a_obj_subid_key];
 
  511                "obj_id" => array(
"integer", $a_obj_id),
 
  512                "sub_type" => array(
"text", $a_subtype),
 
  513                "sub_id" => array(
"integer", $sub_obj_ids)
 
  517        $record_groups = array();
 
  519        foreach ($a_records as $rec) {
 
  520            $obj_id = (int) $rec[$a_obj_id_key];
 
  521            $sub_id = $rec[$a_obj_subid_key];
 
  531                    $record_groups[
$record_id]->setTable(
"adv_md_values");
 
  536                    "obj_id" => array(
"integer", 
$obj_id),
 
  537                    "sub_type" => array(
"text", $a_subtype),
 
  538                    "sub_id" => array(
"integer", 
$sub_id)
 
  541                foreach ($record_groups[
$record_id]->getElements() as $element) {
 
  542                    if ($element->getADT()->getType() == 
"MultiEnum") {
 
  543                        $element->setFakeSingle(
true);
 
  555                if ($a_amet_filter) {
 
  556                    foreach ($a_amet_filter as $field_id => $element) {
 
  558                            if (!$element->isInCondition(
$adt_group->getElement($field_id))) {
 
  565                foreach (
$adt_group->getElements() as $element_id => $element) {
 
  566                    if (!$element->isNull()) {
 
  569                        $rec[
"md_" . $element_id] = $pb->getSortable();
 
  570                        $rec[
"md_" . $element_id . 
"_presentation"] = $pb;
 
  572                        $rec[
"md_" . $element_id] = 
null;
 
An exception for terminatinating execution or to throw for unit testing.
ADT Active Record by type helper class.
static preloadByPrimary($a_table, array $a_primary)
Read values by (partial) primary key.
static deleteByPrimary($a_table, array $a_primary, $a_type=null)
Delete values by (partial) primary key.
static readByPrimary($a_table, array $a_primary, $a_type=null)
Read directly.
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 getInstance()
Get singleton.
static initActiveRecordByType()
Init active record by type.
getType()
Get type (from class/instance)
static getADTGroupForDefinitions(array $a_defs)
Init ADTGroup for definitions.
static getInstancesByRecordId($a_record_id, $a_only_searchable=false)
Get definitions by record id.
static _getSelectedRecordsByObject($a_obj_type, $a_ref_id, $a_sub_type="")
Get selected records by object.
static saveObjRecSelection($a_obj_id, $a_sub_type="", array $a_records=null, $a_delete_before=true)
Save repository object record selection.
static getObjRecSelection($a_obj_id, $a_sub_type="")
Get repository object record selection.
static _getRecords()
Get records.
static $preload_obj_records
static _deleteByObjId($a_obj_id)
Delete by objekt id.
static getInstancesForObjectId($a_obj_id, $a_obj_type=null, $a_sub_type="-", $a_sub_id=0)
Get instances for given object id.
__construct($a_record_id, $a_obj_id, $a_sub_type="-", $a_sub_id=0)
Constructor.
static preloadByObjIds(array $a_obj_ids)
Preload list gui data.
static preloadedRead($a_type, $a_obj_id)
static findByObjectId($a_obj_id)
Find all entries for object (regardless of sub-type/sub-id)
isDisabled($a_element_id)
Is element disabled?
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.
getDefinitions()
Get record field definitions.
setActiveRecordPrimary($a_obj_id, $a_sub_type="-", $a_sub_id=0)
Set the primary values for active record.
static _appendXMLByObjId(ilXmlWriter $a_xml_writer, $a_obj_id)
Get xml of object values.
getADTGroup()
Init ADT group for current record.
write(array $a_additional_data=null)
Write record values.
getActiveRecord()
Init ADT DB Bridge (aka active record helper class)
static _deleteByFieldId($a_field_id, ilADT $a_adt)
Delete values by field_id.
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.
static _getAllReferences($a_id)
get all reference ids of object
static _lookupType($a_id, $a_reference=false)
lookup object type
xmlEndTag($tag)
Writes an endtag.
xmlElement($tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
xmlStartTag($tag, $attrs=null, $empty=false, $encode=true, $escape=true)
Writes a starttag.
if(!array_key_exists('StateId', $_REQUEST)) $id
foreach($_POST as $key=> $value) $res