BxPollsModule.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. }
  20. /**
  21. * ACTION METHODS
  22. */
  23. public function actionGetBlock()
  24. {
  25. $iContentId = (int)bx_get('content_id');
  26. $sBlock = bx_process_input(bx_get('block'));
  27. $sMethod = 'serviceGetBlock' . bx_gen_method_name($sBlock);
  28. if(!method_exists($this, $sMethod))
  29. return echoJson(array());
  30. $aBlock = $this->$sMethod($iContentId);
  31. if(empty($aBlock) || !is_array($aBlock))
  32. return echoJson(array());
  33. return echoJson(array(
  34. 'content' => $aBlock['content']
  35. ));
  36. }
  37. /**
  38. * SERVICE METHODS
  39. */
  40. public function serviceGetBlockSubentries($iContentId = 0)
  41. {
  42. return $this->_serviceTemplateFunc('entrySubentries', $iContentId);
  43. }
  44. public function serviceGetBlockResults($iContentId = 0)
  45. {
  46. return $this->_serviceTemplateFunc('entryResults', $iContentId);
  47. }
  48. /**
  49. * PERMISSION METHODS
  50. */
  51. public function isAllowedVote($isPerformAction = false)
  52. {
  53. $aCheck = checkActionModule($this->_iProfileId, 'vote entry', $this->getName(), false);
  54. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  55. return $aCheck[CHECK_ACTION_MESSAGE];
  56. return CHECK_ACTION_RESULT_ALLOWED;
  57. }
  58. /**
  59. * INTERNAL METHODS
  60. */
  61. protected function _getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl)
  62. {
  63. return array();
  64. }
  65. protected function _getContentForTimelinePost($aEvent, $aContentInfo)
  66. {
  67. $aBlock = $this->_oTemplate->entrySubentries($aContentInfo);
  68. $aResult = parent::_getContentForTimelinePost($aEvent, $aContentInfo);
  69. $aResult['title'] = $this->_oConfig->getTitle($aContentInfo);
  70. $aResult['text'] = '';
  71. $aResult['raw'] = $this->_oTemplate->getJsCode('entry') . $aBlock['content'];
  72. $this->_oTemplate->addJs(array('entry.js'));
  73. $this->_oTemplate->addCss(array('entry.css'));
  74. return $aResult;
  75. }
  76. }
  77. /** @} */