/**
  * 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();
         }
     }
 }