/** * Fonction chargeants les données d'abonnements * * @param ObjectManager $manager Manager de Fixtures * * @return void */ public function load(ObjectManager $manager) { $abonnement1 = new Abonnement(); $abonnement2 = new Abonnement(); $abonnement3 = new Abonnement(); $abonnement1->setUser($this->getReference('user-martin')); $abonnement1->addCategory($this->getReference('category-meca')); $abonnement1->addCategory($this->getReference('category-ardu')); $abonnement1->addCategory($this->getReference('category-cao')); $abonnement1->addProject($this->getReference('projet-charles')); $abonnement1->addProject($this->getReference('projet-gregoire')); $abonnement2->setUser($this->getReference('user-charles')); $abonnement2->addCategory($this->getReference('category-meca')); $abonnement2->addCategory($this->getReference('category-ardu')); $abonnement2->addCategory($this->getReference('category-cao')); $abonnement2->addProject($this->getReference('projet-martin')); $abonnement2->addProject($this->getReference('projet-gregoire')); $abonnement3->setUser($this->getReference('user-gregoire')); $abonnement3->addCategory($this->getReference('category-laser')); $abonnement3->addCategory($this->getReference('category-info')); $abonnement3->addCategory($this->getReference('category-soud')); $abonnement3->addProject($this->getReference('projet-charles')); $abonnement3->addProject($this->getReference('projet-martin')); $manager->persist($abonnement1); $manager->persist($abonnement2); $manager->persist($abonnement3); $manager->flush(); }
/** * Fonction d'ajout de projet aux abonnements user * * Ajoute un projets aux abonnements projets d'un utilisateur * * @param array $user Entité User * @param array $projet Entité Projet * * @return void */ public function addAboProjet($user, $projet) { $abonnement = $this->em->getRepository("CentraleLilleNewsFeedBundle:Abonnement"); if (!$abonnement->findOneBy(array('user' => $user))) { $abonnement = new Abonnement(); $abonnement->setUser($user); $abonnement->setProjects($projet); } else { $abonnement = $abonnement->findOneBy(array('user' => $user)); $abonnement->addProject($projet); } $this->em->persist($abonnement); $this->em->flush(); return $this; }
/** * Fonction de recherche de tous les abonnements d'un user * * Retourne un tableau des projets auxquels est abonné un user * en comprenant également ceux des catégories auxquelles il est abonné * * @param array $user Entité User * * @return array $projets */ public function getAboAll($user) { $projets = []; $abonnement = $this->em->getRepository("CentraleLilleNewsFeedBundle:Abonnement"); if (!$abonnement->findOneBy(array('user' => $user))) { $abonnement = new Abonnement(); $abonnement->setUser($user); $this->em->persist($abonnement); $this->em->flush(); } else { $aboCategories = $this->getAboCategory($user); $aboProjets = $this->getAboProjet($user); foreach ($aboProjets as $aboProjet) { array_push($projets, $aboProjet); } foreach ($aboCategories as $aboCategory) { $projetsCat = $this->em->getRepository('CentraleLilleNewsFeedBundle:Category')->findOneBy(array('name' => $aboCategory->getName()))->getProjects(); foreach ($projetsCat as $projetCat) { if (!in_array($projetCat, $projets)) { array_push($projets, $projetCat); } } } } return $projets; }