Ejemplo n.º 1
0
 public function createSecondCEPB()
 {
     $curtainEyeletPriceBand = new CurtainEyeletPriceBand();
     $curtainEyeletPriceBand->setCurtainSize("152\"");
     $curtainEyeletPriceBand->setPrice(130.95);
     $this->em->persist($curtainEyeletPriceBand);
     $this->em->flush();
     return $curtainEyeletPriceBand;
 }
 public function updateAction()
 {
     if ($this->getRequest()->get('save_new') != null) {
         $cepb = new CurtainEyeletPriceBand();
         $cepb->setCurtainSize($this->getRequest()->get('size_new'));
         $cepb->setPrice($this->getRequest()->get('price_new'));
         $em = $this->getDoctrine()->getEntityManager();
         $em->persist($cepb);
         $em->flush();
     } else {
         if ($this->getRequest()->get('submit_all') != null) {
             $repository = $this->getDoctrine()->getRepository('ElmetSiteBundle:CurtainEyeletPriceBand');
             $cepbs = $repository->findAll();
             foreach ($cepbs as $cepb) {
                 $cepb->setCurtainSize($this->getRequest()->get('all:size_' . $cepb->getId()));
                 $cepb->setPrice($this->getRequest()->get('all:price_' . $cepb->getId()));
                 $em = $this->getDoctrine()->getEntityManager();
                 $em->merge($cepb);
             }
             $em->flush();
         } else {
             $params = $this->getRequest()->request->all();
             $keys = array_keys($params);
             $id = 0;
             foreach ($keys as $key) {
                 $param = $params[$key];
                 if ($param == 'Save') {
                     $index = stripos($key, '_');
                     $id = substr($key, $index + 1);
                 }
             }
             if ($id != 0) {
                 $repository = $this->getDoctrine()->getRepository('ElmetSiteBundle:CurtainEyeletPriceBand');
                 $cepb = $repository->findOneById($id);
                 $cepb->setCurtainSize($this->getRequest()->get('single:size_' . $id));
                 $cepb->setPrice($this->getRequest()->get('single:price_' . $id));
                 $em = $this->getDoctrine()->getEntityManager();
                 $em->merge($cepb);
                 $em->flush();
             }
         }
     }
     return $this->viewAction();
 }