Просмотр исходного кода

Ticket #4999 - Avatar for account profile.

AntonLV 1 год назад
Родитель
Сommit
0d148e795a

+ 44 - 8
inc/classes/BxDolAccount.php

@@ -15,6 +15,9 @@ class BxDolAccount extends BxDolFactory implements iBxDolSingleton
     protected $_aInfo;
     protected $_oQuery;
 
+    protected $_sImageField;
+    protected $_aImageTranscoders;
+
     /**
      * Constructor
      */
@@ -29,6 +32,14 @@ class BxDolAccount extends BxDolFactory implements iBxDolSingleton
 
         $this->_iAccountID = $iAccountId; // since constructor is protected $iAccountId is always valid
         $this->_oQuery = BxDolAccountQuery::getInstance();
+
+        $this->_sImageField = 'picture';
+        $this->_aImageTranscoders = [
+            'icon' => 'sys_accounts_icon',
+            'thumb' => 'sys_accounts_thumb',
+            'ava' => 'sys_accounts_avatar',
+            'ava_big' => 'sys_accounts_avatar_big'
+        ];
     }
 
     /**
@@ -532,7 +543,6 @@ class BxDolAccount extends BxDolFactory implements iBxDolSingleton
      */
     public function getUnit($iAccountId = false, $aParams = array())
     {
-        
         $sTemplate = 'unit';
         $sTemplateSize = false;
         $aTemplateVars = array();
@@ -550,24 +560,42 @@ class BxDolAccount extends BxDolFactory implements iBxDolSingleton
                     $aTemplateVars = $aParams['template']['vars'];
             }
         }
+
         $sTemplate = 'account_' . $sTemplate . '.html';
         if(empty($sTemplateSize))
             $sTemplateSize = 'thumb';
 
         $sTitle = $this->getDisplayName($iAccountId);
+        $aInfo = $this->getInfo($iAccountId);
 
-        $aTmplVars = array(
+        $sImageUrl = $this->_getImageUrl($sTemplateSize, $aInfo);
+        $bImageUrl = !empty($sImageUrl);
+
+        $aTmplVars = [
             'size' => $sTemplateSize,
-            'color' => implode(', ', BxDolTemplate::getColorCode(($iAccountId ? $iAccountId : $this->_iAccountID), 1.0)),
-            'letter' => mb_strtoupper(mb_substr($sTitle, 0, 1)),
             'content_url' => $this->getUrl($iAccountId),
             'title' => $sTitle,
             'title_attr' => bx_html_attribute($sTitle),
-            'bx_if:show_online' => array(
+            'bx_if:show_thumb_image' => [
+                'condition' => $bImageUrl,
+                'content' => [
+                    'size' => $sTemplateSize,
+                    'url' => $sImageUrl
+                ]
+            ],
+            'bx_if:show_thumb_letter' => [
+                'condition' => !$bImageUrl,
+                'content' => [
+                    'size' => $sTemplateSize,
+                    'color' => implode(', ', BxDolTemplate::getColorCode(($iAccountId ? $iAccountId : $this->_iAccountID), 1.0)),
+                    'letter' => mb_strtoupper(mb_substr($sTitle, 0, 1)),
+                ]
+            ],
+            'bx_if:show_online' => [
                 'condition' => $this->isOnline($iAccountId),
-                'content' => array()
-            )
-        );
+                'content' => []
+            ]
+        ];
 
         if(!empty($aTemplateVars) && is_array($aTemplateVars))
             $aTmplVars = array_merge ($aTmplVars, $aTemplateVars);
@@ -1069,6 +1097,14 @@ class BxDolAccount extends BxDolFactory implements iBxDolSingleton
         return $iCount;
     }
 
+    protected function _getImageUrl($sSize, $aData)
+    {
+        $sImageUrl = '';
+        if(!empty($this->_aImageTranscoders[$sSize]) && ($oImagesTranscoder = BxDolTranscoderImage::getObjectInstance($this->_aImageTranscoders[$sSize])) !== false)
+            $sImageUrl = $oImagesTranscoder->getFileUrl($aData[$this->_sImageField]);
+
+        return $sImageUrl;
+    }
 }
 
 /** @} */

+ 6 - 1
template/account_unit.html

@@ -1,7 +1,12 @@
 <div class="bx-account-unit bx-def-unit flex items-center mb-4 mr-2">
     <div class="bx-def-unit-img bx-def-__size__ bx-def-__size__-size flex-none">
         <a class="text-center" href="__content_url__">
