Example #1
0
 /**
  * 
  */
 public static function initApp(&$view, &$model, $backend, $context, $modelIri, $serviceUrl, $staticUrlBase, $baseImagesPath, $dataHash, $uiHash, $titleHelperLimit, $dimensionElementLimit)
 {
     // if cubeVizApp was not loaded yet
     if (false === CubeViz_ViewHelper::$isCubeVizAppLoaded) {
         // get information about the selected model
         $modelStore = $model->getStore();
         $modelInformation = CubeViz_ViewHelper::getModelInformation($modelStore, $model, $modelIri);
         /**
          * Set view and some of its properties.
          */
         $view->cubevizImagesPath = $baseImagesPath;
         /**
          * Get hashes from parameter list
          */
         // hash for data
         if (null == $dataHash) {
             $dataHash = null;
         }
         // hash for ui
         if (null == $uiHash) {
             $uiHash = null;
         }
         $view->isCubeVizDataselectionModuleLoaded = false === isset($view->isCubeVizDataselectionModuleLoaded) ? false : $view->isCubeVizDataselectionModuleLoaded;
         /**
          * Read information from files according to given hashes
          */
         $c = new CubeViz_ConfigurationLink($model, $titleHelperLimit, $dimensionElementLimit);
         $config = array();
         $generatedDataHash = '';
         $generatedUiHash = '';
         list($config['data'], $generatedDataHash) = $c->read($dataHash, 'data');
         list($config['ui'], $generatedUiHash) = $c->read($uiHash, 'ui');
         $config['backend'] = array('context' => $context, 'database' => $backend, 'dataHash' => $generatedDataHash, 'imagesPath' => $baseImagesPath, 'modelInformation' => $modelInformation, 'modelUrl' => $modelIri, 'serviceUrl' => $serviceUrl, 'uiHash' => $generatedUiHash, 'uiParts' => array('dataselectionModule' => array('isLoaded' => CubeViz_ViewHelper::$isCubeVizDataselectionModuleLoaded), 'index' => array('isLoaded' => CubeViz_ViewHelper::$isCubeVizIndexLoaded)), 'uiSettings' => array(), 'url' => $staticUrlBase . 'cubeviz/');
         CubeViz_ViewHelper::$isCubeVizAppLoaded = true;
         return $config;
     }
     return null;
 }
Example #2
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);
 }