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
00035 class Mage_Adminhtml_Poll_AnswerController extends Mage_Adminhtml_Controller_Action
00036 {
00037 public function editAction()
00038 {
00039 $this->loadLayout();
00040
00041 $this->_setActiveMenu('cms/poll');
00042 $this->_addBreadcrumb(Mage::helper('poll')->__('Poll Manager'), Mage::helper('poll')->__('Poll Manager'), $this->getUrl('*/*/'));
00043 $this->_addBreadcrumb(Mage::helper('poll')->__('Edit Poll Answer'), Mage::helper('poll')->__('Edit Poll Answer'));
00044
00045 $this->_addContent($this->getLayout()->createBlock('adminhtml/poll_answer_edit'));
00046
00047 $this->renderLayout();
00048 }
00049
00050 public function saveAction()
00051 {
00052
00053 if ( $post = $this->getRequest()->getPost() ) {
00054 try {
00055 $model = Mage::getModel('poll/poll_answer');
00056 $model->setData($post)
00057 ->setId($this->getRequest()->getParam('id'))
00058 ->save();
00059
00060 Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('poll')->__('Answer was successfully saved'));
00061 $this->_redirect('*/poll/edit', array('id' => $this->getRequest()->getParam('poll_id'), 'tab' => 'answers_section'));
00062 return;
00063 } catch (Exception $e) {
00064 Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
00065 $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
00066 return;
00067 }
00068 }
00069 $this->_redirect('*/*/');
00070 }
00071
00072 public function gridAction()
00073 {
00074 $this->getResponse()->setBody($this->getLayout()->createBlock('adminhtml/poll_edit_tab_answers_grid')->toHtml());
00075 }
00076
00077 public function jsonSaveAction()
00078 {
00079 $response = new Varien_Object();
00080 $response->setError(0);
00081
00082 if ( $post = $this->getRequest()->getPost() ) {
00083 $data = Zend_Json_Decoder::decode($post['data']);
00084 try {
00085 if( trim($data['answer_title']) == '' ) {
00086 throw new Exception(Mage::helper('poll')->__('Invalid Answer'));
00087 }
00088 $model = Mage::getModel('poll/poll_answer');
00089 $model->setData($data)
00090 ->save();
00091 } catch (Exception $e) {
00092 $response->setError(1);
00093 $response->setMessage($e->getMessage());
00094 }
00095 }
00096 $this->getResponse()->setBody( $response->toJson() );
00097 }
00098
00099 public function jsonDeleteAction()
00100 {
00101 $response = new Varien_Object();
00102 $response->setError(0);
00103
00104 if ( $id = $this->getRequest()->getParam('id') ) {
00105 try {
00106 $model = Mage::getModel('poll/poll_answer');
00107 $model->setId(Zend_Json_Decoder::decode($id))
00108 ->delete();
00109 } catch (Exception $e) {
00110 $response->setError(1);
00111 $response->setMessage($e->getMessage());
00112 }
00113 } else {
00114 $response->setError(1);
00115 $response->setMessage(Mage::helper('poll')->__('Unable to find answer to delete.'));
00116 }
00117 $this->getResponse()->setBody( $response->toJson() );
00118 }
00119
00120 protected function _isAllowed()
00121 {
00122 return Mage::getSingleton('admin/session')->isAllowed('cms/poll');
00123 }
00124
00125 }