BxBaseInformer.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaBaseView UNA Base Representation Classes
  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. if(!$this->_bEnabled)
  36. return '';
  37. $this->_addPermanentMessages();
  38. if (!$this->_aMessages)
  39. return '';
  40. $aTmplVarsMessages = array();
  41. foreach ($this->_aMessages as $sId => $a) {
  42. $a['class'] = $this->_aMapType2Class[$a['type']];
  43. $aTmplVarsMessages[] = $a;
  44. }
  45. $this->_addJsCss();
  46. return $this->_oTemplate->parseHtmlByName('informer.html', array(
  47. 'bx_repeat:messages' => $aTmplVarsMessages,
  48. ));
  49. }
  50. /**
  51. * Add css/js files which are needed for display and functionality.
  52. */
  53. protected function _addJsCss()
  54. {
  55. if ($this->_bJsCssAdded)
  56. return;
  57. $this->_oTemplate->addCss(array('informer.css'));
  58. $this->_bJsCssAdded = true;
  59. }
  60. }
  61. /** @} */