public function getContents()
 {
     $query = new Erfurt_Sparql_SimpleQuery();
     $results = false;
     $similars = array();
     $typesArr = array();
     $types = $this->_getTypes();
     $url = new OntoWiki_Url(array('route' => 'properties'), array('r'));
     $listUrl = new OntoWiki_Url(array('route' => 'instances'), array());
     $titleHelper = new OntoWiki_Model_TitleHelper($this->_owApp->selectedModel);
     $titleHelper->addResources($types);
     foreach ($types as $typeUri) {
         if (!array_key_exists($typeUri, $typesArr)) {
             $typesArr[$typeUri] = $typeUri;
         }
         $query->resetInstance()->setProloguePart('SELECT DISTINCT ?uri')->setWherePart('WHERE {
                     ?uri a <' . $typeUri . '> .
                     FILTER (!sameTerm(?uri, <' . (string) $this->_owApp->selectedResource . '>))
                     FILTER (isURI(?uri))
                 }')->setLimit(OW_SHOW_MAX + 1);
         if ($instances = $this->_owApp->selectedModel->sparqlQuery($query)) {
             $results = true;
             $url->setParam('r', $typeUri, true);
             // create properties url for the class
             $typesArr[$typeUri] = array('uri' => $typeUri, 'url' => (string) $url, 'title' => $titleHelper->getTitle($typeUri, $this->_lang), 'has_more' => false);
             // has_more is used for the dots
             if (count($instances) > OW_SHOW_MAX) {
                 $typesArr[$typeUri]['has_more'] = true;
                 $instances = array_splice($instances, 0, OW_SHOW_MAX);
             }
             $instTitleHelper = new OntoWiki_Model_TitleHelper($this->_owApp->selectedModel);
             $instTitleHelper->addResources($instances, 'uri');
             $conf['filter'][0] = array('mode' => 'rdfsclass', 'rdfsclass' => $typeUri, 'action' => 'add');
             // the list url is used for the context menu link
             $listUrl->setParam('instancesconfig', json_encode($conf), true);
             $listUrl->setParam('init', true, true);
             $typesArr[$typeUri]['listUrl'] = (string) $listUrl;
             foreach ($instances as $row) {
                 $instanceUri = $row['uri'];
                 // set URL
                 $url->setParam('r', $instanceUri, true);
                 if (!array_key_exists($typeUri, $similars)) {
                     $similars[$typeUri] = array();
                 }
                 // add instance
                 $similars[$typeUri][$instanceUri] = array('uri' => $instanceUri, 'title' => $instTitleHelper->getTitle($instanceUri, $this->_lang), 'url' => (string) $url);
             }
         }
     }
     $this->view->types = $typesArr;
     $this->view->similars = $similars;
     if (!$results) {
         $this->view->message = 'No matches.';
     }
     return $this->render('similarinstances');
 }
예제 #2
0
 /**
  * Returns the content for the model list.
  */
 public function getContents()
 {
     $models = array();
     $selectedModel = $this->_owApp->selectedModel ? $this->_owApp->selectedModel->getModelIri() : null;
     $lang = $this->_config->languages->locale;
     $titleHelper = new OntoWiki_Model_TitleHelper();
     $titleHelper->addResources(array_keys($this->graphUris));
     $useGraphUriAsLink = false;
     if (isset($this->_privateConfig->useGraphUriAsLink) && (bool) $this->_privateConfig->useGraphUriAsLink) {
         $useGraphUriAsLink = true;
     }
     foreach ($this->graphUris as $graphUri => $true) {
         $linkUrl = $this->_config->urlBase . 'model/select/?m=' . urlencode($graphUri);
         if ($useGraphUriAsLink) {
             if (isset($this->_config->vhosts)) {
                 $vHostsArray = $this->_config->vhosts->toArray();
                 foreach ($vHostsArray as $vHostUri) {
                     if (strpos($graphUri, $vHostUri) !== false) {
                         // match
                         $linkUrl = $graphUri;
                         break;
                     }
                 }
             }
         }
         $temp = array();
         $temp['url'] = $linkUrl;
         $temp['graphUri'] = $graphUri;
         $temp['selected'] = $selectedModel == $graphUri ? 'selected' : '';
         // use URI if no title exists
         $label = $titleHelper->getTitle($graphUri, $lang);
         $temp['label'] = !empty($label) ? $label : $graphUri;
         $temp['backendName'] = $true;
         $models[] = $temp;
     }
     $content = $this->render('modellist', $models, 'models');
     return $content;
 }
