/**
  * Returns the content
  */
 public function getContents()
 {
     $q = new DataCube_Query($this->_owApp->selectedModel, $this->_titleHelperLimit, $this->_dimensionElementLimit);
     if (false === $q->containsDataCubeInformation()) {
         return false;
     }
     /**
      * Set paths
      */
     $basePath = $this->view->basePath = $this->_config->staticUrlBase . 'extensions/cubeviz/';
     $baseCssPath = $basePath . 'public/css/';
     $baseImagesPath = $basePath . 'public/images/';
     $baseJavascriptPath = $basePath . 'public/javascript/';
     /**
      * Including javascript files for this action
      */
     $this->view->headScript()->appendFile($baseJavascriptPath . 'libraries/CryptoJS_Md5.js', 'text/javascript')->appendFile($baseJavascriptPath . 'libraries/json2.js', 'text/javascript')->appendFile($baseJavascriptPath . 'libraries/underscore.js', 'text/javascript')->appendFile($baseJavascriptPath . 'libraries/underscore.string.js', 'text/javascript')->appendScript('_.mixin(_.str.exports());')->appendFile($basePath . 'ChartConfig.js', 'text/javascript');
     // If this module is in the "development" context
     if ('development' === $this->_privateConfig->get('context')) {
         $this->view->headScript()->appendFile($baseJavascriptPath . 'libraries/munit.js', 'text/javascript')->appendFile($baseJavascriptPath . 'Test.js', 'text/javascript')->appendFile($baseJavascriptPath . 'Main.js', 'text/javascript');
         // otherwise it is in "production" context
     } else {
         $this->view->headScript()->appendFile($baseJavascriptPath . 'Main-production.js', 'text/javascript');
     }
     /**
      * Including css files for this action
      */
     $this->view->headLink()->prependStylesheet($baseCssPath . 'foreign/FontAwesome/css/font-awesome.min.css')->prependStylesheet($baseCssPath . 'main.css')->prependStylesheet($baseCssPath . 'DataselectionModule/attribute.css')->prependStylesheet($baseCssPath . 'DataselectionModule/component.css')->prependStylesheet($baseCssPath . 'DataselectionModule/dataSelectionModule.css')->prependStylesheet($baseCssPath . 'DataselectionModule/dataSet.css')->prependStylesheet($baseCssPath . 'DataselectionModule/footer.css')->prependStylesheet($baseCssPath . 'DataselectionModule/measure.css')->prependStylesheet($baseCssPath . 'DataselectionModule/slice.css');
     // IE specific CSS for fontawesome
     if (strpos($_SERVER['HTTP_USER_AGENT'], '(compatible; MSIE ') !== FALSE) {
         $this->view->headLink()->appendStylesheet($baseCssPath . 'foreign/FontAwesome/css/font-awesome-ie7.min.css');
     }
     /**
      * Model information
      */
     $model = $this->_owApp->selectedModel;
     $modelIri = $model->getModelIri();
     $modelStore = $model->getStore();
     $serviceUrl = true === isset($_SESSION['ONTOWIKI']['serviceUrl']) ? $_SESSION['ONTOWIKI']['serviceUrl'] : null;
     CubeViz_ViewHelper::$isCubeVizDataselectionModuleLoaded = true;
     // init cubeVizApp
     $config = CubeViz_ViewHelper::initApp($this->view, $model, $this->_owApp->getConfig()->store->backend, $this->_privateConfig->get('context'), $modelIri, $serviceUrl, $this->_config->staticUrlBase, $baseImagesPath, $this->_request->getParam('cv_dataHash'), $this->_request->getParam('cv_uiHash'), $this->_titleHelperLimit, $this->_dimensionElementLimit);
     if (null !== $config) {
         $this->view->headScript()->appendScript('cubeVizApp._ = ' . json_encode($config, JSON_FORCE_OBJECT) . ';')->appendScript('cubeVizApp._.backend.chartConfig = CubeViz_ChartConfig;');
     }
     $this->view->translate = $this->_owApp->translate;
     /**
      * fill template with content and give generated HTML back
      */
     return $this->render('public/templates/cubeviz/DataselectionModule');
 }
 /**
  *
  */
 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;
 }
