1
0

BxBaseCategories.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. * Multi Categories object representation.
  11. * @see BxDolCategories
  12. */
  13. class BxBaseCategories extends BxDolCategories
  14. {
  15. protected $_oTemplate;
  16. public function __construct($oTemplate = null)
  17. {
  18. parent::__construct();
  19. if($oTemplate)
  20. $this->_oTemplate = $oTemplate;
  21. else
  22. $this->_oTemplate = BxDolTemplate::getInstance();
  23. }
  24. public function getCategoriesList($bAsArray = false)
  25. {
  26. $aContextInfo = bx_get_page_info();
  27. $mProfileContextId = false;
  28. if($aContextInfo !== false)
  29. $mProfileContextId = $aContextInfo['context_profile_id'];
  30. if($mProfileContextId)
  31. $aCats = $this->getData([
  32. 'type' => 'by_module&context_with_num',
  33. 'module' => $this->_sModule,
  34. 'context_id' => $mProfileContextId
  35. ]);
  36. else
  37. $aCats = $this->getData([
  38. 'type' => 'by_module_with_num',
  39. 'module' => $this->_sModule
  40. ]);
  41. $aTmplVarsCats = [];
  42. foreach($aCats as $aCat) {
  43. $bIcon = !empty($aCat['icon']);
  44. $sValue = $aCat['value'];
  45. $aTmplVarsCats[] = array_merge([
  46. 'url' => $this->getUrl($this->_sModule, $sValue, $mProfileContextId ? '&context_id=' . $mProfileContextId : ''),
  47. 'name' => _t($sValue),
  48. 'value' => $sValue,
  49. 'num' => (int)$aCat['num'],
  50. ], !$this->_bIsApi ? [
  51. 'bx_if:show_icon' => [
  52. 'condition' => $bIcon,
  53. 'content' => [
  54. 'bx_if:show_icon_font' => [
  55. 'condition' => $bIcon && $aCat['icon_type'] == 'icon',
  56. 'content' => [
  57. 'icon_name' => $aCat['icon'],
  58. ]
  59. ],
  60. 'bx_if:show_icon_html' => [
  61. 'condition' => $bIcon && in_array($aCat['icon_type'], ['emoji', 'image']),
  62. 'content' => [
  63. 'icon_code' => $aCat['icon'],
  64. ]
  65. ],
  66. ]
  67. ],
  68. 'selected_class' => $sValue == bx_get('category') ? 'bx-menu-tab-active' : '',
  69. ] : [
  70. 'icon_type' => $aCat['icon_type'],
  71. 'icon' => $aCat['icon']
  72. ]);
  73. }
  74. if($bAsArray)
  75. return $aTmplVarsCats;
  76. return !empty($aTmplVarsCats) ? $this->_oTemplate->parseHtmlByName('category_list_multi.html', [
  77. 'bx_repeat:cats' => $aTmplVarsCats
  78. ]) : '';
  79. }
  80. }
  81. /** @} */