Client::getDisplayName()   A
last analyzed

Complexity

Conditions 4
Paths 6

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.2
c 0
b 0
f 0
cc 4
eloc 9
nc 6
nop 0
1
<?php
2
3
namespace ClientBundle\Entity;
4
5
use Doctrine\Common\Collections\ArrayCollection;
6
use Doctrine\ORM\Mapping as ORM;
7
use Symfony\Component\Validator\Constraints as Assert;
8
9
/**
10
 * Class Client
11
 * @ORM\Entity(repositoryClass="ClientBundle\Repository\ClientRepository")
12
 * @ORM\Table(name="client")
13
 * @ORM\HasLifecycleCallbacks
14
 */
15
class Client
16
{
17
    /**
18
     * @ORM\Column(type="integer")
19
     * @ORM\Id
20
     * @ORM\GeneratedValue(strategy="AUTO")
21
     */
22
    private $id;
23
24
    /**
25
     * @ORM\Column(type="string", length=50, nullable=false)
26
     * @Assert\NotBlank(message = "client.firstname.not_blank")
27
     */
28
    private $firstname;
29
30
    /**
31
     * @ORM\Column(type="string", length=50, nullable=true)
32
     */
33
    private $surname;
34
35
    /**
36
     * @ORM\Column(type="date", nullable=true)
37
     * @Assert\Date()
38
     */
39
    private $birthday;
40
41
    /**
42
     * @ORM\Column(type="date", nullable=true)
43
     * @Assert\Date()
44
     */
45
    private $createdAt;
46
47
    /**
48
     * @ORM\OneToMany(targetEntity="Contact", mappedBy="client", cascade={"remove"})
49
     */
50
    private $contacts;
51
52
    /**
53
     * @ORM\ManyToMany(targetEntity="Category", inversedBy="clients")
54
     * @ORM\JoinTable(name="client_category")
55
     */
56
    private $categories;
57
58
    /**
59
     * @ORM\ManyToOne(targetEntity="Lang")
60
     */
61
    private $language;
62
63
    /**
64
     * @ORM\Column(type="text", nullable=true)
65
     */
66
    private $description;
67
68
    /**
69
     * @ORM\Column(type="array", nullable=true)
70
     */
71
    private $tags;
72
73
    /**
74
     * Constructor
75
     */
76
    public function __construct()
77
    {
78
        $this->contacts = new ArrayCollection();
79
        $this->categories = new ArrayCollection();
80
    }
81
82
    /**
83
     * Get id
84
     *
85
     * @return integer
86
     */
87
    public function getId()
88
    {
89
        return $this->id;
90
    }
91
92
    /**
93
     * Get tags
94
     *
95
     * @return array
96
     */
97
    public function getTags()
98
    {
99
        return $this->tags;
100
    }
101
102
    /**
103
     * Set tags
104
     *
105
     * @param array $tags
106
     *
107
     * @return Client
108
     */
109
    public function setTags($tags)
110
    {
111
        $this->tags = $tags;
112
113
        return $this;
114
    }
115
116
    /**
117
     * Set firstname
118
     *
119
     * @param string $firstname
120
     *
121
     * @return Client
122
     */
123
    public function setFirstname($firstname)
124
    {
125
        $this->firstname = $firstname;
126
127
        return $this;
128
    }
129
130
    /**
131
     * Get firstname
132
     *
133
     * @return string
134
     */
135
    public function getFirstname()
136
    {
137
        return $this->firstname;
138
    }
139
140
    /**
141
     * Set surname
142
     *
143
     * @param string $surname
144
     *
145
     * @return Client
146
     */
147
    public function setSurname($surname)
148
    {
149
        $this->surname = $surname;
150
151
        return $this;
152
    }
153
154
    /**
155
     * Get surname
156
     *
157
     * @return string
158
     */
159
    public function getSurname()
160
    {
161
        return $this->surname;
162
    }
163
164
    /**
165
     * Get display name
166
     *
167
     * @return string
168
     */
169
    public function getDisplayName()
170
    {
171
        $displayName = '';
172
        if (!empty($this->getSurname())) {
173
            $displayName = $this->getSurname();
174
        }
175
        if (!empty($this->getFirstname())) {
176
            if (!empty($displayName)) {
177
                $displayName .= ' ';
178
            }
179
            $displayName .= $this->getFirstname();
180
        }
181
182
        return $displayName;
183
    }
184
185
    /**
186
     * @return string
187
     */
188
    public function __toString()
189
    {
190
        return (string) $this ->getDisplayName();
191
    }
192
193
    /**
194
     * Set birthday
195
     *
196
     * @param \DateTime $birthday
197
     *
198
     * @return Client
199
     */
200
    public function setBirthday($birthday)
201
    {
202
        $this->birthday = $birthday;
203
204
        return $this;
205
    }
206
207
    /**
208
     * Get birthday
209
     *
210
     * @return \DateTime
211
     */
212
    public function getBirthday()
213
    {
214
        return $this->birthday;
215
    }
216
217
    /**
218
     * Set createdAt
219
     *
220
     * @return Client
221
     * @ORM\PrePersist
222
     */
223
    public function setCreatedAt()
224
    {
225
        $this->createdAt = new \DateTime('now');
226
227
        return $this;
228
    }
229
230
    /**
231
     * Get createdAt
232
     *
233
     * @return \DateTime
234
     */
235
    public function getCreatedAt()
236
    {
237
        return $this->createdAt;
238
    }
239
240
    /**
241
     * Set description
242
     *
243
     * @param string $description
244
     *
245
     * @return Client
246
     */
247
    public function setDescription($description)
248
    {
249
        $this->description = $description;
250
251
        return $this;
252
    }
253
254
    /**
255
     * Get description
256
     *
257
     * @return string
258
     */
259
    public function getDescription()
260
    {
261
        return $this->description;
262
    }
263
264
    /**
265
     * Add contact
266
     *
267
     * @param \ClientBundle\Entity\Contact $contact
268
     *
269
     * @return Client
270
     */
271
    public function addContact(\ClientBundle\Entity\Contact $contact)
272
    {
273
        $contact->setClient($this);
274
        $this->contacts[] = $contact;
275
276
        return $this;
277
    }
278
279
    /**
280
     * Remove contact
281
     *
282
     * @param \ClientBundle\Entity\Contact $contact
283
     */
284
    public function removeContact(\ClientBundle\Entity\Contact $contact)
285
    {
286
        $this->contacts->removeElement($contact);
287
    }
288
289
    /**
290
     * Get contacts
291
     *
292
     * @return \Doctrine\Common\Collections\Collection
293
     */
294
    public function getContacts()
295
    {
296
        return $this->contacts;
297
    }
298
299
    /**
300
     * Add category
301
     *
302
     * @param \ClientBundle\Entity\Category $category
303
     *
304
     * @return Client
305
     */
306
    public function addCategory(\ClientBundle\Entity\Category $category)
307
    {
308
        $this->categories[] = $category;
309
310
        return $this;
311
    }
312
313
    /**
314
     * Remove category
315
     *
316
     * @param \ClientBundle\Entity\Category $category
317
     */
318
    public function removeCategory(\ClientBundle\Entity\Category $category)
319
    {
320
        $this->categories->removeElement($category);
321
    }
322
323
    /**
324
     * Get categories
325
     *
326
     * @return \Doctrine\Common\Collections\Collection
327
     */
328
    public function getCategories()
329
    {
330
        return $this->categories;
331
    }
332
333
    /**
334
     * Set language
335
     *
336
     * @param \ClientBundle\Entity\Lang $language
337
     *
338
     * @return Client
339
     */
340
    public function setLanguage(\ClientBundle\Entity\Lang $language = null)
341
    {
342
        $this->language = $language;
343
344
        return $this;
345
    }
346
347
    /**
348
     * Get language
349
     *
350
     * @return \ClientBundle\Entity\Lang
351
     */
352
    public function getLanguage()
353
    {
354
        return $this->language;
355
    }
356
}
357