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_Adminhtml_TagController extends Mage_Adminhtml_Controller_Action
00035 {
00036
00037 protected function _initAction()
00038 {
00039 $this->loadLayout()
00040 ->_setActiveMenu('catalog/tag')
00041 ->_addBreadcrumb(Mage::helper('adminhtml')->__('Catalog'), Mage::helper('adminhtml')->__('Catalog'))
00042 ->_addBreadcrumb(Mage::helper('adminhtml')->__('Tags'), Mage::helper('adminhtml')->__('Tags'))
00043 ;
00044 return $this;
00045 }
00046
00047 public function indexAction()
00048 {
00049 $this->_initAction()
00050 ->_addBreadcrumb(Mage::helper('adminhtml')->__('All Tags'), Mage::helper('adminhtml')->__('All Tags'))
00051 ->_setActiveMenu('catalog/tag/all')
00052 ->_addContent($this->getLayout()->createBlock('adminhtml/tag_tag'))
00053 ->renderLayout();
00054 }
00055
00056 public function newAction()
00057 {
00058 $this->_forward('edit');
00059 }
00060
00061 public function editAction()
00062 {
00063 $id = $this->getRequest()->getParam('tag_id');
00064 $model = Mage::getModel('tag/tag');
00065
00066 if ($id) {
00067 $model->load($id);
00068 }
00069
00070
00071 $data = Mage::getSingleton('adminhtml/session')->getTagData(true);
00072 if (! empty($data)) {
00073 $model->setData($data);
00074 }
00075
00076 Mage::register('tag_tag', $model);
00077
00078 $this->_initAction()
00079 ->_addBreadcrumb($id ? Mage::helper('adminhtml')->__('Edit Tag') : Mage::helper('adminhtml')->__('New Tag'), $id ? Mage::helper('adminhtml')->__('Edit Tag') : Mage::helper('adminhtml')->__('New Tag'))
00080 ->_addContent($this->getLayout()->createBlock('adminhtml/tag_tag_edit')->setData('action', $this->getUrl('*/tag_edit/save')))
00081 ->renderLayout();
00082 }
00083
00084 public function saveAction()
00085 {
00086 if ($data = $this->getRequest()->getPost()) {
00087 $data['name']=trim($data['name']);
00088 $model = Mage::getModel('tag/tag');
00089 $model->setData($data);
00090
00091 switch( $this->getRequest()->getParam('ret') ) {
00092 case 'all':
00093 $url = $this->getUrl('*/*/index', array(
00094 'customer_id' => $this->getRequest()->getParam('customer_id'),
00095 'product_id' => $this->getRequest()->getParam('product_id'),
00096 ));
00097 break;
00098
00099 case 'pending':
00100 $url = $this->getUrl('*/tag/pending', array(
00101 'customer_id' => $this->getRequest()->getParam('customer_id'),
00102 'product_id' => $this->getRequest()->getParam('product_id'),
00103 ));
00104 break;
00105
00106 default:
00107 $url = $this->getUrl('*/*/index', array(
00108 'customer_id' => $this->getRequest()->getParam('customer_id'),
00109 'product_id' => $this->getRequest()->getParam('product_id'),
00110 ));
00111 }
00112
00113
00114 try {
00115 $model->save();
00116 $model->aggregate();
00117 Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('Tag was successfully saved'));
00118 Mage::getSingleton('adminhtml/session')->setTagData(false);
00119 $this->getResponse()->setRedirect($url);
00120 return;
00121 } catch (Exception $e) {
00122 Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
00123 Mage::getSingleton('adminhtml/session')->setTagData($data);
00124 $this->_redirect('*/*/edit', array('tag_id' => $this->getRequest()->getParam('tag_id')));
00125 return;
00126 }
00127 }
00128 $this->getResponse()->setRedirect($url);
00129 }
00130
00131 public function deleteAction()
00132 {
00133 if ($id = $this->getRequest()->getParam('tag_id')) {
00134
00135 switch( $this->getRequest()->getParam('ret') ) {
00136 case 'all':
00137 $url = $this->getUrl('*/*/', array(
00138 'customer_id' => $this->getRequest()->getParam('customer_id'),
00139 'product_id' => $this->getRequest()->getParam('product_id'),
00140 ));
00141 break;
00142
00143 case 'pending':
00144 $url = $this->getUrl('*/tag/pending', array(
00145 'customer_id' => $this->getRequest()->getParam('customer_id'),
00146 'product_id' => $this->getRequest()->getParam('product_id'),
00147 ));
00148 break;
00149
00150 default:
00151 $url = $this->getUrl('*/*/', array(
00152 'customer_id' => $this->getRequest()->getParam('customer_id'),
00153 'product_id' => $this->getRequest()->getParam('product_id'),
00154 ));
00155 }
00156
00157 try {
00158 $model = Mage::getModel('tag/tag');
00159 $model->setId($id);
00160 $model->delete();
00161 Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('Tag was successfully deleted'));
00162 $this->getResponse()->setRedirect($url);
00163 return;
00164 }
00165 catch (Exception $e) {
00166 Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
00167 $this->_redirect('*/*/edit', array('tag_id' => $this->getRequest()->getParam('tag_id')));
00168 return;
00169 }
00170 }
00171 Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Unable to find a tag to delete'));
00172 $this->getResponse()->setRedirect($url);
00173 }
00174
00175
00176
00177
00178
00179 public function pendingAction()
00180 {
00181 $this->_initAction()
00182 ->_addBreadcrumb(Mage::helper('adminhtml')->__('Pending Tags'), Mage::helper('adminhtml')->__('Pending Tags'))
00183 ->_setActiveMenu('catalog/tag/pending')
00184 ->_addContent($this->getLayout()->createBlock('adminhtml/tag_pending'))
00185 ->renderLayout();
00186 }
00187
00188
00189
00190
00191
00192 public function productAction()
00193 {
00194 Mage::register('tagId', $this->getRequest()->getParam('tag_id'));
00195
00196 $this->_initAction()
00197 ->_addBreadcrumb(Mage::helper('adminhtml')->__('Products'), Mage::helper('adminhtml')->__('Products'))
00198 ->_setActiveMenu('catalog/tag/product')
00199 ->_addContent($this->getLayout()->createBlock('adminhtml/tag_product'))
00200 ->renderLayout();
00201 }
00202
00203
00204
00205
00206
00207 public function customerAction()
00208 {
00209 Mage::register('tagId', $this->getRequest()->getParam('tag_id'));
00210
00211 $this->_initAction()
00212 ->_addBreadcrumb(Mage::helper('adminhtml')->__('Customers'), Mage::helper('adminhtml')->__('Customers'))
00213 ->_setActiveMenu('catalog/tag/customer')
00214 ->_addContent($this->getLayout()->createBlock('adminhtml/tag_customer'))
00215 ->renderLayout();
00216 }
00217
00218 public function massDeleteAction()
00219 {
00220 $tagIds = $this->getRequest()->getParam('tag');
00221 if(!is_array($tagIds)) {
00222 Mage::getSingleton('adminhtml/session')->addError($this->__('Please select tag(s)'));
00223 } else {
00224 try {
00225 foreach ($tagIds as $tagId) {
00226 $tag = Mage::getModel('tag/tag')->load($tagId);
00227 $tag->delete();
00228 }
00229 Mage::getSingleton('adminhtml/session')->addSuccess(
00230 $this->__('Total of %d record(s) were successfully deleted', count($tagIds))
00231 );
00232 } catch (Exception $e) {
00233 Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
00234 }
00235 }
00236 $ret = $this->getRequest()->getParam('ret') ? $this->getRequest()->getParam('ret') : 'index';
00237 $this->_redirect('*/*/'.$ret);
00238 }
00239
00240 public function massStatusAction()
00241 {
00242 $tagIds = $this->getRequest()->getParam('tag');
00243 $storeId = (int)$this->getRequest()->getParam('store', 0);
00244 if(!is_array($tagIds)) {
00245
00246 Mage::getSingleton('adminhtml/session')->addError($this->__('Please select tag(s)'));
00247 } else {
00248 try {
00249 foreach ($tagIds as $tagId) {
00250 $tag = Mage::getModel('tag/tag')
00251 ->load($tagId)
00252 ->setStatus($this->getRequest()->getParam('status'));
00253 $tag->save();
00254 }
00255 Mage::getSingleton('adminhtml/session')->addSuccess(
00256 $this->__('Total of %d record(s) were successfully updated', count($tagIds))
00257 );
00258 } catch (Exception $e) {
00259 Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
00260 }
00261 }
00262 $ret = $this->getRequest()->getParam('ret') ? $this->getRequest()->getParam('ret') : 'index';
00263 $this->_redirect('*/*/'.$ret);
00264 }
00265
00266 protected function _isAllowed()
00267 {
00268 switch ($this->getRequest()->getActionName()) {
00269 case 'pending':
00270 return Mage::getSingleton('admin/session')->isAllowed('catalog/tag/pending');
00271 break;
00272 case 'all':
00273 return Mage::getSingleton('admin/session')->isAllowed('catalog/tag/all');
00274 break;
00275 default:
00276 return Mage::getSingleton('admin/session')->isAllowed('catalog/tag');
00277 break;
00278 }
00279 }
00280 }