예제 #3
0
 /**
  * @desc get the titles for a given array of resources
  *
  * @param string modelIri
  * @param array resources
  *
  * @return array An associative array of resources and their titles
  */
 public function getTitles($modelIri, $resources)
 {
     // ["http://pfarrerbuch.comiles.eu/sachsen/"]
     $resources = json_decode($resources);
     $model = $this->_store->getModel($modelIri);
     $titleHelper = new OntoWiki_Model_TitleHelper($model, $this->_store);
     $titleHelper->addResources($resources);
     $titles = array();
     foreach ($resources as $resourceUri) {
         $titles[$resourceUri] = $titleHelper->getTitle($resourceUri);
     }
     return $titles;
 }
 /**
  * Displays all preoperties and values for a resource, denoted by parameter
  */
 public function propertiesAction()
 {
     $this->_addLastModifiedHeader();
     $store = $this->_owApp->erfurt->getStore();
     $graph = $this->_owApp->selectedModel;
     $resource = $this->_owApp->selectedResource;
     $navigation = $this->_owApp->navigation;
     $translate = $this->_owApp->translate;
     // add export formats to resource menu
     $resourceMenu = OntoWiki_Menu_Registry::getInstance()->getMenu('resource');
     $menu = new OntoWiki_Menu();
     $menu->setEntry('Resource', $resourceMenu);
     $event = new Erfurt_Event('onCreateMenu');
     $event->menu = $resourceMenu;
     $event->resource = $this->_owApp->selectedResource;
     $event->model = $this->_owApp->selectedModel;
     $event->trigger();
     $event = new Erfurt_Event('onPropertiesAction');
     $event->uri = (string) $resource;
     $event->graph = $this->_owApp->selectedModel->getModelUri();
     $event->trigger();
     // Give plugins a chance to add entries to the menu
     $this->view->placeholder('main.window.menu')->set($menu->toArray(false, true));
     $title = $resource->getTitle($this->_config->languages->locale) ? $resource->getTitle($this->_config->languages->locale) : OntoWiki_Utils::contractNamespace((string) $resource);
     $windowTitle = sprintf($translate->_('Properties of %1$s'), $title);
     $this->view->placeholder('main.window.title')->set($windowTitle);
     if (!empty($resource)) {
         $event = new Erfurt_Event('onPreTabsContentAction');
         $event->uri = (string) $resource;
         $result = $event->trigger();
         if ($result) {
             $this->view->preTabsContent = $result;
         }
         $event = new Erfurt_Event('onPrePropertiesContentAction');
         $event->uri = (string) $resource;
         $result = $event->trigger();
         if ($result) {
             $this->view->prePropertiesContent = $result;
         }
         $model = new OntoWiki_Model_Resource($store, $graph, (string) $resource);
         $values = $model->getValues();
         $predicates = $model->getPredicates();
         // new trigger onPropertiesActionData to work with data (reorder with plugin)
         $event = new Erfurt_Event('onPropertiesActionData');
         $event->uri = (string) $resource;
         $event->predicates = $predicates;
         $event->values = $values;
         $result = $event->trigger();
         if ($result) {
             $predicates = $event->predicates;
             $values = $event->values;
         }
         $titleHelper = new OntoWiki_Model_TitleHelper($graph);
         // add graphs
         $graphs = array_keys($predicates);
         $titleHelper->addResources($graphs);
         // set RDFa widgets update info for editable graphs and other graph info
         $graphInfo = array();
         $editableFlags = array();
         foreach ($graphs as $g) {
             $graphInfo[$g] = $titleHelper->getTitle($g, $this->_config->languages->locale);
             if ($this->_erfurt->getAc()->isModelAllowed('edit', $g)) {
                 $editableFlags[$g] = true;
                 $this->view->placeholder('update')->append(array('sourceGraph' => $g, 'queryEndpoint' => $this->_config->urlBase . 'sparql/', 'updateEndpoint' => $this->_config->urlBase . 'update/'));
             } else {
                 $editableFlags[$g] = false;
             }
         }
         $this->view->graphs = $graphInfo;
         $this->view->editableFlags = $editableFlags;
         $this->view->values = $values;
         $this->view->predicates = $predicates;
         $this->view->resourceUri = (string) $resource;
         $this->view->graphUri = $graph->getModelIri();
         $this->view->graphBaseUri = $graph->getBaseIri();
         $this->view->editable = false;
         // use $this->editableFlags[$graph] now
         // prepare namespaces
         $namespacePrefixes = $graph->getNamespacePrefixes();
         $graphBase = $graph->getBaseUri();
         if (!array_key_exists(OntoWiki_Utils::DEFAULT_BASE, $namespacePrefixes)) {
             $namespacePrefixes[OntoWiki_Utils::DEFAULT_BASE] = $graphBase;
         }
         $this->view->namespacePrefixes = $namespacePrefixes;
     }
     $toolbar = $this->_owApp->toolbar;
     // show only if not forwarded and if model is writeable
     // TODO: why is isEditable not false here?
     if ($this->_request->getParam('action') == 'properties' && $graph->isEditable() && $this->_owApp->erfurt->getAc()->isModelAllowed('edit', $this->_owApp->selectedModel)) {
         // TODO: check acl
         $toolbar->appendButton(OntoWiki_Toolbar::EDIT, array('name' => 'Edit Properties', 'title' => 'SHIFT + ALT + e'));
         $toolbar->appendButton(OntoWiki_Toolbar::EDITADD, array('name' => 'Clone', 'class' => 'clone-resource', 'title' => 'SHIFT + ALT + l'));
         // ->appendButton(OntoWiki_Toolbar::EDITADD, array('name' => 'Add Property', 'class' => 'property-add'));
         $params = array('name' => 'Delete', 'url' => $this->_config->urlBase . 'resource/delete/?r=' . urlencode((string) $resource));
         $toolbar->appendButton(OntoWiki_Toolbar::SEPARATOR);
         $toolbar->appendButton(OntoWiki_Toolbar::DELETE, $params);
         $toolbar->prependButton(OntoWiki_Toolbar::SEPARATOR);
         $toolbar->prependButton(OntoWiki_Toolbar::ADD, array('name' => 'Add Property', '+class' => 'property-add', 'title' => 'SHIFT + ALT + a'));
         $toolbar->prependButton(OntoWiki_Toolbar::SEPARATOR);
         $toolbar->prependButton(OntoWiki_Toolbar::CANCEL, array('+class' => 'hidden', 'title' => 'SHIFT + ALT + c'));
         $toolbar->prependButton(OntoWiki_Toolbar::SAVE, array('+class' => 'hidden', 'title' => 'SHIFT + ALT + s'));
     }
     // let plug-ins add buttons
     $toolbarEvent = new Erfurt_Event('onCreateToolbar');
     $toolbarEvent->resource = (string) $resource;
     $toolbarEvent->graph = (string) $graph;
     $toolbarEvent->toolbar = $toolbar;
     $eventResult = $toolbarEvent->trigger();
     if ($eventResult instanceof OntoWiki_Toolbar) {
         $toolbar = $eventResult;
     }
     // add toolbar
     $this->view->placeholder('main.window.toolbar')->set($toolbar);
     //show modules
     $this->addModuleContext('main.window.properties');
 }
