Completed
Pull Request — dev (#9)
by Arnaud
02:46
created

Action::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

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