-            <p class="bx-account-unit-thumb bx-def-__size__ bx-def-__size__-size flex items-center justify-center box-border m-0 rounded-full text-white font-bold" style="background-color:rgba(__color__)">__letter__</p>
+            <bx_if:show_thumb_image>
+                <img class="bx-account-unit-thumb bx-def-__size__ bx-def-__size__-size rounded-full box-border" src="__url__" />
+            </bx_if:show_thumb_image>
+            <bx_if:show_thumb_letter>
+                <p class="bx-account-unit-thumb bx-def-__size__ bx-def-__size__-size flex items-center justify-center box-border m-0 rounded-full text-white font-bold" style="background-color:rgba(__color__)">__letter__</p>
+            </bx_if:show_thumb_letter>
         </a>
         <bx_if:show_online>
             <div class="bx-account-unit-online"></div>

+ 6 - 1
template/account_unit_wo_info.html

@@ -1,7 +1,12 @@
 <div class="bx-account-unit-wo-info bx-def-__size__-size text-center">
     <div class="bx-def-unit-img bx-def-__size__-size">
         <a href="__content_url__">
-            <p class="bx-account-unit-thumb bx-def-__size__ bx-def-__size__-size flex items-center justify-center box-border m-0 rounded-full text-white font-bold" style="background-color:rgba(__color__)">__letter__</p>
+            <bx_if:show_thumb_image>
+                <img class="bx-account-unit-thumb bx-def-__size__ bx-def-__size__-size rounded-full box-border" src="__url__" />
+            </bx_if:show_thumb_image>
+            <bx_if:show_thumb_letter>
+                <p class="bx-account-unit-thumb bx-def-__size__ bx-def-__size__-size flex items-center justify-center box-border m-0 rounded-full text-white font-bold" style="background-color:rgba(__color__)">__letter__</p>
+            </bx_if:show_thumb_letter>
         </a>
         <bx_if:show_online>
             <div class="bx-account-unit-online"></div>

+ 6 - 1
template/account_unit_wo_info_links.html

@@ -1,6 +1,11 @@
 <div class="bx-account-unit-wo-info bx-def-__size__-size text-center">
     <div class="bx-def-unit-img bx-def-__size__-size">
-        <p class="bx-account-unit-thumb bx-def-__size__ bx-def-__size__-size flex items-center justify-center box-border m-0 rounded-full text-white font-bold" style="background-color:rgba(__color__)">__letter__</p>
+        <bx_if:show_thumb_image>
+            <img class="bx-account-unit-thumb bx-def-__size__ bx-def-__size__-size rounded-full box-border" src="__url__" />
+        </bx_if:show_thumb_image>
+        <bx_if:show_thumb_letter>
+            <p class="bx-account-unit-thumb bx-def-__size__ bx-def-__size__-size flex items-center justify-center box-border m-0 rounded-full text-white font-bold" style="background-color:rgba(__color__)">__letter__</p>
+        </bx_if:show_thumb_letter>
         <bx_if:show_online>
             <div class="bx-account-unit-online"></div>
         </bx_if:show_online>

+ 8 - 1
template/scripts/BxBaseFormAccount.php

@@ -114,6 +114,7 @@ class BxFormAccountCheckerHelper extends BxDolFormCheckerHelper
  */
 class BxBaseFormAccount extends BxTemplFormView
 {
+    static $FIELD_PICTURE = 'picture';
     static $FIELD_EMAIL = 'email';
     static $FIELD_PASSWORD = 'password';
     static $FIELD_PASSWORD_CHANGED = 'password_changed';
@@ -246,7 +247,13 @@ class BxBaseFormAccount extends BxTemplFormView
 
         $_aValsToAdd = [
             self::$FIELD_CHANGED => $iNow
-        ];        
+        ];
+
+        if(($mixedPicture = $this->getCleanValue(self::$FIELD_PICTURE))) {
+            $iPicture = is_array($mixedPicture) ? array_pop($mixedPicture) : (int)$mixedPicture;
+            if($iPicture)
+                $_aValsToAdd[self::$FIELD_PICTURE] = $iPicture;
+        }
 
         if(($sPwd = $this->getCleanValue(self::$FIELD_PASSWORD))) {
             $oDb->logPassword($val);