summaryrefslogblamecommitdiffstats
path: root/library/Pbs/Graph.php
blob: ae3ab16ceb4f073ae5d07d67b206f5be077c1654 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16















                                                               
                                             


                                                 







                                                                                         




































                                                                                                                                           
<?php

class Pbs_Graph{

	private $db = null;
	private $membership;
	private $graphstring;
	
	public function graph($groupID)
    {
		$this->db = Zend_Db_Table::getDefaultAdapter();
        $db = $this->db;
        
        
        
        $this->graphstring = 'digraph groups {
				size="5,5";';
		$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,$end);
		return $end;
	}
	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'];
			$this->graphstring .= '"'.$this->getGroupTitle($row['parentID']).'" -> "'.$this->getGroupTitle($groupID).'";'."\n";
			// 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'];
			$this->graphstring .= '"'.$this->getGroupTitle($groupID).'" -> "'.$this->getGroupTitle($row['groupID']).'";'."\n";
			// get the function recursive an increase the level
			$this->getChildGroups($row['groupID'], $level+1);
		}
	}
}