mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-13 07:24:13 +01:00
N°4913 - Avoid object initials to overflow in medallions
This commit is contained in:
@@ -251,7 +251,7 @@ class UIExtKeyWidget
|
||||
$aOption['picture_url'] = $oImage->GetDisplayURL($sClassAllowed, $oObj->GetKey(), $sObjectImageAttCode);
|
||||
$aOption['initials'] = '';
|
||||
} else {
|
||||
$aOption['initials'] = utils::ToAcronym($oObj->Get('friendlyname'));
|
||||
$aOption['initials'] = utils::FormatInitialsForMedallion(utils::ToAcronym($oObj->Get('friendlyname')));
|
||||
}
|
||||
}
|
||||
array_push($aOptions, $aOption);
|
||||
@@ -829,7 +829,7 @@ JS
|
||||
}
|
||||
|
||||
if (array_key_exists('initials', $aValue)) {
|
||||
$aElt['initials'] = $aValue['initials'];
|
||||
$aElt['initials'] = utils::FormatInitialsForMedallion($aValue['initials']);
|
||||
if (array_key_exists('picture_url', $aValue)) {
|
||||
$aElt['picture_url'] = $aValue['picture_url'];
|
||||
}
|
||||
|
||||
@@ -3050,6 +3050,20 @@ HTML;
|
||||
return $aMentionedObjects;
|
||||
}
|
||||
|
||||
/**
|
||||
* Note: This method is not ideal, but other solutions seemed even less ideal:
|
||||
* * Add a "$sMaxLength" param. to utils::ToAcronym(): Does not work for every use cases (see corresponding ticket) as in some parts utils::ToAcronym isn't necessarly meant to be used in a medallion.
|
||||
*
|
||||
* @param string $sInitials
|
||||
*
|
||||
* @return string Truncates $sInitials so it can fit in medallions
|
||||
* @since 3.0.1 N°4913
|
||||
*/
|
||||
public static function FormatInitialsForMedallion(string $sInitials): string
|
||||
{
|
||||
return mb_substr($sInitials, 0, 3);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $sUrl
|
||||
* @param string $sParamName
|
||||
|
||||
@@ -2539,7 +2539,7 @@ EOF
|
||||
} else {
|
||||
// If no image found, fallback on initials
|
||||
$aMatch['picture_style'] = '';
|
||||
$aMatch['initials'] = utils::ToAcronym($oObject->Get('friendlyname'));
|
||||
$aMatch['initials'] = utils::FormatInitialsForMedallion(utils::ToAcronym($oObject->Get('friendlyname')));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -648,7 +648,7 @@ HTML
|
||||
// Open medallion from profile picture or first name letter
|
||||
$bEntryHasMedallionPicture = (empty($aContactPicturesCache[$iEntryUserId]) === false);
|
||||
$sEntryMedallionStyle = $bEntryHasMedallionPicture ? ' background-image: url(\''.$aContactPicturesCache[$iEntryUserId].'\');' : '';
|
||||
$sEntryMedallionContent = $bEntryHasMedallionPicture ? '' : UserRights::GetUserInitials($sEntryUserLogin);
|
||||
$sEntryMedallionContent = $bEntryHasMedallionPicture ? '' : utils::FormatInitialsForMedallion(UserRights::GetUserInitials($sEntryUserLogin));
|
||||
// - Entry tooltip
|
||||
$sEntryMedallionTooltip = utils::HtmlEntities($sEntryUserLogin);
|
||||
$sEntryMedallionTooltipPlacement = ($iEntryUserId === $iCurrentUserId) ? 'left' : 'right';
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
{% if oUIBlock.GetAuthorPictureAbsUrl() is not empty %}
|
||||
<img class="ibo-activity-entry--author-picture" src="{{ oUIBlock.GetAuthorPictureAbsUrl() }}" alt="{{ oUIBlock.GetAuthorInitials() }}">
|
||||
{% else %}
|
||||
<div class="ibo-activity-entry--author-initials">{{ oUIBlock.GetAuthorInitials() }}</div>
|
||||
<div class="ibo-activity-entry--author-initials">{{ oUIBlock.GetAuthorInitials()|slice(0, 3) }}</div>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
</div>
|
||||
|
||||
@@ -554,6 +554,40 @@ class UtilsTest extends \Combodo\iTop\Test\UnitTest\ItopTestCase
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider FormatInitialsForMedallionProvider
|
||||
* @covers utils::FormatInitialsForMedallion
|
||||
*
|
||||
* @param string $sInput
|
||||
* @param string $sExpected
|
||||
*/
|
||||
public function testFormatInitialsForMedallion(string $sInput, string $sExpected)
|
||||
{
|
||||
$sTested = utils::FormatInitialsForMedallion($sInput);
|
||||
$this->assertEquals($sExpected, $sTested);
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 3.0.1
|
||||
*/
|
||||
public function FormatInitialsForMedallionProvider()
|
||||
{
|
||||
return [
|
||||
'All letters kept (2)' => [
|
||||
'AB',
|
||||
'AB',
|
||||
],
|
||||
'All letters kept (3)' => [
|
||||
'ABC',
|
||||
'ABC',
|
||||
],
|
||||
'Only 3 first letters kept (4)' => [
|
||||
'ABCD',
|
||||
'ABC',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sExpressionToConvert
|
||||
* @param int $iExpectedConvertedValue
|
||||
|
||||
Reference in New Issue
Block a user