summaryrefslogtreecommitdiff
path: root/app/Export
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2016-03-04 17:57:45 -0500
committerFrederic Guillot <fred@kanboard.net>2016-03-04 17:57:45 -0500
commitf32507d423c46e8e9612b5239728e6c617e4cbcb (patch)
treee1f8c066d1ac47f344da7b5e9060bfab2a6fb57e /app/Export
parentc083822806e075fd1932d7ce86903b4df967babb (diff)
Add namespace Export and move classes
Diffstat (limited to 'app/Export')
-rw-r--r--app/Export/SubtaskExport.php124
-rw-r--r--app/Export/TaskExport.php148
-rw-r--r--app/Export/TransitionExport.php77
3 files changed, 349 insertions, 0 deletions
diff --git a/app/Export/SubtaskExport.php b/app/Export/SubtaskExport.php
new file mode 100644
index 00000000..386c566b
--- /dev/null
+++ b/app/Export/SubtaskExport.php
@@ -0,0 +1,124 @@
+<?php
+
+namespace Kanboard\Export;
+
+use Kanboard\Core\Base;
+use Kanboard\Model\Task;
+use Kanboard\Model\Subtask;
+use Kanboard\Model\User;
+
+/**
+ * Subtask Export
+ *
+ * @package export
+ * @author Frederic Guillot
+ */
+class SubtaskExport extends Base
+{
+ /**
+ * Subtask statuses
+ *
+ * @access private
+ * @var array
+ */
+ private $subtask_status = array();
+
+ /**
+ * Fetch subtasks and return the prepared CSV
+ *
+ * @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)
+ {
+ $this->subtask_status = $this->subtask->getStatusList();
+ $subtasks = $this->getSubtasks($project_id, $from, $to);
+ $results = array($this->getColumns());
+
+ foreach ($subtasks as $subtask) {
+ $results[] = $this->format($subtask);
+ }
+
+ return $results;
+ }
+
+ /**
+ * Get column titles
+ *
+ * @access public
+ * @return string[]
+ */
+ public function getColumns()
+ {
+ return array(
+ e('Subtask Id'),
+ e('Title'),
+ e('Status'),
+ e('Assignee'),
+ e('Time estimated'),
+ e('Time spent'),
+ e('Task Id'),
+ e('Task Title'),
+ );
+ }
+
+ /**
+ * Format the output of a subtask array
+ *
+ * @access public
+ * @param array $subtask Subtask properties
+ * @return array
+ */
+ public function format(array $subtask)
+ {
+ $values = array();
+ $values[] = $subtask['id'];
+ $values[] = $subtask['title'];
+ $values[] = $this->subtask_status[$subtask['status']];
+ $values[] = $subtask['assignee_name'] ?: $subtask['assignee_username'];
+ $values[] = $subtask['time_estimated'];
+ $values[] = $subtask['time_spent'];
+ $values[] = $subtask['task_id'];
+ $values[] = $subtask['task_title'];
+
+ return $values;
+ }
+
+ /**
+ * Get all subtasks for a given project
+ *
+ * @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 getSubtasks($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(Subtask::TABLE)
+ ->eq('project_id', $project_id)
+ ->columns(
+ Subtask::TABLE.'.*',
+ User::TABLE.'.username AS assignee_username',
+ User::TABLE.'.name AS assignee_name',
+ Task::TABLE.'.title AS task_title'
+ )
+ ->gte('date_creation', $from)
+ ->lte('date_creation', $to)
+ ->join(Task::TABLE, 'id', 'task_id')
+ ->join(User::TABLE, 'id', 'user_id')
+ ->asc(Subtask::TABLE.'.id')
+ ->findAll();
+ }
+}
diff --git a/app/Export/TaskExport.php b/app/Export/TaskExport.php
new file mode 100644
index 00000000..b98582aa
--- /dev/null
+++ b/app/Export/TaskExport.php
@@ -0,0 +1,148 @@
+<?php
+
+namespace Kanboard\Export;
+
+use Kanboard\Core\Base;
+use Kanboard\Core\DateParser;
+use Kanboard\Model\Task;
+use PDO;
+
+/**
+ * Task Export
+ *
+ * @package export
+ * @author Frederic Guillot
+ */
+class TaskExport extends Base
+{
+ /**
+ * Fetch tasks and return the prepared CSV
+ *
+ * @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)
+ {
+ $tasks = $this->getTasks($project_id, $from, $to);
+ $swimlanes = $this->swimlane->getList($project_id);
+ $results = array($this->getColumns());
+
+ foreach ($tasks as &$task) {
+ $results[] = array_values($this->format($task, $swimlanes));
+ }
+
+ return $results;
+ }
+
+ /**
+ * Get the list of tasks for a given project and date range
+ *
+ * @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 getTasks($project_id, $from, $to)
+ {
+ $sql = '
+ SELECT
+ tasks.id,
+ projects.name AS project_name,
+ tasks.is_active,
+ project_has_categories.name AS category_name,
+ tasks.swimlane_id,
+ columns.title AS column_title,
+ tasks.position,
+ tasks.color_id,
+ tasks.date_due,
+ creators.username AS creator_username,
+ users.username AS assignee_username,
+ users.name AS assignee_name,
+ tasks.score,
+ tasks.title,
+ tasks.date_creation,
+ tasks.date_modification,
+ tasks.date_completed,
+ tasks.date_started,
+ tasks.time_estimated,
+ tasks.time_spent
+ FROM tasks
+ LEFT JOIN users ON users.id = tasks.owner_id
+ LEFT JOIN users AS creators ON creators.id = tasks.creator_id
+ LEFT JOIN project_has_categories ON project_has_categories.id = tasks.category_id
+ LEFT JOIN columns ON columns.id = tasks.column_id
+ LEFT JOIN projects ON projects.id = tasks.project_id
+ WHERE tasks.date_creation >= ? AND tasks.date_creation <= ? AND tasks.project_id = ?
+ ORDER BY tasks.id ASC
+ ';
+
+ 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)));
+ }
+
+ $rq = $this->db->execute($sql, array($from, $to, $project_id));
+ return $rq->fetchAll(PDO::FETCH_ASSOC);
+ }
+
+ /**
+ * Format the output of a task array
+ *
+ * @access public
+ * @param array $task Task properties
+ * @param array $swimlanes List of swimlanes
+ * @return array
+ */
+ public function format(array &$task, array &$swimlanes)
+ {
+ $colors = $this->color->getList();
+
+ $task['is_active'] = $task['is_active'] == Task::STATUS_OPEN ? e('Open') : e('Closed');
+ $task['color_id'] = $colors[$task['color_id']];
+ $task['score'] = $task['score'] ?: 0;
+ $task['swimlane_id'] = isset($swimlanes[$task['swimlane_id']]) ? $swimlanes[$task['swimlane_id']] : '?';
+
+ $task = $this->dateParser->format($task, array('date_due', 'date_modification', 'date_creation', 'date_started', 'date_completed'), DateParser::DATE_FORMAT);
+
+ return $task;
+ }
+
+ /**
+ * Get column titles
+ *
+ * @access public
+ * @return string[]
+ */
+ public function getColumns()
+ {
+ return array(
+ e('Task Id'),
+ e('Project'),
+ e('Status'),
+ e('Category'),
+ e('Swimlane'),
+ e('Column'),
+ e('Position'),
+ e('Color'),
+ e('Due date'),
+ e('Creator'),
+ e('Assignee Username'),
+ e('Assignee Name'),
+ e('Complexity'),
+ e('Title'),
+ e('Creation date'),
+ e('Modification date'),
+ e('Completion date'),
+ e('Start date'),
+ e('Time estimated'),
+ e('Time spent'),
+ );
+ }
+}
diff --git a/app/Export/TransitionExport.php b/app/Export/TransitionExport.php
new file mode 100644
index 00000000..97dc28a7
--- /dev/null
+++ b/app/Export/TransitionExport.php
@@ -0,0 +1,77 @@
+<?php
+
+namespace Kanboard\Export;
+
+use Kanboard\Core\Base;
+use Kanboard\Core\DateParser;
+
+/**
+ * Transition Export
+ *
+ * @package export
+ * @author Frederic Guillot
+ */
+class TransitionExport extends Base
+{
+ /**
+ * 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->transition->getAllByProjectAndDate($project_id, $from, $to);
+
+ foreach ($transitions as $transition) {
+ $results[] = $this->format($transition);
+ }
+
+ return $results;
+ }
+
+ /**
+ * Get column titles
+ *
+ * @access protected
+ * @return string[]
+ */
+ protected 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 protected
+ * @param array $transition
+ * @return array
+ */
+ protected function format(array $transition)
+ {
+ $values = array(
+ (int) $transition['id'],
+ $transition['title'],
+ $transition['src_column'],
+ $transition['dst_column'],
+ $transition['name'] ?: $transition['username'],
+ date($this->config->get('application_datetime_format', DateParser::DATE_TIME_FORMAT), $transition['date']),
+ round($transition['time_spent'] / 3600, 2)
+ );
+
+ return $values;
+ }
+}