BxBaseMenuMoreAuto.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. define('BX_DEF_MENU_ITEM_MORE_AUTO', 'more-auto');
  11. class BxBaseMenuMoreAuto extends BxTemplMenu
  12. {
  13. protected $_sTmplNameItemMore;
  14. protected $_sTmplNameItemMorePopup;
  15. protected $_bMoreAuto;
  16. protected $_iMoreAutoItemsStatic;
  17. protected $_bMoreAutoItemsStaticOnly;
  18. protected $_sJsObjectMoreAuto;
  19. protected $_aHtmlIds;
  20. public function __construct($aObject, $oTemplate = false)
  21. {
  22. parent::__construct($aObject, $oTemplate);
  23. $this->_sTmplNameItemMore = 'menu_item_more.html';
  24. $this->_sTmplNameItemMorePopup = 'menu_item_more_popup.html';
  25. $this->_bMoreAuto = null;
  26. $this->_iMoreAutoItemsStatic = 1;
  27. $this->_bMoreAutoItemsStaticOnly = false;
  28. $this->_sJsObjectMoreAuto = 'oMenuMoreAuto' . bx_gen_method_name($this->_sObject);
  29. $sPrefix = str_replace('_', '-', $this->_sObject);
  30. $this->_aHtmlIds = array(
  31. 'main' => $sPrefix,
  32. 'more_auto_popup' => $sPrefix . '-ma-popup',
  33. );
  34. }
  35. public function getCode()
  36. {
  37. $sResult = parent::getCode();
  38. if($this->_isMoreAuto()) {
  39. $this->_oTemplate->addJs(array('BxDolMenuMoreAuto.js'));
  40. if(!empty($sResult))
  41. $sResult = $this->_oTemplate->parseHtmlByName('menu_more_auto.html', array(
  42. 'menu' => $sResult
  43. ));
  44. }
  45. return $sResult;
  46. }
  47. protected function _isMoreAuto()
  48. {
  49. if(is_bool($this->_bMoreAuto))
  50. return $this->_bMoreAuto;
  51. $aResult = $this->getMenuItems();
  52. $sItem = BX_DEF_MENU_ITEM_MORE_AUTO;
  53. if(!empty($this->_aObject['menu_items'][$sItem]) && is_array($this->_aObject['menu_items'][$sItem]) && (int)$this->_aObject['menu_items'][$sItem]['active'] == 1)
  54. $this->_bMoreAuto = true;
  55. else
  56. $this->_bMoreAuto = false;
  57. return $this->_bMoreAuto;
  58. }
  59. protected function _getTemplateVars()
  60. {
  61. $bMoreAuto = $this->_isMoreAuto();
  62. $aResult = array_merge(parent::_getTemplateVars(), array(
  63. 'html_id' => $this->_getHtmlIdMain(),
  64. 'bx_if:show_more_auto_class' => array(
  65. 'condition' => $bMoreAuto,
  66. 'content' => array()
  67. ),
  68. 'js_code' => $bMoreAuto ? $this->_getJsCodeMoreAuto() : ''
  69. ));
  70. return $aResult;
  71. }
  72. protected function _getJsCodeMoreAuto()
  73. {
  74. $sJsObject = $this->_getJsObjectMoreAuto();
  75. $aJsParams = array(
  76. 'sObject' => $this->_sObject,
  77. 'iItemsStatic' => $this->_iMoreAutoItemsStatic,
  78. 'bItemsStaticOnly' => $this->_bMoreAutoItemsStaticOnly ? 1 : 0,
  79. 'aHtmlIds' => $this->_getHtmlIds()
  80. );
  81. return $this->_oTemplate->_wrapInTagJsCode("if(!" . $sJsObject . ") {var " . $sJsObject . " = new BxDolMenuMoreAuto(" . json_encode($aJsParams) . "); " . $sJsObject . ".init();}");
  82. }
  83. protected function _getMenuItem ($aItem)
  84. {
  85. $aItem['popup'] = '';
  86. if($aItem['name'] != BX_DEF_MENU_ITEM_MORE_AUTO)
  87. return parent::_getMenuItem($aItem);
  88. $aItem['onclick'] = $this->_getJsObjectMoreAuto() . '.more(this);';
  89. $aItem['popup'] = BxTemplFunctions::getInstance()->transBox($this->_aHtmlIds['more_auto_popup'], $this->_oTemplate->parseHtmlByName($this->_getTmplNameItemMorePopup(), array(
  90. 'content' => ''
  91. )), true);
  92. return parent::_getMenuItem($aItem);
  93. }
  94. protected function _getHtmlIds()
  95. {
  96. return $this->_aHtmlIds;
  97. }
  98. protected function _getHtmlIdMain()
  99. {
  100. return $this->_aHtmlIds['main'];
  101. }
  102. protected function _getJsObjectMoreAuto()
  103. {
  104. return $this->_sJsObjectMoreAuto;
  105. }
  106. protected function _getTmplNameItemMore()
  107. {
  108. return $this->_sTmplNameItemMore;
  109. }
  110. protected function _getTmplNameItemMorePopup()
  111. {
  112. return $this->_sTmplNameItemMorePopup;
  113. }
  114. }
  115. /** @} */