Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Summary.php
Go to the documentation of this file.
1 <?php
7 
9 
14 {
20  protected $_template = 'Magento_Review::rating/stars/summary.phtml';
21 
27  protected $_coreRegistry = null;
28 
34  protected $_votesFactory;
35 
41  protected $_ratingFactory;
42 
50  public function __construct(
51  \Magento\Backend\Block\Template\Context $context,
52  \Magento\Review\Model\ResourceModel\Rating\Option\Vote\CollectionFactory $votesFactory,
53  \Magento\Review\Model\RatingFactory $ratingFactory,
54  \Magento\Framework\Registry $registry,
55  array $data = []
56  ) {
57  $this->_votesFactory = $votesFactory;
58  $this->_ratingFactory = $ratingFactory;
59  $this->_coreRegistry = $registry;
60  parent::__construct($context, $data);
61  }
62 
68  protected function _construct()
69  {
70  if ($this->_coreRegistry->registry('review_data')) {
71  $this->setReviewId($this->_coreRegistry->registry('review_data')->getId());
72  }
73  }
74 
80  public function getRating()
81  {
82  if (!$this->getRatingCollection()) {
83  $ratingCollection = $this->_votesFactory->create()->setReviewFilter(
84  $this->getReviewId()
85  )->addRatingInfo()->load();
86  $this->setRatingCollection($ratingCollection->getSize() ? $ratingCollection : false);
87  }
88  return $this->getRatingCollection();
89  }
90 
96  public function getRatingSummary()
97  {
98  if (!$this->getRatingSummaryCache()) {
99  $this->setRatingSummaryCache($this->_ratingFactory->create()->getReviewSummary($this->getReviewId()));
100  }
101 
102  return $this->getRatingSummaryCache();
103  }
104 }
__construct(\Magento\Backend\Block\Template\Context $context, \Magento\Review\Model\ResourceModel\Rating\Option\Vote\CollectionFactory $votesFactory, \Magento\Review\Model\RatingFactory $ratingFactory, \Magento\Framework\Registry $registry, array $data=[])
Definition: Summary.php:50