N°3545 - Activity panel: Change caselogs order so it's defined by the details zlist

This commit is contained in:
Molkobain
2021-02-10 18:14:36 +01:00
parent 3be360dfb9
commit e6c0333915
3 changed files with 39 additions and 17 deletions

View File

@@ -849,6 +849,12 @@ EOF
$aDetails = [];
foreach ($aFields as $sAttCode) {
$oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode);
// Skip case logs as they will be hadnled by the activty panel
if ($oAttDef instanceof AttributeCaseLog) {
continue;
}
$sAttDefClass = get_class($oAttDef);
$sAttLabel = MetaModel::GetLabel($sClass, $sAttCode);

View File

@@ -1334,26 +1334,36 @@ abstract class MetaModel
*
* @param string $sClass
* @param string[] $aDesiredAttTypes Array of AttributeDefinition classes to filter the list on
* @param string|null $sListCode If provided, attributes will be limited to those in this zlist
*
* @return array
* @throws \CoreException
*/
final public static function GetAttributesList($sClass, $aDesiredAttTypes = [])
final public static function GetAttributesList(string $sClass, array $aDesiredAttTypes = [], ?string $sListCode = null)
{
self::_check_subclass($sClass);
if(empty($aDesiredAttTypes))
{
return array_keys(self::$m_aAttribDefs[$sClass]);
$aAttributesToCheck = [];
if (!is_null($sListCode)) {
$aAttCodes = self::FlattenZList(self::GetZListItems($sClass, $sListCode));
foreach ($aAttCodes as $sAttCode) {
// Important: As $aAttributesToCheck will only be used to check the type of the attribute definition, we considered is was ok to mix strings and objects to lower the memory print.
$aAttributesToCheck[$sAttCode] = get_class(self::$m_aAttribDefs[$sClass][$sAttCode]);
}
} else {
$aAttributesToCheck = self::$m_aAttribDefs[$sClass];
}
if (empty($aDesiredAttTypes)) {
return array_keys($aAttributesToCheck);
}
$aMatchingAttCodes = [];
foreach(self::$m_aAttribDefs[$sClass] as $sAttCode => $oAttDef)
{
foreach($aDesiredAttTypes as $sDesiredAttType)
{
if(is_a($oAttDef, $sDesiredAttType))
{
/** @var string|AttributeDefinition $mAttDef See how it's built */
foreach ($aAttributesToCheck as $sAttCode => $mAttDef) {
foreach ($aDesiredAttTypes as $sDesiredAttType) {
// Important: Use of a method allowing either an object or a class as a parameter is important
if (is_a($mAttDef, $sDesiredAttType, true)) {
$aMatchingAttCodes[] = $sAttCode;
}
}
@@ -1633,18 +1643,20 @@ abstract class MetaModel
* Return an array of attribute codes for the caselogs attributes of $sClass
*
* @param string $sClass
* @param string|null $sListCode If provided, will only return attributes from ths zlist
*
* @return array
* @throws \CoreException
* @since 3.0.0
*/
final public static function GetCaseLogs(string $sClass)
final public static function GetCaseLogs(string $sClass, ?string $sListCode = null)
{
if (!isset(static::$m_aCaseLogsAttributesCache[$sClass])) {
static::$m_aCaseLogsAttributesCache[$sClass] = self::GetAttributesList($sClass, ['AttributeCaseLog']);
$sScopeKey = empty($sListCode) ? 'all' : 'zlist:'.$sListCode;
if (!isset(static::$m_aCaseLogsAttributesCache[$sClass][$sScopeKey])) {
static::$m_aCaseLogsAttributesCache[$sClass][$sScopeKey] = self::GetAttributesList($sClass, ['AttributeCaseLog'], $sListCode);
}
return static::$m_aCaseLogsAttributesCache[$sClass];
return static::$m_aCaseLogsAttributesCache[$sClass][$sScopeKey];
}
/** @var array */

View File

@@ -122,9 +122,13 @@ class ActivityPanel extends UIBlock
$this->InitializeCaseLogTabs();
$this->InitializeCaseLogTabsEntryForms();
$aCaseLogAttCodes = MetaModel::GetCaseLogs($sObjectClass);
foreach($aCaseLogAttCodes as $sCaseLogAttCode)
{
// Get only case logs from the "details" zlist, but if none (2.7 and older) show them all
$aCaseLogAttCodes = MetaModel::GetCaseLogs($sObjectClass, 'details');
if (empty($aCaseLogAttCodes)) {
$aCaseLogAttCodes = MetaModel::GetCaseLogs($sObjectClass);
}
foreach ($aCaseLogAttCodes as $sCaseLogAttCode) {
$this->AddCaseLogTab($sCaseLogAttCode);
}