Completed
Push — master ( 530ce9...1b2ae5 )
by Paweł
23:42 queued 20:31
created

Widget::setName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
/**
4
 * This file is part of the Superdesk Web Publisher Template Engine Bundle.
5
 *
6
 * Copyright 2015 Sourcefabric z.u. and contributors.
7
 *
8
 * For the full copyright and license information, please see the
9
 * AUTHORS and LICENSE files distributed with this source code.
10
 *
11
 * @copyright 2015 Sourcefabric z.ú.
12
 * @license http://www.superdesk.org/license
13
 */
14
namespace SWP\Bundle\TemplateEngineBundle\Model;
15
16
use SWP\Component\Common\Model\TimestampableInterface;
17
use SWP\Component\MultiTenancy\Model\TenantAwareInterface;
18
use SWP\Component\MultiTenancy\Model\TenantInterface;
19
use SWP\TemplatesSystem\Gimme\Model\WidgetInterface;
20
use Doctrine\Common\Collections\ArrayCollection;
21
22
/**
23
 * Widget.
24
 */
25
class Widget implements WidgetInterface, TenantAwareInterface, TimestampableInterface
26
{
27
    const TYPE_HTML = 1;
28
29
    protected $types = [
30
        self::TYPE_HTML => '\\SWP\\TemplatesSystem\\Gimme\\Widget\\HtmlWidget',
31
    ];
32
33
    /**
34
     * @var int
35
     */
36
    protected $id;
37
38
    /**
39
     * @var string
40
     */
41
    protected $type;
42
43
    /**
44
     * @var string
45
     */
46
    protected $name;
47
48
    /**
49
     * @var bool
50
     */
51
    protected $visible;
52
53
    /**
54
     * @var []
55
     */
56
    protected $parameters;
57
58
    /**
59
     * @var ArrayCollection
60
     */
61
    protected $containers;
62
63
    /**
64
     * @var TenantInterface
65
     */
66
    protected $tenant;
67
68
    /**
69
     * @var \DateTime
70
     */
71
    protected $createdAt;
72
73
    /**
74
     * @var \DateTime
75
     */
76
    protected $updatedAt = null;
77
78
    public function __construct()
79
    {
80
        $this->createdAt = new \DateTime();
81
        $this->parameters = [];
82
        $this->setVisible();
83
        $this->setType();
84
    }
85
86
    /**
87
     * Get id.
88
     *
89
     * @return int
90
     */
91
    public function getId()
92
    {
93
        return $this->id;
94
    }
95
96
    /**
97
     * Set name.
98
     *
99
     * @param string $name
100
     *
101
     * @return Widget
102
     */
103
    public function setName($name)
104
    {
105
        $this->name = $name;
106
107
        return $this;
108
    }
109
110
    /**
111
     * Get name.
112
     *
113
     * @return string
114
     */
115
    public function getName()
116
    {
117
        return $this->name;
118
    }
119
120
    /**
121
     * Gets the value of visible.
122
     *
123
     * @return bool
124
     */
125
    public function getVisible()
126
    {
127
        return $this->visible;
128
    }
129
130
    /**
131
     * Sets the value of visible.
132
     *
133
     * @param bool $visible the visible
134
     *
135
     * @return self
136
     */
137
    public function setVisible($visible = true)
138
    {
139
        $this->visible = $visible;
140
141
        return $this;
142
    }
143
144
    /**
145
     * Gets the value of type.
146
     *
147
     * @return string
148
     */
149
    public function getType()
150
    {
151
        return $this->type;
152
    }
153
154
    /**
155
     * Sets the value of type.
156
     *
157
     * @param int $type the type
158
     *
159
     * @return self
160
     */
161
    public function setType($type = self::TYPE_HTML)
162
    {
163
        if (array_key_exists($type, $this->types)) {
164
            $this->type = $this->types[$type];
165
        } else {
166
            $this->type = $this->types[self::TYPE_HTML];
167
        }
168
169
        return $this;
170
    }
171
172
    /**
173
     * {@inheritdoc}
174
     */
175
    public function getParameters()
176
    {
177
        return $this->parameters;
178
    }
179
180
    /**
181
     * Sets the value of parameters.
182
     *
183
     * @param [] $parameters the parameters
0 ignored issues
show
Documentation introduced by
The doc-type [] could not be parsed: Unknown type name "" at position 0. [(view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
184
     *
185
     * @return self
186
     */
187
    public function setParameters($parameters = array())
188
    {
189
        $this->parameters = $parameters;
190
191
        return $this;
192
    }
193
194
    /**
195
     * Gets the value of containers.
196
     *
197
     * @return ArrayCollection
198
     */
199
    public function getContainers()
200
    {
201
        return $this->containers;
202
    }
203
204
    /**
205
     * Sets the value of containers.
206
     *
207
     * @param ArrayCollection $containers the containers
208
     *
209
     * @return self
210
     */
211
    protected function setContainers(ArrayCollection $containers)
212
    {
213
        $this->containers = $containers;
214
215
        return $this;
216
    }
217
218
    /**
219
     * {@inheritdoc}
220
     */
221
    public function getTenant()
222
    {
223
        return $this->tenant;
224
    }
225
226
    /**
227
     * {@inheritdoc}
228
     */
229
    public function setTenant(TenantInterface $tenant)
230
    {
231
        $this->tenant = $tenant;
232
    }
233
234
    /**
235
     * {@inheritdoc}
236
     */
237
    public function getCreatedAt()
238
    {
239
        return $this->createdAt;
240
    }
241
242
    /**
243
     * {@inheritdoc}
244
     */
245
    public function setCreatedAt(\DateTime $createdAt)
246
    {
247
        $this->createdAt = $createdAt;
248
    }
249
250
    /**
251
     * {@inheritdoc}
252
     */
253
    public function getUpdatedAt()
254
    {
255
        if (is_null($this->updatedAt)) {
256
            return $this->createdAt;
257
        }
258
259
        return $this->updatedAt;
260
    }
261
262
    /**
263
     * {@inheritdoc}
264
     */
265
    public function setUpdatedAt(\DateTime $updatedAt)
266
    {
267
        $this->updatedAt = $updatedAt;
268
    }
269
}
270