Ejemplo n.º 1
0
 public function importRealtorsAction(Request $request)
 {
     $session = $this->getRequest()->getSession();
     $loggedInUserId = $session->get('userId');
     $currentTimestamp = new DateTime();
     if ($request->getMethod() == 'POST') {
         //echo $_FILES['file']['type'];die();
         if (!($_FILES['file']['type'] == "text/comma-separated-values") && !($_FILES['file']['type'] == "application/vnd.ms-excel")) {
             $error = 'Wrong file selected';
             return $this->render('RAAAdminBundle:Airline:importAirlines.html.twig', array('error' => $error));
         } else {
             if (is_uploaded_file($_FILES['file']['tmp_name'])) {
                 //readfile($_FILES['file']['tmp_name']);
             }
             $handle = fopen($_FILES['file']['tmp_name'], "r");
             while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
                 $firstName = $data[0];
                 $lastName = $data[1];
                 $email = $data[2];
                 $password = $data[3];
                 $phone = $data[4];
                 $address = $data[5];
                 $address2 = $data[6];
                 $city = $data[7];
                 $state = $data[8];
                 $country = $data[9];
                 $pincode = $data[10];
                 $fax = $data[11];
                 $business = $data[12];
                 $overview = $data[13];
                 $twitter = $data[14];
                 $google = $data[15];
                 $linkedin = $data[16];
                 $video = $data[17];
                 $facebook = $data[18];
                 $realtor = new User();
                 $realtor->setFirstName($firstName);
                 $realtor->setLastName($lastName);
                 $realtor->setEmail($email);
                 $realtor->setPassword(md5($password));
                 $realtor->setPhone($phone);
                 $realtor->setAddress($address);
                 $realtor->setAddress2($address2);
                 $realtor->setCity($city);
                 $realtor->setState($state);
                 $realtor->setCountry($country);
                 $realtor->setPinCode($pincode);
                 $realtor->setFax($fax);
                 $realtor->setBusinessName($business);
                 $realtor->setOverview($overview);
                 $realtor->setTwitter($twitter);
                 $realtor->setGoogle($google);
                 $realtor->setLinkedin($linkedin);
                 $realtor->setFacebook($facebook);
                 $realtor->setVideo($video);
                 $realtor->setType(2);
                 $realtor->setPlanId(1);
                 $realtor->setStatus(1);
                 $realtor->setCreatorId($loggedInUserId);
                 $realtor->setModifierId($loggedInUserId);
                 $realtor->setCreationTimestamp($currentTimestamp);
                 $realtor->setModificationTimestamp($currentTimestamp);
                 $em = $this->getDoctrine()->getEntityManager();
                 $em->persist($realtor);
                 $em->flush();
             }
             fclose($handle);
             //print "Import done";
         }
     }
     return $this->render('RAAAdminBundle:Airline:importAirlines.html.twig');
 }