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 class Mage_Adminhtml_Catalog_SearchController extends Mage_Adminhtml_Controller_Action 00029 { 00030 protected function _initAction() 00031 { 00032 $this->loadLayout() 00033 ->_setActiveMenu('catalog/search') 00034 ->_addBreadcrumb(Mage::helper('catalog')->__('Search'), Mage::helper('catalog')->__('Search')) 00035 ; 00036 return $this; 00037 } 00038 00039 public function indexAction() 00040 { 00041 $this->_initAction() 00042 ->_addBreadcrumb(Mage::helper('catalog')->__('Catalog'), Mage::helper('catalog')->__('Catalog')) 00043 ->_addContent($this->getLayout()->createBlock('adminhtml/catalog_search')) 00044 ->renderLayout(); 00045 } 00046 00047 public function newAction() 00048 { 00049 $this->_forward('edit'); 00050 } 00051 00052 public function editAction() 00053 { 00054 $id = $this->getRequest()->getParam('id'); 00055 $model = Mage::getModel('catalogsearch/query'); 00056 00057 if ($id) { 00058 $model->load($id); 00059 if (! $model->getId()) { 00060 Mage::getSingleton('adminhtml/session')->addError(Mage::helper('catalog')->__('This search no longer exists')); 00061 $this->_redirect('*/*'); 00062 return; 00063 } 00064 } 00065 00066 // set entered data if was error when we do save 00067 $data = Mage::getSingleton('adminhtml/session')->getPageData(true); 00068 if (!empty($data)) { 00069 $model->addData($data); 00070 } 00071 00072 Mage::register('current_catalog_search', $model); 00073 00074 $block = $this->getLayout()->createBlock('adminhtml/catalog_search_edit') 00075 ->setData('action', $this->getUrl('*/catalog_search/save')); 00076 00077 $this->_initAction(); 00078 00079 $this->getLayout()->getBlock('head')->setCanLoadRulesJs(true); 00080 00081 $this 00082 ->_addBreadcrumb($id ? Mage::helper('catalog')->__('Edit Search') : Mage::helper('catalog')->__('New Search'), $id ? Mage::helper('catalog')->__('Edit Search') : Mage::helper('catalog')->__('New Search')) 00083 ->_addContent($block) 00084 ->renderLayout(); 00085 00086 } 00087 00088 public function saveAction() 00089 { 00090 if ($data = $this->getRequest()->getPost()) { 00091 $model = Mage::getModel('catalogsearch/query'); 00092 00093 if ($queryText = $this->getRequest()->getParam('query_text')) { 00094 $model->load($queryText); 00095 if ($model->getId() && $this->getRequest()->getParam('query_id') != $model->getId()) { 00096 Mage::getSingleton('adminhtml/session')->addError(Mage::helper('catalog')->__('Search Term with such search query already exist.')); 00097 Mage::getSingleton('adminhtml/session')->setPageData($data); 00098 $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('query_id'))); 00099 return; 00100 } 00101 } 00102 00103 $model->addData($data); 00104 Mage::getSingleton('adminhtml/session')->setPageData($model->getData()); 00105 try { 00106 $model->save(); 00107 Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('catalog')->__('Search Term was successfully saved')); 00108 Mage::getSingleton('adminhtml/session')->setPageData(false); 00109 $this->_redirect('*/*/'); 00110 return; 00111 } catch (Exception $e) { 00112 Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); 00113 Mage::getSingleton('adminhtml/session')->setPageData($data); 00114 $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id'))); 00115 return; 00116 } 00117 } 00118 $this->_redirect('*/*/'); 00119 } 00120 00121 public function deleteAction() 00122 { 00123 if ($id = $this->getRequest()->getParam('id')) { 00124 try { 00125 $model = Mage::getModel('catalogsearch/query'); 00126 $model->setId($id); 00127 $model->delete(); 00128 Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('catalog')->__('Search was successfully deleted')); 00129 $this->_redirect('*/*/'); 00130 return; 00131 } 00132 catch (Exception $e) { 00133 Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); 00134 $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id'))); 00135 return; 00136 } 00137 } 00138 Mage::getSingleton('adminhtml/session')->addError(Mage::helper('catalog')->__('Unable to find a search term to delete')); 00139 $this->_redirect('*/*/'); 00140 } 00141 00142 public function massDeleteAction() 00143 { 00144 $searchIds = $this->getRequest()->getParam('search'); 00145 if(!is_array($searchIds)) { 00146 Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Please select catalog searches')); 00147 } else { 00148 try { 00149 foreach ($searchIds as $searchId) { 00150 $model = Mage::getModel('catalogsearch/query')->load($searchId); 00151 $model->delete(); 00152 } 00153 Mage::getSingleton('adminhtml/session')->addSuccess( 00154 Mage::helper('adminhtml')->__( 00155 'Total of %d record(s) were successfully deleted', count($searchIds) 00156 ) 00157 ); 00158 } catch (Exception $e) { 00159 Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); 00160 } 00161 } 00162 00163 $this->_redirect('*/*/index'); 00164 } 00165 00166 protected function _isAllowed() 00167 { 00168 return Mage::getSingleton('admin/session')->isAllowed('catalog/search'); 00169 } 00170 }