/**
  * @since 2.2
  *
  * @param Description $description
  *
  * @return QuerySegment
  */
 public function interpretDescription(Description $description)
 {
     $query = new QuerySegment();
     $cqid = QuerySegment::$qnum;
     $cquery = new QuerySegment();
     $cquery->type = QuerySegment::Q_CLASS_HIERARCHY;
     $cquery->joinfield = array();
     foreach ($description->getCategories() as $category) {
         $categoryId = $this->queryBuilder->getStore()->getObjectIds()->getSMWPageID($category->getDBkey(), NS_CATEGORY, $category->getInterwiki(), '');
         if ($categoryId != 0) {
             $cquery->joinfield[] = $categoryId;
         }
     }
     if (count($cquery->joinfield) == 0) {
         // Empty result.
         $query->type = QuerySegment::Q_VALUE;
         $query->joinTable = '';
         $query->joinfield = '';
     } else {
         // Instance query with disjunction of classes (categories)
         $query->joinTable = $this->queryBuilder->getStore()->findPropertyTableID(new DIProperty('_INST'));
         $query->joinfield = "{$query->alias}.s_id";
         $query->components[$cqid] = "{$query->alias}.o_id";
         $this->queryBuilder->addQuerySegmentForId($cqid, $cquery);
     }
     return $query;
 }
Ejemplo n.º 2
0
 /**
  * Create an Condition from an ClassDescription.
  *
  * @param ClassDescription $description
  * @param string $joinVariable
  * @param DIProperty|null $orderByProperty
  *
  * @return Condition
  */
 public function buildCondition(Description $description, $joinVariable, $orderByProperty = null)
 {
     list($condition, $namespaces) = $this->mapCategoriesToConditionElements($description->getCategories(), $joinVariable);
     // empty disjunction: always false, no results to order
     if ($condition === '') {
         return new FalseCondition();
     }
     $result = new WhereCondition($condition, true, $namespaces);
     $this->compoundConditionBuilder->addOrderByDataForProperty($result, $joinVariable, $orderByProperty, DataItem::TYPE_WIKIPAGE);
     return $result;
 }