[TASK] Integrate signal-slot-handling in Grid Data Service
authorOliver Hader <oliver@typo3.org>
Thu, 22 Mar 2012 21:29:56 +0000 (22:29 +0100)
committerSteffen Ritter <info@rs-websystems.de>
Tue, 27 Mar 2012 14:46:07 +0000 (16:46 +0200)
* SIGNAL_GenerateDataArray_BeforeCaching
* SIGNAL_GenerateDataArray_PostProcesss
* SIGNAL_GetDataArray_PostProcesss
* SIGNAL_SortDataArray_PostProcesss
* SIGNAL_CalcChangePercentage_PreProcess
* SIGNAL_CalcChangePercentage_PostProcess

Change-Id: I577a14bd4f4ae8e0eedd804929b7175beb22647e
Resolves: #35166
Releases: 4.7, 6.0
Reviewed-on: http://review.typo3.org/9825
Reviewed-by: Steffen Ritter
Tested-by: Steffen Ritter
typo3/sysext/workspaces/Classes/Service/GridData.php

index d68a59d..0dfb3c7 100644 (file)
  * @subpackage Service
  */
 class Tx_Workspaces_Service_GridData {
+       const SIGNAL_GenerateDataArray_BeforeCaching = 'generateDataArray.beforeCaching';
+       const SIGNAL_GenerateDataArray_PostProcesss = 'generateDataArray.postProcess';
+       const SIGNAL_GetDataArray_PostProcesss = 'getDataArray.postProcess';
+       const SIGNAL_SortDataArray_PostProcesss = 'sortDataArray.postProcess';
+       const SIGNAL_CalcChangePercentage_PreProcess = 'calcChangePercentage.preProcess';
+       const SIGNAL_CalcChangePercentage_PostProcess = 'calcChangePercentage.postProcess';
+
        /**
         * Id of the current active workspace.
         *
@@ -185,10 +192,24 @@ class Tx_Workspaces_Service_GridData {
                                }
                        }
 
+                               // Suggested slot method:
+                               // methodName(Tx_Workspaces_Service_GridData $gridData, array &$dataArray, array $versions)
+                       $this->emitSignal(
+                               self::SIGNAL_GenerateDataArray_BeforeCaching,
+                               &$this->dataArray, $versions
+                       );
+
                        $this->sortDataArray();
                        $this->setDataArrayIntoCache($versions, $filterTxt);
                }
 
+                       // Suggested slot method:
+                       // methodName(Tx_Workspaces_Service_GridData $gridData, array &$dataArray, array $versions)
+               $this->emitSignal(
+                       self::SIGNAL_GenerateDataArray_PostProcesss,
+                       &$this->dataArray, $versions
+               );
+
                $this->sortDataArray();
        }
 
@@ -207,6 +228,13 @@ class Tx_Workspaces_Service_GridData {
                        $dataArrayPart[] = $this->dataArray[$i];
                }
 
+                       // Suggested slot method:
+                       // methodName(Tx_Workspaces_Service_GridData $gridData, array &$dataArray, $start, $limit)
+               $this->emitSignal(
+                       self::SIGNAL_GetDataArray_PostProcesss,
+                       &$this->dataArray, $start, $limit
+               );
+
                return $dataArrayPart;
        }
 
@@ -306,6 +334,13 @@ class Tx_Workspaces_Service_GridData {
                } else {
                        t3lib_div::sysLog('Try to sort "' . $this->sort . '" in "Tx_Workspaces_Service_GridData::sortDataArray" but $this->dataArray is empty! This might be the Bug #26422 which could not reproduced yet.', 3);
                }
+
+                       // Suggested slot method:
+                       // methodName(Tx_Workspaces_Service_GridData $gridData, array &$dataArray, $sortColumn, $sortDirection)
+               $this->emitSignal(
+                       self::SIGNAL_SortDataArray_PostProcesss,
+                       &$this->dataArray, $this->sort, $this->sortDir
+               );
        }
 
        /**
@@ -410,11 +445,19 @@ class Tx_Workspaces_Service_GridData {
        public function calculateChangePercentage($table, array $diffRecordOne, array $diffRecordTwo) {
 
                        // Initialize:
+               $processed = FALSE;
                $changePercentage = 0;
                $changePercentageArray = array();
 
+                       // Suggested slot method:
+                       // methodName(Tx_Workspaces_Service_GridData $gridData, &$changePercentage, array $firstRecord, array $secondRecord, &$processed)
+               $this->emitSignal(
+                       self::SIGNAL_CalcChangePercentage_PreProcess,
+                       &$changePercentage, $diffRecordOne, $diffRecordTwo, &$processed
+               );
+
                        // Check that records are arrays:
-               if (is_array($diffRecordOne) && is_array($diffRecordTwo)) {
+               if ($processed === FALSE && is_array($diffRecordOne) && is_array($diffRecordTwo)) {
 
                                // Load full table description
                        t3lib_div::loadTCA($table);
@@ -469,7 +512,14 @@ class Tx_Workspaces_Service_GridData {
                                count($changePercentageArray) > 0 ? $changePercentage = round($sumPctChange / count($changePercentageArray)) : $changePercentage = 0;
                        }
 
+                               // Suggested slot method:
+                               // methodName(Tx_Workspaces_Service_GridData $gridData, &$changePercentage, array $firstRecord, array $secondRecord, array $changePercentageArray)
+                       $this->emitSignal(
+                               self::SIGNAL_CalcChangePercentage_PostProcess,
+                               &$changePercentage, $diffRecordOne, $diffRecordTwo, $changePercentageArray
+                       );
                }
+
                return $changePercentage;
        }
 
@@ -505,6 +555,26 @@ class Tx_Workspaces_Service_GridData {
 
                return $state;
        }
+
+       /**
+        * Emits a signal to be handled by any registered slots.
+        *
+        * @param string $signalName Name of the signal
+        * @return void
+        */
+       protected function emitSignal($signalName) {
+                       // Arguments are always ($this, [method argument], [method argument], ...)
+               $signalArguments = array_merge(
+                       array($this),
+                       array_slice(func_get_args(), 1)
+               );
+
+               t3lib_SignalSlot_Dispatcher::getInstance()->dispatch(
+                       'Tx_Workspaces_Service_GridData',
+                       $signalName,
+                       $signalArguments
+               );
+       }
 }