1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27: 28: 29: 30: 31: 32: 33:
34:
35: class Mage_Adminhtml_RatingController extends Mage_Adminhtml_Controller_Action
36: {
37: public function indexAction()
38: {
39: $this->_initEnityId();
40: $this->loadLayout();
41:
42: $this->_setActiveMenu('catalog/ratings');
43: $this->_addBreadcrumb(Mage::helper('adminhtml')->__('Manage Ratings'), Mage::helper('adminhtml')->__('Manage Ratings'));
44: $this->_addContent($this->getLayout()->createBlock('adminhtml/rating_rating'));
45:
46: $this->renderLayout();
47: }
48:
49: public function editAction()
50: {
51: $this->_initEnityId();
52: $this->loadLayout();
53:
54: $ratingModel = Mage::getModel('rating/rating');
55: if ($this->getRequest()->getParam('id')) {
56: $ratingModel->load($this->getRequest()->getParam('id'));
57: }
58:
59: $this->_title($ratingModel->getId() ? $ratingModel->getRatingCode() : $this->__('New Rating'));
60:
61: $this->_setActiveMenu('catalog/ratings');
62: $this->_addBreadcrumb(Mage::helper('adminhtml')->__('Manage Ratings'), Mage::helper('adminhtml')->__('Manage Ratings'));
63:
64: $this->_addContent($this->getLayout()->createBlock('adminhtml/rating_edit'))
65: ->_addLeft($this->getLayout()->createBlock('adminhtml/rating_edit_tabs'));
66: $this->renderLayout();
67: }
68:
69: public function newAction()
70: {
71: $this->_forward('edit');
72: }
73:
74: 75: 76:
77: public function saveAction()
78: {
79: $this->_initEnityId();
80:
81: if ($this->getRequest()->getPost()) {
82: try {
83: $ratingModel = Mage::getModel('rating/rating');
84:
85: $stores = $this->getRequest()->getParam('stores');
86: $position = (int)$this->getRequest()->getParam('position');
87: $stores[] = 0;
88: $ratingModel->setRatingCode($this->getRequest()->getParam('rating_code'))
89: ->setRatingCodes($this->getRequest()->getParam('rating_codes'))
90: ->setStores($stores)
91: ->setPosition($position)
92: ->setId($this->getRequest()->getParam('id'))
93: ->setEntityId(Mage::registry('entityId'))
94: ->save();
95:
96: $options = $this->getRequest()->getParam('option_title');
97:
98: if (is_array($options)) {
99: $i = 1;
100: foreach ($options as $key => $optionCode) {
101: $optionModel = Mage::getModel('rating/rating_option');
102: if (!preg_match("/^add_([0-9]*?)$/", $key)) {
103: $optionModel->setId($key);
104: }
105:
106: $optionModel->setCode($optionCode)
107: ->setValue($i)
108: ->setRatingId($ratingModel->getId())
109: ->setPosition($i)
110: ->save();
111: $i++;
112: }
113: }
114:
115: Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('The rating has been saved.'));
116: Mage::getSingleton('adminhtml/session')->setRatingData(false);
117:
118: $this->_redirect('*/*/');
119: return;
120: } catch (Exception $e) {
121: Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
122: Mage::getSingleton('adminhtml/session')->setRatingData($this->getRequest()->getPost());
123: $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
124: return;
125: }
126: }
127: $this->_redirect('*/*/');
128: }
129:
130: public function deleteAction()
131: {
132: if( $this->getRequest()->getParam('id') > 0 ) {
133: try {
134: $model = Mage::getModel('rating/rating');
135:
136: $model->load($this->getRequest()->getParam('id'))
137: ->delete();
138: Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('The rating has been deleted.'));
139: $this->_redirect('*/*/');
140: } catch (Exception $e) {
141: Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
142: $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
143: }
144: }
145: $this->_redirect('*/*/');
146: }
147:
148: protected function _initEnityId()
149: {
150: $this->_title($this->__('Catalog'))
151: ->_title($this->__('Reviews and Ratings'))
152: ->_title($this->__('Manage Ratings'));
153:
154: Mage::register('entityId', Mage::getModel('rating/rating_entity')->getIdByCode('product'));
155: }
156:
157: protected function _isAllowed()
158: {
159: return Mage::getSingleton('admin/session')->isAllowed('catalog/reviews_ratings/ratings');
160: }
161:
162: }
163: