Przeglądaj źródła

Ticket #4268 - Profiles: Change picture/cover actions from profile cover area should fire corresponding alerts.

AntonLV 3 lat temu
rodzic
commit
61dfe1f326

+ 50 - 26
modules/base/general/classes/BxBaseModGeneralModule.php

@@ -72,38 +72,18 @@ class BxBaseModGeneralModule extends BxDolModule
         return true;        
     }
 
-    
     public function actionUpdateImage($sFiledName, $iContentId, $sValue)
     {
-        $CNF = &$this->_oConfig->CNF;
-        $aData = $this->_oDb->getContentInfoById($iContentId);
-        if ($this->checkAllowedEdit($aData) === CHECK_ACTION_RESULT_ALLOWED){
-        
-            $this->_oDb->updateEntriesBy([$sFiledName => $sValue], [$CNF['FIELD_ID'] => $iContentId]);
-            //TODO add transcoder settings
-            $oImgStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE']);
-            $sImageUrl = $oImgStorage->getFileUrlById($sValue);
-            
-            $this->actionUpdateImagePosition($iContentId, $sFiledName, '', '');
-            
-            echo $sImageUrl;
-        }
-        
+        $mixedResult = $this->serviceUpdateImage($sFiledName, $iContentId, $sValue);
+        if($mixedResult !== false)
+            echo $mixedResult;
     }
-    
+
     public function actionUpdateImagePosition($iContentId, $sFiledName, $sH, $sV)
     {
-        $CNF = &$this->_oConfig->CNF;
-        $sFieldNamePos = 'FIELD_' . strtoupper($sFiledName) . '_POSITION';
-        if (isset($CNF[$sFieldNamePos])){
-            $sValue = '';
-            $CNF = &$this->_oConfig->CNF;
-            if ($sH != '' || $sV != '')
-                $sValue = json_encode(['x' => $sH, 'y' => $sV]);
-            $this->_oDb->updateEntriesBy([$CNF[$sFieldNamePos] => $sValue], [$CNF['FIELD_ID'] => $iContentId]);
-        }
+        $this->serviceUpdateImagePosition($iContentId, $sFiledName, $sH, $sV);
     }
-    
+
     public function actionApprove()
     {
         $CNF = &$this->_oConfig->CNF;
@@ -657,6 +637,48 @@ class BxBaseModGeneralModule extends BxDolModule
         return $aTextFields;
     }
 
+    public function serviceUpdateImage($sFiledName, $iContentId, $sValue)
+    {
+        $CNF = &$this->_oConfig->CNF;
+
+        $aData = $this->_oDb->getContentInfoById($iContentId);
+        if(empty($aData) || !is_array($aData))
+            return false;
+
+        if($this->checkAllowedEdit($aData) !== CHECK_ACTION_RESULT_ALLOWED)
+            return false;
+
+        //TODO add transcoder settings
+        $oImgStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE']);
+        if(!$oImgStorage)
+            return false;
+
+        $this->_oDb->updateEntriesBy([$sFiledName => $sValue], [$CNF['FIELD_ID'] => $iContentId]);
+
+        $this->serviceUpdateImagePosition($iContentId, $sFiledName, '', '');
+
+        $this->onUpdateImage($iContentId, $sFiledName, $sValue);
+
+        return $oImgStorage->getFileUrlById($sValue);
+    }
+
+    public function serviceUpdateImagePosition($iContentId, $sFiledName, $sH, $sV)
+    {
+        $CNF = &$this->_oConfig->CNF;
+
+        $sFieldNamePos = 'FIELD_' . strtoupper($sFiledName) . '_POSITION';
+        if(!isset($CNF[$sFieldNamePos]))
+            return false;
+
+        $sValue = '';
+        if($sH != '' || $sV != '')
+            $sValue = json_encode(['x' => $sH, 'y' => $sV]);
+
+        $this->_oDb->updateEntriesBy([$CNF[$sFieldNamePos] => $sValue], [$CNF['FIELD_ID'] => $iContentId]);
+
+        return true;
+    }
+
     public function serviceManageTools($sType = 'common')
     {
         if(!isLogged())
@@ -2847,6 +2869,8 @@ class BxBaseModGeneralModule extends BxDolModule
         $this->onPublished($mixedContent[$CNF['FIELD_ID']]);
     }
 
+    public function onUpdateImage($iContentId, $sFiledName, $sFiledValue, $iProfileId = 0) {}
+
     public function alertAfterAdd($aContentInfo) {}
     
     public function alertAfterEdit($aContentInfo) {}

+ 8 - 20
modules/base/profile/classes/BxBaseModProfileFormEntry.php

@@ -218,33 +218,21 @@ class BxBaseModProfileFormEntry extends BxBaseModGeneralFormEntry
         if(!$bResult) 
             return;
 
-        $CNF = &$this->_oModule->_oConfig->CNF;
-
-        $aField2Method = [
-            $CNF['FIELD_PICTURE'] => 'picture',
-            $CNF['FIELD_COVER'] => 'cover',
-        ];
-
-        if(!empty($aField2Method[$sPictureField]))
-            bx_alert($this->_oModule->getName(), 'profile_' . $aField2Method[$sPictureField] . '_changed', $iFileId, $iProfileId, [
-                'object_author_id' => $iProfileId, 
-                'content' => $iContentId, 
-                'field' => $sPictureField
-            ]);
+        $this->_oModule->onUpdateImage($iContentId, $sPictureField, $iFileId, $iProfileId);
     }
 
     protected function _getProfilePhotoGhostTmplVars($sField, $aContentInfo = array())
     {
     	$CNF = &$this->_oModule->_oConfig->CNF;
 
-    	return array (
-			'name' => $this->aInputs[$sField]['name'],
+    	return [
+            'name' => $this->aInputs[$sField]['name'],
             'content_id' => $this->aInputs[$sField]['content_id'],
-			'bx_if:set_thumb' => array (
-				'condition' => false,
-				'content' => array (),
-			),
-		);
+            'bx_if:set_thumb' => [
+                'condition' => false,
+                'content' => [],
+            ]
+        ];
     }
 
     protected function _isAdmin ($iContentId = 0)

+ 22 - 0
modules/base/profile/classes/BxBaseModProfileModule.php

@@ -1864,6 +1864,28 @@ class BxBaseModProfileModule extends BxBaseModGeneralModule implements iBxDolCon
     }
 
     // ====== COMMON METHODS
+    public function onUpdateImage($iContentId, $sFiledName, $sFiledValue, $iProfileId = 0)
+    {
+        $CNF = &$this->_oConfig->CNF;
+
+        $sModule = $this->getName();
+
+        if(!$iProfileId && ($oProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $sModule)) !== false)
+            $iProfileId = $oProfile->id();
+
+        $aField2Method = [
+            $CNF['FIELD_PICTURE'] => 'picture',
+            $CNF['FIELD_COVER'] => 'cover',
+        ];
+
+        if(!empty($aField2Method[$sFiledName]))
+            bx_alert($sModule, 'profile_' . $aField2Method[$sFiledName] . '_changed', $sFiledValue, $iProfileId, [
+                'object_author_id' => $iProfileId, 
+                'content' => $iContentId, 
+                'field' => $sFiledName
+            ]);
+    }
+
     protected function _alertParams($aContentInfo)
     {
         $aParams = parent::_alertParams($aContentInfo);