BxBaseInformer.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. foreach ($this->_aMessages as $sId => $a)
  39. $this->_aMessages[$sId]['class'] = $this->_aMapType2Class[$a['type']];
  40. $this->_addJsCss();
  41. return $this->_oTemplate->parseHtmlByName('informer.html', array(
  42. 'bx_repeat:messages' => $this->_aMessages,
  43. ));
  44. }
  45. /**
  46. * Add css/js files which are needed for display and functionality.
  47. */
  48. protected function _addJsCss()
  49. {
  50. if ($this->_bJsCssAdded)
  51. return;
  52. $this->_oTemplate->addCss(array('informer.css'));
  53. $this->_bJsCssAdded = true;
  54. }
  55. }
  56. /** @} */