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_Poll_AnswerController extends Mage_Adminhtml_Controller_Action
36: {
37: public function editAction()
38: {
39: $this->loadLayout();
40:
41: $this->_setActiveMenu('cms/poll');
42: $this->_addBreadcrumb(Mage::helper('poll')->__('Poll Manager'),
43: Mage::helper('poll')->__('Poll Manager'), $this->getUrl('*/*/'));
44: $this->_addBreadcrumb(Mage::helper('poll')->__('Edit Poll Answer'),
45: Mage::helper('poll')->__('Edit Poll Answer'));
46:
47: $this->_addContent($this->getLayout()->createBlock('adminhtml/poll_answer_edit'));
48:
49: $this->renderLayout();
50: }
51:
52: public function saveAction()
53: {
54:
55: if ( $post = $this->getRequest()->getPost() ) {
56: try {
57: $model = Mage::getModel('poll/poll_answer');
58: $model->setData($post)
59: ->setId($this->getRequest()->getParam('id'))
60: ->save();
61:
62: Mage::getSingleton('adminhtml/session')->addSuccess(
63: Mage::helper('poll')->__('The answer has been saved.'));
64: $this->_redirect('*/poll/edit',
65: array('id' => $this->getRequest()->getParam('poll_id'), 'tab' => 'answers_section'));
66: return;
67: } catch (Exception $e) {
68: Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
69: $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
70: return;
71: }
72: }
73: $this->_redirect('*/*/');
74: }
75:
76: public function gridAction()
77: {
78: $this->getResponse()->setBody(
79: $this->getLayout()->createBlock('adminhtml/poll_edit_tab_answers_grid')->toHtml()
80: );
81: }
82:
83: public function jsonSaveAction()
84: {
85: $response = new Varien_Object();
86: $response->setError(0);
87:
88: if ( $post = $this->getRequest()->getPost() ) {
89: $data = Zend_Json::decode($post['data']);
90: try {
91: if( trim($data['answer_title']) == '' ) {
92: throw new Exception(Mage::helper('poll')->__('Invalid Answer.'));
93: }
94: $model = Mage::getModel('poll/poll_answer');
95: $model->setData($data)
96: ->save();
97: } catch (Exception $e) {
98: $response->setError(1);
99: $response->setMessage($e->getMessage());
100: }
101: }
102: $this->getResponse()->setBody( $response->toJson() );
103: }
104:
105: public function jsonDeleteAction()
106: {
107: $response = new Varien_Object();
108: $response->setError(0);
109:
110: if ( $id = $this->getRequest()->getParam('id') ) {
111: try {
112: $model = Mage::getModel('poll/poll_answer');
113: $model->setId(Zend_Json::decode($id))
114: ->delete();
115: } catch (Exception $e) {
116: $response->setError(1);
117: $response->setMessage($e->getMessage());
118: }
119: } else {
120: $response->setError(1);
121: $response->setMessage(Mage::helper('poll')->__('Unable to find an answer to delete.'));
122: }
123: $this->getResponse()->setBody( $response->toJson() );
124: }
125:
126: protected function _isAllowed()
127: {
128: return Mage::getSingleton('admin/session')->isAllowed('cms/poll');
129: }
130:
131: }
132: