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

#5273 Get rid of duplicates in code. Stage 2.

Aleksandr T 9 месяцев назад
Родитель
Сommit
28f3c47005

+ 51 - 0
modules/base/text/classes/BxBaseModTextFormEntry.php

@@ -319,6 +319,57 @@ class BxBaseModTextFormEntry extends BxBaseModGeneralFormEntry
             'editor_id' => isset($CNF['FIELD_TEXT_ID']) ? $CNF['FIELD_TEXT_ID'] : ''
     	];
     }
+
+    protected function _processFilesInAlbumsAndStories ($sFieldFile, $iContentId = 0, $isAssociateWithContent = false)
+    {
+        $CNF = &$this->_oModule->_oConfig->CNF;
+
+        if($isAssociateWithContent)
+            return parent::processFiles ($sFieldFile, $iContentId, $isAssociateWithContent);
+
+        $aMediasOld = $this->_oModule->_oDb->getMediaListByContentId($iContentId);                
+
+        if(!parent::processFiles ($sFieldFile, $iContentId, $isAssociateWithContent)) 
+            return false;
+
+        $aMediasNew = $this->_oModule->_oDb->getMediaListByContentId($iContentId);
+
+        $aIdsOld = array_column($aMediasOld, 'id');
+        $aIdsNew = array_column($aMediasNew, 'id');
+        $aIdsAdded = array_diff($aIdsNew, $aIdsOld);
+
+        if(!empty($aIdsAdded)) {
+            $aContentInfo = $this->_oModule->_oDb->getContentInfoById($iContentId);
+            $iProfileId = $this->getContentOwnerProfileId($iContentId);
+
+             /**
+             * @hooks
+             * @hookdef hook-bx_base_text-medias_added 'bx_base_text', 'medias_added' - hook on new medias added in story (album)
+             * - $unit_name - equals `bx_base_text` (bx_stories or bx_albums)
+             * - $action - equals `medias_added` 
+             * - $object_id - album id or story id
+             * - $sender_id - author's profile_id
+             * - $extra_params - array of additional params with the following array keys:
+             *      - `object_author_id` - [int] confirmation type can be none/phone/email/email_and_phone/email_or_phone
+             *      - `subobjects_ids` - [array] array of ids for added media's
+             *      - `medias_added` - [array] array of ids for added media's
+             *      - `privacy_view` - [string] privacy view value for current story (album)
+             *      - `cf` - [int] content filter id
+             * @hook @ref hook-bx_base_text-medias_added
+             */
+            bx_alert($this->_oModule->getName(), 'medias_added', $iContentId, $iProfileId, [
+                'object_author_id' => $iProfileId,
+
+                'subobjects_ids' => $aIdsAdded,
+                'medias_added' => $aIdsAdded,
+
+                'privacy_view' => $aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']],
+                'cf' => $aContentInfo[$CNF['FIELD_CF']]
+            ]);
+        }
+
+        return true;
+    }
 }
 
 /** @} */

+ 1 - 47
modules/boonex/albums/classes/BxAlbumsFormEntry.php

