Commit | Line | Data |
---|---|---|
dec6d031 JB |
1 | <?php |
2 | namespace App\Entity; | |
3 | ||
4 | use Doctrine\Common\Collections\ArrayCollection; | |
5 | use Doctrine\ORM\Mapping as ORM; | |
c3bce7b6 JB |
6 | use JMS\Serializer\Annotation\ExclusionPolicy; |
7 | use JMS\Serializer\Annotation\Expose; | |
dec6d031 JB |
8 | |
9 | /** | |
10 | * @ORM\Entity() | |
11 | * @ORM\Table(name="Person", indexes={@ORM\Index(name="authentification_idx", columns={"email", "password"}), | |
c3bce7b6 | 12 | * @ORM\Index(name="search_idx", columns={"firstname", "lastname", "email"})}); |
dec6d031 JB |
13 | */ |
14 | class Person | |
15 | { | |
16 | /** | |
17 | * @ORM\Id | |
18 | * @ORM\Column(type="bigint") | |
19 | * @ORM\GeneratedValue(strategy="AUTO") | |
20 | */ | |
21 | protected $id; | |
22 | ||
23 | /** | |
24 | * @ORM\Column(type="string") | |
25 | */ | |
26 | protected $firstname; | |
27 | ||
28 | /** | |
29 | * @ORM\Column(type="string") | |
30 | */ | |
31 | protected $lastname; | |
32 | ||
33 | /** | |
34 | * @ORM\Column(type="string", unique=true) | |
35 | */ | |
36 | protected $email; | |
37 | ||
38 | /** | |
39 | * @ORM\Column(type="string") | |
40 | */ | |
41 | protected $password; | |
42 | ||
43 | /** | |
44 | * @ORM\Column(type="boolean", options={"default":false}) | |
45 | */ | |
46 | protected $online; | |
47 | ||
48 | /** | |
49 | * One person have many friends | |
50 | * @ORM\OneToMany(targetEntity="App\Entity\Friendship", mappedBy="person", cascade={"all"}) | |
51 | */ | |
52 | protected $friends; | |
53 | ||
54 | /** | |
55 | * One person have many friends | |
56 | * @ORM\OneToMany(targetEntity="App\Entity\Friendship", mappedBy="friend", cascade={"all"}) | |
57 | */ | |
58 | protected $friends_with_me; | |
59 | ||
60 | /** | |
61 | * [__construct description] | |
62 | * NOTE: Should we forbid reverse pairs (person_id=123 and friend_id=456 | |
63 | * can be viewed as the same as person_id=456 and friend_id=123) | |
64 | * if we view friendship as a bidirectionnal association? | |
65 | */ | |
66 | public function __construct() | |
67 | { | |
68 | $this->friends = new ArrayCollection(); | |
69 | $this->friends_with_me = new ArrayCollection(); | |
70 | } | |
71 | ||
72 | public function getId() | |
73 | { | |
74 | return $this->id; | |
75 | } | |
76 | ||
77 | public function getFirstName() | |
78 | { | |
79 | return $this->firstname; | |
80 | } | |
81 | ||
82 | public function getLastName() | |
83 | { | |
84 | return $this->lastname; | |
85 | } | |
86 | ||
87 | public function getEmail() | |
88 | { | |
89 | return $this->email; | |
90 | } | |
91 | ||
92 | public function getPassword() | |
93 | { | |
94 | return $this->password; | |
95 | } | |
96 | ||
97 | public function getOnline() | |
98 | { | |
99 | return $this->online; | |
100 | } | |
101 | ||
102 | public function getFriends() | |
103 | { | |
104 | return $this->friends; | |
105 | } | |
106 | ||
107 | public function getFriendsWithMe() | |
108 | { | |
109 | return $this->friends_with_me; | |
110 | } | |
111 | ||
112 | public function setId($id) | |
113 | { | |
114 | $this->id = $id; | |
115 | return $this; | |
116 | } | |
117 | ||
118 | public function setFirstName($firstname) | |
119 | { | |
120 | $this->firstname = $firstname; | |
121 | return $this; | |
122 | } | |
123 | ||
124 | public function setLastName($lastname) | |
125 | { | |
126 | $this->lastname = $lastname; | |
127 | return $this; | |
128 | } | |
129 | ||
130 | public function setEmail($email) | |
131 | { | |
132 | $this->email = $email; | |
133 | return $this; | |
134 | } | |
135 | ||
136 | public function setPassword($password) | |
137 | { | |
138 | $this->password = $password; | |
139 | return $this; | |
140 | } | |
141 | ||
142 | public function setOnline($online) | |
143 | { | |
144 | $this->online = $online; | |
145 | return $this; | |
146 | } | |
147 | ||
148 | public function addFriendship(Friendship $friendship) | |
149 | { | |
150 | $this->friends->add($friendship); | |
151 | $friendship->friend->addFriendshipWithMe($friendship); | |
152 | } | |
153 | ||
154 | public function addFriendshipWithMe(Friendship $friendship) | |
155 | { | |
156 | $this->friends_with_me->add($friendship); | |
157 | } | |
158 | ||
d68c2073 | 159 | public function addFriend(Person $friend) |
dec6d031 JB |
160 | { |
161 | $fs = new Friendship(); | |
162 | $fs->setPerson($this); | |
163 | $fs->setFriend($friend); | |
164 | // set defaults validation to true for now | |
165 | $fs->setIsValid(true); | |
166 | ||
167 | $this->addFriendship($fs); | |
168 | } | |
169 | } |