Пример #1
0
 /**
  * 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;
 }
 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));
 }