Beispiel #1
0
 public function importRealtorsAction(Request $request)
 {
     ini_set('max_execution_time', 10000000);
     $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('RARAdminBundle:Realtor:importRealtors.html.twig',array('error'=>$error)); 
         		}
         		else
         		{*/
         //echo"<pre>";print_r($_FILES);die;
         if (is_uploaded_file($_FILES['file']['tmp_name'])) {
             //readfile($_FILES['file']['tmp_name']);
         }
         $handle = fopen($_FILES['file']['tmp_name'], "r");
         /*$i=0;
         		while (($data = fgetcsv($handle, 10000000, ";")) !== FALSE) 
         		{
         			$arrFile[] = $data;
         			$i++;
         			if($i>50)
         				break;
         		}
         		echo "<PRE>";print_r($arrFile);die;*/
         $stateCode = '';
         $cityName = '';
         $companyName = '';
         $phone = '';
         $businessUrl = '';
         $address = '';
         $zipCode = '';
         $stateName = '';
         $category1 = '';
         $category2 = '';
         while (($data = fgetcsv($handle, 10000000, ";")) !== FALSE) {
             $data = explode(';', $data[0]);
             if (isset($data[0])) {
                 $stateCode = ltrim($data[0]);
             }
             if (isset($data[1])) {
                 $cityName = ltrim($data[1]);
             }
             if (isset($data[2])) {
                 $companyName = ltrim($data[2]);
             }
             if (isset($data[3])) {
                 $phone = ltrim($data[3]);
             }
             if (isset($data[4])) {
                 $businessUrl = ltrim($data[4]);
             }
             if (isset($data[5])) {
                 $address = ltrim($data[5]);
             }
             if (isset($data[6])) {
                 $zipCode = ltrim($data[6]);
             }
             if (isset($data[7])) {
                 $stateName = ltrim($data[7]);
             }
             if (isset($data[8])) {
                 $category1 = ltrim($data[8]);
             }
             if (isset($data[9])) {
                 $category2 = ltrim($data[9]);
             }
             $em = $this->getDoctrine()->getEntityManager();
             $city = $em->createQueryBuilder()->select('City')->from('RARAdminBundle:City', 'City')->where('City.city_name = :cityName')->setParameter('cityName', $cityName)->getQuery()->getArrayResult();
             //echo $cityName."<PRE>";print_r($data);die;
             $cityId = $city[0]['id'];
             $country = 'US';
             $arrCat = explode(',,,,,', $category2);
             $category2 = $arrCat[0];
             $realtor = new User();
             $realtor->setState($stateCode);
             $realtor->setCity($cityId);
             $realtor->setBusinessName($companyName);
             $realtor->setPhone($phone);
             $realtor->setBusinessUrl($businessUrl);
             $realtor->setAddress($address);
             $realtor->setPinCode($zipCode);
             //$realtor->setStateName($stateName);
             $realtor->setCountry($country);
             $realtor->setCategory1($category1);
             $realtor->setCategory2($category2);
             $realtor->setImage('default_user_image.jpeg');
             $realtor->setLogo('company.jpeg');
             $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);
         //}
     }
     return $this->render('RARAdminBundle:Realtor:importRealtors.html.twig');
 }