Beispiel #3
0
 /**
  * 
  */
 public static function exportAsCSV($dataHash, $model, $titleHelperLimit, $dimensionElementLimit)
 {
     $attributeSet = false;
     $c = new CubeViz_ConfigurationLink($model, $titleHelperLimit, $dimensionElementLimit);
     $data = $result = array(array());
     // get all information to export
     list($data, $dh) = $c->read($dataHash, 'data');
     /**
      * set the header of the CSV file
      */
     foreach ($data['selectedComponents']['dimensions'] as $element) {
         $result[0][] = $element['__cv_niceLabel'];
     }
     // measure
     $result[0][] = $data['selectedComponents']['measure']['__cv_niceLabel'];
     // use attribute, if available
     if (true === isset($data['selectedComponents']['attribute'])) {
         $result[0][] = $data['selectedComponents']['attribute']['__cv_niceLabel'];
         $attributeSet = true;
     }
     /**
      * set the content of the CSV file
      */
     $query = new DataCube_Query($model, $titleHelperLimit, $dimensionElementLimit);
     $selectedDimensions = $data['selectedComponents']['dimensions'];
     $i = 1;
     $retrievedObservations = $query->getObservations($data['selectedDS']['__cv_uri'], $data['selectedComponents']['dimensions']);
     // each line in the CSV file represents one observation
     foreach ($retrievedObservations as $observation) {
         // go through all dimensions
         foreach ($selectedDimensions as $d) {
             // e.g. http://data.lod2.eu/scoreboard/properties/country
             $dimensionUrl = $d['http://purl.org/linked-data/cube#dimension'];
             // save dimension element url
             $dimensionElementUrl = $observation[$dimensionUrl];
             // use dimension element url to get his label
             foreach ($d['__cv_elements'] as $dimensionElement) {
                 if ($dimensionElement['__cv_uri'] == $dimensionElementUrl) {
                     $result[$i][] = $dimensionElement['__cv_niceLabel'];
                 }
             }
         }
         // get measure
         $measureUri = $data['selectedComponents']['measure']['http://purl.org/linked-data/cube#measure'];
         $result[$i][] = $observation[$measureUri];
         // get attribute, if available
         if (true === $attributeSet) {
             $result[$i][] = $data['selectedComponents']['attribute']['__cv_niceLabel'];
         }
         ++$i;
     }
     return CubeViz_Exporter::arrayToCsv($result, ';', '"');
 }
 /**
  *
  */
 public function savecontenttofileAction()
 {
     $this->_helper->viewRenderer->setNoRender();
     $this->_helper->layout->disableLayout();
     /**
      * save parameter
      */
     $hash = $this->_request->getParam('hash', '');
     $modelIri = $this->_request->getParam('modelIri', '');
     $stringifiedContent = $this->_request->getParam('stringifiedContent', '');
     $type = $this->_request->getParam('type', '');
     $useObservations = $this->_request->getParam('useObservations', '');
     // if type is data, than load observations before save content
     if ('data' == $type && 'false' == $useObservations) {
         // setup
         $model = new Erfurt_Rdf_Model($modelIri);
         $query = new DataCube_Query($model, $this->_titleHelperLimit, $this->_dimensionElementLimit);
         // decode content
         $content = json_decode($stringifiedContent, true);
         // load observations
         $content['retrievedObservations'] = $query->getObservations($content['selectedDS']['__cv_uri'], $content['selectedComponents']['dimensions']);
         $stringifiedContent = json_encode($content, JSON_FORCE_OBJECT);
     }
     // write given content to file
     $configuration = new CubeViz_ConfigurationLink($this->_owApp->selectedModel, $this->_titleHelperLimit, $this->_dimensionElementLimit);
     $configuration->write($stringifiedContent, $hash);
     // send back generated hash
     $this->_sendJSONResponse(null);
 }