BxBaseMenuMoreAuto.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 $_sJsObjectMoreAuto;
  18. protected $_aHtmlIds;
  19. public function __construct($aObject, $oTemplate = false)
  20. {
  21. parent::__construct($aObject, $oTemplate);
  22. $this->_sTmplNameItemMore = 'menu_item_more.html';
  23. $this->_sTmplNameItemMorePopup = 'menu_item_more_popup.html';
  24. $this->_bMoreAuto = null;
  25. $this->_iMoreAutoItemsStatic = 1;
  26. $this->_sJsObjectMoreAuto = 'oMenuMoreAuto' . bx_gen_method_name($this->_sObject);
  27. $sPrefix = str_replace('_', '-', $this->_sObject);
  28. $this->_aHtmlIds = array(
  29. 'more_auto_popup' => $sPrefix . '-ma-popup',
  30. );
  31. }
  32. public function getCode()
  33. {
  34. $sResult = parent::getCode();
  35. if($this->_isMoreAuto())
  36. $this->_oTemplate->addJs(array('BxDolMenuMoreAuto.js'));
  37. return $sResult;
  38. }
  39. protected function _isMoreAuto()
  40. {
  41. if(is_bool($this->_bMoreAuto))
  42. return $this->_bMoreAuto;
  43. $aResult = $this->getMenuItems();
  44. $sItem = BX_DEF_MENU_ITEM_MORE_AUTO;
  45. if(!empty($this->_aObject['menu_items'][$sItem]) && is_array($this->_aObject['menu_items'][$sItem]) && (int)$this->_aObject['menu_items'][$sItem]['active'] == 1)
  46. $this->_bMoreAuto = true;
  47. else
  48. $this->_bMoreAuto = false;
  49. return $this->_bMoreAuto;
  50. }
  51. protected function _getTemplateVars()
  52. {
  53. $bMoreAuto = $this->_isMoreAuto();
  54. $aResult = array_merge(parent::_getTemplateVars(), array(
  55. 'bx_if:show_more_auto_class' => array(
  56. 'condition' => $bMoreAuto,
  57. 'content' => array()
  58. ),
  59. 'js_code' => $bMoreAuto ? $this->_getJsCodeMoreAuto() : ''
  60. ));
  61. return $aResult;
  62. }
  63. protected function _getJsCodeMoreAuto()
  64. {
  65. $aParams = array(
  66. 'sObject' => $this->_sObject,
  67. 'iItemsStatic' => $this->_iMoreAutoItemsStatic,
  68. 'aHtmlIds' => $this->_aHtmlIds
  69. );
  70. return $this->_oTemplate->_wrapInTagJsCode("if(!" . $this->_sJsObjectMoreAuto . ") var " . $this->_sJsObjectMoreAuto . " = new BxDolMenuMoreAuto(" . json_encode($aParams) . "); " . $this->_sJsObjectMoreAuto . ".init();");
  71. }
  72. protected function _getMenuItem ($aItem)
  73. {
  74. $aItem['popup'] = '';
  75. if($aItem['name'] != BX_DEF_MENU_ITEM_MORE_AUTO)
  76. return parent::_getMenuItem($aItem);
  77. $aItem['onclick'] = $this->_sJsObjectMoreAuto . '.more(this);';
  78. $aItem['popup'] = BxTemplFunctions::getInstance()->transBox($this->_aHtmlIds['more_auto_popup'], $this->_oTemplate->parseHtmlByName($this->_getTmplNameItemMorePopup(), array(
  79. 'content' => ''
  80. )), true);
  81. return parent::_getMenuItem($aItem);
  82. }
  83. protected function _getTmplNameItemMore()
  84. {
  85. return $this->_sTmplNameItemMore;
  86. }
  87. protected function _getTmplNameItemMorePopup()
  88. {
  89. return $this->_sTmplNameItemMorePopup;
  90. }
  91. }
  92. /** @} */