summaryrefslogtreecommitdiff
path: root/app/Model/Transition.php
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2015-03-28 12:39:46 -0400
committerFrederic Guillot <fred@kanboard.net>2015-03-28 12:39:46 -0400
commit26fea9b96ba4376a54b5d55b207d3eac040160d7 (patch)
tree5034c38ffff04d8d60becd1c09d4360036ce0927 /app/Model/Transition.php
parent87d2c6d99e6eb26b526f5da22b3496e3d02d11ed (diff)
Add task transitions csv export
Diffstat (limited to 'app/Model/Transition.php')
-rw-r--r--app/Model/Transition.php103
1 files changed, 103 insertions, 0 deletions
diff --git a/app/Model/Transition.php b/app/Model/Transition.php
index 583d3aca..cb759e4a 100644
--- a/app/Model/Transition.php
+++ b/app/Model/Transition.php
@@ -64,4 +64,107 @@ class Transition extends Base
->join(Board::TABLE.' as dst', 'id', 'dst_column_id', self::TABLE, 'dst')
->findAll();
}
+
+ /**
+ * Get all transitions by project
+ *
+ * @access public
+ * @param integer $project_id
+ * @param mixed $from Start date (timestamp or user formatted date)
+ * @param mixed $to End date (timestamp or user formatted date)
+ * @return array
+ */
+ public function getAllByProjectAndDate($project_id, $from, $to)
+ {
+ if (! is_numeric($from)) {
+ $from = $this->dateParser->removeTimeFromTimestamp($this->dateParser->getTimestamp($from));
+ }
+
+ if (! is_numeric($to)) {
+ $to = $this->dateParser->removeTimeFromTimestamp(strtotime('+1 day', $this->dateParser->getTimestamp($to)));
+ }
+
+ return $this->db->table(self::TABLE)
+ ->columns(
+ Task::TABLE.'.id',
+ Task::TABLE.'.title',
+ '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'
+ )
+ ->gte('date', $from)
+ ->lte('date', $to)
+ ->eq(self::TABLE.'.project_id', $project_id)
+ ->desc('date')
+ ->join(Task::TABLE, 'id', 'task_id')
+ ->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();
+ }
+
+ /**
+ * Get project export
+ *
+ * @access public
+ * @param integer $project_id Project id
+ * @param mixed $from Start date (timestamp or user formatted date)
+ * @param mixed $to End date (timestamp or user formatted date)
+ * @return array
+ */
+ public function export($project_id, $from, $to)
+ {
+ $results = array($this->getColumns());
+ $transitions = $this->getAllByProjectAndDate($project_id, $from, $to);
+
+ foreach ($transitions as $transition) {
+ $results[] = $this->format($transition);
+ }
+
+ return $results;
+ }
+
+ /**
+ * Get column titles
+ *
+ * @access public
+ * @return string[]
+ */
+ public function getColumns()
+ {
+ return array(
+ e('Id'),
+ e('Task Title'),
+ e('Source column'),
+ e('Destination column'),
+ e('Executer'),
+ e('Date'),
+ e('Time spent'),
+ );
+ }
+
+ /**
+ * Format the output of a transition array
+ *
+ * @access public
+ * @param array $transition
+ * @return array
+ */
+ public function format(array $transition)
+ {
+ $values = array();
+ $values[] = $transition['id'];
+ $values[] = $transition['title'];
+ $values[] = $transition['src_column'];
+ $values[] = $transition['dst_column'];
+ $values[] = $transition['name'] ?: $transition['username'];
+ $values[] = date('Y-m-d H:i', $transition['date']);
+ $values[] = round($transition['time_spent'] / 3600, 2);
+
+ return $values;
+ }
}