/** * */ 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, ';', '"'); }
/** * Exports dataselection given by dataHash. */ public function exportAction() { $this->_helper->viewRenderer->setNoRender(); $this->_helper->layout->disableLayout(); // do nothing, if export was deactivated if (false === $this->_privateConfig->get('useExport')) { return; } $model = $this->_owApp->selectedModel; /** * all these parameter pointing to the same dataHash */ $dataselection = $this->_request->getParam('dataselection', ''); $datacube = $this->_request->getParam('datacube', ''); if ('' != $dataselection) { $dataHash = $dataselection; } elseif ('' != $datacube) { $dataHash = $datacube; } else { return; } // optional parameter $type = $this->_request->getParam('type', ''); $filename = 'cubevizExport_' . $dataHash; switch ($type) { case 'csv': // comma separated file $contentType = 'text/csv'; $filename .= '.csv'; break; default: // turtle $contentType = 'application/x-turtle'; $filename .= '.ttl'; break; } // setup response try { $output = CubeViz_Exporter::_($type, $dataHash, $model, $this->_titleHelperLimit, $this->_dimensionElementLimit); $this->getResponse()->setHeader('Content-Type', $contentType, true)->setHeader('Content-Disposition', 'filename="' . $filename . '"')->setHeader('Pragma', 'no-cache')->setHeader('Expires', '0'); echo $output; } catch (Exception $e) { if ('development' === $this->_privateConfig->get('context')) { throw $e; } else { echo "Something went wrong with the Exporter, " . "please contact the side administrator if the problem persists. " . "Sorry."; } } }