mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-19 00:28:47 +02:00
#520 Capability to define a default sort order (PHP/XML)
SVN:trunk[1900]
This commit is contained in:
@@ -494,6 +494,11 @@ 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)
|
||||
{
|
||||
self::_check_subclass($sClass);
|
||||
return array_key_exists("order_by_default", self::$m_aClassParams[$sClass]) ? self::$m_aClassParams[$sClass]["order_by_default"]: array();
|
||||
}
|
||||
final static public function GetAttributeOrigin($sClass, $sAttCode)
|
||||
{
|
||||
self::_check_subclass($sClass);
|
||||
@@ -2009,6 +2014,12 @@ 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
|
||||
//
|
||||
@@ -2043,7 +2054,7 @@ abstract class MetaModel
|
||||
$aAttToLoad[$sFirstClassAlias][$sFieldAlias] = MetaModel::GetAttributeDef($oFilter->GetFirstJoinedClass(), $sFieldAlias);
|
||||
}
|
||||
}
|
||||
// By default, force the name attribute to be the ordering key
|
||||
// At least, force the name attribute to be the ordering key
|
||||
//
|
||||
if (empty($aOrderSpec))
|
||||
{
|
||||
|
||||
@@ -122,15 +122,6 @@ try
|
||||
$iSortIndex++;
|
||||
}
|
||||
|
||||
if (count($aOrderBy) == 0)
|
||||
{
|
||||
$aOrderBy['friendlyname'] = true; // By default, sort by name
|
||||
}
|
||||
else
|
||||
{
|
||||
// $oPage->add("</p>ICI: OrderBy already set to: <pre>'".print_r($aOrderBy, true)."'</pre></p>\n");
|
||||
}
|
||||
|
||||
// Load only the requested columns
|
||||
$oSet = new DBObjectSet($oFilter, $aOrderBy, $aExtraParams, null, $iEnd-$iStart, $iStart);
|
||||
$sClassAlias = $oSet->GetFilter()->GetClassAlias();
|
||||
|
||||
@@ -223,12 +223,15 @@ EOF;
|
||||
protected function GetUniqueElement($oDOMNode, $sTagName, $bMustExist = true)
|
||||
{
|
||||
$oNode = null;
|
||||
foreach($oDOMNode->childNodes as $oChildNode)
|
||||
if ($oDOMNode->hasChildNodes())
|
||||
{
|
||||
if ($oChildNode->nodeName == $sTagName)
|
||||
foreach($oDOMNode->childNodes as $oChildNode)
|
||||
{
|
||||
$oNode = $oChildNode;
|
||||
break;
|
||||
if ($oChildNode->nodeName == $sTagName)
|
||||
{
|
||||
$oNode = $oChildNode;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($bMustExist && is_null($oNode))
|
||||
@@ -255,11 +258,14 @@ EOF;
|
||||
protected function GetNodeText($oNode)
|
||||
{
|
||||
$sText = '';
|
||||
foreach($oNode->childNodes as $oChildNode)
|
||||
if ($oNode->hasChildNodes())
|
||||
{
|
||||
if ($oChildNode instanceof DOMCharacterData) // Base class of DOMText and DOMCdataSection
|
||||
foreach($oNode->childNodes as $oChildNode)
|
||||
{
|
||||
$sText .= $oChildNode->wholeText;
|
||||
if ($oChildNode instanceof DOMCharacterData) // Base class of DOMText and DOMCdataSection
|
||||
{
|
||||
$sText .= $oChildNode->wholeText;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $sText;
|
||||
@@ -281,17 +287,20 @@ EOF;
|
||||
if ($oItems)
|
||||
{
|
||||
$res = array();
|
||||
foreach($oItems->childNodes as $oItem)
|
||||
if ($oItems->hasChildNodes())
|
||||
{
|
||||
// When an attribute is msising
|
||||
if ($oItem->hasAttribute('key'))
|
||||
foreach($oItems->childNodes as $oItem)
|
||||
{
|
||||
$key = $oItem->getAttribute('key');
|
||||
$res[$key] = $this->GetNodeAsArrayOfItems($oItem);
|
||||
}
|
||||
else
|
||||
{
|
||||
$res[] = $this->GetNodeAsArrayOfItems($oItem);
|
||||
// When an attribute is msising
|
||||
if ($oItem->hasAttributes() && $oItem->hasAttribute('key'))
|
||||
{
|
||||
$key = $oItem->getAttribute('key');
|
||||
$res[$key] = $this->GetNodeAsArrayOfItems($oItem);
|
||||
}
|
||||
else
|
||||
{
|
||||
$res[] = $this->GetNodeAsArrayOfItems($oItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -407,6 +416,23 @@ EOF;
|
||||
$aClassParams['icon'] = "utils::GetAbsoluteUrlModulesRoot().'$sIcon'";
|
||||
}
|
||||
|
||||
$oOrder = $this->GetOptionalElement($oProperties, 'order');
|
||||
if ($oOrder)
|
||||
{
|
||||
$oColumnsNode = $this->GetUniqueElement($oOrder, 'columns');
|
||||
$oColumns = $oColumnsNode->getElementsByTagName('column');
|
||||
$aSortColumns = array();
|
||||
foreach($oColumns as $oColumn)
|
||||
{
|
||||
$aSortColumns[] = "'".$oColumn->getAttribute('name')."' => ".(($oColumn->getAttribute('ascending') == 'true') ? 'true' : 'false');
|
||||
}
|
||||
if (count($aSortColumns) > 0)
|
||||
{
|
||||
$aClassParams['order_by_default'] = "array(".implode(", ", $aSortColumns).")";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Finalize class params declaration
|
||||
//
|
||||
$aClassParamsPHP = array();
|
||||
|
||||
Reference in New Issue
Block a user