[FEATURE] HMENU - sectionIndex: where clause should be configurable
authorStefan Galinski <stefan.galinski@gmail.com>
Wed, 25 Jul 2012 11:27:29 +0000 (13:27 +0200)
committerStefan Galinski <stefan.galinski@gmail.com>
Wed, 15 Aug 2012 11:33:38 +0000 (13:33 +0200)
This changeset implements the sectionIndex setting
"useColPos" that can be used to change the colPos
query filter. A negative value drops the filter
completely. Only integers are allowed as values
and stdWrap is possible.

Example:
tt_content.menu.20.3.1.sectionIndex.useColPos = -1

Change-Id: Ic65cdee014aa7972e3d28504a678a001355ed312
Resolves: #21142
Releases: 6.0
Reviewed-on: http://review.typo3.org/11251
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
Reviewed-by: Stefan Neufeind
Reviewed-by: Georg Ringer
Tested-by: Georg Ringer
Reviewed-by: Stefan Galinski
Tested-by: Stefan Galinski
typo3/sysext/cms/tests/tslib/class.tslib_menuTest.php
typo3/sysext/cms/tslib/class.tslib_menu.php

index 0800a36..a43620a 100644 (file)
@@ -50,6 +50,7 @@ class tslib_menuTest extends Tx_Extbase_Tests_Unit_BaseTestCase {
 
                $backupGlobalVariables['TSFE'] = $GLOBALS['TSFE'];
                $GLOBALS['TSFE'] = $this->getMock('tslib_fe');
+               $GLOBALS['TSFE']->cObj = new tslib_cObj();
        }
 
        public function tearDown() {
@@ -207,5 +208,61 @@ class tslib_menuTest extends Tx_Extbase_Tests_Unit_BaseTestCase {
                $result = $this->fixture->_call('sectionIndex', 'field');
                $this->assertCount($expectedAmount, $result);
        }
+
+       /**
+        * @return array
+        */
+       public function sectionIndexQueriesWithDifferentColPosDataProvider() {
+               return array(
+                       'no configuration' => array(
+                               array(),
+                               'colPos=0'
+                       ),
+                       'with useColPos 2' => array(
+                               array('useColPos' => 2),
+                               'colPos=2'
+                       ),
+                       'with useColPos -1' => array(
+                               array('useColPos' => -1),
+                               ''
+                       ),
+                       'with stdWrap useColPos' => array(
+                               array(
+                                       'useColPos.' => array(
+                                               'wrap' => '2|',
+                                       ),
+                               ),
+                               'colPos=2'
+                       ),
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider sectionIndexQueriesWithDifferentColPosDataProvider
+        * @param array $configuration
+        * @param string $whereClausePrefix
+        */
+       public function sectionIndexQueriesWithDifferentColPos($configuration, $whereClausePrefix) {
+               $this->prepareSectionIndexTest();
+
+               $this->fixture->sys_page->expects($this->once())->method('getPage')
+                       ->will($this->returnValue(array()));
+
+               $this->fixture->mconf['sectionIndex.'] = $configuration;
+               $queryConfiguration = array(
+                       'pidInList' => 12,
+                       'orderBy' => 'field',
+                       'languageField' =>'sys_language_uid',
+                       'where' => $whereClausePrefix,
+               );
+
+               $this->fixture->parent_cObj->expects($this->once())->method('exec_getQuery')
+                       ->with('tt_content', $queryConfiguration)
+                       ->will($this->returnValue(1));
+
+               $this->fixture->_call('sectionIndex', 'field', 12);
+       }
 }
+
 ?>
\ No newline at end of file
index 3db75ef..66ea97b 100644 (file)
@@ -1773,11 +1773,18 @@ class tslib_menu {
                        return array();
                }
 
+               $configuration = $this->mconf['sectionIndex.'];
+               $useColPos = 0;
+               if (trim($configuration['useColPos']) !== '' || is_array($configuration['useColPos.'])) {
+                       $useColPos = $GLOBALS['TSFE']->cObj->stdWrap($configuration['useColPos'], $configuration['useColPos.']);
+                       $useColPos = intval($useColPos);
+               }
+
                $selectSetup = array(
                        'pidInList' => $pid,
                        'orderBy' => $altSortField,
                        'languageField' => 'sys_language_uid',
-                       'where' => 'colPos=0'
+                       'where' => ($useColPos >= 0 ? 'colPos=' . $useColPos : ''),
                );
 
                $resource = $this->parent_cObj->exec_getQuery('tt_content', $selectSetup);