Overview

Packages

  • currencysymbol
  • MAbout
  • Mage
    • Admin
    • Adminhtml
    • AdminNotification
    • Api
    • Api2
    • Authorizenet
    • Backup
    • Bundle
    • Captcha
    • Catalog
    • CatalogIndex
    • CatalogInventory
    • CatalogRule
    • CatalogSearch
    • Centinel
    • Checkout
    • Cms
    • Compiler
    • Connect
    • Contacts
    • Core
    • Cron
    • CurrencySymbol
    • Customer
    • Dataflow
    • Directory
    • DirtectPost
    • Downloadable
    • Eav
    • GiftMessage
    • GoogleAnalytics
    • GoogleBase
    • GoogleCheckout
    • ImportExport
    • Index
    • Install
    • Log
    • Media
    • Newsletter
    • Oauth
    • Page
    • PageCache
    • Paygate
    • Payment
    • Paypal
    • PaypalUk
    • Persistent
    • Poll
    • ProductAlert
    • Rating
    • Reports
    • Review
    • Rss
    • Rule
    • Sales
    • SalesRule
    • Sedfriend
    • Sendfriend
    • Shipping
    • Sitemap
    • Tag
    • Tax
    • Usa
    • Weee
    • Widget
    • Wishlist
    • XmlConnect
  • None
  • Phoenix
    • Moneybookers
  • PHP
  • Zend
    • Date
    • Mime
    • XmlRpc

