Kaynağa Gözat

Ticket #4817 - Courses improvements. Core changes.

AntonLV 2 yıl önce
ebeveyn
işleme
57e349499b

+ 6 - 9
modules/base/files/classes/BxBaseModFilesFormUpload.php

@@ -55,15 +55,12 @@ class BxBaseModFilesFormUpload extends BxBaseModTextFormEntry
         bx_import('BxDolPrivacy');
 
         // get values form main form to pass it to each file later
-        $aFormValues = array();
-        foreach ($this->aInputs as $aInput) {
-            if(in_array($aInput['name'], array('do_submit', 'profile_id', $CNF['FIELD_PHOTO'])))
-                continue;
-
-            $aFormValues[$aInput['name']] = $this->getCleanValue($aInput['name']);
-        }
+        $aFormValues = [];
+        foreach ($this->aInputs as $aInput)
+            if(!empty($aInput['db']) && is_array($aInput['db']))
+                $aFormValues[$aInput['name']] = $this->getCleanValue($aInput['name']);
 
-        $aContentIds = array();
+        $aContentIds = [];
         foreach ($aGhostFiles as $aFile) {
             if (CHECK_ACTION_RESULT_ALLOWED !== $this->_oModule->checkAllowedAdd())
                 continue;
@@ -74,7 +71,7 @@ class BxBaseModFilesFormUpload extends BxBaseModTextFormEntry
                 $iContentId = BxBaseModGeneralFormEntry::insert (array_merge(array(
                     $CNF['FIELD_FOR_STORING_FILE_ID'] => $aFile['id'],
                     $CNF['FIELD_TITLE'] => $this->getCleanValue('title-' . $aFile['id']),
-                    $CNF['FIELD_AUTHOR'] => bx_get('profile_id') && $this->_oModule->serviceIsAllowedAddContentToProfile(bx_get('profile_id')) ? bx_get('profile_id') : '',
+                    $CNF['FIELD_AUTHOR'] => bx_get('profile_id') && $this->_oModule->serviceIsAllowedAddContentToContext(bx_get('profile_id')) ? bx_get('profile_id') : '',
                     $CNF['FIELD_STATUS_ADMIN'] => !$this->_oModule->_isModerator() && !$this->_oModule->_oConfig->isAutoApproveEnabled() ? BX_BASE_MOD_GENERAL_STATUS_PENDING : BX_BASE_MOD_TEXT_STATUS_ACTIVE
                 ), $aFormValues));
             if (!$iContentId)

+ 24 - 0
modules/base/files/classes/BxBaseModFilesFormsEntryHelper.php

@@ -87,6 +87,30 @@ class BxBaseModFilesFormsEntryHelper extends BxBaseModTextFormsEntryHelper
         
         return array('need_redirect_after_action' => true, 'content_ids_array' => $aContentIds);
     }
+    
+    protected function getRedirectUrlAfterAdd($mixedContent)
+    {
+        $CNF = &$this->_oModule->_oConfig->CNF;
+            
+        $iProfileId = false;
+        $sUri = $CNF['URI_AUTHOR_ENTRIES'];
+
+        $sKeyIds = 'content_ids_array';
+        if(!empty($mixedContent[$sKeyIds]) && is_array($mixedContent[$sKeyIds])) {
+            $aContentInfo = $this->_oModule->_oDb->getContentInfoById(array_pop($mixedContent[$sKeyIds]));
+
+            if(($sKey = 'FIELD_AUTHOR') && isset($CNF[$sKey]) && ($iAuthor = (int)$aContentInfo[$CNF[$sKey]])) {
+                $iProfileId = $iAuthor;
+            }
+
+            if(($sKey = 'FIELD_ALLOW_VIEW_TO') && isset($CNF[$sKey]) && ($iVisibility = (int)$aContentInfo[$CNF[$sKey]]) < 0) {
+                $iProfileId = abs($iVisibility);
+                $sUri = $CNF['URI_ENTRIES_BY_CONTEXT'];
+            }
+        }
+
+        return 'page.php?i=' . $sUri . '&profile_id=' . (($oProfile = BxDolProfile::getInstance($iProfileId)) !== false ? $oProfile->id() : bx_get_logged_profile_id());
+    }
 }
 
 /** @} */

+ 67 - 17
modules/base/general/classes/BxBaseModGeneralFormEntry.php

@@ -418,6 +418,8 @@ class BxBaseModGeneralFormEntry extends BxTemplFormView
 
         parent::initChecker ($aValues, $aSpecificValues);
 
+        $this->_processContextBeforeAdd();
+
         foreach($aPrivacyFields as $sField => $sObject)
             $this->_validatePrivacyField($sField, $sObject, $aValues);
     }
@@ -509,33 +511,35 @@ class BxBaseModGeneralFormEntry extends BxTemplFormView
         $bMulticatEnabled = $this->_isMulticatEnabled();
         if ($bMulticatEnabled)
             $this->processMulticatBefore($CNF['FIELD_MULTICAT'], $aValsToAdd);
+
         $iContentId = parent::insert ($aValsToAdd, $isIgnore);
