/**
  * @extra:Route("/measuring/{id}",name="_meal_measuring")
  */
 public function measuringAction($id)
 {
     $em = $this->get('doctrine.orm.entity_manager');
     $meal = $em->find('Hector\\FoodServiceBundle\\Entity\\Meal', $id);
     $form = $this->get('form.factory')->createBuilder('form')->add('responsible', 'text')->add('calibrated', 'checkbox', array('required' => false));
     foreach ($meal->getItems() as $item) {
         $form = $form->add(strval($item->getId()), new MeasuringFormType());
     }
     $form = $form->getForm();
     $request = $this->get('request');
     if ($request->getMethod() == 'POST') {
         $form->bindRequest($request);
         if ($form->isValid()) {
             $datetime = new \DateTime();
             foreach ($form->getChildren() as $key => $child) {
                 if (is_object($child->getData()) && get_class($child->getData()) === "Hector\\FoodServiceBundle\\Entity\\Measuring") {
                     $measuring = new Measuring();
                     $measuring->setTemperature($child->getData()->getTemperature());
                     $measuring->setCalibrated($form->get('calibrated')->getData());
                     $measuring->setResponsible($form->get('responsible')->getData());
                     $measuring->setTime($datetime);
                     $measuring->setItem($em->find('Hector\\FoodServiceBundle\\Entity\\Item', (int) $key));
                     $em->persist($measuring);
                 }
             }
             $em->flush();
             $this->get('session')->setFlash('notice', 'Medición realizada correctamente.');
             return $this->redirect($this->generateUrl('_meal_index'));
         }
     }
     return $this->render('HectorFoodServiceBundle:Meal:measuring.html.twig', array('meal' => $meal, 'form' => $form->createView(), 'formName' => $form->getName()));
 }
Esempio n. 2
0
 public function generate($meals, $manager)
 {
     for ($i = 0; $i < 20; $i++) {
         //$int= rand(0,time());
         //$string = date("Y-m-d H:i:s",$int); //totally random
         //$string = strtotime('2011-05-16 '.$i.':30:30');  //not working
         $datetime = new \DateTime('1970-01-01');
         $datetime->add(new \DateInterval('PT' . ($i + 2) . 'H'));
         foreach ($meals as $meal) {
             $measuring = new Measuring();
             $measuring->setCalibrated(false);
             $measuring->setTime($datetime);
             $measuring->setResponsible("Hector Hurtarte");
             $measuring->setTemperature(rand(0, 25));
             $measuring->setItem($meal);
             $manager->persist($measuring);
         }
     }
 }