mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-13 07:24:13 +01:00
Internal: reworked default ordering (added DBObjectSet::GetRealSortOrder)
SVN:trunk[1927]
This commit is contained in:
@@ -321,6 +321,20 @@ class DBObjectSet
|
||||
return $this->m_iLimitStart;
|
||||
}
|
||||
|
||||
public function GetRealSortOrder()
|
||||
{
|
||||
// Get the class default sort order if not specified with the API
|
||||
//
|
||||
if (empty($this->m_aOrderBy))
|
||||
{
|
||||
return MetaModel::GetOrderByDefault($this->m_oFilter->GetClass());
|
||||
}
|
||||
else
|
||||
{
|
||||
return $this->m_aOrderBy;
|
||||
}
|
||||
}
|
||||
|
||||
public function Load()
|
||||
{
|
||||
if ($this->m_bLoaded) return;
|
||||
@@ -329,11 +343,11 @@ class DBObjectSet
|
||||
|
||||
if ($this->m_iLimitCount > 0)
|
||||
{
|
||||
$sSQL = MetaModel::MakeSelectQuery($this->m_oFilter, $this->m_aOrderBy, $this->m_aArgs, $this->m_aAttToLoad, $this->m_aExtendedDataSpec, $this->m_iLimitCount, $this->m_iLimitStart);
|
||||
$sSQL = MetaModel::MakeSelectQuery($this->m_oFilter, $this->GetRealSortOrder(), $this->m_aArgs, $this->m_aAttToLoad, $this->m_aExtendedDataSpec, $this->m_iLimitCount, $this->m_iLimitStart);
|
||||
}
|
||||
else
|
||||
{
|
||||
$sSQL = MetaModel::MakeSelectQuery($this->m_oFilter, $this->m_aOrderBy, $this->m_aArgs, $this->m_aAttToLoad, $this->m_aExtendedDataSpec);
|
||||
$sSQL = MetaModel::MakeSelectQuery($this->m_oFilter, $this->GetRealSortOrder(), $this->m_aArgs, $this->m_aAttToLoad, $this->m_aExtendedDataSpec);
|
||||
}
|
||||
$resQuery = CMDBSource::Query($sSQL);
|
||||
if (!$resQuery) return;
|
||||
@@ -370,7 +384,7 @@ class DBObjectSet
|
||||
{
|
||||
if (is_null($this->m_iCount))
|
||||
{
|
||||
$sSQL = MetaModel::MakeSelectQuery($this->m_oFilter, $this->m_aOrderBy, $this->m_aArgs, null, null, 0, 0, true);
|
||||
$sSQL = MetaModel::MakeSelectQuery($this->m_oFilter, array(), $this->m_aArgs, null, null, 0, 0, true);
|
||||
$resQuery = CMDBSource::Query($sSQL);
|
||||
if (!$resQuery) return 0;
|
||||
|
||||
|
||||
@@ -494,11 +494,26 @@ abstract class MetaModel
|
||||
self::_check_subclass($sClass);
|
||||
return array_key_exists("display_template", self::$m_aClassParams[$sClass]) ? self::$m_aClassParams[$sClass]["display_template"]: '';
|
||||
}
|
||||
final static public function GetOrderByDefault($sClass)
|
||||
|
||||
final static public function GetOrderByDefault($sClass, $bOnlyDeclared = false)
|
||||
{
|
||||
self::_check_subclass($sClass);
|
||||
return array_key_exists("order_by_default", self::$m_aClassParams[$sClass]) ? self::$m_aClassParams[$sClass]["order_by_default"]: array();
|
||||
$aOrderBy = array_key_exists("order_by_default", self::$m_aClassParams[$sClass]) ? self::$m_aClassParams[$sClass]["order_by_default"]: array();
|
||||
if ($bOnlyDeclared)
|
||||
{
|
||||
// Used to reverse engineer the declaration of the data model
|
||||
return $aOrderBy;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (count($aOrderBy) == 0)
|
||||
{
|
||||
$aOrderBy['friendlyname'] = true;
|
||||
}
|
||||
return $aOrderBy;
|
||||
}
|
||||
}
|
||||
|
||||
final static public function GetAttributeOrigin($sClass, $sAttCode)
|
||||
{
|
||||
self::_check_subclass($sClass);
|
||||
@@ -2014,12 +2029,6 @@ abstract class MetaModel
|
||||
}
|
||||
}
|
||||
|
||||
// Get the class default sort order if not specified with the API
|
||||
//
|
||||
if (empty($aOrderBy))
|
||||
{
|
||||
$aOrderBy = self::GetOrderByDefault($oFilter->GetClass());
|
||||
}
|
||||
// Check the order by specification, and prefix with the class alias
|
||||
// and make sure that the ordering columns are going to be selected
|
||||
//
|
||||
@@ -2054,22 +2063,6 @@ abstract class MetaModel
|
||||
$aAttToLoad[$sFirstClassAlias][$sFieldAlias] = MetaModel::GetAttributeDef($oFilter->GetFirstJoinedClass(), $sFieldAlias);
|
||||
}
|
||||
}
|
||||
// At least, force the name attribute to be the ordering key
|
||||
//
|
||||
if (empty($aOrderSpec))
|
||||
{
|
||||
foreach ($oFilter->GetSelectedClasses() as $sSelectedAlias => $sSelectedClass)
|
||||
{
|
||||
// By default, simply order on the "friendlyname" attribute, ascending
|
||||
$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"]))
|
||||
{
|
||||
$aAttToLoad[$sSelectedAlias]["friendlyname"] = MetaModel::GetAttributeDef($sSelectedClass, "friendlyname");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($oSelect))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user