@@ -27,53 +27,7 @@ class BxAlbumsFormEntry extends BxBaseModTextFormEntry
 
     public function processFiles ($sFieldFile, $iContentId = 0, $isAssociateWithContent = false)
     {
-        $CNF = &$this->_oModule->_oConfig->CNF;
-
-        if($isAssociateWithContent)
-            return parent::processFiles ($sFieldFile, $iContentId, $isAssociateWithContent);
-
-        $aMediasOld = $this->_oModule->_oDb->getMediaListByContentId($iContentId);                
-
-        if(!parent::processFiles ($sFieldFile, $iContentId, $isAssociateWithContent)) 
-            return false;
-
-        $aMediasNew = $this->_oModule->_oDb->getMediaListByContentId($iContentId);
-
-        $aIdsOld = array_column($aMediasOld, 'id');
-        $aIdsNew = array_column($aMediasNew, 'id');
-        $aIdsAdded = array_diff($aIdsNew, $aIdsOld);
-
-        if(!empty($aIdsAdded)) {
-            $aContentInfo = $this->_oModule->_oDb->getContentInfoById($iContentId);
-            $iProfileId = $this->getContentOwnerProfileId($iContentId);
-
-             /**
-             * @hooks
-             * @hookdef hook-bx_albums-medias_added 'bx_albums', 'medias_added' - hook on new medias added in album
-             * - $unit_name - equals `bx_albums`
-             * - $action - equals `medias_added` 
-             * - $object_id - album_id
-             * - $sender_id - author's profile_id
-             * - $extra_params - array of additional params with the following array keys:
-             *      - `object_author_id` - [int] confirmation type can be none/phone/email/email_and_phone/email_or_phone
-             *      - `subobjects_ids` - [array] array of ids for added media's
-             *      - `medias_added` - [array] array of ids for added media's
-             *      - `privacy_view` - [string] privacy view value for current album
-             *      - `cf` - [int] content filter id
-             * @hook @ref hook-bx_albums-medias_added
-             */
-            bx_alert($this->_oModule->getName(), 'medias_added', $iContentId, $iProfileId, [
-                'object_author_id' => $iProfileId,
-
-                'subobjects_ids' => $aIdsAdded,
-                'medias_added' => $aIdsAdded,
-
-                'privacy_view' => $aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']],
-                'cf' => $aContentInfo[$CNF['FIELD_CF']]
-            ]);
-        }
-
-        return true;
+        return parent::_processFilesInAlbumsAndStories($sFieldFile, $iContentId, $isAssociateWithContent);
     }
     
     protected function _associalFileWithContent($oStorage, $iFileId, $iProfileId, $iContentId, $sPictureField = '')

+ 1 - 47
modules/boonex/stories/classes/BxStoriesFormEntry.php

@@ -28,53 +28,7 @@ class BxStoriesFormEntry extends BxBaseModTextFormEntry
 
     public function processFiles ($sFieldFile, $iContentId = 0, $isAssociateWithContent = false)
     {
-        $CNF = &$this->_oModule->_oConfig->CNF;
-
-        if($isAssociateWithContent)
-            return parent::processFiles ($sFieldFile, $iContentId, $isAssociateWithContent);
-
-        $aMediasOld = $this->_oModule->_oDb->getMediaListByContentId($iContentId);                
-
-        if(!parent::processFiles ($sFieldFile, $iContentId, $isAssociateWithContent)) 
-            return false;
-
-        $aMediasNew = $this->_oModule->_oDb->getMediaListByContentId($iContentId);
-
-        $aIdsOld = array_column($aMediasOld, 'id');
-        $aIdsNew = array_column($aMediasNew, 'id');
-        $aIdsAdded = array_diff($aIdsNew, $aIdsOld);
-
-        if(!empty($aIdsAdded)) {
-            $aContentInfo = $this->_oModule->_oDb->getContentInfoById($iContentId);
-            $iProfileId = $this->getContentOwnerProfileId($iContentId);
-
-             /**
-             * @hooks
-             * @hookdef hook-bx_stories-medias_added 'bx_stories', 'medias_added' - hook on new medias added in story
-             * - $unit_name - equals `bx_stories`
-             * - $action - equals `medias_added` 
-             * - $object_id - story_id
-             * - $sender_id - author's profile_id
-             * - $extra_params - array of additional params with the following array keys:
-             *      - `object_author_id` - [int] confirmation type can be none/phone/email/email_and_phone/email_or_phone
-             *      - `subobjects_ids` - [array] array of ids for added media's
-             *      - `medias_added` - [array] array of ids for added media's
-             *      - `privacy_view` - [string] privacy view value for current story
-             *      - `cf` - [int] content filter id
-             * @hook @ref hook-bx_stories-medias_added
-             */
-            bx_alert($this->_oModule->getName(), 'medias_added', $iContentId, $iProfileId, [
-                'object_author_id' => $iProfileId,
-
-                'subobjects_ids' => $aIdsAdded,
-                'medias_added' => $aIdsAdded,
-
-                'privacy_view' => $aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']],
-                'cf' => $aContentInfo[$CNF['FIELD_CF']]
-            ]);
-        }
-
-        return true;
+        return parent::_processFilesInAlbumsAndStories($sFieldFile, $iContentId, $isAssociateWithContent);
     }
     
     protected function _associalFileWithContent($oStorage, $iFileId, $iProfileId, $iContentId, $sPictureField = '')