Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Detailed.php
Go to the documentation of this file.
1 <?php
7 
12 
17 {
23  protected $_voteCollection = false;
24 
30  protected $_template = 'Magento_Review::rating/detailed.phtml';
31 
37  protected $_coreRegistry = null;
38 
44  protected $_ratingsFactory;
45 
51  protected $_votesFactory;
52 
60  public function __construct(
61  \Magento\Backend\Block\Template\Context $context,
62  \Magento\Review\Model\ResourceModel\Rating\CollectionFactory $ratingsFactory,
63  \Magento\Review\Model\ResourceModel\Rating\Option\Vote\CollectionFactory $votesFactory,
64  \Magento\Framework\Registry $registry,
65  array $data = []
66  ) {
67  $this->_ratingsFactory = $ratingsFactory;
68  $this->_votesFactory = $votesFactory;
69  $this->_coreRegistry = $registry;
70  parent::__construct($context, $data);
71  }
72 
78  protected function _construct()
79  {
80  parent::_construct();
81 
82  if ($this->_coreRegistry->registry('review_data')) {
83  $this->setReviewId($this->_coreRegistry->registry('review_data')->getReviewId());
84  }
85  }
86 
92  public function getRating()
93  {
94  if (!$this->getRatingCollection()) {
95  if ($this->_coreRegistry->registry('review_data')) {
96  $stores = $this->_coreRegistry->registry('review_data')->getStores();
97 
98  $stores = array_diff($stores, [0]);
99 
100  $ratingCollection = $this->_ratingsFactory->create()->addEntityFilter(
101  'product'
102  )->setStoreFilter(
103  $stores
104  )->setActiveFilter(
105  true
106  )->setPositionOrder()->load()->addOptionToItems();
107 
108  $this->_voteCollection = $this->_votesFactory->create()->setReviewFilter(
109  $this->getReviewId()
110  )->addOptionInfo()->load()->addRatingOptions();
111  } elseif (!$this->getIsIndependentMode()) {
112  $ratingCollection = $this->_ratingsFactory->create()->addEntityFilter(
113  'product'
114  )->setStoreFilter(
115  null
116  )->setPositionOrder()->load()->addOptionToItems();
117  } else {
118  $stores = $this->getRequest()->getParam('select_stores') ?: $this->getRequest()->getParam('stores');
119  $ratingCollection = $this->_ratingsFactory->create()->addEntityFilter(
120  'product'
121  )->setStoreFilter(
122  $stores
123  )->setPositionOrder()->load()->addOptionToItems();
124  if (intval($this->getRequest()->getParam('id'))) {
125  $this->_voteCollection = $this->_votesFactory->create()->setReviewFilter(
126  intval($this->getRequest()->getParam('id'))
127  )->addOptionInfo()->load()->addRatingOptions();
128  }
129  }
130  $this->setRatingCollection($ratingCollection->getSize() ? $ratingCollection : false);
131  }
132  return $this->getRatingCollection();
133  }
134 
140  public function setIndependentMode()
141  {
142  $this->setIsIndependentMode(true);
143  return $this;
144  }
145 
154  public function isSelected($option, $rating)
155  {
156  if ($this->getIsIndependentMode()) {
157  $ratings = $this->getRequest()->getParam('ratings');
158 
159  if (isset($ratings[$option->getRatingId()])) {
160  return $option->getId() == $ratings[$option->getRatingId()];
161  } elseif (!$this->_voteCollection) {
162  return false;
163  }
164  }
165 
166  if ($this->_voteCollection) {
167  foreach ($this->_voteCollection as $vote) {
168  if ($option->getId() == $vote->getOptionId()) {
169  return true;
170  }
171  }
172  }
173  return false;
174  }
175 }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
__construct(\Magento\Backend\Block\Template\Context $context, \Magento\Review\Model\ResourceModel\Rating\CollectionFactory $ratingsFactory, \Magento\Review\Model\ResourceModel\Rating\Option\Vote\CollectionFactory $votesFactory, \Magento\Framework\Registry $registry, array $data=[])
Definition: Detailed.php:60
$rating
Definition: item.phtml:18