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

Merge branch 'master' of https://github.com/unaio/una

roman.lesnikov@gmail.com 2 лет назад
Родитель
Сommit
170993753f

+ 89 - 0
modules/base/groups/classes/BxBaseModGroupsConnectionFans.php

@@ -21,6 +21,11 @@ class BxBaseModGroupsConnectionFans extends BxTemplConnection
         $this->_oModule = BxDolModule::getInstance($this->_sModule);
     }
 
+    public function getModule()
+    {
+        return $this->_sModule;
+    }
+
     public function getActionTitle ($sAction, $iInitiatorId, $iContentId, $bFlip = false)
     {
         $aResult = [];
@@ -52,6 +57,90 @@ class BxBaseModGroupsConnectionFans extends BxTemplConnection
         return !empty($aResult[$sAction]) ? _t($aResult[$sAction]) : '';
     }
 
+    public function hasQuestionnaire($iContentProfileId)
+    {
+        $CNF = &$this->_oModule->_oConfig->CNF;
+        
+        if(empty($CNF['FIELD_JOIN_CONFIRMATION']))
+            return false;
+
+        $aContentInfo = $this->_oModule->_oDb->getContentInfoByProfileId($iContentProfileId);
+        if(empty($aContentInfo) || !is_array($aContentInfo))
+            return false;
+
+        return (int)$aContentInfo[$CNF['FIELD_JOIN_CONFIRMATION']] != 0 && $this->_oModule->_oDb->hasQuestions($aContentInfo[$CNF['FIELD_ID']]);
+    }
+
+    public function getQuestionnaireForm($sAction, $iContentProfileId, $aParams = [])
+    {
+        $CNF = &$this->_oModule->_oConfig->CNF;
+
+        if(empty($aParams['request']) || !is_array($aParams['request']))
+            $aParams['request'] = [];
+
+        $aForm = [
+            'form_attrs' => [
+                'id' => $this->_oModule->getName() . '_questionnaire',
+                'action' => BX_DOL_URL_ROOT . bx_append_url_params($this->_oModule->_oConfig->getBaseUri() . 'get_questionnaire', array_merge([
+                    'o' => $this->_sObject, 
+                    'a' => $sAction, 
+                    'cpi' => $iContentProfileId
+                ], $aParams['request']))
+            ],
+            'params' => [
+                'db' => [
+                    'table' => $CNF['TABLE_ANSWERS'],
+                    'key' => '',
+                    'uri' => '',
+                    'uri_title' => '',
+                    'submit_name' => 'do_submit'
+                ],
+            ],
+            'inputs' => []
+        ];
+
+        $aQuestions = $this->_oModule->_oDb->getQuestions(['sample' => 'content_pid', 'content_pid' => $iContentProfileId]);
+        if(empty($aQuestions) || !is_array($aQuestions))
+            return false;
+
+        foreach($aQuestions as $aQuestion) {
+            $aForm['inputs'][] = [
+                'type' => 'text',
+                'name' => 'question_' . $aQuestion['id'],
+                'caption' => $aQuestion['question'],
+                'value' => '',
+                'required' => '1',
+                'checker' => [
+                    'func' => 'Avail',
+                    'params' => [],
+                    'error' => _t($CNF['T']['form_qnr_field_qn_err']),
+                ],
+                'db' => [
+                    'pass' => 'Xss',
+                ],
+            ];
+        }
+
+        $aForm['inputs']['controls'] = [
+            'name' => 'controls',
+            'type' => 'input_set', [
+                'type' => 'submit',
+                'name' => 'do_submit',
+                'value' => _t('_Submit'),
+            ], [
+                'type' => 'reset',
+                'name' => 'close',
+                'value' => _t('_Cancel'),
+                'attrs' => [
+                    'onclick' => "$('.bx-popup-applied:visible').dolPopupHide()",
+                    'class' => 'bx-def-margin-sec-left',
+                ],
+            ]
+        ];
+
+    	return new BxTemplFormView($aForm);
+    }
+
     protected function _checkAllowedConnectInitiator ($oInitiator, $isPerformAction = false)
     {
         if(!bx_srv($oInitiator->getModule(), 'act_as_profile'))

+ 21 - 0
modules/base/groups/classes/BxBaseModGroupsDb.php

@@ -490,6 +490,17 @@ class BxBaseModGroupsDb extends BxBaseModProfileDb
                 $sOrderClause = "`tq`.`order` ASC";
                 break;
             
+            case 'content_pid':
+                $aMethod['params'][1] = [
+                    'module' => $this->_oConfig->getName(),
+                    'content_pid' => $aParams['content_pid']
+                ];
+
+                $sJoinClause = "INNER JOIN `sys_profiles` AS `tp` ON `tq`.`content_id`=`tp`.`content_id` AND `tp`.`type`=:module";
+                $sWhereClause = " AND `tp`.`id`=:content_pid";
+                $sOrderClause = "`tq`.`order` ASC";
+                break;
+
             case 'answers':
                 $aMethod['params'][1] = [
                     'content_id' => $aParams['content_id'],
@@ -512,6 +523,16 @@ class BxBaseModGroupsDb extends BxBaseModProfileDb
 
         return call_user_func_array([$this, $aMethod['name']], $aMethod['params']);
     }
+    
+    public function hasQuestions($iContentId)
+    {
+        $aQuestions = $this->getQuestions([
+            'sample' => 'content_id', 
+            'content_id' => $iContentId
+        ]);
+
+        return !empty($aQuestions) && is_array($aQuestions);
+    }
 
     public function getQuestionOrderMax($iContentId)
     {

+ 6 - 1
modules/base/groups/classes/BxBaseModGroupsMenuSnippetMeta.php

@@ -26,7 +26,12 @@ class BxBaseModGroupsMenuSnippetMeta extends BxBaseModProfileMenuSnippetMeta
 
     protected function getMenuItemConnectionJsCode($sConnection, $sAction, $iContentProfile, $aItem)
     {
-        return $this->_oModule->_oConfig->getJsObject('main') . ".connAction(this, '" . $sConnection . "', '" . $sAction . "', '" . $iContentProfile . "')";
+        $CNF = &$this->_oModule->_oConfig->CNF;
+
+        if($sConnection == $CNF['OBJECT_CONNECTIONS'] && ($oConnection = BxDolConnection::getObjectInstance($sConnection)) !== false && $oConnection->hasQuestionnaire($iContentProfile))
+            return $this->_oModule->_oConfig->getJsObject('main') . ".connAction(this, '" . $sConnection . "', '" . $sAction . "', '" . $iContentProfile . "')";
+
+        return parent::getMenuItemConnectionJsCode($sConnection, $sAction, $iContentProfile, $aItem);
     }
 
     protected function _getMenuItemJoinPaid($aItem)

+ 1 - 1
modules/base/groups/classes/BxBaseModGroupsMenuViewActions.php

@@ -44,7 +44,7 @@ class BxBaseModGroupsMenuViewActions extends BxBaseModProfileMenuViewActions
                     ];
             }
             else {
-                if(!empty($CNF['FIELD_JOIN_CONFIRMATION']) && (int)$this->_aContentInfo[$CNF['FIELD_JOIN_CONFIRMATION']] != 0)
+                if($oConn->hasQuestionnaire($iGroupProfileId))
                     $sOnclickAddFan = $this->_oModule->_oConfig->getJsObject('entry') . ".connAction(this, 'bx_events_fans', 'add', '" . $iGroupProfileId . "')";
 
                 if(isset($CNF['T']['menu_item_title_become_fan'], $CNF['T']['menu_item_title_leave_group']))

+ 23 - 65
modules/base/groups/classes/BxBaseModGroupsModule.php

@@ -208,7 +208,14 @@ class BxBaseModGroupsModule extends BxBaseModProfileModule
         }
         return parent::serviceGetParticipatingProfiles($iProfileId);
     }
