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 DolphinCore Dolphin Core
  7. * @{
  8. */
  9. bx_import('BxDolInformer');
  10. /**
  11. * Informer representation.
  12. * @see BxDolInformer
  13. */
  14. class BxBaseInformer extends BxDolInformer {
  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. parent::__construct ();
  24. if ($oTemplate)
  25. $this->_oTemplate = $oTemplate;
  26. else
  27. $this->_oTemplate = BxDolTemplate::getInstance();
  28. }
  29. /**
  30. * Display Informer.
  31. */
  32. public function display () {
  33. $this->_addPermanentMessages();
  34. if (!$this->_aMessages)
  35. return '';
  36. foreach ($this->_aMessages as $sId => $a)
  37. $this->_aMessages[$sId]['class'] = $this->_aMapType2Class[$a['type']];
  38. $this->_addJsCss();
  39. return $this->_oTemplate->parseHtmlByName('informer.html', array(
  40. 'bx_repeat:messages' => $this->_aMessages,
  41. ));
  42. }
  43. /**
  44. * Add css/js files which are needed for display and functionality.
  45. */
  46. protected function _addJsCss() {
  47. if ($this->_bJsCssAdded)
  48. return;
  49. $this->_oTemplate->addCss(array('informer.css'));
  50. $this->_bJsCssAdded = true;
  51. }
  52. }
  53. /** @} */