Summary.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Review\Block\Adminhtml\Rating;
  7. use Magento\Review\Model\ResourceModel\Rating\Collection as RatingCollection;
  8. /**
  9. * Adminhtml summary rating stars
  10. */
  11. class Summary extends \Magento\Backend\Block\Template
  12. {
  13. /**
  14. * Rating summary template name
  15. *
  16. * @var string
  17. */
  18. protected $_template = 'Magento_Review::rating/stars/summary.phtml';
  19. /**
  20. * Core registry
  21. *
  22. * @var \Magento\Framework\Registry
  23. */
  24. protected $_coreRegistry = null;
  25. /**
  26. * Rating resource option model
  27. *
  28. * @var \Magento\Review\Model\ResourceModel\Rating\Option\Vote\CollectionFactory
  29. */
  30. protected $_votesFactory;
  31. /**
  32. * Rating model
  33. *
  34. * @var \Magento\Review\Model\RatingFactory
  35. */
  36. protected $_ratingFactory;
  37. /**
  38. * @param \Magento\Backend\Block\Template\Context $context
  39. * @param \Magento\Review\Model\ResourceModel\Rating\Option\Vote\CollectionFactory $votesFactory
  40. * @param \Magento\Review\Model\RatingFactory $ratingFactory
  41. * @param \Magento\Framework\Registry $registry
  42. * @param array $data
  43. */
  44. public function __construct(
  45. \Magento\Backend\Block\Template\Context $context,
  46. \Magento\Review\Model\ResourceModel\Rating\Option\Vote\CollectionFactory $votesFactory,
  47. \Magento\Review\Model\RatingFactory $ratingFactory,
  48. \Magento\Framework\Registry $registry,
  49. array $data = []
  50. ) {
  51. $this->_votesFactory = $votesFactory;
  52. $this->_ratingFactory = $ratingFactory;
  53. $this->_coreRegistry = $registry;
  54. parent::__construct($context, $data);
  55. }
  56. /**
  57. * Initialize review data
  58. *
  59. * @return void
  60. */
  61. protected function _construct()
  62. {
  63. if ($this->_coreRegistry->registry('review_data')) {
  64. $this->setReviewId($this->_coreRegistry->registry('review_data')->getId());
  65. }
  66. }
  67. /**
  68. * Get collection of ratings
  69. *
  70. * @return RatingCollection
  71. */
  72. public function getRating()
  73. {
  74. if (!$this->getRatingCollection()) {
  75. $ratingCollection = $this->_votesFactory->create()->setReviewFilter(
  76. $this->getReviewId()
  77. )->addRatingInfo()->load();
  78. $this->setRatingCollection($ratingCollection->getSize() ? $ratingCollection : false);
  79. }
  80. return $this->getRatingCollection();
  81. }
  82. /**
  83. * Get rating summary
  84. *
  85. * @return string
  86. */
  87. public function getRatingSummary()
  88. {
  89. if (!$this->getRatingSummaryCache()) {
  90. $this->setRatingSummaryCache($this->_ratingFactory->create()->getReviewSummary($this->getReviewId()));
  91. }
  92. return $this->getRatingSummaryCache();
  93. }
  94. }