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_NotificationController extends Mage_Adminhtml_Controller_Action
36: {
37: public function indexAction()
38: {
39: $this->_title($this->__('System'))->_title($this->__('Notifications'));
40:
41: $this->loadLayout()
42: ->_setActiveMenu('system/notification')
43: ->_addBreadcrumb(Mage::helper('adminnotification')->__('Messages Inbox'), Mage::helper('adminhtml')->__('Messages Inbox'))
44: ->_addContent($this->getLayout()->createBlock('adminhtml/notification_inbox'))
45: ->renderLayout();
46: }
47:
48: public function markAsReadAction()
49: {
50: if ($id = $this->getRequest()->getParam('id')) {
51: $session = Mage::getSingleton('adminhtml/session');
52: $model = Mage::getModel('adminnotification/inbox')
53: ->load($id);
54:
55: if (!$model->getId()) {
56: $session->addError(Mage::helper('adminnotification')->__('Unable to proceed. Please, try again.'));
57: $this->_redirect('*/*/');
58: return ;
59: }
60:
61: try {
62: $model->setIsRead(1)
63: ->save();
64: $session->addSuccess(Mage::helper('adminnotification')->__('The message has been marked as read.'));
65: } catch (Mage_Core_Exception $e) {
66: $session->addError($e->getMessage());
67: } catch (Exception $e) {
68: $session->addException($e, Mage::helper('adminnotification')->__('An error occurred while marking notification as read.'));
69: }
70:
71: $this->_redirectReferer();
72: return;
73: }
74: $this->_redirect('*/*/');
75: }
76:
77: public function massMarkAsReadAction()
78: {
79: $session = Mage::getSingleton('adminhtml/session');
80: $ids = $this->getRequest()->getParam('notification');
81: if (!is_array($ids)) {
82: $session->addError(Mage::helper('adminnotification')->__('Please select messages.'));
83: } else {
84: try {
85: foreach ($ids as $id) {
86: $model = Mage::getModel('adminnotification/inbox')
87: ->load($id);
88: if ($model->getId()) {
89: $model->setIsRead(1)
90: ->save();
91: }
92: }
93: $this->_getSession()->addSuccess(
94: Mage::helper('adminnotification')->__('Total of %d record(s) have been marked as read.', count($ids))
95: );
96: } catch (Mage_Core_Exception $e) {
97: $session->addError($e->getMessage());
98: } catch (Exception $e) {
99: $session->addException($e, Mage::helper('adminnotification')->__('An error occurred while marking the messages as read.'));
100: }
101: }
102: $this->_redirect('*/*/');
103: }
104:
105: public function removeAction()
106: {
107: if ($id = $this->getRequest()->getParam('id')) {
108: $session = Mage::getSingleton('adminhtml/session');
109: $model = Mage::getModel('adminnotification/inbox')
110: ->load($id);
111:
112: if (!$model->getId()) {
113: $this->_redirect('*/*/');
114: return ;
115: }
116:
117: try {
118: $model->setIsRemove(1)
119: ->save();
120: $session->addSuccess(Mage::helper('adminnotification')->__('The message has been removed.'));
121: } catch (Mage_Core_Exception $e) {
122: $session->addError($e->getMessage());
123: } catch (Exception $e) {
124: $session->addException($e, Mage::helper('adminnotification')->__('An error occurred while removing the message.'));
125: }
126:
127: $this->_redirect('*/*/');
128: return;
129: }
130: $this->_redirect('*/*/');
131: }
132:
133: public function massRemoveAction()
134: {
135: $session = Mage::getSingleton('adminhtml/session');
136: $ids = $this->getRequest()->getParam('notification');
137: if (!is_array($ids)) {
138: $session->addError(Mage::helper('adminnotification')->__('Please select messages.'));
139: } else {
140: try {
141: foreach ($ids as $id) {
142: $model = Mage::getModel('adminnotification/inbox')
143: ->load($id);
144: if ($model->getId()) {
145: $model->setIsRemove(1)
146: ->save();
147: }
148: }
149: $this->_getSession()->addSuccess(
150: Mage::helper('adminnotification')->__('Total of %d record(s) have been removed.', count($ids))
151: );
152: } catch (Mage_Core_Exception $e) {
153: $session->addError($e->getMessage());
154: } catch (Exception $e) {
155: $session->addException($e, Mage::helper('adminnotification')->__('An error occurred while removing messages.'));
156: }
157: }
158: $this->_redirectReferer();
159: }
160:
161: protected function _isAllowed()
162: {
163: switch ($this->getRequest()->getActionName()) {
164: case 'markAsRead':
165: $acl = 'system/adminnotification/mark_as_read';
166: break;
167:
168: case 'massMarkAsRead':
169: $acl = 'system/adminnotification/mark_as_read';
170: break;
171:
172: case 'remove':
173: $acl = 'system/adminnotification/remove';
174: break;
175:
176: case 'massRemove':
177: $acl = 'system/adminnotification/remove';
178: break;
179:
180: default:
181: $acl = 'system/adminnotification/show_list';
182: }
183: return Mage::getSingleton('admin/session')->isAllowed($acl);
184: }
185: }
186: