diff options
| author | Lesstat <florianbarth@gmx.de> | 2015-07-11 11:44:26 +0200 |
|---|---|---|
| committer | Lesstat <florianbarth@gmx.de> | 2015-07-11 11:44:26 +0200 |
| commit | a85a1c613239c20fe72eb96c2921f4c220ec156b (patch) | |
| tree | d032b4591e518cbbbfaa8886f8f5d98a6ea2efb7 /app/Model/TaskAnalytic.php | |
| parent | 5101eaa8060ce3c75a81a26f6e47aae40e3d4ac3 (diff) | |
| parent | 7e94d0ca233d15d6124c0adf3f956a119c82ccae (diff) | |
Merged branch 'master' of https://github.com/fguillot/kanboard
only imports conflicted
Diffstat (limited to 'app/Model/TaskAnalytic.php')
| -rw-r--r-- | app/Model/TaskAnalytic.php | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/app/Model/TaskAnalytic.php b/app/Model/TaskAnalytic.php new file mode 100644 index 00000000..33a645c1 --- /dev/null +++ b/app/Model/TaskAnalytic.php @@ -0,0 +1,71 @@ +<?php + +namespace Model; + +/** + * Task Analytic + * + * @package model + * @author Frederic Guillot + */ +class TaskAnalytic extends Base +{ + /** + * Get the time between date_creation and date_completed or now if empty + * + * @access public + * @param array $task + * @return integer + */ + public function getLeadTime(array $task) + { + return ($task['date_completed'] ?: time()) - $task['date_creation']; + } + + /** + * Get the time between date_started and date_completed or now if empty + * + * @access public + * @param array $task + * @return integer + */ + public function getCycleTime(array $task) + { + if (empty($task['date_started'])) { + return 0; + } + + return ($task['date_completed'] ?: time()) - $task['date_started']; + } + + /** + * Get the average time spent in each column + * + * @access public + * @param array $task + * @return array + */ + public function getTimeSpentByColumn(array $task) + { + $result = array(); + $columns = $this->board->getColumnsList($task['project_id']); + $sums = $this->transition->getTimeSpentByTask($task['id']); + + foreach ($columns as $column_id => $column_title) { + + $time_spent = isset($sums[$column_id]) ? $sums[$column_id] : 0; + + if ($task['column_id'] == $column_id) { + $time_spent += ($task['date_completed'] ?: time()) - $task['date_moved']; + } + + $result[] = array( + 'id' => $column_id, + 'title' => $column_title, + 'time_spent' => $time_spent, + ); + } + + return $result; + } +} |
