summaryrefslogtreecommitdiff
path: root/app/Export/TransitionExport.php
blob: 35f9fe44b7f49003bc8727e9f713e6adb9d24498 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php

namespace Kanboard\Export;

use Kanboard\Core\Base;

/**
 * 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->transitionModel->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->dateParser->getUserDateTimeFormat(), $transition['date']),
            round($transition['time_spent'] / 3600, 2)
        );

        return $values;
    }
}