v1.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <?php
  2. /**
  3. * The main widget class file of zin module of ZenTaoPMS.
  4. *
  5. * @copyright Copyright 2009-2023 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.zentao.net)
  6. * @license ZPL(https://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
  7. * @author sunhao<sunhao@easycorp.ltd>
  8. * @package zin
  9. * @link http://www.zentao.net
  10. */
  11. namespace zin;
  12. require_once dirname(__DIR__) . DS . 'pagebase' . DS . 'v1.php';
  13. require_once dirname(__DIR__) . DS . 'featurebar' . DS . 'v1.php';
  14. require_once dirname(__DIR__) . DS . 'mainnavbar' . DS . 'v1.php';
  15. require_once dirname(__DIR__) . DS . 'menuviewswitcher' . DS . 'v1.php';
  16. /**
  17. * 主要内容部件类。
  18. * The main widget class.
  19. *
  20. * @author Hao Sun
  21. */
  22. class main extends wg
  23. {
  24. /**
  25. * Define the blocks.
  26. *
  27. * @var array
  28. * @access protected
  29. */
  30. protected static $defineBlocks = array
  31. (
  32. 'navbar' => array('map' => 'mainNavbar'),
  33. 'menu' => array('map' => 'featureBar,nav,toolbar'),
  34. 'sidebar' => array('map' => 'sidebar')
  35. );
  36. /**
  37. * Define the properties.
  38. *
  39. * @access protected
  40. * @return ?node
  41. */
  42. protected function buildMenu()
  43. {
  44. $menuBlocks = $this->block('menu');
  45. if(empty($menuBlocks)) return null;
  46. list($featureBarList, $navList, $toolbarList, $restList) = groupWgInList($menuBlocks, array('featureBar', 'nav', 'toolbar'));
  47. $featureBar = null;
  48. if(!empty($featureBarList)) $featureBar = $featureBarList[0];
  49. elseif(!empty($navList)) $featureBar = new featureBar($navList);
  50. $toolbar = null;
  51. if(!empty($toolbarList)) $toolbar = $toolbarList[0];
  52. if($toolbar instanceof node && !$toolbar->hasProp('id')) $toolbar->setProp('id', 'actionBar');
  53. /* 来自二级或三级导航中的内容: */
  54. $navbarMenu = new menuViewSwitcher();
  55. return div
  56. (
  57. set::id('mainMenu'),
  58. $featureBar,
  59. $navbarMenu,
  60. $toolbar,
  61. $restList
  62. );
  63. }
  64. /**
  65. * Build main content.
  66. *
  67. * @access protected
  68. * @return node
  69. */
  70. protected function buildContent()
  71. {
  72. $leftSides = array();
  73. $rightSides = array();
  74. $sidebars = $this->block('sidebar');
  75. if(!empty($sidebars))
  76. {
  77. foreach($sidebars as $sidebar)
  78. {
  79. if(!($sidebar instanceof node)) continue;
  80. $sidebar->setDefaultProps(array('parent' => '#mainContainer'));
  81. if($sidebar->prop('side') === 'left') $leftSides[] = $sidebar;
  82. else $rightSides[] = $sidebar;
  83. }
  84. }
  85. $children = $this->children();
  86. $hasLeftSide = !empty($leftSides);
  87. $hasRightSide = !empty($rightSides);
  88. if($hasLeftSide || $hasRightSide)
  89. {
  90. $children = array
  91. (
  92. setClass('row', array('has-sidebar-left' => $hasLeftSide, 'has-sidebar-right' => $hasRightSide)),
  93. $leftSides,
  94. div
  95. (
  96. $children,
  97. setID('mainContentCell'),
  98. setClass('main-content-cell')
  99. ),
  100. $rightSides
  101. );
  102. }
  103. return div
  104. (
  105. set::id('mainContent'),
  106. $children
  107. );
  108. }
  109. /**
  110. * Build main navbar from block.
  111. *
  112. * @access protected
  113. * @return array
  114. */
  115. protected function buildMainNavbar()
  116. {
  117. $workspace = commonModel::getWorkspaceInfo();
  118. if($workspace['opened']) return null;
  119. $navbar = $this->block('navbar');
  120. if(!$navbar) return mainNavbar();
  121. return $navbar;
  122. }
  123. /**
  124. * Override the build method.
  125. *
  126. * @access protected
  127. * @return mixed
  128. */
  129. protected function build()
  130. {
  131. return div
  132. (
  133. set::id('main'),
  134. set($this->getRestProps()),
  135. $this->buildMainNavbar(),
  136. div
  137. (
  138. setID('mainContainer'),
  139. setClass('container'),
  140. $this->buildMenu(),
  141. $this->buildContent()
  142. )
  143. );
  144. }
  145. }