4 use Doctrine\Common\Collections\ArrayCollection
;
5 use Doctrine\ORM\Mapping
as ORM
;
6 use JMS\Serializer\Annotation
as Serializer
;
10 * @ORM\Table(name="Person", indexes={@ORM\Index(name="authentification_idx", columns={"email", "password"}),
11 * @ORM\Index(name="search_idx", columns={"firstname", "lastname", "email"})});
12 * @Serializer\ExclusionPolicy("all")
18 * @ORM\Column(type="bigint")
19 * @ORM\GeneratedValue(strategy="AUTO")
25 * @ORM\Column(type="string")
31 * @ORM\Column(type="string")
37 * @ORM\Column(type="string", unique=true)
43 * @ORM\Column(type="string")
48 * @ORM\Column(type="boolean", options={"default":false})
54 * One person have many friends
55 * @ORM\OneToMany(targetEntity="App\Entity\Friendship", mappedBy="person")
60 * One person have many friends
61 * @ORM\OneToMany(targetEntity="App\Entity\Friendship", mappedBy="friend")
63 protected $friends_with_me;
66 * [__construct description]
67 * NOTE: Should we forbid reverse pairs (person_id=123 and friend_id=456
68 * can be viewed as the same as person_id=456 and friend_id=123)
69 * if we view friendship as a bidirectionnal association?
71 public function __construct()
73 $this->friends
= new ArrayCollection();
74 $this->friends_with_me
= new ArrayCollection();
77 public function getId()
82 public function getFirstName()
84 return $this->firstname
;
87 public function getLastName()
89 return $this->lastname
;
92 public function getEmail()
97 public function getPassword()
99 return $this->password
;
102 public function getOnline()
104 return $this->online
;
107 public function getFriends()
109 return $this->friends
;
112 public function getFriendsWithMe()
114 return $this->friends_with_me
;
117 public function setId($id)
123 public function setFirstName($firstname)
125 $this->firstname
= $firstname;
129 public function setLastName($lastname)
131 $this->lastname
= $lastname;
135 public function setEmail($email)
137 $this->email
= $email;
141 public function setPassword($password)
143 $this->password
= $password;
147 public function setOnline($online)
149 $this->online
= $online;
153 public function addFriendship(Friendship
$friendship)
155 $this->friends
->add($friendship);
156 $friendship->friend
->addFriendshipWithMe($friendship);
159 public function addFriendshipWithMe(Friendship
$friendship)
161 $this->friends_with_me
->add($friendship);
164 public function addFriend(Person
$friend)
166 $fs = new Friendship();
167 $fs->setPerson($this);
168 $fs->setFriend($friend);
169 // set defaults validation to true for now
170 $fs->setIsValid(true);
172 $this->addFriendship($fs);