N°902.3 Portal: Extract column sorting helper to a specific service

This commit is contained in:
Molkobain
2019-07-22 11:44:03 +02:00
parent cdbdf580c8
commit 0205f150a3
4 changed files with 80 additions and 53 deletions

View File

@@ -131,3 +131,6 @@ services:
browse_brick: browse_brick:
alias: Combodo\iTop\Portal\Helper\BrowseBrickHelper alias: Combodo\iTop\Portal\Helper\BrowseBrickHelper
public: true public: true
brick_controller_helper:
alias: Combodo\iTop\Portal\Helper\BrickControllerHelper
public: true

View File

@@ -68,6 +68,8 @@ class BrowseBrickController extends BrickController
$oBrowseBrickHelper = $this->get('browse_brick'); $oBrowseBrickHelper = $this->get('browse_brick');
/** @var \Combodo\iTop\Portal\Helper\RequestManipulatorHelper $oRequestManipulator */ /** @var \Combodo\iTop\Portal\Helper\RequestManipulatorHelper $oRequestManipulator */
$oRequestManipulator = $this->get('request_manipulator'); $oRequestManipulator = $this->get('request_manipulator');
/** @var \Combodo\iTop\Portal\Helper\BrickControllerHelper */
$oBrickControllerHelper = $this->get('brick_controller_helper');
/** @var \Combodo\iTop\Portal\Brick\BrowseBrick $oBrick */ /** @var \Combodo\iTop\Portal\Brick\BrowseBrick $oBrick */
$oBrick = $this->get('brick_collection')->getBrickById($sBrickId); $oBrick = $this->get('brick_collection')->getBrickById($sBrickId);
@@ -75,7 +77,7 @@ class BrowseBrickController extends BrickController
// Getting availables browse modes // Getting availables browse modes
$aBrowseModes = $oBrick->GetAvailablesBrowseModes(); $aBrowseModes = $oBrick->GetAvailablesBrowseModes();
$aBrowseButtons = array_keys($aBrowseModes); $aBrowseButtons = array_keys($aBrowseModes);
// Getting current browse mode (First from router pamater, then default brick value) // Getting current browse mode (First from router parameter, then default brick value)
$sBrowseMode = (!empty($sBrowseMode)) ? $sBrowseMode : $oBrick->GetDefaultBrowseMode(); $sBrowseMode = (!empty($sBrowseMode)) ? $sBrowseMode : $oBrick->GetDefaultBrowseMode();
// Getting current dataloading mode (First from router parameter, then query parameter, then default brick value) // Getting current dataloading mode (First from router parameter, then query parameter, then default brick value)
$sDataLoading = ($sDataLoading !== null) ? $sDataLoading : $oRequestManipulator->ReadParam('sDataLoading', $sDataLoading = ($sDataLoading !== null) ? $sDataLoading : $oRequestManipulator->ReadParam('sDataLoading',
@@ -360,7 +362,7 @@ class BrowseBrickController extends BrickController
$oSet->OptimizeColumnLoad($aColumnAttrs); $oSet->OptimizeColumnLoad($aColumnAttrs);
// Setting specified column sort, setting default datamodel one otherwise // Setting specified column sort, setting default datamodel one otherwise
$aSortedParams = $this->ExtractSortParams(); $aSortedParams = $oBrickControllerHelper->ExtractSortParams();
if (!empty($aSortedParams)) if (!empty($aSortedParams))
{ {
$oSet->SetOrderBy($aSortedParams); $oSet->SetOrderBy($aSortedParams);
@@ -430,28 +432,4 @@ class BrowseBrickController extends BrickController
return $oResponse; return $oResponse;
} }
/**
* Extract sort params from request and convert them to iTop OQL format
*
* @return array
*
* @since 2.7.0
*/
protected function ExtractSortParams()
{
/** @var \Combodo\iTop\Portal\Helper\RequestManipulatorHelper $oRequestManipulator */
$oRequestManipulator = $this->get('request_manipulator');
// Getting sort params
$aSortParams = $oRequestManipulator->ReadParam('aSortParams', array());
// Converting sort direction to proper format for DBObjectSet as it only accept real booleans
foreach ($aSortParams as $sAttributeAlias => $sDirection)
{
$aSortParams[$sAttributeAlias] = ($sDirection === 'true');
}
return $aSortParams;
}
} }

View File

