diff options
author | Frederic Guillot <fred@kanboard.net> | 2016-03-04 17:57:45 -0500 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2016-03-04 17:57:45 -0500 |
commit | f32507d423c46e8e9612b5239728e6c617e4cbcb (patch) | |
tree | e1f8c066d1ac47f344da7b5e9060bfab2a6fb57e /app/Export/SubtaskExport.php | |
parent | c083822806e075fd1932d7ce86903b4df967babb (diff) |
Add namespace Export and move classes
Diffstat (limited to 'app/Export/SubtaskExport.php')
-rw-r--r-- | app/Export/SubtaskExport.php | 124 |
1 files changed, 124 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(); + } +} |