protected function _fetchDescription($maxDepth) { $query = new Erfurt_Sparql_SimpleQuery(); $query->setProloguePart('SELECT ?p ?o')->setWherePart(sprintf('{<%s> ?p ?o . }', $this->getIri())); $description = array(); $result = null; if ($this->_model) { $result = $this->_model->sparqlQuery($query, array('result_format' => 'extended')); } else { $result = Erfurt_App::getInstance()->getStore()->sparqlQuery($query, array('result_format' => 'extended')); } if ($maxDepth > 0 && $result) { foreach ($result['results']['bindings'] as $row) { $property = $row['p']['value']; $this->_descriptionResource($property); $currentValue = array('type' => $row['o']['type'], 'value' => $row['o']['value']); if ($row['o']['type'] == 'uri') { $this->_descriptionResource($row['o']['value']); } else { if ($row['o']['type'] == 'typed-literal') { $currentValue['type'] = 'literal'; $currentValue['datatype'] = $row['o']['datatype']; } else { if (isset($row['o']['xml:lang'])) { $currentValue['lang'] = $row['o']['xml:lang']; } } } if (!array_key_exists($property, $description)) { $description[$property] = array(); } array_push($description[$property], $currentValue); if ($row['o']['type'] === 'bnode') { $nodeId = $row['o']['value']; $bNode = self::initWithBlankNode($nodeId, $this->_model); $nodeKey = sprintf('_:%s', $nodeId); $description[$nodeKey] = $bNode->getDescription($maxDepth - 1); } } } return array($this->getIri() => $description); }
/** * Load Naming Scheme from Model or Ini * * @param $resource String|Array eigther the resource URI or an array with its properties * * @return Array */ private function loadNamingSchema($resource) { if (isset($this->_config->namingSchemeProperty)) { $schemeProperty = $this->_config->namingSchemeProperty; // set the query result as empty array so we can be sure its an array $result = array(); if (is_string($resource)) { $resourceUri = $resource; $query = 'SELECT ?scheme' . PHP_EOL; $query .= 'WHERE {' . PHP_EOL; $query .= ' <' . $resourceUri . '> a ?type .' . PHP_EOL; $query .= ' ?type <' . $schemeProperty . '> ?scheme .' . PHP_EOL; $query .= '}' . PHP_EOL; $result = $this->_model->sparqlQuery($query); } else { if (is_array($resource)) { $resourceProps = $resource; $types = $resourceProps[$this->_config->property->type]; foreach ($types as $type) { if ($type['type'] == 'uri') { $query = 'SELECT ?scheme' . PHP_EOL; $query .= 'WHERE {' . PHP_EOL; $query .= ' <' . $type['value'] . '> <' . $schemeProperty . '> ?scheme .' . PHP_EOL; $query .= '}' . PHP_EOL; $result = $this->_model->sparqlQuery($query); if (count($result) > 0) { // break with the first type which has a sheme defined break; } } } } } if (count($result) > 0) { $scheme = $result[0]['scheme']; return explode('/', $scheme); } } return explode('/', $this->_config->defaultNamingScheme); }