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/TaskExport.php

144 lines
4.4 KiB
PHP
Raw Normal View History

2014-11-23 20:13:38 +01:00
<?php
namespace Model;
use PDO;
/**
* Task Export model
*
* @package model
* @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);
2015-01-16 14:23:05 +01:00
$swimlanes = $this->swimlane->getSwimlanesList($project_id);
2014-11-23 20:13:38 +01:00
$results = array($this->getColumns());
foreach ($tasks as &$task) {
2015-01-16 14:23:05 +01:00
$results[] = array_values($this->format($task, $swimlanes));
2014-11-23 20:13:38 +01:00
}
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,
2015-01-16 14:23:05 +01:00
tasks.swimlane_id,
2014-11-23 20:13:38 +01:00
columns.title AS column_title,
tasks.position,
tasks.color_id,
tasks.date_due,
creators.username AS creator_username,
users.username AS assignee_username,
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 = ?
2015-01-16 14:23:05 +01:00
ORDER BY tasks.id ASC
2014-11-23 20:13:38 +01:00
';
if (! is_numeric($from)) {
$from = $this->dateParser->resetDateToMidnight($this->dateParser->getTimestamp($from));
}
if (! is_numeric($to)) {
$to = $this->dateParser->resetDateToMidnight(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
2015-01-16 14:23:05 +01:00
* @param array $task Task properties
* @param array $swimlanes List of swimlanes
2014-11-23 20:13:38 +01:00
* @return array
*/
2015-01-16 14:23:05 +01:00
public function format(array &$task, array &$swimlanes)
2014-11-23 20:13:38 +01:00
{
$colors = $this->color->getList();
$task['is_active'] = $task['is_active'] == Task::STATUS_OPEN ? e('Open') : e('Closed');
$task['color_id'] = $colors[$task['color_id']];
2015-01-16 14:23:05 +01:00
$task['score'] = $task['score'] ?: 0;
$task['swimlane_id'] = isset($swimlanes[$task['swimlane_id']]) ? $swimlanes[$task['swimlane_id']] : '?';
2014-11-23 20:13:38 +01:00
$this->dateParser->format($task, array('date_due', 'date_modification', 'date_creation', 'date_started', 'date_completed'), 'Y-m-d');
return $task;
}
/**
* Get column titles
*
* @access public
2015-01-16 14:23:05 +01:00
* @return string[]
2014-11-23 20:13:38 +01:00
*/
public function getColumns()
{
return array(
e('Task Id'),
e('Project'),
e('Status'),
e('Category'),
2015-01-16 14:23:05 +01:00
e('Swimlane'),
2014-11-23 20:13:38 +01:00
e('Column'),
e('Position'),
e('Color'),
e('Due date'),
e('Creator'),
e('Assignee'),
e('Complexity'),
e('Title'),
e('Creation date'),
e('Modification date'),
e('Completion date'),
e('Start date'),
e('Time estimated'),
e('Time spent'),
);
}
}