コード例 #1
0
 /**
  * Sets up this test case
  *
  * @return void
  */
 public function setUp()
 {
     $this->mockPersistenceManager = $this->getMock('Tx_Extbase_Persistence_ManagerInterface');
     $this->mockPersistenceManager->expects($this->any())->method('getObjectDataByQuery')->will($this->returnValue(array('one', 'two')));
     $this->mockPersistenceManager->expects($this->any())->method('getObjectCountByQuery')->will($this->returnValue(2));
     $this->mockDataMapper = $this->getMock('Tx_Extbase_Persistence_Mapper_DataMapper');
     $this->mockQuery = $this->getMock('Tx_Extbase_Persistence_QueryInterface');
     $this->queryResult = new Tx_Extbase_Persistence_QueryResult($this->mockQuery);
     $this->queryResult->injectPersistenceManager($this->mockPersistenceManager);
     $this->queryResult->injectDataMapper($this->mockDataMapper);
     $this->sampleResult = array(array('foo' => 'Foo1', 'bar' => 'Bar1'), array('foo' => 'Foo2', 'bar' => 'Bar2'));
     $this->mockDataMapper->expects($this->any())->method('map')->will($this->returnValue($this->sampleResult));
 }
コード例 #2
0
ファイル: Query.php プロジェクト: NaveedWebdeveloper/Test
 /**
  * Gets the node-tuple source for this query.
  *
  * @return Tx_Extbase_Persistence_QOM_SourceInterface the node-tuple source; non-null
  */
 public function getSource()
 {
     if ($this->source === NULL) {
         $this->source = $this->qomFactory->selector($this->getType(), $this->dataMapper->convertClassNameToTableName($this->getType()));
     }
     return $this->source;
 }
コード例 #3
0
 /**
  * Executes the query against the database and returns the result
  *
  * @return array<object> The query result as an array of objects
  * @api
  */
 public function execute()
 {
     $rows = $this->persistenceManager->getObjectDataByQuery($this);
     if ($this->getQuerySettings()->getReturnRawQueryResult() === TRUE) {
         return $rows;
     } else {
         return $this->dataMapper->map($this->getType(), $rows);
     }
 }
コード例 #4
0
 /**
  * Populate this proxy by asking the $population closure.
  *
  * @return object The instance (hopefully) returned
  */
 public function _loadRealInstance()
 {
     // this check safeguards against a proxy being activated multiple times
     // usually that does not happen, but if the proxy is held from outside
     // it's parent... the result would be weird.
     if ($this->parentObject->_getProperty($this->propertyName) instanceof Tx_Extbase_Persistence_LazyLoadingProxy) {
         $objects = $this->dataMapper->fetchRelated($this->parentObject, $this->propertyName, $this->fieldValue, FALSE, FALSE);
         $propertyValue = $this->dataMapper->mapResultToPropertyValue($this->parentObject, $this->propertyName, $objects);
         $this->parentObject->_setProperty($this->propertyName, $propertyValue);
         $this->parentObject->_memorizeCleanState($this->propertyName);
         return $propertyValue;
     } else {
         return $this->parentObject->_getProperty($this->propertyName);
     }
 }
コード例 #5
0
 /**
  * Counts the elements in the storage array
  *
  * @return int The number of elements in the ObjectStorage
  */
 public function count()
 {
     $columnMap = $this->dataMapper->getDataMap(get_class($this->parentObject))->getColumnMap($this->propertyName);
     $numberOfElements = NULL;
     if ($columnMap->getTypeOfRelation() === Tx_Extbase_Persistence_Mapper_ColumnMap::RELATION_HAS_MANY) {
         $numberOfElements = $this->dataMapper->countRelated($this->parentObject, $this->propertyName, $this->fieldValue);
     } else {
         $this->initialize();
         $numberOfElements = count($this->storage);
     }
     if (is_null($numberOfElements)) {
         throw new Tx_Extbase_Persistence_Exception('The number of elements could not be determined.', 1252514486);
     }
     return $numberOfElements;
 }
コード例 #6
0
ファイル: Backend.php プロジェクト: NaveedWebdeveloper/Test
 /**
  * Remove related objects
  *
  * @param Tx_Extbase_DomainObject_DomainObjectInterface $object The object to scanned for related objects
  * @return void
  */
 protected function removeRelatedObjects(Tx_Extbase_DomainObject_DomainObjectInterface $object)
 {
     $className = get_class($object);
     $dataMap = $this->dataMapper->getDataMap($className);
     $classSchema = $this->reflectionService->getClassSchema($className);
     $properties = $object->_getProperties();
     foreach ($properties as $propertyName => $propertyValue) {
         $columnMap = $dataMap->getColumnMap($propertyName);
         $propertyMetaData = $classSchema->getProperty($propertyName);
         if ($propertyMetaData['cascade'] === 'remove') {
             if ($columnMap->getTypeOfRelation() === Tx_Extbase_Persistence_Mapper_ColumnMap::RELATION_HAS_MANY) {
                 foreach ($propertyValue as $containedObject) {
                     $this->removeObject($containedObject);
                 }
             } elseif ($propertyValue instanceof Tx_Extbase_DomainObject_DomainObjectInterface) {
                 $this->removeObject($propertyValue);
             }
         }
     }
 }
コード例 #7
0
 /**
  * Transforms orderings into SQL.
  *
  * @param array $orderings An array of orderings (Tx_Extbase_Persistence_QOM_Ordering)
  * @param Tx_Extbase_Persistence_QOM_SourceInterface $source The source
  * @param array &$sql The query parts
  * @return void
  */
 protected function parseOrderings(array $orderings, Tx_Extbase_Persistence_QOM_SourceInterface $source, array &$sql)
 {
     foreach ($orderings as $propertyName => $order) {
         switch ($order) {
             case Tx_Extbase_Persistence_QOM_QueryObjectModelConstantsInterface::JCR_ORDER_ASCENDING:
                 // Deprecated since Extbase 1.1
             // Deprecated since Extbase 1.1
             case Tx_Extbase_Persistence_QueryInterface::ORDER_ASCENDING:
                 $order = 'ASC';
                 break;
             case Tx_Extbase_Persistence_QOM_QueryObjectModelConstantsInterface::JCR_ORDER_DESCENDING:
                 // Deprecated since Extbase 1.1
             // Deprecated since Extbase 1.1
             case Tx_Extbase_Persistence_QueryInterface::ORDER_DESCENDING:
                 $order = 'DESC';
                 break;
             default:
                 throw new Tx_Extbase_Persistence_Exception_UnsupportedOrder('Unsupported order encountered.', 1242816074);
         }
         if ($source instanceof Tx_Extbase_Persistence_QOM_SelectorInterface) {
             $className = $source->getNodeTypeName();
             $tableName = $this->dataMapper->convertClassNameToTableName($className);
             while (strpos($propertyName, '.') !== FALSE) {
                 $this->addUnionStatement($className, $tableName, $propertyName, $sql);
             }
         } elseif ($source instanceof Tx_Extbase_Persistence_QOM_JoinInterface) {
             $tableName = $source->getLeft()->getSelectorName();
         }
         $columnName = $this->dataMapper->convertPropertyNameToColumnName($propertyName, $className);
         if (strlen($tableName) > 0) {
             $sql['orderings'][] = $tableName . '.' . $columnName . ' ' . $order;
         } else {
             $sql['orderings'][] = $columnName . ' ' . $order;
         }
     }
 }