-        
-        if(!empty($iContentId)) {
-            foreach($this->aInputs as $aInput) {
-                if ($aInput['type'] == 'nested_form') {
-                    if (is_array($aInput['ghost_template']) && !isset($aInput['ghost_template']['inputs'])) {
-                        foreach ($aInput['ghost_template'] as $oFormNested) {
-                            $iNestedContentId = $oFormNested->insert(array('content_id' => $iContentId));
+        if(empty($iContentId))
+            return $iContentId;
 
-                            if ($aInput['rateable']) {
-                                BxDolFormQuery::addFormField($this->id, $aInput['name'], $iContentId, $iAuthor, $this->_oModule->getName(), $iNestedContentId);
-                            }
+        foreach($this->aInputs as $aInput) {
+            if ($aInput['type'] == 'nested_form') {
+                if (is_array($aInput['ghost_template']) && !isset($aInput['ghost_template']['inputs'])) {
+                    foreach ($aInput['ghost_template'] as $oFormNested) {
+                        $iNestedContentId = $oFormNested->insert(array('content_id' => $iContentId));
+
+                        if ($aInput['rateable']) {
+                            BxDolFormQuery::addFormField($this->id, $aInput['name'], $iContentId, $iAuthor, $this->_oModule->getName(), $iNestedContentId);
                         }
                     }
                 }
             }
-            
-            if ($bMulticatEnabled)
-                $this->processMulticatAfter($CNF['FIELD_MULTICAT'], $iContentId);
         }
 
-        foreach($this->aInputs as $aInput) {
-            if (isset($aInput['rateable']) && $aInput['rateable'] && $aInput['type'] != 'nested_form'){
+        if($bMulticatEnabled)
+            $this->processMulticatAfter($CNF['FIELD_MULTICAT'], $iContentId);
+
+        foreach($this->aInputs as $aInput)
+            if(isset($aInput['rateable']) && $aInput['rateable'] && $aInput['type'] != 'nested_form')
                 BxDolFormQuery::addFormField($this->id, $aInput['name'], $iContentId, $iAuthor, $this->_oModule->getName());
-            }
-        }
 
+        if(($iContextNid = $this->getCleanValue('context_nid')) !== false)
+            $this->_processContextAfterAdd($iContentId, $iContextNid);
+            
         return $iContentId;
     }
 
@@ -998,6 +1002,52 @@ class BxBaseModGeneralFormEntry extends BxTemplFormView
         }
     }
 
+    protected function _processContextBeforeAdd()
+    {
+        $CNF = &$this->_oModule->_oConfig->CNF;
+
+        $sKey = 'FIELD_ALLOW_VIEW_TO';
+        if(!isset($CNF[$sKey], $this->aInputs[$CNF[$sKey]]))
+            return;
+
+        if(($iContextId = bx_get('context_pid')) !== false)
+            $this->aInputs[$CNF[$sKey]] = array_merge($this->aInputs[$CNF[$sKey]], [
+                'type' => 'hidden',
+                'value' => -abs((int)$iContextId)
+            ]);
+
+        if(($iNodeId = bx_get('context_nid')) !== false && !isset($this->aInputs['context_nid'])) {
+            $this->aInputs['context_nid'] = [
+                'name' => 'context_nid',
+                'type' => 'hidden',
+                'value' => (int)$iNodeId
+            ];
+        }
+    }
+
+    protected function _processContextAfterAdd($iContentId, $iContextNid)
+    {
+        $CNF = &$this->_oModule->_oConfig->CNF;
+
+        $sKey = 'FIELD_ALLOW_VIEW_TO';
+        if(!isset($CNF[$sKey]))
+            return;
+
+        $aContentInfo = $this->_oModule->_oDb->getContentInfoById($iContentId);
+        if(!is_numeric($aContentInfo[$CNF[$sKey]]) || (int)$aContentInfo[$CNF[$sKey]] > 0)
+            return;
+
+        $iContextPid = abs($aContentInfo[$CNF[$sKey]]);
+        $oContext = BxDolProfile::getInstance($iContextPid);
+        if(!$oContext)
+            return;
+
+        $sModule = $oContext->getModule();
+        $sMethod = 'on_content_added';
+        if(bx_is_srv($sModule, $sMethod))
+            bx_srv($sModule, $sMethod, [$this->MODULE, $iContentId, $oContext->getContentId(), $iContextNid]);
+    }
+
     /**
      * 
      * MultiCategories related methods. 

+ 11 - 0
modules/base/general/classes/BxBaseModGeneralFormsEntryHelper.php

@@ -626,6 +626,17 @@ class BxBaseModGeneralFormsEntryHelper extends BxDolProfileForms
         if(($oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW'])) !== false)
             $oPrivacy->deleteGroupCustomByContentId($iContentId);
 
+        $sKey = 'FIELD_ALLOW_VIEW_TO';
+        if(isset($CNF[$sKey], $aContentInfo[$CNF[$sKey]]) && ($iContextPid = (int)$aContentInfo[$CNF[$sKey]]) < 0) {
+            $iContextPid = abs($iContextPid);
+            if(($oContext = BxDolProfile::getInstance($iContextPid)) !== false) {
+                $sModule = $oContext->getModule();
+                $sMethod = 'on_content_deleted';
+                if(bx_is_srv($sModule, $sMethod))
+                    bx_srv($sModule, $sMethod, [$this->_oModule->getName(), $iContentId, $oContext->getContentId()]);
+            }
+        }
+
         bx_audit(
             $iContentId, 
             $this->_oModule->getName(), 

+ 11 - 0
modules/base/general/classes/BxBaseModGeneralModule.php

@@ -503,6 +503,17 @@ class BxBaseModGeneralModule extends BxDolModule
     }
 
     // ====== SERVICE METHODS
+    public function serviceIsAllowedAddContentToContext($iContextPid)
+    {
+        $oContext = false;
+        if(!$iContextPid || !($oContext = BxDolProfile::getInstance((int)$iContextPid)))
+            return false;
+
+        if($iContextPid == bx_get_logged_profile_id())
+            return true;
+
+        return bx_srv($oContext->getModule(), 'check_allowed_post_in_profile', [$oContext->getContentId(), $this->getName()]) === CHECK_ACTION_RESULT_ALLOWED;
+    }
 
     public function serviceIsBadgesAvaliable()
     {