public function lastchange($uri) { // TODO: fill this value with the erfurt versioning api $versioning = Erfurt_App::getInstance()->getVersioning(); $history = $versioning->getLastModifiedForResource($uri, (string) OntoWiki::getInstance()->selectedModel); if (empty($history)) { return array('resourceUri' => $uri, 'resourceTitle' => '', 'timeStamp' => '', 'timeIso8601' => '', 'timeDuration' => '', 'userTitle' => '', 'userUri' => '', 'userHref' => ''); } $th = new OntoWiki_Model_TitleHelper(OntoWiki::getInstance()->selectedModel); $th->addResource($history['useruri']); $th->addResource($uri); $return = array(); $userUrl = new OntoWiki_Url(array('route' => 'properties')); $userUrl->setParam('r', $history['useruri']); $return['resourceUri'] = $uri; $return['resourceTitle'] = $th->getTitle($uri); $return['timeStamp'] = $history['tstamp']; //unix timestamp $return['timeIso8601'] = date('c', $history['tstamp']); // ISO 8601 format try { $return['timeDuration'] = OntoWiki_Utils::dateDifference($history['tstamp'], null, 3); // x days ago } catch (Exception $e) { $return['timeDuration'] = ''; } $return['userTitle'] = $th->getTitle($history['useruri']); $return['userUri'] = $history['useruri']; $return['userHref'] = $userUrl; //use URI helper return $return; }
protected function _descriptionResource($uri) { if (null === $this->_descriptionHelper) { $this->_descriptionHelper = new OntoWiki_Model_TitleHelper($this->_model); } $this->_descriptionHelper->addResource($uri); }
/** * Get information about the selected model * @param $modelStore Store of selected model * @param $model Model itself * @param $modelIri Iri of the selected model * @return Array Array with fields containing information about the model */ public static function getModelInformation($modelStore, $model, $modelIri) { $modelResource = new OntoWiki_Model_Resource($modelStore, $model, $modelIri); $modelResource = $modelResource->getValues(); $titleHelper = new OntoWiki_Model_TitleHelper($model); $modelInformation = array(); // if model resource contains further information about the model if (true === isset($modelResource[$modelIri])) { // just add all used predicates to title helper, to get // the titles later on foreach ($modelResource[$modelIri] as $predicateUri => $object) { $titleHelper->addResource($predicateUri); } // now build model information array foreach ($modelResource[$modelIri] as $predicateUri => $object) { // set predicate label $modelInformation[$predicateUri] = array('predicateLabel' => $titleHelper->getTitle($predicateUri)); // choose type of content (uri or literal) if (true === isset($object[0]['content'])) { $modelInformation[$predicateUri]['content'] = $object[0]['content']; } else { $modelInformation[$predicateUri]['content'] = $object[0]['uri']; } } } return $modelInformation; }
public function getpossiblevaluesAction() { $listHelper = Zend_Controller_Action_HelperBroker::getStaticHelper('List'); $listName = $this->_request->getParam('list'); if ($listHelper->listExists($listName)) { $list = $listHelper->getList($listName); //TODO the store is not serialized anymore. it is missing by default. Controllers have to set it //how to determine here? //use the default store here - but also Sparql-Adapters are possible $list->setStore($this->_erfurt->getStore()); } else { $this->view->values = array(); return; } $predicate = $this->_request->getParam('predicate', ''); $inverse = $this->_request->getParam('inverse', ''); $this->view->values = $list->getPossibleValues($predicate, true, $inverse == "true"); require_once 'OntoWiki/Model/TitleHelper.php'; $titleHelper = new OntoWiki_Model_TitleHelper($this->_owApp->selectedModel); foreach ($this->view->values as $value) { if ($value['type'] == 'uri') { $titleHelper->addResource($value['value']); } } foreach ($this->view->values as $key => $value) { if ($value['type'] == 'uri') { $this->view->values[$key]['title'] = $titleHelper->getTitle($value['value']); } else { $this->view->values[$key]['title'] = $value['value']; } } }
public function testPrependTitlePropertyDifferentInstances() { $config = array('titleHelper' => array('properties' => array('skosPlabel' => 'http://www.w3.org/2004/02/skos/core#prefLabel', 'dcTitle' => 'http://purl.org/dc/elements/1.1/title', 'dcTitle2' => 'http://purl.org/dc/terms/title', 'swrcTitle' => 'http://swrc.ontoware.org/ontology#title', 'foafName' => 'http://xmlns.com/foaf/0.1/name', 'doapName' => 'http://usefulinc.com/ns/doap#name', 'siocName' => 'http://rdfs.org/sioc/ns#name', 'tagName' => 'http://www.holygoat.co.uk/owl/redwood/0.1/tags/name', 'lgeodName' => 'http://linkedgeodata.org/vocabulary#name', 'geoName' => 'http://www.geonames.org/ontology#name', 'goName' => 'http://www.geneontology.org/dtds/go.dtd#name', 'rdfsLabel' => 'http://www.w3.org/2000/01/rdf-schema#label'), 'searchMode' => 'language')); $graph = new Erfurt_Rdf_Model($this->_modelUri); $resource = 'http://example.org/graph123/resourceABC'; $titleHelper = new OntoWiki_Model_TitleHelper($graph, $this->_store, $config); $titleHelper->addResource($resource); $title = $titleHelper->getTitle($resource); $this->assertEquals('testABC', $title); // now prepend a property $titleHelper = new OntoWiki_Model_TitleHelper($graph, $this->_store, $config); $titleHelper->prependTitleProperty('http://ns.ontowiki.net/SysOnt/Site/menuLabel'); $titleHelper->addResource($resource); $title = $titleHelper->getTitle($resource); $this->assertEquals('testMenuLabel', $title); }
/** * Returns the property values for all resources at once. * This method generate one SPARQL query to receive all values . * Original Name was getValues() * @return array */ public function getValuesBySingleQuery() { if ($this->_valuesUptodate) { return $this->_values; } else { $this->updateValueQuery(); } if (empty($this->_resources)) { return array(); } $this->getResults(); $result = array(); if (isset($this->_results['results']['bindings'])) { $result = $this->_results['results']['bindings']; } //fill titlehelper foreach ($result as $row) { foreach ($this->_shownProperties as $property) { if (isset($row[$property['varName']]) && $row[$property['varName']]['type'] == 'uri' && substr($row[$property['varName']]['value'], 0, 2) != '_:') { $this->_titleHelper->addResource($row[$property['varName']]['value']); } } if (isset($row['__TYPE']) && $row['__TYPE']['type'] == 'uri') { $this->_titleHelper->addResource($row['__TYPE']['value']); } $this->_titleHelper->addResource($row[$this->_resourceVar->getName()]['value']); } $valueResults = array(); foreach ($result as $row) { $resourceUri = $row[$this->_resourceVar->getName()]['value']; if (!array_key_exists($resourceUri, $valueResults)) { $valueResults[$resourceUri] = array(); } $url = new OntoWiki_Url(array('route' => 'properties'), array('r')); $value = null; $link = null; foreach ($row as $varName => $data) { if (!isset($valueResults[$resourceUri][$varName])) { $valueResults[$resourceUri][$varName] = array(); } if ($data['type'] == 'uri') { if (substr($data['value'], 0, 2) == '_:') { continue; // skip blanknode values here due to backend problems with filters } // object type is uri --> handle object property $objectUri = $data['value']; $url->setParam('r', $objectUri, true); $link = (string) $url; // set up event $event = new Erfurt_Event('onDisplayObjectPropertyValue'); //find uri foreach ($this->_shownProperties as $property) { if ($varName == $property['varName']) { $event->property = $property['uri']; } } $event->value = $objectUri; // trigger $value = $event->trigger(); // set default if event has not been handled if (!$event->handled()) { $value = $this->_titleHelper->getTitle($objectUri); } } else { // object is a literal $object = $data['value']; $propertyUri = null; foreach ($this->_shownProperties as $property) { if ($varName == $property['varName']) { $propertyUri = $property['uri']; } } if ($object !== null) { // set up event $event = new Erfurt_Event('onDisplayLiteralPropertyValue'); $event->property = $propertyUri; $event->value = $object; $event->setDefault($object); // trigger $value = $event->trigger(); } } //check for dulplicate values if (isset($valueResults[$resourceUri][$varName])) { foreach ($valueResults[$resourceUri][$varName] as $old) { if ($old['origvalue'] == $data['value'] && $old['type'] == $data['type']) { $link = null; continue 2; // dont add this value } } } //add value $valueResults[$resourceUri][$varName][] = array('value' => $value, 'origvalue' => $data['value'], 'type' => $data['type'], 'url' => $link, 'uri' => $data['value']); $value = null; $link = null; } } foreach ($this->getShownResources() as $resource) { if (!isset($valueResults[$resource['value']])) { //there are no statements about this resource $valueResults[$resource['value']] = array(); } } $this->_values = $valueResults; $this->_valuesUptodate = true; return $valueResults; }
/** * Add additional fields to each entry of the given array. These fields are * heavily used in the UI. Each field starts with __cv_ and could be ignored * usally. * @param $assocSPOArray array Usally the result of generateAssocSPOArrayFromSparqlResult * @param $useTitleHelper bool optional Manually deactivate title helper * @return Array An enriched version of given $assocSPOArray */ public function enrichResult($assocSPOArray, $useTitleHelper = true) { // generate unique hash using given SPO array and model uri $objectId = md5($this->_model->getModelIri() . json_encode($assocSPOArray)); // check there is already a cached object for this hash $result = $this->_objectCache->load($objectId); // no cache entry found if (false === $result) { // start QueryCache transaction $this->_queryCache->startTransaction($objectId); $return = array(); $spoArrayCount = count($assocSPOArray); if (true === $useTitleHelper) { $titleHelper = new OntoWiki_Model_TitleHelper($this->_model); /** * go through all entries to add them to title helper */ if ($this->_titleHelperLimit >= $spoArrayCount) { foreach ($assocSPOArray as $mainKey => $entry) { if (true === Erfurt_Uri::check($mainKey)) { $titleHelper->addResource($mainKey); } } } } /** * enrich data with CubeViz specific stuff */ foreach ($assocSPOArray as $mainKey => $entry) { // URI of the element $entry['__cv_uri'] = $mainKey; // hashed URI of the element $entry['__cv_hashedUri'] = md5($mainKey); if (true === $useTitleHelper && $this->_titleHelperLimit >= $spoArrayCount) { // Nice label using TitleHelper $entry['__cv_niceLabel'] = $titleHelper->getTitle($mainKey); } else { $entry['__cv_niceLabel'] = $mainKey; } // Comment if (true === isset($entry['http://www.w3.org/2000/01/rdf-schema#comment']) && true === is_string($entry['http://www.w3.org/2000/01/rdf-schema#comment']) && 0 < strlen($entry['http://www.w3.org/2000/01/rdf-schema#comment'])) { $entry['__cv_description'] = $entry['http://www.w3.org/2000/01/rdf-schema#comment']; } else { $entry['__cv_description'] = ''; } $return[] = $entry; } // end the QueryCache transaction $this->_queryCache->endTransaction($objectId); // save the result value in the object cache $this->_objectCache->save($result, $objectId); } return $return; }
/** * JSON output of the RDFauthor selection Cache File of the current model or * of the model given in parameter m */ public function rdfauthorcacheAction() { // service controller needs no view renderer $this->_helper->viewRenderer->setNoRender(); // disable layout for Ajax requests $this->_helper->layout()->disableLayout(); $store = OntoWiki::getInstance()->erfurt->getStore(); $response = $this->getResponse(); $model = $this->_owApp->selectedModel; if (isset($this->_request->m)) { $model = $store->getModel($this->_request->m); } if (empty($model)) { throw new OntoWiki_Exception('Missing parameter m (model) and no selected model in session!'); } $output = array(); $properties = $model->sparqlQuery('SELECT DISTINCT ?uri { ?uri a ?propertyClass. FILTER( sameTerm(?propertyClass, <' . EF_OWL_OBJECT_PROPERTY . '>) || sameTerm(?propertyClass, <' . EF_OWL_DATATYPE_PROPERTY . '>) || sameTerm(?propertyClass, <' . EF_OWL_ONTOLOGY_PROPERTY . '>) || sameTerm(?propertyClass, <' . EF_RDF_PROPERTY . '>) )} LIMIT 200 '); if (!empty($properties)) { // push all URIs to titleHelper $titleHelper = new OntoWiki_Model_TitleHelper($model); foreach ($properties as $property) { $titleHelper->addResource($property['uri']); } $lastProperty = end($properties); foreach ($properties as $property) { $newProperty = array(); // return title from titleHelper $newProperty['label'] = $titleHelper->getTitle($property['uri']); $pdata = $model->sparqlQuery('SELECT DISTINCT ?key ?value WHERE { <' . $property['uri'] . '> ?key ?value FILTER( sameTerm(?key, <' . EF_RDF_TYPE . '>) || sameTerm(?key, <' . EF_RDFS_DOMAIN . '>) || sameTerm(?key, <' . EF_RDFS_RANGE . '>) ) FILTER(isUri(?value)) } LIMIT 20'); if (!empty($pdata)) { $types = array(); $ranges = array(); $domains = array(); // prepare the data in arrays foreach ($pdata as $data) { if ($data['key'] == EF_RDF_TYPE && $data['value'] != EF_RDF_PROPERTY) { $types[] = $data['value']; } elseif ($data['key'] == EF_RDFS_RANGE) { $ranges[] = $data['value']; } elseif ($data['key'] == EF_RDFS_DOMAIN) { $domains[] = $data['value']; } } if (!empty($types)) { $newProperty['type'] = array_unique($types); } if (!empty($ranges)) { $newProperty['range'] = array_unique($ranges); } if (!empty($domains)) { $newProperty['domain'] = array_unique($domains); } } $output[$property['uri']] = $newProperty; } } // send the response $response->setHeader('Content-Type', 'application/json'); $response->setBody(json_encode($output)); }
/** * Listing history for selected Resource */ public function listAction() { $model = $this->_owApp->selectedModel; $translate = $this->_owApp->translate; $store = $this->_erfurt->getStore(); $resource = $this->_owApp->selectedResource; $ac = $this->_erfurt->getAc(); $params = $this->_request->getParams(); $limit = 20; $rUriEncoded = urlencode((string) $resource); $mUriEncoded = urlencode((string) $model); $feedUrl = $this->_config->urlBase . "history/feed?r={$rUriEncoded}&mUriEncoded"; $this->view->headLink()->appendAlternate($feedUrl, 'application/atom+xml', 'History Feed'); // redirecting to home if no model/resource is selected if (empty($model) || empty($this->_owApp->selectedResource) && empty($params['r']) && $this->_owApp->lastRoute !== 'instances') { $this->_abort('No model/resource selected.', OntoWiki_Message::ERROR); } // getting page (from and for paging) if (!empty($params['page']) && (int) $params['page'] > 0) { $page = (int) $params['page']; } else { $page = 1; } // enabling versioning $versioning = $this->_erfurt->getVersioning(); $versioning->setLimit($limit); if (!$versioning->isVersioningEnabled()) { $this->_abort('Versioning/History is currently disabled', null, false); } $singleResource = true; // setting if class or instances if ($this->_owApp->lastRoute === 'instances') { // setting default title $title = $resource->getTitle() ? $resource->getTitle() : OntoWiki_Utils::contractNamespace($resource->getIri()); $windowTitle = $translate->_('Versions for elements of the list'); $listHelper = Zend_Controller_Action_HelperBroker::getStaticHelper('List'); $listName = "instances"; if ($listHelper->listExists($listName)) { $list = $listHelper->getList($listName); $list->setStore($store); } else { $this->_owApp->appendMessage(new OntoWiki_Message('something went wrong with the list of instances', OntoWiki_Message::ERROR)); } $query = clone $list->getResourceQuery(); $query->setLimit(0); $query->setOffset(0); //echo htmlentities($query); $results = $model->sparqlQuery($query); $resourceVar = $list->getResourceVar()->getName(); $resources = array(); foreach ($results as $result) { $resources[] = $result[$resourceVar]; } //var_dump($resources); $historyArray = $versioning->getHistoryForResourceList($resources, (string) $this->_owApp->selectedModel, $page); //var_dump($historyArray); $singleResource = false; } else { // setting default title $title = $resource->getTitle() ? $resource->getTitle() : OntoWiki_Utils::contractNamespace($resource->getIri()); $windowTitle = sprintf($translate->_('Versions for %1$s'), $title); $historyArray = $versioning->getHistoryForResource((string) $resource, (string) $this->_owApp->selectedModel, $page); } $historyArrayCount = count($historyArray); if ($historyArrayCount === $limit + 1) { $count = $page * $limit + 1; unset($historyArray[$limit]); } else { $count = ($page - 1) * $limit + $historyArrayCount; } $idArray = array(); $userArray = $this->_erfurt->getUsers(); $titleHelper = new OntoWiki_Model_TitleHelper(); // Load IDs for rollback and Username Labels for view foreach ($historyArray as $key => $entry) { $idArray[] = (int) $entry['id']; if (!$singleResource) { $historyArray[$key]['url'] = $this->_config->urlBase . "view?r=" . urlencode($entry['resource']); $titleHelper->addResource($entry['resource']); } if ($entry['useruri'] == $this->_erfurt->getConfig()->ac->user->anonymousUser) { $userArray[$entry['useruri']] = 'Anonymous'; } else { if ($entry['useruri'] == $this->_erfurt->getConfig()->ac->user->superAdmin) { $userArray[$entry['useruri']] = 'SuperAdmin'; } else { if (is_array($userArray[$entry['useruri']])) { if (isset($userArray[$entry['useruri']]['userName'])) { $userArray[$entry['useruri']] = $userArray[$entry['useruri']]['userName']; } else { $titleHelper->addResource($entry['useruri']); $userArray[$entry['useruri']] = $titleHelper->getTitle($entry['useruri']); } } } } } $this->view->userArray = $userArray; $this->view->idArray = $idArray; $this->view->historyArray = $historyArray; $this->view->singleResource = $singleResource; $this->view->titleHelper = $titleHelper; if (empty($historyArray)) { $this->_owApp->appendMessage(new OntoWiki_Message('No history for the selected resource(s).', OntoWiki_Message::INFO)); } if ($this->_erfurt->getAc()->isActionAllowed('Rollback')) { $this->view->rollbackAllowed = true; // adding submit button for rollback-action $toolbar = $this->_owApp->toolbar; $toolbar->appendButton(OntoWiki_Toolbar::SUBMIT, array('name' => $translate->_('Rollback changes'), 'id' => 'history-rollback')); $this->view->placeholder('main.window.toolbar')->set($toolbar); } else { $this->view->rollbackAllowed = false; } // paging $statusBar = $this->view->placeholder('main.window.statusbar'); // the normal page_param p collides with the generic-list param p OntoWiki_Pager::setOptions(array('page_param' => 'page')); $statusBar->append(OntoWiki_Pager::get($count, $limit)); // setting view variables $url = new OntoWiki_Url(array('controller' => 'history', 'action' => 'rollback')); $this->view->placeholder('main.window.title')->set($windowTitle); $this->view->formActionUrl = (string) $url; $this->view->formMethod = 'post'; // $this->view->formName = 'instancelist'; $this->view->formName = 'history-rollback'; $this->view->formEncoding = 'multipart/form-data'; }
/** * * @param void * @return void */ public function compareAction() { // set paths $basePath = $this->view->basePath = $this->_config->staticUrlBase . 'extensions/cubeviz/'; $baseCssPath = $basePath . 'public/css/'; $baseJavascriptPath = $basePath . 'public/javascript/'; $baseImagesPath = $basePath . 'public/images/'; /** * Including css files for this action */ $this->view->headLink()->appendStylesheet($baseCssPath . 'foreign/Bootstrap/bootstrap.min.css')->appendStylesheet($baseCssPath . 'foreign/FontAwesome/css/font-awesome.min.css')->appendStylesheet($baseCssPath . '/CompareAction/CompareAction.css')->appendStylesheet($baseCssPath . '/main.css'); // Libraries $this->view->headScript()->appendFile($basePath . 'ChartConfig.js', 'text/javascript')->appendFile($baseJavascriptPath . 'libraries/highcharts.js', 'text/javascript')->appendFile($baseJavascriptPath . 'libraries/highcharts-more.js', 'text/javascript')->appendFile($baseJavascriptPath . 'libraries/CryptoJS_Md5.js', 'text/javascript')->appendFile($baseJavascriptPath . 'libraries/json2.js', 'text/javascript')->appendFile($baseJavascriptPath . 'libraries/javascriptStats-1.0.1.js', 'text/javascript')->appendFile($baseJavascriptPath . 'libraries/formulaParser.js', 'text/javascript')->appendFile($baseJavascriptPath . 'libraries/underscore.js', 'text/javascript')->appendFile($baseJavascriptPath . 'libraries/underscore.string.js', 'text/javascript')->appendScript('_.mixin(_.str.exports());'); // for underscore.string // 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'); } $this->view->translate = $this->_owApp->translate; $this->view->staticUrlBase = $this->_config->staticUrlBase; $this->view->cubevizImagesPath = $basePath . 'public/images/'; $on = $this->_owApp->getNavigation(); $on->disableNavigation(); // disable OntoWiki's Navigation /** * load data and setup view */ $store = $this->_erfurt->getStore(); $th = new OntoWiki_Model_TitleHelper(null, $store); $models = $store->getAvailableModels(); $this->view->models = array(); // config for frontend if (false === CubeViz_ViewHelper::$isCubeVizAppLoaded) { $config['backend'] = array('context' => $this->_privateConfig->get('context'), 'database' => $this->_owApp->getConfig()->store->backend, 'dataHash' => '', 'imagesPath' => $baseImagesPath, 'modelInformation' => array(), 'modelUrl' => '', 'serviceUrl' => '', 'uiHash' => '', 'uiParts' => array('dataselectionModule' => array()), 'uiSettings' => array(), 'retrievedObservations' => array(), 'url' => $this->_config->staticUrlBase . 'cubeviz/'); $this->view->headScript()->appendScript('cubeVizApp._ = ' . json_encode($config, JSON_FORCE_OBJECT) . ';')->appendScript('cubeVizApp._.backend.chartConfig = CubeViz_ChartConfig;'); } // each element will be an object (acting as an associative array) // with "1" or "2" as key (index) $config['compareAction'] = array('datasets' => array(1 => null, 2 => null), 'components' => array('dimensions' => array(1 => null, 2 => null), 'measures' => array(1 => null, 2 => null), 'attributes' => array(1 => null, 2 => null)), 'models' => array(1 => null, 2 => null), 'originalObservations' => array(1 => null, 2 => null), 'retrievedObservations' => array(1 => null, 2 => null), 'slices' => array(1 => null, 2 => null), 'equalDimensions' => array(), 'unequalDimensions' => array(1 => null, 2 => null), 'numberOfObservations' => array(1 => -1, 2 => -1)); $this->view->headScript()->appendScript('cubeVizApp._.compareAction = ' . json_encode($config['compareAction'], JSON_FORCE_OBJECT) . ';'); // modellist foreach ($models as $modelUri => $entry) { $th->addResource($modelUri); } foreach ($models as $modelUri => $entry) { $this->view->models[] = array('label' => $th->getTitle($modelUri), 'uri' => $modelUri); } }