瀏覽代碼

Ticket #4558 - Build-in API support: Polls.

AntonLV 1 年之前
父節點
當前提交
2bc30d0e33
共有 2 個文件被更改,包括 23 次插入 和 8 次删除
  1. 3 1
      modules/boonex/polls/classes/BxPollsModule.php
  2. 20 7
      modules/boonex/polls/classes/BxPollsTemplate.php

+ 3 - 1
modules/boonex/polls/classes/BxPollsModule.php

@@ -184,7 +184,9 @@ class BxPollsModule extends BxBaseModTextModule
 
 
         list($iContentId, $aContentInfo) = $mixedContent;
         list($iContentId, $aContentInfo) = $mixedContent;
 
 
-        return $this->_oTemplate->entryTextAndSubentries($aContentInfo, $bForceDisplaySubentries);
+        $mixedResult = $this->_oTemplate->entryTextAndSubentries($aContentInfo, $bForceDisplaySubentries);
+
+        return $this->_bIsApi ? [bx_api_get_block('entity_poll', $mixedResult)] : $mixedResult;
     }
     }
     
     
     /**
     /**

+ 20 - 7
modules/boonex/polls/classes/BxPollsTemplate.php

@@ -93,6 +93,13 @@ class BxPollsTemplate extends BxBaseModTextTemplate
         $oModule = $this->getModule();
         $oModule = $this->getModule();
         $CNF = &$oModule->_oConfig->CNF;
         $CNF = &$oModule->_oConfig->CNF;
 
 
+        if($this->_bIsApi)
+            return [
+                'object' => $CNF['OBJECT_VOTES_SUBENTRIES'],
+                'subentries' => $this->_getGetBlockContentSubentries($aData),
+                'results' => $this->_getGetBlockContentResults($aData)
+            ];
+
         $sMethod = '_getGetBlockContent';
         $sMethod = '_getGetBlockContent';
         $sMenuItem = '';
         $sMenuItem = '';
         if(!$bForceDisplaySubentries && $oModule->isPerformed($aData[$CNF['FIELD_ID']])) {
         if(!$bForceDisplaySubentries && $oModule->isPerformed($aData[$CNF['FIELD_ID']])) {
@@ -248,6 +255,9 @@ class BxPollsTemplate extends BxBaseModTextTemplate
         $CNF = &$this->getModule()->_oConfig->CNF;
         $CNF = &$this->getModule()->_oConfig->CNF;
 
 
         $aSubentries = $this->_oDb->getSubentries(array('type' => 'entry_id', 'entry_id' => $aData[$CNF['FIELD_ID']]));
         $aSubentries = $this->_oDb->getSubentries(array('type' => 'entry_id', 'entry_id' => $aData[$CNF['FIELD_ID']]));
+        if($this->_bIsApi)
+            return $aSubentries;
+
         if(empty($aSubentries) || !is_array($aSubentries))
         if(empty($aSubentries) || !is_array($aSubentries))
             return '';
             return '';
 
 
@@ -284,10 +294,10 @@ class BxPollsTemplate extends BxBaseModTextTemplate
         $iContentId = (int)$aData[$CNF['FIELD_ID']];
         $iContentId = (int)$aData[$CNF['FIELD_ID']];
         $aSubentries = $this->_oDb->getSubentries(['type' => 'entry_id', 'entry_id' => $iContentId]);
         $aSubentries = $this->_oDb->getSubentries(['type' => 'entry_id', 'entry_id' => $iContentId]);
         if(empty($aSubentries) || !is_array($aSubentries))
         if(empty($aSubentries) || !is_array($aSubentries))
-            return '';
+            return $this->_bIsApi ? [] : '';
 
 
         if($bHiddenResults && !$oModule->isPerformed($iContentId))
         if($bHiddenResults && !$oModule->isPerformed($iContentId))
-            return '';
+            return $this->_bIsApi ? [] : '';
         
         
         $iTotal = 0;
         $iTotal = 0;
         foreach($aSubentries as $aSubentry)
         foreach($aSubentries as $aSubentry)
@@ -299,16 +309,19 @@ class BxPollsTemplate extends BxBaseModTextTemplate
             $oVotes->setEntry($aData);
             $oVotes->setEntry($aData);
 
 
             $fPercent = $iTotal > 0 ? 100 * (float)$aSubentry['votes']/$iTotal : 0;
             $fPercent = $iTotal > 0 ? 100 * (float)$aSubentry['votes']/$iTotal : 0;
-            $aTmplVarsSubentries[] = array(
+            $aTmplVarsSubentries[] = array_merge([
                 'title' => bx_process_output($aSubentry['title']),
                 'title' => bx_process_output($aSubentry['title']),
                 'width' => (int)round($fPercent) . '%',
                 'width' => (int)round($fPercent) . '%',
-                'votes' => $oVotes->getCounter(array('show_counter_empty' => true, 'show_counter_in_brackets' => false)),
                 'percent' => _t('_bx_polls_txt_subentry_vote_percent', $iTotal > 0 ? round($fPercent, 2) : 0),
                 'percent' => _t('_bx_polls_txt_subentry_vote_percent', $iTotal > 0 ? round($fPercent, 2) : 0),
-                'js_code' => $oVotes->getJsScript(array('dynamic_mode' => $bDynamic))
-            );
+            ], ($this->_bIsApi ? [
+                'votes' => $oVotes->getCounterAPI(['show_counter_empty' => true, 'show_counter_in_brackets' => false]),
+            ] : [
+                'votes' => $oVotes->getCounter(['show_counter_empty' => true, 'show_counter_in_brackets' => false]),
+                'js_code' => $oVotes->getJsScript(['dynamic_mode' => $bDynamic])
+            ]));
         }
         }
 
 
-        return $this->parseHtmlByName('subentries_results.html', array(
+        return $this->_bIsApi ? $aTmplVarsSubentries : $this->parseHtmlByName('subentries_results.html', array(
             'html_id' => $this->_oConfig->getHtmlIds('content') . $iContentId,
             'html_id' => $this->_oConfig->getHtmlIds('content') . $iContentId,
             'bx_repeat:subentries' => $aTmplVarsSubentries,
             'bx_repeat:subentries' => $aTmplVarsSubentries,
         ));
         ));