Ver Fonte

Prerequisite for #1334. New API: DBObjectSet::SetOrderByClasses. Helper to sort on multicolumn queries (SELECT a, b FROM)

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@4413 a333f486-631f-4898-b8df-5754b55c2be0
romainq há 8 anos atrás
pai
commit
6374dc3de4
1 ficheiros alterados com 30 adições e 2 exclusões
  1. 30 2
      core/dbobjectset.class.php

+ 30 - 2
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)
 	{
@@ -462,6 +462,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
 	 * 
 	 * @return int