ソースを参照

Ticket #5283 - Market: Edit product resets previously uploaded product icon. Point 1.

AntonLV 11 ヶ月 前
親
コミット
b198a4b301

+ 6 - 6
modules/base/general/classes/BxBaseModGeneralFormEntry.php

@@ -626,15 +626,15 @@ class BxBaseModGeneralFormEntry extends BxTemplFormView
         if(isset($CNF['FIELD_CHANGED']) && empty($aValsToAdd[$CNF['FIELD_CHANGED']]) && empty($this->getCleanValue($CNF['FIELD_CHANGED'])))
             $aValsToAdd[$CNF['FIELD_CHANGED']] = time();
 
-        if(CHECK_ACTION_RESULT_ALLOWED === $this->_oModule->checkAllowedSetThumb($iContentId) && isset($CNF['FIELD_THUMB'])) {
-            $aThumb = isset($_POST[$CNF['FIELD_THUMB']]) ? bx_process_input ($_POST[$CNF['FIELD_THUMB']], BX_DATA_INT) : false;
+        if(($sKey = 'FIELD_THUMB') && isset($CNF[$sKey]) && ($aThumb = bx_get($CNF[$sKey])) !== false && $this->_oModule->checkAllowedSetThumb($iContentId) === CHECK_ACTION_RESULT_ALLOWED) {
+            $aThumb = bx_process_input($aThumb, BX_DATA_INT);
 
-            $aValsToAdd[$CNF['FIELD_THUMB']] = 0;
+            $aValsToAdd[$CNF[$sKey]] = 0;
             if(!empty($aThumb)) {
                 if(is_array($aThumb) && ($iFileThumb = array_pop($aThumb)))
-                   $aValsToAdd[$CNF['FIELD_THUMB']] = $iFileThumb;
-               else
-                   $aValsToAdd[$CNF['FIELD_THUMB']] = $aThumb;
+                   $aValsToAdd[$CNF[$sKey]] = $iFileThumb;
+                else
+                   $aValsToAdd[$CNF[$sKey]] = $aThumb;
             }
         }
 

+ 5 - 5
modules/base/text/classes/BxBaseModTextFormEntry.php

@@ -32,7 +32,7 @@ class BxBaseModTextFormEntry extends BxBaseModGeneralFormEntry
                     'Simple' => _t($CNF['T']['form_field_covers_uploader_simple']), 
                     'HTML5' => _t($CNF['T']['form_field_covers_uploader_html5'])
                 );
-                $this->aInputs[$CNF[$sKf]]['images_transcoder'] = $CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW'];
+                $this->aInputs[$CNF[$sKf]]['images_transcoder'] = $CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW'] ?? '';
                 $this->aInputs[$CNF[$sKf]]['storage_private'] = 0;
                 $this->aInputs[$CNF[$sKf]]['multiple'] = false;
                 $this->aInputs[$CNF[$sKf]]['content_id'] = 0;
