public function testCanConstructSomeProperty()
 {
     $property = $this->getMockBuilder('\\SMW\\DIProperty')->disableOriginalConstructor()->getMock();
     $description = $this->getMockBuilder('\\SMW\\Query\\Language\\Description')->disableOriginalConstructor()->getMockForAbstractClass();
     $instance = new DescriptionFactory();
     $this->assertInstanceOf('SMW\\Query\\Language\\SomeProperty', $instance->newSomeProperty($property, $description));
 }
 /**
  * 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 string $displayTitle
  *
  * @return DIProperty|false
  */
 public function getPropertyFromDisplayTitle($displayTitle)
 {
     $descriptionFactory = new DescriptionFactory();
     $description = $descriptionFactory->newSomeProperty(new DIProperty('_DTITLE'), $descriptionFactory->newValueDescription(new DIBlob($displayTitle)));
     $query = new Query($description);
     $query->setLimit(1);
     $dataItems = $this->cachedPropertyValuesPrefetcher->queryPropertyValuesFor($query);
     if (is_array($dataItems) && $dataItems !== array()) {
         $dataItem = end($dataItems);
         // Cache results as a linked list attached to
         // the property so that it can be purged all together
         return new DIProperty($dataItem->getDBKey());
     }
     return false;
 }
 public function descriptionProvider()
 {
     $descriptionFactory = new DescriptionFactory();
     $dataItemFactory = new DataItemFactory();
     #0 Blob + wildcard
     $isFixedPropertyTable = false;
     $indexField = '';
     $sortKeys = array();
     $property = $dataItemFactory->newDIProperty('Foo');
     $property->setPropertyTypeId('_txt');
     $description = $descriptionFactory->newSomeProperty($property, $descriptionFactory->newThingDescription());
     $expected = new \stdClass();
     $expected->type = 1;
     $expected->joinTable = 'FooPropTable';
     $expected->components = array(1 => "t0.p_id");
     $expected->sortfields = array();
     $provider[] = array($description, $isFixedPropertyTable, $indexField, $sortKeys, $expected);
     #1 WikiPage + SMW_CMP_EQ
     $isFixedPropertyTable = false;
     $indexField = 'wikipageIndex';
     $sortKeys = array();
     $property = $dataItemFactory->newDIProperty('Foo');
     $property->setPropertyTypeId('_wpg');
     $description = $descriptionFactory->newSomeProperty($property, $descriptionFactory->newValueDescription($dataItemFactory->newDIWikiPage('Bar', NS_MAIN), null, SMW_CMP_EQ));
     $expected = new \stdClass();
     $expected->type = 1;
     $expected->joinTable = 'FooPropTable';
     $expected->components = array(1 => "t0.p_id", 2 => "t0.wikipageIndex");
     $expected->queryNumber = 0;
     $expected->where = '';
     $expected->sortfields = array();
     $provider[] = array($description, $isFixedPropertyTable, $indexField, $sortKeys, $expected);
     #2 WikiPage + SMW_CMP_EQ + sort
     $isFixedPropertyTable = false;
     $indexField = 'wikipageIndex';
     $sortKeys = array('Foo' => 'DESC');
     $property = $dataItemFactory->newDIProperty('Foo');
     $property->setPropertyTypeId('_wpg');
     $description = $descriptionFactory->newSomeProperty($property, $descriptionFactory->newValueDescription($dataItemFactory->newDIWikiPage('Bar', NS_MAIN), null, SMW_CMP_EQ));
     $expected = new \stdClass();
     $expected->type = 1;
     $expected->joinTable = 'FooPropTable';
     $expected->components = array(1 => "t0.p_id", 2 => "t0.wikipageIndex");
     $expected->queryNumber = 0;
     $expected->where = '';
     $expected->sortfields = array('Foo' => 'idst0.smw_sortkey');
     $expected->from = ' INNER JOIN  AS idst0 ON idst0.smw_id=t0.wikipageIndex';
     $provider[] = array($description, $isFixedPropertyTable, $indexField, $sortKeys, $expected);
     #3 Blob + SMW_CMP_EQ
     $isFixedPropertyTable = false;
     $indexField = 'blobIndex';
     $sortKeys = array();
     $property = $dataItemFactory->newDIProperty('Foo');
     $property->setPropertyTypeId('_txt');
     $description = $descriptionFactory->newSomeProperty($property, $descriptionFactory->newValueDescription($dataItemFactory->newDIBlob('Bar'), null, SMW_CMP_EQ));
     $expected = new \stdClass();
     $expected->type = 1;
     $expected->joinTable = 'FooPropTable';
     $expected->components = array(1 => "t0.p_id");
     $expected->queryNumber = 0;
     $expected->where = '(t0.blobIndex=fixedFooWhereCond)';
     $expected->sortfields = array();
     $provider[] = array($description, $isFixedPropertyTable, $indexField, $sortKeys, $expected);
     #4 Blob + SMW_CMP_EQ + sort
     $isFixedPropertyTable = false;
     $indexField = 'blobIndex';
     $sortKeys = array('Foo' => 'ASC');
     $property = $dataItemFactory->newDIProperty('Foo');
     $property->setPropertyTypeId('_txt');
     $description = $descriptionFactory->newSomeProperty($property, $descriptionFactory->newValueDescription($dataItemFactory->newDIBlob('Bar'), null, SMW_CMP_EQ));
     $expected = new \stdClass();
     $expected->type = 1;
     $expected->joinTable = 'FooPropTable';
     $expected->components = array(1 => "t0.p_id");
     $expected->queryNumber = 0;
     $expected->where = '(t0.blobIndex=fixedFooWhereCond)';
     $expected->sortfields = array('Foo' => 't0.blobIndex');
     $expected->from = '';
     $provider[] = array($description, $isFixedPropertyTable, $indexField, $sortKeys, $expected);
     #5 Check SemanticMaps compatibility mode (invokes `getSQLCondition`)
     $isFixedPropertyTable = false;
     $indexField = 'blobIndex';
     $sortKeys = array();
     $property = $dataItemFactory->newDIProperty('Foo');
     $property->setPropertyTypeId('_txt');
     $valueDescription = $this->getMockBuilder('\\SMW\\Query\\Language\\ValueDescription')->disableOriginalConstructor()->setMethods(array('getSQLCondition', 'getDataItem'))->getMock();
     $valueDescription->expects($this->any())->method('getProperty')->will($this->returnValue($property));
     $valueDescription->expects($this->any())->method('getDataItem')->will($this->returnValue($dataItemFactory->newDIBlob('13,56')));
     $valueDescription->expects($this->once())->method('getSQLCondition')->will($this->returnValue('foo AND bar'));
     $description = $descriptionFactory->newSomeProperty($property, $valueDescription);
     $expected = new \stdClass();
     $expected->type = 1;
     $expected->joinTable = 'FooPropTable';
     $expected->components = array(1 => "t0.p_id");
     $expected->queryNumber = 0;
     $expected->where = '(foo AND bar)';
     $expected->sortfields = array();
     $expected->from = '';
     $provider[] = array($description, $isFixedPropertyTable, $indexField, $sortKeys, $expected);
     #6, see 556
     $isFixedPropertyTable = false;
     $indexField = '';
     $sortKeys = array();
     $property = $dataItemFactory->newDIProperty('Foo');
     $property->setPropertyTypeId('_txt');
     $description = $descriptionFactory->newSomeProperty($property, $descriptionFactory->newDisjunction(array($descriptionFactory->newValueDescription($dataItemFactory->newDIBlob('Bar')), $descriptionFactory->newValueDescription($dataItemFactory->newDIBlob('Baz')))));
     $expected = new \stdClass();
     $expected->type = 1;
     $expected->joinTable = 'FooPropTable';
     $expected->components = array(1 => "t0.p_id");
     $expected->queryNumber = 0;
     $expected->where = '((t0.=fixedFooWhereCond) OR (t0.=fixedFooWhereCond))';
     $expected->sortfields = array();
     $expected->from = '';
     $provider[] = array($description, $isFixedPropertyTable, $indexField, $sortKeys, $expected);
     return $provider;
 }