Added Gantt Activity
This commit is contained in:
29
application/classes/lnapp/jpgraph.php
Normal file
29
application/classes/lnapp/jpgraph.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This is class helps with rendering JPGraph images.
|
||||
*
|
||||
* @package lnApp
|
||||
* @subpackage JPGraph
|
||||
* @category Helpers
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010 Deon George
|
||||
* @license http://dev.leenooks.net/license.html
|
||||
*/
|
||||
abstract class lnApp_JPGraph {
|
||||
public function __construct() {
|
||||
// JPGraph should be installed in a our includes dir
|
||||
$jpgraph = DOCROOT.'includes/jpgraph/src';
|
||||
|
||||
if (! file_exists($jpgraph.'/jpgraph_gantt.php'))
|
||||
throw new Kohana_Exception('jpgraph_gantt.php must be installed in '.$jpgraph);
|
||||
|
||||
if (! function_exists('imagetypes') && ! function_exists('imagecreatefromstring'))
|
||||
throw new Kohana_Exception('It seems that GD support is not available. Please add GD support to your PHP configuration.');
|
||||
|
||||
require_once($jpgraph.'/jpgraph.php');
|
||||
|
||||
return $jpgraph;
|
||||
}
|
||||
}
|
||||
?>
|
104
application/classes/lnapp/jpgraph/gantt.php
Normal file
104
application/classes/lnapp/jpgraph/gantt.php
Normal file
@@ -0,0 +1,104 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This is class helps with rendering JPGraph Gantt images.
|
||||
*
|
||||
* @package lnApp
|
||||
* @subpackage JPGraph
|
||||
* @category Helpers
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010 Deon George
|
||||
* @license http://dev.leenooks.net/license.html
|
||||
*/
|
||||
class lnApp_JPGraph_Gantt extends JPGraph {
|
||||
// Our JPGraph object
|
||||
public $jpgraph;
|
||||
private $_count;
|
||||
private $_items = array();
|
||||
|
||||
public function __construct() {
|
||||
// Run through our parent checks
|
||||
$jpgraph = parent::__construct();
|
||||
|
||||
if (! file_exists($jpgraph.'/jpgraph_gantt.php'))
|
||||
throw new Kohana_Exception('jpgraph_gantt.php must be installed in '.$jpgraph);
|
||||
|
||||
require_once $jpgraph.'/jpgraph_gantt.php';
|
||||
|
||||
$this->jpgraph = new GanttGraph(0,0,'auto');
|
||||
return $this;
|
||||
}
|
||||
|
||||
// Add a new line item to the Gantt Chart
|
||||
public function add($summary,$start,$end) {
|
||||
$this->_count = count($this->_items);
|
||||
|
||||
$this->_items[$this->_count]['summary'] = $summary;
|
||||
$this->_items[$this->_count]['start'] = $start;
|
||||
$this->_items[$this->_count]['end'] = $end;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function caption($value) {
|
||||
$this->_items[$this->_count]['caption'] = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function csim($value) {
|
||||
$this->_items[$this->_count]['csim'] = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function progress($value) {
|
||||
$this->_items[$this->_count]['progress'] = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function sort($value) {
|
||||
$this->_items[$this->_count]['sort'] = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
// This will compile the gantt and output a URL that has the image
|
||||
public function draw($name) {
|
||||
// Sort our items by sort criteria.
|
||||
sort::MAsort($this->_items,'sort,summary',0);
|
||||
|
||||
$c = 0;
|
||||
$ls = '';
|
||||
foreach ($this->_items as $item) {
|
||||
// Put a gap between our priority items.
|
||||
if ($c AND ($lp != $item['sort']))
|
||||
$c++;
|
||||
|
||||
if ($ls != $item['summary'])
|
||||
$c++;
|
||||
|
||||
$lp = $item['sort'];
|
||||
$ls = $item['summary'];
|
||||
|
||||
$activity = new GanttBar($c,$item['summary'],$item['start'],$item['end']);
|
||||
$activity->progress->Set($item['progress']);
|
||||
$activity->caption ->Set($item['caption']);
|
||||
$activity->SetCSIMTarget('#',($item['csim'] ? $item['csim'] : 'NoCSIM'));
|
||||
$activity->title->SetCSIMTarget('#',($item['csim'] ? $item['csim'] : 'NoCSIM'));
|
||||
|
||||
$this->jpgraph->Add($activity);
|
||||
}
|
||||
|
||||
$tmpfile = '/tmp/'.$name.'.png';
|
||||
$file = 'session/'.$name.'.png';
|
||||
|
||||
$this->jpgraph->Stroke($tmpfile);
|
||||
Session::instance()->set($file,file_get_contents($tmpfile));
|
||||
unlink($tmpfile);
|
||||
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
?>
|
105
application/classes/lnapp/sort.php
Normal file
105
application/classes/lnapp/sort.php
Normal file
@@ -0,0 +1,105 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class is used to sort multiple dimension arrays.
|
||||
*
|
||||
* @package lnApp
|
||||
* @subpackage Sort
|
||||
* @category Helpers
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010 Deon George
|
||||
* @license http://dev.leenooks.net/license.html
|
||||
* @uses Style
|
||||
*/
|
||||
class lnApp_Sort {
|
||||
/**
|
||||
* Sort a multi dimensional array.
|
||||
*
|
||||
* @param array Multi demension array passed by reference
|
||||
* @param string Comma delimited string of sort keys.
|
||||
* @param boolean Whether to reverse sort.
|
||||
* @return array Sorted multi demension array.
|
||||
*/
|
||||
public static function masort(&$data,$sortby,$rev=0) {
|
||||
// if the array to sort is null or empty
|
||||
if (! $data)
|
||||
return;
|
||||
|
||||
static $MASORT_CACHE = array();
|
||||
|
||||
if (empty($MASORT_CACHE[$sortby])) {
|
||||
$code = "\$c=0;\n";
|
||||
|
||||
foreach (explode(',',$sortby) as $key) {
|
||||
$code .= "if (is_object(\$a) || is_object(\$b)) {\n";
|
||||
|
||||
$code .= " if (is_array(\$a->$key)) {\n";
|
||||
$code .= " asort(\$a->$key);\n";
|
||||
$code .= " \$aa = array_shift(\$a->$key);\n";
|
||||
$code .= " } else\n";
|
||||
$code .= " \$aa = \$a->$key;\n";
|
||||
|
||||
$code .= " if (is_array(\$b->$key)) {\n";
|
||||
$code .= " asort(\$b->$key);\n";
|
||||
$code .= " \$bb = array_shift(\$b->$key);\n";
|
||||
$code .= " } else\n";
|
||||
$code .= " \$bb = \$b->$key;\n";
|
||||
|
||||
$code .= " if (\$aa != \$bb)";
|
||||
if ($rev)
|
||||
$code .= " return (\$aa < \$bb ? 1 : -1);\n";
|
||||
else
|
||||
$code .= " return (\$aa > \$bb ? 1 : -1);\n";
|
||||
|
||||
$code .= "} else {\n";
|
||||
|
||||
$code .= " \$a = array_change_key_case(\$a);\n";
|
||||
$code .= " \$b = array_change_key_case(\$b);\n";
|
||||
|
||||
$key = strtolower($key);
|
||||
|
||||
$code .= " if ((! isset(\$a['$key'])) && isset(\$b['$key'])) return 1;\n";
|
||||
$code .= " if (isset(\$a['$key']) && (! isset(\$b['$key']))) return -1;\n";
|
||||
|
||||
$code .= " if ((isset(\$a['$key'])) && (isset(\$b['$key']))) {\n";
|
||||
$code .= " if (is_array(\$a['$key'])) {\n";
|
||||
$code .= " asort(\$a['$key']);\n";
|
||||
$code .= " \$aa = array_shift(\$a['$key']);\n";
|
||||
$code .= " } else\n";
|
||||
$code .= " \$aa = \$a['$key'];\n";
|
||||
|
||||
$code .= " if (is_array(\$b['$key'])) {\n";
|
||||
$code .= " asort(\$b['$key']);\n";
|
||||
$code .= " \$bb = array_shift(\$b['$key']);\n";
|
||||
$code .= " } else\n";
|
||||
$code .= " \$bb = \$b['$key'];\n";
|
||||
|
||||
$code .= " if (\$aa != \$bb)\n";
|
||||
$code .= " if (is_numeric(\$aa) && is_numeric(\$bb)) {\n";
|
||||
|
||||
if ($rev)
|
||||
$code .= " return (\$aa < \$bb ? 1 : -1);\n";
|
||||
else
|
||||
$code .= " return (\$aa > \$bb ? 1 : -1);\n";
|
||||
|
||||
$code .= " } else {\n";
|
||||
|
||||
if ($rev)
|
||||
$code .= " if ( (\$c = strcasecmp(\$bb,\$aa)) != 0 ) return \$c;\n";
|
||||
else
|
||||
$code .= " if ( (\$c = strcasecmp(\$aa,\$bb)) != 0 ) return \$c;\n";
|
||||
|
||||
$code .= " }\n";
|
||||
$code .= " }\n";
|
||||
$code .= "}\n";
|
||||
}
|
||||
|
||||
$code .= 'return $c;';
|
||||
|
||||
$MASORT_CACHE[$sortby] = create_function('$a, $b',$code);
|
||||
}
|
||||
|
||||
uasort($data,$MASORT_CACHE[$sortby]);
|
||||
}
|
||||
}
|
||||
?>
|
Reference in New Issue
Block a user