@@ -45,7 +45,7 @@ class BxBaseModTextFormEntry extends BxBaseModGeneralFormEntry
         if(($sKf = 'FIELD_PHOTO') && ($sKs = 'OBJECT_STORAGE_PHOTOS') && isset($CNF[$sKf], $CNF[$sKs]) && isset($this->aInputs[$CNF[$sKf]])) {
             $this->aInputs[$CNF[$sKf]]['storage_object'] = $CNF[$sKs];
             $this->aInputs[$CNF[$sKf]]['uploaders'] = !empty($this->aInputs[$CNF[$sKf]]['value']) ? unserialize($this->aInputs[$CNF[$sKf]]['value']) : $CNF['OBJECT_UPLOADERS'];
-            $this->aInputs[$CNF[$sKf]]['images_transcoder'] = $CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW_PHOTOS'];
+            $this->aInputs[$CNF[$sKf]]['images_transcoder'] = $CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW_PHOTOS'] ?? '';
             $this->aInputs[$CNF[$sKf]]['storage_private'] = 0;
             $this->aInputs[$CNF[$sKf]]['multiple'] = true;
             $this->aInputs[$CNF[$sKf]]['content_id'] = 0;
@@ -56,7 +56,7 @@ class BxBaseModTextFormEntry extends BxBaseModGeneralFormEntry
         if(($sKf = 'FIELD_SOUND') && ($sKs = 'OBJECT_STORAGE_SOUNDS')  && isset($CNF[$sKf], $CNF[$sKs]) && isset($this->aInputs[$CNF[$sKf]])) {
             $this->aInputs[$CNF[$sKf]]['storage_object'] = $CNF[$sKs];
             $this->aInputs[$CNF[$sKf]]['uploaders'] = !empty($this->aInputs[$CNF[$sKf]]['value']) ? unserialize($this->aInputs[$CNF[$sKf]]['value']) : $CNF['OBJECT_UPLOADERS'];
-            $this->aInputs[$CNF[$sKf]]['images_transcoder'] = $CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW_FILES'];
+            $this->aInputs[$CNF[$sKf]]['images_transcoder'] = $CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW_FILES'] ?? '';
             $this->aInputs[$CNF[$sKf]]['storage_private'] = 0;
             $this->aInputs[$CNF[$sKf]]['multiple'] = true;
             $this->aInputs[$CNF[$sKf]]['content_id'] = 0;
@@ -67,7 +67,7 @@ class BxBaseModTextFormEntry extends BxBaseModGeneralFormEntry
         if(($sKf = 'FIELD_VIDEO') && ($sKs = 'OBJECT_STORAGE_VIDEOS') && isset($CNF[$sKf], $CNF[$sKs]) && isset($this->aInputs[$CNF[$sKf]])) {
             $this->aInputs[$CNF[$sKf]]['storage_object'] = $CNF[$sKs];
             $this->aInputs[$CNF[$sKf]]['uploaders'] = !empty($this->aInputs[$CNF[$sKf]]['value']) ? unserialize($this->aInputs[$CNF[$sKf]]['value']) : $CNF['OBJECT_UPLOADERS'];
-            $this->aInputs[$CNF[$sKf]]['images_transcoder'] = $CNF['OBJECT_VIDEOS_TRANSCODERS']['poster_preview'];
+            $this->aInputs[$CNF[$sKf]]['images_transcoder'] = $CNF['OBJECT_VIDEOS_TRANSCODERS']['poster_preview'] ?? '';
             $this->aInputs[$CNF[$sKf]]['storage_private'] = 0;
             $this->aInputs[$CNF[$sKf]]['multiple'] = true;
             $this->aInputs[$CNF[$sKf]]['content_id'] = 0;
@@ -78,7 +78,7 @@ class BxBaseModTextFormEntry extends BxBaseModGeneralFormEntry
         if(($sKf = 'FIELD_FILE') && ($sKs = 'OBJECT_STORAGE_FILES') && isset($CNF[$sKf], $CNF[$sKs]) && isset($this->aInputs[$CNF[$sKf]])) {
             $this->aInputs[$CNF[$sKf]]['storage_object'] = $CNF[$sKs];
             $this->aInputs[$CNF[$sKf]]['uploaders'] = !empty($this->aInputs[$CNF[$sKf]]['value']) ? unserialize($this->aInputs[$CNF[$sKf]]['value']) : $CNF['OBJECT_UPLOADERS'];
-            $this->aInputs[$CNF[$sKf]]['images_transcoder'] = $CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW_FILES'];
+            $this->aInputs[$CNF[$sKf]]['images_transcoder'] = $CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW_FILES'] ?? '';
             $this->aInputs[$CNF[$sKf]]['storage_private'] = 0;
             $this->aInputs[$CNF[$sKf]]['multiple'] = true;
             $this->aInputs[$CNF[$sKf]]['content_id'] = 0;

+ 34 - 32
modules/boonex/market/classes/BxMarketFormEntry.php

@@ -197,14 +197,15 @@ class BxMarketFormEntry extends BxBaseModTextFormEntry
             }
         }
 
-        //TODO: Continue from here. Do the same for Thumb.
-        if(($aCover = bx_get($CNF['FIELD_COVER'])) !== false && $this->_oModule->checkAllowedSetCover() === CHECK_ACTION_RESULT_ALLOWED) {
-            $aCover = bx_process_input($aCover, BX_DATA_INT);
-
-            $aValsToAdd[$CNF['FIELD_COVER']] = 0;
-            if(!empty($aCover) && is_array($aCover) && ($iFileCover = array_pop($aCover)))
-                $aValsToAdd[$CNF['FIELD_COVER']] = $iFileCover;
-        }
+        $bSetImage = $this->_oModule->checkAllowedSetCover() === CHECK_ACTION_RESULT_ALLOWED; //--- Allow to set both Thumb and Cover.
+        foreach(['FIELD_THUMB', 'FIELD_COVER'] as $sKey)
+            if($bSetImage && ($aImage = bx_get($CNF[$sKey])) !== false) {
+                $aImage = bx_process_input($aImage, BX_DATA_INT);
+
+                $aValsToAdd[$CNF[$sKey]] = 0;
+                if(!empty($aImage) && is_array($aImage) && ($iFileImage = array_pop($aImage)))
+                    $aValsToAdd[$CNF[$sKey]] = $iFileImage;
+            }
 
         $aPackage = bx_process_input(bx_get($CNF['FIELD_PACKAGE']), BX_DATA_INT);
         $aValsToAdd[$CNF['FIELD_PACKAGE']] = 0;
@@ -247,31 +248,31 @@ class BxMarketFormEntry extends BxBaseModTextFormEntry
         $sStorage = $oStorage->getObject();
         switch($sStorage) {
         	case $this->_oModule->_oConfig->CNF['OBJECT_STORAGE']:
-        		$this->_oModule->_oDb->associatePhotoWithContent($iContentId, $iFileId, $this->getCleanValue('title-' . $iFileId));
-        		break;
+                    $this->_oModule->_oDb->associatePhotoWithContent($iContentId, $iFileId, $this->getCleanValue('title-' . $iFileId));
+                    break;
 
         	case $this->_oModule->_oConfig->CNF['OBJECT_STORAGE_FILES']:
-        		$aParams = array(
-        			'type' => $this->getCleanValue('type-' . $iFileId)        			
-        		);
-
-        		switch ($aParams['type']) {
-        			case BX_MARKET_FILE_TYPE_VERSION:
-        				$aParams = array_merge($aParams, array(
-        					'version' => $this->getCleanValue('version-' . $iFileId),
-        				));
-        				break;
-        				
-        			case BX_MARKET_FILE_TYPE_UPDATE:
-        				$aParams = array_merge($aParams, array(
-        					'version' => $this->getCleanValue('version-from-' . $iFileId),
-        					'version_to' => $this->getCleanValue('version-to-' . $iFileId),
-        				));
-        				break;
-        		}
-
-        		$this->_oModule->_oDb->associateFileWithContent($iContentId, $iFileId, $aParams);
-        		break;
+                    $aParams = array(
+                        'type' => $this->getCleanValue('type-' . $iFileId)        			
+                    );
+
+                    switch ($aParams['type']) {
+                        case BX_MARKET_FILE_TYPE_VERSION:
+                            $aParams = array_merge($aParams, array(
+                                'version' => $this->getCleanValue('version-' . $iFileId),
+                            ));
+                            break;
+
+                        case BX_MARKET_FILE_TYPE_UPDATE:
+                            $aParams = array_merge($aParams, array(
+                                'version' => $this->getCleanValue('version-from-' . $iFileId),
+                                'version_to' => $this->getCleanValue('version-to-' . $iFileId),
+                            ));
+                            break;
+                    }
+
+                    $this->_oModule->_oDb->associateFileWithContent($iContentId, $iFileId, $aParams);
+                    break;
         }
     }
 
@@ -285,7 +286,8 @@ class BxMarketFormEntry extends BxBaseModTextFormEntry
             $aResult['bx_if:set_thumb']['condition'] = $this->_bPhotoGhostCheckboxes && $aResult['bx_if:set_thumb']['condition'];
 
         return array_merge($aResult, [
-            'cover_id' => isset($aContentInfo[$CNF['FIELD_COVER']]) ? $aContentInfo[$CNF['FIELD_COVER']] : 0,
+            'thumb_id' => $aContentInfo[$CNF['FIELD_THUMB']] ?? 0,
+            'cover_id' => $aContentInfo[$CNF['FIELD_COVER']] ?? 0,
             'bx_if:set_cover' => [
                 'condition' => $this->_bPhotoGhostCheckboxes && $this->_oModule->checkAllowedSetCover() === CHECK_ACTION_RESULT_ALLOWED,
                 'content' => [

+ 1 - 1
modules/boonex/market/classes/BxMarketTemplate.php

@@ -64,7 +64,7 @@ class BxMarketTemplate extends BxBaseModTextTemplate
         ];
 
         //--- Process Cover
-        $bIsAllowEditCover = $oModule->checkAllowedEdit($aData) === CHECK_ACTION_RESULT_ALLOWED;
+        $bIsAllowEditCover = $oModule->checkAllowedEdit($aData) === CHECK_ACTION_RESULT_ALLOWED && $oModule->checkAllowedSetCover() === CHECK_ACTION_RESULT_ALLOWED;
         $bShowImage = $aVars['bx_if:show_image']['condition'];
 
         $aVars['bx_if:show_entry_cover'] = [