BxBaseCmtsReviews.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. return $this->_oTemplate->parseHtmlByContent($sResult, array(
  30. 'mood' => $this->_getMood($mixedCmt, $aDp)
  31. ));
  32. }
  33. function getRatingBlock($aDp = array())
  34. {
  35. $mixedResult = $this->isViewAllowed();
  36. if($mixedResult !== CHECK_ACTION_RESULT_ALLOWED)
  37. return $mixedResult;
  38. $aBp = array();
  39. $this->_getParams($aBp, $aDp);
  40. $iId = $this->getId();
  41. $sCaption = _t($this->_aT['block_rating_title']);
  42. $sContent = $this->_oTemplate->parseHtmlByName('reviews_rating_block.html', array(
  43. 'style_prefix' => $this->_sStylePrefix,
  44. 'system' => $this->_sSystem,
  45. 'id' => $iId,
  46. 'content' => $this->_oTemplate->parseHtmlByName('review_mood_legend.html', array_merge(array(
  47. 'style_prefix' => $this->_sStylePrefix,
  48. 'html_id' => $this->getRatingLegendId(),
  49. 'value' => $this->_oQuery->getReviewsAvg($iId),
  50. 'bx_if:show_init' => array(
  51. 'condition' => false,
  52. 'content' => array()
  53. )
  54. ), $this->_getTmplVarsStars())),
  55. 'script' => $this->getJsScript($aBp, $aDp)
  56. ));
  57. return $aDp['in_designbox'] ? DesignBoxContent($sCaption, $sContent) : array(
  58. 'title' => $sCaption,
  59. 'content' => $sContent
  60. );
  61. }
  62. protected function _getMood(&$aCmt, $aDp = array())
  63. {
  64. $sHtmlId = $this->getMoodLegendId($aCmt['cmt_id']);
  65. return $this->_oTemplate->parseHtmlByName('review_mood_legend.html', array_merge(array(
  66. 'style_prefix' => $this->_sStylePrefix,
  67. 'html_id' => $sHtmlId,
  68. 'value' => (int)$aCmt['cmt_mood'],
  69. 'bx_if:show_init' => array(
  70. 'condition' => isset($aDp['dynamic_mode']) && (bool)$aDp['dynamic_mode'],
  71. 'content' => array(
  72. 'style_prefix' => $this->_sStylePrefix,
  73. 'js_object' => $this->_sJsObjName,
  74. 'html_id' => $sHtmlId,
  75. )
  76. )
  77. ), $this->_getTmplVarsStars()));
  78. }
  79. protected function _getTmplVarsStars() {
  80. $aTmplVarsStars = $aTmplVarsSlider = array();
  81. for($i = $this->_iMoodMinValue; $i <= $this->_iMoodMaxValue; $i++) {
  82. $aTmplVarsStars[] = array(
  83. 'style_prefix' => $this->_sStylePrefix,
  84. 'value' => $i
  85. );
  86. $aTmplVarsSlider[] = array(
  87. 'style_prefix' => $this->_sStylePrefix
  88. );
  89. }
  90. return array(
  91. 'bx_repeat:stars' => $aTmplVarsStars,
  92. 'bx_repeat:slider' => $aTmplVarsSlider
  93. );
  94. }
  95. }
  96. /** @} */