Beispiel #1
0
 /**
  * Short description of method getPropertiesValues
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @param  Resource resource
  * @param  array properties
  * @return array
  */
 public function getPropertiesValues(core_kernel_classes_Resource $resource, $properties)
 {
     $returnValue = array();
     // check whenever or not properties is empty
     if (count($properties) == 0) {
         return array();
     }
     /*foreach($properties as $property){
       	$returnValue[$property->getUri()] = $this->getPropertyValues($resource, $property);
       }*/
     $predicatesQuery = '';
     //build the predicate query
     //$predicatesQuery = implode(',', $properties);
     foreach ($properties as $property) {
         $uri = is_string($property) ? $property : $property->getUri();
         $returnValue[$uri] = array();
         $predicatesQuery .= ", " . $this->getPersistence()->quote($uri);
     }
     $predicatesQuery = substr($predicatesQuery, 1);
     $platform = $this->getPersistence()->getPlatForm();
     //the unique sql query
     $query = 'SELECT predicate, object, l_language 
         FROM statements 
         WHERE 
             subject = ' . $this->getPersistence()->quote($resource->getUri()) . ' 
             AND predicate IN (' . $predicatesQuery . ')
             AND (' . $platform->isNullCondition('l_language') . ' OR l_language = ' . $this->getPersistence()->quote(DEFAULT_LANG) . ' OR l_language = ' . $this->getPersistence()->quote(\common_session_SessionManager::getSession()->getDataLanguage()) . ') 
             AND ' . $this->getModelReadSqlCondition();
     $result = $this->getPersistence()->query($query);
     $rows = $result->fetchAll();
     $sortedByLg = Utils::sortByLanguage($this->getPersistence(), $rows, 'l_language');
     $identifiedLg = Utils::identifyFirstLanguage($sortedByLg);
     foreach ($rows as $row) {
         $value = $platform->getPhpTextValue($row['object']);
         $returnValue[$row['predicate']][] = common_Utils::isUri($value) ? new core_kernel_classes_Resource($value) : new core_kernel_classes_Literal($value);
     }
     return (array) $returnValue;
 }
Beispiel #2
0
 /**
  *
  * @param core_kernel_classes_Class $resource
  * @param array $propertyFilters
  * @param array $options
  * @return string
  */
 public function getFilteredQuery(core_kernel_classes_Class $resource, $propertyFilters = array(), $options = array())
 {
     $rdftypes = array();
     // Check recursivity...
     if (isset($options['recursive']) && $options['recursive']) {
         foreach ($this->getSubClasses($resource, $options['recursive']) as $subClass) {
             $rdftypes[] = $subClass->getUri();
         }
     }
     // Check additional classes...
     if (isset($options['additionalClasses'])) {
         foreach ($options['additionalClasses'] as $aC) {
             $rdftypes[] = $aC instanceof core_kernel_classes_Resource ? $aC->getUri() : $aC;
             $rdftypes = array_unique($rdftypes);
         }
     }
     // Add the class type of the given class
     if (!in_array($resource->getUri(), $rdftypes)) {
         $rdftypes[] = $resource->getUri();
     }
     $and = isset($options['chaining']) === false ? true : (strtolower($options['chaining']) === 'and' ? true : false);
     $like = isset($options['like']) === false ? true : $options['like'];
     $lang = isset($options['lang']) === false ? '' : $options['lang'];
     $offset = isset($options['offset']) === false ? 0 : $options['offset'];
     $limit = isset($options['limit']) === false ? 0 : $options['limit'];
     $order = isset($options['order']) === false ? '' : $options['order'];
     $orderdir = isset($options['orderdir']) === false ? 'ASC' : $options['orderdir'];
     $query = Utils::buildFilterQuery($this->getModel(), $rdftypes, $propertyFilters, $and, $like, $lang, $offset, $limit, $order, $orderdir);
     return $query;
 }