ソースを参照

Ticket #4971 - Build-in API support: Attached polls in Timeline.

AntonLV 1 年間 前
親
コミット
0b9a24263e

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

@@ -1361,18 +1361,18 @@ class BxBaseModGeneralFormEntry extends BxTemplFormView
 
     protected function genCustomInputPolls ($aInput)
     {
-        if($this->_bIsApi) {
-            $sModule = $this->_oModule->getName();
-
-            return array_merge($aInput, [
-                'type' => 'polls',
-                'form_get' => '/api.php?r=' . $sModule . '/get_poll_form',
-                'form_submit' => '/api.php?r=' . $sModule . '/submit_poll_form',
-                'remove' => '/api.php?r=' . $sModule . '/delete_poll',
-            ]);
-        }
-
-        return $this->_oModule->_oTemplate->getPollField(!empty($aInput['content_id']) ? (int)$aInput['content_id'] : 0);
+        $mixedResult = $this->_oModule->_oTemplate->getPollField(!empty($aInput['content_id']) ? (int)$aInput['content_id'] : 0);
+
+        $sModule = $this->_oModule->getName();
+        return $this->_bIsApi ? array_merge($aInput, [
+            'type' => 'polls',
+            'value' => implode(',', array_column($mixedResult, 'id')),
+            'values' => $mixedResult,
+            'request_get' => '/api.php?r=' . $sModule . '/get_poll_form',
+            'request_submit' => '/api.php?r=' . $sModule . '/submit_poll_form',
+            'request_remove' => '/api.php?r=' . $sModule . '/delete_poll',
+            'request_results' => '/api.php?r=' . $sModule . '/get_block_poll_results',
+        ]) : $mixedResult;
     }
 
     protected function _isMulticatEnabled(){

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

@@ -723,6 +723,8 @@ class BxBaseModGeneralModule extends BxDolModule
             'GetPollForm' => '',
             'SubmitPollForm' => '',
             'DeletePoll' => '',
+            'GetBlockPollAnswers' => '',
+            'GetBlockPollResults' => '',
             // page blocks
             'EntityTextBlock' => '',
             'EntityInfo' => '',

+ 28 - 19
modules/base/general/classes/BxBaseModGeneralTemplate.php

@@ -773,22 +773,25 @@ class BxBaseModGeneralTemplate extends BxDolModuleTemplate
         if(empty($sContent))
             return '';
 
-    	return array(
+        return [
             'content' => $sContent,
             'menu' => $this->_getPollBlockMenu($aPoll, 'answers')
-        ); 
+        ]; 
     }
 
     public function entryPollResults($aPoll, $bDynamic = false)
     {
-        $sContent = $this->_getPollResults($aPoll, $bDynamic);
-        if(empty($sContent))
+        $mixedContent = $this->_getPollResults($aPoll, $bDynamic);
+        if($this->_bIsApi)
+            return $mixedContent;
+
+        if(empty($mixedContent))
             return '';
 
-        return array(
-            'content' => $sContent,
+        return [
+            'content' => $mixedContent,
             'menu' => $this->_getPollBlockMenu($aPoll, 'results')
-        );  
+        ];
     }
 
     public function getPollForm($iParentCid = 0)
@@ -807,30 +810,36 @@ class BxBaseModGeneralTemplate extends BxDolModuleTemplate
         if(empty($iProfileId))
             $iProfileId = bx_get_logged_profile_id();
 
-        $aPolls = array();
+        $aPolls = [];
         if(!empty($iContentId))
-            $aPolls = array_merge($aPolls, $this->_oDb->getPolls(array(
+            $aPolls = array_merge($aPolls, $this->_oDb->getPolls([
                 'type' => 'content_id', 
                 'content_id' => $iContentId, 
-            )));
+            ]));
 
-        $aPolls = array_merge($aPolls, $this->_oDb->getPolls(array(
+        $aPolls = array_merge($aPolls, $this->_oDb->getPolls([
             'type' => 'author_id', 
             'author_id' => $iProfileId, 
             'unused' => true
-        )));
+        ]));
 
-        $sPolls = '';
-        foreach($aPolls as $aPoll)
-            $sPolls .= $this->getPollItem($aPoll, $iProfileId, array(
+        $mixedPolls = $this->_bIsApi ? [] : '';
+        foreach($aPolls as $aPoll) {
+            $mixedPoll = $this->getPollItem($aPoll, $iProfileId, [
                 'parent_cid' => $iContentId,
                 'manage' => true
-            ));
+            ]);
+
+            if($this->_bIsApi)
+                $mixedPolls[] = $mixedPoll;
+            else
+                $mixedPolls .= $mixedPoll;
+        }
 
-        return $this->parseHtmlByName('poll_form_field.html', array(
+        return $this->_bIsApi ? $mixedPolls : $this->parseHtmlByName('poll_form_field.html', [
             'html_id' => $this->_oConfig->getHtmlIds('add_poll_form_field'),
-            'polls' => $sPolls
-        ));
+            'polls' => $mixedPolls
+        ]);
     }
 
     public function getPollItem($mixedPoll, $iProfileId = 0, $aParams = [])

+ 2 - 2
modules/boonex/russian/data/langs/bx_timeline/ru.xml

@@ -147,8 +147,8 @@
     <string name="_bx_timeline_form_poll_input_answers"><![CDATA[Ответы]]></string>
     <string name="_bx_timeline_form_poll_input_answers_err"><![CDATA[Голосование должно иметь как минимум 2 не пустых ответа.]]></string>
     <string name="_bx_timeline_form_poll_input_answers_add"><![CDATA[Добавить ещё]]></string>    
-    <string name="_bx_timeline_form_poll_input_sys_do_submit"><![CDATA[Добавить]]></string>
-    <string name="_bx_timeline_form_poll_input_do_submit"><![CDATA[Добавить]]></string>
+    <string name="_bx_timeline_form_poll_input_sys_do_submit"><![CDATA[Создать]]></string>
+    <string name="_bx_timeline_form_poll_input_do_submit"><![CDATA[Создать опрос]]></string>
     <string name="_bx_timeline_form_poll_input_do_cancel"><![CDATA[Закрыть]]></string>
 
     <string name="_bx_timeline_form_reposto"><![CDATA[Сделать репост]]></string>

+ 2 - 2
modules/boonex/timeline/install/langs/en.xml

@@ -147,8 +147,8 @@
     <string name="_bx_timeline_form_poll_input_answers"><![CDATA[Answers]]></string>
     <string name="_bx_timeline_form_poll_input_answers_err"><![CDATA[Poll should have at least 2 non-empty answers.]]></string>
     <string name="_bx_timeline_form_poll_input_answers_add"><![CDATA[Add More]]></string>
-    <string name="_bx_timeline_form_poll_input_sys_do_submit"><![CDATA[Add]]></string>
-    <string name="_bx_timeline_form_poll_input_do_submit"><![CDATA[Add]]></string>
+    <string name="_bx_timeline_form_poll_input_sys_do_submit"><![CDATA[Create]]></string>
+    <string name="_bx_timeline_form_poll_input_do_submit"><![CDATA[Create poll]]></string>
     <string name="_bx_timeline_form_poll_input_do_cancel"><![CDATA[Close]]></string>
 
     <string name="_bx_timeline_form_repost"><![CDATA[Repost]]></string>