BxPollsModule.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. public function serviceGetResultsSearchExtended($aParams)
  46. {
  47. $this->_oTemplate->addJs(array('entry.js'));
  48. $this->_oTemplate->addCss(array('entry.css'));
  49. return $this->_oTemplate->getJsCode('entry') . BxDolService::call('system', 'get_results', array($aParams), 'TemplSearchExtendedServices');
  50. }
  51. public function serviceGetBlockSubentries($iContentId = 0, $bForceDisplay = false)
  52. {
  53. if (!$iContentId)
  54. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  55. if (!$iContentId)
  56. return false;
  57. if(!$bForceDisplay && $this->_oDb->isPerformed($iContentId, bx_get_logged_profile_id()))
  58. return $this->serviceGetBlockResults($iContentId);
  59. return $this->_serviceTemplateFunc('entrySubentries', $iContentId);
  60. }
  61. public function serviceGetBlockResults($iContentId = 0)
  62. {
  63. return $this->_serviceTemplateFunc('entryResults', $iContentId);
  64. }
  65. /**
  66. * PERMISSION METHODS
  67. */
  68. public function isAllowedVote($isPerformAction = false)
  69. {
  70. $aCheck = checkActionModule($this->_iProfileId, 'vote entry', $this->getName(), false);
  71. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  72. return $aCheck[CHECK_ACTION_MESSAGE];
  73. return CHECK_ACTION_RESULT_ALLOWED;
  74. }
  75. /**
  76. * INTERNAL METHODS
  77. */
  78. protected function _getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  79. {
  80. return array();
  81. }
  82. protected function _getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams = array())
  83. {
  84. $CNF = &$this->_oConfig->CNF;
  85. $bDynamic = isset($aBrowseParams['dynamic_mode']) && $aBrowseParams['dynamic_mode'] === true;
  86. $sInclude = '';
  87. $sInclude .= $this->_oTemplate->addJs(array('entry.js'), $bDynamic);
  88. $sInclude .= $this->_oTemplate->addCss(array('entry.css'), $bDynamic);
  89. $aBlock = $this->_oTemplate->{$this->_oDb->isPerformed($aContentInfo[$CNF['FIELD_ID']], bx_get_logged_profile_id()) ? 'entryResults' : 'entrySubentries'}($aContentInfo, $bDynamic);
  90. $aResult = parent::_getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams);
  91. $aResult['title'] = $this->_oConfig->getTitle($aContentInfo);
  92. $aResult['text'] = '';
  93. $aResult['raw'] = ($bDynamic ? $sInclude : '') . $this->_oTemplate->getJsCode('entry') . $aBlock['content'];
  94. return $aResult;
  95. }
  96. }
  97. /** @} */