BxBaseMenuManage.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 BxBaseMenuManage extends BxTemplMenu
  14. {
  15. protected $_sObjectManage;
  16. protected $_oObjectManage;
  17. protected $_bAsButton;
  18. protected $_iContentId;
  19. public function __construct ($aObject, $oTemplate)
  20. {
  21. parent::__construct ($aObject, $oTemplate);
  22. $this->_sObjectManage = false;
  23. $this->_oObjectManage = null;
  24. $this->_bAsButton = false;
  25. $this->_iContentId = 0;
  26. }
  27. public function isVisible()
  28. {
  29. if((int)$this->_aObject['active'] == 0)
  30. return false;
  31. if(!$this->_oObjectManage || !$this->_oObjectManage->isVisible())
  32. return false;
  33. return true;
  34. }
  35. public function setContentId($iContentId)
  36. {
  37. $this->_iContentId = $iContentId;
  38. }
  39. /**
  40. * Get current menu in manage menu
  41. * @return menu object name
  42. */
  43. public function getObjectManage()
  44. {
  45. return $this->_sObjectManage;
  46. }
  47. /**
  48. * Set current menu object in manage menu
  49. * @param $sMenuObject menu object name
  50. * @param $bAsButton boolean use autogenerated menu with single 'more' button or not
  51. */
  52. public function setObjectManage ($sMenuObject, $bAsButton = false)
  53. {
  54. $this->_sObjectManage = $sMenuObject;
  55. $this->_oObjectManage = BxDolMenu::getObjectInstance($this->_sObjectManage);
  56. $this->_bAsButton = $bAsButton;
  57. }
  58. public function getCode ()
  59. {
  60. if(!$this->isVisible())
  61. return '';
  62. if(!empty($this->_iContentId) && method_exists($this->_oObjectManage, 'setContentId'))
  63. $this->_oObjectManage->setContentId($this->_iContentId);
  64. $this->_addJsCss();
  65. if(!$this->_bAsButton)
  66. return $this->_oObjectManage->getCode();
  67. $oMenu = new BxTemplMenu(['template' => 'menu_horizontal.html', 'menu_id' => $this->_sObjectManage . '_wrapper', 'menu_items' => [
  68. ['id' => $this->_sObjectManage . '_more', 'name' => $this->_sObjectManage . '_more', 'link' => 'javascript:void(0)', 'onclick' => 'bx_menu_popup(\'' . $this->_sObjectManage . '\', this, {pointer: {el: $(this).parents(\'li:first\'), align:\'right\'}, cssClass: \'bx-popup-menu\'}, {id: ' . $this->_iContentId . '});', 'title' => '', 'icon' => $this->_oTemplate->getImageAuto('cog', false)]
  69. ]]);
  70. return $oMenu->getCode();
  71. }
  72. public function getCodeAPI ()
  73. {
  74. if(!$this->isVisible())
  75. return [];
  76. if(!empty($this->_iContentId) && method_exists($this->_oObjectManage, 'setContentId'))
  77. $this->_oObjectManage->setContentId($this->_iContentId);
  78. return $this->_oObjectManage->getCodeAPI();
  79. }
  80. }
  81. /** @} */