ExtBase
authorJochen Rau <j.rau@web.de>
Thu, 26 Mar 2009 11:49:05 +0000 (11:49 +0000)
committerJochen Rau <j.rau@web.de>
Thu, 26 Mar 2009 11:49:05 +0000 (11:49 +0000)
* Removed namespace for $_GET Var. action=setup
* Fixed issue with fetchWithRelationTable()
* Fixed issue with fullQuote() while converting properties to fields

typo3/sysext/extbase/Classes/Persistence/Mapper/DataMap.php
typo3/sysext/extbase/Classes/Persistence/Mapper/ObjectRelationalMapper.php
typo3/sysext/extbase/Classes/Persistence/Repository.php
typo3/sysext/extbase/Classes/Utility/Strings.php
typo3/sysext/extbase/Classes/View/Helper/ConvertHelper.php
typo3/sysext/extbase/Classes/View/Helper/ForHelper.php
typo3/sysext/extbase/Classes/View/Helper/LinkHelper.php
typo3/sysext/extbase/Classes/View/Helper/TranslateHelper.php
typo3/sysext/extbase/Classes/View/TemplateView.php
typo3/sysext/extbase/class.tx_extbase_dispatcher.php

index 2ce32e1..83d05ec 100644 (file)
@@ -249,19 +249,20 @@ class Tx_ExtBase_Persistence_Mapper_DataMap {
         * Converts a value from a property type to a database field type
         *
         * @param mixed $propertyValue The property value
+        * @param boolean $fullQuoteString TRUE if a field value of type string should be full quoted via $GLOBALS['TYPO3_DB']->fullQuoteStr()
         * @return mixed The converted value
         */
-       public function convertPropertyValueToFieldValue($propertyValue) {
-               if (is_bool($propertyValue)) {
+       public function convertPropertyValueToFieldValue($propertyValue, $fullQuoteString = TRUE) {
+               if (is_bool($value)) {
                        $convertedValue = $propertyValue ? 1 : 0;
-               } elseif ($propertyValue instanceof Tx_ExtBase_DomainObject_AbstractDomainObject) {
+               } elseif ($value instanceof Tx_ExtBase_DomainObject_AbstractDomainObject) {
                        $convertedValue = $propertyValue->getUid();
                } elseif ($propertyValue instanceof DateTime) {
                        $convertedValue = $propertyValue->format('U');
                } elseif (is_int($propertyValue)) {
                        $convertedValue = $propertyValue;
                } else {
-                       $convertedValue = $GLOBALS['TYPO3_DB']->fullQuoteStr((string)$propertyValue, '');
+                       $convertedValue = $fullQuoteString === TRUE ? $GLOBALS['TYPO3_DB']->fullQuoteStr((string)$propertyValue, '') : $propertyValue;
                }
                return $convertedValue;
        }
index 610e129..07c1be4 100644 (file)
@@ -193,7 +193,7 @@ class Tx_ExtBase_Persistence_Mapper_ObjectRelationalMapper implements t3lib_Sing
                
                $joinTables = $this->getJoinClause($className);         
                $res = $this->db->exec_SELECTquery(
-                       '*', // TODO limit fetched fields (CH: should we do that?)
+                       '*', // TODO limit fetched fields (CH: should we do that? JR: Not needed; only existing properties will be mapped)
                        $dataMap->getTableName() . ' ' . $joinTables,
                        $where . $enableFields,
                        $groupBy,
@@ -204,14 +204,16 @@ class Tx_ExtBase_Persistence_Mapper_ObjectRelationalMapper implements t3lib_Sing
                $fieldMap = array();
                $i = 0;
                // FIXME mysql_fetch_field should be available in t3lib_db (patch core)
-               while ($field = mysql_fetch_field($res)) {
-                       $fieldMap[$field->table][$field->name] = $i;
-                       $i++;
+               $rows = array();
+               if ($res !== FALSE) {
+                       while ($field = mysql_fetch_field($res)) {
+                               $fieldMap[$field->table][$field->name] = $i;
+                               $i++;
+                       }
+                       while($rows[] = $this->db->sql_fetch_row($res));
+                       array_pop($rows);
                }
 
-               $rows = array();
-               while($rows[] = $this->db->sql_fetch_row($res));
-               array_pop($rows);
                
                // SK: Do we want to make it possible to ignore "enableFields"?
                // TODO language overlay; workspace overlay
@@ -251,8 +253,8 @@ class Tx_ExtBase_Persistence_Mapper_ObjectRelationalMapper implements t3lib_Sing
         * @param string Optional ORDER BY field(s), defaults to blank string.
         * @param string Optional LIMIT value ([begin,]max), defaults to blank string.
         */
-       // SK: Are SQL injections possible here? Can we somehow prevent them? I did not check it thoroughly yet, but I think they are possible
        public function fetchWithRelationTable($parentObject, $columnMap, $where = '1=1', $groupBy = '', $orderBy = '', $limit = '', $useEnableFields = TRUE) {
+               $dataMap = $this->getDataMap(get_class($parentObject));
                if ($useEnableFields === TRUE) {
                        $enableFields = $GLOBALS['TSFE']->sys_page->enableFields($columnMap->getChildTableName());
                } else {
@@ -267,7 +269,13 @@ class Tx_ExtBase_Persistence_Mapper_ObjectRelationalMapper implements t3lib_Sing
                        $limit
                        );
                // TODO language overlay; workspace overlay; sorting
-               return $rows ? $rows : array();
+               $objects = array();
+               if (is_array($rows)) {
+                       if (count($rows) > 0) {
+                               $objects = $this->reconstituteObjects($dataMap, $fieldMap, $rows);
+                       }
+               }
+               return $objects;
        }
 
        /**
@@ -281,7 +289,7 @@ class Tx_ExtBase_Persistence_Mapper_ObjectRelationalMapper implements t3lib_Sing
        // SK: I Need to check this method more thoroughly.
        // SK: Are loops detected during reconstitution?
        protected function reconstituteObjects($dataMap, &$fieldMap, array $rows) {
-               $objects = array();             
+               $objects = array();
                foreach ($rows as $row) {
                        $properties = array();
                        foreach ($dataMap->getColumnMaps() as $columnMap) {
@@ -493,7 +501,7 @@ class Tx_ExtBase_Persistence_Mapper_ObjectRelationalMapper implements t3lib_Sing
                                $row[$columnName] = count($properties[$propertyName]);
                        } else {
                                if ($properties[$propertyName] !== NULL) {
-                                       $row[$columnName] = $dataMap->convertPropertyValueToFieldValue($properties[$propertyName]);
+                                       $row[$columnName] = $dataMap->convertPropertyValueToFieldValue($properties[$propertyName], FALSE);
                                }
                        }
                }
index 81daf98..bafb34b 100644 (file)
@@ -152,7 +152,7 @@ abstract class Tx_ExtBase_Persistence_Repository implements Tx_ExtBase_Persisten
         * @param bool $useEnableFields Wether to automatically restrict the query by enable fields
         * @return array An array of objects, an empty array if no objects found
         */
-       public function find($conditions = '', $groupBy = '', $orderBy = '', $limit = '', $useEnableFields = TRUE) {            
+       public function find($conditions = '', $groupBy = '', $orderBy = '', $limit = '', $useEnableFields = TRUE) {
                return $this->dataMapper->find($this->aggregateRootClassName, $conditions, $groupBy, $orderBy, $limit, $useEnableFields);
        }
 
index c7d143e..c18bd3b 100644 (file)
@@ -38,7 +38,7 @@ abstract class Tx_ExtBase_Utility_Strings {
         * @return string UpperCamelCasedWord
         */
        public static function underscoredToUpperCamelCase($string) {
-               $upperCamelCase = (str_replace(' ', '', ucwords(preg_replace('![^A-Z^a-z^0-9]+!', ' ', strtolower($string)))));
+               $upperCamelCase = str_replace(' ', '', ucwords(preg_replace('![^A-Z^a-z^0-9]+!', ' ', strtolower($string))));
                return $upperCamelCase;
        }
        
@@ -49,7 +49,7 @@ abstract class Tx_ExtBase_Utility_Strings {
         * @return string lowerCamelCasedWord
         */
        public static function underscoredToLowerCamelCase($string) {
-               $upperCamelCase = (str_replace(' ', '', ucwords(preg_replace('![^A-Z^a-z^0-9]+!', ' ', strtolower($string)))));
+               $upperCamelCase = str_replace(' ', '', ucwords(preg_replace('![^A-Z^a-z^0-9]+!', ' ', strtolower($string))));
                $lowerCamelCase = strtolower(substr($upperCamelCase,0,1) ) . substr($upperCamelCase,1);
                return $lowerCamelCase;
        }
index a3bae72..5e39b5f 100644 (file)
@@ -31,7 +31,7 @@
  */
 class Tx_ExtBase_View_Helper_ConvertHelper extends Tx_ExtBase_View_Helper_AbstractHelper {
 
-       public function render($view, $arguments, $templateSource, $variables) {
+       public function render($view, $arguments, $content, $templateSource, $variables) {
                $value = $content;
                $format = $arguments['format'];
                if ($value instanceof DateTime) {
index c37983f..726198a 100644 (file)
@@ -31,7 +31,7 @@
  */
 class Tx_ExtBase_View_Helper_ForHelper extends Tx_ExtBase_View_Helper_AbstractHelper {
 
-       public function render($view, $arguments, $templateSource, $variables) {
+       public function render($view, $arguments, $content, $templateSource, $variables) {
                if (is_array($arguments['each'])) {
                        foreach ($arguments['each'] as $singleElement) {
                                $variables[Tx_ExtBase_Utility_Strings::underscoredToUpperCamelCase($arguments['as'])] = $singleElement;
index 30acf64..c1d844b 100644 (file)
@@ -59,7 +59,7 @@ class Tx_ExtBase_View_Helper_LinkHelper extends Tx_ExtBase_View_Helper_AbstractH
         * @param string $variables 
         * @return string A content wrapped in a link
         */
-       public function render($view, $arguments, $templateSource, $variables) {
+       public function render($view, $arguments, $content, $templateSource, $variables) {
                $parameters = t3lib_div::_GET();
                $prefixedExtensionKey = 'tx_' . strtolower($this->request->getExtensionName()) . '_' . strtolower($this->request->getControllerName());
                if (!empty($arguments['to'])) {
index 9f02826..5a8aa59 100644 (file)
@@ -67,7 +67,7 @@ class Tx_ExtBase_View_Helper_TranslateHelper extends Tx_ExtBase_View_Helper_Abst
        // var $LLtestPrefixAlt='';             // Save as LLtestPrefix, but additional prefix for the alternative value in getLL() function calls
        
 
-       public function render($view, $arguments, $templateSource, $variables) {
+       public function render($view, $arguments, $content, $templateSource, $variables) {
                $this->initializeLocalization($view);
                $translation = $this->translate($arguments['key']);
                return (is_string($translation) && !empty($translation)) ? $translation : '';
index 2a39fa2..feea417 100644 (file)
@@ -259,7 +259,7 @@ class Tx_ExtBase_View_TemplateView extends Tx_ExtBase_View_AbstractView {
                        if (!empty($viewHelperName)) {
                                $viewHelperClassName = 'Tx_ExtBase_View_Helper_' . $viewHelperName . 'Helper';
                                $viewHelper = $this->getViewHelper($viewHelperClassName);
-                               $content = $viewHelper->render($this, $arguments, $templateSource, $variables);
+                               $content = $viewHelper->render($this, $arguments, $content, $templateSource, $variables);
                        }
                }
                return $content;
index d7bd3b4..5ff71e2 100644 (file)
@@ -77,7 +77,7 @@ class Tx_ExtBase_Dispatcher {
         * @return String $content The processed content
         */
        public function dispatch($content, $configuration) {
-               $parameters = t3lib_div::_GET('tx_' . strtolower($extensionName) . '_' . strtolower($controllerName));
+               $parameters = t3lib_div::_GET();
                $extensionName = $configuration['extension'];
                $controllerName = $configuration['controller'];
                // TODO Should we implement switched controllers?