/** * Load data fixtures with the passed EntityManager * * @param \Doctrine\Common\Persistence\ObjectManager $manager */ public function load(ObjectManager $manager) { $user = $this->getReference('user1'); $trainigDay = new TrainingDay(); $trainigDay->setDate(new \DateTime()); $trainigDay->setUser($user); $dateMonday = new \DateTime(); $dateMonday->modify('last monday'); $trainigMonday = new TrainingDay(); $trainigMonday->setDate($dateMonday); $trainigMonday->setUser($user); $enduranceTraining = new EnduranceTraining(); $enduranceTraining->setName('Joggen'); $enduranceTraining->setLength(45); $enduranceTraining->setNote('Bli'); $enduranceTraining2 = new EnduranceTraining(); $enduranceTraining2->setName('Schwimmen'); $enduranceTraining2->setLength(100); $enduranceTraining2->setNote('Bla'); $enduranceTraining3 = new EnduranceTraining(); $enduranceTraining3->setName('Laufen'); $enduranceTraining3->setLength(150); $enduranceTraining3->setNote('Blub'); $enduranceTraining->setTrainingDay($trainigDay); $enduranceTraining2->setTrainingDay($trainigDay); $enduranceTraining3->setTrainingDay($trainigMonday); $manager->persist($trainigDay); $manager->persist($trainigMonday); $manager->persist($enduranceTraining); $manager->persist($enduranceTraining2); $manager->persist($enduranceTraining3); $manager->flush(); $this->addReference('trainingDay', $trainigDay); $this->addReference('trainingMonday', $trainigMonday); }
/** * @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'))); }