BxTasksMenuBrowse.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. * @defgroup Tasks Tasks
  6. * @ingroup UnaModules
  7. *
  8. * @{
  9. */
  10. class BxTasksMenuBrowse extends BxTemplMenu
  11. {
  12. protected $_sModule;
  13. protected $_oModule;
  14. protected $_iProfileId;
  15. protected $_oPermalink;
  16. protected $_sParamName;
  17. protected $_iParamValue;
  18. public function __construct($aObject, $oTemplate = false)
  19. {
  20. $this->_sModule = 'bx_tasks';
  21. $this->_oModule = BxDolModule::getInstance($this->_sModule);
  22. parent::__construct($aObject, $oTemplate);
  23. $this->_isMultilevel = true;
  24. $this->_iProfileId = 0;
  25. $this->_oPermalink = BxDolPermalinks::getInstance();
  26. $this->_sParamName = 'context_pid';
  27. if(($iParamValue = bx_get($this->_sParamName)) !== false)
  28. $this->_iParamValue = (int)$iParamValue;
  29. }
  30. public function setProfileId($iProfileId)
  31. {
  32. $this->_iProfileId = $iProfileId;
  33. }
  34. protected function getMenuItemsRaw ()
  35. {
  36. $aContexts = $this->_oModule->getContexts();
  37. $aMenuItems = [];
  38. foreach($aContexts as $sName => $sTitle) {
  39. $aSubmenu = $this->_getMenuSubitems($this->_iProfileId, $sName);
  40. if(empty($aSubmenu))
  41. continue;
  42. $aMenuItems[] = [
  43. 'name' => $sName,
  44. 'class' => '',
  45. 'link' => 'javascript:void(0)',
  46. 'onclick' => "javascript:bx_menu_toggle(this, '" . $this->_sObject . "', '" . $sName . "')",
  47. 'target' => '_self',
  48. 'icon' => bx_is_srv($sName, 'module_icon') ? bx_srv($sName, 'module_icon') : '',
  49. 'title' => $sTitle,
  50. 'subitems' => $aSubmenu
  51. ];
  52. }
  53. return $aMenuItems;
  54. }
  55. protected function _getMenuSubitems($iProfile, $sContextModule)
  56. {
  57. $CNF = $this->_oModule->_oConfig->CNF;
  58. $aIds = $this->_oModule->_oDb->getContextsIdsByType($sContextModule, $iProfile);
  59. $aSubmenu = [];
  60. foreach($aIds as $iId) {
  61. $oContext = BxDolProfile::getInstance($iId);
  62. if(!$oContext)
  63. continue;
  64. $sUrl = bx_absolute_url(bx_append_url_params($this->_oPermalink->permalink($CNF['URL_HOME']), [
  65. $this->_sParamName => $iId
  66. ]));
  67. $aSubmenu[] = [
  68. 'id' => 'context-' . $iId,
  69. 'name' => 'context-' . $iId,
  70. 'class_add' => $iId == $this->_iParamValue ? 'bx-menu-tab-active' : '',
  71. 'class' => '',
  72. 'link' => $this->_bIsApi ? bx_api_get_relative_url($sUrl) : $sUrl,
  73. 'onclick' => '',
  74. 'target' => '_self',
  75. 'title' => $oContext->getDisplayName(),
  76. 'icon' => $oContext->getIcon(),
  77. 'active' => 1
  78. ];
  79. }
  80. return $aSubmenu;
  81. }
  82. }
  83. /** @} */