BxBaseModTextVotePollAnswers.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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 BaseText Base classes for text modules
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxBaseModTextVotePollAnswers extends BxTemplVoteLikes
  12. {
  13. protected $_sModule;
  14. protected $_oModule;
  15. protected $_aObjectInfo;
  16. protected $_aPollInfo;
  17. protected $_bHiddenResults;
  18. protected $_bAnonymousVoting;
  19. protected $_sTmplNameElementBlock;
  20. function __construct($sSystem, $iId, $iInit = 1)
  21. {
  22. $this->_oModule = BxDolModule::getInstance($this->_sModule);
  23. parent::__construct($sSystem, $iId, $iInit, $this->_oModule->_oTemplate);
  24. $CNF = &$this->_oModule->_oConfig->CNF;
  25. $this->_aElementDefaults = array_merge($this->_aElementDefaults, array(
  26. 'show_do_vote_label' => true,
  27. 'show_counter' => false
  28. ));
  29. $this->_aObjectInfo = $this->_oModule->_oDb->getPollAnswers(array('type' => 'id', 'id' => $iId));
  30. $this->_aPollInfo = $this->_oModule->_oDb->getPolls(array('type' => 'answer_id', 'answer_id' => $iId));
  31. $this->_bHiddenResults = $CNF['PARAM_POLL_HIDDEN_RESULTS'];
  32. $this->_bAnonymousVoting = $CNF['PARAM_POLL_ANONYMOUS_VOTING'];
  33. $this->_sTmplNameElementBlock = 'poll_answer_ve_block.html';
  34. }
  35. public function getJsClick($iValue = 0)
  36. {
  37. $CNF = &$this->_oModule->_oConfig->CNF;
  38. $sJsObjectVote = $this->getJsObjectName();
  39. $sJsObjectPoll = $this->_oModule->_oConfig->getJsObject('poll');
  40. return $sJsObjectVote . '.vote(this, ' . $this->getValue() . ', function(oLink, oData) {' . $sJsObjectPoll . '.onPollAnswerVote(oLink, oData, ' . $this->_aPollInfo[$CNF['FIELD_POLL_ID']] . ');})';
  41. }
  42. public function getCounter($aParams = array())
  43. {
  44. $CNF = &$this->_oModule->_oConfig->CNF;
  45. $bShowInBrackets = !isset($aParams['show_counter_in_brackets']) || $aParams['show_counter_in_brackets'] == true;
  46. $iObjectId = $this->getId();
  47. $iAuthorId = $this->_getAuthorId();
  48. if($this->_bHiddenResults)
  49. if(!$this->isPerformed($iObjectId, $iAuthorId))
  50. return '';
  51. $sResult = parent::getCounter($aParams);
  52. if($bShowInBrackets)
  53. $sResult = '(' . $sResult . ')';
  54. return $sResult;
  55. }
  56. public function getObjectAuthorId($iObjectId = 0)
  57. {
  58. if(empty($this->_aSystem['trigger_field_author']))
  59. return 0;
  60. $aPoll = $this->_oModule->_oDb->getPolls(array('type' => 'answer_id', 'answer_id' => $iObjectId ? $iObjectId : $this->getId()));
  61. if(empty($aPoll) || !is_array($aPoll))
  62. return 0;
  63. return $aPoll[$this->_aSystem['trigger_field_author']];
  64. }
  65. public function isPerformed($iObjectId, $iAuthorId, $iAuthorIp = 0)
  66. {
  67. $CNF = &$this->_oModule->_oConfig->CNF;
  68. return $this->_oModule->isPollPerformed((int)$this->_aPollInfo[$CNF['FIELD_POLL_ID']], $iAuthorId, $iAuthorIp);
  69. }
  70. /**
  71. * Permissions functions
  72. */
  73. public function isAllowedVote($isPerformAction = false)
  74. {
  75. if(!parent::isAllowedVote($isPerformAction))
  76. return false;
  77. $CNF = &$this->_oModule->_oConfig->CNF;
  78. $iContentId = $this->_aPollInfo[$CNF['FIELD_POLL_CONTENT_ID']];
  79. if(empty($iContentId))
  80. return true;
  81. $aContentInfo = $this->_oModule->_oDb->getContentInfoById($iContentId);
  82. return $this->_oModule->checkAllowedView($aContentInfo) === CHECK_ACTION_RESULT_ALLOWED;
  83. }
  84. public function isAllowedVoteViewVoters($isPerformAction = false)
  85. {
  86. if($this->_bAnonymousVoting)
  87. return false;
  88. return parent::isAllowedVoteViewVoters($isPerformAction);
  89. }
  90. /**
  91. * Internal functions
  92. */
  93. protected function _getIconDo($bVoted)
  94. {
  95. return $bVoted ? 'far dot-circle' : 'far circle';
  96. }
  97. protected function _getTitleDo($bVoted)
  98. {
  99. return bx_process_output($this->_aObjectInfo['title']);
  100. }
  101. protected function _getTitleDoBy($aParams = array())
  102. {
  103. $CNF = &$this->_oModule->_oConfig->CNF;
  104. return _t($CNF['T']['txt_poll_answer_vote_do_by']);
  105. }
  106. protected function _getCounterLabel($iCount, $aParams = array())
  107. {
  108. $CNF = &$this->_oModule->_oConfig->CNF;
  109. return _t($CNF['T']['txt_poll_answer_vote_counter'], $iCount);
  110. }
  111. protected function _isShowDoVote($aParams, $isAllowedVote, $bCount)
  112. {
  113. return !isset($aParams['show_do_vote']) || $aParams['show_do_vote'] == true;
  114. }
  115. protected function _getTmplContentElementBlock()
  116. {
  117. return $this->_oTemplate->getHtml($this->_sTmplNameElementBlock);
  118. }
  119. }
  120. /** @} */