BxBaseInformer.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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-red-frame.png',
  19. BX_INFORMER_INFO => 'information-frame.png',
  20. );
  21. protected $_aMapType2Class = array(
  22. BX_INFORMER_ALERT => 'bx-informer-msg-alert',
  23. BX_INFORMER_INFO => 'bx-informer-msg-info',
  24. );
  25. public function __construct ($oTemplate) {
  26. parent::__construct ();
  27. if ($oTemplate)
  28. $this->_oTemplate = $oTemplate;
  29. else
  30. $this->_oTemplate = BxDolTemplate::getInstance();
  31. }
  32. /**
  33. * Display Informer.
  34. */
  35. public function display () {
  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->_aMessages[$sId]['icon_url'] = $this->_oTemplate->getIconUrl($this->_aMapType2Icon[$a['type']]);
  42. }
  43. $this->_addJsCss();
  44. return $this->_oTemplate->parseHtmlByName('informer.html', array(
  45. 'bx_repeat:messages' => $this->_aMessages,
  46. ));
  47. }
  48. /**
  49. * Add css/js files which are needed for display and functionality.
  50. */
  51. protected function _addJsCss() {
  52. if ($this->_bJsCssAdded)
  53. return;
  54. $this->_oTemplate->addCss('informer.css');
  55. $this->_bJsCssAdded = true;
  56. }
  57. }
  58. /** @} */