diff options
Diffstat (limited to 'library/Pbs/Graph.php')
-rw-r--r-- | library/Pbs/Graph.php | 269 |
1 files changed, 134 insertions, 135 deletions
diff --git a/library/Pbs/Graph.php b/library/Pbs/Graph.php index f9b236a..a37af35 100644 --- a/library/Pbs/Graph.php +++ b/library/Pbs/Graph.php @@ -1,4 +1,4 @@ -<?php +<? php /* * Copyright (c) 2011 - OpenSLX GmbH, RZ Uni Freiburg * This program is free software distributed under the GPL version 2. @@ -10,138 +10,137 @@ * General information about OpenSLX can be found at http://openslx.org/ */ -class Pbs_Graph{ - - private $db = null; - private $membership; - private $graphstring; - private $level; - private $edges; - private $crawledNodes; - private $childs = array(); - - public function graph($groupID) - { - $this->db = Zend_Db_Table::getDefaultAdapter(); - $db = $this->db; - - - $path = "../resources/groupgraphs/"; - @mkdir($path ,0777, true); - - $this->graphstring = 'digraph groups { - size="7,5"; - pad=0.1; - graph[ bgcolor=transparent ]; - node [ style=filled fillcolor="#ffffffff" ];'; - if($this->level <0) - $this->graphstring .= '"'.$this->getGroupTitle($groupID).'"'; - else - $this->graphstring .= '"'.$this->getGroupTitle($groupID).'" [ fontcolor="#ffffffff", style=filled, fillcolor="#004A99FF"];'; - - if(count($this->childs) >=1){ - foreach($this->childs as $childID){ - $this->edges[$groupID][$childID] = 1; - $this->graphstring .= '"'.$this->getGroupTitle($groupID).'" -> "'.$this->getGroupTitle($childID).'";'."\n"; - $this->getChildGroups($childID); - } - } - $this->getParentGroups($groupID); - $this->getChildGroups($groupID); - $this->graphstring .= '}'; - - // for debugging - # $fp = fopen($path.'thisgraph.dot', "w"); - # fputs ($fp, $this->graphstring); - # fclose ($fp); - - - $this->graphstring = str_replace(array("\t","\n"),"",$this->graphstring); - $this->graphstring = str_replace('"','\"',$this->graphstring); - - $md5 = md5($this->graphstring); - $path = "../resources/groupgraphs/"; - @mkdir($path ,0777, true); - - // randomly delete cached files, old files are not needed - // so delete it sometimes - if(rand(0,20) == 1){ - $days = "14"; // delete all files older than this many days - $seconds = ($days*24*60*60); - - $files = scandir($path); - foreach ($files as $num => $fname){ - if (file_exists("{$path}{$fname}") && ((time() - filemtime("{$path}{$fname}")) > $seconds)) { - $mod_time = filemtime("{$path}{$fname}"); - unlink("{$path}{$fname}"); - } - } - } - - if(!file_exists($path.$md5.".png")){ - $str = 'echo "'; - $str .= $this->graphstring; - $str .= '" | dot -Tpng >'.$path.$md5.".png"; - exec($str); - } - - passthru("cat ".$path.$md5.".png", $result); - return $result; - } - private function getGroupTitle($groupID){ - $group = new Application_Model_Group(); - $groupmapper = new Application_Model_GroupMapper(); - $groupmapper->find($groupID,$group); - return $group->getTitle(); - } - public function newChild($id){ - $this->childs[] = $id; - } - - private function getParentGroups($groupID, $level=1) { - if($this->crawledNodes['parent'][$groupID] == 1) - return; - $this->crawledNodes['parent'][$groupID] = 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) { - if(@$this->crawledNodes['child'][$groupID] == 1) - return; - $this->crawledNodes['child'][$groupID] = 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; - } +class Pbs_Graph { + + private $db = null; + private $membership; + private $graphstring; + private $level; + private $edges; + private $crawledNodes; + private $childs = array(); + + public function graph($groupID) { + $this->db = Zend_Db_Table::getDefaultAdapter(); + $db = $this->db; + + + $path = "../resources/groupgraphs/"; + @mkdir($path , 0777, true); + + $this->graphstring = 'digraph groups { + size="7,5"; + pad=0.1; + graph[ bgcolor=transparent ]; + node [ style=filled fillcolor="#ffffffff" ];'; + if($this->level < 0) + { $this->graphstring . = '"'.$this->getGroupTitle($groupID).'"'; } + else + { $this->graphstring . = '"'.$this->getGroupTitle($groupID).'" [ fontcolor="#ffffffff", style=filled, fillcolor="#004A99FF"];'; } + + if(count($this->childs) >= 1) { + foreach($this->childs as $childID) { + $this->edges[$groupID][$childID] = 1; + $this->graphstring . = '"'.$this->getGroupTitle($groupID).'" -> "'.$this->getGroupTitle($childID).'";'."\n"; + $this->getChildGroups($childID); + } + } + $this->getParentGroups($groupID); + $this->getChildGroups($groupID); + $this->graphstring . = '}'; + + // for debugging +# $fp = fopen($path.'thisgraph.dot', "w"); +# fputs ($fp, $this->graphstring); +# fclose ($fp); + + + $this->graphstring = str_replace(array("\t", "\n"), "", $this->graphstring); + $this->graphstring = str_replace('"', '\"', $this->graphstring); + + $md5 = md5($this->graphstring); + $path = "../resources/groupgraphs/"; + @mkdir($path , 0777, true); + + // randomly delete cached files, old files are not needed + // so delete it sometimes + if(rand(0, 20) == 1) { + $days = "14"; // delete all files older than this many days + $seconds = ($days * 24 * 60 * 60); + + $files = scandir($path); + foreach ($files as $num => $fname) { + if (file_exists("{$path}{$fname}") && ((time() - filemtime("{$path}{$fname}")) > $seconds)) { + $mod_time = filemtime("{$path}{$fname}"); + unlink("{$path}{$fname}"); + } + } + } + + if(!file_exists($path.$md5.".png")) { + $str = 'echo "'; + $str . = $this->graphstring; + $str . = '" | dot -Tpng >'.$path.$md5.".png"; + exec($str); + } + + passthru("cat ".$path.$md5.".png", $result); + return $result; + } + private function getGroupTitle($groupID) { + $group = new Application_Model_Group(); + $groupmapper = new Application_Model_GroupMapper(); + $groupmapper->find($groupID, $group); + return $group->getTitle(); + } + public function newChild($id) { + $this->childs[] = $id; + } + + private function getParentGroups($groupID, $level = 1) { + if($this->crawledNodes['parent'][$groupID] == 1) + { return; } + $this->crawledNodes['parent'][$groupID] = 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) { + if(@$this->crawledNodes['child'][$groupID] == 1) + { return; } + $this->crawledNodes['child'][$groupID] = 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; + } } |