Ver Fonte

Ticket #4558 - Build-in API support: Selected Friends/Relations/Memberships in Privacy form field.

AntonLV há 1 ano atrás
pai
commit
48d10bed6b

+ 43 - 3
inc/classes/BxDolPrivacy.php

@@ -397,16 +397,21 @@ class BxDolPrivacy extends BxDolFactory implements iBxDolFactoryObject
         return $this->_oDb->getGroupCustom($aParams);
     }
 
-    public function insertGroupCustom($aGroup, $aItems = [])
+    /**
+     * Note. Is used when privacy group is processing after the main form submit.
+     */
+    public function addGroupCustom($aGroup, $aItems = [])
     {
-        $iGroupId = (int)$aGroup['group_id'];
-
         $this->deleteGroupCustom([
             'profile_id' => $aGroup['profile_id'],
             'content_id' => $aGroup['content_id'],
             'object' => $aGroup['object']
         ]);
 
+        if(empty($aItems) || !is_array($aItems))
+            return 0;
+
+        $iGroupId = (int)$aGroup['group_id'];
         $iGroupCustomId = $this->_oDb->insertGroupCustom($aGroup);
         if($iGroupCustomId !== false && !empty($aItems) && is_array($aItems)) {
             $bMembers = $iGroupId == BX_DOL_PG_FRIENDS_SELECTED || $iGroupId == BX_DOL_PG_RELATIONS_SELECTED;
@@ -419,6 +424,41 @@ class BxDolPrivacy extends BxDolFactory implements iBxDolFactoryObject
         return $iGroupCustomId;
     }
 
+    /**
+     * Note. Is used when privacy group is processing after the main form submit.
+     */
+    public function editGroupCustom($aGroup, $aItems = [])
+    {
+        $aGroupCustom = $this->getGroupCustom([
+            'type' => 'pco',
+            'profile_id' => $aGroup['profile_id'],
+            'content_id' => $aGroup['content_id'],
+            'object' => $this->_sObject
+        ]);
+        if(empty($aGroupCustom) || !is_array($aGroupCustom))
+            return $this->addGroupCustom($aGroup, $aItems);
+
+        $iGroupId = (int)$aGroupCustom['group_id'];
+        $iGroupCustomId = (int)$aGroupCustom['id'];
+
+        if($iGroupId != (int)$aGroup['group_id'])
+            return $this->addGroupCustom($aGroup, $aItems);
+
+        $bMembers = $iGroupId == BX_DOL_PG_FRIENDS_SELECTED || $iGroupId == BX_DOL_PG_RELATIONS_SELECTED;
+        $bMemberships = $iGroupId == BX_DOL_PG_MEMBERSHIPS_SELECTED;
+        if(($bMembers || $bMemberships) && ($sType = $bMembers ? 'member' : ($bMemberships ? 'membership' : '')) !== '') {
+            $sTypeUc = ucfirst($sType);
+
+            $this->_oDb->{'deleteGroupCustom' . $sTypeUc}(['group_id' => $iGroupCustomId]);
+
+            if(!empty($aItems) && is_array($aItems))
+                foreach($aItems as $iItemId)
+                    $this->_oDb->{'insertGroupCustom' . $sTypeUc}(['group_id' => $iGroupCustomId, $sType . '_id' => $iItemId]);
+        }
+
+        return $iGroupCustomId;
+    }
+
     public function updateGroupCustom($aParamsSet, $aParamsWhere)
     {
         return $this->_oDb->updateGroupCustom($aParamsSet, $aParamsWhere);

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

@@ -530,11 +530,13 @@ class BxBaseModGeneralFormEntry extends BxTemplFormView
             }
         }
 
