Ejemplo n.º 1
0
 /**
  * Returns an array of orderings created from a given demand object.
  *
  * @param Tx_News_Domain_Model_DemandInterface $demand
  * @return array<\TYPO3\CMS\Extbase\Persistence\Generic\Qom\ConstraintInterface>
  */
 protected function createOrderingsFromDemand(Tx_News_Domain_Model_DemandInterface $demand)
 {
     $orderings = array();
     if ($demand->getTopNewsFirst()) {
         $orderings['istopnews'] = \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING;
     }
     if (Tx_News_Utility_Validation::isValidOrdering($demand->getOrder(), $demand->getOrderByAllowed())) {
         $orderList = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $demand->getOrder(), TRUE);
         if (!empty($orderList)) {
             // go through every order statement
             foreach ($orderList as $orderItem) {
                 list($orderField, $ascDesc) = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(' ', $orderItem, TRUE);
                 // count == 1 means that no direction is given
                 if ($ascDesc) {
                     $orderings[$orderField] = strtolower($ascDesc) == 'desc' ? \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING : \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING;
                 } else {
                     $orderings[$orderField] = \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING;
                 }
             }
         }
     }
     return $orderings;
 }