1
0

BxBaseVoteStars.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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 UnaBaseView UNA Base Representation Classes
  7. * @{
  8. */
  9. /**
  10. * @see BxDolVote
  11. */
  12. class BxBaseVoteStars extends BxDolVoteStars
  13. {
  14. protected $_sTmplNameDoVoteStars;
  15. public function __construct($sSystem, $iId, $iInit = true, $oTemplate = false)
  16. {
  17. parent::__construct($sSystem, $iId, $iInit, $oTemplate);
  18. $this->_sJsClsName .= 'Stars';
  19. $sHtmlId = str_replace(array('_' , ' '), array('-', '-'), $sSystem) . '-' . $iId;
  20. $this->_aHtmlIds = array_merge($this->_aHtmlIds, array(
  21. 'main' => 'bx-vote-stars-' . $sHtmlId,
  22. 'legend_stars' => 'bx-vote-stars-legend-' . $sHtmlId,
  23. ));
  24. $this->_aElementDefaults = array(
  25. 'show_do_vote_legend' => false,
  26. 'show_counter' => true,
  27. 'show_counter_empty' => false,
  28. 'show_legend' => false,
  29. 'show_script' => true
  30. );
  31. $this->_sTmplNameDoVoteStars = 'vote_do_vote_stars.html';
  32. }
  33. public function getLegend($aParams = array())
  34. {
  35. $sJsObject = $this->getJsObjectName();
  36. $iMinValue = $this->getMinValue();
  37. $iMaxValue = $this->getMaxValue();
  38. $aLegend = $this->_oQuery->getLegend($this->_iId);
  39. $aTmplVarsItems = array();
  40. for($i = $iMaxValue; $i >= $iMinValue; $i--) {
  41. $aTmplVarsStars = $aTmplVarsSlider = array();
  42. for($j = $iMinValue; $j <= $iMaxValue; $j++) {
  43. $aTmplVarsStars[] = array(
  44. 'style_prefix' => $this->_sStylePrefix,
  45. 'value' => $i
  46. );
  47. $aTmplVarsSlider[] = array(
  48. 'style_prefix' => $this->_sStylePrefix
  49. );
  50. }
  51. $aTmplVarsItems[] = array(
  52. 'style_prefix' => $this->_sStylePrefix,
  53. 'value' => $i,
  54. 'bx_repeat:stars' => $aTmplVarsStars,
  55. 'bx_repeat:slider' => $aTmplVarsSlider,
  56. 'label' => isset($aLegend[$i]['count']) ? (int)$aLegend[$i]['count'] : 0
  57. );
  58. }
  59. return $this->_oTemplate->parseHtmlByName($this->_sTmplNameLegend, array(
  60. 'style_prefix' => $this->_sStylePrefix,
  61. 'html_id' => $this->_aHtmlIds['legend_stars'],
  62. 'type' => $this->_sType,
  63. 'bx_repeat:items' => $aTmplVarsItems
  64. ));
  65. }
  66. /**
  67. * Internal methods.
  68. */
  69. protected function _getTmplVarsElement($aParams = array())
  70. {
  71. $aTmplVars = parent::_getTmplVarsElement($aParams);
  72. $aVote = $this->_getVote();
  73. $aTmplVars['bx_if:show_vote_data'] = array(
  74. 'condition' => true,
  75. 'content' => array(
  76. 'rate' => $aVote['rate'],
  77. 'count' => $aVote['count']
  78. )
  79. );
  80. return $aTmplVars;
  81. }
  82. protected function _getDoVote($aParams = array(), $isAllowedVote = true)
  83. {
  84. $sJsObject = $this->getJsObjectName();
  85. $iMinValue = $this->getMinValue();
  86. $iMaxValue = $this->getMaxValue();
  87. $aTmplVarsStars = $aTmplVarsLegend = $aTmplVarsSlider = $aTmplVarsButtons = array();
  88. for($i = $iMinValue; $i <= $iMaxValue; $i++) {
  89. $aTmplVarsStars[] = array(
  90. 'style_prefix' => $this->_sStylePrefix,
  91. 'value' => $i
  92. );
  93. $aTmplVarsLegend[] = array(
  94. 'style_prefix' => $this->_sStylePrefix,
  95. 'value' => $i
  96. );
  97. $aTmplVarsSlider[] = array(
  98. 'style_prefix' => $this->_sStylePrefix
  99. );
  100. if($isAllowedVote)
  101. $aTmplVarsButtons[] = array(
  102. 'style_prefix' => $this->_sStylePrefix,
  103. 'js_object' => $sJsObject,
  104. 'value' => $i
  105. );
  106. }
  107. return $this->_oTemplate->parseHtmlByName($this->_sTmplNameDoVoteStars, array(
  108. 'style_prefix' => $this->_sStylePrefix,
  109. 'bx_repeat:stars' => $aTmplVarsStars,
  110. 'bx_if:show_legend' => array(
  111. 'condition' => isset($aParams['show_do_vote_legend']) && $aParams['show_do_vote_legend'] === true,
  112. 'content' => array(
  113. 'style_prefix' => $this->_sStylePrefix,
  114. 'bx_repeat:legend' => $aTmplVarsLegend,
  115. )
  116. ),
  117. 'bx_repeat:slider' => $aTmplVarsSlider,
  118. 'bx_repeat:buttons' => $aTmplVarsButtons,
  119. ));
  120. }
  121. protected function _isShowLegend($aParams, $isAllowedVote, $isAllowedVoteView, $bCount)
  122. {
  123. return isset($aParams['show_legend']) && $aParams['show_legend'] === true && $isAllowedVoteView;
  124. }
  125. }
  126. /** @} */