/** * Create train * * @param \MlankaTech\AppBundle\Entity\Train $train * @return \MlankaTech\AppBundle\Entity\Train */ public function create(\MlankaTech\AppBundle\Entity\Train $train) { $this->logger->info("Service TrainManager create()"); $train->setStatus($this->sm->active()); $train->setCondition($this->conditionManager->unknown()); if ($this->getCurrentUser()) { $train->setCreatedBy($this->getCurrentUser()); } else { $train->setCreatedBy(NULL); } $this->em->persist($train); $this->em->flush(); /** * Mark motor coach as assigned */ $motorCoaches = $train->getMotorcoaches(); if (!$motorCoaches->isEmpty()) { foreach ($motorCoaches as $coach) { $coach->setTrain($train); $coach->setAssigned(true); $coach->setStatus($this->sm->offline()); $this->eventDispatcher->dispatch(MotorCoachEvents::ASSIGNED_TO_TRAIN, new MotorCoachEvent($coach)); } } return $train; }