AntonLV 8 лет назад
Родитель
Сommit
64e121a060

+ 35 - 0
modules/boonex/polls/classes/BxPollsModule.php

@@ -131,6 +131,41 @@ class BxPollsModule extends BxBaseModTextModule
         return $this->_serviceTemplateFunc('entryResults', $iContentId);
     }
 
+    /**
+     * @page service Service Calls
+     * @section bx_polls Polls
+     * @subsection bx_polls-page_blocks Page Blocks
+     * @subsubsection bx_polls-get_block_text_and_subentries get_block_text_and_subentries
+     * 
+     * @code bx_srv('bx_polls', 'get_block_text_and_subentries', [...]); @endcode
+     * 
+     * Get page block with poll question and answers with possibility to switch to results.
+     *
+     * @param $iContentId (optional) poll's ID. If empty value is provided, an attempt to get it from GET/POST arrays will be performed.
+     * @param $bForceDisplay (optional) if true is passed then the block will be displayed as is (without checking whether user answered the poll or not).
+     * @return HTML string with block content to display on the site or false if there is no enough input data. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
+     * 
+     * @see BxPollsModule::serviceGetBlockTextAndSubentries
+     */
+    /** 
+     * @ref bx_polls-get_block_text_and_subentries "get_block_text_and_subentries"
+     */
+    public function serviceGetBlockTextAndSubentries($iContentId = 0, $bForceDisplaySubentries = false)
+    {
+        if (!$iContentId)
+            $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
+        if (!$iContentId)
+            return false;
+
+        $mixedContent = $this->_getContent($iContentId);
+        if($mixedContent === false)
+            return false;
+
+        list($iContentId, $aContentInfo) = $mixedContent;
+
+        return $this->_oTemplate->entryTextAndSubentries($aContentInfo, $bForceDisplaySubentries);
+    }
+    
     /**
      * PERMISSION METHODS
      */

+ 59 - 27
modules/boonex/polls/classes/BxPollsTemplate.php

@@ -32,24 +32,6 @@ class BxPollsTemplate extends BxBaseModTextTemplate
         return parent::getJsCode($sType, $aParams, $bWrap);
     }
 
-    public function getTmplVarsText($aData)
-    {
-        $CNF = &$this->getModule()->_oConfig->CNF;
-
-        $aVars = parent::getTmplVarsText($aData);
-
-        $sMethod = '_getGetBlockContent' . (!$this->_oDb->isPerformed($aData[$CNF['FIELD_ID']], bx_get_logged_profile_id()) ? 'Subentries' : 'Results');
-        $sSubentries = $this->$sMethod($aData);
-
-        $aVars['bx_if:show_subentries'] = array(
-            'condition' => !empty($sSubentries),
-            'content' => array(
-                'entry_subentries' => $sSubentries
-            )
-        );
-        return $aVars;
-    }
-
     public function entrySubentries ($aData, $bDynamic = false)
     {
         $sContent = $this->_getGetBlockContentSubentries($aData, $bDynamic);
@@ -74,6 +56,50 @@ class BxPollsTemplate extends BxBaseModTextTemplate
         );
     }
 
