php 动态生成组织结构图
一个 php 动态生成组织结构图的类,比如我们公司的组织结构,总栽,总经理,IT部,客服部,业务部,这就属于一个组织结构,还有类似于这样的其它组织,利用这个 PHP 的类对象可以很好的生成一个组织机构的图形,更形象的进行展出出来,让大家一眼可以看出公司的一个组织人员状态。
这个类其实用得还不是很多,比如像企业站,我们基本上就可以直接用 PS 来画一个组织机构图了,那么对于 PHP 动态生成组织结构图,应该用在什么地方呢,我想可以放在一些比较大型的信息站上面,就像 B2B 类的网站,每个企业会员都有自己的公司黄页,如果要加企业的组织结构图,就可以用这个 php 动态生成组织结构类,每个单位的组织结构图都不一样,可以进行调用不同的参数生成不同的组织结构图,这也是 php 功能强大的体现之一。
[code lang="php"]
hasChild($resData['result'],$parentid);
$tempid = $hasChild[count($hasChild)-1];
//如果该节点的parentid是公司的uuid则该节点是root节点
if($list['parentid'] == $resData['comid']){
$this->rootnodeid = $list['nodeid'];
}else if($list['parentid'] == $this->rootnodeid){
//如果该节点的parentid是root节点的uuid则该节点是某部门的partroot节点
$this->lastid = array();
$this->levelpt = array();
$this->partroot[] = $list['nodeid'];
?>
2){
$this->levelpt[$level][$list['nodei
d']] = $list['parentid'];
}
//判断节点的parentid是不是部门根节点
if(in_array($list['parentid'], $this->partroot)){
$this->partson[] = $list['nodeid'];
}
//判断节点是不是该层最后一个节点
if($list['nodeid'] == $tempid){
$this->lastid[] = $list['nodeid'];
}
//画线:调用playLine()方法
$this->playLine($list['nodeid'], $list['node
id'], $level);
if($level == 2){
if(in_array($list['nodeid'],$this->lastid)){
echo '

';
}else {
echo '

';
}
}else if($level != 2){
if(in_array($list['nodeid'],$this->lastid) ){
echo '

';
}else{
echo '

';
}
}
?>
partleft += 45;
$this->displayChildren($resData, $list['nodeid'], $level+1);
$this->partleft -= 45;
//判断是否是一个部门的结束
if($list['parentid'] == $this->rootnodeid){
echo "
";
}
}
}
}
//找出当前parntid的子uuid
function hasChild($param,$parentid) {
$tempArr = array();
foreach($param as $list){
if($list['parentid'] == $parentid){
$tempArr[] = $list['nodeid'];
}
}
return $tempArr;
}
//递归画线
function playLine($uuid, $curid, $level){
if($level >= 3){
$this->playLine($uuid, $this->levelpt[$level][$curid], $l
evel-1);
if($level == 3 && in_array($this->levelpt[$level][$curi
d], $this->lastid)){
$level = $level-1;
echo '
';
}else if($level == 3 && !in_array($this->levelpt[$level][$
curid], $this->lastid)){
$level = $level-1;
echo '
';
}else if($level != 3 && in_array($this->levelpt[$level][$cu
rid], $this->lastid)){
$level = $level-1;
echo '
';
}else if($level != 3 && !in_array($this->levelpt[$level][$c
urid], $this->lastid)){
$level = $level-1;
echo '

';
}
}
}
}
?>
[/code]