Code

Applied in_array strict patches from trunk
[gosa.git] / gosa-core / plugins / generic / statistics / chartClasses / class_objectCountChart.inc
1 <?php
3 class objectCountChart extends statChart
4 {
5     protected $title = 'Object count';
7     function __construct(&$config)
8     {
9         parent::__construct($config);
10         $this->graphName = get_class();
11     }
14     /*! \brief  Generates the line-graph which displays the plugin usage over time.
15      */ 
16     function render()
17     {
18         $lineMax = 20;
19         $gData = $this->graphData;
20         $dataSet = new pData;  
21         $seriesCnt = 0;
23         foreach($gData['objectCountPerInterval'] as $category => $count){
24             if(empty($category) || in_array_strict($category, $this->skipSeries)) continue;
26             // Add results to our data set.
27             $dataSet->AddPoint($count, $category);
28             $dataSet->SetSerieName($this->getCategoryTranslation($category), $category);
29             $dataSet->AddSerie($category);
31             // Detect maximum value, to adjust the Y-Axis
32             $tmpMax = max($count);
33             if($tmpMax > $lineMax) $lineMax = $tmpMax;
34             $seriesCnt ++;
35             if($seriesCnt>=8) break;
36         }
38         // Keep a list of all selecteable data-series, to allow the user to disable
39         //  or enable series on demand.
40         $this->seriesList = array();
41         foreach($gData['objectCountPerInterval'] as $key => $data){
42             $this->seriesList[$key] = $this->getCategoryTranslation($key); 
43         }
45         // Add timeline
46         $dataSet->AddPoint($gData['dates'], 'date');
47         $dataSet->SetAbsciseLabelSerie('date');  
49         // Read graph from cache?
50         $pCache = new pCache($this->cachePath);
51         if($this->enableCaching && $pCache->IsInCache(get_class(),$dataSet->GetData())){
52             $filename =  $pCache->GetHash(get_class(),$dataSet->GetData());
53             $filename = '/var/spool/gosa/'.$filename;    
54             if(file_exists($filename) && is_readable($filename)){
55                 $this->graphID = preg_replace("/[^0-9]/","",microtime(TRUE)).rand(0,99999);
56                 session::set('statistics::graphFile'.$this->graphID,$filename);
57                 return;
58             }
59         }
61         $chart = new pChart(900,230);  
62         $chart->setFixedScale(0,$lineMax);
63         $chart->setFontProperties("./themes/default/fonts/LiberationSans-Regular.ttf",10);  
64         $chart->setGraphArea(50,28,630,200);  
65         $chart->drawFilledRoundedRectangle(7,7,693,223,5,240,240,240);  
66         $chart->drawRoundedRectangle(5,5,695,225,5,230,230,230);  
67         $chart->drawGraphArea(255,255,255,TRUE);  
68         $chart->drawGrid(4,TRUE,200,200,200,50);  
69         $chart->drawTreshold(0,143,55,72,TRUE,TRUE);  
70         $chart->drawTitle(50,22,_($this->title),50,50,50,585);  
71         $chart->drawScale($dataSet->GetData(),$dataSet->GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2, TRUE);     
73         // Only draw this graph if we've at least one series to draw! 
74         if($seriesCnt){
75             $chart->drawFilledLineGraph($dataSet->GetData(),$dataSet->GetDataDescription(),50,TRUE);
76             $chart->drawLegend(720,0,$dataSet->GetDataDescription(),255,255,255);
77         }
80         // Generate new and unique graph id
81         $this->graphID = preg_replace("/[^0-9]/","",microtime(TRUE));
82         $file = '/tmp/graph_'.$this->graphID;
83         $chart->Render($file);
84         session::set('statistics::graphFile'.$this->graphID,$file);
85         $pCache->WriteToCache(get_class(),$dataSet->GetData(),$chart);   
87         return;
88     }
90 }
91 ?>