mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-12 23:14:18 +01:00
#421 Sort IP addresses on INET_ATON (API only, see #520 to have this as the default sort order for NW Interfaces)
SVN:trunk[1897]
This commit is contained in:
@@ -318,6 +318,12 @@ abstract class AttributeDefinition
|
||||
public function GetSQLValues($value) {return array();} // returns column/value pairs (1 in most of the cases), for WRITING (Insert, Update)
|
||||
public function RequiresIndex() {return false;}
|
||||
|
||||
public function GetOrderBySQLExpressions($sClassAlias)
|
||||
{
|
||||
// Note: This is the responsibility of this function to place backticks around column aliases
|
||||
return array('`'.$sClassAlias.$this->GetCode().'`');
|
||||
}
|
||||
|
||||
// Import - differs slightly from SQL input, but identical in most cases
|
||||
//
|
||||
public function GetImportColumns() {return $this->GetSQLColumns();}
|
||||
@@ -1899,6 +1905,12 @@ class AttributeIPAddress extends AttributeString
|
||||
$sNum = '(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])';
|
||||
return "^($sNum\\.$sNum\\.$sNum\\.$sNum)$";
|
||||
}
|
||||
|
||||
public function GetOrderBySQLExpressions($sClassAlias)
|
||||
{
|
||||
// Note: This is the responsibility of this function to place backticks around column aliases
|
||||
return array('INET_ATON(`'.$sClassAlias.$this->GetCode().'`)');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -2024,7 +2024,18 @@ abstract class MetaModel
|
||||
throw new CoreException("Wrong direction in ORDER BY spec, found '$bAscending' and expecting a boolean value");
|
||||
}
|
||||
$sFirstClassAlias = $oFilter->GetFirstJoinedClassAlias();
|
||||
$aOrderSpec[$sFirstClassAlias.$sFieldAlias] = $bAscending;
|
||||
if (self::IsValidAttCode($oFilter->GetClass(), $sFieldAlias))
|
||||
{
|
||||
$oAttDef = self::GetAttributeDef($oFilter->GetClass(), $sFieldAlias);
|
||||
foreach($oAttDef->GetOrderBySQLExpressions($sFirstClassAlias) as $sSQLExpression)
|
||||
{
|
||||
$aOrderSpec[$sSQLExpression] = $bAscending;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$aOrderSpec['`'.$sFirstClassAlias.$sFieldAlias.'`'] = $bAscending;
|
||||
}
|
||||
|
||||
// Make sure that the columns used for sorting are present in the loaded columns
|
||||
if (!is_null($aAttToLoad) && !isset($aAttToLoad[$sFirstClassAlias][$sFieldAlias]))
|
||||
@@ -2039,7 +2050,7 @@ abstract class MetaModel
|
||||
foreach ($oFilter->GetSelectedClasses() as $sSelectedAlias => $sSelectedClass)
|
||||
{
|
||||
// By default, simply order on the "friendlyname" attribute, ascending
|
||||
$aOrderSpec[$sSelectedAlias."friendlyname"] = true;
|
||||
$aOrderSpec['`'.$sSelectedAlias."friendlyname`"] = true;
|
||||
|
||||
// Make sure that the columns used for sorting are present in the loaded columns
|
||||
if (!is_null($aAttToLoad) && !isset($aAttToLoad[$sSelectedAlias]["friendlyname"]))
|
||||
@@ -2080,7 +2091,7 @@ abstract class MetaModel
|
||||
foreach($aExtendedDataSpec['fields'] as $sColumn)
|
||||
{
|
||||
$sColRef = $oFilter->GetClassAlias().'_extdata_'.$sColumn;
|
||||
$aExtendedFields[$sColRef] = new FieldExpressionResolved($sColumn, $sTableAlias);;
|
||||
$aExtendedFields[$sColRef] = new FieldExpressionResolved($sColumn, $sTableAlias);
|
||||
}
|
||||
$oSelectExt = new SQLQuery($aExtendedDataSpec['table'], $sTableAlias, $aExtendedFields);
|
||||
$oSelect->AddInnerJoin($oSelectExt, 'id', $aExtendedDataSpec['join_key'] /*, $sTableAlias*/);
|
||||
|
||||
@@ -407,7 +407,8 @@ class SQLQuery
|
||||
$aOrderBySpec = array();
|
||||
foreach($aOrderBy as $sFieldAlias => $bAscending)
|
||||
{
|
||||
$aOrderBySpec[] = '`'.$sFieldAlias.'`'.($bAscending ? " ASC" : " DESC");
|
||||
// Note: sFieldAlias must have backticks around column aliases
|
||||
$aOrderBySpec[] = $sFieldAlias.($bAscending ? " ASC" : " DESC");
|
||||
}
|
||||
$sOrderBy = implode(", ", $aOrderBySpec);
|
||||
return $sOrderBy;
|
||||
|
||||
Reference in New Issue
Block a user