1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
<?php
class Pbs_Graph{
private $db = null;
private $membership;
private $graphstring;
private $level;
private $edges;
public function graph($groupID)
{
$this->db = Zend_Db_Table::getDefaultAdapter();
$db = $this->db;
$this->graphstring = 'digraph groups {
size="5,5";
graph[ bgcolor=transparent ];
node [ style=filled fillcolor="#ffffffff" ];
"'.$this->getGroupTitle($groupID).'" [ fontcolor="#ffffffff", style=filled, fillcolor="#004A99FF"];
';
$this->getParentGroups($groupID);
$this->getChildGroups($groupID);
$this->graphstring .= '}';
$this->graphstring = str_replace(array("\t","\n"),"",$this->graphstring);
$this->graphstring = str_replace('"','\"',$this->graphstring);
$str = 'echo "';
$str .= $this->graphstring;
$str .= '" | dot -Tpng ';
passthru($str, $result);
return $result;
}
private function getGroupTitle($groupID){
$group = new Application_Model_Group();
$groupmapper = new Application_Model_GroupMapper();
$groupmapper->find($groupID,$group);
return $group->getTitle();
}
private function getParentGroups($groupID, $level=1) {
$db = Zend_Db_Table::getDefaultAdapter();
$query = 'SELECT parentID FROM pbs_groupgroups WHERE groupID="'.$groupID.'"';
$stmt = $db->query($query);
$result = $stmt->fetchAll();
foreach($result as $row){
// save the current groupID in level-list
#$data[$level][] = $row['parentID'];
if($this->edges[$row['parentID']][$groupID] != 1){
$this->graphstring .= '"'.$this->getGroupTitle($row['parentID']).'" -> "'.$this->getGroupTitle($groupID).'";'."\n";
$this->edges[$row['parentID']][$groupID] = 1;
}
// get the function recursive an increase the level
$this->getParentGroups($row['parentID'], $level+1);
}
}
// Gets all childs-groups from a given group
private function getChildGroups($groupID, $level=1) {
$db = Zend_Db_Table::getDefaultAdapter();
$query = 'SELECT groupID FROM pbs_groupgroups WHERE parentID="'.$groupID.'"';
$stmt = $db->query($query);
$result = $stmt->fetchAll();
foreach($result as $row){
// save the current groupID in level-list
#$data[$level][] = $row['groupID'];
if($this->edges[$groupID][$row['groupID']] != 1){
$this->graphstring .= '"'.$this->getGroupTitle($groupID).'" -> "'.$this->getGroupTitle($row['groupID']).'";'."\n";
$this->edges[$groupID][$row['groupID']] = 1;
}
if($this->level >= $level){
$this->graphstring .= '"'.$this->getGroupTitle($row['groupID']).'"'.' [ fontcolor="#ffffffff", style=filled, fillcolor="#004A99FF"];'."\n";
}
// get the function recursive an increase the level
$this->getChildGroups($row['groupID'], $level+1);
}
}
public function setHiglightLevel($i){
$this->level = $i;
}
}
|