1
0

BxBaseModTextVotePollAnswers.php 4.8 KB

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