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