BxDolInformer.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. protected $_aMessages = array();
  36. /**
  37. * Constructor
  38. */
  39. public function __construct() {
  40. if (isset($GLOBALS['bxDolClasses']['BxDolInformer']))
  41. trigger_error ('Multiple instances are not allowed for the BxDolInformer class.', E_USER_ERROR);
  42. parent::__construct();
  43. }
  44. /**
  45. * Prevent cloning the instance
  46. */
  47. public function __clone() {
  48. if (isset($GLOBALS['bxDolClasses']['BxDolInformer']))
  49. trigger_error('Clone is not allowed for the BxDolInformer class.', E_USER_ERROR);
  50. }
  51. /**
  52. * Get Informer object instance
  53. * @return object instance or false on error
  54. */
  55. public static function getInstance($oTemplate = false) {
  56. if (isset($GLOBALS['bxDolClasses']['BxDolInformer']))
  57. return $GLOBALS['bxDolClasses']['BxDolInformer'];
  58. bx_import('BxTemplInformer');
  59. $o = new BxTemplInformer($oTemplate);
  60. return ($GLOBALS['bxDolClasses']['BxDolInformer'] = $o);
  61. }
  62. /**
  63. * Add message to informer.
  64. * @param $sId - message id
  65. * @param $sMsg - message text
  66. * @param $iType - message type: BX_INFORMER_ALERT, BX_INFORMER_INFO or BX_INFORMER_ERROR
  67. */
  68. public function add ($sId, $sMsg, $iType = BX_INFORMER_INFO) {
  69. $this->_aMessages[$sId] = array (
  70. 'id' => $sId,
  71. 'msg' => $sMsg,
  72. 'type' => $iType,
  73. );
  74. }
  75. /**
  76. * Remove message from informer.
  77. * @param $sId - message id
  78. */
  79. public function remove ($sId) {
  80. unset($this->_aMessages[$sId]);
  81. }
  82. /**
  83. * Add permanent messages which are displayed on every page.
  84. */
  85. protected function _addPermanentMessages () {
  86. // add account related permament messages
  87. if (isLogged()) {
  88. bx_import('BxDolAccount');
  89. $oAccount = BxDolAccount::getInstance();
  90. if ($oAccount)
  91. $oAccount->addInformerPermanentMessages($this);
  92. }
  93. // add permament messages from modules
  94. bx_alert('system', 'informer_permament_messages', 0, false, array('informer' => $this));
  95. }
  96. }
  97. /** @} */