BxPollsModule.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup Polls Polls
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. /**
  12. * Polls module
  13. */
  14. class BxPollsModule extends BxBaseModTextModule
  15. {
  16. function __construct(&$aModule)
  17. {
  18. parent::__construct($aModule);
  19. $CNF = &$this->_oConfig->CNF;
  20. $this->_aSearchableNamesExcept = array_merge($this->_aSearchableNamesExcept, array(
  21. $CNF['FIELD_ANONYMOUS'],
  22. $CNF['FIELD_HIDDEN_RESULTS']
  23. ));
  24. }
  25. /**
  26. * ACTION METHODS
  27. */
  28. public function actionGetBlock()
  29. {
  30. $iContentId = (int)bx_get('content_id');
  31. $sBlock = bx_process_input(bx_get('block'));
  32. $sMethod = 'serviceGetBlock' . bx_gen_method_name($sBlock);
  33. if(!method_exists($this, $sMethod))
  34. return echoJson(array());
  35. $aBlock = $this->$sMethod($iContentId, true);
  36. if(empty($aBlock) || !is_array($aBlock))
  37. return echoJson(array());
  38. return echoJson(array(
  39. 'content' => $aBlock['content']
  40. ));
  41. }
  42. /**
  43. * SERVICE METHODS
  44. */
  45. /**
  46. * @page service Service Calls
  47. * @section bx_polls Polls
  48. * @subsection bx_polls-page_blocks Page Blocks
  49. * @subsubsection bx_polls-get_results_search_extended get_results_search_extended
  50. *
  51. * @code bx_srv('bx_polls', 'get_results_search_extended', [...]); @endcode
  52. *
  53. * Get page block with the results of Extended Search.
  54. *
  55. * @param $aParams an array with search params.
  56. * @return HTML string with block content to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  57. *
  58. * @see BxPollsModule::serviceGetResultsSearchExtended
  59. */
  60. /**
  61. * @ref bx_polls-get_results_search_extended "get_results_search_extended"
  62. */
  63. public function serviceGetResultsSearchExtended($aParams)
  64. {
  65. $this->_oTemplate->addJs(array('entry.js'));
  66. $this->_oTemplate->addCss(array('entry.css'));
  67. return $this->_oTemplate->getJsCode('entry') . BxDolService::call('system', 'get_results', array($aParams), 'TemplSearchExtendedServices');
  68. }
  69. /**
  70. * @page service Service Calls
  71. * @section bx_polls Polls
  72. * @subsection bx_polls-page_blocks Page Blocks
  73. * @subsubsection bx_polls-get_block_subentries get_block_subentries
  74. *
  75. * @code bx_srv('bx_polls', 'get_block_subentries', [...]); @endcode
  76. *
  77. * Get page block with poll questions.
  78. *
  79. * @param $iContentId (optional) poll's ID. If empty value is provided, an attempt to get it from GET/POST arrays will be performed.
  80. * @param $bForceDisplay (optional) if true is passed then the block will be displayed as is (without checking whether user answered the poll or not).
  81. * @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.
  82. *
  83. * @see BxPollsModule::serviceGetBlockSubentries
  84. */
  85. /**
  86. * @ref bx_polls-get_block_subentries "get_block_subentries"
  87. */
  88. public function serviceGetBlockSubentries($iContentId = 0, $bForceDisplay = false)
  89. {
  90. if (!$iContentId)
  91. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  92. if (!$iContentId)
  93. return false;
  94. if(!$bForceDisplay && $this->_oDb->isPerformed($iContentId, bx_get_logged_profile_id()))
  95. return $this->serviceGetBlockResults($iContentId);
  96. return $this->_serviceTemplateFunc('entrySubentries', $iContentId);
  97. }
  98. /**
  99. * @page service Service Calls
  100. * @section bx_polls Polls
  101. * @subsection bx_polls-page_blocks Page Blocks
  102. * @subsubsection bx_polls-get_block_results get_block_results
  103. *
  104. * @code bx_srv('bx_polls', 'get_block_results', [...]); @endcode
  105. *
  106. * Get page block with poll results.
  107. *
  108. * @param $iContentId (optional) poll's ID. If empty value is provided, an attempt to get it from GET/POST arrays will be performed.
  109. * @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.
  110. *
  111. * @see BxPollsModule::serviceGetBlockResults
  112. */
  113. /**
  114. * @ref bx_polls-get_block_results "get_block_results"
  115. */
  116. public function serviceGetBlockResults($iContentId = 0)
  117. {
  118. return $this->_serviceTemplateFunc('entryResults', $iContentId);
  119. }
  120. /**
  121. * PERMISSION METHODS
  122. */
  123. public function isAllowedVote($isPerformAction = false)
  124. {
  125. $aCheck = checkActionModule($this->_iProfileId, 'vote entry', $this->getName(), false);
  126. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  127. return $aCheck[CHECK_ACTION_MESSAGE];
  128. return CHECK_ACTION_RESULT_ALLOWED;
  129. }
  130. /**
  131. * INTERNAL METHODS
  132. */
  133. protected function _getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  134. {
  135. return array();
  136. }
  137. protected function _getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams = array())
  138. {
  139. $CNF = &$this->_oConfig->CNF;
  140. $bDynamic = isset($aBrowseParams['dynamic_mode']) && $aBrowseParams['dynamic_mode'] === true;
  141. $sInclude = '';
  142. $sInclude .= $this->_oTemplate->addJs(array('entry.js'), $bDynamic);
  143. $sInclude .= $this->_oTemplate->addCss(array('entry.css'), $bDynamic);
  144. $aBlock = $this->_oTemplate->{$this->_oDb->isPerformed($aContentInfo[$CNF['FIELD_ID']], bx_get_logged_profile_id()) ? 'entryResults' : 'entrySubentries'}($aContentInfo, $bDynamic);
  145. $aResult = parent::_getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams);
  146. $aResult['title'] = $this->_oConfig->getTitle($aContentInfo);
  147. $aResult['text'] = '';
  148. $aResult['raw'] = ($bDynamic ? $sInclude : '') . $this->_oTemplate->getJsCode('entry') . $aBlock['content'];
  149. return $aResult;
  150. }
  151. }
  152. /** @} */