Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
Rating Class Reference
Inheritance diagram for Rating:
AbstractModel IdentityInterface DataObject

Public Member Functions

 __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=[])
 
 addOptionVote ($optionId, $entityPkValue)
 
 updateOptionVote ($optionId)
 
 getOptions ()
 
 getEntitySummary ($entityPkValue, $onlyForCurrentStore=true)
 
 getReviewSummary ($reviewId, $onlyForCurrentStore=true)
 
 getEntityIdByCode ($entityCode)
 
 getIdentities ()
 
- Public Member Functions inherited from AbstractModel
 __construct (\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
 
 __sleep ()
 
 __wakeup ()
 
 setIdFieldName ($name)
 
 getIdFieldName ()
 
 getId ()
 
 setId ($value)
 
 isDeleted ($isDeleted=null)
 
 hasDataChanges ()
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 setDataChanges ($value)
 
 getOrigData ($key=null)
 
 setOrigData ($key=null, $data=null)
 
 dataHasChangedFor ($field)
 
 getResourceName ()
 
 getResourceCollection ()
 
 getCollection ()
 
 load ($modelId, $field=null)
 
 beforeLoad ($identifier, $field=null)
 
 afterLoad ()
 
 isSaveAllowed ()
 
 setHasDataChanges ($flag)
 
 save ()
 
 afterCommitCallback ()
 
 isObjectNew ($flag=null)
 
 beforeSave ()
 
 validateBeforeSave ()
 
 getCacheTags ()
 
 cleanModelCache ()
 
 afterSave ()
 
 delete ()
 
 beforeDelete ()
 
 afterDelete ()
 
 afterDeleteCommit ()
 
 getResource ()
 
 getEntityId ()
 
 setEntityId ($entityId)
 
 clearInstance ()
 
 getStoredData ()
 
 getEventPrefix ()
 
- Public Member Functions inherited from DataObject
 __construct (array $data=[])
 
 addData (array $arr)
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 getData ($key='', $index=null)
 
 getDataByPath ($path)
 
 getDataByKey ($key)
 
 setDataUsingMethod ($key, $args=[])
 
 getDataUsingMethod ($key, $args=null)
 
 hasData ($key='')
 
 toArray (array $keys=[])
 
 convertToArray (array $keys=[])
 
 toXml (array $keys=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 convertToXml (array $arrAttributes=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 toJson (array $keys=[])
 
 convertToJson (array $keys=[])
 
 toString ($format='')
 
 __call ($method, $args)
 
 isEmpty ()
 
 serialize ($keys=[], $valueSeparator='=', $fieldSeparator=' ', $quote='"')
 
 debug ($data=null, &$objects=[])
 
 offsetSet ($offset, $value)
 
 offsetExists ($offset)
 
 offsetUnset ($offset)
 
 offsetGet ($offset)
 

Data Fields

const ENTITY_PRODUCT_CODE = 'product'
 
const ENTITY_PRODUCT_REVIEW_CODE = 'product_review'
 
const ENTITY_REVIEW_CODE = 'review'
 

Protected Member Functions

 _construct ()
 
- Protected Member Functions inherited from AbstractModel
 _construct ()
 
 _init ($resourceModel)
 
 _setResourceModel ($resourceName, $collectionName=null)
 
 _getResource ()
 
 _getEventData ()
 
 _beforeLoad ($modelId, $field=null)
 
 _afterLoad ()
 
 _hasModelChanged ()
 
 _getValidatorBeforeSave ()
 
 _createValidatorBeforeSave ()
 
 _getValidationRulesBeforeSave ()
 
 _clearReferences ()
 
 _clearData ()
 
- Protected Member Functions inherited from DataObject
 _getData ($key)
 
 _underscore ($name)
 

Protected Attributes

 $_ratingOptionFactory
 
 $_ratingCollectionF
 
- Protected Attributes inherited from AbstractModel
 $_eventPrefix = 'core_abstract'
 
 $_eventObject = 'object'
 
 $_idFieldName = 'id'
 
 $_hasDataChanges = false
 
 $_origData
 
 $_isDeleted = false
 
 $_resource
 
 $_resourceCollection
 
 $_resourceName
 
 $_collectionName
 
 $_cacheTag = false
 
 $_dataSaveAllowed = true
 
 $_isObjectNew = null
 
 $_validatorBeforeSave = null
 
 $_eventManager
 
 $_cacheManager
 
 $_registry
 
 $_logger
 
 $_appState
 
 $_actionValidator
 
 $storedData = []
 
- Protected Attributes inherited from DataObject
 $_data = []
 

Additional Inherited Members

- Static Protected Attributes inherited from DataObject
static $_underscoreCache = []
 

Detailed Description

Rating model

@api @method array getRatingCodes() @method \Magento\Review\Model\Rating setRatingCodes(array $value) @method array getStores() @method \Magento\Review\Model\Rating setStores(array $value) @method string getRatingCode()

Author
Magento Core Team core@.nosp@m.mage.nosp@m.ntoco.nosp@m.mmer.nosp@m.ce.co.nosp@m.m
Since
100.0.2

Definition at line 23 of file Rating.php.

Constructor & Destructor Documentation

◆ __construct()

__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 = [] 
)
Parameters
\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
\Magento\Framework\Data\Collection\AbstractDb$resourceCollection
array$data

Definition at line 53 of file Rating.php.

61  {
62  $this->_ratingOptionFactory = $ratingOptionFactory;
63  $this->_ratingCollectionF = $ratingCollectionF;
64  parent::__construct($context, $registry, $resource, $resourceCollection, $data);
65  }
$resource
Definition: bulk.php:12

Member Function Documentation

◆ _construct()

_construct ( )
protected

Define resource model

Returns
void

Definition at line 72 of file Rating.php.

73  {
74  $this->_init(\Magento\Review\Model\ResourceModel\Rating::class);
75  }

◆ addOptionVote()

addOptionVote (   $optionId,
  $entityPkValue 
)
Parameters
int$optionId
int$entityPkValue
Returns
$this

Definition at line 82 of file Rating.php.

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  }

◆ getEntityIdByCode()

getEntityIdByCode (   $entityCode)

Get rating entity type id by code

Parameters
string$entityCode
Returns
int

Definition at line 162 of file Rating.php.

163  {
164  return $this->getResource()->getEntityIdByCode($entityCode);
165  }

◆ getEntitySummary()

getEntitySummary (   $entityPkValue,
  $onlyForCurrentStore = true 
)

Get rating collection object

Parameters
int$entityPkValue
bool$onlyForCurrentStore
Returns
\Magento\Framework\Data\Collection\AbstractDb

Definition at line 139 of file Rating.php.

140  {
141  $this->setEntityPkValue($entityPkValue);
142  return $this->_getResource()->getEntitySummary($this, $onlyForCurrentStore);
143  }

◆ getIdentities()

getIdentities ( )

Return unique ID(s) for each object in system

Returns
array

Implements IdentityInterface.

Definition at line 172 of file Rating.php.

173  {
174  // clear cache for all reviews
175  return [Review::CACHE_TAG];
176  }

◆ getOptions()

getOptions ( )

retrieve rating options

Returns
array

Definition at line 119 of file Rating.php.

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  }
getData($key='', $index=null)
Definition: DataObject.php:119
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17

