[+FEATURE] Extbase (Persistence): Implemented ordering (eg. $query->setOrderings...
authorJochen Rau <j.rau@web.de>
Wed, 15 Jul 2009 09:31:24 +0000 (09:31 +0000)
committerJochen Rau <j.rau@web.de>
Wed, 15 Jul 2009 09:31:24 +0000 (09:31 +0000)
typo3/sysext/extbase/Classes/Persistence/QOM/QueryObjectModelFactory.php
typo3/sysext/extbase/Classes/Persistence/Query.php
typo3/sysext/extbase/Classes/Persistence/Storage/Typo3DbBackend.php

index 8d33b27..e62685e 100644 (file)
@@ -412,7 +412,7 @@ class Tx_Extbase_Persistence_QOM_QueryObjectModelFactory implements Tx_Extbase_P
         * @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
         */
        public function ascending(Tx_Extbase_Persistence_QOM_DynamicOperandInterface $operand) {
-               throw new Tx_Extbase_Persistence_Exception('Method not yet implemented, sorry!', 1217058209);
+               return t3lib_div::makeInstance('Tx_Extbase_Persistence_QOM_Ordering', $operand, Tx_Extbase_Persistence_QOM_QueryObjectModelConstantsInterface::JCR_ORDER_ASCENDING);
        }
 
        /**
@@ -426,7 +426,7 @@ class Tx_Extbase_Persistence_QOM_QueryObjectModelFactory implements Tx_Extbase_P
         * @throws Tx_Extbase_Persistence_Exception_RepositoryException if the operation otherwise fails
         */
        public function descending(Tx_Extbase_Persistence_QOM_DynamicOperandInterface $operand) {
-               throw new Tx_Extbase_Persistence_Exception('Method not yet implemented, sorry!', 1217058210);
+               return t3lib_div::makeInstance('Tx_Extbase_Persistence_QOM_Ordering', $operand, Tx_Extbase_Persistence_QOM_QueryObjectModelConstantsInterface::JCR_ORDER_DESCENDING);
        }
 
        /**
index 1d292d7..8c5eea3 100644 (file)
@@ -34,7 +34,7 @@
  * @scope prototype
  */
 class Tx_Extbase_Persistence_Query implements Tx_Extbase_Persistence_QueryInterface {
-// SK: Is "limit" and "order" and "offset" evaluated?
+
        /**
         * @var string
         */
@@ -223,7 +223,15 @@ class Tx_Extbase_Persistence_Query implements Tx_Extbase_Persistence_QueryInterf
         * @return Tx_Extbase_Persistence_QueryInterface
         */
        public function setOrderings(array $orderings) {
-               $this->orderings = $orderings;
+               $parsedOrderings = array();
+               foreach ($orderings as $propertyName => $order) {
+                       if ($order === Tx_Extbase_Persistence_QueryInterface::ORDER_DESCENDING) {
+                               $parsedOrderings[] = $this->QOMFactory->descending($this->QOMFactory->propertyValue($propertyName));
+                       } else {
+                               $parsedOrderings[] = $this->QOMFactory->ascending($this->QOMFactory->propertyValue($propertyName));
+                       }
+               }
+               $this->orderings = $parsedOrderings;
                return $this;
        }
 
index 33c7e0e..805518a 100644 (file)
@@ -475,10 +475,23 @@ class Tx_Extbase_Persistence_Storage_Typo3DbBackend implements Tx_Extbase_Persis
         * @param array $boundVariableValues
         * @return void
         */
-       protected function parseOrderings(array $orderings = NULL, array &$sql, array &$parameters, array $boundVariableValues) {
-               if (is_array($orderings)) {
-                       foreach ($orderings as $propertyName => $ordering) {
-                               // TODO Implement
+       protected function parseOrderings(array $orderings, array &$sql, array &$parameters, array $boundVariableValues) {
+               foreach ($orderings as $ordering) {
+                       $operand = $ordering->getOperand();
+                       $order = $ordering->getOrder();
+                       if ($operand instanceof Tx_Extbase_Persistence_QOM_PropertyValue) {
+                               switch ($order) {
+                                       case Tx_Extbase_Persistence_QOM_QueryObjectModelConstantsInterface::JCR_ORDER_ASCENDING:
+                                               $order = 'ASC';
+                                               break;
+                                       case Tx_Extbase_Persistence_QOM_QueryObjectModelConstantsInterface::JCR_ORDER_DESCENDING:
+                                               $order = 'DESC';
+                                               break;
+                                       default:
+                                               throw new Tx_Extbase_Persistence_Exception('Unsupported order encountered.', 1242816074);
+                               }
+
+                               $sql['orderings'][] = $ordering->getOperand()->getPropertyName() . ' ' . $order;
                        }
                }
        }