Classes

  • Mage_Review_Block_Customer_List
  • Mage_Review_Block_Customer_Recent
  • Mage_Review_Block_Customer_View
  • Mage_Review_Block_Form
  • Mage_Review_Block_Helper
  • Mage_Review_Block_Product_View
  • Mage_Review_Block_Product_View_List
  • Mage_Review_Block_View
  • Mage_Review_CustomerController
  • Mage_Review_Helper_Data
  • Mage_Review_Model_Mysql4_Review
  • Mage_Review_Model_Mysql4_Review_Collection
  • Mage_Review_Model_Mysql4_Review_Product_Collection
  • Mage_Review_Model_Mysql4_Review_Status_Collection
  • Mage_Review_Model_Mysql4_Review_Summary
  • Mage_Review_Model_Mysql4_Review_Summary_Collection
  • Mage_Review_Model_Observer
  • Mage_Review_Model_Resource_Review
  • Mage_Review_Model_Resource_Review_Collection
  • Mage_Review_Model_Resource_Review_Product_Collection
  • Mage_Review_Model_Resource_Review_Status
  • Mage_Review_Model_Resource_Review_Status_Collection
  • Mage_Review_Model_Resource_Review_Summary
  • Mage_Review_Model_Resource_Review_Summary_Collection
  • Mage_Review_Model_Review
  • Mage_Review_Model_Review_Status
  • Mage_Review_Model_Review_Summary
  • Mage_Review_Model_Session
  • Mage_Review_ProductController
  • Overview
  • Package
  • Class
  • Tree
  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_Review
 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:  * Review model
 29:  *
 30:  * @method Mage_Review_Model_Resource_Review _getResource()
 31:  * @method Mage_Review_Model_Resource_Review getResource()
 32:  * @method string getCreatedAt()
 33:  * @method Mage_Review_Model_Review setCreatedAt(string $value)
 34:  * @method Mage_Review_Model_Review setEntityId(int $value)
 35:  * @method int getEntityPkValue()
 36:  * @method Mage_Review_Model_Review setEntityPkValue(int $value)
 37:  * @method int getStatusId()
 38:  * @method Mage_Review_Model_Review setStatusId(int $value)
 39:  *
 40:  * @category    Mage
 41:  * @package     Mage_Review
 42:  * @author      Magento Core Team <core@magentocommerce.com>
 43:  */
 44: class Mage_Review_Model_Review extends Mage_Core_Model_Abstract
 45: {
 46: 
 47:     /**
 48:      * Event prefix for observer
 49:      *
 50:      * @var string
 51:      */
 52:     protected $_eventPrefix = 'review';
 53: 
 54:     /**
 55:      * @deprecated after 1.3.2.4
 56:      *
 57:      */
 58:     const ENTITY_PRODUCT = 1;
 59: 
 60:     /**
 61:      * Review entity codes
 62:      *
 63:      */
 64:     const ENTITY_PRODUCT_CODE   = 'product';
 65:     const ENTITY_CUSTOMER_CODE  = 'customer';
 66:     const ENTITY_CATEGORY_CODE  = 'category';
 67: 
 68:     const STATUS_APPROVED       = 1;
 69:     const STATUS_PENDING        = 2;
 70:     const STATUS_NOT_APPROVED   = 3;
 71: 
 72:     protected function _construct()
 73:     {
 74:         $this->_init('review/review');
 75:     }
 76: 
 77:     public function getProductCollection()
 78:     {
 79:         return Mage::getResourceModel('review/review_product_collection');
 80:     }
 81: 
 82:     public function getStatusCollection()
 83:     {
 84:         return Mage::getResourceModel('review/review_status_collection');
 85:     }
 86: 
 87:     public function getTotalReviews($entityPkValue, $approvedOnly=false, $storeId=0)
 88:     {
 89:         return $this->getResource()->getTotalReviews($entityPkValue, $approvedOnly, $storeId);
 90:     }
 91: 
 92:     public function aggregate()
 93:     {
 94:         $this->getResource()->aggregate($this);
 95:         return $this;
 96:     }
 97: 
 98:     public function getEntitySummary($product, $storeId=0)
 99:     {
100:         $summaryData = Mage::getModel('review/review_summary')
101:             ->setStoreId($storeId)
102:             ->load($product->getId());
103:         $summary = new Varien_Object();
104:         $summary->setData($summaryData->getData());
105:         $product->setRatingSummary($summary);
106:     }
107: 
108:     public function getPendingStatus()
109:     {
110:         return self::STATUS_PENDING;
111:     }
112: 
113:     public function getReviewUrl()
114:     {
115:         return Mage::getUrl('review/product/view', array('id' => $this->getReviewId()));
116:     }
117: 
118:     public function validate()
119:     {
120:         $errors = array();
121: 
122:         if (!Zend_Validate::is($this->getTitle(), 'NotEmpty')) {
123:             $errors[] = Mage::helper('review')->__('Review summary can\'t be empty');
124:         }
125: 
126:         if (!Zend_Validate::is($this->getNickname(), 'NotEmpty')) {
127:             $errors[] = Mage::helper('review')->__('Nickname can\'t be empty');
128:         }
129: 
130:         if (!Zend_Validate::is($this->getDetail(), 'NotEmpty')) {
131:             $errors[] = Mage::helper('review')->__('Review can\'t be empty');
132:         }
133: 
134:         if (empty($errors)) {
135:             return true;
136:         }
137:         return $errors;
138:     }
139: 
140:     /**
141:      * Perform actions after object delete
142:      *
143:      * @return Mage_Core_Model_Abstract
144:      */
145:     protected function _afterDeleteCommit()
146:     {
147:         $this->getResource()->afterDeleteCommit($this);
148:         return parent::_afterDeleteCommit();
149:     }
150: 
151:     /**
152:      * Append review summary to product collection
153:      *
154:      * @param Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection $collection
155:      * @return Mage_Review_Model_Review
156:      */
157:     public function appendSummary($collection)
158:     {
159:         $entityIds = array();
160:         foreach ($collection->getItems() as $_itemId => $_item) {
161:             $entityIds[] = $_item->getEntityId();
162:         }
163: 
164:         if (sizeof($entityIds) == 0) {
165:             return $this;
166:         }
167: 
168:         $summaryData = Mage::getResourceModel('review/review_summary_collection')
169:             ->addEntityFilter($entityIds)
170:             ->addStoreFilter(Mage::app()->getStore()->getId())
171:             ->load();
172: 
173:         foreach ($collection->getItems() as $_item ) {
174:             foreach ($summaryData as $_summary) {
175:                 if ($_summary->getEntityPkValue() == $_item->getEntityId()) {
176:                     $_item->setRatingSummary($_summary);
177:                 }
178:             }
179:         }
180: 
181:         return $this;
182:     }
183: 
184:     protected function _beforeDelete()
185:     {
186:         $this->_protectFromNonAdmin();
187:         return parent::_beforeDelete();
188:     }
189: 
190:     /**
191:      * Check if current review approved or not
192:      *
193:      * @return bool
194:      */
195:     public function isApproved()
196:     {
197:         return $this->getStatusId() == self::STATUS_APPROVED;
198:     }
199: 
200:     /**
201:      * Check if current review available on passed store
202:      *
203:      * @param int|Mage_Core_Model_Store $store
204:      * @return bool
205:      */
206:     public function isAvailableOnStore($store = null)
207:     {
208:         $store = Mage::app()->getStore($store);
209:         if ($store) {
210:             return in_array($store->getId(), (array)$this->getStores());
211:         }
212: 
213:         return false;
214:     }
215: 
216:     /**
217:      * Get review entity type id by code
218:      *
219:      * @param string $entityCode
220:      * @return int|bool
221:      */
222:     public function getEntityIdByCode($entityCode)
223:     {
224:         return $this->getResource()->getEntityIdByCode($entityCode);
225:     }
226: }
227: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0