From 2f8dc0fa0fbe9d110e2718964bdd65023733d57e Mon Sep 17 00:00:00 2001 From: Romain Quetiez Date: Fri, 23 Sep 2016 15:05:06 +0000 Subject: [PATCH] Prerequisite for #1334. New API: DBObjectSet::SetOrderByClasses. Helper to sort on multicolumn queries (SELECT a, b FROM) SVN:trunk[4413] --- core/dbobjectset.class.php | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/core/dbobjectset.class.php b/core/dbobjectset.class.php index 047a4ac53..5100cabf6 100644 --- a/core/dbobjectset.class.php +++ b/core/dbobjectset.class.php @@ -445,8 +445,8 @@ class DBObjectSet /** * Sets the sort order for loading the rows from the DB. Changing the order by causes a Reload. - * - * @param hash $aOrderBy Format: field_code => boolean (true = ascending, false = descending) + * + * @param hash $aOrderBy Format: [alias.]attcode => boolean (true = ascending, false = descending) */ public function SetOrderBy($aOrderBy) { @@ -461,6 +461,34 @@ class DBObjectSet } } + /** + * Sets the sort order for loading the rows from the DB. Changing the order by causes a Reload. + * + * @param hash $aAliases Format: alias => boolean (true = ascending, false = descending). If omitted, then it defaults to all the selected classes + */ + public function SetOrderByClasses($aAliases = null) + { + if ($aAliases === null) + { + $aAliases = array(); + foreach ($this->GetSelectedClasses() as $sAlias => $sClass) + { + $aAliases[$sAlias] = true; + } + } + + $aAttributes = array(); + foreach ($aAliases as $sAlias => $bClassDirection) + { + foreach (MetaModel::GetOrderByDefault($this->m_oFilter->GetClass($sAlias)) as $sAttCode => $bAttributeDirection) + { + $bDirection = $bClassDirection ? $bAttributeDirection : !$bAttributeDirection; + $aAttributes[$sAlias.'.'.$sAttCode] = $bDirection; + } + } + $this->SetOrderBy($aAttributes); + } + /** * Returns the 'count' limit for loading the rows from the DB *