/** * @param Bundle $bundle * @param Developer $developer */ public function manageBundleRecommendation(Bundle $bundle, Developer $developer) { if ($developer->isUsingBundle($bundle)) { $activity = $this->entityManager->getRepository('Knp\\Bundle\\KnpBundlesBundle\\Entity\\Activity')->findOneBy(array('type' => Activity::ACTIVITY_TYPE_RECOMMEND, 'bundle' => $bundle, 'developer' => $developer)); if ($activity) { $this->entityManager->remove($activity); } $bundle->removeRecommender($developer); } else { $activity = new Activity(); $activity->setType(Activity::ACTIVITY_TYPE_RECOMMEND); $activity->setBundle($bundle); $activity->setDeveloper($developer); $this->entityManager->persist($activity); $bundle->addRecommender($developer); } $this->entityManager->persist($bundle); $this->entityManager->flush(); }