예제 #1
0
 public function indexAction(Request $request)
 {
     $em = $this->getDoctrine()->getManager();
     $um = $this->get('fos_user.user_manager');
     $user_id = $this->get('security.context')->getToken()->getUser();
     $billing = $this->getDoctrine()->getRepository('AppBundle:Billing')->findAll();
     $status = $this->getDoctrine()->getRepository('AppBundle:Status')->findOneById(3);
     $user = new Userform();
     if ($request->isMethod('POST')) {
         $user->setSellpartner($user_id);
         $string = "";
         $chaine = "0123456789";
         srand((double) microtime() * 1000000);
         for ($i = 0; $i < 12; $i++) {
             $string .= $chaine[rand() % strlen($chaine)];
         }
         $file = $request->files->get('img');
         $valid_filetypes = array('jpg', 'jpeg');
         if ($file instanceof UploadedFile) {
             if ($file->getError() == '0') {
                 $originalName = explode('.', $file->getClientOriginalName());
                 if (!($file->getSize() < 2000000)) {
                     echo 'taille';
                     die;
                     return $this->redirectToRoute('app_homepage');
                 }
                 if (!in_array(strtolower($originalName[sizeof($originalName) - 1]), $valid_filetypes)) {
                     echo 'valid';
                     die;
                     return $this->redirectToRoute('app_homepage');
                 }
                 if (!($file->getMimeType() == "image/jpeg" or $file->getMimeType() == "image/png")) {
                     echo 'mimetype';
                     die;
                     return $this->redirectToRoute('app_homepage');
                 }
             } else {
                 return $this->redirectToRoute('app_homepage');
             }
         } else {
             return $this->redirectToRoute('app_homepage');
         }
         $document = new Document();
         $document->setFile($file);
         $document->setSubDirectory('photos');
         $document->processFile();
         $uploadedURL = $document->getUploadDirectory() . DIRECTORY_SEPARATOR . $document->getSubDirectory() . DIRECTORY_SEPARATOR . $file->getBasename();
         $user->setUsername($string);
         $user->setStatus($status);
         $user->setFirstname($request->request->get('firstname'));
         $user->setLastname($request->request->get('lastname'));
         $user->setEmail($request->request->get('email'));
         $user->setMobile($request->request->get('number'));
         $user->setStudyLevel($request->request->get('level'));
         $user->setAddress($request->request->get('address'));
         $user->setZipcode(intval($request->request->get('zipcode')));
         $user->setCity($request->request->get('city'));
         $user->setSchool($user_id->getSchoolId());
         $user->setPicture($uploadedURL);
         $user->setLastBillingPrice($request->request->get('amount'));
         $type = $this->getDoctrine()->getRepository('AppBundle:Billing')->findOneById($request->request->get('payment'));
         $user->setLastBillingType($type);
         $date = DateTime::createFromFormat('m/d/Y', trim($request->request->get('birthdate')));
         $date->format('Y-m-d');
         $user->setBirthdate($date);
         $em->persist($user);
         $em->flush();
         return $this->redirectToRoute('app_homepage');
     }
     return $this->render('AppBundle:Default:index.html.twig', array('billing' => $billing));
 }