Mage_Adminhtml_SitemapController Class Reference

Inheritance diagram for Mage_Adminhtml_SitemapController:

Mage_Adminhtml_Controller_Action Mage_Core_Controller_Varien_Action

List of all members.

Public Member Functions

 indexAction ()
 newAction ()
 editAction ()
 saveAction ()
 deleteAction ()
 generateAction ()

Protected Member Functions

 _initAction ()
 _isAllowed ()


Detailed Description

Definition at line 34 of file SitemapController.php.


Member Function Documentation

_initAction (  )  [protected]

Init actions

Returns:
Mage_Adminhtml_SitemapController

Definition at line 41 of file SitemapController.php.

00042     {
00043         // load layout, set active menu and breadcrumbs
00044         $this->loadLayout()
00045             ->_setActiveMenu('catalog/system_sitemap')
00046             ->_addBreadcrumb(Mage::helper('catalog')->__('Catalog'), Mage::helper('catalog')->__('Catalog'))
00047             ->_addBreadcrumb(Mage::helper('sitemap')->__('Google Sitemap'), Mage::helper('sitemap')->__('Google Sitemap'))
00048         ;
00049         return $this;
00050     }

_isAllowed (  )  [protected]

Check the permission to run it

Returns:
boolean

Reimplemented from Mage_Adminhtml_Controller_Action.

Definition at line 241 of file SitemapController.php.

00242     {
00243         return Mage::getSingleton('admin/session')->isAllowed('catalog/sitemap');
00244     }

deleteAction (  ) 

Delete action

Definition at line 167 of file SitemapController.php.

00168     {
00169         // check if we know what should be deleted
00170         if ($id = $this->getRequest()->getParam('sitemap_id')) {
00171             try {
00172                 // init model and delete
00173                 $model = Mage::getModel('sitemap/sitemap');
00174                 $model->setId($id);
00175                 // init and load sitemap model
00176 
00177                 /* @var $sitemap Mage_Sitemap_Model_Sitemap */
00178                 $model->load($id);
00179                 // delete file
00180                 if ($model->getSitemapFilename() && file_exists($model->getPreparedFilename())){
00181                     unlink($model->getPreparedFilename());
00182                 }
00183                 $model->delete();
00184                 // display success message
00185                 Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('sitemap')->__('Sitemap was successfully deleted'));
00186                 // go to grid
00187                 $this->_redirect('*/*/');
00188                 return;
00189 
00190             } catch (Exception $e) {
00191                 // display error message
00192                 Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
00193                 // go back to edit form
00194                 $this->_redirect('*/*/edit', array('sitemap_id' => $id));
00195                 return;
00196             }
00197         }
00198         // display error message
00199         Mage::getSingleton('adminhtml/session')->addError(Mage::helper('sitemap')->__('Unable to find a sitemap to delete'));
00200         // go to grid
00201         $this->_redirect('*/*/');
00202     }

editAction (  ) 

Edit sitemap

Definition at line 74 of file SitemapController.php.

00075     {
00076         // 1. Get ID and create model
00077         $id = $this->getRequest()->getParam('sitemap_id');
00078         $model = Mage::getModel('sitemap/sitemap');
00079 
00080         // 2. Initial checking
00081         if ($id) {
00082             $model->load($id);
00083             if (! $model->getId()) {
00084                 Mage::getSingleton('adminhtml/session')->addError(Mage::helper('sitemap')->__('This sitemap no longer exists'));
00085                 $this->_redirect('*/*/');
00086                 return;
00087             }
00088         }
00089 
00090         // 3. Set entered data if was error when we do save
00091         $data = Mage::getSingleton('adminhtml/session')->getFormData(true);
00092         if (! empty($data)) {
00093             $model->setData($data);
00094         }
00095 
00096         // 4. Register model to use later in blocks
00097         Mage::register('sitemap_sitemap', $model);
00098 
00099         // 5. Build edit form
00100         $this->_initAction()
00101             ->_addBreadcrumb($id ? Mage::helper('sitemap')->__('Edit Sitemap') : Mage::helper('sitemap')->__('New Sitemap'), $id ? Mage::helper('sitemap')->__('Edit Sitemap') : Mage::helper('sitemap')->__('New Sitemap'))
00102             ->_addContent($this->getLayout()->createBlock('adminhtml/sitemap_edit'))
00103             ->renderLayout();
00104     }

