BxBaseModTextMenuCategories.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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 BaseText Base classes for text modules
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. /**
  12. * Menu representation.
  13. * @see BxDolMenu
  14. */
  15. class BxBaseModTextMenuCategories extends BxTemplMenu
  16. {
  17. protected $_sModule;
  18. protected $_oModule;
  19. protected $_bExtendedMode;
  20. public function __construct ($aObject, $oTemplate)
  21. {
  22. parent::__construct ($aObject, $oTemplate);
  23. $this->_oModule = BxDolModule::getInstance($this->_sModule);
  24. $this->_bDisplayAddons = true;
  25. $this->_bExtendedMode = false;
  26. }
  27. public function getMenuItems ()
  28. {
  29. $CNF = &$this->_oModule->_oConfig->CNF;
  30. $oCategory = BxDolCategory::getObjectInstance($CNF['OBJECT_CATEGORY']);
  31. if(!$oCategory)
  32. return [];
  33. $aCategories = $oCategory->getCategoriesList(false, true);
  34. if($this->_bIsApi && $aCategories && is_array($aCategories))
  35. return reset($aCategories)['data'];
  36. if(!isset($aCategories['bx_repeat:cats']))
  37. return [];
  38. $iCount = 0;
  39. foreach ($aCategories['bx_repeat:cats'] as $sKey => $aCategory) {
  40. $iCount += $aCategories['bx_repeat:cats'][$sKey]['num'];
  41. }
  42. $aItems = [[
  43. 'class_add' => 'bx-psmi-show-0' . (bx_get('category') == '' ? ' bx-menu-item-active' : ''),
  44. 'name' => 'show-0',
  45. 'title' => _t($CNF['T']['txt_all_categories']),
  46. 'link' => BxDolPermalinks::getInstance()->permalink($CNF['URL_HOME']),
  47. 'icon' => '',
  48. 'bx_if:onclick' => [
  49. 'condition' => false,
  50. 'content' => [
  51. 'onclick' => 'javascript:',
  52. ]
  53. ],
  54. 'attrs' => '',
  55. 'bx_if:image' => array (
  56. 'condition' => false,
  57. 'content' => [],
  58. ),
  59. 'bx_if:image_inline' => array (
  60. 'condition' => false,
  61. 'content' => [],
  62. ),
  63. 'bx_if:icon' => array (
  64. 'condition' => $this->_bExtendedMode,
  65. 'content' => ['icon' => 'swatchbook'],
  66. ),
  67. 'bx_if:icon-a' => array (
  68. 'condition' => false,
  69. 'content' => [],
  70. ),
  71. 'bx_if:icon-html' => array (
  72. 'condition' => false,
  73. 'content' => [],
  74. ),
  75. 'bx_if:addon' => [
  76. 'condition' => true,
  77. 'content' => ['addon' => $iCount]
  78. ]
  79. ]];
  80. foreach ($aCategories['bx_repeat:cats'] as $sKey => $aCategory) {
  81. $aCategoryData = $this->_getExtendedInfo($aCategory['value']);
  82. if(!empty($aCategoryData) && (empty($aCategoryData['visible_for_levels']) || !BxDolAcl::getInstance()->isMemberLevelInSet($aCategoryData['visible_for_levels'])))
  83. continue;
  84. $sIconSrc = $sIcon = $sIconUrl = $sIconA = $sIconHtml = '';
  85. if($this->_bExtendedMode && !empty($aCategoryData)) {
  86. $sIconSrc = $aCategoryData['icon'] ?: 'folder';
  87. list($sIcon, $sIconUrl, $sIconA, $sIconHtml) = BxTemplFunctions::getInstance()->getIcon($sIconSrc);
  88. }
  89. $aItems[] = [
  90. 'class_add' => 'bx-psmi-show-' . $aCategories['bx_repeat:cats'][$sKey]['value'] . (bx_get('category') == $aCategories['bx_repeat:cats'][$sKey]['value'] ? ' bx-menu-item-active' : ''),
  91. 'name' => 'show-' . $aCategories['bx_repeat:cats'][$sKey]['value'],
  92. 'title' => $aCategories['bx_repeat:cats'][$sKey]['name'],
  93. 'link' => $aCategories['bx_repeat:cats'][$sKey]['url'],
  94. 'icon' => $sIconSrc,
  95. 'bx_if:onclick' => [
  96. 'condition' => false,
  97. 'content' => [
  98. 'onclick' => 'javascript:',
  99. ]
  100. ],
  101. 'attrs' => '',
  102. 'bx_if:image' => array (
  103. 'condition' => (bool)$sIconUrl,
  104. 'content' => array('icon_url' => $sIconUrl),
  105. ),
  106. 'bx_if:image_inline' => array (
  107. 'condition' => false,
  108. 'content' => array('image' => ''),
  109. ),
  110. 'bx_if:icon' => array (
  111. 'condition' => (bool)$sIcon,
  112. 'content' => array('icon' => $sIcon),
  113. ),
  114. 'bx_if:icon-a' => array (
  115. 'condition' => (bool)$sIconA,
  116. 'content' => array('icon-a' => $sIconA),
  117. ),
  118. 'bx_if:icon-html' => array (
  119. 'condition' => (bool)$sIconHtml,
  120. 'content' => array('icon' => $sIconHtml),
  121. ),
  122. 'bx_if:addon' => [
  123. 'condition' => true,
  124. 'content' => ['addon' => $aCategories['bx_repeat:cats'][$sKey]['num']]
  125. ]
  126. ];
  127. }
  128. if(empty($aItems) || !is_array($aItems))
  129. return $aItems;
  130. return $this->_addMenuItemsMoreLess($aItems, (int)getParam($CNF['PARAM_VISIBLE_CATEGORIES']));
  131. }
  132. protected function _getMenuItem($a)
  133. {
  134. $mixedResult = parent::_getMenuItem($a);
  135. if($mixedResult !== false && !empty($mixedResult['link']) && strpos($mixedResult['link'], 'javascript:') === false)
  136. $mixedResult['link'] = bx_append_url_params($mixedResult['link'], [
  137. 'owner' => 1
  138. ]);
  139. return $mixedResult;
  140. }
  141. protected function _getExtendedInfo($iId)
  142. {
  143. return $this->_oModule->_oDb->getCategories(['type' => 'by_category', 'category' => $iId]);
  144. }
  145. }
  146. /** @} */