1
0

BxBaseMenuProfileFollowings.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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['onclick']))
  55. $aMenuItems[$iIndex]['onclick'] = "javascript:bx_menu_toggle(this, '" . $this->_sObject . "', '" . $aItem['name'] . "')";
  56. $aSubmenu = $this->_getMenuSubitems($iProfile, $aItem['module']);
  57. if(!empty($aSubmenu))
  58. $aMenuItems[$iIndex]['subitems'] = $aSubmenu;
  59. else
  60. unset($aMenuItems[$iIndex]);
  61. }
  62. return $aMenuItems;
  63. }
  64. protected function _getMenuSubitems($iProfile, $sContextModule, $iStart = 0, $iPerPage = 0)
  65. {
  66. if(!$iPerPage)
  67. $iPerPage = $this->_iPerPageDefault;
  68. $aIds = $this->_oConnection->getConnectedContentByType($iProfile, [$sContextModule], false, $iStart, $iPerPage + 1);
  69. $bNext = false;
  70. if(count($aIds) > $iPerPage) {
  71. array_pop($aIds);
  72. $bNext = true;
  73. }
  74. $aSubmenu = array();
  75. foreach($aIds as $iId) {
  76. $oContext = BxDolProfile::getInstance($iId);
  77. if(!$oContext)
  78. continue;
  79. $aSubmenu[] = array(
  80. 'id' => 'context-' . $iId,
  81. 'name' => 'context-' . $iId,
  82. 'class' => '',
  83. 'link' => $oContext->getUrl(),
  84. 'onclick' => '',
  85. 'target' => '_self',
  86. 'title' => $oContext->getDisplayName(),
  87. 'icon' => $oContext->getIcon(),
  88. 'active' => 1
  89. );
  90. }
  91. if($bNext) {
  92. $sMoreName = 'context-type-' . str_replace('_', '-', $sContextModule) . '-more';
  93. $aSubmenu[] = array(
  94. 'id' => $sMoreName,
  95. 'name' => $sMoreName,
  96. 'class' => '',
  97. 'link' => 'javascript:void(0)',
  98. 'onclick' => "javascript:bx_menu_followings_load_more(this, '" . $this->_sObject . "', '" . $sContextModule . "', " . ($iStart + $iPerPage) . ", " . $iPerPage . ")",
  99. 'target' => '_self',
  100. 'title' => _t('_sys_show_more'),
  101. 'icon' => 'chevron-down',
  102. 'active' => 1
  103. );
  104. }
  105. return $aSubmenu;
  106. }
  107. protected function _getTmplVarsAddon($mixedAddon, $aMenuItem)
  108. {
  109. $aAddon = parent::_getTmplVarsAddon($mixedAddon, $aMenuItem);
  110. $sAddonF = '';
  111. if(!empty($aAddon['addon']))
  112. $sAddonF = $this->_oTemplate->parseHtmlByTemplateName('menu_item_addon', array(
  113. 'content' => $aAddon['addon']
  114. ));
  115. return array(
  116. 'addon' => $aAddon['addon'],
  117. 'addonf' => $sAddonF
  118. );
  119. }
  120. }
  121. /** @} */