/**
  * Load data fixtures with the passed EntityManager
  *
  * @param \Doctrine\Common\Persistence\ObjectManager $manager
  */
 public function load(ObjectManager $manager)
 {
     $trainigDay = $this->getReference('trainingDay');
     $trainigMonday = $this->getReference('trainingMonday');
     $strengthEntry1 = new StrengthTraining();
     $strengthEntry1->setName('Squats');
     $strengthEntry1->setNote('Bli');
     $strengthEntry1->setReruns(10);
     $strengthEntry1->setWeight(30);
     $strengthEntry1->setSets(3);
     $strengthEntry2 = new StrengthTraining();
     $strengthEntry2->setName('Beinpresse');
     $strengthEntry2->setNote('Bla');
     $strengthEntry2->setReruns(15);
     $strengthEntry2->setWeight(60);
     $strengthEntry2->setSets(3);
     $strengthEntry3 = new StrengthTraining();
     $strengthEntry3->setName('Kreuzheben');
     $strengthEntry3->setNote('Blub');
     $strengthEntry3->setReruns(8);
     $strengthEntry3->setWeight(20);
     $strengthEntry3->setSets(4);
     $strengthEntry1->setTrainingDay($trainigDay);
     $strengthEntry2->setTrainingDay($trainigMonday);
     $strengthEntry3->setTrainingDay($trainigMonday);
     $manager->persist($strengthEntry1);
     $manager->persist($strengthEntry2);
     $manager->persist($strengthEntry3);
     $manager->flush();
 }
 /**
  * @Route("/new/{date}")
  * @ParamConverter("date", options={"format": "d-m-Y"})
  * @param Request  $request
  * @param Datetime $date
  *
  * @return \Symfony\Component\HttpFoundation\Request
  */
 public function newAction(Request $request, Datetime $date)
 {
     $form = $this->createForm(TrainingContainerType::class, null, array('data' => array('date' => $date, 'route_back' => $request->getHost() . $this->generateUrl('trainingschedule_overview_index', array(), UrlGeneratorInterface::ABSOLUTE_PATH)), 'required' => false));
     /** @var UsernamePasswordToken $token */
     $token = $this->container->get('security.token_storage')->getToken();
     if ($request->isMethod(Request::METHOD_POST)) {
         $form->handleRequest($request);
         if ($form->isValid()) {
             $data = $form->getData();
             /** @var TrainingDayRepository $repository */
             $repository = $this->getDoctrine()->getManager()->getRepository('TrainingScheduleBundle:TrainingDay');
             $trainingDay = $repository->findOneBy(array('date' => $data['date'], 'user' => $token->getUser()));
             if (is_null($trainingDay)) {
                 $trainingDay = new TrainingDay();
                 $trainingDay->setDate($data['date']);
                 $trainingDay->setUser($token->getUser());
                 $this->getDoctrine()->getManager()->persist($trainingDay);
             }
             if ($data['Training']['type'] == EnduranceTraining::__className()) {
                 /** @var EnduranceTraining $enduranceTraining */
                 $enduranceTraining = $data['Training']['enduranceTraining'];
                 $enduranceTraining->setName($data['Training']['name']);
                 $enduranceTraining->setNote($data['Training']['note']);
                 $enduranceTraining->setTrainingDay($trainingDay);
                 $this->getDoctrine()->getManager()->persist($enduranceTraining);
             }
             if ($data['Training']['type'] == StrengthTraining::__className()) {
                 /** @var StrengthTraining $strengthTraining */
                 $strengthTraining = $data['Training']['strengthTraining'];
                 $strengthTraining->setName($data['Training']['name']);
                 $strengthTraining->setNote($data['Training']['note']);
                 $strengthTraining->setTrainingDay($trainingDay);
                 $this->getDoctrine()->getManager()->persist($strengthTraining);
             }
             $this->getDoctrine()->getManager()->flush();
             return $this->redirectToRoute('trainingschedule_overview_index');
         }
     }
     // generate suggestion for last weekday
     $weekDaySuggestions = TrainingHelper::generateWeekDaySuggestion($this->getDoctrine()->getManager(), $date, $token->getUser());
     // generate suggestion for last entries
     $ownTrainingSuggestions = TrainingHelper::generateOwnTrainingSuggestion($this->getDoctrine()->getManager(), $date, $token->getUser());
     return $this->render('TrainingScheduleBundle:Training:new.html.twig', array('form' => $form->createView(), 'weekDaySuggestions' => $weekDaySuggestions, 'ownTrainingSuggestions' => $ownTrainingSuggestions));
 }
 /**
  * @param FormBuilderInterface $builder
  * @param array                $options
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $tmpo = "dad";
     $tmpo = $tmpo;
     $builder->add('name', TextType::class, array('attr' => array('class' => 'form-control')))->add('type', ChoiceType::class, array('choices' => array(StrengthTraining::__className() => 'StrengthTraining', EnduranceTraining::__className() => 'EnduranceTraining'), 'data' => StrengthTraining::__className(), 'attr' => array('class' => 'form-control')))->add('note', TextType::class, array('attr' => array('class' => 'form-control')))->add('enduranceTraining', EnduranceTrainingType::class, array('label' => false, 'attr' => array('style' => 'display:none;', 'class' => 'EnduranceTraining')))->add('strengthTraining', StrengthTrainingType::class, array('label' => false, 'attr' => array('class' => 'StrengthTraining')));
 }