/**
  * Translates a query an manipulates given query object
  *
  * @param Tx_PtExtlist_Domain_QueryObject_Criteria $criteria Criteria to be translated
  * @param \TYPO3\CMS\Extbase\Persistence\Generic\Query $extbaseQuery Query to add criteria to
  * @param \TYPO3\CMS\Extbase\Persistence\Repository $extbaseRepository Associated repository
  * @throws Exception
  * @return \TYPO3\CMS\Extbase\Persistence\Generic\Query
  */
 public static function translateCriteria(Tx_PtExtlist_Domain_QueryObject_Criteria $criteria, \TYPO3\CMS\Extbase\Persistence\Generic\Query $extbaseQuery, \TYPO3\CMS\Extbase\Persistence\Repository $extbaseRepository)
 {
     if (!is_a($criteria, 'Tx_PtExtlist_Domain_QueryObject_OrCriteria')) {
         throw new Exception('Given criteria is not of type Tx_PtExtlist_Domain_QueryObject_Criteria --> cannot be translated by or criteria translator! 1326466193');
     }
     /**
      * This is a little ugly here:
      *
      * As we do not create Extbase criterias from our generic pt_extlist criterias
      * but set the criterias directly on the created extbase query, we have to cheat
      * here and generate two helper queries, whenever a OR query has to be translated.
      *
      * After having translated the two criterias of the generic OR criteria, we
      * put them together again in a single extbase query.
      */
     $tmpQuery1 = $extbaseRepository->createQuery();
     $tmpQuery2 = $extbaseRepository->createQuery();
     // translate first OR criteria by creating a new extbase query
     $tmpQuery1 = Tx_PtExtlist_Domain_DataBackend_ExtBaseDataBackend_ExtBaseInterpreter_ExtBaseInterpreter::setCriteriaOnExtBaseQueryByCriteria($criteria->getFirstCriteria(), $tmpQuery1, $extbaseRepository);
     // translate second OR criteria by creating a new extbase query
     $tmpQuery2 = Tx_PtExtlist_Domain_DataBackend_ExtBaseDataBackend_ExtBaseInterpreter_ExtBaseInterpreter::setCriteriaOnExtBaseQueryByCriteria($criteria->getSecondCriteria(), $tmpQuery2, $extbaseRepository);
     // put both translated criterias together again in a single extbase query
     if ($extbaseQuery->getConstraint()) {
         $extbaseQuery->matching($extbaseQuery->logicalAnd($extbaseQuery->getConstraint(), $extbaseQuery->logicalOr($tmpQuery1->getConstraint(), $tmpQuery2->getConstraint())));
     } else {
         $extbaseQuery->matching($extbaseQuery->logicalOr($tmpQuery1->getConstraint(), $tmpQuery2->getConstraint()));
     }
     return $extbaseQuery;
 }
 /**
  * Sets up this test case
  *
  * @return void
  */
 protected function setUp()
 {
     $this->query = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Persistence\Generic\Query::class, array('dummy'), array('someType'));
     $this->querySettings = $this->getMock(\TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface::class);
     $this->query->_set('querySettings', $this->querySettings);
     $this->persistenceManager = $this->getMock(\TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface::class);
     $this->backend = $this->getMock(\TYPO3\CMS\Extbase\Persistence\Generic\BackendInterface::class);
     $this->query->_set('persistenceManager', $this->persistenceManager);
     $this->dataMapper = $this->getMock(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper::class);
     $this->query->_set('dataMapper', $this->dataMapper);
     $this->controller = $this->getAccessibleMock(\TYPO3\CMS\Fluid\ViewHelpers\Widget\Controller\PaginateController::class, array('dummy'), array(), '', false);
     $this->controller->_set('view', $this->getMock(\TYPO3\CMS\Extbase\Mvc\View\ViewInterface::class));
 }
 protected function createConstraint(Query $query, $queueName)
 {
     $constraints = array();
     $constraints[] = $query->equals('queueName', $queueName);
     $constraints[] = $query->equals('state', Message::STATE_PUBLISHED);
     $constraints[] = $query->logicalOr($query->equals('starttime', 0), $query->lessThanOrEqual('starttime', time()));
     $query->matching($query->logicalAnd($constraints));
 }
 /**
  * Sets up this test case
  *
  * @return void
  */
 protected function setUp()
 {
     $this->query = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Persistence\Generic\Query::class, array('dummy'), array('someType'));
     $this->querySettings = $this->getMock(\TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface::class);
     $this->query->_set('querySettings', $this->querySettings);
     $this->persistenceManager = $this->getMock(\TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface::class);
     $this->backend = $this->getMock(\TYPO3\CMS\Extbase\Persistence\Generic\BackendInterface::class);
     $this->backend->expects($this->any())->method('getQomFactory')->will($this->returnValue(NULL));
     $this->persistenceManager->expects($this->any())->method('getBackend')->will($this->returnValue($this->backend));
     $this->query->_set('persistenceManager', $this->persistenceManager);
     $this->dataMapper = $this->getMock(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper::class);
     $this->query->_set('dataMapper', $this->dataMapper);
     $this->controller = $this->getAccessibleMock(\TYPO3\CMS\Fluid\ViewHelpers\Widget\Controller\PaginateController::class, array('dummy'), array(), '', FALSE);
     $this->controller->_set('view', $this->getMock(\TYPO3\CMS\Extbase\Mvc\View\ViewInterface::class));
 }
 /**
  * Translates a query an manipulates given query object
  *
  * @param Tx_PtExtlist_Domain_QueryObject_Criteria $criteria Criteria to be translated
  * @param \TYPO3\CMS\Extbase\Persistence\Generic\Query $extbaseQuery Query to add criteria to
  * @param \TYPO3\CMS\Extbase\Persistence\Repository $extbaseRepository Associated repository
  * @return \TYPO3\CMS\Extbase\Persistence\Generic\Query
  */
 public static function translateCriteria(Tx_PtExtlist_Domain_QueryObject_Criteria $criteria, \TYPO3\CMS\Extbase\Persistence\Generic\Query $extbaseQuery, \TYPO3\CMS\Extbase\Persistence\Repository $extbaseRepository)
 {
     // translate NOT criteria by creating a new extbase query
     $tmpQuery = Tx_PtExtlist_Domain_DataBackend_ExtBaseDataBackend_ExtBaseInterpreter_ExtBaseInterpreter::setCriteriaOnExtBaseQueryByCriteria($criteria->getCriteria(), $extbaseRepository->createQuery(), $extbaseRepository);
     // put translated criteria together again in a single extbase query
     if ($extbaseQuery->getConstraint()) {
         $extbaseQuery->matching($extbaseQuery->logicalAnd($extbaseQuery->getConstraint(), $extbaseQuery->logicalNot($tmpQuery->getConstraint())));
     } else {
         $extbaseQuery->matching($extbaseQuery->logicalNot($tmpQuery->getConstraint()));
     }
     return $extbaseQuery;
 }
 /**
  * Executes the parent execute() method and returns an
  * OverlayQueryResult instead of a normal QueryResult
  *
  * @param $returnRawQueryResult boolean avoids the object mapping by the persistence
  * @return \Int\NewsSlideit\Persistence\OverlayQueryResult
  */
 public function execute($returnRawQueryResult = FALSE)
 {
     $result = parent::execute($returnRawQueryResult);
     if ($result instanceof QueryResultInterface) {
         $result = $this->objectManager->get('Int\\NewsSlideit\\Persistence\\OverlayQueryResult', $this);
     }
     return $result;
 }