generateAction (  ) 

Generate sitemap

Definition at line 207 of file SitemapController.php.

00208     {
00209         // init and load sitemap model
00210         $id = $this->getRequest()->getParam('sitemap_id');
00211         $sitemap = Mage::getModel('sitemap/sitemap');
00212         /* @var $sitemap Mage_Sitemap_Model_Sitemap */
00213         $sitemap->load($id);
00214         // if sitemap record exists
00215         if ($sitemap->getId()) {
00216             try {
00217                 $sitemap->generateXml();
00218 
00219                 $this->_getSession()->addSuccess(Mage::helper('sitemap')->__('Sitemap "%s" has been successfully generated', $sitemap->getSitemapFilename()));
00220             }
00221             catch (Mage_Core_Exception $e) {
00222                 $this->_getSession()->addError($e->getMessage());
00223             }
00224             catch (Exception $e) {
00225                 $this->_getSession()->addException($e, Mage::helper('sitemap')->__('Unable to generate a sitemap'));
00226             }
00227         }
00228         else {
00229             $this->_getSession()->addError(Mage::helper('sitemap')->__('Unable to find a sitemap to generate'));
00230         }
00231 
00232         // go to grid
00233         $this->_redirect('*/*/');
00234     }

indexAction (  ) 

Index action

Definition at line 55 of file SitemapController.php.

00056     {
00057         $this->_initAction()
00058             ->_addContent($this->getLayout()->createBlock('adminhtml/sitemap'))
00059             ->renderLayout();
00060     }

newAction (  ) 

Create new sitemap

Definition at line 65 of file SitemapController.php.

00066     {
00067         // the same form is used to create and edit
00068         $this->_forward('edit');
00069     }

saveAction (  ) 

Save action

Definition at line 109 of file SitemapController.php.

00110     {
00111         // check if data sent
00112         if ($data = $this->getRequest()->getPost()) {
00113             // init model and set data
00114             $model = Mage::getModel('sitemap/sitemap');
00115 
00116             if ($this->getRequest()->getParam('sitemap_id')) {
00117                 $model ->load($this->getRequest()->getParam('sitemap_id'));
00118 
00119                 if ($model->getSitemapFilename() && file_exists($model->getPreparedFilename())){
00120                     unlink($model->getPreparedFilename());
00121                 }
00122             }
00123 
00124 
00125             $model->setData($data);
00126 
00127             // try to save it
00128             try {
00129                 // save the data
00130                 $model->save();
00131                 // display success message
00132                 Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('sitemap')->__('Sitemap was successfully saved'));
00133                 // clear previously saved data from session
00134                 Mage::getSingleton('adminhtml/session')->setFormData(false);
00135 
00136                 // check if 'Save and Continue'
00137                 if ($this->getRequest()->getParam('back')) {
00138                     $this->_redirect('*/*/edit', array('sitemap_id' => $model->getId()));
00139                     return;
00140                 }
00141                 // go to grid or forward to generate action
00142                 if ($this->getRequest()->getParam('generate')) {
00143                     $this->getRequest()->setParam('sitemap_id', $model->getId());
00144                     $this->_forward('generate');
00145                     return;
00146                 }
00147                 $this->_redirect('*/*/');
00148                 return;
00149 
00150             } catch (Exception $e) {
00151                 // display error message
00152                 Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
00153                 // save data in session
00154                 Mage::getSingleton('adminhtml/session')->setFormData($data);
00155                 // redirect to edit form
00156                 $this->_redirect('*/*/edit', array('sitemap_id' => $this->getRequest()->getParam('sitemap_id')));
00157                 return;
00158             }
00159         }
00160         $this->_redirect('*/*/');
00161 
00162     }


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:23:29 2009 for Magento by  doxygen 1.5.8