SystemNode.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | EasyAdmin
  4. // +----------------------------------------------------------------------
  5. // | PHP交流群: 763822524
  6. // +----------------------------------------------------------------------
  7. // | 开源协议 https://mit-license.org
  8. // +----------------------------------------------------------------------
  9. // | github开源项目:https://github.com/zhongshaofa/EasyAdmin
  10. // +----------------------------------------------------------------------
  11. namespace app\common\model;
  12. use app\common\model\TimeModel;
  13. class SystemNode extends TimeModel
  14. {
  15. public function getNodeTreeList()
  16. {
  17. $list = $this->select()->toArray();
  18. $list = $this->buildNodeTree($list);
  19. return $list;
  20. }
  21. protected function buildNodeTree($list)
  22. {
  23. $newList = [];
  24. $repeatString = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
  25. foreach ($list as $vo) {
  26. if ($vo['type'] == 1) {
  27. $newList[] = $vo;
  28. foreach ($list as $v) {
  29. if ($v['type'] == 2 && strpos($v['node'], $vo['node'] . '/') !== false) {
  30. $v['node'] = "{$repeatString}├{$repeatString}" . $v['node'];
  31. $newList[] = $v;
  32. }
  33. }
  34. }
  35. }
  36. return $newList;
  37. }
  38. }