BxBaseInformer.php 1.9 KB

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