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")
29 * @ORM\Column(type="string")
35 * @ORM\Column(type="string")
41 * @ORM\Column(type="string", unique=true)
47 * @ORM\Column(type="string")
53 * @ORM\Column(type="boolean", options={"default":false})
59 * One person have many friends
60 * @ORM\OneToMany(targetEntity="App\Entity\Friendship", mappedBy="person", cascade={"all"})
65 * One person have many friends
66 * @ORM\OneToMany(targetEntity="App\Entity\Friendship", mappedBy="friend", cascade={"all"})
68 protected $friends_with_me;
71 * [__construct description]
72 * NOTE: Should we forbid reverse pairs (person_id=123 and friend_id=456
73 * can be viewed as the same as person_id=456 and friend_id=123)
74 * if we view friendship as a bidirectionnal association?
76 public function __construct()
78 $this->friends
= new ArrayCollection();
79 $this->friends_with_me
= new ArrayCollection();
82 public function getId()
87 public function getFirstName()
89 return $this->firstname
;
92 public function getLastName()
94 return $this->lastname
;
97 public function getEmail()
102 public function getPassword()
104 return $this->password
;
107 public function getOnline()
109 return $this->online
;
112 public function getFriends()
114 return $this->friends
;
117 public function getFriendsWithMe()
119 return $this->friends_with_me
;
122 public function setId($id)
128 public function setFirstName($firstname)
130 $this->firstname
= $firstname;
134 public function setLastName($lastname)
136 $this->lastname
= $lastname;
140 public function setEmail($email)
142 $this->email
= $email;
146 public function setPassword($password)
148 $this->password
= $password;
152 public function setOnline($online)
154 $this->online
= $online;
158 public function addFriendship(Friendship
$friendship)
160 $this->friends
->add($friendship);
161 $friendship->friend
->addFriendshipWithMe($friendship);
164 public function addFriendshipWithMe(Friendship
$friendship)
166 $this->friends_with_me
->add($friendship);
169 public function addFriend(Person
$friend)
171 $fs = new Friendship();
172 $fs->setPerson($this);
173 $fs->setFriend($friend);
174 // set defaults validation to true for now
175 $fs->setIsValid(true);
177 $this->addFriendship($fs);