/app/code/core/Mage/AdminNotification/Model/Inbox.php

https://gitlab.com/LisovyiEvhenii/ismextensions · PHP · 210 lines · 81 code · 14 blank · 115 comment · 4 complexity · aa4212b432eb6c0b18d5d10f6d352f43 MD5 · raw file

  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@magento.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.magento.com for more information.
  20. *
  21. * @category Mage
  22. * @package Mage_AdminNotification
  23. * @copyright Copyright (c) 2006-2016 X.commerce, Inc. and affiliates (http://www.magento.com)
  24. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  25. */
  26. /**
  27. * AdminNotification Inbox model
  28. *
  29. * @method Mage_AdminNotification_Model_Resource_Inbox _getResource()
  30. * @method Mage_AdminNotification_Model_Resource_Inbox getResource()
  31. * @method int getSeverity()
  32. * @method Mage_AdminNotification_Model_Inbox setSeverity(int $value)
  33. * @method string getDateAdded()
  34. * @method Mage_AdminNotification_Model_Inbox setDateAdded(string $value)
  35. * @method string getTitle()
  36. * @method Mage_AdminNotification_Model_Inbox setTitle(string $value)
  37. * @method string getDescription()
  38. * @method Mage_AdminNotification_Model_Inbox setDescription(string $value)
  39. * @method string getUrl()
  40. * @method Mage_AdminNotification_Model_Inbox setUrl(string $value)
  41. * @method int getIsRead()
  42. * @method Mage_AdminNotification_Model_Inbox setIsRead(int $value)
  43. * @method int getIsRemove()
  44. * @method Mage_AdminNotification_Model_Inbox setIsRemove(int $value)
  45. *
  46. * @category Mage
  47. * @package Mage_AdminNotification
  48. * @author Magento Core Team <core@magentocommerce.com>
  49. */
  50. class Mage_AdminNotification_Model_Inbox extends Mage_Core_Model_Abstract
  51. {
  52. const SEVERITY_CRITICAL = 1;
  53. const SEVERITY_MAJOR = 2;
  54. const SEVERITY_MINOR = 3;
  55. const SEVERITY_NOTICE = 4;
  56. protected function _construct()
  57. {
  58. $this->_init('adminnotification/inbox');
  59. }
  60. /**
  61. * Retrieve Severity collection array
  62. *
  63. * @return array|string
  64. */
  65. public function getSeverities($severity = null)
  66. {
  67. $severities = array(
  68. self::SEVERITY_CRITICAL => Mage::helper('adminnotification')->__('critical'),
  69. self::SEVERITY_MAJOR => Mage::helper('adminnotification')->__('major'),
  70. self::SEVERITY_MINOR => Mage::helper('adminnotification')->__('minor'),
  71. self::SEVERITY_NOTICE => Mage::helper('adminnotification')->__('notice'),
  72. );
  73. if (!is_null($severity)) {
  74. if (isset($severities[$severity])) {
  75. return $severities[$severity];
  76. }
  77. return null;
  78. }
  79. return $severities;
  80. }
  81. /**
  82. * Retrieve Latest Notice
  83. *
  84. * @return Mage_AdminNotification_Model_Inbox
  85. */
  86. public function loadLatestNotice()
  87. {
  88. $this->setData(array());
  89. $this->getResource()->loadLatestNotice($this);
  90. return $this;
  91. }
  92. /**
  93. * Retrieve notice statuses
  94. *
  95. * @return array
  96. */
  97. public function getNoticeStatus()
  98. {
  99. return $this->getResource()->getNoticeStatus($this);
  100. }
  101. /**
  102. * Parse and save new data
  103. *
  104. * @param array $data
  105. * @return Mage_AdminNotification_Model_Inbox
  106. */
  107. public function parse(array $data)
  108. {
  109. return $this->getResource()->parse($this, $data);
  110. }
  111. /**
  112. * Add new message
  113. *
  114. * @param int $severity
  115. * @param string $title
  116. * @param string|array $description
  117. * @param string $url
  118. * @param bool $isInternal
  119. * @return Mage_AdminNotification_Model_Inbox
  120. */
  121. public function add($severity, $title, $description, $url = '', $isInternal = true)
  122. {
  123. if (!$this->getSeverities($severity)) {
  124. Mage::throwException($this->__('Wrong message type'));
  125. }
  126. if (is_array($description)) {
  127. $description = '<ul><li>' . implode('</li><li>', $description) . '</li></ul>';
  128. }
  129. $date = date('Y-m-d H:i:s');
  130. $this->parse(array(array(
  131. 'severity' => $severity,
  132. 'date_added' => $date,
  133. 'title' => $title,
  134. 'description' => $description,
  135. 'url' => $url,
  136. 'internal' => $isInternal
  137. )));
  138. return $this;
  139. }
  140. /**
  141. * Add critical severity message
  142. *
  143. * @param string $title
  144. * @param string|array $description
  145. * @param string $url
  146. * @param bool $isInternal
  147. * @return Mage_AdminNotification_Model_Inbox
  148. */
  149. public function addCritical($title, $description, $url = '', $isInternal = true)
  150. {
  151. $this->add(self::SEVERITY_CRITICAL, $title, $description, $url, $isInternal);
  152. return $this;
  153. }
  154. /**
  155. * Add major severity message
  156. *
  157. * @param string $title
  158. * @param string|array $description
  159. * @param string $url
  160. * @param bool $isInternal
  161. * @return Mage_AdminNotification_Model_Inbox
  162. */
  163. public function addMajor($title, $description, $url = '', $isInternal = true)
  164. {
  165. $this->add(self::SEVERITY_MAJOR, $title, $description, $url, $isInternal);
  166. return $this;
  167. }
  168. /**
  169. * Add minor severity message
  170. *
  171. * @param string $title
  172. * @param string|array $description
  173. * @param string $url
  174. * @param bool $isInternal
  175. * @return Mage_AdminNotification_Model_Inbox
  176. */
  177. public function addMinor($title, $description, $url = '', $isInternal = true)
  178. {
  179. $this->add(self::SEVERITY_MINOR, $title, $description, $url, $isInternal);
  180. return $this;
  181. }
  182. /**
  183. * Add notice
  184. *
  185. * @param string $title
  186. * @param string|array $description
  187. * @param string $url
  188. * @param bool $isInternal
  189. * @return Mage_AdminNotification_Model_Inbox
  190. */
  191. public function addNotice($title, $description, $url = '', $isInternal = true)
  192. {
  193. $this->add(self::SEVERITY_NOTICE, $title, $description, $url, $isInternal);
  194. return $this;
  195. }
  196. }