BxBaseVotingView.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. /**
  3. * @package Dolphin Core
  4. * @copyright Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  5. * @license CC-BY - http://creativecommons.org/licenses/by/3.0/
  6. */
  7. defined('BX_DOL') or die('hack attempt');
  8. bx_import('BxDolVoting');
  9. bx_import('BxDolTemplate');
  10. /**
  11. * @see BxDolVoting
  12. */
  13. class BxBaseVotingView extends BxDolVoting
  14. {
  15. var $_iSizeStarBigX = 18;
  16. var $_iSizeStarBigY = 16;
  17. var $_iSizeStarSmallX = 11;
  18. var $_iSizeStarSmallY = 15;
  19. function BxBaseVotingView( $sSystem, $iId, $iInit = 1 )
  20. {
  21. BxDolVoting::BxDolVoting( $sSystem, $iId, $iInit );
  22. }
  23. function getSmallVoting ($iCanRate = 1, $iVoteRateOverride = false)
  24. {
  25. if ($iCanRate != 0) {
  26. if (!$this->checkAction()) $iCanRate = 0;
  27. }
  28. return $this->getVoting($iCanRate, $this->_iSizeStarSmallX, $this->_iSizeStarSmallY, 'small', 0, true, $iVoteRateOverride);
  29. }
  30. function getManySmallVoting($iCanRate = 1, $iID = 0, $isShowCount = true, $iVoteRateOverride = false)
  31. {
  32. if ($iCanRate != 0) {
  33. if (!$this->checkAction()) $iCanRate = 0;
  34. }
  35. return $this->getVoting($iCanRate, $this->_iSizeStarSmallX, $this->_iSizeStarSmallY, 'small', $iID, $isShowCount, $iVoteRateOverride);
  36. }
  37. function getBigVoting ($iCanRate = 1, $iVoteRateOverride = false)
  38. {
  39. if ($iCanRate != 0) {
  40. if (!$this->checkAction()) $iCanRate = 0;
  41. }
  42. return $this->getVoting($iCanRate, $this->_iSizeStarBigX, $this->_iSizeStarBigY, 'big', 0, true, $iVoteRateOverride);
  43. }
  44. function getJustVotingElement($iCanRate, $iPossibleID = 0, $iVoteRateOverride = false)
  45. {
  46. return $this->getManySmallVoting($iCanRate, $iPossibleID, false, $iVoteRateOverride);
  47. }
  48. function getVoting($iCanRate, $iSizeX, $iSizeY, $sName, $iPossibleID = 0, $isShowCount = true, $iVoteRateOverride = false) {
  49. $oSysTemplate = BxDolTemplate::getInstance();
  50. $sSiteUrl = BX_DOL_URL_ROOT;
  51. $iMax = $this->getMaxVote();
  52. $iWidth = $iSizeX*$iMax;
  53. $sSystemName = $this->getSystemName();
  54. $iObjId = $iPossibleID ? $iPossibleID : $this->getId();
  55. $sDivId = $this->getSystemName() . $sName;
  56. if ($iPossibleID>0) {
  57. $sDivId .= $iPossibleID;
  58. }
  59. $sRet = '<div class="votes_'.$sName.'" id="' . $sDivId . '">';
  60. if ($iCanRate)
  61. $sRet .= <<<EOF
  62. <script language="javascript">
  63. var oVoting{$sDivId} = new BxDolVoting('{$sSiteUrl}', '{$sSystemName}', '{$iObjId}', '{$sDivId}', '{$sDivId}Slider', {$iSizeX}, {$iMax});
  64. </script>
  65. EOF;
  66. $sRet .= '<div class="votes_gray_'.$sName.'" style="width:'.$iWidth.'px;">';
  67. if ($iCanRate)
  68. {
  69. $sRet .= '<div class="votes_buttons">';
  70. for ($i=1 ; $i<=$iMax ; ++$i)
  71. {
  72. $sRet .= '<a href="javascript:'.$i.';void(0);" onmouseover="oVoting'.$sDivId.'.over('.$i.');" onmouseout="oVoting'.$sDivId.'.out();" onclick="oVoting'.$sDivId.'.vote('.$i.')"><img class="votes_button_' . $sName . '" src="' . $oSysTemplate->getImageUrl('vote_star_null.gif') . '" alt="" /></a>';
  73. }
  74. $sRet .= '</div>';
  75. }
  76. $iVoteRate = (false === $iVoteRateOverride ? $this->getVoteRate() : $iVoteRateOverride);
  77. $sRet .= '<div id="'.$sDivId.'Slider" class="votes_active_'.$sName.'" style="width:'.round($iVoteRate*($iMax ? $iWidth/$iMax : 0)).'px;"></div>';
  78. $sRet .= '</div>';
  79. if ($isShowCount)
  80. $sRet .= '<b>'.$this->getVoteCount(). ' ' . _t('_votes') . '</b>';
  81. $sRet .= '<div class="clear_both"></div>';
  82. $sRet .= '</div>';
  83. return $sRet;
  84. }
  85. function getExtraJs () {
  86. BxDolTemplate::getInstance()->addJs('BxDolVoting.js');
  87. }
  88. }