N°967 Portal: Browse brick actions are now ordered following a rank tag

This commit is contained in:
Stephen Abello
2019-08-14 12:27:47 +02:00
parent 71cd61dfe4
commit 088f08b315
2 changed files with 33 additions and 0 deletions

View File

@@ -112,6 +112,31 @@ class BrowseBrick extends PortalBrick
$this->iDefaultListLength = static::DEFAULT_LIST_LENGTH;
}
/**
* Compare function to sort actions by their rank attribute
*
* @param array $aAction1
* @param array $aAction2
*
* @return int
*/
public static function CompareActionsByRank($aAction1, $aAction2)
{
$bIsAction1RankSet = array_key_exists('rank', $aAction1);
$bIsAction2RankSet = array_key_exists('rank', $aAction2);
if($bIsAction1RankSet && $bIsAction2RankSet)
{
//If a1 == a2 return 0, if a1 > a2 return 1 else return -1
return ($aAction1['rank'] === $aAction2['rank'] ? 0 : ($aAction1['rank'] > $aAction2['rank'] ? 1 : -1));
}
else
{
//If a1 == a2 == null return 0, if a2 is null and not a1 return 1 else return -1
return ($bIsAction1RankSet === $bIsAction2RankSet ? 0 : ($bIsAction1RankSet ? 1 : -1));
}
}
/**
* Returns the brick levels
*
@@ -548,6 +573,11 @@ class BrowseBrick extends PortalBrick
throw new DOMFormatException('BrowseBrick : '.$sTagName.'/action/opening_target has a wrong value. "'.$aTmpAction['opening_target'].'" given, '.implode('|',
static::$aOpeningTargets).' expected.', null, null, $oActionOpeningTargetNode);
}
$oActionRankNode = $oActionNode->GetOptionalElement('rank');
if ($oActionRankNode !== null)
{
$aTmpAction['rank'] = (int)$oActionRankNode->GetText();
}
// Action rules
/** @var \Combodo\iTop\DesignElement $oRuleNode */
foreach ($oActionNode->GetNodes('./rules/rule') as $oRuleNode)
@@ -571,6 +601,7 @@ class BrowseBrick extends PortalBrick
null, null, $oActionNode);
}
}
uasort($aLevel[$sTagName], "static::CompareActionsByRank");
}
break;

View File

@@ -1165,6 +1165,8 @@
<!-- Optional tag to define if the action should be done in a modal window ("modal"), a new window ("new") or the current window ("self") -->
<!--<opening_target>modal</opening_target>-->
<icon_class>fc fc-new-request fc-1-6x fc-flip-horizontal</icon_class>
<!-- Optional tag to order actions -->
<!--<rank>1</rank>-->
<rules>
<rule id="contact-to-userrequest"/>
<rule id="servicesubcategory-to-userrequest"/>