-        if($this->_bIsApi && isset($CNF['FIELD_ALLOW_VIEW_TO']) && ($mixedAllowViewTo = $this->getCleanValue($CNF['FIELD_ALLOW_VIEW_TO'])) !== false && ($mixedAllowViewToItems = $this->getCleanValue($CNF['FIELD_ALLOW_VIEW_TO'] . '_items')) !== false) {
-            $aAllowViewToItems = explode(',', $mixedAllowViewToItems);
+        if($this->_bIsApi && ($sKeyF = 'FIELD_ALLOW_VIEW_TO') && isset($CNF[$sKeyF]) && ($mixedAllowViewTo = $this->getCleanValue($CNF[$sKeyF])) !== false) {
+            $aAllowViewToItems = [];
+            if(($mixedAllowViewToItems = $this->getCleanValue($CNF[$sKeyF] . '_items')) !== false)
+                $aAllowViewToItems = explode(',', $mixedAllowViewToItems);
 
-            if(($sKey = 'OBJECT_PRIVACY_VIEW') && isset($CNF[$sKey]) && ($sObject = $CNF[$sKey]) && ($oPrivacy = BxDolPrivacy::getObjectInstance($sObject)) !== false)
-                $oPrivacy->insertGroupCustom([
+            if(($sKeyO = 'OBJECT_PRIVACY_VIEW') && isset($CNF[$sKeyO]) && ($sObject = $CNF[$sKeyO]) && ($oPrivacy = BxDolPrivacy::getObjectInstance($sObject)) !== false)
+                $oPrivacy->addGroupCustom([
                     'profile_id' => $iAuthor,
                     'content_id' => 0,
                     'object' => $sObject,
@@ -636,10 +638,26 @@ class BxBaseModGeneralFormEntry extends BxTemplFormView
                 BxDolFormQuery::addFormField($this->id, $aInput['name'], $iContentId, $iAuthor, $this->_oModule->getName());
             }
         }
-		
-        if($mixedResult !== false)
+
+        if($mixedResult !== false) {
             $this->_processTrackFields($iContentId);
 
+            if($this->_bIsApi && ($sKeyF = 'FIELD_ALLOW_VIEW_TO') && isset($CNF[$sKeyF]) && ($mixedAllowViewTo = $this->getCleanValue($CNF[$sKeyF])) !== false) {
+                $aAllowViewToItems = [];
+                if(($mixedAllowViewToItems = $this->getCleanValue($CNF[$sKeyF] . '_items')) !== false)
+                    $aAllowViewToItems = explode(',', $mixedAllowViewToItems);
+
+                if(($sKeyO = 'OBJECT_PRIVACY_VIEW') && isset($CNF[$sKeyO]) && ($sObject = $CNF[$sKeyO]) && ($oPrivacy = BxDolPrivacy::getObjectInstance($sObject)) !== false) {
+                    $oPrivacy->editGroupCustom([
+                        'profile_id' => $iAuthor,
+                        'content_id' => $iContentId,
+                        'object' => $sObject,
+                        'group_id' => (int)$mixedAllowViewTo
+                    ], $aAllowViewToItems);
+                }
+            }
+        }
+
         return $mixedResult;
     }
     

+ 25 - 5
modules/boonex/timeline/classes/BxTimelineFormPost.php

@@ -152,11 +152,13 @@ class BxTimelineFormPost extends BxBaseModGeneralFormEntry
         if(empty($iContentId))
             return $iContentId;
 
-        if($this->_bIsApi && ($mixedAllowViewTo = $this->getCleanValue($CNF['FIELD_OBJECT_PRIVACY_VIEW'])) !== false && ($mixedAllowViewToItems = $this->getCleanValue($CNF['FIELD_OBJECT_PRIVACY_VIEW'] . '_items')) !== false) {
-            $aAllowViewToItems = explode(',', $mixedAllowViewToItems);
+        if($this->_bIsApi && ($sKeyF = 'FIELD_OBJECT_PRIVACY_VIEW') && ($mixedAllowViewTo = $this->getCleanValue($CNF[$sKeyF])) !== false) {
+            $aAllowViewToItems = [];
+            if(($mixedAllowViewToItems = $this->getCleanValue($CNF[$sKeyF] . '_items')) !== false)
+                $aAllowViewToItems = explode(',', $mixedAllowViewToItems);
 
-            if(($sKey = 'OBJECT_PRIVACY_VIEW') && ($sObject = $CNF[$sKey]) && ($oPrivacy = BxDolPrivacy::getObjectInstance($sObject)) !== false)
-                $oPrivacy->insertGroupCustom([
+            if(($sKeyO = 'OBJECT_PRIVACY_VIEW') && ($sObject = $CNF[$sKeyO]) && ($oPrivacy = BxDolPrivacy::getObjectInstance($sObject)) !== false)
+                $oPrivacy->addGroupCustom([
                     'profile_id' => $aValsToAdd['object_owner_id'],
                     'content_id' => 0,
                     'object' => $sObject,
@@ -185,7 +187,25 @@ class BxTimelineFormPost extends BxBaseModGeneralFormEntry
             $aValsToAdd[$CNF['FIELD_PUBLISHED']] = $iPublished;
         }
 
-        return parent::update($iContentId, $aValsToAdd, $aTrackTextFieldsChanges);
+        $mixedResult = parent::update($iContentId, $aValsToAdd, $aTrackTextFieldsChanges);
+        if($mixedResult !== false) {
+            if($this->_bIsApi && ($sKeyF = 'FIELD_OBJECT_PRIVACY_VIEW') && ($mixedAllowViewTo = $this->getCleanValue($CNF[$sKeyF])) !== false) {
+                $aAllowViewToItems = [];
+                if(($mixedAllowViewToItems = $this->getCleanValue($CNF[$sKeyF] . '_items')) !== false)
+                    $aAllowViewToItems = explode(',', $mixedAllowViewToItems);
+
+                if(($sKeyO = 'OBJECT_PRIVACY_VIEW') && ($sObject = $CNF[$sKeyO]) && ($oPrivacy = BxDolPrivacy::getObjectInstance($sObject)) !== false) {
+                    $oPrivacy->editGroupCustom([
+                        'profile_id' => $iAuthor,
+                        'content_id' => $iContentId,
+                        'object' => $sObject,
+                        'group_id' => (int)$mixedAllowViewTo
+                    ], $aAllowViewToItems);
+                }
+            }
+        }
+
+        return $mixedResult;
     }
 
     public function addHtmlEditor($iViewMode, &$aInput, $sUniq)