Example #7
0
 /**
  * Checks if equals condition makes utf-8 argument lowercase correctly
  *
  * @test
  * @dataProvider equalsForCaseSensitiveFalseLowercasesOperandProvider
  * @param string $propertyName The name of the property to compare against
  * @param mixed $operand The value to compare with
  * @param string $expectedOperand
  */
 public function equalsForCaseSensitiveFalseLowercasesOperand($propertyName, $operand, $expectedOperand)
 {
     /** @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject $objectManager */
     $objectManager = $this->getMock(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
     /** @var \TYPO3\CMS\Extbase\Persistence\Generic\Qom\DynamicOperandInterface $dynamicOperand */
     $dynamicOperand = $this->getMock(\TYPO3\CMS\Extbase\Persistence\Generic\Qom\PropertyValueInterface::class);
     $objectManager->expects($this->any())->method('get')->will($this->returnValue($dynamicOperand));
     /** @var $qomFactory \TYPO3\CMS\Extbase\Persistence\Generic\Qom\QueryObjectModelFactory */
     $qomFactory = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Persistence\Generic\Qom\QueryObjectModelFactory::class, array('comparison'));
     $qomFactory->_set('objectManager', $objectManager);
     $qomFactory->expects($this->once())->method('comparison')->with($this->anything(), $this->anything(), $expectedOperand);
     $this->query->_set('qomFactory', $qomFactory);
     $this->query->equals($propertyName, $operand, false);
 }
 /**
  * Adds default constraints to the query - in this case it
  * enables us to always just search for the latest version of an extension
  *
  * @param \TYPO3\CMS\Extbase\Persistence\Generic\Query $query the query to adjust
  * @return \TYPO3\CMS\Extbase\Persistence\Generic\Query
  */
 protected function addDefaultConstraints(\TYPO3\CMS\Extbase\Persistence\Generic\Query $query)
 {
     if ($query->getConstraint()) {
         $query->matching($query->logicalAnd($query->getConstraint(), $query->equals('current_version', TRUE)));
     } else {
         $query->matching($query->equals('current_version', TRUE));
     }
     return $query;
 }
 /**
  * Sets sortings on an extbase query by given query object. Returns manipulated extbase query.
  *
  * @param Tx_PtExtlist_Domain_QueryObject_Query $query Query object to get sortings from
  * @param \TYPO3\CMS\Extbase\Persistence\Generic\Query $extbaseQuery Query object to set sortings on
  * @return \TYPO3\CMS\Extbase\Persistence\Generic\Query Manipulated ExtBase query object
  */
 public static function setSortingOnExtBaseQueryByQueryObject(Tx_PtExtlist_Domain_QueryObject_Query $query, \TYPO3\CMS\Extbase\Persistence\Generic\Query $extbaseQuery)
 {
     $sortings = $query->getSortings();
     $extBaseSortings = array();
     foreach ($sortings as $field => $direction) {
         /* sorting is array('field' => 'Direction: 1 | -1') */
         $extBaseDirection = $direction == Tx_PtExtlist_Domain_QueryObject_Query::SORTINGSTATE_ASC ? \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING : \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING;
         $extBaseSortings[$field] = $extBaseDirection;
     }
     $extbaseQuery->setOrderings($extBaseSortings);
     return $extbaseQuery;
 }
 /**
  * Adds default constraints to the query - in this case it
  * enables us to always just search for the latest version of an extension
  *
  * @param \TYPO3\CMS\Extbase\Persistence\Generic\Query $query the query to adjust
  * @return \TYPO3\CMS\Extbase\Persistence\Generic\Query
  */
 protected function addDefaultConstraints(\TYPO3\CMS\Extbase\Persistence\Generic\Query $query)
 {
     if ($query->getConstraint()) {
         $query->matching($query->logicalAnd($query->getConstraint(), $query->equals('current_version', true), $query->greaterThanOrEqual('reviewState', 0)));
     } else {
         $query->matching($query->logicalAnd($query->equals('current_version', true), $query->greaterThanOrEqual('reviewState', 0)));
     }
     return $query;
 }
 /**
  * @return void
  */
 public function testGetCurrentFrontendUserFetchesFromFrontendUserRepository()
 {
     $GLOBALS['TSFE'] = (object) array('loginUser' => 1, 'fe_user' => (object) array('user' => array('uid' => 1)));
     $instance = $this->getMock($this->getViewHelperClassName(), array('dummy'));
     $query = new Query('TYPO3\\CMS\\Extbase\\Domain\\Model\\FrontendUser');
     $querySettings = new Typo3QuerySettings();
     $query->setQuerySettings($querySettings);
     $repository = $this->getMock('TYPO3\\CMS\\Extbase\\Domain\\Repository\\FrontendUserRepository', array('findByUid', 'createQuery', 'setDefaultQuerySettings'), array(), '', FALSE);
     $repository->expects($this->once())->method('setDefaultQuerySettings')->with($querySettings);
     $repository->expects($this->once())->method('createQuery')->willReturn($query);
     $repository->expects($this->once())->method('findByUid')->with(1)->willReturn('test');
     $instance->injectFrontendUserRepository($repository);
     $result = $instance->getCurrentFrontendUser();
     $this->assertEquals('test', $result);
 }
 /**
  * Adds given constraint to given query. Uses logical AND if there is already a constraint registered in query
  *
  * @param \TYPO3\CMS\Extbase\Persistence\Generic\Query $extbaseQuery
  * @param \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ConstraintInterface $constraint
  * @return \TYPO3\CMS\Extbase\Persistence\Generic\Query
  */
 protected static function addConstraint(\TYPO3\CMS\Extbase\Persistence\Generic\Query $extbaseQuery, \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ConstraintInterface $constraint)
 {
     if ($extbaseQuery->getConstraint() != null) {
         $extbaseQuery->matching($extbaseQuery->logicalAnd($extbaseQuery->getConstraint(), $constraint));
     } else {
         $extbaseQuery->matching($constraint);
     }
     return $extbaseQuery;
 }
Example #13
0
 /**
  * Sets the start offset of the result set to offset. Returns $this to
  * allow for chaining (fluid interface)
  *
  * @param integer $offset
  * @return \TYPO3\CMS\Extbase\Persistence\QueryInterface
  */
 public function setOffset($offset)
 {
     parent::setOffset($offset);
     if ($this->statement) {
         $this->sqlParser->setLimitStatement($this->getLimitStatement());
         $statement = $this->sqlParser->toString();
         $this->statement = $this->qomFactory->statement($statement, $this->parameters);
     }
     return $this;
 }