mirror of
https://github.com/Combodo/iTop.git
synced 2026-05-19 15:22:17 +02:00
N°902.3 Portal: Extract column sorting helper to a specific service
This commit is contained in:
@@ -130,4 +130,7 @@ services:
|
||||
public: true
|
||||
browse_brick:
|
||||
alias: Combodo\iTop\Portal\Helper\BrowseBrickHelper
|
||||
public: true
|
||||
brick_controller_helper:
|
||||
alias: Combodo\iTop\Portal\Helper\BrickControllerHelper
|
||||
public: true
|
||||
@@ -68,6 +68,8 @@ class BrowseBrickController extends BrickController
|
||||
$oBrowseBrickHelper = $this->get('browse_brick');
|
||||
/** @var \Combodo\iTop\Portal\Helper\RequestManipulatorHelper $oRequestManipulator */
|
||||
$oRequestManipulator = $this->get('request_manipulator');
|
||||
/** @var \Combodo\iTop\Portal\Helper\BrickControllerHelper */
|
||||
$oBrickControllerHelper = $this->get('brick_controller_helper');
|
||||
|
||||
/** @var \Combodo\iTop\Portal\Brick\BrowseBrick $oBrick */
|
||||
$oBrick = $this->get('brick_collection')->getBrickById($sBrickId);
|
||||
@@ -75,7 +77,7 @@ class BrowseBrickController extends BrickController
|
||||
// Getting availables browse modes
|
||||
$aBrowseModes = $oBrick->GetAvailablesBrowseModes();
|
||||
$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();
|
||||
// Getting current dataloading mode (First from router parameter, then query parameter, then default brick value)
|
||||
$sDataLoading = ($sDataLoading !== null) ? $sDataLoading : $oRequestManipulator->ReadParam('sDataLoading',
|
||||
@@ -360,7 +362,7 @@ class BrowseBrickController extends BrickController
|
||||
$oSet->OptimizeColumnLoad($aColumnAttrs);
|
||||
|
||||
// Setting specified column sort, setting default datamodel one otherwise
|
||||
$aSortedParams = $this->ExtractSortParams();
|
||||
$aSortedParams = $oBrickControllerHelper->ExtractSortParams();
|
||||
if (!empty($aSortedParams))
|
||||
{
|
||||
$oSet->SetOrderBy($aSortedParams);
|
||||
@@ -430,28 +432,4 @@ class BrowseBrickController extends BrickController
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -275,14 +275,16 @@ class ManageBrickController extends BrickController
|
||||
/** @var string $sPortalId */
|
||||
$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 */
|
||||
$oUrlGenerator = $this->get('url_generator');
|
||||
/** @var \Combodo\iTop\Portal\Helper\RequestManipulatorHelper $oRequestManipulator */
|
||||
$oRequestManipulator = $this->get('request_manipulator');
|
||||
/** @var \Combodo\iTop\Portal\Helper\SecurityHelper $oSecurityHelper */
|
||||
$oSecurityHelper = $this->get('security_helper');
|
||||
/** @var \Combodo\iTop\Portal\Helper\ScopeValidatorHelper $oScopeValidator */
|
||||
$oScopeValidator = $this->get('scope_validator');
|
||||
/** @var \Combodo\iTop\Portal\Helper\BrickControllerHelper */
|
||||
$oBrickControllerHelper = $this->get('brick_controller_helper');
|
||||
/** @var \Combodo\iTop\Portal\Brick\BrickCollection $oBrickCollection */
|
||||
$oBrickCollection = $this->get('brick_collection');
|
||||
|
||||
@@ -402,7 +404,7 @@ class ManageBrickController extends BrickController
|
||||
$this->ManageSearchValue($aData, $oQuery, $sClass, $aColumnsAttrs);
|
||||
|
||||
// - Transforming search sort params to OQL format
|
||||
$aSortedParams = $this->ExtractSortParams($aColumnsAttrs);
|
||||
$aSortedParams = $oBrickControllerHelper->ExtractSortParams();
|
||||
|
||||
// Preparing areas
|
||||
// - We need to retrieve distinct values for the grouping attribute
|
||||
@@ -878,30 +880,6 @@ class ManageBrickController extends BrickController
|
||||
$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.
|
||||
* If a limit is given, the remaining groups are aggregated (group by result and search request).
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user