/** * @Route("/save", name="banner_config_save") * @Method("POST") * @Template() */ public function saveAction(Request $request) { /** @var $tr \Symfony\Component\Translation\Translator */ $tr = $this->get('translator'); $newBannerIds = $request->get('newBanners'); $probabilities = $request->get('probability'); $zoneId = $request->get('zoneId'); if (!is_array($newBannerIds)) { throw new \Exception('invalid banner ID\'s'); } /** @var $em \Doctrine\ORM\EntityManager */ $em = $this->get('doctrine.orm.entity_manager'); $zonesRepository = $em->getRepository('HyperAdsBundle:Zone'); /** @var $bannersRepository \Hyper\AdsBundle\Entity\BannerRepository */ $bannersRepository = $em->getRepository('HyperAdsBundle:Banner'); /** @var $zone \Hyper\AdsBundle\Entity\Zone */ $zone = $zonesRepository->find($zoneId); if (empty($zone)) { throw $this->createNotFoundException($tr->trans('zone.not.exists', array(), 'HyperAdsBundle')); } /** @var $banners \Hyper\AdsBundle\Entity\Banner[] */ $banners = $bannersRepository->findBy(array('id' => $newBannerIds)); $referenceUpdater = new ReferencesUpdater($em); $referenceUpdater->setZone($zone); $referenceUpdater->setProbabilities($probabilities); $referenceUpdater->setBanners($banners); $referenceUpdater->updateReferences(); return $this->redirect($this->generateUrl('admin_zone_show', array('id' => $zoneId))); }
/** * @Route("/save", name="banner_config_save") * @Method("POST") * @Template() */ public function saveAction(Request $request) { $fixedByAdminSpec = $request->get('newBanners'); $probabilities = $request->get('probability'); $zoneId = $request->get('zoneId'); if (empty($fixedByAdminSpec)) { $fixedByAdminSpec = array(); } if (!is_array($fixedByAdminSpec)) { throw new \Exception('invalid banner ID\'s'); } /** @var $em \Doctrine\ORM\EntityManager */ $em = $this->get('doctrine.orm.entity_manager'); $zonesRepository = $em->getRepository('HyperAdsBundle:Zone'); /** @var $bannersRepository \Hyper\AdsBundle\Entity\AdvertisementRepository */ $bannersRepository = $em->getRepository('HyperAdsBundle:Banner'); /** @var $zone \Hyper\AdsBundle\Entity\Zone */ $zone = $zonesRepository->find($zoneId); if (empty($zone)) { throw $this->createNotFoundException($this->trans('zone.not.exists')); } $banners = array(); /** @var $banners \Hyper\AdsBundle\Entity\Banner[] */ if (!empty($fixedByAdminSpec)) { $banners = $bannersRepository->findBy(array('id' => array_keys($fixedByAdminSpec))); } $referenceUpdater = new ReferencesUpdater($em); $referenceUpdater->setZone($zone); $referenceUpdater->setProbabilities($probabilities); $referenceUpdater->setBanners($banners); $referenceUpdater->setFixedByAdminSpecification($fixedByAdminSpec); $referenceUpdater->updateReferences(); $this->get('session')->setFlash('success', $this->trans('banners.configs.are.saved')); return $this->redirect($this->generateUrl('admin_zone_show', array('id' => $zoneId))); }
public function testRaisingExceptionProbabilitiesBannersInequality() { $this->updater->setZone(new Zone()); $this->updater->setBanners(array($this->banner1, $this->banner2)); $this->updater->setProbabilities(array($this->banner1->getId() => self::MOCK_PROBABILITY_1, self::FAKE_BANNER_ID => self::MOCK_PROBABILITY_2)); $this->setExpectedException('InvalidArgumentException', ReferencesUpdater::ERROR_PROBABILITIES_BANNER_COUNT); $this->updater->updateReferences(); }