Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Rating.php
Go to the documentation of this file.
1 <?php
6 namespace Magento\Review\Model;
7 
9 
24 {
28  const ENTITY_PRODUCT_CODE = 'product';
29 
30  const ENTITY_PRODUCT_REVIEW_CODE = 'product_review';
31 
32  const ENTITY_REVIEW_CODE = 'review';
33 
38 
43 
53  public function __construct(
54  \Magento\Framework\Model\Context $context,
55  \Magento\Framework\Registry $registry,
56  \Magento\Review\Model\Rating\OptionFactory $ratingOptionFactory,
57  \Magento\Review\Model\ResourceModel\Rating\Option\CollectionFactory $ratingCollectionF,
58  \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
59  \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
60  array $data = []
61  ) {
62  $this->_ratingOptionFactory = $ratingOptionFactory;
63  $this->_ratingCollectionF = $ratingCollectionF;
64  parent::__construct($context, $registry, $resource, $resourceCollection, $data);
65  }
66 
72  protected function _construct()
73  {
74  $this->_init(\Magento\Review\Model\ResourceModel\Rating::class);
75  }
76 
82  public function addOptionVote($optionId, $entityPkValue)
83  {
84  $this->_ratingOptionFactory->create()->setOptionId(
85  $optionId
86  )->setRatingId(
87  $this->getId()
88  )->setReviewId(
89  $this->getReviewId()
90  )->setEntityPkValue(
91  $entityPkValue
92  )->addVote();
93  return $this;
94  }
95 
100  public function updateOptionVote($optionId)
101  {
102  $this->_ratingOptionFactory->create()->setOptionId(
103  $optionId
104  )->setVoteId(
105  $this->getVoteId()
106  )->setReviewId(
107  $this->getReviewId()
108  )->setDoUpdate(
109  1
110  )->addVote();
111  return $this;
112  }
113 
119  public function getOptions()
120  {
121  $options = $this->getData('options');
122  if ($options) {
123  return $options;
124  } elseif ($this->getId()) {
125  return $this->_ratingCollectionF->create()->addRatingFilter(
126  $this->getId()
127  )->setPositionOrder()->load()->getItems();
128  }
129  return [];
130  }
131 
139  public function getEntitySummary($entityPkValue, $onlyForCurrentStore = true)
140  {
141  $this->setEntityPkValue($entityPkValue);
142  return $this->_getResource()->getEntitySummary($this, $onlyForCurrentStore);
143  }
144 
150  public function getReviewSummary($reviewId, $onlyForCurrentStore = true)
151  {
152  $this->setReviewId($reviewId);
153  return $this->_getResource()->getReviewSummary($this, $onlyForCurrentStore);
154  }
155 
162  public function getEntityIdByCode($entityCode)
163  {
164  return $this->getResource()->getEntityIdByCode($entityCode);
165  }
166 
172  public function getIdentities()
173  {
174  // clear cache for all reviews
175  return [Review::CACHE_TAG];
176  }
177 }
getData($key='', $index=null)
Definition: DataObject.php:119
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
getEntityIdByCode($entityCode)
Definition: Rating.php:162
$resource
Definition: bulk.php:12
getReviewSummary($reviewId, $onlyForCurrentStore=true)
Definition: Rating.php:150
updateOptionVote($optionId)
Definition: Rating.php:100
getEntitySummary($entityPkValue, $onlyForCurrentStore=true)
Definition: Rating.php:139
__construct(\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Review\Model\Rating\OptionFactory $ratingOptionFactory, \Magento\Review\Model\ResourceModel\Rating\Option\CollectionFactory $ratingCollectionF, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
Definition: Rating.php:53
addOptionVote($optionId, $entityPkValue)
Definition: Rating.php:82