BxBaseCmtsReviews.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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->_sTmplNameItemContent = 'review_content.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, $aDp = [])
  74. {
  75. $oForm = parent::_getForm($sAction, $iId, $aDp);
  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 _getContent($aCmt, $aBp = [], $aDp = [])
  90. {
  91. $sMood = $this->_getMood($aCmt, $aDp);
  92. $sContent = parent::_getContent($aCmt, $aBp, $aDp);
  93. return $this->_oTemplate->parseHtmlByContent($sContent, [
  94. 'bx_if:show_mood' => [
  95. 'condition' => !empty($sMood),
  96. 'content' => [
  97. 'style_prefix' => $this->_sStylePrefix,
  98. 'mood' => $sMood
  99. ]
  100. ]
  101. ]);
  102. }
  103. protected function _getMood(&$aCmt, $aDp = array())
  104. {
  105. if(!is_array($aCmt))
  106. $aCmt = $this->getCommentSimple((int)$aCmt);
  107. if((int)$aCmt['cmt_parent_id'] > 0)
  108. return '';
  109. $sHtmlId = $this->getMoodLegendId($aCmt['cmt_id']);
  110. return $this->_oTemplate->parseHtmlByName('review_mood_legend.html', array_merge(array(
  111. 'style_prefix' => $this->_sStylePrefix,
  112. 'html_id' => $sHtmlId,
  113. 'value' => (int)$aCmt['cmt_mood'],
  114. 'bx_if:show_init' => array(
  115. 'condition' => isset($aDp['dynamic_mode']) && (bool)$aDp['dynamic_mode'],
  116. 'content' => array(
  117. 'style_prefix' => $this->_sStylePrefix,
  118. 'js_object' => $this->_sJsObjName,
  119. 'html_id' => $sHtmlId,
  120. )
  121. )
  122. ), $this->_getTmplVarsStars()));
  123. }
  124. protected function _getTmplVarsStars() {
  125. $aTmplVarsStars = $aTmplVarsSlider = array();
  126. for($i = $this->_iMoodMinValue; $i <= $this->_iMoodMaxValue; $i++) {
  127. $aTmplVarsStars[] = array(
  128. 'style_prefix' => $this->_sStylePrefix,
  129. 'value' => $i
  130. );
  131. $aTmplVarsSlider[] = array(
  132. 'style_prefix' => $this->_sStylePrefix
  133. );
  134. }
  135. return array(
  136. 'bx_repeat:stars' => $aTmplVarsStars,
  137. 'bx_repeat:slider' => $aTmplVarsSlider
  138. );
  139. }
  140. }
  141. /** @} */