1
0

BxBaseVoteStars.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. );
  30. $this->_sTmplNameDoVoteStars = 'vote_do_vote_stars.html';
  31. }
  32. public function getLegend($aParams = array())
  33. {
  34. $sJsObject = $this->getJsObjectName();
  35. $iMinValue = $this->getMinValue();
  36. $iMaxValue = $this->getMaxValue();
  37. $aLegend = $this->_oQuery->getLegend($this->_iId);
  38. $aTmplVarsItems = array();
  39. for($i = $iMaxValue; $i >= $iMinValue; $i--) {
  40. $aTmplVarsStars = $aTmplVarsSlider = array();
  41. for($j = $iMinValue; $j <= $iMaxValue; $j++) {
  42. $aTmplVarsStars[] = array(
  43. 'style_prefix' => $this->_sStylePrefix,
  44. 'value' => $i
  45. );
  46. $aTmplVarsSlider[] = array(
  47. 'style_prefix' => $this->_sStylePrefix
  48. );
  49. }
  50. $aTmplVarsItems[] = array(
  51. 'style_prefix' => $this->_sStylePrefix,
  52. 'value' => $i,
  53. 'bx_repeat:stars' => $aTmplVarsStars,
  54. 'bx_repeat:slider' => $aTmplVarsSlider,
  55. 'label' => isset($aLegend[$i]['count']) ? (int)$aLegend[$i]['count'] : 0
  56. );
  57. }
  58. return $this->_oTemplate->parseHtmlByName($this->_sTmplNameLegend, array(
  59. 'style_prefix' => $this->_sStylePrefix,
  60. 'html_id' => $this->_aHtmlIds['legend_stars'],
  61. 'type' => $this->_sType,
  62. 'bx_repeat:items' => $aTmplVarsItems
  63. ));
  64. }
  65. /**
  66. * Internal methods.
  67. */
  68. protected function _getTmplVarsElement($aParams = array())
  69. {
  70. $aTmplVars = parent::_getTmplVarsElement($aParams);
  71. $aVote = $this->_getVote();
  72. $aTmplVars['bx_if:show_vote_data'] = array(
  73. 'condition' => true,
  74. 'content' => array(
  75. 'rate' => $aVote['rate'],
  76. 'count' => $aVote['count']
  77. )
  78. );
  79. return $aTmplVars;
  80. }
  81. protected function _getDoVote($aParams = array(), $isAllowedVote = true)
  82. {
  83. $sJsObject = $this->getJsObjectName();
  84. $iMinValue = $this->getMinValue();
  85. $iMaxValue = $this->getMaxValue();
  86. $aTmplVarsStars = $aTmplVarsLegend = $aTmplVarsSlider = $aTmplVarsButtons = array();
  87. for($i = $iMinValue; $i <= $iMaxValue; $i++) {
  88. $aTmplVarsStars[] = array(
  89. 'style_prefix' => $this->_sStylePrefix,
  90. 'value' => $i
  91. );
  92. $aTmplVarsLegend[] = array(
  93. 'style_prefix' => $this->_sStylePrefix,
  94. 'value' => $i
  95. );
  96. $aTmplVarsSlider[] = array(
  97. 'style_prefix' => $this->_sStylePrefix
  98. );
  99. if($isAllowedVote)
  100. $aTmplVarsButtons[] = array(
  101. 'style_prefix' => $this->_sStylePrefix,
  102. 'js_object' => $sJsObject,
  103. 'value' => $i
  104. );
  105. }
  106. return $this->_oTemplate->parseHtmlByName($this->_sTmplNameDoVoteStars, array(
  107. 'style_prefix' => $this->_sStylePrefix,
  108. 'bx_repeat:stars' => $aTmplVarsStars,
  109. 'bx_if:show_legend' => array(
  110. 'condition' => isset($aParams['show_do_vote_legend']) && $aParams['show_do_vote_legend'] === true,
  111. 'content' => array(
  112. 'style_prefix' => $this->_sStylePrefix,
  113. 'bx_repeat:legend' => $aTmplVarsLegend,
  114. )
  115. ),
  116. 'bx_repeat:slider' => $aTmplVarsSlider,
  117. 'bx_repeat:buttons' => $aTmplVarsButtons,
  118. ));
  119. }
  120. protected function _isShowLegend($aParams, $isAllowedVote, $isAllowedVoteView, $bCount)
  121. {
  122. return isset($aParams['show_legend']) && $aParams['show_legend'] === true && $isAllowedVoteView;
  123. }
  124. }
  125. /** @} */