コード例 #1
0
 /**
  * Constructor.
  * 
  * @since 0.6
  * 
  * @param SMWDataItem $dataItem
  * @param string $comparator
  * @param string $radius
  */
 public function __construct(SMWDataItem $dataItem, $comparator, $radius)
 {
     parent::__construct($dataItem, $comparator);
     // Only if the MapsGeoFunctions class is  loaded, we can create the bounding box.
     if (self::geoFunctionsAreAvailable()) {
         $this->calculateBounds($dataItem, $radius);
     }
 }
コード例 #2
0
 /**
  * @param SMWDataItem $areaCenter
  * @param string $comparator
  * @param string $radius
  * @param SMWDIProperty $property
  *
  * @throws InvalidArgumentException
  */
 public function __construct(SMWDataItem $areaCenter, $comparator, $radius, SMWDIProperty $property = null)
 {
     if (!$areaCenter instanceof SMWDIGeoCoord) {
         throw new InvalidArgumentException('$areaCenter needs to be a SMWDIGeoCoord');
     }
     parent::__construct($areaCenter, $property, $comparator);
     $this->radius = MapsDistanceParser::parseDistance($radius);
     $this->center = $areaCenter;
     $this->bounds = $this->getBoundingBox();
 }
コード例 #3
0
 /**
  * Create an SMWSparqlCondition from an SMWValueDescription.
  *
  * @param $description SMWValueDescription
  * @param $joinVariable string name, see buildSparqlCondition()
  * @param $orderByProperty mixed SMWDIProperty or null, see buildSparqlCondition()
  * @return SMWSparqlCondition
  */
 protected function buildValueCondition(SMWValueDescription $description, $joinVariable, $orderByProperty)
 {
     $dataItem = $description->getDataItem();
     switch ($description->getComparator()) {
         case SMW_CMP_EQ:
             $comparator = '=';
             break;
         case SMW_CMP_LESS:
             $comparator = '<';
             break;
         case SMW_CMP_GRTR:
             $comparator = '>';
             break;
         case SMW_CMP_LEQ:
             $comparator = '<=';
             break;
         case SMW_CMP_GEQ:
             $comparator = '>=';
             break;
         case SMW_CMP_NEQ:
             $comparator = '!=';
             break;
         case SMW_CMP_LIKE:
             $comparator = 'regex';
             break;
         case SMW_CMP_NLKE:
             $comparator = '!regex';
             break;
         default:
             $comparator = '';
             // unkown, unsupported
     }
     if ($comparator === '') {
         $result = $this->buildTrueCondition($joinVariable, $orderByProperty);
     } elseif ($comparator == '=') {
         $expElement = SMWExporter::getDataItemHelperExpElement($dataItem);
         if (is_null($expElement)) {
             $expElement = SMWExporter::getDataItemExpElement($dataItem);
         }
         $result = new SMWSparqlSingletonCondition($expElement);
         $this->addOrderByDataForProperty($result, $joinVariable, $orderByProperty, $dataItem->getDIType());
     } elseif ($comparator == 'regex' || $comparator == '!regex') {
         if ($dataItem instanceof SMWDIBlob) {
             $pattern = '^' . str_replace(array('^', '.', '\\', '+', '{', '}', '(', ')', '|', '^', '$', '[', ']', '*', '?'), array('\\^', '\\.', '\\\\', '\\+', '\\{', '\\}', '\\(', '\\)', '\\|', '\\^', '\\$', '\\[', '\\]', '.*', '.'), $dataItem->getString()) . '$';
             $result = new SMWSparqlFilterCondition("{$comparator}( ?{$joinVariable}, \"{$pattern}\", \"s\")", array());
             $this->addOrderByDataForProperty($result, $joinVariable, $orderByProperty, $dataItem->getDIType());
         } else {
             $result = $this->buildTrueCondition($joinVariable, $orderByProperty);
         }
     } else {
         $result = new SMWSparqlFilterCondition('', array());
         $this->addOrderByData($result, $joinVariable, $dataItem->getDIType());
         $orderByVariable = $result->orderByVariable;
         if ($dataItem instanceof SMWDIWikiPage) {
             $expElement = SMWExporter::getDataItemExpElement($dataItem->getSortKeyDataItem());
         } else {
             $expElement = SMWExporter::getDataItemHelperExpElement($dataItem);
             if (is_null($expElement)) {
                 $expElement = SMWExporter::getDataItemExpElement($dataItem);
             }
         }
         $valueName = SMWTurtleSerializer::getTurtleNameForExpElement($expElement);
         if ($expElement instanceof SMWExpNsResource) {
             $result->namespaces[$expElement->getNamespaceId()] = $expElement->getNamespace();
         }
         $result->filter = "?{$orderByVariable} {$comparator} {$valueName}";
     }
     return $result;
 }
