1: <?php
2: /**
3: * Magento
4: *
5: * NOTICE OF LICENSE
6: *
7: * This source file is subject to the Open Software License (OSL 3.0)
8: * that is bundled with this package in the file LICENSE.txt.
9: * It is also available through the world-wide-web at this URL:
10: * http://opensource.org/licenses/osl-3.0.php
11: * If you did not receive a copy of the license and are unable to
12: * obtain it through the world-wide-web, please send an email
13: * to license@magentocommerce.com so we can send you a copy immediately.
14: *
15: * DISCLAIMER
16: *
17: * Do not edit or add to this file if you wish to upgrade Magento to newer
18: * versions in the future. If you wish to customize Magento for your
19: * needs please refer to http://www.magentocommerce.com for more information.
20: *
21: * @category Mage
22: * @package Mage_Rating
23: * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24: * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25: */
26:
27: /**
28: * Rating model
29: *
30: * @method Mage_Rating_Model_Resource_Rating getResource()
31: * @method Mage_Rating_Model_Resource_Rating _getResource()
32: * @method array getRatingCodes()
33: * @method Mage_Rating_Model_Rating setRatingCodes(array $value)
34: * @method array getStores()
35: * @method Mage_Rating_Model_Rating setStores(array $value)
36: * @method string getRatingCode()
37: * @method Mage_Rating_Model_Rating getRatingCode(string $value)
38: *
39: * @category Mage
40: * @package Mage_Rating
41: * @author Magento Core Team <core@magentocommerce.com>
42: */
43: class Mage_Rating_Model_Rating extends Mage_Core_Model_Abstract
44: {
45: /**
46: * rating entity codes
47: *
48: */
49: const ENTITY_PRODUCT_CODE = 'product';
50: const ENTITY_PRODUCT_REVIEW_CODE = 'product_review';
51: const ENTITY_REVIEW_CODE = 'review';
52:
53: /**
54: * Define resource model
55: *
56: * @return void
57: */
58: protected function _construct()
59: {
60: $this->_init('rating/rating');
61: }
62:
63: public function addOptionVote($optionId, $entityPkValue)
64: {
65: Mage::getModel('rating/rating_option')->setOptionId($optionId)
66: ->setRatingId($this->getId())
67: ->setReviewId($this->getReviewId())
68: ->setEntityPkValue($entityPkValue)
69: ->addVote();
70: return $this;
71: }
72:
73: public function updateOptionVote($optionId)
74: {
75: Mage::getModel('rating/rating_option')->setOptionId($optionId)
76: ->setVoteId($this->getVoteId())
77: ->setReviewId($this->getReviewId())
78: ->setDoUpdate(1)
79: ->addVote();
80: return $this;
81: }
82:
83: /**
84: * retrieve rating options
85: *
86: * @return array
87: */
88: public function getOptions()
89: {
90: if ($options = $this->getData('options')) {
91: return $options;
92: }
93: elseif ($id = $this->getId()) {
94: return Mage::getResourceModel('rating/rating_option_collection')
95: ->addRatingFilter($id)
96: ->setPositionOrder()
97: ->load()
98: ->getItems();
99: }
100: return array();
101: }
102:
103: /**
104: * Get rating collection object
105: *
106: * @return Varien_Data_Collection_Db
107: */
108:
109: public function getEntitySummary($entityPkValue, $onlyForCurrentStore = true)
110: {
111: $this->setEntityPkValue($entityPkValue);
112: return $this->_getResource()->getEntitySummary($this, $onlyForCurrentStore);
113: }
114:
115: public function getReviewSummary($reviewId, $onlyForCurrentStore = true)
116: {
117: $this->setReviewId($reviewId);
118: return $this->_getResource()->getReviewSummary($this, $onlyForCurrentStore);
119: }
120:
121: /**
122: * Get rating entity type id by code
123: *
124: * @param string $entityCode
125: * @return int
126: */
127: public function getEntityIdByCode($entityCode)
128: {
129: return $this->getResource()->getEntityIdByCode($entityCode);
130: }
131: }
132: