Exemplo n.º 1
0
 /**
  * 
  * @param Request $request
  * @return type
  */
 public function suscribeAction(Request $request)
 {
     //On créé un objet company
     $company = new Company();
     $infos = new Infos();
     $company->setInfos($infos->setLat('BIM')->setUpdateCoords(TRUE));
     // On crée le FormBuilder grâce au service form factory
     $form = $this->get('form.factory')->create(new CompanyType(), $company);
     //Si le formulaire est valide
     if ($form->handleRequest($request)->isValid()) {
         //on récupère l'utilisateur
         $user = $this->container->get('security.context')->getToken()->getUser();
         // on upload le logo
         $company->getLogo()->upload('logo', $user->getId());
         //on récupère l'entity manager
         $em = $this->getDoctrine()->getManager();
         //on associe company et user
         $user->setCompany($company);
         //on génère le slider avec 3 slides par défault
         $slider = new Slider();
         $slider->setNbOfSlides(3);
         $slider->setSize('M');
         for ($i = 0; $i < 3; $i++) {
             $slide = new Image();
             $slide->setAlt('Temporary pic')->setExt('svg')->setName('slide_' . ($i + 1))->setUrl('Defaults/img/slide_' . ($i + 1) . '.svg')->setType('slide')->setSliderPosition($i + 1)->setSlider($slider);
             $em->persist($slide);
             //on associe la slide au slider
             $slider->addSlide($slide);
         }
         //on associe le slider à l'utilisateur
         $company->setSlider($slider);
         //on persiste les entités
         $em->persist($user);
         $em->persist($infos);
         $em->persist($company);
         $em->persist($slider);
         //on enregistre en bdd
         $em->flush();
         //on redirige vers la page d'administration de l'utilisateur
         return $this->redirect($this->generateUrl('stpe_cms_home'));
     }
     return $this->render('STPECMSBundle::Inscription/suscribe.html.twig', array('form' => $form->createView()));
 }
Exemplo n.º 2
0
 private function createSlide($slider)
 {
     $slide = new Image();
     return $slide->setAlt('Temporary pic')->setExt('svg')->setName('slide_' . ($i + 1))->setUrl('Defaults/img/slide_' . ($i + 1) . '.png')->setType('slide')->setSliderPosition($i + 1)->setSlider($slider);
 }