* finish task #6656.

This commit is contained in:
wangyidong
2019-12-05 11:25:12 +08:00
parent 2115b47e59
commit 7d6913d91c
2 changed files with 16 additions and 13 deletions

View File

@@ -41,7 +41,7 @@ class dept extends control
$this->view->depts = $this->dept->getTreeMenu($rootDeptID = 0, array('deptmodel', 'createManageLink'));
$this->view->parentDepts = $parentDepts;
$this->view->sons = $this->dept->getSons($deptID);
$this->view->tree = $this->dept->getDataStructure(0);
$this->view->tree = $this->dept->getDataStructure();
$this->display();
}

View File

@@ -432,27 +432,30 @@ class deptModel extends model
/**
* Get data structure
* @param integer $rootDeptID
* @access public
* @return object
* @return array
*/
public function getDataStructure($rootDeptID = 0)
public function getDataStructure()
{
$tree = array_values($this->getSons($rootDeptID));
$users = $this->loadModel('user')->getPairs('noletter|noclosed|nodeleted|all');
if(count($tree))
$treeGroups = $this->dao->select('*')->from(TABLE_DEPT)->orderBy('grade_desc,`order`')->fetchGroup('parent', 'id');
$tree = array();
foreach($treeGroups as $parent => $groups)
{
foreach ($tree as $node)
foreach($groups as $deptID => $node)
{
$node->managerName = $users[$node->manager];
$children = $this->getDataStructure($node->id);
if(count($children))
$node->managerName = zget($users, $node->manager);
if(isset($tree[$deptID]))
{
$node->children = $children;
$node->children = $tree[$deptID];
$node->actions = array('delete' => false);
unset($tree[$deptID]);
}
$tree[$node->parent][] = $node;
}
}
}
return $tree;
krsort($tree);
return array_pop($tree);
}
}