summaryrefslogtreecommitdiff
path: root/app/Model/TaskAnalyticModel.php
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2016-05-28 19:48:22 -0400
committerFrederic Guillot <fred@kanboard.net>2016-05-28 19:48:22 -0400
commit14713b0ec7ed93ca45578da069ad4e19a7d8addf (patch)
tree79972d53f6091a1ddb17f64a6a05a5523f5d5168 /app/Model/TaskAnalyticModel.php
parent936376ffe74c583d3cb819e98f53a85137fdf8bc (diff)
Rename all models
Diffstat (limited to 'app/Model/TaskAnalyticModel.php')
-rw-r--r--app/Model/TaskAnalyticModel.php72
1 files changed, 72 insertions, 0 deletions
diff --git a/app/Model/TaskAnalyticModel.php b/app/Model/TaskAnalyticModel.php
new file mode 100644
index 00000000..3d6fe8a8
--- /dev/null
+++ b/app/Model/TaskAnalyticModel.php
@@ -0,0 +1,72 @@
+<?php
+
+namespace Kanboard\Model;
+
+use Kanboard\Core\Base;
+
+/**
+ * Task Analytic
+ *
+ * @package Kanboard\Model
+ * @author Frederic Guillot
+ */
+class TaskAnalyticModel 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->columnModel->getList($task['project_id']);
+ $sums = $this->transitionModel->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;
+ }
+}