/**
  * Train monitor
  *
  * @author Mfana Ronald Conco <*****@*****.**>
  * @param Request $request
  * @param Train $train
  * @ParamConverter("train", class="MlankaTechAppBundle:Train", options={"slug" = "slug"})
  * @Secure(roles="ROLE_TRAIN_MONITOR")
  * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
  */
 public function monitorAction(Request $request, Train $train)
 {
     $this->get('logger')->info('TrainController  profileAction()');
     $motorCoaches = array();
     foreach ($train->getMotorcoaches() as $motorCoach) {
         $motorCoaches[] = $motorCoach->getUnit();
     }
     return $this->render('MlankaTechAppBundle:Train:monitor.html.twig', array('action' => 'train_monitor', 'train' => $train, 'page_header' => 'Train monitor', 'breadcrumb' => 'Monitor', 'motorCoaches' => $motorCoaches));
 }
 /**
  * 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;
 }