+    public function entryTextAndSubentries($aData, $bForceDisplaySubentries = false)
+    {
+        $CNF = &$this->getModule()->_oConfig->CNF;
+
+        $sMethod = '_getGetBlockContent';
+        $sMenuItem = '';
+        if(!$bForceDisplaySubentries && $this->_oDb->isPerformed($aData[$CNF['FIELD_ID']], bx_get_logged_profile_id())) {
+            $sMethod .= 'Results';
+            $sMenuItem = 'results';
+        }
+        else {
+            $sMethod .= 'Subentries';
+            $sMenuItem = 'subentries';
+        };
+
+        $sSubentries = $this->$sMethod($aData);
+        $oMenu = $this->_getGetBlockMenu($aData, $sMenuItem);
+
+        $sMenu = str_replace('_', '-', $this->_oConfig->getName()) . '-menu-db';
+        $sMenuId = $sMenu . '-' . time() . rand(0, PHP_INT_MAX);        
+
+        $aTmplVars = parent::getTmplVarsText($aData);
+        $aTmplVars = array_merge($aTmplVars, array(
+            'menu' => BxTemplFunctions::getInstance()->designBoxMenu($oMenu, array(
+                'menu' => array(
+                    'id' => $sMenuId, 
+                    'class' => $sMenu, 
+                    'onclick' => "bx_menu_slide_inline('#" . $sMenuId . "', this, $(this).parents('.bx-db-menu:first'))"
+                )
+            )),
+            'bx_if:show_subentries' => array(
+                'condition' => !empty($sSubentries),
+                'content' => array(
+                    'entry_subentries' => $sSubentries
+                )
+            )
+        ));
+
+        return array(
+            'content' => $this->parseHtmlByName('entry-text-subentries.html', $aTmplVars),
+            'menu' => $oMenu
+        );
+    }
+
     protected function getTitle($aData)
     {
         return $this->_oConfig->getTitle($aData);
@@ -97,27 +123,33 @@ class BxPollsTemplate extends BxBaseModTextTemplate
     {
         $CNF = &$this->getModule()->_oConfig->CNF;
 
+        $sPostfix = '-' . time() . rand(0, PHP_INT_MAX);
         $sJsObject = $this->_oConfig->getJsObject('entry');
         $iContentId = $aData[$CNF['FIELD_ID']];
 
         $aBlocks = array(
-        	'subentries' => true, 
-        	'results' => (int)$aData[$CNF['FIELD_HIDDEN_RESULTS']] == 0 || $this->_oDb->isPerformed($iContentId, bx_get_logged_profile_id())
+            'subentries' => true, 
+            'results' => (int)$aData[$CNF['FIELD_HIDDEN_RESULTS']] == 0 || $this->_oDb->isPerformed($iContentId, bx_get_logged_profile_id())
         );
 
         $aMenu = array();
-        foreach($aBlocks as $sBlock => $bActive)
-            if($bActive) {
-                $sId = $this->_oConfig->getHtmlIds('block_link_' . $sBlock);
-                $aMenu[] = array('id' => $sId, 'name' => $sId, 'class' => '', 'link' => 'javascript:void(0)', 'onclick' => 'javascript:' . $sJsObject . '.changeBlock(this, \'' . $sBlock . '\', ' . $iContentId . ')', 'target' => '_self', 'title' => _t('_bx_polls_menu_item_view_' . $sBlock));
-            }
+        foreach($aBlocks as $sBlock => $bActive) {
+            if(!$bActive) 
+                continue;
+
+            $sId = $this->_oConfig->getHtmlIds('block_link_' . $sBlock) . $sPostfix;
+            if(!empty($sSelected) && $sSelected == $sBlock)
+                $sSelected = $sId;
+
+            $aMenu[] = array('id' => $sId, 'name' => $sId, 'class' => '', 'link' => 'javascript:void(0)', 'onclick' => 'javascript:' . $sJsObject . '.changeBlock(this, \'' . $sBlock . '\', ' . $iContentId . ')', 'target' => '_self', 'title' => _t('_bx_polls_menu_item_view_' . $sBlock));
+        }
 
         if(count($aMenu) <= 1)
             return '';
 
-        $oMenu = new BxTemplMenuInteractive(array('template' => 'menu_interactive_vertical.html', 'menu_id'=> $this->_oConfig->getHtmlIds('block_menu'), 'menu_items' => $aMenu));
+        $oMenu = new BxTemplMenuInteractive(array('template' => 'menu_interactive_vertical.html', 'menu_id' => $this->_oConfig->getHtmlIds('block_menu') . $sPostfix, 'menu_items' => $aMenu));
         if(!empty($sSelected))
-            $oMenu->setSelected('', $this->_oConfig->getHtmlIds('block_link_' . $sSelected));
+            $oMenu->setSelected('', $sSelected);
 
         return $oMenu;
     }

+ 1 - 0
modules/boonex/polls/install/langs/en.xml

@@ -69,6 +69,7 @@
 	<string name="_bx_polls_page_title_view_entry"><![CDATA[{title}]]></string>
 	<string name="_bx_polls_page_block_title_entry_subentries"><![CDATA[Answers]]></string>
 	<string name="_bx_polls_page_block_title_entry_text"><![CDATA[Description]]></string>
+        <string name="_bx_polls_page_block_title_entry_text_and_subentries"><![CDATA[Description and Answers]]></string>
 	<string name="_bx_polls_page_title_browse"><![CDATA[Polls]]></string>
 	<string name="_bx_polls_page_title_search_results"><![CDATA[Polls matching "{0}"]]></string>
 	<string name="_bx_polls_page_title_browse_by_author"><![CDATA[Polls of {display_name}]]></string>

+ 3 - 2
modules/boonex/polls/install/sql/enable.sql

@@ -47,8 +47,9 @@ INSERT INTO `sys_objects_page`(`object`, `title_system`, `title`, `module`, `lay
 ('bx_polls_view_entry', '_bx_polls_page_title_sys_view_entry', '_bx_polls_page_title_view_entry', 'bx_polls', 12, 2147483647, 1, 'view-poll', '', '', '', '', 0, 1, 0, 'BxPollsPageEntry', 'modules/boonex/polls/classes/BxPollsPageEntry.php');
 
 INSERT INTO `sys_pages_blocks`(`object`, `cell_id`, `module`, `title_system`, `title`, `designbox_id`, `visible_for_levels`, `type`, `content`, `deletable`, `copyable`, `active`, `order`) VALUES 
-('bx_polls_view_entry', 2, 'bx_polls', '', '_bx_polls_page_block_title_entry_text', 13, 2147483647, 'service', 'a:2:{s:6:\"module\";s:8:\"bx_polls\";s:6:\"method\";s:17:\"entity_text_block\";}', 0, 0, 1, 2),
-('bx_polls_view_entry', 1, 'bx_polls', '', '_bx_polls_page_block_title_entry_subentries', 13, 2147483647, 'service', 'a:2:{s:6:\"module\";s:8:\"bx_polls\";s:6:\"method\";s:20:\"get_block_subentries\";}', 0, 0, 0, 0),
+('bx_polls_view_entry', 2, 'bx_polls', '', '_bx_polls_page_block_title_entry_text', 13, 2147483647, 'service', 'a:2:{s:6:\"module\";s:8:\"bx_polls\";s:6:\"method\";s:17:\"entity_text_block\";}', 0, 0, 0, 0),
+('bx_polls_view_entry', 2, 'bx_polls', '', '_bx_polls_page_block_title_entry_text_and_subentries', 3, 2147483647, 'service', 'a:2:{s:6:\"module\";s:8:\"bx_polls\";s:6:\"method\";s:29:\"get_block_text_and_subentries\";}', 0, 0, 1, 2),
+('bx_polls_view_entry', 1, 'bx_polls', '', '_bx_polls_page_block_title_entry_subentries', 11, 2147483647, 'service', 'a:2:{s:6:\"module\";s:8:\"bx_polls\";s:6:\"method\";s:20:\"get_block_subentries\";}', 0, 0, 0, 0),
 ('bx_polls_view_entry', 2, 'bx_polls', '', '_bx_polls_page_block_title_entry_author', 13, 2147483647, 'service', 'a:2:{s:6:\"module\";s:8:\"bx_polls\";s:6:\"method\";s:13:\"entity_author\";}', 0, 0, 1, 1),
 ('bx_polls_view_entry', 3, 'bx_polls', '_bx_polls_page_block_title_sys_entry_context', '_bx_polls_page_block_title_entry_context', 13, 2147483647, 'service', 'a:2:{s:6:\"module\";s:8:\"bx_polls\";s:6:\"method\";s:14:\"entity_context\";}', 0, 0, 1, 1),
 ('bx_polls_view_entry', 3, 'bx_polls', '', '_bx_polls_page_block_title_entry_info', 11, 2147483647, 'service', 'a:2:{s:6:\"module\";s:8:\"bx_polls\";s:6:\"method\";s:11:\"entity_info\";}', 0, 0, 1, 2),

+ 20 - 14
modules/boonex/polls/js/entry.js

@@ -32,32 +32,38 @@ BxPollsEntry.prototype.changeBlockSnippet = function(oLink, sBlock, iContentId)
 };
 
 BxPollsEntry.prototype.changeBlock = function(oLink, sBlock, iContentId, onComplete) {
-	var $this = this;
+    var $this = this;
 
     this.loadingInBlock(oLink, true);
 
     if(typeof onComplete !== 'function')
-    	onComplete = function(iContentId, oData) {
-			$('#' + $this._aHtmlIds['content'] + iContentId).bx_anim('hide', $this._sAnimationEffect, $this._iAnimationSpeed, function() {
-	    		$(this).replaceWith(oData.content);
-	    	});
-		};
+        onComplete = function(iContentId, oData) {
+            var oContent = $(oLink).parents('.bx-db-container:first').find('.bx-polls-content');
+            if(!oContent.length)
+                oContent = $('#' + $this._aHtmlIds['content'] + iContentId);
+            if(!oContent.length)
+                return;
+
+            oContent.bx_anim('hide', $this._sAnimationEffect, $this._iAnimationSpeed, function() {
+                $(this).replaceWith(oData.content);
+            });
+        };
 
     jQuery.get (
         this._sActionsUrl + 'get_block',
         {
-        	block: sBlock,
-        	content_id: iContentId
+            block: sBlock,
+            content_id: iContentId
         },
         function(oData) {
-        	if(oLink)
-        		$this.loadingInBlock(oLink, false);
+            if(oLink)
+                $this.loadingInBlock(oLink, false);
 
-        	if(!oData.content)
-        		return;
+            if(!oData.content)
+                return;
 
-        	if(typeof onComplete === 'function')
-    			onComplete(iContentId, oData);
+            if(typeof onComplete === 'function')
+                onComplete(iContentId, oData);
         },
         'json'
     );

+ 22 - 1
modules/boonex/polls/template/css/entry.css

@@ -1,4 +1,25 @@
-/*--- Subentries ---*/
+/*--- Text and Subentries ---*/
+.bx-polls-entity-actions {
+    position: relative;
+    width: 100%;
+}
+.bx-polls-entity-actions .bx-db-menu {
+    position: absolute;
+    top: 0;
+    right: 0;
+    line-height: normal;
+}
+.bx-polls-entity-actions .bx-db-menu-tab {
+    display: inline-block;
+    float: none;
+    margin: 0;
+}
+.bx-polls-entity-actions .bx-polls-menu-db {
+    position: relative;
+    display: block;
+    margin: 0;
+    padding: 1rem;
+}
 
 /*--- Results ---*/
 div.bx-polls-result-graph {

+ 14 - 0
modules/boonex/polls/template/entry-text-subentries.html

@@ -0,0 +1,14 @@
+<div class="bx-polls-entity-actions">__menu__</div>
+<div class="bx-polls-entity-entity-content bx-content-padding-block">
+    <div class="bx-base-text-entity-content bx-base-text-entity-content bx-def-constraint-list bx-def-constraint-pre bx-def-constraint-object bx-def-constraint-iframe bx-def-constraint-img">
+        __entry_text__
+    </div>
+    <bx_if:show_image>
+        <div class="bx-base-text-entity-image bx-def-margin-top bx-def-font-align-center">
+            <img class="bx-def-border-radius-block" src="__entry_image__" />
+        </div>
+    </bx_if:show_image>
+    <bx_if:show_subentries>
+        <div class="bx-poll-entity-subentries bx-def-margin-top">__entry_subentries__</div>
+    </bx_if:show_subentries>
+</div>

+ 1 - 4
modules/boonex/polls/template/entry-text.html

@@ -5,7 +5,4 @@
     <div class="bx-base-text-entity-image bx-def-margin-top bx-def-font-align-center">
         <img class="bx-def-border-radius-block" src="__entry_image__" />
     </div>
-</bx_if:show_image>
-<bx_if:show_subentries>
-    <div class="bx-poll-entity-subentries bx-def-margin-top">__entry_subentries__</div>
-</bx_if:show_subentries>
+</bx_if:show_image>

+ 1 - 0
modules/boonex/russian/data/langs/bx_polls/ru.xml

@@ -69,6 +69,7 @@
 	<string name="_bx_polls_page_title_view_entry"><![CDATA[{title}]]></string>
 	<string name="_bx_polls_page_block_title_entry_subentries"><![CDATA[Ответы]]></string>
 	<string name="_bx_polls_page_block_title_entry_text"><![CDATA[Описание]]></string>
+        <string name="_bx_polls_page_block_title_entry_text_and_subentries"><![CDATA[Описание и ответы]]></string>
 	<string name="_bx_polls_page_title_browse"><![CDATA[Голосования]]></string>
 	<string name="_bx_polls_page_title_search_results"><![CDATA[Голосования, соответствующие "{0}"]]></string>
 	<string name="_bx_polls_page_title_browse_by_author"><![CDATA[Голосования {display_name}]]></string>