@@ -275,14 +275,16 @@ class ManageBrickController extends BrickController
/** @var string $sPortalId */ /** @var string $sPortalId */
$sPortalId = $this->getParameter('combodo.portal.instance.id'); $sPortalId = $this->getParameter('combodo.portal.instance.id');
/** @var \Combodo\iTop\Portal\Helper\RequestManipulatorHelper $oRequestManipulator */
$oRequestManipulator = $this->get('request_manipulator');
/** @var \Combodo\iTop\Portal\Routing\UrlGenerator $oUrlGenerator */ /** @var \Combodo\iTop\Portal\Routing\UrlGenerator $oUrlGenerator */
$oUrlGenerator = $this->get('url_generator'); $oUrlGenerator = $this->get('url_generator');
/** @var \Combodo\iTop\Portal\Helper\RequestManipulatorHelper $oRequestManipulator */
$oRequestManipulator = $this->get('request_manipulator');
/** @var \Combodo\iTop\Portal\Helper\SecurityHelper $oSecurityHelper */ /** @var \Combodo\iTop\Portal\Helper\SecurityHelper $oSecurityHelper */
$oSecurityHelper = $this->get('security_helper'); $oSecurityHelper = $this->get('security_helper');
/** @var \Combodo\iTop\Portal\Helper\ScopeValidatorHelper $oScopeValidator */ /** @var \Combodo\iTop\Portal\Helper\ScopeValidatorHelper $oScopeValidator */
$oScopeValidator = $this->get('scope_validator'); $oScopeValidator = $this->get('scope_validator');
/** @var \Combodo\iTop\Portal\Helper\BrickControllerHelper */
$oBrickControllerHelper = $this->get('brick_controller_helper');
/** @var \Combodo\iTop\Portal\Brick\BrickCollection $oBrickCollection */ /** @var \Combodo\iTop\Portal\Brick\BrickCollection $oBrickCollection */
$oBrickCollection = $this->get('brick_collection'); $oBrickCollection = $this->get('brick_collection');
@@ -402,7 +404,7 @@ class ManageBrickController extends BrickController
$this->ManageSearchValue($aData, $oQuery, $sClass, $aColumnsAttrs); $this->ManageSearchValue($aData, $oQuery, $sClass, $aColumnsAttrs);
// - Transforming search sort params to OQL format // - Transforming search sort params to OQL format
$aSortedParams = $this->ExtractSortParams($aColumnsAttrs); $aSortedParams = $oBrickControllerHelper->ExtractSortParams();
// Preparing areas // Preparing areas
// - We need to retrieve distinct values for the grouping attribute // - We need to retrieve distinct values for the grouping attribute
@@ -878,30 +880,6 @@ class ManageBrickController extends BrickController
$aData['sSearchValue'] = $sSearchValue; $aData['sSearchValue'] = $sSearchValue;
} }
/**
* Extract sort params from request and convert them to iTop OQL format
*
* @return array
*
* @since 2.7.0
*/
protected function ExtractSortParams()
{
/** @var \Combodo\iTop\Portal\Helper\RequestManipulatorHelper $oRequestManipulator */
$oRequestManipulator = $this->get('request_manipulator');
// Getting sort params
$aSortParams = $oRequestManipulator->ReadParam('aSortParams', array());
// Converting sort direction to proper format for DBObjectSet as it only accept real booleans
foreach ($aSortParams as $sAttributeAlias => $sDirection)
{
$aSortParams[$sAttributeAlias] = ($sDirection === 'true');
}
return $aSortParams;
}
/** /**
* Get the groups using a given attribute code. * Get the groups using a given attribute code.
* If a limit is given, the remaining groups are aggregated (group by result and search request). * If a limit is given, the remaining groups are aggregated (group by result and search request).

View File

@@ -0,0 +1,68 @@
<?php
/**
* Copyright (C) 2013-2019 Combodo SARL
*
* This file is part of iTop.
*
* iTop is free software; you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* iTop is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
*
*
*/
namespace Combodo\iTop\Portal\Helper;
/**
* Class BrickControllerHelper
*
* @package Combodo\iTop\Portal\Helper
* @since 2.7.0
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
*/
class BrickControllerHelper
{
/** @var \Combodo\iTop\Portal\Helper\RequestManipulatorHelper $oRequestManipulator */
private $oRequestManipulator;
/**
* BrowseBrickHelper constructor.
*
* @param \Combodo\iTop\Portal\Helper\RequestManipulatorHelper $oRequestManipulator
*/
public function __construct(RequestManipulatorHelper $oRequestManipulator)
{
$this->oRequestManipulator = $oRequestManipulator;
}
/**
* Extract sort params from request and convert them to iTop OQL format
*
* @return array
*
* @since 2.7.0
*/
public function ExtractSortParams()
{
// Getting sort params
$aSortParams = $this->oRequestManipulator->ReadParam('aSortParams', array());
// Converting sort direction to proper format for DBObjectSet as it only accept real booleans
foreach ($aSortParams as $sAttributeAlias => $sDirection)
{
$aSortParams[$sAttributeAlias] = ($sDirection === 'true');
}
return $aSortParams;
}
}