diff --git a/lib/gantti.php b/lib/gantti.php index 4c13d00..be46c7f 100644 --- a/lib/gantti.php +++ b/lib/gantti.php @@ -1,6 +1,6 @@ false, 'cellwidth' => 40, 'cellheight' => 40, 'today' => true, ); - - $this->options = array_merge($defaults, $params); + + $this->options = array_merge($defaults, $params); $this->cal = new Calendar(); $this->data = $data; $this->seconds = 60*60*24; $this->cellstyle = 'style="width: ' . $this->options['cellwidth'] . 'px; height: ' . $this->options['cellheight'] . 'px"'; - - // parse data and find first and last date - $this->parse(); - + + // parse data and find first and last date + $this->parse(); + } 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'] - ); - + $d['start'] = $start = strtotime($d['start']); + $d['end'] = $end = strtotime($d['end']); + + $this->blocks[] = $d; + 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 + // build the months while($current->lastDay()->timestamp <= $lastDay) { $month = $current->month(); $this->months[] = $month; @@ -67,19 +64,19 @@ function parse() { } $current = $current->next(); } - + } function render() { - + $html = array(); - - // common styles + + // common styles $cellstyle = 'style="line-height: ' . $this->options['cellheight'] . 'px; height: ' . $this->options['cellheight'] . 'px"'; $wrapstyle = 'style="width: ' . $this->options['cellwidth'] . 'px"'; $totalstyle = 'style="width: ' . (count($this->days)*$this->options['cellwidth']) . 'px"'; - // start the diagram - $html[] = '
'; + // start the diagram + $html[] = '
'; // set a title if available if($this->options['title']) { @@ -90,14 +87,14 @@ function render() { $html[] = ''; // data section $html[] = '
'; - + // data header section $html[] = '
'; @@ -105,8 +102,8 @@ function render() { $html[] = '
    '; foreach($this->months as $month) { $html[] = '
  • ' . $month->name() . '
  • '; - } - $html[] = '
'; + } + $html[] = ''; // days headers $html[] = '
    '; @@ -116,19 +113,19 @@ function render() { $today = ($day->isToday()) ? ' today' : ''; $html[] = '
  • ' . $day->padded() . '
  • '; - } - $html[] = '
'; - + } + $html[] = ''; + // end header $html[] = '
'; // main items $html[] = '
    '; - + foreach($this->blocks as $i => $block) { - + $html[] = '
  • '; - + // days $html[] = '
      '; foreach($this->days as $day) { @@ -137,8 +134,8 @@ function render() { $today = ($day->isToday()) ? ' today' : ''; $html[] = '
    • ' . $day . '
    • '; - } - $html[] = '
    '; + } + $html[] = '
'; // the block $days = (($block['end'] - $block['start']) / $this->seconds); @@ -147,37 +144,37 @@ function render() { $left = round($offset * $this->options['cellwidth']); $width = round($days * $this->options['cellwidth'] - 9); $height = round($this->options['cellheight']-8); - $class = ($block['class']) ? ' ' . $block['class'] : ''; + $class = (array_key_exists("class", $block)) ? ' ' . $block['class'] : ''; $html[] = '' . $days . ''; $html[] = ''; - + } - - $html[] = ''; - + + $html[] = ''; + if($this->options['today']) { - + // today $today = $this->cal->today(); - $offset = (($today->timestamp - $this->first->month()->timestamp) / $this->seconds); + $offset = (($today->timestamp - $this->first->month()->timestamp) / $this->seconds); $left = round($offset * $this->options['cellwidth']) + round(($this->options['cellwidth'] / 2) - 1); - + if($today->timestamp > $this->first->month()->firstDay()->timestamp && $today->timestamp < $this->last->month()->lastDay()->timestamp) { $html[] = ''; } } - + // end data section - $html[] = '
'; + $html[] = ''; // end diagram $html[] = '
'; return implode('', $html); - + } - + function __toString() { return $this->render(); } diff --git a/readme.mdown b/readme.mdown index f9e7c2a..621b62e 100644 --- a/readme.mdown +++ b/readme.mdown @@ -42,7 +42,7 @@ $data[] = array( $data[] = array( 'label' => 'Project 3', 'start' => '2012-05-25', - 'end' => '2012-06-20' + 'end' => '2012-06-20', 'class' => 'urgent', );