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