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
00035 class Mage_Adminhtml_Catalog_Product_ReviewController extends Mage_Adminhtml_Controller_Action
00036 {
00037 public function indexAction()
00038 {
00039 if ($this->getRequest()->getParam('ajax')) {
00040 return $this->_forward('reviewGrid');
00041 }
00042
00043 $this->loadLayout();
00044 $this->_setActiveMenu('catalog/review');
00045
00046 $this->_addContent($this->getLayout()->createBlock('adminhtml/review_main'));
00047
00048 $this->renderLayout();
00049 }
00050
00051 public function pendingAction()
00052 {
00053 if ($this->getRequest()->getParam('ajax')) {
00054 Mage::register('usePendingFilter', true);
00055 return $this->_forward('reviewGrid');
00056 }
00057
00058 $this->loadLayout();
00059 $this->_setActiveMenu('catalog/review');
00060
00061 Mage::register('usePendingFilter', true);
00062 $this->_addContent($this->getLayout()->createBlock('adminhtml/review_main'));
00063
00064 $this->renderLayout();
00065 }
00066
00067 public function editAction()
00068 {
00069 $this->loadLayout();
00070 $this->_setActiveMenu('catalog/review');
00071
00072 $this->_addContent($this->getLayout()->createBlock('adminhtml/review_edit'));
00073
00074 $this->renderLayout();
00075 }
00076
00077 public function newAction()
00078 {
00079 $this->loadLayout();
00080 $this->_setActiveMenu('catalog/review');
00081
00082 $this->getLayout()->getBlock('head')->setCanLoadExtJs(true);
00083
00084 $this->_addContent($this->getLayout()->createBlock('adminhtml/review_add'));
00085 $this->_addContent($this->getLayout()->createBlock('adminhtml/review_product_grid'));
00086
00087 $this->renderLayout();
00088 }
00089
00090 public function saveAction()
00091 {
00092 $reviewId = $this->getRequest()->getParam('id', false);
00093 if ($data = $this->getRequest()->getPost()) {
00094 $review = Mage::getModel('review/review')->load($reviewId)->addData($data);
00095 try {
00096 $review->setId($reviewId)
00097 ->save();
00098
00099 $arrRatingId = $this->getRequest()->getParam('ratings', array());
00100 $votes = Mage::getModel('rating/rating_option_vote')
00101 ->getResourceCollection()
00102 ->setReviewFilter($reviewId)
00103 ->addOptionInfo()
00104 ->load()
00105 ->addRatingOptions();
00106 foreach ($arrRatingId as $ratingId=>$optionId) {
00107 if($vote = $votes->getItemByColumnValue('rating_id', $ratingId)) {
00108 Mage::getModel('rating/rating')
00109 ->setVoteId($vote->getId())
00110 ->setReviewId($review->getId())
00111 ->updateOptionVote($optionId);
00112 } else {
00113 Mage::getModel('rating/rating')
00114 ->setRatingId($ratingId)
00115 ->setReviewId($review->getId())
00116 ->addOptionVote($optionId, $review->getEntityPkValue());
00117 }
00118 }
00119
00120 $review->aggregate();
00121
00122 Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('catalog')->__('Review was saved successfully'));
00123 if( $this->getRequest()->getParam('ret') == 'pending' ) {
00124 $this->getResponse()->setRedirect($this->getUrl('*/*/pending'));
00125 } else {
00126 $this->getResponse()->setRedirect($this->getUrl('*/*/'));
00127 }
00128 return;
00129 } catch (Exception $e){
00130 Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
00131 }
00132 }
00133 $this->_redirectReferer();
00134 }
00135
00136 public function deleteAction()
00137 {
00138 $reviewId = $this->getRequest()->getParam('id', false);
00139
00140 try {
00141 Mage::getModel('review/review')->setId($reviewId)
00142 ->aggregate()
00143 ->delete();
00144
00145 Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('catalog')->__('Review successfully deleted'));
00146 if( $this->getRequest()->getParam('ret') == 'pending' ) {
00147 $this->getResponse()->setRedirect($this->getUrl('*/*/pending'));
00148 } else {
00149 $this->getResponse()->setRedirect($this->getUrl('*/*/'));
00150 }
00151 return;
00152 } catch (Exception $e){
00153 Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
00154 }
00155
00156 $this->_redirectReferer();
00157 }
00158
00159 public function massDeleteAction()
00160 {
00161 $reviewsIds = $this->getRequest()->getParam('reviews');
00162 if(!is_array($reviewsIds)) {
00163 Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Please select review(s)'));
00164 } else {
00165 try {
00166 foreach ($reviewsIds as $reviewId) {
00167 $model = Mage::getModel('review/review')->load($reviewId);
00168 $model->delete();
00169 }
00170 Mage::getSingleton('adminhtml/session')->addSuccess(
00171 Mage::helper('adminhtml')->__('Total of %d record(s) were successfully deleted', count($reviewsIds))
00172 );
00173 } catch (Exception $e) {
00174 Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
00175 }
00176 }
00177
00178 $this->_redirect('*/*/pending');
00179 }
00180
00181 public function massUpdateStatusAction()
00182 {
00183 $reviewsIds = $this->getRequest()->getParam('reviews');
00184 if(!is_array($reviewsIds)) {
00185 Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Please select review(s)'));
00186 } else {
00187 $session = Mage::getSingleton('adminhtml/session');
00188
00189 try {
00190 $status = $this->getRequest()->getParam('status');
00191 foreach ($reviewsIds as $reviewId) {
00192 $model = Mage::getModel('review/review')->load($reviewId);
00193 $model->setStatusId($status)
00194 ->save()
00195 ->aggregate();
00196 }
00197 $session->addSuccess(
00198 Mage::helper('adminhtml')->__('Total of %d record(s) were successfully updated', count($reviewsIds))
00199 );
00200 }
00201 catch (Mage_Core_Exception $e) {
00202 $session->addException($e->getMessage());
00203 }
00204 catch (Exception $e) {
00205 $session->addError(Mage::helper('adminhtml')->__('Error while updating selected review(s). Please try again later.'));
00206 }
00207 }
00208
00209 $this->_redirect('*/*/pending');
00210 }
00211
00212 public function massVisibleInAction()
00213 {
00214 $reviewsIds = $this->getRequest()->getParam('reviews');
00215 if(!is_array($reviewsIds)) {
00216 Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Please select review(s)'));
00217 } else {
00218 $session = Mage::getSingleton('adminhtml/session');
00219
00220 try {
00221 $stores = $this->getRequest()->getParam('stores');
00222 foreach ($reviewsIds as $reviewId) {
00223 $model = Mage::getModel('review/review')->load($reviewId);
00224 $model->setSelectStores($stores);
00225 $model->save();
00226 }
00227 $session->addSuccess(
00228 Mage::helper('adminhtml')->__('Total of %d record(s) were successfully updated', count($reviewsIds))
00229 );
00230 }
00231 catch (Mage_Core_Exception $e) {
00232 $session->addException($e->getMessage());
00233 }
00234 catch (Exception $e) {
00235 $session->addError(Mage::helper('adminhtml')->__('Error while updating selected review(s). Please try again later.'));
00236 }
00237 }
00238
00239 $this->_redirect('*/*/pending');
00240 }
00241
00242 public function productGridAction()
00243 {
00244 $this->getResponse()->setBody($this->getLayout()->createBlock('adminhtml/review_product_grid')->toHtml());
00245 }
00246
00247 public function reviewGridAction()
00248 {
00249 $this->getResponse()->setBody($this->getLayout()->createBlock('adminhtml/review_grid')->toHtml());
00250 }
00251
00252 public function jsonProductInfoAction()
00253 {
00254 $response = new Varien_Object();
00255 $id = $this->getRequest()->getParam('id');
00256 if( intval($id) > 0 ) {
00257 $product = Mage::getModel('catalog/product')
00258 ->load($id);
00259
00260 $response->setId($id);
00261 $response->addData($product->getData());
00262 $response->setError(0);
00263 } else {
00264 $response->setError(1);
00265 $response->setMessage(Mage::helper('catalog')->__('Unable to get product id.'));
00266 }
00267 $this->getResponse()->setBody($response->toJSON());
00268 }
00269
00270 public function postAction()
00271 {
00272 $productId = $this->getRequest()->getParam('product_id', false);
00273 if ($data = $this->getRequest()->getPost()) {
00274 if(isset($data['select_stores'])) {
00275 $data['stores'] = $data['select_stores'];
00276 }
00277
00278 $review = Mage::getModel('review/review')->setData($data);
00279
00280 $product = Mage::getModel('catalog/product')
00281 ->load($productId);
00282
00283 try {
00284 $review->setEntityId(1)
00285 ->setEntityPkValue($productId)
00286 ->setStoreId($product->getStoreId())
00287 ->setStatusId($data['status_id'])
00288 ->setCustomerId(0)
00289 ->save();
00290
00291 $arrRatingId = $this->getRequest()->getParam('ratings', array());
00292 foreach ($arrRatingId as $ratingId=>$optionId) {
00293 Mage::getModel('rating/rating')
00294 ->setRatingId($ratingId)
00295 ->setReviewId($review->getId())
00296 ->addOptionVote($optionId, $productId);
00297 }
00298
00299 $review->aggregate();
00300
00301 Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('catalog')->__('Review was successfully saved'));
00302 if( $this->getRequest()->getParam('ret') == 'pending' ) {
00303 $this->getResponse()->setRedirect($this->getUrl('*/*/pending'));
00304 } else {
00305 $this->getResponse()->setRedirect($this->getUrl('*/*/'));
00306 }
00307
00308 return;
00309 } catch (Exception $e){
00310 die($e->getMessage());
00311 Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
00312 }
00313 }
00314 $this->getResponse()->setRedirect($this->getUrl('*/*/'));
00315 return;
00316 }
00317
00318 public function ratingItemsAction()
00319 {
00320 $this->getResponse()->setBody($this->getLayout()->createBlock('adminhtml/review_rating_detailed')->setIndependentMode()->toHtml());
00321 }
00322
00323 protected function _isAllowed()
00324 {
00325 switch ($this->getRequest()->getActionName()) {
00326 case 'pending':
00327 return Mage::getSingleton('admin/session')->isAllowed('catalog/reviews_ratings/reviews/pending');
00328 break;
00329 default:
00330 return Mage::getSingleton('admin/session')->isAllowed('catalog/reviews_ratings/reviews/all');
00331 break;
00332 }
00333 }
00334 }