00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 class Mage_Review_Model_Review extends Mage_Core_Model_Abstract
00035 {
00036 const ENTITY_PRODUCT = 1;
00037
00038 const STATUS_APPROVED = 1;
00039 const STATUS_PENDING = 2;
00040 const STATUS_NOT_APPROVED = 3;
00041
00042 protected function _construct()
00043 {
00044 $this->_init('review/review');
00045 }
00046
00047 public function getProductCollection()
00048 {
00049 return Mage::getResourceModel('review/review_product_collection');
00050 }
00051
00052 public function getStatusCollection()
00053 {
00054 return Mage::getResourceModel('review/review_status_collection');
00055 }
00056
00057 public function getTotalReviews($entityPkValue, $approvedOnly=false, $storeId=0)
00058 {
00059 return $this->getResource()->getTotalReviews($entityPkValue, $approvedOnly, $storeId);
00060 }
00061
00062 public function aggregate()
00063 {
00064 $this->getResource()->aggregate($this);
00065 return $this;
00066 }
00067
00068 public function getEntitySummary($product, $storeId=0)
00069 {
00070 $summaryData = Mage::getModel('review/review_summary')
00071 ->setStoreId($storeId)
00072 ->load($product->getId());
00073 $summary = new Varien_Object();
00074 $summary->setData($summaryData->getData());
00075 $product->setRatingSummary($summary);
00076 }
00077
00078 public function getPendingStatus()
00079 {
00080 return self::STATUS_PENDING;
00081 }
00082
00083 public function getReviewUrl()
00084 {
00085 return Mage::getUrl('review/product/view', array('id' => $this->getReviewId()));
00086 }
00087
00088 public function validate()
00089 {
00090 $errors = array();
00091
00092 $helper = Mage::helper('customer');
00093
00094 if (!Zend_Validate::is($this->getTitle(), 'NotEmpty')) {
00095 $errors[] = $helper->__('Review summary can\'t be empty');
00096 }
00097
00098 if (!Zend_Validate::is($this->getNickname(), 'NotEmpty')) {
00099 $errors[] = $helper->__('Nickname can\'t be empty');
00100 }
00101
00102 if (!Zend_Validate::is($this->getDetail(), 'NotEmpty')) {
00103 $errors[] = $helper->__('Review can\'t be empty');
00104 }
00105
00106 if (empty($errors)) {
00107 return true;
00108 }
00109 return $errors;
00110 }
00111
00112
00113
00114
00115
00116
00117
00118 public function appendSummary($collection)
00119 {
00120 $entityIds = array();
00121 foreach ($collection->getItems() as $_itemId => $_item) {
00122 $entityIds[] = $_item->getEntityId();
00123 }
00124
00125 if (sizeof($entityIds) == 0) {
00126 return $this;
00127 }
00128
00129 $summaryData = Mage::getResourceModel('review/review_summary_collection')
00130 ->addEntityFilter($entityIds)
00131 ->addStoreFilter(Mage::app()->getStore()->getId())
00132 ->load();
00133
00134 foreach ($collection->getItems() as $_item ) {
00135 foreach ($summaryData as $_summary) {
00136 if ($_summary->getEntityPkValue() == $_item->getEntityId()) {
00137 $_item->setRatingSummary($_summary);
00138 }
00139 }
00140 }
00141
00142 return $this;
00143 }
00144
00145 protected function _beforeDelete()
00146 {
00147 $this->_protectFromNonAdmin();
00148 return parent::_beforeDelete();
00149 }
00150 }