[TASK] Move t3lib_tcemain::getUniqueFields to EXT:version
authorTolleiv Nietsch <info@tolleiv.de>
Fri, 25 May 2012 20:18:17 +0000 (22:18 +0200)
committerStefan Neufeind <typo3.neufeind@speedpartner.de>
Sun, 12 Aug 2012 10:02:28 +0000 (12:02 +0200)
The method is only used within EXT:version, therefore
it should be moved.

Change-Id: Ibe78e8490a726a144d50ee71bd23e09633a1ba6c
Resolves: #37494
Releases: 6.0
Reviewed-on: http://review.typo3.org/11632
Reviewed-by: Stefan Neufeind
Tested-by: Stefan Neufeind
typo3/sysext/version/class.tx_version_tcemain.php

index 7dc258d..24ad497 100644 (file)
@@ -801,7 +801,7 @@ class tx_version_tcemain {
                                                                                )));
 
                                                                                        // Find fields to keep
-                                                                               $keepFields = $tcemainObj->getUniqueFields($table);
+                                                                               $keepFields = $this->getUniqueFields($table);
                                                                                if ($GLOBALS['TCA'][$table]['ctrl']['sortby']) {
                                                                                        $keepFields[] = $GLOBALS['TCA'][$table]['ctrl']['sortby'];
                                                                                }
@@ -1438,5 +1438,27 @@ class tx_version_tcemain {
        public function getCommandMap(t3lib_TCEmain $tceMain, array $commandMap) {
                return t3lib_div::makeInstance('tx_version_tcemain_CommandMap', $this, $tceMain, $commandMap);
        }
+
+       /**
+        * Returns all fieldnames from a table which have the unique evaluation type set.
+        *
+        * @param string $table Table name
+        * @return array Array of fieldnames
+        */
+       protected function getUniqueFields($table) {
+               $listArr = array();
+               t3lib_div::loadTCA($table);
+               if ($GLOBALS['TCA'][$table]['columns']) {
+                       foreach ($GLOBALS['TCA'][$table]['columns'] as $field => $configArr) {
+                               if ($configArr['config']['type'] === 'input') {
+                                       $evalCodesArray = t3lib_div::trimExplode(',', $configArr['config']['eval'], 1);
+                                       if (in_array('uniqueInPid', $evalCodesArray) || in_array('unique', $evalCodesArray)) {
+                                               $listArr[] = $field;
+                                       }
+                               }
+                       }
+               }
+               return $listArr;
+       }
 }
-?>
\ No newline at end of file
+?>