BxBaseMenuProfileFollowings.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. * Menu representation.
  11. * @see BxDolMenu
  12. */
  13. class BxBaseMenuProfileFollowings extends BxTemplMenu
  14. {
  15. protected $_sConnection;
  16. protected $_oConnection;
  17. protected $_iPerPageDefault;
  18. public function __construct ($aObject, $oTemplate)
  19. {
  20. parent::__construct ($aObject, $oTemplate);
  21. $this->_bMultilevel = true;
  22. $this->_bDisplayAddons = true;
  23. $this->_sConnection = 'sys_profiles_subscriptions';
  24. $this->_oConnection = BxDolConnection::getObjectInstance($this->_sConnection);
  25. $this->_iPerPageDefault = 10;
  26. }
  27. public function performActionLoadMore($sContextModule)
  28. {
  29. $aResult = [];
  30. $iStart = (int)bx_get('start');
  31. $iPerPage = (int)bx_get('per_page');
  32. $iProfile = bx_get_logged_profile_id();
  33. $aSubitems = $this->_getMenuSubitems($iProfile, $sContextModule, $iStart, $iPerPage);
  34. if(empty($aSubitems) || !is_array($aSubitems))
  35. return echoJson($aResult);
  36. $aTmplVarsSubitems = [];
  37. foreach($aSubitems as $aSubitem) {
  38. $aSubitem = $this->_getMenuItem($aSubitem);
  39. if($aSubitem !== false)
  40. $aTmplVarsSubitems[] = $aSubitem;
  41. }
  42. $aResult['content'] = $this->_oTemplate->parseHtmlByName(str_replace('.html', '_subitems.html', $this->getTemplateName()), [
  43. 'bx_repeat:menu_items' => $aTmplVarsSubitems,
  44. ]);
  45. return echoJson($aResult);
  46. }
  47. protected function getMenuItemsRaw ()
  48. {
  49. $aMenuItems = parent::getMenuItemsRaw();
  50. if(empty($aMenuItems) || !is_array($aMenuItems))
  51. return $aMenuItems;
  52. $iProfile = bx_get_logged_profile_id();
  53. foreach($aMenuItems as $iIndex => $aItem) {
  54. if(empty($aItem['icon']) && bx_is_srv($aItem['module'], 'module_icon'))
  55. $aMenuItems[$iIndex]['icon'] = bx_srv($aItem['module'], 'module_icon');
  56. if(empty($aItem['onclick']))
  57. $aMenuItems[$iIndex]['onclick'] = "javascript:bx_menu_toggle(this, '" . $this->_sObject . "', '" . $aItem['name'] . "')";
  58. $aSubmenu = $this->_getMenuSubitems($iProfile, $aItem['module']);
  59. if(!empty($aSubmenu))
  60. $aMenuItems[$iIndex]['subitems'] = $aSubmenu;
  61. else
  62. unset($aMenuItems[$iIndex]);
  63. }
  64. return $aMenuItems;
  65. }
  66. protected function _getMenuSubitems($iProfile, $sContextModule, $iStart = 0, $iPerPage = 0)
  67. {
  68. if(!$iPerPage)
  69. $iPerPage = $this->_iPerPageDefault;
  70. $aIds = $this->_oConnection->getConnectedContentByType($iProfile, [$sContextModule], false, $iStart, $iPerPage + 1);
  71. $bNext = false;
  72. if(count($aIds) > $iPerPage) {
  73. array_pop($aIds);
  74. $bNext = true;
  75. }
  76. $aSubmenu = array();
  77. foreach($aIds as $iId) {
  78. $oContext = BxDolProfile::getInstance($iId);
  79. if(!$oContext)
  80. continue;
  81. $aSubmenu[] = array(
  82. 'id' => 'context-' . $iId,
  83. 'name' => 'context-' . $iId,
  84. 'class' => '',
  85. 'link' => $oContext->getUrl(),
  86. 'onclick' => '',
  87. 'target' => '_self',
  88. 'title' => $oContext->getDisplayName(),
  89. 'icon' => $oContext->getIcon(),
  90. 'active' => 1
  91. );
  92. }
  93. if($bNext) {
  94. $sMoreName = 'context-type-' . str_replace('_', '-', $sContextModule) . '-more';
  95. $aSubmenu[] = array(
  96. 'id' => $sMoreName,
  97. 'name' => $sMoreName,
  98. 'class' => '',
  99. 'link' => 'javascript:void(0)',
  100. 'onclick' => "javascript:bx_menu_followings_load_more(this, '" . $this->_sObject . "', '" . $sContextModule . "', " . ($iStart + $iPerPage) . ", " . $iPerPage . ")",
  101. 'target' => '_self',
  102. 'title' => _t('_sys_show_more'),
  103. 'icon' => 'chevron-down',
  104. 'active' => 1
  105. );
  106. }
  107. return $aSubmenu;
  108. }
  109. protected function _getTmplVarsAddon($mixedAddon, $aMenuItem)
  110. {
  111. $aAddon = parent::_getTmplVarsAddon($mixedAddon, $aMenuItem);
  112. $sAddonF = '';
  113. if(!empty($aAddon['addon']))
  114. $sAddonF = $this->_oTemplate->parseHtmlByTemplateName('menu_item_addon', array(
  115. 'content' => $aAddon['addon']
  116. ));
  117. return array(
  118. 'addon' => $aAddon['addon'],
  119. 'addonf' => $sAddonF
  120. );
  121. }
  122. }
  123. /** @} */