4 use Doctrine\Common\Collections\ArrayCollection
;
5 use Doctrine\ORM\Mapping
as ORM
;
6 use JMS\Serializer\Annotation\ExclusionPolicy
;
7 use JMS\Serializer\Annotation\Expose
;
11 * @ORM\Table(name="Person", indexes={@ORM\Index(name="authentification_idx", columns={"email", "password"}),
12 * @ORM\Index(name="search_idx", columns={"firstname", "lastname", "email"})});
13 * The following annotations tells the serializer to skip all properties which
14 * have not marked with @Expose.
16 * @ExclusionPolicy("all")
22 * @ORM\Column(type="bigint")
23 * @ORM\GeneratedValue(strategy="AUTO")
28 * @ORM\Column(type="string")
33 * @ORM\Column(type="string")
38 * @ORM\Column(type="string", unique=true)
43 * @ORM\Column(type="string")
48 * @ORM\Column(type="boolean", options={"default":false})
53 * One person have many friends
54 * @ORM\OneToMany(targetEntity="App\Entity\Friendship", mappedBy="person", cascade={"all"})
59 * One person have many friends
60 * @ORM\OneToMany(targetEntity="App\Entity\Friendship", mappedBy="friend", cascade={"all"})
62 protected $friends_with_me;
65 * [__construct description]
66 * NOTE: Should we forbid reverse pairs (person_id=123 and friend_id=456
67 * can be viewed as the same as person_id=456 and friend_id=123)
68 * if we view friendship as a bidirectionnal association?
70 public function __construct()
72 $this->friends
= new ArrayCollection();
73 $this->friends_with_me
= new ArrayCollection();
76 public function getId()
81 public function getFirstName()
83 return $this->firstname
;
86 public function getLastName()
88 return $this->lastname
;
91 public function getEmail()
96 public function getPassword()
98 return $this->password
;
101 public function getOnline()
103 return $this->online
;
106 public function getFriends()
108 return $this->friends
;
111 public function getFriendsWithMe()
113 return $this->friends_with_me
;
116 public function setId($id)
122 public function setFirstName($firstname)
124 $this->firstname
= $firstname;
128 public function setLastName($lastname)
130 $this->lastname
= $lastname;
134 public function setEmail($email)
136 $this->email
= $email;
140 public function setPassword($password)
142 $this->password
= $password;
146 public function setOnline($online)
148 $this->online
= $online;
152 public function addFriendship(Friendship
$friendship)
154 $this->friends
->add($friendship);
155 $friendship->friend
->addFriendshipWithMe($friendship);
158 public function addFriendshipWithMe(Friendship
$friendship)
160 $this->friends_with_me
->add($friendship);
163 public function addFriend(Person
$friend)
165 $fs = new Friendship();
166 $fs->setPerson($this);
167 $fs->setFriend($friend);
168 // set defaults validation to true for now
169 $fs->setIsValid(true);
171 $this->addFriendship($fs);