◆ getReviewSummary()

getReviewSummary (   $reviewId,
  $onlyForCurrentStore = true 
)
Parameters
int$reviewId
bool$onlyForCurrentStore
Returns
array

Definition at line 150 of file Rating.php.

151  {
152  $this->setReviewId($reviewId);
153  return $this->_getResource()->getReviewSummary($this, $onlyForCurrentStore);
154  }

◆ updateOptionVote()

updateOptionVote (   $optionId)
Parameters
int$optionId
Returns
$this

Definition at line 100 of file Rating.php.

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  }

Field Documentation

◆ $_ratingCollectionF

$_ratingCollectionF
protected

Definition at line 42 of file Rating.php.

◆ $_ratingOptionFactory

$_ratingOptionFactory
protected

Definition at line 37 of file Rating.php.

◆ ENTITY_PRODUCT_CODE

const ENTITY_PRODUCT_CODE = 'product'

rating entity codes

Definition at line 28 of file Rating.php.

◆ ENTITY_PRODUCT_REVIEW_CODE

const ENTITY_PRODUCT_REVIEW_CODE = 'product_review'

Definition at line 30 of file Rating.php.

◆ ENTITY_REVIEW_CODE

const ENTITY_REVIEW_CODE = 'review'

Definition at line 32 of file Rating.php.


The documentation for this class was generated from the following file: