public function updateAction() { if ($this->getRequest()->get('save_new') != null) { $repository = $this->getDoctrine()->getRepository('ElmetSiteBundle:CurtainPriceBand'); $curtainPriceBand = $repository->findOneById($this->getRequest()->get('priceband_new')); $cushionCover = new CushionCover(); $cushionCover->setCurtainPriceBand($curtainPriceBand); $cushionCover->setSize($this->getRequest()->get('size_new')); $cushionCover->setPrice($this->getRequest()->get('price_new')); $cushionCover->setFinish(""); $em = $this->getDoctrine()->getEntityManager(); $em->persist($cushionCover); $em->flush(); } else { if ($this->getRequest()->get('submit_all') != null) { $ccRepository = $this->getDoctrine()->getRepository('ElmetSiteBundle:CushionCover'); $priceBandRepository = $this->getDoctrine()->getRepository('ElmetSiteBundle:CurtainPriceBand'); $cushionCovers = $ccRepository->findAll(); foreach ($cushionCovers as $cushionCover) { $curtainPriceBand = $priceBandRepository->findOneById($this->getRequest()->get('all:priceband_' . $cushionCover->getId())); $cushionCover->setCurtainPriceBand($curtainPriceBand); $cushionCover->setSize($this->getRequest()->get('all:size_' . $cushionCover->getId())); $cushionCover->setPrice($this->getRequest()->get('all:price_' . $cushionCover->getId())); $em = $this->getDoctrine()->getEntityManager(); $em->merge($cushionCover); } $em->flush(); } else { $params = $this->getRequest()->request->all(); $keys = array_keys($params); $cc_id = 0; foreach ($keys as $key) { $param = $params[$key]; if ($param == 'Save') { $index = stripos($key, '_'); $cc_id = substr($key, $index + 1); } } if ($cc_id != 0) { $repository = $this->getDoctrine()->getRepository('ElmetSiteBundle:CushionCover'); $cushionCover = $repository->findOneById($cc_id); $repository = $this->getDoctrine()->getRepository('ElmetSiteBundle:CurtainPriceBand'); $curtainPriceBand = $repository->findOneById($this->getRequest()->get('single:priceband_' . $cc_id)); $cushionCover->setCurtainPriceBand($curtainPriceBand); $cushionCover->setSize($this->getRequest()->get('single:size_' . $cc_id)); $cushionCover->setPrice($this->getRequest()->get('single:price_' . $cc_id)); $em = $this->getDoctrine()->getEntityManager(); $em->merge($cushionCover); $em->flush(); } } } return $this->viewAction(); }
public function createSecondCushionCover() { $curtainPriceBand = $this->cpbRepository->findOneById(2); $cushionCover = new CushionCover(); $cushionCover->setCurtainPriceBand($curtainPriceBand); $cushionCover->setSize("18\" X 18\""); $cushionCover->setPrice(130.95); $cushionCover->setFinish("Shiny"); $this->em->persist($cushionCover); $this->em->flush(); return $cushionCover; }