summaryrefslogtreecommitdiff
path: root/app/Controller
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2015-06-21 22:13:13 -0400
committerFrederic Guillot <fred@kanboard.net>2015-06-21 22:13:13 -0400
commit59da03c2cb3c5c68daa39d79ee0c4c50b9bed35e (patch)
tree14b4d433108a7701ef2967222848712a1f1389f3 /app/Controller
parent81e40e2c910f0be3f6031445a4d2c1714cdeb385 (diff)
Remove some code duplication
Diffstat (limited to 'app/Controller')
-rw-r--r--app/Controller/Analytic.php42
1 files changed, 14 insertions, 28 deletions
diff --git a/app/Controller/Analytic.php b/app/Controller/Analytic.php
index 41fe7169..2413ba92 100644
--- a/app/Controller/Analytic.php
+++ b/app/Controller/Analytic.php
@@ -65,31 +65,7 @@ class Analytic extends Base
*/
public function cfd()
{
- $project = $this->getProject();
- $values = $this->request->getValues();
-
- $from = $this->request->getStringParam('from', date('Y-m-d', strtotime('-1week')));
- $to = $this->request->getStringParam('to', date('Y-m-d'));
-
- if (! empty($values)) {
- $from = $values['from'];
- $to = $values['to'];
- }
-
- $display_graph = $this->projectDailySummary->countDays($project['id'], $from, $to) >= 2;
-
- $this->response->html($this->layout('analytic/cfd', array(
- 'values' => array(
- 'from' => $from,
- 'to' => $to,
- ),
- 'display_graph' => $display_graph,
- 'metrics' => $display_graph ? $this->projectDailySummary->getAggregatedMetrics($project['id'], $from, $to) : array(),
- 'project' => $project,
- 'date_format' => $this->config->get('application_date_format'),
- 'date_formats' => $this->dateParser->getAvailableFormats(),
- 'title' => t('Cumulative flow diagram for "%s"', $project['name']),
- )));
+ $this->commonAggregateMetrics('analytic/cfd', 'total', 'Cumulative flow diagram for "%s"');
}
/**
@@ -99,6 +75,16 @@ class Analytic extends Base
*/
public function burndown()
{
+ $this->commonAggregateMetrics('analytic/burndown', 'score', 'Burndown chart for "%s"');
+ }
+
+ /**
+ * Common method for CFD and Burdown chart
+ *
+ * @access private
+ */
+ private function commonAggregateMetrics($template, $column, $title)
+ {
$project = $this->getProject();
$values = $this->request->getValues();
@@ -112,17 +98,17 @@ class Analytic extends Base
$display_graph = $this->projectDailySummary->countDays($project['id'], $from, $to) >= 2;
- $this->response->html($this->layout('analytic/burndown', array(
+ $this->response->html($this->layout($template, array(
'values' => array(
'from' => $from,
'to' => $to,
),
'display_graph' => $display_graph,
- 'metrics' => $display_graph ? $this->projectDailySummary->getAggregatedMetrics($project['id'], $from, $to, 'score') : array(),
+ 'metrics' => $display_graph ? $this->projectDailySummary->getAggregatedMetrics($project['id'], $from, $to, $column) : array(),
'project' => $project,
'date_format' => $this->config->get('application_date_format'),
'date_formats' => $this->dateParser->getAvailableFormats(),
- 'title' => t('Burndown chart for "%s"', $project['name']),
+ 'title' => t($title, $project['name']),
)));
}
}