summaryrefslogtreecommitdiff
path: root/app/Formatter/GroupAutoCompleteFormatter.php
blob: 9d740b7fce2c5fe9e157330562b49a0ce42bd879 (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
<?php

namespace Kanboard\Formatter;

use Kanboard\Core\Filter\FormatterInterface;
use Kanboard\Core\Group\GroupProviderInterface;

/**
 * Auto-complete formatter for groups
 *
 * @package  Kanboard\Formatter
 * @author   Frederic Guillot
 */
class GroupAutoCompleteFormatter extends BaseFormatter implements FormatterInterface
{
    /**
     * Groups found
     *
     * @access protected
     * @var GroupProviderInterface[]
     */
    protected $groups;

    /**
     * Set groups
     *
     * @access public
     * @param  GroupProviderInterface[] $groups
     * @return $this
     */
    public function withGroups(array $groups)
    {
        $this->groups = $groups;
        return $this;
    }

    /**
     * Format groups for the ajax auto-completion
     *
     * @access public
     * @return array
     */
    public function format()
    {
        $result = array();

        foreach ($this->groups as $group) {
            $result[] = array(
                'id' => $group->getInternalId(),
                'external_id' => $group->getExternalId(),
                'value' => $group->getName(),
                'label' => $group->getName(),
            );
        }

        return $result;
    }
}