00001 <?php 00002 /** 00003 * Magento 00004 * 00005 * NOTICE OF LICENSE 00006 * 00007 * This source file is subject to the Open Software License (OSL 3.0) 00008 * that is bundled with this package in the file LICENSE.txt. 00009 * It is also available through the world-wide-web at this URL: 00010 * http://opensource.org/licenses/osl-3.0.php 00011 * If you did not receive a copy of the license and are unable to 00012 * obtain it through the world-wide-web, please send an email 00013 * to license@magentocommerce.com so we can send you a copy immediately. 00014 * 00015 * DISCLAIMER 00016 * 00017 * Do not edit or add to this file if you wish to upgrade Magento to newer 00018 * versions in the future. If you wish to customize Magento for your 00019 * needs please refer to http://www.magentocommerce.com for more information. 00020 * 00021 * @category Mage 00022 * @package Mage_Adminhtml 00023 * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com) 00024 * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) 00025 */ 00026 00027 /** 00028 * Admin ratings controller 00029 * 00030 * @category Mage 00031 * @package Mage_Adminhtml 00032 * @author Magento Core Team <core@magentocommerce.com> 00033 */ 00034 00035 class Mage_Adminhtml_RatingController extends Mage_Adminhtml_Controller_Action 00036 { 00037 public function indexAction() 00038 { 00039 $this->_initEnityId(); 00040 $this->loadLayout(); 00041 00042 $this->_setActiveMenu('catalog/ratings'); 00043 $this->_addBreadcrumb(Mage::helper('adminhtml')->__('Manage Ratings'), Mage::helper('adminhtml')->__('Manage Ratings')); 00044 $this->_addContent($this->getLayout()->createBlock('adminhtml/rating_rating')); 00045 00046 $this->renderLayout(); 00047 } 00048 00049 public function editAction() 00050 { 00051 $this->_initEnityId(); 00052 $this->loadLayout(); 00053 00054 $this->_setActiveMenu('catalog/ratings'); 00055 $this->_addBreadcrumb(Mage::helper('adminhtml')->__('Manage Ratings'), Mage::helper('adminhtml')->__('Manage Ratings')); 00056 00057 $this->_addContent($this->getLayout()->createBlock('adminhtml/rating_edit')) 00058 ->_addLeft($this->getLayout()->createBlock('adminhtml/rating_edit_tabs')); 00059 $this->renderLayout(); 00060 } 00061 00062 public function newAction() 00063 { 00064 $this->_forward('edit'); 00065 } 00066 00067 public function saveAction() 00068 { 00069 $this->_initEnityId(); 00070 00071 if ( $this->getRequest()->getPost() ) { 00072 try { 00073 $ratingModel = Mage::getModel('rating/rating'); 00074 00075 $stores = $this->getRequest()->getParam('stores'); 00076 $stores[] = 0; 00077 $ratingModel->setRatingCode($this->getRequest()->getParam('rating_code')) 00078 ->setRatingCodes($this->getRequest()->getParam('rating_codes')) 00079 ->setStores($stores) 00080 ->setId($this->getRequest()->getParam('id')) 00081 ->setEntityId(Mage::registry('entityId')) 00082 ->save(); 00083 00084 $options = $this->getRequest()->getParam('option_title'); 00085 00086 if( is_array($options) ) { 00087 $i = 1; 00088 foreach( $options as $key => $optionCode ) { 00089 $optionModel = Mage::getModel('rating/rating_option'); 00090 if( !preg_match("/^add_([0-9]*?)$/", $key) ) { 00091 $optionModel->setId($key); 00092 } 00093 00094 $optionModel->setCode($optionCode) 00095 ->setValue($i) 00096 ->setRatingId($ratingModel->getId()) 00097 ->setPosition($i) 00098 ->save(); 00099 $i++; 00100 } 00101 } 00102 00103 Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('Rating was successfully saved')); 00104 Mage::getSingleton('adminhtml/session')->setRatingData(false); 00105 00106 $this->_redirect('*/*/'); 00107 return; 00108 } catch (Exception $e) { 00109 Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); 00110 Mage::getSingleton('adminhtml/session')->setRatingData($this->getRequest()->getPost()); 00111 $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id'))); 00112 return; 00113 } 00114 } 00115 $this->_redirect('*/*/'); 00116 } 00117 00118 public function deleteAction() 00119 { 00120 if( $this->getRequest()->getParam('id') > 0 ) { 00121 try { 00122 $model = Mage::getModel('rating/rating'); 00123 /* @var $model Mage_Rating_Model_Rating */ 00124 $model->setId($this->getRequest()->getParam('id')) 00125 ->delete(); 00126 Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('Rating was successfully deleted')); 00127 $this->_redirect('*/*/'); 00128 } catch (Exception $e) { 00129 Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); 00130 $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id'))); 00131 } 00132 } 00133 $this->_redirect('*/*/'); 00134 } 00135 00136 protected function _initEnityId() 00137 { 00138 Mage::register('entityId', Mage::getModel('rating/rating_entity')->getIdByCode('product')); 00139 } 00140 00141 protected function _isAllowed() 00142 { 00143 return Mage::getSingleton('admin/session')->isAllowed('catalog/reviews_ratings/ratings'); 00144 } 00145 00146 }