Ejemplo n.º 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;
 }
Ejemplo n.º 2
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
  * @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;
 }
Ejemplo n.º 3
0
 /**
  * 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;
 }
Ejemplo n.º 4
0
 /**
  * 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;
 }
 /**
  * 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;
 }