-    
+
+    public function serviceGetSafeServices()
+    {
+        return array_merge(parent::serviceGetSafeServices(), [
+            'GetQuestionnaire' => '',
+        ]);
+    }
+
     /**
      * Check if this module entry can be used as profile
      */
@@ -1146,80 +1153,31 @@ class BxBaseModGroupsModule extends BxBaseModProfileModule
     {
         $CNF = &$this->_oConfig->CNF;
 
-        $aContentProfileInfo = BxDolProfileQuery::getInstance()->getInfoById($iContentProfileId);
-        if(empty($aContentProfileInfo) || !is_array($aContentProfileInfo))
-            return ['code' => 1];
-
-        $aForm = [
-            'form_attrs' => [
-                'id' => $this->getName() . '_questionnaire',
-                'action' => BX_DOL_URL_ROOT . bx_append_url_params($this->_oConfig->getBaseUri() . 'get_questionnaire', [
-                    's' => $sSource,
-                    'o' => $sObject, 
-                    'a' => $sAction, 
-                    'cpi' => $iContentProfileId
-                ])
-            ],
-            'params' => [
-                'db' => [
-                    'table' => $CNF['TABLE_ANSWERS'],
-                    'key' => '',
-                    'uri' => '',
-                    'uri_title' => '',
-                    'submit_name' => 'do_submit'
-                ],
-            ],
-            'inputs' => []
-        ];
-
-        $aQuestions = $this->_oDb->getQuestions(['sample' => 'content_id', 'content_id' => $aContentProfileInfo['content_id']]);
-        if(empty($aQuestions) || !is_array($aQuestions))
+        $aContentInfo = $this->_oDb->getContentInfoByProfileId($iContentProfileId);
+        if(empty($aContentInfo) || !is_array($aContentInfo))
             return ['code' => 1];
+        
+        $oForm = null;
+        if(($oConnection = BxDolConnection::getObjectInstance($sObject)) !== false) {
+            $oForm = $oConnection->getQuestionnaireForm($sAction, $iContentProfileId, ['request' => [
+                's' => $sSource,
+            ]]);
 
-        foreach($aQuestions as $aQuestion) {
-            $aForm['inputs'][] = [
-                'type' => 'text',
-                'name' => 'question_' . $aQuestion['id'],
-                'caption' => $aQuestion['question'],
-                'value' => '',
-                'required' => '1',
-                'checker' => [
-                    'func' => 'Avail',
-                    'params' => [],
-                    'error' => _t($CNF['T']['form_qnr_field_qn_err']),
-                ],
-                'db' => [
-                    'pass' => 'Xss',
-                ],
-            ];
+            if($oForm === false)
+                return ['code' => 3];
         }
-
-        $aForm['inputs']['controls'] = [
-            'name' => 'controls',
-            'type' => 'input_set', [
-                'type' => 'submit',
-                'name' => 'do_submit',
-                'value' => _t('_Submit'),
-            ], [
-                'type' => 'reset',
-                'name' => 'close',
-                'value' => _t('_Cancel'),
-                'attrs' => [
-                    'onclick' => "$('.bx-popup-applied:visible').dolPopupHide()",
-                    'class' => 'bx-def-margin-sec-left',
-                ],
-            ]
-        ];
-
-    	$oForm = new BxTemplFormView($aForm);
+        else
+            return ['code' => 2];
+        
         $oForm->initChecker();
         if($oForm->isSubmittedAndValid()) {
             $iProfileId = bx_get_logged_profile_id();
 
+            $aQuestions = $this->_oDb->getQuestions(['sample' => 'content_pid', 'content_pid' => $iContentProfileId]);
             foreach($aQuestions as $aQuestion)
                 $this->_oDb->insertAnswer((int)$aQuestion['id'], $iProfileId, $oForm->getCleanValue('question_' . $aQuestion['id']));
 
-            return ['code' => 0, 'o' => $sObject, 'a' => $sAction, 'cpi' => $iContentProfileId, 'ci' => $aContentProfileInfo['content_id'], 'eval' => $this->_oConfig->getJsObject($sSource) . '.connActionPerformed(oData)'];
+            return ['code' => 0, 'o' => $sObject, 'a' => $sAction, 'cpi' => $iContentProfileId, 'ci' => $aContentInfo[$CNF['FIELD_ID']], 'eval' => $this->_oConfig->getJsObject($sSource) . '.connActionPerformed(oData)'];
         }
 
         bx_import('BxTemplFunctions');

+ 15 - 0
template/scripts/BxBaseServiceConnections.php

@@ -47,6 +47,21 @@ class BxBaseServiceConnections extends BxDol
         if(!$oConnection)
             return ['code' => 2];
 
+        $sMethod = 'hasQuestionnaire';
+        if($aParams['a'] == 'add' && method_exists($oConnection, $sMethod) && $oConnection->$sMethod($aParams['cid'])) {
+            $sModule = $oConnection->getModule();
+
+            return [
+                'a' => $aParams['a'],
+                'block' => [
+                    'content' => [bx_api_get_block('form', $oConnection->getQuestionnaireForm('add', $aParams['cid'])->getCodeAPI(), ['ext' => [
+                        'name' => $sModule, 
+                        'request' => ['url' => '/api.php?r=' . $sModule . '/get_questionnaire&params[]=main&params[]=' . $aParams['o'] . '&params[]=add&params[]=' . $aParams['cid'], 'immutable' => true]
+                    ]])]
+                ]
+            ];
+        }
+
         $sMethod = 'action' . bx_gen_method_name($aParams['a']);
         if(!method_exists($oConnection, $sMethod))
             return ['code' => 2];