/**
  *
  */
 public function loadStandardConfigForData($config)
 {
     $query = new DataCube_Query($this->_model, $this->_titleHelperLimit, $this->_dimensionElementLimit);
     // if no data structure definitions were selected
     if (0 === count($config['dataSets'])) {
         $config['dataSets'] = $query->getDataSets();
     }
     // if no data sets were selected
     if (0 === count($config['selectedDS'])) {
         $config['selectedDS'] = isset($config['dataSets'][0]) ? $config['dataSets'][0] : null;
     }
     // if no data structure definitions were selected
     if (0 === count($config['dataStructureDefinitions'])) {
         $config['dataStructureDefinitions'] = $query->getDataStructureDefinitions();
     }
     // if no data structure definition was selected, use the DSD from the
     // selected DS
     if (0 === count($config['selectedDSD'])) {
         foreach ($config['dataStructureDefinitions'] as $ds) {
             if ($ds['__cv_uri'] == $config['selectedDS'][DataCube_UriOf::Structure]) {
                 $config['selectedDSD'] = $ds;
             }
         }
         // if no related data structure definition was found, throw an exception
         if (0 == count($config['selectedDSD'])) {
             throw new CubeViz_Exception('Selected DataSet ' . $config['selectedDS'] . ' has no ' . 'related Data Structure Definition!');
         }
     }
     // if no components were selected
     if (0 === count($config['components'])) {
         /**
          * Dimensions
          */
         $dimensions = $query->getComponents($config['selectedDSD']['__cv_uri'], $config['selectedDS']['__cv_uri'], DataCube_UriOf::Dimension);
         $numberOfDimensions = count($dimensions);
         $numberOfUsedMultipleDimensions = 0;
         $useMultipleDimensionAnyway = false;
         // set components
         $config['components']['dimensions'] = array();
         foreach ($dimensions as $dimension) {
             $config['components']['dimensions'][$dimension['__cv_uri']] = $dimension;
         }
         // set selectedComponents
         $config['selectedComponents']['dimensions'] = array();
         foreach ($dimensions as $dimension) {
             /**
              * Preselect a couple of elements for current dimension
              */
             $numberOfElements = $dimension['__cv_elements'];
             $numberOfElementsToPreSelect = (int) ceil(count($numberOfElements) * 0.3);
             if (10 < $numberOfElementsToPreSelect) {
                 $numberOfElementsToPreSelect = 10;
             } elseif (0 == $numberOfElementsToPreSelect) {
                 $numberOfElementsToPreSelect = 1;
             }
             // if more than one dimensions available use only 2 multiple at
             // the same time and only one element of the other ones
             if (2 > $numberOfUsedMultipleDimensions && 2 < $numberOfDimensions && 1 < $numberOfElementsToPreSelect) {
                 ++$numberOfUsedMultipleDimensions;
                 // fallback option, if there are a couple of one elmement
                 // dimensions between two multiple ones.
                 if (2 == $numberOfUsedMultipleDimensions) {
                     $useMultipleDimensionAnyway = true;
                 }
             }
             $preSelectedElements = array();
             $stillUsedIndexes = array();
             // if this dimension has only one element or we have already
             // reach the maximum number of multiple dimensions
             if (1 == $numberOfElementsToPreSelect || 2 == $numberOfUsedMultipleDimensions && false == $useMultipleDimensionAnyway) {
                 foreach ($dimension['__cv_elements'] as $elementUri => $element) {
                     $preSelectedElements[$elementUri] = $dimension['__cv_elements'][$elementUri];
                     break;
                 }
                 // ... more than one element
             } elseif (1 < $numberOfElementsToPreSelect) {
                 for ($i = 0; $i < $numberOfElementsToPreSelect; ++$i) {
                     // search as long as necessary a new random index
                     do {
                         $randomI = rand(0, $numberOfElementsToPreSelect);
                         // only break if new index is not already in use
                         if (false === in_array($randomI, $stillUsedIndexes)) {
                             $stillUsedIndexes[] = $randomI;
                             break;
                         }
                     } while (true);
                     $j = 0;
                     foreach ($dimension['__cv_elements'] as $elementUri => $element) {
                         // after compute a random index for a certain element
                         // lets find this element by count up as long as the
                         // current element's index is equal to the computed one.
                         if ($j++ == $randomI) {
                             $preSelectedElements[$elementUri] = $dimension['__cv_elements'][$elementUri];
                             // in this way we keep the elementUri as key
                             break;
                         }
                     }
                 }
                 // ... has no elements
             } else {
                 $preSelectedElements = array();
             }
             $dimension['__cv_elements'] = $preSelectedElements;
             $config['selectedComponents']['dimensions'][$dimension['__cv_uri']] = $dimension;
             if (true == $useMultipleDimensionAnyway) {
                 $useMultipleDimensionAnyway = false;
             }
         }
     }
     /**
      * measures
      */
     if (false === isset($config['selectedComponents']['measure']) || false === isset($config['components']['measures'])) {
         $measures = $query->getComponents($config['selectedDSD']['__cv_uri'], $config['selectedDS']['__cv_uri'], DataCube_UriOf::Measure);
         $config['selectedComponents']['measure'] = null;
         // set measures
         $config['components']['measures'] = array();
         foreach ($measures as $measure) {
             $config['components']['measures'][$measure['__cv_uri']] = $measure;
             if (null == $config['selectedComponents']['measure']) {
                 $config['selectedComponents']['measure'] = $measure;
             }
         }
     }
     /**
      * attributes
      */
     if (false === isset($config['selectedComponents']['attribute']) || false === isset($config['components']['attributes'])) {
         $attributes = $query->getComponents($config['selectedDSD']['__cv_uri'], $config['selectedDS']['__cv_uri'], DataCube_UriOf::Attribute);
         $config['selectedComponents']['attribute'] = null;
         // set attributes
         $config['components']['attributes'] = array();
         foreach ($attributes as $attribute) {
             $config['components']['attributes'][$attribute['__cv_uri']] = $attribute;
         }
         $config['selectedComponents']['attribute'] = null;
     }
     /**
      * slices
      */
     if (0 == count($config['slices'])) {
         $config['slices'] = array();
         // get slice keys
         $sliceKeys = $query->getSliceKeys($config['selectedDSD']['__cv_uri'], $config['selectedDS']['__cv_uri']);
         // collect all slices in one list
         foreach ($sliceKeys as $sliceKey) {
             $config['slices'] = array_merge($config['slices'], $sliceKey['slices']);
         }
     }
     /**
      * number of multiple dimensions
      */
     $config['numberOfMultipleDimensions'] = 0;
     foreach ($config['selectedComponents']['dimensions'] as $dim) {
         if (1 < count($dim['__cv_elements'])) {
             ++$config['numberOfMultipleDimensions'];
         }
     }
     // number of one element dimensions
     $config['numberOfOneElementDimensions'] = 0;
     foreach ($config['selectedComponents']['dimensions'] as $dim) {
         if (1 == count($dim['__cv_elements'])) {
             ++$config['numberOfOneElementDimensions'];
         }
     }
     /**
      * Observations
      */
     $config['retrievedObservations'] = $query->getObservations($config['selectedDS']['__cv_uri'], $config['selectedComponents']['dimensions']);
     return $config;
 }
 /**
  *
  */
 public function getdatasetsAction()
 {
     $this->_helper->viewRenderer->setNoRender();
     $this->_helper->layout->disableLayout();
     // parameter
     $m = $this->_request->getParam('modelIri', '');
     $dsdUrl = $this->_request->getParam('dsdUrl', '');
     // check if model there
     if (false === $this->_erfurt->getStore()->isModelAvailable($m)) {
         $code = 404;
         $this->_sendJSONResponse(array('code' => $code, 'content' => '', 'message' => 'Model not available'), $code);
         return;
     }
     // check if dsdUrl is valid
     if ('' != $dsdUrl && false === Erfurt_Uri::check($dsdUrl)) {
         $code = 400;
         $this->_sendJSONResponse(array('code' => $code, 'content' => '', 'message' => 'dsdUrl is not valid'), $code);
         return;
     }
     // load data sets
     try {
         $model = new Erfurt_Rdf_Model($m);
         $query = new DataCube_Query($model, $this->_titleHelperLimit, $this->_dimensionElementLimit);
         $code = 200;
         $content = array('code' => $code, 'content' => $query->getDataSets($dsdUrl), 'message' => '');
     } catch (Exception $e) {
         $code = 400;
         $content = array('code' => $code, 'content' => '', 'message' => $e->getMessage());
     }
     $this->_sendJSONResponse($content, $code);
 }