/** * Fonction d'ajout de catégorie aux abonnements user * * Ajoute une categorie aux abonnements catégories d'un utilisateur * * @param array $user Entité User * @param array $category Entité Category * * @return void */ public function addAboCategory($user, $category) { $abonnement = $this->em->getRepository("CentraleLilleNewsFeedBundle:Abonnement"); if (!$abonnement->findOneBy(array('user' => $user))) { $abonnement = new Abonnement(); $abonnement->setUser($user); $abonnement->setCategories($category); } else { $abonnement = $abonnement->findOneBy(array('user' => $user)); $abonnement->addCategory($category); } $this->em->persist($abonnement); $this->em->flush(); return $this; }