From b782f2f9b26e6fe19d4a3b6e3c7896851f3815be Mon Sep 17 00:00:00 2001 From: Molkobain Date: Thu, 25 Mar 2021 17:09:05 +0100 Subject: [PATCH] Move utils::GetUserPictureAbsUrl() with other user methods --- core/userrights.class.inc.php | 70 ++++++++++++++++------------------- 1 file changed, 32 insertions(+), 38 deletions(-) diff --git a/core/userrights.class.inc.php b/core/userrights.class.inc.php index 0be085ed90..38297e998b 100644 --- a/core/userrights.class.inc.php +++ b/core/userrights.class.inc.php @@ -1057,33 +1057,6 @@ class UserRights } } - /** - * @param string $sLogin Login of the user from which we return the contact ID - * - * @return string - * @throws \Exception - */ - public static function GetContactId($sLogin = '') - { - if (empty($sLogin)) - { - $oUser = self::$m_oUser; - } - else - { - $oUser = self::FindUser($sLogin); - } - if (is_null($oUser)) - { - return ''; - } - if (!MetaModel::IsValidAttCode(get_class($oUser), static::DEFAULT_USER_CONTACT_ID_ATTCODE)) - { - return ''; - } - return $oUser->Get(static::DEFAULT_USER_CONTACT_ID_ATTCODE); - } - /** * @param string $sLogin Login of the user from which we return the picture URL * @param bool $bAllowDefaultPicture Set to false if you want it to return null instead of the default picture URL when the contact has no picture defined. This can be useful when we want to display something else than the default picture (eg. initials) @@ -1112,24 +1085,18 @@ class UserRights $sContactClass = get_class($oContact); // Check that Contact object still exists and that Contact class has a picture attribute - if(!is_null($oContact) && MetaModel::IsValidAttCode($sContactClass, static::DEFAULT_CONTACT_PICTURE_ATTCODE)) - { + if (!is_null($oContact) && MetaModel::IsValidAttCode($sContactClass, static::DEFAULT_CONTACT_PICTURE_ATTCODE)) { /** @var \ormDocument $oPicture */ $oPicture = $oContact->Get(static::DEFAULT_CONTACT_PICTURE_ATTCODE); - if($oPicture->IsEmpty()) - { - if($bAllowDefaultPicture === true) - { + if ($oPicture->IsEmpty()) { + if ($bAllowDefaultPicture === true) { /** @var \AttributeImage $oAttDef */ $oAttDef = MetaModel::GetAttributeDef($sContactClass, static::DEFAULT_CONTACT_PICTURE_ATTCODE); $sPictureUrl = $oAttDef->Get('default_image'); - } - else - { + } else { $sPictureUrl = null; } - } - else { + } else { if (ContextTag::Check(ContextTag::TAG_PORTAL)) { $sSignature = $oPicture->GetSignature(); $sPictureUrl = utils::GetAbsoluteUrlAppRoot().'pages/exec.php/object/document/display/'.$sContactClass.'/'.$oContact->GetKey().'/'.static::DEFAULT_CONTACT_PICTURE_ATTCODE.'?cache=86400&s='.$sSignature.'&exec_module=itop-portal-base&exec_page=index.php&portal_id='.PORTAL_ID; @@ -1149,6 +1116,33 @@ class UserRights return $sPictureUrl; } + /** + * @param string $sLogin Login of the user from which we return the contact ID + * + * @return string + * @throws \Exception + */ + public static function GetContactId($sLogin = '') + { + if (empty($sLogin)) + { + $oUser = self::$m_oUser; + } + else + { + $oUser = self::FindUser($sLogin); + } + if (is_null($oUser)) + { + return ''; + } + if (!MetaModel::IsValidAttCode(get_class($oUser), static::DEFAULT_USER_CONTACT_ID_ATTCODE)) + { + return ''; + } + return $oUser->Get(static::DEFAULT_USER_CONTACT_ID_ATTCODE); + } + /** * Return the organization name of the current user's contact. * If the user has no contact linked, null is returned.