예제 #5
0
 /**
  * get titles and build link-urls (for a sparql result of the resource query)
  *
  * @param array $resources an array of resource uris
  *
  * @return array
  */
 public function convertResources($resources)
 {
     // add titles first, seperatly
     $uris = array();
     foreach ($resources as $resource) {
         $uris[] = $resource['value'];
     }
     $this->_titleHelper->addResources($uris);
     //$lang = OntoWiki::getInstance()->getConfig()->languages->locale;
     $resourceResults = array();
     foreach ($resources as $resource) {
         $thisResource = $resource;
         $thisResource['uri'] = $resource['value'];
         // the URL to view this resource in detail
         $url = new OntoWiki_Url(array('controller' => 'resource', 'action' => 'properties'), array());
         $url->r = $resource['value'];
         $thisResource['url'] = (string) $url;
         // title
         $thisResource['title'] = $this->_titleHelper->getTitle($resource['value']);
         $resourceResults[] = $thisResource;
     }
     return $resourceResults;
 }
예제 #6
0
 public function getContents()
 {
     $url = new OntoWiki_Url(array('route' => 'properties'));
     if (!empty($this->_subjects)) {
         $instances = array();
         $instancesTitleHelper = new OntoWiki_Model_TitleHelper($this->_owApp->selectedModel);
         $instancesTitleHelper->addResources($this->_subjects, 'resourceUri');
         foreach ($this->_subjects as $instance) {
             $instanceUri = $instance['resourceUri'];
             if (!array_key_exists($instanceUri, $instances)) {
                 // URL
                 $url->setParam('r', $instanceUri, true);
                 $instances[$instanceUri] = array('uri' => $instanceUri, 'title' => $instancesTitleHelper->getTitle($instanceUri, $this->_lang), 'url' => (string) $url);
             }
         }
         $this->view->instances = $instances;
     }
     if (!empty($this->_objects)) {
         $objects = array();
         $objectTitleHelper = new OntoWiki_Model_TitleHelper($this->_owApp->selectedModel);
         $objectTitleHelper->addResources($this->_objects, 'resourceUri');
         foreach ($this->_objects as $object) {
             $objectUri = $object['resourceUri'];
             if (!array_key_exists($objectUri, $objects)) {
                 // URL
                 $url->setParam('r', $objectUri, true);
                 $objects[$objectUri] = array('uri' => $objectUri, 'title' => $objectTitleHelper->getTitle($objectUri, $this->_lang), 'url' => (string) $url);
             }
         }
         $this->view->objects = $objects;
     }
     $url = new OntoWiki_Url(array('controller' => 'resource', 'action' => 'instances'));
     $url->setParam('instancesconfig', json_encode(array('filter' => array(array('id' => 'propertyUsage', 'action' => 'add', 'mode' => 'query', 'query' => (string) $this->_subjectQuery)))));
     $url->setParam('init', true);
     $this->view->subjectListLink = (string) $url;
     $url->setParam('instancesconfig', json_encode(array('filter' => array(array('id' => 'propertyUsage', 'action' => 'add', 'mode' => 'query', 'query' => (string) $this->_objectQuery)))));
     $this->view->objectListLink = (string) $url;
     if (empty($this->_subjects) && empty($this->_objects)) {
         $this->view->message = 'No matches.';
     }
     // render data into template
     return $this->render('usage');
 }
 public function getContents()
 {
     $titleHelper = new OntoWiki_Model_TitleHelper($this->_owApp->selectedModel);
     $query = new Erfurt_Sparql_SimpleQuery();
     $results = false;
     $_predicates = $this->_predicates;
     $properties = array();
     $instances = array();
     $url = new OntoWiki_Url(array('route' => 'properties'), array('r'));
     $titleHelper->addResources($_predicates, 'uri');
     foreach ($_predicates as $predicate) {
         $predicateUri = $predicate['uri'];
         $url->setParam('r', $predicateUri, true);
         // create properties url for the relation
         $properties[$predicateUri]['uri'] = $predicateUri;
         $properties[$predicateUri]['url'] = (string) $url;
         $properties[$predicateUri]['title'] = $titleHelper->getTitle($predicateUri, $this->_lang);
         $query->resetInstance()->setProloguePart('SELECT DISTINCT ?uri')->setWherePart('WHERE {
                     ?uri <' . $predicateUri . '> <' . (string) $this->_owApp->selectedResource . '> .
                     FILTER (isURI(?uri))
                 }')->setLimit(OW_SHOW_MAX + 1);
         if ($subjects = $this->_owApp->selectedModel->sparqlQuery($query)) {
             $results = true;
             // has_more is used for the dots
             if (count($subjects) > OW_SHOW_MAX) {
                 $properties[$predicateUri]['has_more'] = true;
                 $subjects = array_splice($subjects, 0, OW_SHOW_MAX);
             } else {
                 $properties[$predicateUri]['has_more'] = false;
             }
             $subjectTitleHelper = new OntoWiki_Model_TitleHelper($this->_owApp->selectedModel);
             $subjectTitleHelper->addResources($subjects, 'uri');
             foreach ($subjects as $subject) {
                 $subjectUri = $subject['uri'];
                 $subject['title'] = $subjectTitleHelper->getTitle($subjectUri, $this->_lang);
                 // set URL
                 $url->setParam('r', $subjectUri, true);
                 $subject['url'] = (string) $url;
                 if (array_key_exists($predicateUri, $instances)) {
                     if (!array_key_exists($subjectUri, $instances[$predicateUri])) {
                         $instances[$predicateUri][$subjectUri] = $subject;
                     }
                 } else {
                     $instances[$predicateUri] = array($subjectUri => $subject);
                 }
             }
         }
     }
     $this->view->resource = $this->_owApp->selectedResource;
     $this->view->properties = $properties;
     $this->view->instances = $instances;
     if (!$results) {
         $this->view->message = 'No matches.';
     }
     return $this->render('linkinghere');
 }
 /**
  * Searches for properties in the local database.
  *
  * @param array  $termsArray
  * @param string $modelUri
  * @param int    $limit
  *
  * @return array
  */
 private function _searchLocalPropertiesOnly(array $termsArray, $modelUri, $limit)
 {
     require_once 'Erfurt/Sparql/SimpleQuery.php';
     $query = new Erfurt_Sparql_SimpleQuery();
     $query->setProloguePart('SELECT DISTINCT ?uri ?o');
     if (null !== $modelUri) {
         $query->addFrom($modelUri);
     }
     $where = '{ { ?uri ?p ?o . ?uri <' . EF_RDF_TYPE . '> ?o2 .
         FILTER (
             sameTerm(?o2, <http://www.w3.org/1999/02/22-rdf-syntax-ns#Property>) ||
             sameTerm(?o2, <http://www.w3.org/2002/07/owl#DatatypeProperty>) ||
             sameTerm(?o2, <http://www.w3.org/2002/07/owl#ObjectProperty>)
         )
         FILTER ((';
     $uriRegexFilter = array();
     foreach ($termsArray as $t) {
         $uriRegexFilter[] = 'regex(str(?uri), "' . $t . '", "i")';
     }
     $where .= implode(' && ', $uriRegexFilter) . ') || (isLiteral(?o) && ';
     $oRegexFilter = array();
     foreach ($termsArray as $t) {
         $oRegexFilter[] = 'regex(?o, "' . $t . '", "i")';
     }
     $where .= implode(' && ', $oRegexFilter) . ')) } UNION {';
     $where .= '?s ?uri ?o .
               FILTER (';
     $where .= implode(' && ', $uriRegexFilter) . ') } }';
     $query->setWherePart($where);
     $query->setOrderClause('?uri');
     $query->setLimit($limit);
     $store = Erfurt_App::getInstance()->getStore();
     $queryResult = $store->sparqlQuery($query, array('result_format' => 'extended'));
     $tempResult = array();
     foreach ($queryResult['results']['bindings'] as $row) {
         if ($row['o']['type'] === 'literal') {
             $weight = $this->_getWeight($termsArray, $row['uri']['value'], $row['o']['value']);
         } else {
             $weight = $this->_getWeight($termsArray, $row['uri']['value']);
         }
         if (isset($tempResult[$row['uri']['value']])) {
             if ($weight > $tempResult[$row['uri']['value']]) {
                 $tempResult[$row['uri']['value']] = $weight;
             }
         } else {
             $tempResult[$row['uri']['value']] = $weight;
         }
     }
     arsort($tempResult);
     require_once 'OntoWiki/Model/TitleHelper.php';
     require_once 'OntoWiki/Utils.php';
     if (null !== $modelUri) {
         $model = $store->getModel($modelUri, false);
         $titleHelper = new OntoWiki_Model_TitleHelper($model);
     } else {
         $titleHelper = new OntoWiki_Model_TitleHelper();
     }
     $titleHelper->addResources(array_keys($tempResult));
     $translate = $this->_owApp->translate;
     $result = array();
     foreach ($tempResult as $uri => $w) {
         $title = $titleHelper->getTitle($uri);
         if (null !== $title) {
             $result[$uri] = str_replace('|', '&Iota;', $title) . '|' . $uri . '|' . $translate->_('Local Search');
         } else {
             $result[$uri] = OntoWiki_Utils::compactUri($uri) . $uri . '|' . $translate->_('Local Search');
         }
     }
     return $result;
 }
 /**
  * JSON output of the RDFauthor init config, which is a RDF/JSON Model
  * without objects where the user should be able to add data
  *
  * get/post parameters:
  *   mode - class, resource or clone
  *          class: prop list based on one class' resources
  *          resource: prop list based on one resource
  *          clone: prop list and values based on one resource (with new uri)
  *          edit: prop list and values based on one resource
  *   uri  - parameter for mode (class uri, resource uri)
  */
 public function rdfauthorinitAction()
 {
     // 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!');
     }
     if (isset($this->_request->uri) && Zend_Uri::check($this->_request->uri)) {
         $parameter = $this->_request->uri;
     } else {
         throw new OntoWiki_Exception('Missing or invalid parameter uri (clone uri) !');
     }
     if (isset($this->_request->mode)) {
         $workingMode = $this->_request->mode;
     } else {
         $workingMode = 'resource';
     }
     if ($workingMode != 'edit') {
         $resourceUri = $model->getBaseUri() . 'newResource/' . md5(date('F j, Y, g:i:s:u a'));
     } else {
         $resourceUri = $parameter;
     }
     if ($workingMode == 'class') {
         $properties = $model->sparqlQuery('SELECT DISTINCT ?uri ?value {
             ?s ?uri ?value.
             ?s a <' . $parameter . '>.
             } LIMIT 20 ', array('result_format' => 'extended'));
     } elseif ($workingMode == 'clone') {
         // FIXME: more than one values of a property are not supported right now
         // FIXME: Literals are not supported right now
         $properties = $model->sparqlQuery('SELECT ?uri ?value {
             <' . $parameter . '> ?uri ?value.
             #FILTER (isUri(?value))
             } LIMIT 20 ', array('result_format' => 'extended'));
     } elseif ($workingMode == 'edit') {
         $properties = $model->sparqlQuery('SELECT ?uri ?value {
             <' . $parameter . '> ?uri ?value.
             } LIMIT 20 ', array('result_format' => 'extended'));
     } else {
         // resource
         $properties = $model->sparqlQuery('SELECT DISTINCT ?uri ?value {
             <' . $parameter . '> ?uri ?value.
             } LIMIT 20 ', array('result_format' => 'extended'));
     }
     // empty object to hold data
     $output = new stdClass();
     $newProperties = new stdClass();
     $properties = $properties['results']['bindings'];
     // feed title helper w/ URIs
     $titleHelper = new OntoWiki_Model_TitleHelper($model);
     $titleHelper->addResources($properties, 'uri');
     if (!empty($properties)) {
         foreach ($properties as $property) {
             $currentUri = $property['uri']['value'];
             $currentValue = $property['value']['value'];
             $currentType = $property['value']['type'];
             $value = new stdClass();
             if ($currentType == 'literal' || $currentType == 'typed-literal') {
                 if (isset($property['value']['datatype'])) {
                     $value->datatype = $property['value']['datatype'];
                 } else {
                     if (isset($property['value']['xml:lang'])) {
                         $value->lang = $property['value']['xml:lang'];
                     }
                 }
                 /* not in RDFauthor 0.8
                    else {
                        // plain literal --> rdfQuery needs extra quotes
                        $currentValue = '"' . $currentValue . '"';
                    }
                    */
             }
             // return title from titleHelper
             $value->title = $titleHelper->getTitle($currentUri);
             if ($currentUri == EF_RDF_TYPE) {
                 switch ($workingMode) {
                     case 'resource':
                         /* fallthrough */
                     /* fallthrough */
                     case 'clone':
                         $value->value = $currentValue;
                         break;
                     case 'edit':
                         $value->value = $currentValue;
                         break;
                     case 'class':
                         $value->value = $parameter;
                         break;
                 }
                 $value->type = $currentType;
             } else {
                 // $currentUri != EF_RDF_TYPE
                 if ($workingMode == 'clone' || $workingMode == 'edit') {
                     $value->value = $currentValue;
                     $value->type = $currentType;
                 }
                 if ($workingMode == 'class') {
                     $value->value = '';
                     $value->type = $currentType;
                 }
             }
             // deal with multiple values of a property
             if (isset($newProperties->{$currentUri})) {
                 $tempProperty = $newProperties->{$currentUri};
                 $tempProperty[] = $value;
                 $newProperties->{$currentUri} = $tempProperty;
             } else {
                 $newProperties->{$currentUri} = array($value);
             }
         }
         // foreach
         $output->{$resourceUri} = $newProperties;
     } else {
         // empty sparql results -> start with a plain resource
         if ($workingMode == 'class') {
             // for classes, add the rdf:type property
             $value = new stdClass();
             $value->value = $parameter;
             $value->type = 'uri';
             $value->hidden = true;
             $uri = EF_RDF_TYPE;
             $newProperties->{$uri} = array($value);
         }
         $value = new stdClass();
         $value->type = 'literal';
         $value->title = 'label';
         $uri = EF_RDFS_LABEL;
         $newProperties->{$uri} = array($value);
         $output->{$resourceUri} = $newProperties;
     }
     // send the response
     $response->setHeader('Content-Type', 'application/json');
     $response->setBody(json_encode($output));
 }
예제 #10
0
 public function infoAction()
 {
     OntoWiki::getInstance()->getNavigation()->disableNavigation();
     $this->_owApp->selectedResource = new OntoWiki_Resource($this->_request->getParam('m'), $this->_owApp->selectedModel);
     $store = $this->_owApp->erfurt->getStore();
     $graph = $this->_owApp->selectedModel;
     $resource = $this->_owApp->selectedResource;
     //$navigation = $this->_owApp->navigation;
     $translate = $this->_owApp->translate;
     $event = new Erfurt_Event('onPropertiesAction');
     $event->uri = (string) $resource;
     $event->graph = (string) $resource;
     $event->trigger();
     $windowTitle = $translate->_('Model info');
     $this->view->placeholder('main.window.title')->set($windowTitle);
     $title = $resource->getTitle($this->_owApp->getConfig()->languages->locale);
     $this->view->modelTitle = $title ? $title : OntoWiki_Utils::contractNamespace((string) $resource);
     $resourcesUrl = new OntoWiki_Url(array('route' => 'instances'), array());
     $resourcesUrl->init = true;
     $this->view->resourcesUrl = (string) $resourcesUrl;
     if (!empty($resource)) {
         $model = new OntoWiki_Model_Resource($store, $graph, (string) $resource);
         $values = $model->getValues();
         $predicates = $model->getPredicates();
         $titleHelper = new OntoWiki_Model_TitleHelper($graph);
         $graphs = array_keys($predicates);
         $titleHelper->addResources($graphs);
         $graphInfo = array();
         $editableFlags = array();
         foreach ($graphs as $g) {
             $graphInfo[$g] = $titleHelper->getTitle($g, $this->_config->languages->locale);
             $editableFlags[$g] = false;
         }
         $this->view->graphs = $graphInfo;
         $this->view->resourceIri = (string) $resource;
         $this->view->graphIri = $graph->getModelIri();
         $this->view->values = $values;
         $this->view->predicates = $predicates;
         $this->view->graphBaseIri = $graph->getBaseIri();
         $this->view->namespacePrefixes = $graph->getNamespacePrefixes();
         $this->view->editableFlags = $editableFlags;
         if (!is_array($this->view->namespacePrefixes)) {
             $this->view->namespacePrefixes = array();
         }
         if (!array_key_exists(OntoWiki_Utils::DEFAULT_BASE, $this->view->namespacePrefixes)) {
             $this->view->namespacePrefixes[OntoWiki_Utils::DEFAULT_BASE] = $graph->getBaseIri();
         }
         $infoUris = $this->_config->descriptionHelper->properties;
         //echo (string)$resource;
         if (count($values) > 0) {
             $query = 'ASK FROM <' . (string) $resource . '>' . ' WHERE {' . '     <' . (string) $resource . '> a <http://xmlns.com/foaf/0.1/PersonalProfileDocument>' . ' }';
             $q = Erfurt_Sparql_SimpleQuery::initWithString($query);
             if ($this->_owApp->extensionManager->isExtensionActive('foafprofileviewer') && $store->sparqlAsk($q) === true) {
                 $this->view->showFoafLink = true;
                 $this->view->foafLink = $this->_config->urlBase . 'foafprofileviewer/display';
             }
         }
         $this->view->infoPredicates = array();
         foreach ($infoUris as $infoUri) {
             if (isset($predicates[(string) $graph]) && array_key_exists($infoUri, $predicates[(string) $graph])) {
                 $this->view->infoPredicates[$infoUri] = $predicates[(string) $graph][$infoUri];
             }
         }
     }
     $this->addModuleContext('main.window.modelinfo');
 }