BxPollsVoteSubentries.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. class BxPollsVoteSubentries extends BxTemplVoteLikes
  12. {
  13. protected $_sModule;
  14. protected $_oModule;
  15. protected $_aObjectInfo;
  16. protected $_aContentInfo;
  17. protected $_sTmplNameElementBlock;
  18. // A poll vote follows the object's IsUndo setting, unlike a like.
  19. protected $_bUndoAlways = false;
  20. function __construct($sSystem, $iId, $iInit = 1)
  21. {
  22. $this->_sModule = 'bx_polls';
  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 = array_merge($this->_aElementDefaults, array(
  27. 'show_do_vote_label' => true,
  28. 'show_counter' => false
  29. ));
  30. $this->_aObjectInfo = $this->_oModule->_oDb->getSubentries(array('type' => 'id', 'id' => $iId));
  31. $this->_aContentInfo = array();
  32. $this->_sTmplNameElementBlock = 'subentries_ve_block.html';
  33. }
  34. public function setEntry($aEntry)
  35. {
  36. $this->_aContentInfo = $aEntry;
  37. }
  38. public function getEntryField($sField)
  39. {
  40. if(empty($this->_aContentInfo))
  41. $this->_aContentInfo = $this->_oModule->_oDb->getContentInfoBySubentryId($this->getId());
  42. return isset($this->_aContentInfo[$sField]) ? $this->_aContentInfo[$sField] : false;
  43. }
  44. public function getJsClick($iValue = 0)
  45. {
  46. $CNF = $this->_oModule->_oConfig->CNF;
  47. $sJsObjectVote = $this->getJsObjectName();
  48. $sJsObjectEntry = $this->_oModule->_oConfig->getJsObject('entry');
  49. return $sJsObjectVote . '.vote(this, ' . $this->getValue() . ', function(oLink, oData) {' . $sJsObjectEntry . '.onVote(oLink, oData, ' . $this->getEntryField($CNF['FIELD_ID']) . ', \'' . $this->getEntryField('salt') . '\');})';
  50. }
  51. public function getCounter($aParams = array())
  52. {
  53. $CNF = $this->_oModule->_oConfig->CNF;
  54. $bShowInBrackets = !isset($aParams['show_counter_in_brackets']) || $aParams['show_counter_in_brackets'] == true;
  55. $iObjectId = $this->getId();
  56. $iAuthorId = $this->_getAuthorId();
  57. if((int)$this->getEntryField($CNF['FIELD_HIDDEN_RESULTS']) == 1)
  58. if(!$this->isPerformed($iObjectId, $iAuthorId))
  59. return '';
  60. $sResult = parent::getCounter($aParams);
  61. if($bShowInBrackets)
  62. $sResult = '(' . $sResult . ')';
  63. return $sResult;
  64. }
  65. public function getObjectAuthorId($iObjectId = 0)
  66. {
  67. if(empty($this->_aSystem['trigger_field_author']))
  68. return 0;
  69. $aContentInfo = $this->_oModule->_oDb->getContentInfoBySubentryId($iObjectId ? $iObjectId : $this->getId());
  70. return $aContentInfo[$this->_aSystem['trigger_field_author']];
  71. }
  72. public function isPerformed($iObjectId, $iAuthorId, $iAuthorIp = 0)
  73. {
  74. $CNF = $this->_oModule->_oConfig->CNF;
  75. return $this->_oModule->isPerformed((int)$this->getEntryField($CNF['FIELD_ID']), $iAuthorId, $iAuthorIp);
  76. }
  77. /**
  78. * Permissions functions
  79. */
  80. public function isAllowedVote($isPerformAction = false)
  81. {
  82. return $this->_oModule->isAllowedVote($isPerformAction) === CHECK_ACTION_RESULT_ALLOWED;
  83. }
  84. public function isAllowedVoteViewVoters($isPerformAction = false)
  85. {
  86. $CNF = $this->_oModule->_oConfig->CNF;
  87. if((int)$this->getEntryField($CNF['FIELD_ANONYMOUS_VOTING']) == 1)
  88. return false;
  89. return parent::isAllowedVoteViewVoters($isPerformAction);
  90. }
  91. /**
  92. * Internal functions
  93. */
  94. protected function _getIconDo($bVoted)
  95. {
  96. return $bVoted ? 'far dot-circle' : 'far circle';
  97. }
  98. protected function _getTitleDo($bVoted)
  99. {
  100. return bx_process_output($this->_aObjectInfo['title']);
  101. }
  102. protected function _getTitleDoBy($aParams = array())
  103. {
  104. return _t('_bx_polls_txt_subentry_vote_do_by');
  105. }
  106. protected function _getCounterLabel($iCount, $aParams = array())
  107. {
  108. return _t('_bx_polls_txt_subentry_vote_counter', $iCount);
  109. }
  110. protected function _isShowDoVote($aParams, $isAllowedVote, $bCount)
  111. {
  112. return !isset($aParams['show_do_vote']) || $aParams['show_do_vote'] == true;
  113. }
  114. protected function _getTmplContentElementBlock()
  115. {
  116. return $this->_oTemplate->getHtml($this->_sTmplNameElementBlock);
  117. }
  118. }
  119. /** @} */