Issues (3627)

CategoryBundle/Event/CategoryTypesEvent.php (1 issue)

1
<?php
2
3
/*
4
 * @copyright   2014 Mautic Contributors. All rights reserved
5
 * @author      Mautic
6
 *
7
 * @link        http://mautic.org
8
 *
9
 * @license     GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
10
 */
11
12
namespace Mautic\CategoryBundle\Event;
13
14
use Mautic\CategoryBundle\Entity\Category;
15
use Mautic\CoreBundle\Event\CommonEvent;
16
17
/**
18
 * Class CategoryTypesEvent.
19
 */
20
class CategoryTypesEvent extends CommonEvent
21
{
22
    /**
23
     * @var array
24
     */
25
    protected $types = [];
26
27
    /**
28
     * Returns the array of Category Types.
29
     *
30
     * @return array
31
     */
32
    public function getCategoryTypes()
33
    {
34
        if (!array_key_exists('global', $this->types)) {
35
            // Alphabetize once
36
            asort($this->types);
37
38
            $this->types = array_merge(
39
                ['global' => 'mautic.category.global'],
40
                $this->types
41
            );
42
        }
43
44
        return $this->types;
45
    }
46
47
    /**
48
     * Adds the category type and label.
49
     *
50
     * @param string $type
51
     * @param string $label
52
     */
53
    public function addCategoryType($type, $label = null)
54
    {
55
        if (is_int($type)) {
0 ignored issues
show
The condition is_int($type) is always false.
Loading history...
56
            $type = $label;
57
        }
58
59
        if (null === $label) {
60
            $label = 'mautic.'.$type.'.'.$type;
61
        }
62
63
        $this->types[$type] = $label;
64
    }
65
}
66