/**
  * Get xml of object values
  *
  * @access public
  * @static
  * @param object instance of ilXmlWriter
  * @param int $a_obj_id
  */
 public static function _appendXMLByObjId(ilXmlWriter $xml_writer, $a_obj_id)
 {
     global $ilDB;
     $type = ilObject::_lookupType($a_obj_id);
     // Get active field_definitions
     $query = "SELECT field_id FROM adv_md_record amr " . "JOIN adv_md_record_objs amro ON amr.record_id = amro.record_id " . "JOIN adv_mdf_definition amfd ON amr.record_id = amfd.record_id " . "WHERE active = 1 " . "AND obj_type = " . $ilDB->quote($type, 'text') . " ";
     $xml_writer->xmlStartTag('AdvancedMetaData');
     $res = $ilDB->query($query);
     while ($row = $res->fetchRow(DB_FETCHMODE_OBJECT)) {
         include_once 'Services/AdvancedMetaData/classes/class.ilAdvancedMDValue.php';
         $value = ilAdvancedMDValue::_getInstance($a_obj_id, $row->field_id);
         $value->appendXML($xml_writer);
     }
     $xml_writer->xmlEndTag('AdvancedMetaData');
 }
 /**
  * Add advanced metadata to json (export)
  * 
  * @param object $a_json
  * @param ilECSSetting $a_server
  * @param array $a_definition
  * @param int $a_mapping_mode
  */
 protected function importMetadataFromJson($a_json, ilECSSetting $a_server, array $a_definition, $a_mapping_mode)
 {
     global $ilLog;
     $ilLog->write("importing metadata from json: " . print_r($a_definition, true));
     include_once './Services/WebServices/ECS/classes/class.ilECSDataMappingSettings.php';
     include_once './Services/AdvancedMetaData/classes/class.ilAdvancedMDValues.php';
     include_once './Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php';
     $mappings = ilECSDataMappingSettings::getInstanceByServerId($a_server->getServerId());
     foreach ($a_definition as $id => $type) {
         if (is_array($type)) {
             $target = $type[1];
             $type = $type[0];
         } else {
             $target = $id;
         }
         $timePlace = null;
         if ($field = $mappings->getMappingByECSName($a_mapping_mode, $id)) {
             switch ($type) {
                 case ilECSUtils::TYPE_ARRAY:
                     $value = implode(',', (array) $a_json->{$target});
                     break;
                 case ilECSUtils::TYPE_INT:
                     $value = (int) $a_json->{$target};
                     break;
                 case ilECSUtils::TYPE_STRING:
                     $value = (string) $a_json->{$target};
                     break;
                 case ilECSUtils::TYPE_TIMEPLACE:
                     if (!is_object($timePlace)) {
                         include_once './Services/WebServices/ECS/classes/class.ilECSTimePlace.php';
                         if (is_object($a_json->{$target})) {
                             $timePlace = new ilECSTimePlace();
                             $timePlace->loadFromJSON($a_json->{$target});
                         } else {
                             $timePlace = new ilECSTimePlace();
                         }
                     }
                     switch ($id) {
                         case 'begin':
                         case 'end':
                             $field_type = ilAdvancedMDFieldDefinition::_lookupFieldType($field);
                             if ($field_type == ilAdvancedMDFieldDefinition::TYPE_DATE || $field_type == ilAdvancedMDFieldDefinition::TYPE_DATETIME) {
                                 $value = $timePlace->{'getUT' . ucfirst($id)}();
                                 break;
                             }
                             // fallthrough
                         // fallthrough
                         case 'room':
                         case 'cycle':
                             $value = $timePlace->{'get' . ucfirst($id)}();
                             break;
                     }
                     break;
             }
             include_once './Services/AdvancedMetaData/classes/class.ilAdvancedMDValue.php';
             $mdv = ilAdvancedMDValue::_getInstance($this->getId(), $field);
             $mdv->toggleDisabledStatus(true);
             $mdv->setValue($value);
             $mdv->save();
         }
     }
 }
 /**
  * Show special form for ecs start
  * 
  * @access private
  * @param object ilAdvMDFieldDefinition
  */
 private function showECSStart($def)
 {
     global $ilUser;
     $this->lng->loadLanguageModule('ecs');
     include_once 'Services/AdvancedMetaData/classes/class.ilAdvancedMDValue.php';
     $value_start = ilAdvancedMDValue::_getInstance($this->obj_id, $def->getFieldId());
     $unixtime = $value_start->getValue() ? $value_start->getValue() : mktime(8, 0, 0, date('m'), date('d'), date('Y'));
     $time = new ilDateTimeInputGUI($this->lng->txt('ecs_event_appointment'), 'md[' . $def->getFieldId() . ']');
     $time->setShowTime(true);
     $time->setDate(new ilDateTime($unixtime, IL_CAL_UNIX));
     $time->enableDateActivation($this->lng->txt('enabled'), 'md_activated[' . $def->getFieldId() . ']', $value_start->getValue() ? true : false);
     $time->setDisabled($value_start->isDisabled());
     $mapping = ilECSDataMappingSettings::_getInstance();
     if ($field_id = $mapping->getMappingByECSName('end')) {
         $value_end = ilAdvancedMDValue::_getInstance($this->obj_id, $field_id);
         list($hours, $minutes) = $this->parseDuration($value_start->getValue(), $value_end->getValue());
         $duration = new ilDurationInputGUI($this->lng->txt('ecs_duration'), 'ecs_duration');
         $duration->setHours($hours);
         $duration->setMinutes($minutes);
         #$duration->setInfo($this->lng->txt('ecs_duration_info'));
         $duration->setShowHours(true);
         $duration->setShowMinutes(true);
         $time->addSubItem($duration);
     }
     if ($field_id = $mapping->getMappingByECSName('cycle')) {
         $value = ilAdvancedMDValue::_getInstance($this->obj_id, $field_id);
         $cycle_def = ilAdvancedMDFieldDefinition::getInstance($field_id);
         switch ($cycle_def->getFieldType()) {
             case ilAdvancedMDFieldDefinition::TYPE_TEXT:
                 $text = new ilTextInputGUI($cycle_def->getTitle(), 'md[' . $cycle_def->getFieldId() . ']');
                 $text->setValue($value->getValue());
                 $text->setSize(20);
                 $text->setMaxLength(512);
                 $text->setDisabled($value->isDisabled());
                 $time->addSubItem($text);
                 break;
             case ilAdvancedMDFieldDefinition::TYPE_SELECT:
                 $select = new ilSelectInputGUI($cycle_def->getTitle(), 'md[' . $cycle_def->getFieldId() . ']');
                 $select->setOptions($cycle_def->getFieldValuesForSelect());
                 $select->setValue($value->getValue());
                 $select->setDisabled($value->isDisabled());
                 $time->addSubItem($select);
                 break;
         }
     }
     if ($field_id = $mapping->getMappingByECSName('room')) {
         $value = ilAdvancedMDValue::_getInstance($this->obj_id, $field_id);
         $room_def = ilAdvancedMDFieldDefinition::getInstance($field_id);
         switch ($room_def->getFieldType()) {
             case ilAdvancedMDFieldDefinition::TYPE_TEXT:
                 $text = new ilTextInputGUI($room_def->getTitle(), 'md[' . $room_def->getFieldId() . ']');
                 $text->setValue($value->getValue());
                 $text->setSize(20);
                 $text->setMaxLength(512);
                 $text->setDisabled($value->isDisabled());
                 $time->addSubItem($text);
                 break;
             case ilAdvancedMDFieldDefinition::TYPE_SELECT:
                 $select = new ilSelectInputGUI($room_def->getTitle(), 'md[' . $room_def->getFieldId() . ']');
                 $select->setOptions($cycle_def->getFieldValuesForSelect());
                 $select->setValue($value->getValue());
                 $select->setDisabled($value->isDisabled());
                 $time->addSubItem($select);
                 break;
         }
     }
     $this->form->addItem($time);
 }