BxDolObjectVote.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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 UnaCore UNA Core
  7. * @{
  8. */
  9. class BxDolObjectVote extends BxDolObject
  10. {
  11. protected $_aVote;
  12. protected $_aElementDefaults;
  13. protected $_aElementDefaultsApi;
  14. protected $_aElementParamsApi; //--- Params from DefaultsApi array to be passed to Api
  15. protected function __construct($sSystem, $iId, $iInit = true, $oTemplate = false)
  16. {
  17. parent::__construct($sSystem, $iId, $iInit, $oTemplate);
  18. if(empty($this->_sSystem))
  19. return;
  20. $this->_aVote = [];
  21. }
  22. public static function onAuthorDelete ($iAuthorId)
  23. {
  24. $aSystems = self::getSystems();
  25. foreach($aSystems as $sSystem => $aSystem)
  26. self::getObjectInstance($sSystem, 0)->getQueryObject()->deleteAuthorEntries($iAuthorId);
  27. return true;
  28. }
  29. public function getObjectAuthorId($iObjectId = 0)
  30. {
  31. if(empty($this->_aSystem['trigger_field_author']))
  32. return 0;
  33. return $this->_oQuery->getObjectAuthorId($iObjectId ? $iObjectId : $this->getId());
  34. }
  35. /**
  36. * Interface functions for outer usage
  37. */
  38. public function isUndo()
  39. {
  40. return (int)$this->_aSystem['is_undo'] == 1;
  41. }
  42. /**
  43. * Permissions functions
  44. */
  45. public function isAllowedVote($isPerformAction = false)
  46. {
  47. if(isAdmin())
  48. return true;
  49. if(!$this->checkAction('vote', $isPerformAction))
  50. return false;
  51. $aObject = $this->_oQuery->getObjectInfo($this->_iId);
  52. if(empty($aObject) || !is_array($aObject))
  53. return false;
  54. return $this->_isAllowedVoteByObject($aObject);
  55. }
  56. public function msgErrAllowedVote()
  57. {
  58. $sMsg = $this->checkActionErrorMsg('vote');
  59. if(empty($sMsg))
  60. $sMsg = _t('_sys_txt_access_denied');
  61. return $sMsg;
  62. }
  63. public function isAllowedVoteView($isPerformAction = false)
  64. {
  65. if(isAdmin())
  66. return true;
  67. return $this->checkAction('vote_view', $isPerformAction);
  68. }
  69. public function msgErrAllowedVoteView()
  70. {
  71. return $this->checkActionErrorMsg('vote_view');
  72. }
  73. public function isAllowedVoteViewVoters($isPerformAction = false)
  74. {
  75. if(isAdmin())
  76. return true;
  77. return $this->checkAction('vote_view_voters', $isPerformAction);
  78. }
  79. public function msgErrAllowedVoteViewVoters()
  80. {
  81. return $this->checkActionErrorMsg('vote_view_voters');
  82. }
  83. /**
  84. * Internal functions
  85. */
  86. protected function _getVote($iObjectId = 0, $bForceGet = false)
  87. {
  88. if(!empty($this->_aVote) && !$bForceGet)
  89. return $this->_aVote;
  90. if(empty($iObjectId))
  91. $iObjectId = $this->getId();
  92. $this->_aVote = $this->_oQuery->getVote($iObjectId);
  93. return $this->_aVote;
  94. }
  95. protected function _getTrack($iObjectId, $iAuthorId)
  96. {
  97. return $this->_oQuery->getTrack($iObjectId, $iAuthorId);
  98. }
  99. }
  100. /** @} */