BxDolInformer.php 3.1 KB

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