1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/kanboard_ynh.git synced 2024-09-03 19:36:17 +02:00
kanboard_ynh/sources/app/Model/SubtaskExport.php

120 lines
3.4 KiB
PHP
Raw Normal View History

2015-01-16 14:23:05 +01:00
<?php
namespace Model;
/**
* Subtask Export
*
* @package model
* @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)
{
2015-02-25 17:29:06 +01:00
$this->subtask_status = $this->subtask->getStatusList();
2015-01-16 14:23:05 +01:00
$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
2015-02-25 17:29:06 +01:00
* @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)
2015-01-16 14:23:05 +01:00
* @return array
*/
public function getSubtasks($project_id, $from, $to)
{
if (! is_numeric($from)) {
2015-02-25 17:29:06 +01:00
$from = $this->dateParser->removeTimeFromTimestamp($this->dateParser->getTimestamp($from));
2015-01-16 14:23:05 +01:00
}
if (! is_numeric($to)) {
2015-02-25 17:29:06 +01:00
$to = $this->dateParser->removeTimeFromTimestamp(strtotime('+1 day', $this->dateParser->getTimestamp($to)));
2015-01-16 14:23:05 +01:00
}
2015-02-25 17:29:06 +01:00
return $this->db->table(Subtask::TABLE)
2015-01-16 14:23:05 +01:00
->eq('project_id', $project_id)
->columns(
2015-02-25 17:29:06 +01:00
Subtask::TABLE.'.*',
2015-01-16 14:23:05 +01:00
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')
2015-02-25 17:29:06 +01:00
->asc(Subtask::TABLE.'.id')
2015-01-16 14:23:05 +01:00
->findAll();
}
}