summaryrefslogtreecommitdiff
path: root/app/Model/Transition.php
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2015-03-26 22:40:46 -0400
committerFrederic Guillot <fred@kanboard.net>2015-03-26 22:40:46 -0400
commit87d2c6d99e6eb26b526f5da22b3496e3d02d11ed (patch)
treeedb8ef750b85fda13ebb2c4f7089eef94328d0f1 /app/Model/Transition.php
parent93fa9b5cba4bf343d3c5dd97420cea81beaf6e88 (diff)
Add task transitions history
Diffstat (limited to 'app/Model/Transition.php')
-rw-r--r--app/Model/Transition.php67
1 files changed, 67 insertions, 0 deletions
diff --git a/app/Model/Transition.php b/app/Model/Transition.php
new file mode 100644
index 00000000..583d3aca
--- /dev/null
+++ b/app/Model/Transition.php
@@ -0,0 +1,67 @@
+<?php
+
+namespace Model;
+
+/**
+ * Transition model
+ *
+ * @package model
+ * @author Frederic Guillot
+ */
+class Transition extends Base
+{
+ /**
+ * SQL table name
+ *
+ * @var string
+ */
+ const TABLE = 'transitions';
+
+ /**
+ * Save transition event
+ *
+ * @access public
+ * @param integer $user_id
+ * @param array $task
+ * @return boolean
+ */
+ public function save($user_id, array $task)
+ {
+ return $this->db->table(self::TABLE)->insert(array(
+ 'user_id' => $user_id,
+ 'project_id' => $task['project_id'],
+ 'task_id' => $task['task_id'],
+ 'src_column_id' => $task['src_column_id'],
+ 'dst_column_id' => $task['dst_column_id'],
+ 'date' => time(),
+ 'time_spent' => time() - $task['date_moved']
+ ));
+ }
+
+ /**
+ * Get all transitions by task
+ *
+ * @access public
+ * @param integer $task_id
+ * @return array
+ */
+ public function getAllByTask($task_id)
+ {
+ return $this->db->table(self::TABLE)
+ ->columns(
+ 'src.title as src_column',
+ 'dst.title as dst_column',
+ User::TABLE.'.name',
+ User::TABLE.'.username',
+ self::TABLE.'.user_id',
+ self::TABLE.'.date',
+ self::TABLE.'.time_spent'
+ )
+ ->eq('task_id', $task_id)
+ ->desc('date')
+ ->join(User::TABLE, 'id', 'user_id')
+ ->join(Board::TABLE.' as src', 'id', 'src_column_id', self::TABLE, 'src')
+ ->join(Board::TABLE.' as dst', 'id', 'dst_column_id', self::TABLE, 'dst')
+ ->findAll();
+ }
+}