Location: PHPKode > projects > GForge Community Edition > gforge-ce-571-src/wwwlib/graphs/Activity.php
<?php
/**
 * Copyright (c) 2005-2008 GForge, LLC
 *
 * @version   $Id$
 * @author Ruben Gutierrez	hide@address.com
 * @date 2006-03-13
 *
 * This file is part of GForge.
 *
 * See LICENSE for details. This file is part of GForge AS and may not be
 * redistributed without written permission of GForge, LLC
 */

require_once('lib/external/jpgraph/jpgraph.php');
require_once('lib/external/jpgraph/jpgraph_line.php');

$session = Session::getSession();
$Lang = $session->getLanguage();

$nbr_days = 14;

$firstday = strtotime(date('Y-m-d')) - (($nbr_days+1)*86400);
$today = date('Y-m-d');

$con = Propel::getConnection();
$stmt = $con->createStatement();

$sql = "SELECT activity_date, sum(measure) AS value FROM project_activity
WHERE activity_date BETWEEN '".date('Y-m-d', $firstday)."' AND '$today'
GROUP BY activity_date ORDER BY activity_date";

$rs = $stmt->executeQuery($sql, ResultSet::FETCHMODE_ASSOC);

$days = array();
$days_lbl = array();
$data = array();

for($i=0;$i<=$nbr_days;$i++) {
	$days[] = date('Y-m-d', $firstday);
	$days_lbl[] = date('m-d', $firstday);
	$data[] = 0;
	$firstday = $firstday + 86400;
}

if ($rs != null && $rs->getRecordCount() > 0) {
	while($rs->next()) {
		$act_date = $rs->getString('activity_date');
		$value = $rs->getInt('value');
		$key = array_search($act_date, $days);
		if ($key !== false && isset($data[$key])) {
			$data[$key] = $value;
		}
	}
}

// Create the graph.
$graph = new Graph(230, 150, 'Site_Activity.png', 60);
$graph->SetScale('textlin');
$graph->img->SetMargin(37, 5, 5, 37);
//$graph->img->SetAntiAliasing();

$graph->SetColor('#ededed');
$graph->SetMarginColor('#ededed');
$graph->SetBox(true);
$graph->SetFrame(true, array(0,0,0), 0);

$graph->xaxis->SetLabelAngle(90);
$graph->xaxis->SetLabelMargin(2);
$graph->xaxis->SetTickLabels($days_lbl);
$graph->xaxis->SetColor('#555A61');

$graph->yaxis->scale->SetGrace(0);
$graph->yaxis->SetLabelMargin(3);
$graph->yaxis->SetColor('#555A61');

$lineplot = new LinePlot($data);
$lineplot->SetColor('#555A61');
$lineplot->SetFillColor('#555A61');
$graph->Add($lineplot);
$graph->Stroke();

?>
 
Return current item: GForge Community Edition