コード例 #4
0
 /**
  * Given an SMWDescription that is just a conjunction or disjunction of
  * SMWValueDescription objects, create and return a plain WHERE condition
  * string for it.
  *
  * @param $query
  * @param SMWDescription $description
  * @param SMWSQLStore3Table $proptable
  * @param SMWDataItemHandler $diHandler for that table
  * @param string $operator SQL operator "AND" or "OR"
  */
 protected function compileValueDescription($query, SMWValueDescription $description, SMWSQLStore3Table $proptable, SMWDataItemHandler $diHandler, $operator)
 {
     $where = '';
     $dataItem = $description->getDataItem();
     // TODO Better get the handle from the property type
     // Some comparators (e.g. LIKE) could use DI values of
     // a different type; we care about the property table, not
     // about the value
     $diType = $dataItem->getDIType();
     // Try comparison based on value field and comparator,
     // but only if no join with SMW IDs table is needed.
     if ($diType != SMWDataItem::TYPE_WIKIPAGE) {
         // Do not support smw_id joined data for now.
         // See if the getSQLCondition method exists and call it if this is the case.
         if (method_exists($description, 'getSQLCondition')) {
             $fields = $diHandler->getTableFields();
             $where = $description->getSQLCondition($query->alias, array_keys($fields), $this->m_dbs);
         }
         if ($where == '') {
             $indexField = $diHandler->getIndexField();
             //Hack to get to the field used as index
             $keys = $diHandler->getWhereConds($dataItem);
             $value = $keys[$indexField];
             switch ($description->getComparator()) {
                 case SMW_CMP_EQ:
                     $comparator = '=';
                     break;
                 case SMW_CMP_LESS:
                     $comparator = '<';
                     break;
                 case SMW_CMP_GRTR:
                     $comparator = '>';
                     break;
                 case SMW_CMP_LEQ:
                     $comparator = '<=';
                     break;
                 case SMW_CMP_GEQ:
                     $comparator = '>=';
                     break;
                 case SMW_CMP_NEQ:
                     $comparator = '!=';
                     break;
                 case SMW_CMP_LIKE:
                 case SMW_CMP_NLKE:
                     if ($description->getComparator() == SMW_CMP_LIKE) {
                         $comparator = ' LIKE ';
                     } else {
                         $comparator = ' NOT LIKE ';
                     }
                     // Escape to prepare string matching:
                     $value = str_replace(array('%', '_', '*', '?'), array('\\%', '\\_', '%', '_'), $value);
                     break;
                 default:
                     throw new MWException("Unsupported comparator '" . $description->getComparator() . "' in query condition.");
             }
             $where = "{$query->alias}.{$indexField}{$comparator}" . $this->m_dbs->addQuotes($value);
         }
     } else {
         // exact match (like comparator = above, but not using $valueField
         throw new MWException("Debug -- this code might be dead.");
         foreach ($diHandler->getWhereConds($dataItem) as $fieldname => $value) {
             $where .= ($where ? ' AND ' : '') . "{$query->alias}.{$fieldname}=" . $this->m_dbs->addQuotes($value);
         }
     }
     if ($where !== '') {
         $query->where .= ($query->where ? " {$operator} " : '') . "({$where})";
     }
 }
コード例 #5
0
 /**
  * Constructor.
  * 
  * @since 0.8
  * 
  * @param SMWDataItem $dataItem
  */
 public function __construct(SMWDataItem $dataItem, $comparator)
 {
     parent::__construct($dataItem, $comparator);
 }