1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AppBundle\Entity; |
4
|
|
|
|
5
|
|
|
use FOS\UserBundle\Model\User as BaseUser; |
6
|
|
|
use Doctrine\ORM\Mapping as ORM; |
7
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
8
|
|
|
use AppBundle\Entity\Poll; |
9
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @ORM\Entity |
13
|
|
|
* @ORM\Table(name="users") |
14
|
|
|
*/ |
15
|
|
|
class User extends BaseUser |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @ORM\Id |
19
|
|
|
* @ORM\Column(type="integer") |
20
|
|
|
* @ORM\GeneratedValue(strategy="AUTO") |
21
|
|
|
*/ |
22
|
|
|
protected $id; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @ORM\ManyToMany(targetEntity="AppBundle\Entity\Group") |
26
|
|
|
* @ORM\JoinTable(name="fos_user_user_group", |
27
|
|
|
* joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")}, |
28
|
|
|
* inverseJoinColumns={@ORM\JoinColumn(name="group_id", referencedColumnName="id")} |
29
|
|
|
* ) |
30
|
|
|
*/ |
31
|
|
|
protected $groups; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @ORM\OneToMany(targetEntity="Poll", mappedBy="creator") |
35
|
|
|
*/ |
36
|
|
|
private $createdPolls; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @ORM\Column(type="string") |
40
|
|
|
*/ |
41
|
|
|
protected $name; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @ORM\OneToMany(targetEntity="Vote", mappedBy="caster") |
45
|
|
|
*/ |
46
|
|
|
private $votes; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Constructor |
50
|
|
|
*/ |
51
|
|
|
public function __construct() |
52
|
|
|
{ |
53
|
|
|
parent::__construct(); |
54
|
|
|
|
55
|
|
|
$this->createdPolls = new ArrayCollection(); |
56
|
|
|
$this->votes = new ArrayCollection(); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Set name |
61
|
|
|
* |
62
|
|
|
* @param string $name |
63
|
|
|
* |
64
|
|
|
* @return Poll |
65
|
|
|
*/ |
66
|
|
|
public function setName(string $name) |
67
|
|
|
{ |
68
|
|
|
$this->name = $name; |
69
|
|
|
|
70
|
|
|
return $this; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Get name |
75
|
|
|
* |
76
|
|
|
* @return string |
77
|
|
|
*/ |
78
|
|
|
public function getName(): string |
79
|
|
|
{ |
80
|
|
|
return $this->name; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Add createdPoll |
85
|
|
|
* |
86
|
|
|
* @param \AppBundle\Entity\Poll $createdPoll |
87
|
|
|
* |
88
|
|
|
* @return User |
89
|
|
|
*/ |
90
|
|
|
public function addCreatedPoll(Poll $createdPoll) |
91
|
|
|
{ |
92
|
|
|
$this->createdPolls[] = $createdPoll; |
93
|
|
|
|
94
|
|
|
return $this; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Remove createdPoll |
99
|
|
|
* |
100
|
|
|
* @param \AppBundle\Entity\Poll $createdPoll |
101
|
|
|
*/ |
102
|
|
|
public function removeCreatedPoll(Poll $createdPoll) |
103
|
|
|
{ |
104
|
|
|
$this->createdPolls->removeElement($createdPoll); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Get createdPolls |
109
|
|
|
* |
110
|
|
|
* @return \Doctrine\Common\Collections\Collection |
111
|
|
|
*/ |
112
|
|
|
public function getCreatedPolls() |
113
|
|
|
{ |
114
|
|
|
return $this->createdPolls; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Add vote |
119
|
|
|
* |
120
|
|
|
* @param \AppBundle\Entity\Vote $vote |
121
|
|
|
* |
122
|
|
|
* @return User |
123
|
|
|
*/ |
124
|
|
|
public function addVote(Vote $vote) |
125
|
|
|
{ |
126
|
|
|
$this->votes[] = $vote; |
127
|
|
|
|
128
|
|
|
return $this; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* Remove vote |
133
|
|
|
* |
134
|
|
|
* @param \AppBundle\Entity\Vote $vote |
135
|
|
|
*/ |
136
|
|
|
public function removeVote(Vote $vote) |
137
|
|
|
{ |
138
|
|
|
$this->votes->removeElement($vote); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* Get votes |
143
|
|
|
* |
144
|
|
|
* @return \Doctrine\Common\Collections\Collection |
145
|
|
|
*/ |
146
|
|
|
public function getVotes() |
147
|
|
|
{ |
148
|
|
|
return $this->votes; |
149
|
|
|
} |
150
|
|
|
} |
151
|
|
|
|