ExtBase:
authorJochen Rau <j.rau@web.de>
Fri, 27 Mar 2009 14:49:03 +0000 (14:49 +0000)
committerJochen Rau <j.rau@web.de>
Fri, 27 Mar 2009 14:49:03 +0000 (14:49 +0000)
* Fixed reconstitution of objects

typo3/sysext/extbase/Classes/Persistence/Mapper/ObjectRelationalMapper.php
typo3/sysext/extbase/class.tx_extbase_dispatcher.php

index 185f562..25edd34 100644 (file)
@@ -198,19 +198,18 @@ class Tx_ExtBase_Persistence_Mapper_ObjectRelationalMapper implements t3lib_Sing
                }
                
                $res = $this->database->exec_SELECTquery(
                }
                
                $res = $this->database->exec_SELECTquery(
-                       '*', // TODO limit fetched fields (CH: should we do that? JR: Not needed; only existing properties will be mapped)
+                       '*',
                        $from,
                        $where . $enableFields,
                        $groupBy,
                        $orderBy,
                        $limit
                        );
                        $from,
                        $where . $enableFields,
                        $groupBy,
                        $orderBy,
                        $limit
                        );
-                       
+
                $fieldMap = $this->getFieldMapFromResult($res);
                $rows = $this->getRowsFromResult($res);
                $fieldMap = $this->getFieldMapFromResult($res);
                $rows = $this->getRowsFromResult($res);
-               
                $this->database->sql_free_result($res);
                $this->database->sql_free_result($res);
-               
+                               
                // SK: Do we want to make it possible to ignore "enableFields"?
                // TODO language overlay; workspace overlay
                $objects = array();
                // SK: Do we want to make it possible to ignore "enableFields"?
                // TODO language overlay; workspace overlay
                $objects = array();
@@ -238,7 +237,7 @@ class Tx_ExtBase_Persistence_Mapper_ObjectRelationalMapper implements t3lib_Sing
        protected function getRowsFromResult($res) {
                $rows = array();
                if ($res !== FALSE) {
        protected function getRowsFromResult($res) {
                $rows = array();
                if ($res !== FALSE) {
-                       while($rows[] = $this->database->sql_fetch_row($res));
+                       while($rows[] = $this->database->sql_fetch_assoc($res));
                        array_pop($rows);
                }
                return $rows;
                        array_pop($rows);
                }
                return $rows;
@@ -291,14 +290,10 @@ class Tx_ExtBase_Persistence_Mapper_ObjectRelationalMapper implements t3lib_Sing
         */
        // SK: I Need to check this method more thoroughly.
        // SK: Are loops detected during reconstitution?
         */
        // SK: I Need to check this method more thoroughly.
        // SK: Are loops detected during reconstitution?
-       protected function reconstituteObjects($dataMap, &$fieldMap, array $rows) {
+       protected function reconstituteObjects(Tx_ExtBase_Persistence_Mapper_DataMap $dataMap, &$fieldMap, array $rows) {
                $objects = array();
                foreach ($rows as $row) {
                $objects = array();
                foreach ($rows as $row) {
-                       $properties = array();
-                       foreach ($dataMap->getColumnMaps() as $columnMap) {
-                               $fieldValue = $row[$fieldMap[$dataMap->getTableName()][$columnMap->getColumnName()]];
-                               $properties[$columnMap->getPropertyName()] = $dataMap->convertFieldValueToPropertyValue($columnMap->getPropertyName(), $fieldValue);
-                       }
+                       $properties = $this->getProperties($dataMap, $row);
                        $object = $this->reconstituteObject($dataMap->getClassName(), $properties);
                        foreach ($dataMap->getColumnMaps() as $columnMap) {
                                if ($columnMap->getTypeOfRelation() === Tx_ExtBase_Persistence_Mapper_ColumnMap::RELATION_HAS_ONE) {
                        $object = $this->reconstituteObject($dataMap->getClassName(), $properties);
                        foreach ($dataMap->getColumnMaps() as $columnMap) {
                                if ($columnMap->getTypeOfRelation() === Tx_ExtBase_Persistence_Mapper_ColumnMap::RELATION_HAS_ONE) {
@@ -320,6 +315,15 @@ class Tx_ExtBase_Persistence_Mapper_ObjectRelationalMapper implements t3lib_Sing
                }
                return $objects;
        }
                }
                return $objects;
        }
+       
+       protected function getProperties(Tx_ExtBase_Persistence_Mapper_DataMap $dataMap, array $row) {
+               $properties = array();
+               foreach ($dataMap->getColumnMaps() as $columnMap) {
+                       $fieldValue = $row[$columnMap->getColumnName()];
+                       $properties[$columnMap->getPropertyName()] = $dataMap->convertFieldValueToPropertyValue($columnMap->getPropertyName(), $fieldValue);
+               }
+               return $properties;
+       }
 
        /**
         * Reconstitutes the specified object and fills it with the given properties.
 
        /**
         * Reconstitutes the specified object and fills it with the given properties.
index bb75b6e..03b04ad 100644 (file)
@@ -77,6 +77,9 @@ class Tx_ExtBase_Dispatcher {
         * @return String $content The processed content
         */
        public function dispatch($content, $configuration) {
         * @return String $content The processed content
         */
        public function dispatch($content, $configuration) {
+               // TODO Remove debug statement
+               // $start_time = microtime(TRUE);
+
                $parameters = t3lib_div::_GET();
                $extensionName = $configuration['extension'];
                $controllerName = $configuration['controller'];
                $parameters = t3lib_div::_GET();
                $extensionName = $configuration['extension'];
                $controllerName = $configuration['controller'];
@@ -118,6 +121,11 @@ class Tx_ExtBase_Dispatcher {
                }
                // TODO Handle $response->getStatus()
                // SK: Call sendHeaders() on the response
                }
                // TODO Handle $response->getStatus()
                // SK: Call sendHeaders() on the response
+               
+               // TODO Remove debug statements
+               // $end_time = microtime(TRUE);
+               // debug($end_time - $start_time, -1);
+               
                return $response->getContent();
        }
        
                return $response->getContent();
        }