Failed Conditions
Pull Request — 4.0 (#4528)
by Kentaro
07:39
created

Member::serialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
ccs 0
cts 0
cp 0
crap 2
1
<?php
2
3
/*
4
 * This file is part of EC-CUBE
5
 *
6
 * Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
7
 *
8
 * http://www.ec-cube.co.jp/
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Eccube\Entity;
15
16
use Doctrine\ORM\Mapping as ORM;
17
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
18
use Symfony\Component\Security\Core\User\UserInterface;
19
use Symfony\Component\Validator\Mapping\ClassMetadata;
20
21 1
if (!class_exists('\Eccube\Entity\Member')) {
22
    /**
23
     * Member
24
     *
25
     * @ORM\Table(name="dtb_member")
26
     * @ORM\InheritanceType("SINGLE_TABLE")
27
     * @ORM\DiscriminatorColumn(name="discriminator_type", type="string", length=255)
28
     * @ORM\HasLifecycleCallbacks()
29
     * @ORM\Entity(repositoryClass="Eccube\Repository\MemberRepository")
30
     */
31
    class Member extends \Eccube\Entity\AbstractEntity implements UserInterface, \Serializable
32
    {
33 19
        public static function loadValidatorMetadata(ClassMetadata $metadata)
34
        {
35 19
            $metadata->addConstraint(new UniqueEntity([
36 19
                'fields' => 'login_id',
37 19
                'message' => 'form_error.member_already_exists',
38
            ]));
39
        }
40
41
        /**
42
         * @return string
43
         */
44 1
        public function __toString()
45
        {
46 1
            return (string) $this->getName();
47
        }
48
49
        /**
50
         * {@inheritdoc}
51
         */
52 1
        public function getRoles()
53
        {
54 1
            return ['ROLE_ADMIN'];
55
        }
56
57
        /**
58
         * {@inheritdoc}
59
         */
60 275
        public function getUsername()
61
        {
62 275
            return $this->login_id;
63
        }
64
65
        /**
66
         * {@inheritdoc}
67
         */
68
        public function eraseCredentials()
69
        {
70
        }
71
72
        /**
73
         * @var int
74
         *
75
         * @ORM\Column(name="id", type="integer", options={"unsigned":true})
76
         * @ORM\Id
77
         * @ORM\GeneratedValue(strategy="IDENTITY")
78
         */
79
        private $id;
80
81
        /**
82
         * @var string|null
83
         *
84
         * @ORM\Column(name="name", type="string", length=255, nullable=true)
85
         */
86
        private $name;
87
88
        /**
89
         * @var string|null
90
         *
91
         * @ORM\Column(name="department", type="string", length=255, nullable=true)
92
         */
93
        private $department;
94
95
        /**
96
         * @var string
97
         *
98
         * @ORM\Column(name="login_id", type="string", length=255)
99
         */
100
        private $login_id;
101
102
        /**
103
         * @var string
104
         *
105
         * @ORM\Column(name="password", type="string", length=255)
106
         */
107
        private $password;
108
109
        /**
110
         * @var string
111
         *
112
         * @ORM\Column(name="salt", type="string", length=255, nullable=true)
113
         */
114
        private $salt;
115
116
        /**
117
         * @var int
118
         *
119
         * @ORM\Column(name="sort_no", type="smallint", options={"unsigned":true})
120
         */
121
        private $sort_no;
122
123
        /**
124
         * @var \DateTime
125
         *
126
         * @ORM\Column(name="create_date", type="datetimetz")
127
         */
128
        private $create_date;
129
130
        /**
131
         * @var \DateTime
132
         *
133
         * @ORM\Column(name="update_date", type="datetimetz")
134
         */
135
        private $update_date;
136
137
        /**
138
         * @var \DateTime|null
139
         *
140
         * @ORM\Column(name="login_date", type="datetimetz", nullable=true)
141
         */
142
        private $login_date;
143
144
        /**
145
         * @var \Eccube\Entity\Master\Work
146
         *
147
         * @ORM\ManyToOne(targetEntity="Eccube\Entity\Master\Work")
148
         * @ORM\JoinColumns({
149
         *   @ORM\JoinColumn(name="work_id", referencedColumnName="id")
150
         * })
151
         */
152
        private $Work;
153
154
        /**
155
         * @var \Eccube\Entity\Master\Authority
156
         *
157
         * @ORM\ManyToOne(targetEntity="Eccube\Entity\Master\Authority")
158
         * @ORM\JoinColumns({
159
         *   @ORM\JoinColumn(name="authority_id", referencedColumnName="id")
160
         * })
161
         */
162
        private $Authority;
163
164
        /**
165
         * @var \Eccube\Entity\Member
166
         *
167
         * @ORM\ManyToOne(targetEntity="Eccube\Entity\Member")
168
         * @ORM\JoinColumns({
169
         *   @ORM\JoinColumn(name="creator_id", referencedColumnName="id")
170
         * })
171
         */
172
        private $Creator;
173
174
        /**
175
         * Get id.
176
         *
177
         * @return int
178
         */
179 315
        public function getId()
180
        {
181 315
            return $this->id;
182
        }
183
184
        /**
185
         * Set name.
186
         *
187
         * @param string|null $name
188
         *
189
         * @return Member
190
         */
191 307
        public function setName($name = null)
192
        {
193 307
            $this->name = $name;
194
195 307
            return $this;
196
        }
197
198
        /**
199
         * Get name.
200
         *
201
         * @return string|null
202
         */
203 170
        public function getName()
204
        {
205 170
            return $this->name;
206
        }
207
208
        /**
209
         * Set department.
210
         *
211
         * @param string|null $department
212
         *
213
         * @return Member
214
         */
215 19
        public function setDepartment($department = null)
216
        {
217 19
            $this->department = $department;
218
219 19
            return $this;
220
        }
221
222
        /**
223
         * Get department.
224
         *
225
         * @return string|null
226
         */
227 22
        public function getDepartment()
228
        {
229 22
            return $this->department;
230
        }
231
232
        /**
233
         * Set loginId.
234
         *
235
         * @param string $loginId
236
         *
237
         * @return Member
238
         */
239 313
        public function setLoginId($loginId)
240
        {
241 313
            $this->login_id = $loginId;
242
243 313
            return $this;
244
        }
245
246
        /**
247
         * Get loginId.
248
         *
249
         * @return string
250
         */
251 24
        public function getLoginId()
252
        {
253 24
            return $this->login_id;
254
        }
255
256
        /**
257
         * Set password.
258
         *
259
         * @param string $password
260
         *
261
         * @return Member
262
         */
263 312
        public function setPassword($password)
264
        {
265 312
            $this->password = $password;
266
267 312
            return $this;
268
        }
269
270
        /**
271
         * Get password.
272
         *
273
         * @return string
274
         */
275 290
        public function getPassword()
276
        {
277 290
            return $this->password;
278
        }
279
280
        /**
281
         * Set salt.
282
         *
283
         * @param string $salt
284
         *
285
         * @return Member
286
         */
287 299
        public function setSalt($salt)
288
        {
289 299
            $this->salt = $salt;
290
291 299
            return $this;
292
        }
293
294
        /**
295
         * Get salt.
296
         *
297
         * @return string
298
         */
299 275
        public function getSalt()
300
        {
301 275
            return $this->salt;
302
        }
303
304
        /**
305
         * Set sortNo.
306
         *
307
         * @param int $sortNo
308
         *
309
         * @return Member
310
         */
311 299
        public function setSortNo($sortNo)
312
        {
313 299
            $this->sort_no = $sortNo;
314
315 299
            return $this;
316
        }
317
318
        /**
319
         * Get sortNo.
320
         *
321
         * @return int
322
         */
323 12
        public function getSortNo()
324
        {
325 12
            return $this->sort_no;
326
        }
327
328
        /**
329
         * Set createDate.
330
         *
331
         * @param \DateTime $createDate
332
         *
333
         * @return Member
334
         */
335 299
        public function setCreateDate($createDate)
336
        {
337 299
            $this->create_date = $createDate;
338
339 299
            return $this;
340
        }
341
342
        /**
343
         * Get createDate.
344
         *
345
         * @return \DateTime
346
         */
347
        public function getCreateDate()
348
        {
349
            return $this->create_date;
350
        }
351
352
        /**
353
         * Set updateDate.
354
         *
355
         * @param \DateTime $updateDate
356
         *
357
         * @return Member
358
         */
359 300
        public function setUpdateDate($updateDate)
360
        {
361 300
            $this->update_date = $updateDate;
362
363 300
            return $this;
364
        }
365
366
        /**
367
         * Get updateDate.
368
         *
369
         * @return \DateTime
370
         */
371
        public function getUpdateDate()
372
        {
373
            return $this->update_date;
374
        }
375
376
        /**
377
         * Set loginDate.
378
         *
379
         * @param \DateTime|null $loginDate
380
         *
381
         * @return Member
382
         */
383 1
        public function setLoginDate($loginDate = null)
384
        {
385 1
            $this->login_date = $loginDate;
386
387 1
            return $this;
388
        }
389
390
        /**
391
         * Get loginDate.
392
         *
393
         * @return \DateTime|null
394
         */
395 153
        public function getLoginDate()
396
        {
397 153
            return $this->login_date;
398
        }
399
400
        /**
401
         * Set Work
402
         *
403
         * @param \Eccube\Entity\Master\Work
404
         *
405
         * @return Member
406
         */
407 312
        public function setWork(\Eccube\Entity\Master\Work $work = null)
408
        {
409 312
            $this->Work = $work;
410
411 312
            return $this;
412
        }
413
414
        /**
415
         * Get work.
416
         *
417
         * @return \Eccube\Entity\Master\Work|null
418
         */
419 21
        public function getWork()
420
        {
421 21
            return $this->Work;
422
        }
423
424
        /**
425
         * Set authority.
426
         *
427
         * @param \Eccube\Entity\Master\Authority|null $authority
428
         *
429
         * @return Member
430
         */
431 306
        public function setAuthority(\Eccube\Entity\Master\Authority $authority = null)
432
        {
433 306
            $this->Authority = $authority;
434
435 306
            return $this;
436
        }
437
438
        /**
439
         * Get authority.
440
         *
441
         * @return \Eccube\Entity\Master\Authority|null
442
         */
443 294
        public function getAuthority()
444
        {
445 294
            return $this->Authority;
446
        }
447
448
        /**
449
         * Set creator.
450
         *
451
         * @param \Eccube\Entity\Member|null $creator
452
         *
453
         * @return Member
454
         */
455 294
        public function setCreator(\Eccube\Entity\Member $creator = null)
456
        {
457 294
            $this->Creator = $creator;
458
459 294
            return $this;
460
        }
461
462
        /**
463
         * Get creator.
464
         *
465
         * @return \Eccube\Entity\Member|null
466
         */
467
        public function getCreator()
468
        {
469
            return $this->Creator;
470
        }
471
472
        /**
473
         * String representation of object
474
         * @link http://php.net/manual/en/serializable.serialize.php
475
         * @return string the string representation of the object or null
476
         * @since 5.1.0
477
         */
478
        public function serialize()
479
        {
480
            // see https://symfony.com/doc/2.7/security/entity_provider.html#create-your-user-entity
481
            // MemberRepository::loadUserByUsername() で Work をチェックしているため、ここでは不要
482
            return serialize([
483
                $this->id,
484
                $this->login_id,
485
                $this->password,
486
                $this->salt,
487
            ]);
488
        }
489
490
        /**
491
         * Constructs the object
492
         * @link http://php.net/manual/en/serializable.unserialize.php
493
         * @param string $serialized <p>
494
         * The string representation of the object.
495
         * </p>
496
         * @return void
497
         * @since 5.1.0
498
         */
499
        public function unserialize($serialized)
500
        {
501
            list (
502
                $this->id,
503
                $this->login_id,
504
                $this->password,
505
                $this->salt,
506
            ) = unserialize($serialized);
507
        }
508
    }
509
}
510