BxDolVoteStars.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. /**
  10. * Star based votes for any content
  11. */
  12. class BxDolVoteStars extends BxTemplVote
  13. {
  14. public function __construct($sSystem, $iId, $iInit = true, $oTemplate = false)
  15. {
  16. parent::__construct($sSystem, $iId, $iInit, $oTemplate);
  17. $this->_oQuery = new BxDolVoteStarsQuery($this);
  18. $this->_sType = BX_DOL_VOTE_TYPE_STARS;
  19. }
  20. /**
  21. * Interface functions for outer usage
  22. */
  23. public function getValue($bVoted)
  24. {
  25. $iObjectId = $this->getId();
  26. $iAuthorId = $this->_getAuthorId();
  27. $iValue = 0;
  28. if($bVoted && ($aTrack = $this->_getTrack($iObjectId, $iAuthorId)) && is_array($aTrack))
  29. $iValue = (int)$aTrack['value'];
  30. return $iValue;
  31. }
  32. /**
  33. * Internal functions
  34. */
  35. protected function _isDuplicate($iObjectId, $iAuthorId, $iAuthorIp, $bVoted)
  36. {
  37. if($bVoted && $this->isUndo())
  38. return false;
  39. return !$this->_oQuery->isPostTimeoutEnded($iObjectId, $iAuthorId, $iAuthorIp);
  40. }
  41. protected function _getVote($iObjectId = 0, $bForceGet = false)
  42. {
  43. $aVote = parent::_getVote($iObjectId, $bForceGet);
  44. if(isset($aVote['rate']))
  45. $aVote['rate'] = (float)$aVote['rate'];
  46. return $aVote;
  47. }
  48. }
  49. /** @} */