summaryrefslogtreecommitdiff
path: root/plugins/Timetrackingeditor/Formatter/SubtaskAutoCompleteFormatter.php
blob: 724a146e713e3c6b951d578fad8756caf7750a86 (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
<?php

namespace Kanboard\Plugin\Timetrackingeditor\Formatter;

use Kanboard\Core\Filter\FormatterInterface;
use Kanboard\Model\ProjectModel;
use Kanboard\Model\SubtaskModel;
use Kanboard\Model\TaskModel;
use Kanboard\Formatter\BaseFormatter;

/**
 * Subtask AutoComplete Formatter
 *
 * @package formatter
 * @author  Thomas Stinner
 */
class SubtaskAutoCompleteFormatter extends BaseFormatter implements FormatterInterface
{
    /**
     * Apply formatter
     *
     * @access public
     * @return array
     */
    public function format()
    {
        $subtasks = $this->query->columns(
            SubtaskModel::TABLE.'.id',
            SubtaskModel::TABLE.'.title'
        )->asc(SubtaskModel::TABLE.'.id')->findAll();

        foreach ($subtasks as &$subtask) {
            $subtask['value'] = $subtask['title'];
            $subtask['label'] = ' > #'.$subtask['id'].' '.$subtask['title'];
        }

        return $subtasks;
    }
}