BxDolInformer.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup DolphinCore Dolphin Core
  7. * @{
  8. */
  9. define('BX_INFORMER_ALERT', 1);
  10. define('BX_INFORMER_INFO', 2);
  11. define('BX_INFORMER_ERROR', 3);
  12. /**
  13. * @page objects
  14. * @section informer Informer
  15. * @ref BxDolInformer
  16. */
  17. /**
  18. * Informer.
  19. *
  20. * It displays alerts or information messages in clearly visible area on the page to let user know important information.
  21. *
  22. * @section example Example of usage
  23. *
  24. * Adding message to informer:
  25. *
  26. * @code
  27. * bx_import('BxDolInformer'); // import informer class
  28. * $oInformer = BxDolInformer::getInstance(); // get object instance
  29. * if ($oInformer) // check if Informer is available for using
  30. * echo $oInformer->add ('my_id', 'Some important information here', BX_INFORMER_ALERT); // add an alert message
  31. * @endcode
  32. *
  33. */
  34. class BxDolInformer extends BxDol
  35. {
  36. protected $_aMessages = array();
  37. /**
  38. * Constructor
  39. */
  40. public function __construct()
  41. {
  42. if (isset($GLOBALS['bxDolClasses']['BxDolInformer']))
  43. trigger_error ('Multiple instances are not allowed for the BxDolInformer class.', E_USER_ERROR);
  44. parent::__construct();
  45. }
  46. /**
  47. * Prevent cloning the instance
  48. */
  49. public function __clone()
  50. {
  51. if (isset($GLOBALS['bxDolClasses']['BxDolInformer']))
  52. trigger_error('Clone is not allowed for the BxDolInformer class.', E_USER_ERROR);
  53. }
  54. /**
  55. * Get Informer object instance
  56. * @return object instance or false on error
  57. */
  58. public static function getInstance($oTemplate = false)
  59. {
  60. if (isset($GLOBALS['bxDolClasses']['BxDolInformer']))
  61. return $GLOBALS['bxDolClasses']['BxDolInformer'];
  62. bx_import('BxTemplInformer');
  63. $o = new BxTemplInformer($oTemplate);
  64. return ($GLOBALS['bxDolClasses']['BxDolInformer'] = $o);
  65. }
  66. /**
  67. * Add message to informer.
  68. * @param $sId - message id
  69. * @param $sMsg - message text
  70. * @param $iType - message type: BX_INFORMER_ALERT, BX_INFORMER_INFO or BX_INFORMER_ERROR
  71. */
  72. public function add ($sId, $sMsg, $iType = BX_INFORMER_INFO)
  73. {
  74. $this->_aMessages[$sId] = array (
  75. 'id' => $sId,
  76. 'msg' => $sMsg,
  77. 'type' => $iType,
  78. );
  79. }
  80. /**
  81. * Remove message from informer.
  82. * @param $sId - message id
  83. */
  84. public function remove ($sId)
  85. {
  86. unset($this->_aMessages[$sId]);
  87. }
  88. /**
  89. * Add permanent messages which are displayed on every page.
  90. */
  91. protected function _addPermanentMessages ()
  92. {
  93. // add account & profile related permament messages
  94. if (isLogged()) {
  95. bx_import('BxDolAccount');
  96. $oAccount = BxDolAccount::getInstance();
  97. if ($oAccount)
  98. $oAccount->addInformerPermanentMessages($this);
  99. bx_import('BxDolProfile');
  100. $oProfile = BxDolProfile::getInstance();
  101. if ($oProfile)
  102. $oProfile->addInformerPermanentMessages($this);
  103. }
  104. // add permament messages from modules
  105. bx_alert('system', 'informer_permament_messages', 0, false, array('informer' => $this));
  106. }
  107. }
  108. /** @} */