em = $em ; } public function isUserLinkedToPointSale(UserInterface $user, PointSaleInterface $pointSale) { foreach($user->getUserPointSales() as $userPointSale) { if($userPointSale->getPointSale()->getId() == $pointSale->getId()) { return true ; } } return false ; } public function linkUserToPointSale(UserInterface $user, PointSaleInterface $pointSale) { if(!$this->isUserLinkedToPointSale($user, $pointSale)) { $userPointSaleClass = $this->em->getClassMetadata(UserPointSaleInterface::class)->getName(); $userPointSale = new $userPointSaleClass ; $userPointSale->setUser($user) ; $userPointSale->setPointSale($pointSale) ; $this->em->persist($userPointSale); $this->em->flush() ; } } }