From 1e4caf287b7cb378328a7086d26ea9f8f425696e Mon Sep 17 00:00:00 2001 From: "shiyangyangwork@yahoo.cn" Date: Sun, 18 Sep 2011 00:20:26 +0000 Subject: [PATCH] * finish the task #520. --- module/project/control.php | 10 +++-- module/project/model.php | 52 +++++++++++++++++++++++++ module/report/model.php | 80 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 139 insertions(+), 3 deletions(-) diff --git a/module/project/control.php b/module/project/control.php index 4495b1db5b..8f3ac7b730 100644 --- a/module/project/control.php +++ b/module/project/control.php @@ -416,9 +416,13 @@ class project extends control $position[] = html::a($this->createLink('project', 'browse', "projectID=$projectID"), $project->name); $position[] = $this->lang->project->burn; - /* Create charts. */ - $dataXML = $this->report->createSingleXML($this->project->getBurnData($project->id), $this->lang->project->charts->burn->graph, $this->lang->report->singleColor); - $charts = $this->report->createJSChart('line', $dataXML, 700, 350); + /* Create charts by flash. */ + //$dataXML = $this->report->createSingleXML($this->project->getBurnData($project->id), $this->lang->project->charts->burn->graph, $this->lang->report->singleColor); + //$charts = $this->report->createJSChart('line', $dataXML, 700, 350); + + /* Create charts by flot. */ + $dataXML= $this->report->createSingleXMLFlot($this->project->getBurnDataFlot($project->id)); + $charts = $this->report->createJSChartFlot($project->name, $dataXML, 700, 350); /* Assign. */ $this->view->header = $header; diff --git a/module/project/model.php b/module/project/model.php index 0ac6469cd2..bf5d869441 100644 --- a/module/project/model.php +++ b/module/project/model.php @@ -287,8 +287,13 @@ class projectModel extends model { if($i <= $counts and $project->status == 'doing') { + /* By flash.*/ $dataXML = $this->report->createSingleXML($this->getBurnData($project->id), $this->lang->project->charts->burn->graph, $this->lang->report->singleColor); $charts[$project->id] = $this->report->createJSChart('line', $dataXML, 'auto', 210); + + /* By flot.*/ + //$dataXML = $this->report->createSingleXMLFlot($this->getBurnData($project->id)); + //$charts[$project->id] = $this->report->createJSChartFlot($project->name, $dataXML, 'auto', 210); } } else @@ -740,6 +745,53 @@ class projectModel extends model return $sets; } + public function getBurnDataFlot($projectID = 0, $itemCounts = 30) + { + /* Get project and burn counts. */ + $project = $this->getById($projectID); + $burnCounts = $this->dao->select('count(*) AS counts')->from(TABLE_BURN)->where('project')->eq($projectID)->fetch('counts'); + + /* If the burnCounts > $itemCounts, get the latest $itemCounts records. */ + $sql = $this->dao->select('date AS name, `left` AS value')->from(TABLE_BURN)->where('project')->eq((int)$projectID); + if($burnCounts > $itemCounts) + { + $sets = $sql->orderBy('date DESC')->limit($itemCounts)->fetchAll('name'); + $sets = array_reverse($sets); + } + else + { + /* The burnCounts < itemCounts, after getting from the db, padding left dates. */ + $sets = $sql->orderBy('date ASC')->fetchAll('name'); + $current = helper::today(); + if($project->end != '0000-00-00') + { + $period = helper::diffDate($project->end, $project->begin) + 1; + $counts = $period > $itemCounts ? $itemCounts : $period; + } + else + { + $counts = $itemCounts; + } + + for($i = 0; $i < $counts - $burnCounts; $i ++) + { + if(helper::diffDate($current, $project->end) > 0) break; + if(!isset($sets[$current])) + { + $sets[$current]->name = $current; + $sets[$current]->value = ''; + } + $nextDay = date(DT_DATE1, strtotime('next day', strtotime($current))); + $current = $nextDay; + } + } + foreach($sets as $set) + { + $set->name = (string)strtotime("$set->name UTC") . '000'; + } + return $sets; + } + /** * Get taskes by search. * diff --git a/module/report/model.php b/module/report/model.php index bac5ee004f..e8bd96211e 100644 --- a/module/report/model.php +++ b/module/report/model.php @@ -77,6 +77,74 @@ $chartID.render("$divID"); EOT; } + public function createJSChartFlot($projectName, $dataXML, $width = 'auto', $height = 500) + { + $this->app->loadLang('project'); + $jsRoot = $this->app->getWebRoot() . 'js/'; + $width = $width . 'px'; + $height = $height . 'px'; +return << + + +

$projectName {$this->lang->project->burn}

+
+ +EOT; + } + /** * Create xml data of single charts. * @@ -109,6 +177,18 @@ EOT; return $data; } + public function createSingleXMLFlot($sets) + { + $data = '['; + foreach($sets as $set) + { + $data .= " [$set->name, $set->value],"; + } + $data = rtrim($data, ','); + $data .= ']'; + return $data; + } + /** * Create the js code to render chart. *