Skip to content
This repository has been archived by the owner on May 4, 2021. It is now read-only.

Commit

Permalink
[CLEANUP] Helper and Hooks
Browse files Browse the repository at this point in the history
Change-Id: I6aa92c7ecc1731b41379bb5355eeaa21c6a341a7
Releases: master, 7
Reviewed-on: https://review.typo3.org/49400
Reviewed-by: Jo Hasenau <info@cybercraft.de>
Tested-by: Jo Hasenau <info@cybercraft.de>
(cherry picked from commit 4679430)
Reviewed-on: https://review.typo3.org/49461
  • Loading branch information
liayn authored and Bunnyfield committed Aug 12, 2016
1 parent 18ab541 commit 39dc564
Show file tree
Hide file tree
Showing 8 changed files with 211 additions and 274 deletions.
61 changes: 25 additions & 36 deletions Classes/Helper/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

use TYPO3\CMS\Core\Database\DatabaseConnection;
use TYPO3\CMS\Core\SingletonInterface;
use TYPO3\CMS\Core\Utility\DebugUtility;

/**
* Gridelements helper class
Expand All @@ -32,31 +31,29 @@
*/
class Helper implements SingletonInterface
{

/**
* @var DatabaseConnection
*/
protected static $databaseConnection;

/**
* Local instance of the helper
*
* @var Helper
*/
protected static $instance = null;

/**
* @var DatabaseConnection
*/
protected $databaseConnection;

/**
* Get instance from the class.
*
* @static
* @return Helper
* @return Helper
*/
public static function getInstance()
{
if (!self::$instance instanceof Helper) {
self::$instance = new self();
self::$instance->setDatabaseConnection($GLOBALS['TYPO3_DB']);
}
self::setDatabaseConnection($GLOBALS['TYPO3_DB']);

return self::$instance;
}
Expand All @@ -65,12 +62,10 @@ public static function getInstance()
* setter for databaseConnection object
*
* @param DatabaseConnection $databaseConnection
*
* @return void
*/
public static function setDatabaseConnection(DatabaseConnection $databaseConnection)
public function setDatabaseConnection(DatabaseConnection $databaseConnection)
{
self::$databaseConnection = $databaseConnection;
$this->databaseConnection = $databaseConnection;
}

/**
Expand All @@ -87,18 +82,15 @@ public function getChildren($table = '', $uid = 0, $sortingField = '', $sortRev
$retVal = array();

if (trim($table) === 'tt_content' && $uid > 0) {

$children = self::getDatabaseConnection()->exec_SELECTgetRows($selectFieldList, 'tt_content',
'tx_gridelements_container = ' . (int)$uid . ' AND deleted = 0', '');
$children = self::getDatabaseConnection()->exec_SELECTgetRows($selectFieldList, 'tt_content', 'tx_gridelements_container = ' . (int)$uid . ' AND deleted = 0', '');

foreach ($children as $child) {
if (trim($sortingField) && isset($child[$sortingField]) && $sortingField !== 'sorting') {
$sortField = $child[$sortingField];
} else {
$sortField = sprintf('%1$011d', $child['sorting']);
}
$sortKey = sprintf('%1$011d',
$child['tx_gridelements_columns']) . '.' . $sortField . ':' . sprintf('%1$011d', $child['uid']);
$sortKey = sprintf('%1$011d', $child['tx_gridelements_columns']) . '.' . $sortField . ':' . sprintf('%1$011d', $child['uid']);

$retVal[$sortKey] = $child;
}
Expand All @@ -123,22 +115,10 @@ public function getPidFromNegativeUid($negativeUid = 0)
{
if ($negativeUid >= 0) {
return $negativeUid;
} else {
$triggerElement = self::$databaseConnection->exec_SELECTgetSingleRow('pid', 'tt_content',
'uid = ' . abs($negativeUid));
$pid = (int)$triggerElement['pid'];
return is_array($triggerElement) && $pid ? $pid : 0;
}
}

/**
* getter for databaseConnection
*
* @return DatabaseConnection databaseConnection
*/
public function getDatabaseConnection()
{
return self::$databaseConnection;
$triggerElement = $this->databaseConnection->exec_SELECTgetSingleRow('pid', 'tt_content', 'uid = ' . abs($negativeUid));
$pid = (int)$triggerElement['pid'];
return is_array($triggerElement) && $pid ? $pid : 0;
}

/**
Expand All @@ -148,7 +128,7 @@ public function getDatabaseConnection()
*
* @param array $record Overlaid record data
*
* @return integer
* @return int[]
*/
public function getSpecificIds(array $record)
{
Expand All @@ -164,6 +144,16 @@ public function getSpecificIds(array $record)
return $specificIds;
}

/**
* getter for databaseConnection
*
* @return DatabaseConnection databaseConnection
*/
public function getDatabaseConnection()
{
return $this->databaseConnection;
}

/**
* Gets the current backend user.
*
Expand All @@ -173,5 +163,4 @@ public function getBackendUser()
{
return $GLOBALS['BE_USER'];
}

}
11 changes: 4 additions & 7 deletions Classes/Hooks/AbstractDatabaseRecordList.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,14 @@
*/
class AbstractDatabaseRecordList implements SingletonInterface
{

/**
* ItemProcFunc for columns items
*
* @param array $queryParts : The array containing the parts to build the query from
* @param DatabaseRecordList $parent : The parent object that triggered this hook
* @param string $table : The name of the table we are currently working on
*
* @return void
* @param array $queryParts The array containing the parts to build the query from
* @param DatabaseRecordList $parent The parent object that triggered this hook
* @param string $table The name of the table we are currently working on
*/
public function makeQueryArray_post(&$queryParts, &$parent, $table)
public function makeQueryArray_post(array &$queryParts, DatabaseRecordList $parent, $table)
{
if ($table === 'tt_content' && $parent instanceof \GridElementsTeam\Gridelements\Xclass\DatabaseRecordList) {
$queryParts['ORDERBY'] = $this->addValueToList($queryParts['ORDERBY'], 'colPos');
Expand Down
14 changes: 3 additions & 11 deletions Classes/Hooks/BackendUtilityGridelements.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
*/
class BackendUtilityGridelements
{

/**
* @var DatabaseConnection
*/
Expand All @@ -50,8 +49,6 @@ class BackendUtilityGridelements
* inject layout setup
*
* @param LayoutSetup $layoutSetup
*
* @return void
*/
public function injectLayoutSetup(LayoutSetup $layoutSetup)
{
Expand All @@ -61,9 +58,7 @@ public function injectLayoutSetup(LayoutSetup $layoutSetup)
/**
* initializes this class
*
* @param integer $pageUid
*
* @return void
* @param int $pageUid
*/
public function init($pageUid)
{
Expand All @@ -85,10 +80,8 @@ public function init($pageUid)
* @param array $row
* @param string $table
* @param string $fieldName
*
* @return void
*/
public function getFlexFormDS_postProcessDS(&$dataStructureArray, $conf, $row, $table, $fieldName)
public function getFlexFormDS_postProcessDS(array &$dataStructureArray, array $conf, array $row, $table, $fieldName)
{
if ($table === 'tt_content' && $fieldName === 'pi_flexform' && $row['CType'] === 'gridelements_pi1' && $row['tx_gridelements_backend_layout']) {
$this->init($row['pid']);
Expand Down Expand Up @@ -117,5 +110,4 @@ public function getDatabaseConnection()
{
return $this->databaseConnection;
}

}
}
28 changes: 11 additions & 17 deletions Classes/Hooks/DataHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
***************************************************************/

use GridElementsTeam\Gridelements\DataHandler\AfterDatabaseOperations;
use GridElementsTeam\Gridelements\DataHandler\MoveRecord;
use GridElementsTeam\Gridelements\DataHandler\PreProcessFieldArray;
use GridElementsTeam\Gridelements\DataHandler\ProcessCmdmap;
use TYPO3\CMS\Core\Database\DatabaseConnection;
use TYPO3\CMS\Core\SingletonInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;
Expand All @@ -35,7 +35,6 @@
*/
class DataHandler implements SingletonInterface
{

/**
* @var DatabaseConnection
*/
Expand Down Expand Up @@ -92,7 +91,7 @@ public function processDatamap_afterDatabaseOperations(
\TYPO3\CMS\Core\DataHandling\DataHandler $parentObj
) {
if (($table === 'tt_content' || $table === 'pages') && $status === 'update' && !$parentObj->isImporting) {
/** @var $hook AfterDatabaseOperations */
/** @var AfterDatabaseOperations $hook */
$hook = GeneralUtility::makeInstance(AfterDatabaseOperations::class);
$hook->execute_afterDatabaseOperations($fieldArray, $table, $id, $parentObj);
}
Expand All @@ -101,15 +100,13 @@ public function processDatamap_afterDatabaseOperations(
/**
* Function to process the drag & drop copy action
*
* @param string $command : The command to be handled by the command map
* @param string $table : The name of the table we are working on
* @param int $id : The id of the record that is going to be copied
* @param string $value : The value that has been sent with the copy command
* @param boolean $commandIsProcessed : A switch to tell the parent object, if the record has been copied
* @param \TYPO3\CMS\Core\DataHandling\DataHandler $parentObj : The parent object that triggered this hook
* @param array|boolean $pasteUpdate : Values to be updated after the record is pasted
*
* @return void
* @param string $command The command to be handled by the command map
* @param string $table The name of the table we are working on
* @param int $id The id of the record that is going to be copied
* @param string $value The value that has been sent with the copy command
* @param boolean $commandIsProcessed A switch to tell the parent object, if the record has been copied
* @param \TYPO3\CMS\Core\DataHandling\DataHandler $parentObj The parent object that triggered this hook
* @param array|bool $pasteUpdate Values to be updated after the record is pasted
*/
public function processCmdmap(
$command,
Expand All @@ -120,9 +117,9 @@ public function processCmdmap(
\TYPO3\CMS\Core\DataHandling\DataHandler &$parentObj,
$pasteUpdate
) {
/** @var $hook \GridElementsTeam\Gridelements\DataHandler\ProcessCmdmap */
if (!$parentObj->isImporting) {
$hook = GeneralUtility::makeInstance('GridElementsTeam\\Gridelements\\DataHandler\\ProcessCmdmap');
/** @var ProcessCmdmap $hook */
$hook = GeneralUtility::makeInstance(ProcessCmdmap::class);
$hook->execute_processCmdmap($command, $table, $id, $value, $commandIsProcessed, $parentObj, $pasteUpdate);
}
}
Expand All @@ -131,8 +128,6 @@ public function processCmdmap(
* setter for databaseConnection object
*
* @param DatabaseConnection $databaseConnection
*
* @return void
*/
public function setDatabaseConnection(DatabaseConnection $databaseConnection)
{
Expand All @@ -148,5 +143,4 @@ public function getDatabaseConnection()
{
return $this->databaseConnection;
}

}
Loading

0 comments on commit 39dc564

Please sign in to comment.