1: <?php
2: /**
3: * Magento
4: *
5: * NOTICE OF LICENSE
6: *
7: * This source file is subject to the Open Software License (OSL 3.0)
8: * that is bundled with this package in the file LICENSE.txt.
9: * It is also available through the world-wide-web at this URL:
10: * http://opensource.org/licenses/osl-3.0.php
11: * If you did not receive a copy of the license and are unable to
12: * obtain it through the world-wide-web, please send an email
13: * to license@magentocommerce.com so we can send you a copy immediately.
14: *
15: * DISCLAIMER
16: *
17: * Do not edit or add to this file if you wish to upgrade Magento to newer
18: * versions in the future. If you wish to customize Magento for your
19: * needs please refer to http://www.magentocommerce.com for more information.
20: *
21: * @category Mage
22: * @package Mage_AdminNotification
23: * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24: * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25: */
26:
27:
28: /**
29: * AdminNotification Inbox model
30: *
31: * @method Mage_AdminNotification_Model_Resource_Inbox _getResource()
32: * @method Mage_AdminNotification_Model_Resource_Inbox getResource()
33: * @method int getSeverity()
34: * @method Mage_AdminNotification_Model_Inbox setSeverity(int $value)
35: * @method string getDateAdded()
36: * @method Mage_AdminNotification_Model_Inbox setDateAdded(string $value)
37: * @method string getTitle()
38: * @method Mage_AdminNotification_Model_Inbox setTitle(string $value)
39: * @method string getDescription()
40: * @method Mage_AdminNotification_Model_Inbox setDescription(string $value)
41: * @method string getUrl()
42: * @method Mage_AdminNotification_Model_Inbox setUrl(string $value)
43: * @method int getIsRead()
44: * @method Mage_AdminNotification_Model_Inbox setIsRead(int $value)
45: * @method int getIsRemove()
46: * @method Mage_AdminNotification_Model_Inbox setIsRemove(int $value)
47: *
48: * @category Mage
49: * @package Mage_AdminNotification
50: * @author Magento Core Team <core@magentocommerce.com>
51: */
52: class Mage_AdminNotification_Model_Inbox extends Mage_Core_Model_Abstract
53: {
54: const SEVERITY_CRITICAL = 1;
55: const SEVERITY_MAJOR = 2;
56: const SEVERITY_MINOR = 3;
57: const SEVERITY_NOTICE = 4;
58:
59: protected function _construct()
60: {
61: $this->_init('adminnotification/inbox');
62: }
63:
64: /**
65: * Retrieve Severity collection array
66: *
67: * @return array|string
68: */
69: public function getSeverities($severity = null)
70: {
71: $severities = array(
72: self::SEVERITY_CRITICAL => Mage::helper('adminnotification')->__('critical'),
73: self::SEVERITY_MAJOR => Mage::helper('adminnotification')->__('major'),
74: self::SEVERITY_MINOR => Mage::helper('adminnotification')->__('minor'),
75: self::SEVERITY_NOTICE => Mage::helper('adminnotification')->__('notice'),
76: );
77:
78: if (!is_null($severity)) {
79: if (isset($severities[$severity])) {
80: return $severities[$severity];
81: }
82: return null;
83: }
84:
85: return $severities;
86: }
87:
88: /**
89: * Retrieve Latest Notice
90: *
91: * @return Mage_AdminNotification_Model_Inbox
92: */
93: public function loadLatestNotice()
94: {
95: $this->setData(array());
96: $this->getResource()->loadLatestNotice($this);
97: return $this;
98: }
99:
100: /**
101: * Retrieve notice statuses
102: *
103: * @return array
104: */
105: public function getNoticeStatus()
106: {
107: return $this->getResource()->getNoticeStatus($this);
108: }
109:
110: /**
111: * Parse and save new data
112: *
113: * @param array $data
114: * @return Mage_AdminNotification_Model_Inbox
115: */
116: public function parse(array $data)
117: {
118: return $this->getResource()->parse($this, $data);
119: }
120:
121: /**
122: * Add new message
123: *
124: * @param int $severity
125: * @param string $title
126: * @param string|array $description
127: * @param string $url
128: * @param bool $isInternal
129: * @return Mage_AdminNotification_Model_Inbox
130: */
131: public function add($severity, $title, $description, $url = '', $isInternal = true)
132: {
133: if (!$this->getSeverities($severity)) {
134: Mage::throwException($this->__('Wrong message type'));
135: }
136: if (is_array($description)) {
137: $description = '<ul><li>' . implode('</li><li>', $description) . '</li></ul>';
138: }
139: $date = date('Y-m-d H:i:s');
140: $this->parse(array(array(
141: 'severity' => $severity,
142: 'date_added' => $date,
143: 'title' => $title,
144: 'description' => $description,
145: 'url' => $url,
146: 'internal' => $isInternal
147: )));
148: return $this;
149: }
150:
151: /**
152: * Add critical severity message
153: *
154: * @param string $title
155: * @param string|array $description
156: * @param string $url
157: * @param bool $isInternal
158: * @return Mage_AdminNotification_Model_Inbox
159: */
160: public function addCritical($title, $description, $url = '', $isInternal = true)
161: {
162: $this->add(self::SEVERITY_CRITICAL, $title, $description, $url, $isInternal);
163: return $this;
164: }
165:
166: /**
167: * Add major severity message
168: *
169: * @param string $title
170: * @param string|array $description
171: * @param string $url
172: * @param bool $isInternal
173: * @return Mage_AdminNotification_Model_Inbox
174: */
175: public function addMajor($title, $description, $url = '', $isInternal = true)
176: {
177: $this->add(self::SEVERITY_MAJOR, $title, $description, $url, $isInternal);
178: return $this;
179: }
180:
181: /**
182: * Add minor severity message
183: *
184: * @param string $title
185: * @param string|array $description
186: * @param string $url
187: * @param bool $isInternal
188: * @return Mage_AdminNotification_Model_Inbox
189: */
190: public function addMinor($title, $description, $url = '', $isInternal = true)
191: {
192: $this->add(self::SEVERITY_MINOR, $title, $description, $url, $isInternal);
193: return $this;
194: }
195:
196: /**
197: * Add notice
198: *
199: * @param string $title
200: * @param string|array $description
201: * @param string $url
202: * @param bool $isInternal
203: * @return Mage_AdminNotification_Model_Inbox
204: */
205: public function addNotice($title, $description, $url = '', $isInternal = true)
206: {
207: $this->add(self::SEVERITY_NOTICE, $title, $description, $url, $isInternal);
208: return $this;
209: }
210: }
211: