diff --git a/data.php b/data.php index 382c645..2e0ea1c 100755 --- a/data.php +++ b/data.php @@ -1,63 +1,48 @@ 'Project 1', - 'start' => '2012-04-20', - 'end' => '2012-05-12' -); - -$data[] = array( - 'label' => 'Project 2', - 'start' => '2012-04-22', - 'end' => '2012-05-22' -); - -$data[] = array( - 'label' => 'Project 3', - 'start' => '2012-05-25', - 'end' => '2012-06-20' -); - -$data[] = array( - 'label' => 'Project 4', - 'start' => '2012-05-06', - 'end' => '2012-06-17', - 'class' => 'important', -); - -$data[] = array( - 'label' => 'Project 5', - 'start' => '2012-05-11', - 'end' => '2012-06-03', - 'class' => 'urgent', -); - -$data[] = array( - 'label' => 'Project 6', - 'start' => '2012-05-15', - 'end' => '2012-07-03' -); - -$data[] = array( - 'label' => 'Project 7', - 'start' => '2012-06-01', - 'end' => '2012-07-03', - 'class' => 'important', -); - -$data[] = array( - 'label' => 'Project 8', - 'start' => '2012-06-01', - 'end' => '2012-08-05' -); - -$data[] = array( - 'label' => 'Project 9', - 'start' => '2012-07-22', - 'end' => '2012-09-05', - 'class' => 'urgent', -); - -?> \ No newline at end of file +$data = +array( + array( + 'label' => 'Project 1', + 'content' => array( + array( + 'start' => '2012-04-20', + 'end' => '2012-05-12', + 'text' => 'ok' + ), + array( + 'start' => '2012-05-15', + 'end' => '2012-05-22', + 'class' => 'urgent' + ), + array( + 'start' => '2012-05-25', + 'end' => '2012-06-01', + 'class' => 'important' + ), + ) + ), + array( + 'label' => 'Project 2', + 'content' => array( + array( + 'start' => '2012-04-10', + 'end' => '2012-04-19', + 'text' => 'ok' + ), + array( + 'start' => '2012-05-10', + 'end' => '2012-05-20', + 'class' => 'urgent' + ), + array( + 'start' => '2012-05-21', + 'end' => '2012-06-01', + 'class' => 'important', + 'text' => 'rest' + ), + ) + ), +) + +?> diff --git a/index.php b/index.php index e9ee3e8..1c0ee0e 100644 --- a/index.php +++ b/index.php @@ -48,6 +48,8 @@

You can download the source for Gantti form Github:
+ https://github.com/pandigresik/gantti + fork from https://github.com/bastianallgeier/gantti

@@ -71,28 +73,51 @@ date_default_timezone_set('UTC'); setlocale(LC_ALL, 'en_US'); - -\$data = array(); - -\$data[] = array( - 'label' => 'Project 1', - 'start' => '2012-04-20', - 'end' => '2012-05-12' +\$data = +array( + array( + 'label' => 'Project 1', + 'content' => array( + array( + 'start' => '2012-04-20', + 'end' => '2012-05-12', + 'text' => 'ok' + ), + array( + 'start' => '2012-05-15', + 'end' => '2012-05-22', + 'class' => 'urgent' + ), + array( + 'start' => '2012-05-25', + 'end' => '2012-06-01', + 'class' => 'important' + ), + ) + ), + array( + 'label' => 'Project 2', + 'content' => array( + array( + 'start' => '2012-04-10', + 'end' => '2012-04-19', + 'text' => 'ok' + ), + array( + 'start' => '2012-05-10', + 'end' => '2012-05-20', + 'class' => 'urgent' + ), + array( + 'start' => '2012-05-21', + 'end' => '2012-06-01', + 'class' => 'important', + 'text' => 'rest' + ), + ) + ), ); -\$data[] = array( - 'label' => 'Project 2', - 'start' => '2012-04-22', - 'end' => '2012-05-22', - 'class' => 'important', -); - -\$data[] = array( - 'label' => 'Project 3', - 'start' => '2012-05-25', - 'end' => '2012-06-20' - 'class' => 'urgent', -); \$gantti = new Gantti(\$data, array( 'title' => 'Demo', diff --git a/lib/gantti.php b/lib/gantti.php index 4c13d00..c4dd1ec 100644 --- a/lib/gantti.php +++ b/lib/gantti.php @@ -11,9 +11,11 @@ class Gantti { var $options = array(); var $cellstyle = false; var $blocks = array(); + var $aside = array(); var $months = array(); var $days = array(); var $seconds = 0; + var $aside_width = '0px'; function __construct($data, $params=array()) { @@ -22,9 +24,11 @@ function __construct($data, $params=array()) { 'cellwidth' => 40, 'cellheight' => 40, 'today' => true, + 'aside' => true, ); - $this->options = array_merge($defaults, $params); + $this->options = array_merge($defaults, $params); + $this->first = isset($this->options['first']) ? strtotime($this->options['first']) : false; $this->cal = new Calendar(); $this->data = $data; $this->seconds = 60*60*24; @@ -37,37 +41,56 @@ function __construct($data, $params=array()) { } function parse() { - - foreach($this->data as $d) { - - $this->blocks[] = array( - 'label' => $d['label'], - 'start' => $start = strtotime($d['start']), - 'end' => $end = strtotime($d['end']), - 'class' => @$d['class'] - ); - - if(!$this->first || $this->first > $start) $this->first = $start; - if(!$this->last || $this->last < $end) $this->last = $end; - - } - - $this->first = $this->cal->date($this->first); - $this->last = $this->cal->date($this->last); - - $current = $this->first->month(); - $lastDay = $this->last->month()->lastDay()->timestamp; - - // build the months - while($current->lastDay()->timestamp <= $lastDay) { - $month = $current->month(); - $this->months[] = $month; - foreach($month->days() as $day) { - $this->days[] = $day; - } - $current = $current->next(); - } - + if(!empty($this->data)){ + foreach($this->data as $d) { + $tmp = array('label' => $d['label'], 'content' => array(),'mark' => array()); + foreach($d['content'] as $c){ + array_push($tmp['content'],array( + 'start' => $start = strtotime($c['start']), + 'end' => $end = strtotime($c['end']), + 'class' => @$c['class'], + 'text' => @$c['text'], + ) + ); + if(!$this->first || $this->first > $start) $this->first = $start; + if(!$this->last || $this->last < $end) $this->last = $end; + } + + if(isset($d['mark']) && !empty($d['mark'])){ + foreach($d['mark'] as $m){ + array_push($tmp['mark'],array( + 'date' => $m['date'], + 'param' => @$m['param'], + 'class' => @$m['class'], + ) + ); + } + } + array_push($this->blocks,$tmp); + /* kumpulkan label, jika sama jadikan satu saja */ + if(!isset($this->aside[$d['label']])){ + $this->aside[$d['label']]['label'] = $d['label']; + $this->aside[$d['label']]['count'] = 0; + } + $this->aside[$d['label']]['count']++; + } + + $this->first = $this->cal->date($this->first); + $this->last = $this->cal->date($this->last); + + $current = $this->first->month(); + $lastDay = $this->last->month()->lastDay()->timestamp; + + // build the months + while($current->lastDay()->timestamp <= $lastDay) { + $month = $current->month(); + $this->months[] = $month; + foreach($month->days() as $day) { + $this->days[] = $day; + } + $current = $current->next(); + } + } } function render() { @@ -87,16 +110,18 @@ function render() { } // sidebar with labels - $html[] = ''; - // data section - $html[] = '
'; + $html[] = '
'; // data header section $html[] = '
'; @@ -104,7 +129,7 @@ function render() { // months headers $html[] = '
    '; foreach($this->months as $month) { - $html[] = '
  • ' . $month->name() . '
  • '; + $html[] = '
  • ' . $month->name() .' '.$month->year(). '
  • '; } $html[] = '
'; @@ -132,23 +157,50 @@ function render() { // days $html[] = '
    '; foreach($this->days as $day) { - + $weekend = ($day->isWeekend()) ? ' weekend' : ''; $today = ($day->isToday()) ? ' today' : ''; - - $html[] = '
  • ' . $day . '
  • '; + /* tandai hari2 tertentu */ + + $mark_class = array(); + if(isset($block['mark']) && !empty($block['mark'])){ + foreach($block['mark'] as $mr){ + if($mr['param'] == '<'){ + if($mr['date'] < $day){ + array_push($mark_class,$mr['class']); + } + } + if($mr['param'] == '>'){ + if($mr['date'] > $day){ + array_push($mark_class,$mr['class']); + } + } + if($mr['param'] == '='){ + + if($mr['date'] == $day){ + array_push($mark_class,$mr['class']); + } + } + + } + } + + $html[] = '
  • '; } $html[] = '
'; - // the block - $days = (($block['end'] - $block['start']) / $this->seconds); - $offset = (($block['start'] - $this->first->month()->timestamp) / $this->seconds); - $top = round($i * ($this->options['cellheight'] + 1)); - $left = round($offset * $this->options['cellwidth']); - $width = round($days * $this->options['cellwidth'] - 9); - $height = round($this->options['cellheight']-8); - $class = ($block['class']) ? ' ' . $block['class'] : ''; - $html[] = '' . $days . ''; + // the block + foreach($block['content'] as $b){ + $days = (($b['end'] - $b['start']) / $this->seconds) + 1; + $offset = (($b['start'] - $this->first->month()->timestamp) / $this->seconds); + $top = round($i * ($this->options['cellheight'] + 1)); + $left = round($offset * $this->options['cellwidth']); + $width = round($days * $this->options['cellwidth'] - 9); + $height = round($this->options['cellheight']-8); + $class = ($b['class']) ? ' ' . $b['class'] : ''; + $text = isset($b['text']) ? $b['text'] : $days; + $html[] = '' . $text . ''; + } $html[] = ''; } @@ -177,7 +229,12 @@ function render() { return implode('', $html); } + + function setAsideCellStyle($count = 1){ + return 'style="line-height: ' . $this->options['cellheight']*$count . 'px; height: ' . $this->options['cellheight']*$count . 'px"'; + } + function __toString() { return $this->render(); } diff --git a/readme.mdown b/readme.mdown index f9e7c2a..4d27a5b 100644 --- a/readme.mdown +++ b/readme.mdown @@ -24,26 +24,49 @@ require('lib/gantti.php'); date_default_timezone_set('UTC'); setlocale(LC_ALL, 'en_US'); -$data = array(); - -$data[] = array( - 'label' => 'Project 1', - 'start' => '2012-04-20', - 'end' => '2012-05-12' -); - -$data[] = array( - 'label' => 'Project 2', - 'start' => '2012-04-22', - 'end' => '2012-05-22', - 'class' => 'important', -); - -$data[] = array( - 'label' => 'Project 3', - 'start' => '2012-05-25', - 'end' => '2012-06-20' - 'class' => 'urgent', +$data = +array( + array( + 'label' => 'Project 1', + 'content' => array( + array( + 'start' => '2012-04-20', + 'end' => '2012-05-12', + 'text' => 'ok' + ), + array( + 'start' => '2012-05-15', + 'end' => '2012-05-22', + 'class' => 'urgent' + ), + array( + 'start' => '2012-05-25', + 'end' => '2012-06-01', + 'class' => 'important' + ), + ) + ), + array( + 'label' => 'Project 2', + 'content' => array( + array( + 'start' => '2012-04-10', + 'end' => '2012-04-19', + 'text' => 'ok' + ), + array( + 'start' => '2012-05-10', + 'end' => '2012-05-20', + 'class' => 'urgent' + ), + array( + 'start' => '2012-05-21', + 'end' => '2012-06-01', + 'class' => 'important', + 'text' => 'rest' + ), + ) + ), ); $gantti = new Gantti($data, array(