BxBaseCmtsReviews.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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 BxDolCmtsReviews
  11. */
  12. class BxBaseCmtsReviews extends BxDolCmtsReviews
  13. {
  14. function __construct( $sSystem, $iId, $iInit = true, $oTemplate = false)
  15. {
  16. parent::__construct($sSystem, $iId, $iInit, $oTemplate);
  17. $this->_sTmplNameItem = 'review.html';
  18. $this->_sJsObjClass = 'BxDolCmtsReviews';
  19. }
  20. public function getStylePrefix()
  21. {
  22. return $this->_sStylePrefix;
  23. }
  24. public function getComment($mixedCmt, $aBp = array(), $aDp = array())
  25. {
  26. $sResult = parent::getComment($mixedCmt, $aBp, $aDp);
  27. if(empty($sResult))
  28. return $sResult;
  29. $sMood = $this->_getMood($mixedCmt, $aDp);
  30. return $this->_oTemplate->parseHtmlByContent($sResult, array(
  31. 'bx_if:show_mood' => array(
  32. 'condition' => !empty($sMood),
  33. 'content' => array(
  34. 'style_prefix' => $this->_sStylePrefix,
  35. 'mood' => $sMood
  36. )
  37. )
  38. ));
  39. }
  40. function getRatingBlock($aDp = array())
  41. {
  42. $mixedResult = $this->isViewAllowed();
  43. if($mixedResult !== CHECK_ACTION_RESULT_ALLOWED)
  44. return $mixedResult;
  45. $aBp = array();
  46. $this->_getParams($aBp, $aDp);
  47. $iId = $this->getId();
  48. $aStats = $this->_oQuery->getReviewsStats($iId);
  49. if(!empty($aStats) && is_array($aStats) && (int)$aStats['count'] > 0)
  50. $sContent = $this->_oTemplate->parseHtmlByName('reviews_rating_block.html', array(
  51. 'style_prefix' => $this->_sStylePrefix,
  52. 'system' => $this->_sSystem,
  53. 'id' => $iId,
  54. 'content' => $this->_oTemplate->parseHtmlByName('review_mood_legend.html', array_merge(array(
  55. 'style_prefix' => $this->_sStylePrefix,
  56. 'html_id' => $this->getRatingLegendId(),
  57. 'value' => (float)$aStats['avg'],
  58. 'bx_if:show_init' => array(
  59. 'condition' => false,
  60. 'content' => array()
  61. )
  62. ), $this->_getTmplVarsStars())),
  63. 'script' => $this->getJsScript($aBp, $aDp)
  64. ));
  65. else
  66. $sContent = MsgBox(_t('_cmt_rvw_txt_empty'));
  67. $sCaption = _t($this->_aT['block_rating_title']);
  68. return $aDp['in_designbox'] ? DesignBoxContent($sCaption, $sContent) : array(
  69. 'title' => $sCaption,
  70. 'content' => $sContent
  71. );
  72. }
  73. protected function _getForm($sAction, $iId)
  74. {
  75. $oForm = parent::_getForm($sAction, $iId);
  76. switch($sAction) {
  77. case BX_CMT_ACTION_POST:
  78. if(!empty($iId))
  79. unset($oForm->aInputs['cmt_mood']);
  80. break;
  81. case BX_CMT_ACTION_EDIT:
  82. $aCmt = $this->getCommentSimple($iId);
  83. if(!empty($aCmt['cmt_parent_id']))
  84. unset($oForm->aInputs['cmt_mood']);
  85. break;
  86. }
  87. return $oForm;
  88. }
  89. protected function _getMood(&$aCmt, $aDp = array())
  90. {
  91. if(!is_array($aCmt))
  92. $aCmt = $this->getCommentSimple((int)$aCmt);
  93. if((int)$aCmt['cmt_parent_id'] > 0)
  94. return '';
  95. $sHtmlId = $this->getMoodLegendId($aCmt['cmt_id']);
  96. return $this->_oTemplate->parseHtmlByName('review_mood_legend.html', array_merge(array(
  97. 'style_prefix' => $this->_sStylePrefix,
  98. 'html_id' => $sHtmlId,
  99. 'value' => (int)$aCmt['cmt_mood'],
  100. 'bx_if:show_init' => array(
  101. 'condition' => isset($aDp['dynamic_mode']) && (bool)$aDp['dynamic_mode'],
  102. 'content' => array(
  103. 'style_prefix' => $this->_sStylePrefix,
  104. 'js_object' => $this->_sJsObjName,
  105. 'html_id' => $sHtmlId,
  106. )
  107. )
  108. ), $this->_getTmplVarsStars()));
  109. }
  110. protected function _getTmplVarsStars() {
  111. $aTmplVarsStars = $aTmplVarsSlider = array();
  112. for($i = $this->_iMoodMinValue; $i <= $this->_iMoodMaxValue; $i++) {
  113. $aTmplVarsStars[] = array(
  114. 'style_prefix' => $this->_sStylePrefix,
  115. 'value' => $i
  116. );
  117. $aTmplVarsSlider[] = array(
  118. 'style_prefix' => $this->_sStylePrefix
  119. );
  120. }
  121. return array(
  122. 'bx_repeat:stars' => $aTmplVarsStars,
  123. 'bx_repeat:slider' => $aTmplVarsSlider
  124. );
  125. }
  126. }
  127. /** @} */