Completed
Push — dev ( 4306de...25864c )
by Arnaud
02:52
created

Action::hasField()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
3
namespace LAG\AdminBundle\Action;
4
5
use LAG\AdminBundle\Action\Configuration\ActionConfiguration;
6
use LAG\AdminBundle\Admin\Filter;
7
use LAG\AdminBundle\Field\Field;
8
9
class Action implements ActionInterface
10
{
11
    /**
12
     * Action name.
13
     *
14
     * @var string
15
     */
16
    protected $name;
17
18
    /**
19
     * Action title.
20
     *
21
     * @var string
22
     */
23
    protected $title;
24
25
    /**
26
     * Fields displayed for this action.
27
     *
28
     * @var Field[]
29
     */
30
    protected $fields = [];
31
32
    /**
33
     * Action permissions.
34
     *
35
     * @var string[]
36
     */
37
    protected $permissions = [];
38
39
    /**
40
     * @var ActionConfiguration
41
     */
42
    protected $configuration;
43
44
    /**
45
     * @var array
46
     */
47
    protected $filters = [];
48
49
    /**
50
     * Action constructor.
51
     *
52
     * @param string $actionName
53
     * @param ActionConfiguration $configuration
54
     */
55 8
    public function __construct($actionName, ActionConfiguration $configuration)
56
    {
57 8
        $this->configuration = $configuration;
58 8
        $this->name = $actionName;
59 8
        $this->title = $configuration->getParameter('title');
60 8
        $this->permissions = $configuration->getParameter('permissions');
61 8
    }
62
63
    /**
64
     * @return string
65
     */
66 7
    public function getName()
67
    {
68 7
        return $this->name;
69
    }
70
71
    /**
72
     * @return string
73
     */
74 1
    public function getTitle()
75
    {
76 1
        return $this->title;
77
    }
78
79
    /**
80
     * @return Field[]
81
     */
82 1
    public function getFields()
83
    {
84 1
        return $this->fields;
85
    }
86
87
    /**
88
     * Return true if action has a field named $fieldName.
89
     *
90
     * @param string $fieldName
91
     *
92
     * @return bool
93
     */
94
    public function hasField($fieldName)
95
    {
96
        return array_key_exists($fieldName, $this->fields);
97
    }
98
99
    /**
100
     * @param Field[] $fields
101
     */
102
    public function setFields($fields)
103
    {
104
        $this->fields = $fields;
105
    }
106
107
    /**
108
     * @param Field $field
109
     */
110 1
    public function addField(Field $field)
111
    {
112 1
        $this->fields[$field->getName()] = $field;
113 1
    }
114
115
    /**
116
     * @return string[]
117
     */
118 2
    public function getPermissions()
119
    {
120 2
        return $this->permissions;
121
    }
122
123
    /**
124
     * @return array
125
     */
126
    public function getFilters()
127
    {
128
        return $this->filters;
129
    }
130
131
    /**
132
     * @param array $filters
133
     */
134
    public function setFilters($filters)
135
    {
136
        $this->filters = $filters;
137
    }
138
139
    /**
140
     * @param Filter $filter
141
     */
142
    public function addFilter(Filter $filter)
143
    {
144
        $this->filters[] = $filter;
145
    }
146
    
147
    /**
148
     * @return ActionConfiguration
149
     */
150 7
    public function getConfiguration()
151
    {
152 7
        return $this->configuration;
153
    }
154
}
155