public function descriptionProvider()
 {
     $descriptionFactory = new DescriptionFactory();
     #0 Disjunction
     $description = $descriptionFactory->newDisjunction();
     $description->addDescription($descriptionFactory->newNamespaceDescription(NS_HELP));
     $description->addDescription($descriptionFactory->newNamespaceDescription(NS_MAIN));
     $expectedDisjunction = new \stdClass();
     $expectedDisjunction->type = 3;
     $expectedDisjunction->components = array(1 => true, 2 => true);
     $provider[] = array($description, $expectedDisjunction);
     #1 Conjunction
     $description = $descriptionFactory->newConjunction();
     $description->addDescription($descriptionFactory->newNamespaceDescription(NS_HELP));
     $description->addDescription($descriptionFactory->newNamespaceDescription(NS_MAIN));
     $expectedConjunction = new \stdClass();
     $expectedConjunction->type = 4;
     $expectedConjunction->components = array(1 => true, 2 => true);
     $provider[] = array($description, $expectedConjunction);
     #2 No query
     $description = $descriptionFactory->newConjunction();
     $description->addDescription($descriptionFactory->newThingDescription());
     $expectedConjunction = new \stdClass();
     $expectedConjunction->type = 0;
     $expectedConjunction->components = array();
     $provider[] = array($description, $expectedConjunction);
     return $provider;
 }
 private function newDisjunctionFor($currentDescription, $newDescription)
 {
     if ($this->queryFeatures & SMW_DISJUNCTION_QUERY) {
         return $this->descriptionFactory->newDisjunction(array($currentDescription, $newDescription));
     }
     $this->addErrorWithMsgKey('smw_nodisjunctions', $newDescription->getQueryString());
     return $currentDescription;
 }
 /**
  * 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;
 }
 public function descriptionProvider()
 {
     $descriptionFactory = new DescriptionFactory();
     $dataItemFactory = new DataItemFactory();
     #0 No concept
     $concept = false;
     $description = $descriptionFactory->newConceptDescription($dataItemFactory->newDIWikiPage('Foo', SMW_NS_CONCEPT));
     $expected = new \stdClass();
     $expected->type = 1;
     $expected->joinfield = '';
     $provider[] = array($description, $concept, $expected);
     #1 Cached concept
     $concept = new \stdClass();
     $concept->concept_size = 1;
     $concept->concept_features = 1;
     $concept->concept_depth = 1;
     $concept->cache_date = strtotime("now");
     $description = $descriptionFactory->newConceptDescription($dataItemFactory->newDIWikiPage('Foo', SMW_NS_CONCEPT));
     $expected = new \stdClass();
     $expected->type = 1;
     $expected->joinfield = 't0.s_id';
     $expected->where = 't0.o_id=42';
     $expected->queryNumber = 0;
     $provider[] = array($description, $concept, $expected);
     #2 Non cached concept
     $concept = new \stdClass();
     $concept->concept_txt = "[[Category:Foo]]";
     $concept->concept_size = 1;
     $concept->concept_features = 1;
     $concept->concept_depth = 1;
     $concept->cache_date = false;
     $description = $descriptionFactory->newConceptDescription($dataItemFactory->newDIWikiPage('Foo', SMW_NS_CONCEPT));
     $expected = new \stdClass();
     $expected->type = 1;
     $expected->joinfield = 't1.s_id';
     $expected->components = array(2 => 't1.o_id');
     $expected->queryNumber = 1;
     $provider[] = array($description, $concept, $expected);
     return $provider;
 }
 public function descriptionProvider()
 {
     $descriptionFactory = new DescriptionFactory();
     $dataItemFactory = new DataItemFactory();
     #0
     $pageId = 42;
     $description = $descriptionFactory->newClassDescription($dataItemFactory->newDIWikiPage('Foo', NS_CATEGORY));
     $expected = new \stdClass();
     $expected->type = 1;
     $expected->components = array(1 => "t0.o_id");
     $expected->joinfield = "t0.s_id";
     $provider[] = array($description, $pageId, $expected);
     #1 Empty
     $pageId = 0;
     $description = $descriptionFactory->newClassDescription($dataItemFactory->newDIWikiPage('Foo', NS_CATEGORY));
     $expected = new \stdClass();
     $expected->type = 2;
     $expected->components = array();
     $expected->joinfield = "";
     $provider[] = array($description, $pageId, $expected);
     return $provider;
 }
 public function descriptionProvider()
 {
     $descriptionFactory = new DescriptionFactory();
     $dataItemFactory = new DataItemFactory();
     #0 SMW_CMP_EQ
     $description = $descriptionFactory->newValueDescription($dataItemFactory->newDIWikiPage('Foo', NS_MAIN), null, SMW_CMP_EQ);
     $expected = new \stdClass();
     $expected->type = 2;
     $expected->alias = "t0";
     $expected->joinfield = array(42);
     $provider[] = array($description, $expected);
     #1 SMW_CMP_LEQ
     $description = $descriptionFactory->newValueDescription($dataItemFactory->newDIWikiPage('Foo', NS_MAIN), null, SMW_CMP_LEQ);
     $expected = new \stdClass();
     $expected->type = 1;
     $expected->alias = "t0";
     $expected->joinfield = "t0.smw_id";
     $expected->where = "t0.smw_sortkey<=Foo";
     $provider[] = array($description, $expected);
     #2 SMW_CMP_LIKE
     $description = $descriptionFactory->newValueDescription($dataItemFactory->newDIWikiPage('Foo', NS_MAIN), null, SMW_CMP_LIKE);
     $expected = new \stdClass();
     $expected->type = 1;
     $expected->alias = "t0";
     $expected->joinfield = "t0.smw_id";
     $expected->where = "t0.smw_sortkey LIKE Foo";
     $provider[] = array($description, $expected);
     #3 not a DIWikiPage
     $description = $descriptionFactory->newValueDescription($dataItemFactory->newDIBLob('Foo'));
     $expected = new \stdClass();
     $expected->type = 1;
     $expected->joinfield = "";
     $expected->where = "";
     $provider[] = array($description, $expected);
     return $provider;
 }
 public function testCanConstructDescriptionFromMonolingualTextValueWithProperty()
 {
     $containerSemanticData = $this->getMockBuilder('\\SMWContainerSemanticData')->disableOriginalConstructor()->getMock();
     $containerSemanticData->expects($this->atLeastOnce())->method('getPropertyValues')->will($this->returnValue(array($this->dataItemFactory->newDIBlob('Bar'))));
     $dataValue = $this->getMockBuilder('\\SMW\\DataValues\\MonolingualTextValue')->disableOriginalConstructor()->setMethods(array('isValid', 'getProperty', 'getDataItem'))->getMock();
     $dataValue->expects($this->atLeastOnce())->method('isValid')->will($this->returnValue(true));
     $dataValue->expects($this->atLeastOnce())->method('getProperty')->will($this->returnValue($this->dataItemFactory->newDIProperty('Foo')));
     $dataValue->expects($this->atLeastOnce())->method('getDataItem')->will($this->returnValue($this->dataItemFactory->newDIContainer($containerSemanticData)));
     $instance = new DescriptionFactory();
     $this->assertInstanceOf('SMW\\Query\\Language\\SomeProperty', $instance->newFromDataValue($dataValue));
 }
 public function testCanConstructConceptDescription()
 {
     $concept = $this->getMockBuilder('\\SMW\\DIWikiPage')->disableOriginalConstructor()->getMock();
     $instance = new DescriptionFactory();
     $this->assertInstanceOf('SMW\\Query\\Language\\ConceptDescription', $instance->newConceptDescription($concept));
 }
 /**
  * @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;
 }