Passed
Push — develop ( 8f0f3d...76f899 )
by BENARD
08:13
created

Page::setEnabled()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace ProjetNormandie\PageBundle\Entity;
4
5
use ApiPlatform\Core\Annotation\ApiFilter;
6
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
7
use Doctrine\ORM\Mapping as ORM;
8
use Knp\DoctrineBehaviors\Contract\Entity\TimestampableInterface;
9
use Knp\DoctrineBehaviors\Model\Timestampable\TimestampableTrait;
10
use Knp\DoctrineBehaviors\Contract\Entity\TranslatableInterface;
11
use Knp\DoctrineBehaviors\Model\Translatable\TranslatableMethodsTrait;
12
use Knp\DoctrineBehaviors\Model\Translatable\TranslatablePropertiesTrait;
13
use Knp\DoctrineBehaviors\Contract\Entity\SluggableInterface;
14
use Knp\DoctrineBehaviors\Model\Sluggable\SluggableTrait;
15
use ProjetNormandie\PageBundle\Contracts\PageInterface;
16
17
/**
18
 * Page
19
 *
20
 * @ORM\Table(name="page")
21
 * @ORM\Entity(repositoryClass="ProjetNormandie\PageBundle\Repository\PageRepository")
22
 * @ApiFilter(
23
 *     SearchFilter::class,
24
 *     properties={
25
 *          "slug": "exact",
26
*      }
27
 * )
28
 */
29
class Page implements TimestampableInterface, TranslatableInterface, SluggableInterface, PageInterface
30
{
31
    use TimestampableTrait;
32
    use TranslatablePropertiesTrait;
33
    use TranslatableMethodsTrait;
34
    use SluggableTrait;
35
36
    /**
37
     * @ORM\Column(name="id", type="integer")
38
     * @ORM\Id
39
     * @ORM\GeneratedValue(strategy="IDENTITY")
40
     */
41
    private ?int $id = null;
42
43
44
    /**
45
     * @ORM\Column(name="name", type="string", nullable=false)
46
     */
47
    private string $name = '';
48
49
     /**
50
     * @ORM\Column(name="status", type="string", nullable=false)
51
     */
52
    private string $status = self::STATUS_PUBLIC;
53
54
    /**
55
     * @ORM\Column(name="enabled", type="boolean", nullable=false, options={"default":true})
56
     */
57
    private bool $enabled = true;
58
59
60
    /**
61
     * @return string
62
     */
63
    public function __toString()
64
    {
65
        return sprintf('%s [%s]', $this->getName(), $this->id);
66
    }
67
68
    /**
69
     * @return string
70
     */
71
    public function getDefaultText(): string
72
    {
73
        return $this->translate('en', false)->getText();
74
    }
75
76
    /**
77
     * Set id
78
     * @param integer $id
79
     * @return $this
80
     */
81
    public function setId(int $id): Page
82
    {
83
        $this->id = $id;
84
        return $this;
85
    }
86
87
    /**
88
     * Get id
89
     * @return integer
90
     */
91
    public function getId(): ?int
92
    {
93
        return $this->id;
94
    }
95
96
    /**
97
     * Set name
98
     * @param string $name
99
     * @return string
100
     */
101
    public function setName(string $name): string
102
    {
103
        $this->name = $name;
104
        return $this;
105
    }
106
107
    /**
108
     * Get name
109
     *
110
     * @return string
111
     */
112
    public function getName(): string
113
    {
114
        return $this->name;
115
    }
116
117
    /**
118
     * @param string $status
119
     * @return $this
120
     */
121
    public function setStatus(string $status): Page
122
    {
123
        $this->status = $status;
124
        return $this;
125
    }
126
127
    /**
128
     * Get status
129
     * @return string
130
     */
131
    public function getStatus(): string
132
    {
133
        return $this->status;
134
    }
135
136
    /**
137
     * Set enabled
138
     * @param bool $enabled
139
     * @return $this
140
     */
141
    public function setEnabled(bool $enabled): Page
142
    {
143
        $this->enabled = $enabled;
144
145
        return $this;
146
    }
147
148
    /**
149
     * Get $enabled
150
     * @return bool
151
     */
152
    public function getEnabled(): bool
153
    {
154
        return $this->enabled;
155
    }
156
157
    /**
158
     * @param string $title
159
     * @return $this
160
     */
161
    public function setTitle(string $title): Page
162
    {
163
        $this->translate(null, false)->setText($title);
164
        return $this;
165
    }
166
167
    /**
168
     * @return string
169
     */
170
    public function getTitle(): string
171
    {
172
        return $this->translate(null, false)->getTitle();
173
    }
174
175
     /**
176
     * @param string $text
177
     * @return $this
178
     */
179
    public function setText(string $text): Page
180
    {
181
        $this->translate(null, false)->setText($text);
182
183
        return $this;
184
    }
185
186
    /**
187
     * @return string
188
     */
189
    public function getText(): string
190
    {
191
        return $this->translate(null, false)->getText();
192
    }
193
194
    /**
195
     * Returns an array of the fields used to generate the slug.
196
     *
197
     * @return string[]
198
     */
199
    public function getSluggableFields(): array
200
    {
201
        return ['name'];
202
    }
203
204
     /**
205
     * @return array
206
     */
207
    public static function getStatusChoices(): array
208
    {
209
        return [
210
            self::STATUS_PUBLIC => self::STATUS_PUBLIC,
211
            self::STATUS_PRIVATE=> self::STATUS_PRIVATE,
212
        ];
213
    }
214
}
215