Esempio n. 1
0
 protected function getPagesFromQuery()
 {
     // get number of pages and fix query limit
     $query = SMWQueryProcessor::createQuery($this->query, SMWQueryProcessor::getProcessedParams(array('format' => 'count')));
     $result = $this->store->getQueryResult($query);
     // get pages and add them to the pages explicitly listed in the 'page' parameter
     $query = SMWQueryProcessor::createQuery($this->query, SMWQueryProcessor::getProcessedParams(array()));
     $query->setUnboundLimit($result instanceof \SMWQueryResult ? $result->getCountValue() : $result);
     return $this->store->getQueryResult($query)->getResults();
 }
 /**
  * Returns all results that have a value near to the searched for value
  * on the property, ordered, and sorted by ending with the smallest
  * one.
  *
  * @param QueryOptions $pageRequestOptions
  * @param integer $count How many entities have the exact same value on the property?
  * @param integer $greater Should the values be bigger? Set false for smaller values.
  *
  * @return array of array of SMWWikiPageValue, SMWDataValue with the
  * first being the entity, and the second the value
  */
 public function doQueryForNearbyResults(PageRequestOptions $pageRequestOptions, $count, $greater = true)
 {
     $comparator = $greater ? SMW_CMP_GRTR : SMW_CMP_LESS;
     $sortOrder = $greater ? 'ASC' : 'DESC';
     if ($pageRequestOptions->value !== null && $pageRequestOptions->value->getTypeID() === '_txt' && strlen($pageRequestOptions->valueString) > 72) {
         $comparator = SMW_CMP_LIKE;
     }
     $descriptionFactory = new DescriptionFactory();
     if ($pageRequestOptions->valueString === '' || $pageRequestOptions->valueString === null) {
         $description = $descriptionFactory->newThingDescription();
     } else {
         $description = $descriptionFactory->newValueDescription($pageRequestOptions->value->getDataItem(), $pageRequestOptions->property->getDataItem(), $comparator);
         $description = $descriptionFactory->newSomeProperty($pageRequestOptions->property->getDataItem(), $description);
     }
     $query = new Query($description);
     $query->setLimit($pageRequestOptions->limit);
     $query->setOffset($pageRequestOptions->offset);
     $query->sort = true;
     $query->sortkeys = array($pageRequestOptions->property->getDataItem()->getKey() => $sortOrder);
     // Note: printrequests change the caption of properties they
     // get (they expect properties to be given to them).
     // Since we want to continue using the property for our
     // purposes, we give a clone to the print request.
     $printouts = array(new PrintRequest(PrintRequest::PRINT_THIS, ''), new PrintRequest(PrintRequest::PRINT_PROP, '', clone $pageRequestOptions->property));
     $query->setExtraPrintouts($printouts);
     $queryResults = $this->store->getQueryResult($query);
     $result = array();
     while ($resultArrays = $queryResults->getNext()) {
         $r = array();
         foreach ($resultArrays as $resultArray) {
             $r[] = $resultArray->getNextDataValue();
         }
         // Note: if results have multiple values for the property
         // then this code just pick the first, which may not be
         // the reason why the result is shown here, i.e., it could
         // be out of order.
         $result[] = $r;
     }
     if (!$greater) {
         $result = array_reverse($result);
     }
     return $result;
 }
 /**
  * @since 2.4
  *
  * @param Query $query
  *
  * @return array
  */
 public function queryPropertyValuesFor(Query $query)
 {
     return $this->store->getQueryResult($query)->getResults();
 }