BxBaseInformer.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. bx_import('BxDolInformer');
  10. /**
  11. * Informer representation.
  12. * @see BxDolInformer
  13. */
  14. class BxBaseInformer extends BxDolInformer
  15. {
  16. protected $_bJsCssAdded = false;
  17. protected $_oTemplate;
  18. protected $_aMapType2Class = array(
  19. BX_INFORMER_ALERT => 'bx-informer-msg-alert',
  20. BX_INFORMER_INFO => 'bx-informer-msg-info',
  21. BX_INFORMER_ERROR => 'bx-informer-msg-error',
  22. );
  23. public function __construct ($oTemplate)
  24. {
  25. parent::__construct ();
  26. if ($oTemplate)
  27. $this->_oTemplate = $oTemplate;
  28. else
  29. $this->_oTemplate = BxDolTemplate::getInstance();
  30. }
  31. /**
  32. * Display Informer.
  33. */
  34. public function display ()
  35. {
  36. $this->_addPermanentMessages();
  37. if (!$this->_aMessages)
  38. return '';
  39. foreach ($this->_aMessages as $sId => $a)
  40. $this->_aMessages[$sId]['class'] = $this->_aMapType2Class[$a['type']];
  41. $this->_addJsCss();
  42. return $this->_oTemplate->parseHtmlByName('informer.html', array(
  43. 'bx_repeat:messages' => $this->_aMessages,
  44. ));
  45. }
  46. /**
  47. * Add css/js files which are needed for display and functionality.
  48. */
  49. protected function _addJsCss()
  50. {
  51. if ($this->_bJsCssAdded)
  52. return;
  53. $this->_oTemplate->addCss(array('informer.css'));
  54. $this->_bJsCssAdded = true;
  55. }
  56. }
  57. /** @} */