BxBaseInformer.php 1.6 KB

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