mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-13 07:24:13 +01:00
@@ -972,6 +972,9 @@ class DBObjectSearch
|
|||||||
|
|
||||||
// Alternative to object mapping: the data are transfered directly into an array
|
// Alternative to object mapping: the data are transfered directly into an array
|
||||||
// This is 10 times faster than creating a set of objects, and makes sense when optimization is required
|
// This is 10 times faster than creating a set of objects, and makes sense when optimization is required
|
||||||
|
/**
|
||||||
|
* @param hash $aOrderBy Array of '[<classalias>.]attcode' => bAscending
|
||||||
|
*/
|
||||||
public function ToDataArray($aColumns = array(), $aOrderBy = array(), $aArgs = array())
|
public function ToDataArray($aColumns = array(), $aOrderBy = array(), $aArgs = array())
|
||||||
{
|
{
|
||||||
$sSQL = MetaModel::MakeSelectQuery($this, $aOrderBy, $aArgs);
|
$sSQL = MetaModel::MakeSelectQuery($this, $aOrderBy, $aArgs);
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ class DBObjectSet
|
|||||||
* Create a new set based on a Search definition.
|
* Create a new set based on a Search definition.
|
||||||
*
|
*
|
||||||
* @param DBObjectSearch $oFilter The search filter defining the objects which are part of the set (multiple columns/objects per row are supported)
|
* @param DBObjectSearch $oFilter The search filter defining the objects which are part of the set (multiple columns/objects per row are supported)
|
||||||
* @param hash $aOrderBy
|
* @param hash $aOrderBy Array of '[<classalias>.]attcode' => bAscending
|
||||||
* @param hash $aArgs Values to substitute for the search/query parameters (if any). Format: param_name => value
|
* @param hash $aArgs Values to substitute for the search/query parameters (if any). Format: param_name => value
|
||||||
* @param hash $aExtendedDataSpec
|
* @param hash $aExtendedDataSpec
|
||||||
* @param int $iLimitCount Maximum number of rows to load (i.e. equivalent to MySQL's LIMIT start, count)
|
* @param int $iLimitCount Maximum number of rows to load (i.e. equivalent to MySQL's LIMIT start, count)
|
||||||
@@ -1156,5 +1156,3 @@ function HashCountComparison($a, $b) // Sort descending on 'count'
|
|||||||
}
|
}
|
||||||
return ($a['count'] > $b['count']) ? -1 : 1;
|
return ($a['count'] > $b['count']) ? -1 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
// Copyright (C) 2010-2013 Combodo SARL
|
// Copyright (C) 2010-2014 Combodo SARL
|
||||||
//
|
//
|
||||||
// This file is part of iTop.
|
// This file is part of iTop.
|
||||||
//
|
//
|
||||||
@@ -2218,6 +2218,9 @@ abstract class MetaModel
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param hash $aOrderBy Array of '[<classalias>.]attcode' => bAscending
|
||||||
|
*/
|
||||||
public static function MakeSelectQuery(DBObjectSearch $oFilter, $aOrderBy = array(), $aArgs = array(), $aAttToLoad = null, $aExtendedDataSpec = null, $iLimitCount = 0, $iLimitStart = 0, $bGetCount = false)
|
public static function MakeSelectQuery(DBObjectSearch $oFilter, $aOrderBy = array(), $aArgs = array(), $aAttToLoad = null, $aExtendedDataSpec = null, $iLimitCount = 0, $iLimitStart = 0, $bGetCount = false)
|
||||||
{
|
{
|
||||||
// Check the order by specification, and prefix with the class alias
|
// Check the order by specification, and prefix with the class alias
|
||||||
@@ -2228,32 +2231,44 @@ abstract class MetaModel
|
|||||||
$aOrderSpec = array();
|
$aOrderSpec = array();
|
||||||
foreach ($aOrderBy as $sFieldAlias => $bAscending)
|
foreach ($aOrderBy as $sFieldAlias => $bAscending)
|
||||||
{
|
{
|
||||||
if ($sFieldAlias != 'id')
|
|
||||||
{
|
|
||||||
MyHelpers::CheckValueInArray('field name in ORDER BY spec', $sFieldAlias, self::GetAttributesList($sClass));
|
|
||||||
}
|
|
||||||
if (!is_bool($bAscending))
|
if (!is_bool($bAscending))
|
||||||
{
|
{
|
||||||
throw new CoreException("Wrong direction in ORDER BY spec, found '$bAscending' and expecting a boolean value");
|
throw new CoreException("Wrong direction in ORDER BY spec, found '$bAscending' and expecting a boolean value");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self::IsValidAttCode($sClass, $sFieldAlias))
|
$iDotPos = strpos($sFieldAlias, '.');
|
||||||
|
if ($iDotPos === false)
|
||||||
{
|
{
|
||||||
$oAttDef = self::GetAttributeDef($sClass, $sFieldAlias);
|
$sAttClass = $sClass;
|
||||||
foreach($oAttDef->GetOrderBySQLExpressions($sClassAlias) as $sSQLExpression)
|
$sAttClassAlias = $sClassAlias;
|
||||||
|
$sAttCode = $sFieldAlias;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$sAttClassAlias = substr($sFieldAlias, 0, $iDotPos);
|
||||||
|
$sAttClass = $oFilter->GetClassName($sAttClassAlias);
|
||||||
|
$sAttCode = substr($sFieldAlias, $iDotPos + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($sAttCode != 'id')
|
||||||
|
{
|
||||||
|
MyHelpers::CheckValueInArray('field name in ORDER BY spec', $sAttCode, self::GetAttributesList($sAttClass));
|
||||||
|
|
||||||
|
$oAttDef = self::GetAttributeDef($sAttClass, $sAttCode);
|
||||||
|
foreach($oAttDef->GetOrderBySQLExpressions($sAttClassAlias) as $sSQLExpression)
|
||||||
{
|
{
|
||||||
$aOrderSpec[$sSQLExpression] = $bAscending;
|
$aOrderSpec[$sSQLExpression] = $bAscending;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$aOrderSpec['`'.$sClassAlias.$sFieldAlias.'`'] = $bAscending;
|
$aOrderSpec['`'.$sAttClassAlias.$sAttCode.'`'] = $bAscending;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure that the columns used for sorting are present in the loaded columns
|
// Make sure that the columns used for sorting are present in the loaded columns
|
||||||
if (!is_null($aAttToLoad) && !isset($aAttToLoad[$sClassAlias][$sFieldAlias]))
|
if (!is_null($aAttToLoad) && !isset($aAttToLoad[$sAttClassAlias][$sAttCode]))
|
||||||
{
|
{
|
||||||
$aAttToLoad[$sClassAlias][$sFieldAlias] = MetaModel::GetAttributeDef($sClass, $sFieldAlias);
|
$aAttToLoad[$sAttClassAlias][$sAttCode] = MetaModel::GetAttributeDef($sAttClass, $sAttCode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -5509,5 +5524,3 @@ MetaModel::RegisterZList("preview", array("description"=>"All attributes visible
|
|||||||
|
|
||||||
MetaModel::RegisterZList("standard_search", array("description"=>"List of criteria for the standard search", "type"=>"filters"));
|
MetaModel::RegisterZList("standard_search", array("description"=>"List of criteria for the standard search", "type"=>"filters"));
|
||||||
MetaModel::RegisterZList("advanced_search", array("description"=>"List of criteria for the advanced search", "type"=>"filters"));
|
MetaModel::RegisterZList("advanced_search", array("description"=>"List of criteria for the advanced search", "type"=>"filters"));
|
||||||
|
|
||||||
?>
|
|
||||||
|
|||||||
@@ -100,6 +100,9 @@ class ValueSetObjects extends ValueSetDefinition
|
|||||||
private $m_bAllowAllData;
|
private $m_bAllowAllData;
|
||||||
private $m_aModifierProperties;
|
private $m_aModifierProperties;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param hash $aOrderBy Array of '[<classalias>.]attcode' => bAscending
|
||||||
|
*/
|
||||||
public function __construct($sFilterExp, $sValueAttCode = '', $aOrderBy = array(), $bAllowAllData = false, $aModifierProperties = array())
|
public function __construct($sFilterExp, $sValueAttCode = '', $aOrderBy = array(), $bAllowAllData = false, $aModifierProperties = array())
|
||||||
{
|
{
|
||||||
$this->m_sContains = '';
|
$this->m_sContains = '';
|
||||||
@@ -415,5 +418,3 @@ class ValueSetEnumClasses extends ValueSetEnum
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
// Copyright (C) 2010-2013 Combodo SARL
|
// Copyright (C) 2010-2014 Combodo SARL
|
||||||
//
|
//
|
||||||
// This file is part of iTop.
|
// This file is part of iTop.
|
||||||
//
|
//
|
||||||
@@ -120,16 +120,16 @@ try
|
|||||||
if ($aNameSpec[0] == '%1$s')
|
if ($aNameSpec[0] == '%1$s')
|
||||||
{
|
{
|
||||||
// The name is made of a single column, let's sort according to the sort algorithm for this column
|
// The name is made of a single column, let's sort according to the sort algorithm for this column
|
||||||
$aOrderBy[$aNameSpec[1][0]] = (utils::ReadParam('sort_order', 'asc') == 'asc');
|
$aOrderBy[$sAlias.'.'.$aNameSpec[1][0]] = (utils::ReadParam('sort_order', 'asc') == 'asc');
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$aOrderBy['friendlyname'] = (utils::ReadParam('sort_order', 'asc') == 'asc');
|
$aOrderBy[$sAlias.'.'.'friendlyname'] = (utils::ReadParam('sort_order', 'asc') == 'asc');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$aOrderBy['friendlyname'] = (utils::ReadParam('sort_order', 'asc') == 'asc');
|
$aOrderBy[$sAlias.'.'.'friendlyname'] = (utils::ReadParam('sort_order', 'asc') == 'asc');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -155,7 +155,7 @@ try
|
|||||||
{
|
{
|
||||||
$sSortCol = $sAttCode;
|
$sSortCol = $sAttCode;
|
||||||
}
|
}
|
||||||
$aOrderBy[$sSortCol] = (utils::ReadParam('sort_order', 'asc') == 'asc');
|
$aOrderBy[$sAlias.'.'.$sSortCol] = (utils::ReadParam('sort_order', 'asc') == 'asc');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$iSortIndex++;
|
$iSortIndex++;
|
||||||
|
|||||||
Reference in New Issue
Block a user