4 use Doctrine\Common\Collections\ArrayCollection
;
5 use Doctrine\ORM\Mapping
as ORM
;
9 * @ORM\Table(name="Person", indexes={@ORM\Index(name="authentification_idx", columns={"email", "password"}),
10 * @ORM\Index(name="search_idx", columns={"firstname", "lastname"})});
16 * @ORM\Column(type="bigint")
17 * @ORM\GeneratedValue(strategy="AUTO")
22 * @ORM\Column(type="string")
27 * @ORM\Column(type="string")
32 * @ORM\Column(type="string", unique=true)
37 * @ORM\Column(type="string")
42 * @ORM\Column(type="boolean", options={"default":false})
47 * One person have many friends
48 * @ORM\OneToMany(targetEntity="App\Entity\Friendship", mappedBy="person", cascade={"all"})
53 * One person have many friends
54 * @ORM\OneToMany(targetEntity="App\Entity\Friendship", mappedBy="friend", cascade={"all"})
56 protected $friends_with_me;
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?
64 public function __construct()
66 $this->friends
= new ArrayCollection();
67 $this->friends_with_me
= new ArrayCollection();
70 public function getId()
75 public function getFirstName()
77 return $this->firstname
;
80 public function getLastName()
82 return $this->lastname
;
85 public function getEmail()
90 public function getPassword()
92 return $this->password
;
95 public function getOnline()
100 public function getFriends()
102 return $this->friends
;
105 public function getFriendsWithMe()
107 return $this->friends_with_me
;
110 public function setId($id)
116 public function setFirstName($firstname)
118 $this->firstname
= $firstname;
122 public function setLastName($lastname)
124 $this->lastname
= $lastname;
128 public function setEmail($email)
130 $this->email
= $email;
134 public function setPassword($password)
136 $this->password
= $password;
140 public function setOnline($online)
142 $this->online
= $online;
146 public function addFriendship(Friendship
$friendship)
148 $this->friends
->add($friendship);
149 $friendship->friend
->addFriendshipWithMe($friendship);
152 public function addFriendshipWithMe(Friendship
$friendship)
154 $this->friends_with_me
->add($friendship);
157 public function addFriend(User
$friend)
159 $fs = new Friendship();
160 $fs->setPerson($this);
161 $fs->setFriend($friend);
162 // set defaults validation to true for now
163 $fs->setIsValid(true);
165 $this->addFriendship($fs);