/** * @Route("/{id}", name="admin_start", defaults={"id": null}) */ public function indexAction(Request $request, City $city = null) { $manager = $this->getDoctrine()->getManager(); if ($request->isMethod('POST')) { $learnerConnectionRequest = $this->getConnectionRequestRepository()->find($request->request->getInt('learner')); $fluentSpeakerConnectionRequest = $this->getConnectionRequestRepository()->find($request->request->getInt('fluentSpeaker')); if ($this->getConnectionRepository()->findForUsers($learnerConnectionRequest->getUser(), $fluentSpeakerConnectionRequest->getUser())) { $this->addFlash('error', sprintf('Personerna %s och %s har redan kopplats ihop tidigare', $learnerConnectionRequest->getUser()->getName(), $fluentSpeakerConnectionRequest->getUser()->getName())); } else { $connection = new Connection($this->getUser()); $connection->setLearner($learnerConnectionRequest->getUser()); $connection->setFluentSpeaker($fluentSpeakerConnectionRequest->getUser()); $connection->setCity($learnerConnectionRequest->getCity()); $connection->setFluentSpeakerComment($fluentSpeakerConnectionRequest->getComment()); $connection->setLearnerComment($learnerConnectionRequest->getComment()); $manager->persist($connection); $manager->remove($learnerConnectionRequest); $manager->remove($fluentSpeakerConnectionRequest); $manager->flush(); $this->get('event_dispatcher')->dispatch(DomainEvents::CONNECTION_CREATED, new ConnectionCreatedEvent($connection)); $this->addFlash('info', sprintf('En koppling skapades melland %s och %s', $learnerConnectionRequest->getUser()->getName(), $fluentSpeakerConnectionRequest->getUser()->getName())); } return $this->redirect($this->generateUrl('admin_start')); } if (!$city) { $city = $this->getCityRepository()->findAll()[0]; } $learners = $this->getConnectionRequestRepository()->findBy(['wantToLearn' => true, 'city' => $city]); $fluentSpeakers = $this->getConnectionRequestRepository()->findBy(['wantToLearn' => false, 'city' => $city]); $cities = $this->getCityRepository()->findAll(); $parameters = ['categories' => $this->getCategoryRepository()->findAll(), 'learners' => $learners, 'fluentSpeakers' => $fluentSpeakers, 'cities' => $cities, 'city' => $city]; return $this->render('admin/default/index.html.twig', $parameters); }
/** * @param ObjectManager $manager */ protected function loadConnections(ObjectManager $manager) { foreach (range(1, 25) as $i) { $connection = new Connection(); $connection->setCity($this->getReference('city-1')); $connection->setFluentSpeaker($this->getReference('user-fluentspeaker')); $connection->setLearner($this->getReference('user-learner')); $manager->persist($connection); } }