Esempio n. 1
0
 protected function importBranchesFromCsv($csvPath)
 {
     ini_set('auto_detect_line_endings', true);
     $siteId = $this->site->getId();
     $states = $this->em->getRepository('SudouxCmsLocationBundle:State')->findAll();
     $header = array('name', 'nmls_id', 'los_id', 'phone', 'fax', 'email', 'address1', 'address2', 'unit', 'city', 'state', 'zipcode', 'latitude', 'longitude', 'directions', 'description');
     $headerValid = true;
     $batchCount = 10;
     if (file_exists($csvPath)) {
         if (($handle = fopen($csvPath, "r")) !== FALSE) {
             $row = 0;
             $states = $this->em->getRepository('SudouxCmsLocationBundle:State')->findAll();
             while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
                 if ($row == 0) {
                     // validate the header
                     for ($i = 0; $i < count($data); $i++) {
                         if ($data[$i] != $header[$i]) {
                             $headerValid = false;
                             break;
                         }
                     }
                     if (!$headerValid) {
                         throw new \Exception('Csv headers are not valid. Correct format is ' . implode(',', $header));
                     }
                 } else {
                     $branch = new Branch();
                     $branch->setName($this->getCsvValue($data[0]));
                     $branch->setNmlsId($this->getCsvValue($data[1]));
                     $branch->setLosId($this->getCsvValue($data[2]));
                     $branch->setPhone($this->getCsvValue($data[3]));
                     $branch->setFax($this->getCsvValue($data[4]));
                     $branch->setEmail($this->getCsvValue($data[5]));
                     $location = new Location();
                     $location->setAddress1($this->getCsvValue($data[6]));
                     $location->setAddress2($this->getCsvValue($data[7]));
                     $location->setUnit($this->getCsvValue($data[8]));
                     $location->setCity($this->getCsvValue($data[9]));
                     foreach ($states as $state) {
                         if ($state->getAbbreviation() == trim($data[10]) || $state->getName() == trim($data[10])) {
                             $location->setState($state);
                             break;
                         }
                     }
                     $location->setZipcode($this->getCsvValue($data[11]));
                     $location->setLatitude($this->getCsvValue($data[12]));
                     $location->setLongitude($this->getCsvValue($data[13]));
                     $branch->setLocation($location);
                     $branch->setDirections($this->getCsvValue($data[14]));
                     $branch->setDescription($this->getCsvValue($data[15]));
                     $branch->setSite($this->site);
                     $this->em->persist($branch);
                     if ($row % $batchCount == 0) {
                         $this->em->flush();
                         $this->em->clear();
                         $this->site = $this->em->getRepository('SudouxCmsSiteBundle:Site')->find($siteId);
                         $states = $this->em->getRepository('SudouxCmsLocationBundle:State')->findAll();
                         $this->output->writeln(sprintf('%s rows processed', $row));
                     }
                 }
                 $row++;
             }
             $this->em->flush();
             $this->em->clear();
             $this->output->writeln(sprintf('Processing complete! %s rows processed', $row));
         }
     }
 }
 public function setApi()
 {
     if (!isset($this->is_prequal)) {
         $this->is_prequal = false;
     }
     if (!isset($this->co_borrower)) {
         $this->co_borrower = new \Doctrine\Common\Collections\ArrayCollection();
     }
     if (!isset($this->asset_account)) {
         $this->asset_account = new \Doctrine\Common\Collections\ArrayCollection();
     }
     if (!isset($this->asset_real_estate)) {
         $this->asset_real_estate = new \Doctrine\Common\Collections\ArrayCollection();
     }
     if (!isset($this->income_monthly)) {
         $this->income_monthly = new \Doctrine\Common\Collections\ArrayCollection();
     }
     if (!isset($this->income_other)) {
         $this->income_other = new \Doctrine\Common\Collections\ArrayCollection();
     }
     if (!isset($this->expense_housing)) {
         $this->expense_housing = new ExpenseHousing();
     }
     if (!isset($this->created)) {
         $this->created = new \DateTime();
     }
     if (!isset($this->modified)) {
         $this->modified = new \DateTime();
     }
     if (!isset($this->deleted)) {
         $this->deleted = false;
     }
     if (!isset($this->message_thread)) {
         $this->message_thread = new \Sudoux\Cms\MessageBundle\Entity\Thread();
         $this->message_thread->setSubject('Loan Application Thread');
     }
     if (!isset($this->last_step_completed) || $this->last_step_completed >= 7) {
         $this->last_step_completed = 7;
         $this->completed = true;
         $this->completed_date = new \DateTime();
     } else {
         $this->completed = false;
     }
     if (!isset($this->sent_to_los)) {
         $this->sent_to_los = false;
     }
     if (!isset($this->property_location)) {
         $this->property_location = new Location();
     } else {
         $propertyCreated = $this->property_location->getCreated();
         if (!isset($propertyCreated)) {
             $this->property_location->setCreated(new \DateTime());
         }
     }
     if (!isset($this->document)) {
         $this->document = new \Doctrine\Common\Collections\ArrayCollection();
     }
     if (!isset($this->loan_type)) {
         $this->loan_type = 0;
     }
     if (!isset($this->source)) {
         $this->source = 3;
     }
     if (!isset($this->lock_status)) {
         $this->lock_status = 0;
     }
     if (!isset($this->no_property_location)) {
         $this->no_property_location = false;
     }
     $this->setStatus(8);
     ///////////////////////
     //
     //Everything below is so that the user doesn't have to set the created dates
     //for anything coming into the API
     ////////////////////////
     $blLocationCreated = $this->borrower->getLocation()->getLocation()->getCreated();
     $bLocationCreated = $this->borrower->getLocation()->getCreated();
     $eLocationCreated = $this->borrower->getEmployment();
     if (!isset($this->status_date)) {
         $this->status_date = new \DateTime();
     }
     if (isset($eLocationCreated)) {
         foreach ($eLocationCreated as $emp) {
             $bEmpLoc = $emp->getLocation()->getCreated();
             if (!isset($bEmpLoc)) {
                 $emp->getLocation()->setApi();
             }
         }
     }
     if (!isset($bLocationCreated)) {
         $this->borrower->getLocation()->getLocation()->setApi();
     }
     if (!isset($blLocationCreated)) {
         $this->borrower->getLocation()->setApi();
     }
     foreach ($this->co_borrower as $coB) {
         $colbLocationCreated = $coB->getLocation()->getLocation()->getCreated();
         $cobLocationCreated = $coB->getLocation()->getCreated();
         $eCoLocationCreated = $coB->getEmployment();
         if (isset($eCoLocationCreated)) {
             foreach ($eCoLocationCreated as $coEmp) {
                 $bCoEmpLoc = $coEmp->getLocation()->getCreated();
                 if (!isset($bCoEmpLoc)) {
                     $coEmp->getLocation()->setApi();
                 }
             }
         }
         if (!isset($cobLocationCreated)) {
             $coB->getLocation()->getLocation()->setApi();
         }
         if (!isset($colbLocationCreated)) {
             $coB->getLocation()->setApi();
         }
     }
 }
Esempio n. 3
0
 public function getAlias()
 {
     $alias = preg_replace("/[^a-zA-Z0-9]/", '-', strtolower($this->name));
     if (isset($this->location)) {
         $address = $this->location->getAddress1();
         $city = $this->location->getCity();
         $state = $this->location->getState();
         $zipcode = $this->location->getZipcode();
         if (isset($address)) {
             $alias .= '-' . preg_replace("/[^a-z0-9]/", '-', strtolower($address));
         }
         if (isset($city)) {
             $alias .= '-' . preg_replace("/[^a-z0-9]/", '-', strtolower($city));
         }
         if (isset($state)) {
             $alias .= '-' . preg_replace("/[^a-z0-9]/", '-', strtolower($state->getName()));
         }
         if (isset($zipcode)) {
             $alias .= '-' . preg_replace("/[^a-z0-9]/", '-', strtolower($zipcode));
         }
     }
     return $alias;
 }
 protected function importBranches()
 {
     $x = 0;
     $counter = 0;
     $zipPicRoot = $this->uploadPath . "/branches/";
     $baseRoot = $this->getContainer()->get('kernel')->getRootDir() . '/../';
     $this->output->writeln("Available Files: " . PHP_EOL);
     chdir($this->uploadPath . "/branches");
     passthru("ls *.csv");
     $csvPick = $this->dialog->ask($this->output, PHP_EOL . '</fg=yellow>Please Enter The Name Of The CSV You Want To Process (branch.csv) - ', 'branch.csv');
     $userName = $this->dialog->ask($this->output, 'Please Enter The User Name To Upload Pics As (admin)', 'admin');
     $user = $this->em->getRepository('SudouxCmsUserBundle:User')->loadUserByUsername($userName);
     if (file_exists($this->uploadPath . "/branches/" . $csvPick)) {
         $this->output->writeln("  File Found: " . PHP_EOL);
         $file = fopen($csvPick, "r");
         //$this->output->writeln(implode(" - ",fgetcsv($file)));
         print_r(fgetcsv($file));
         $picKey = $this->dialog->ask($this->output, 'Which Field(#) Do you want to key the pic off of (1)?', 1);
         while (($newBranchInfo = fgetcsv($file)) !== FALSE) {
             $newBranch = new Branch();
             $newLocation = new Location();
             $x++;
             $this->output->writeln("    Adding Branch {$x}:  " . PHP_EOL);
             $this->output->writeln(implode(" - ", $newBranchInfo));
             if (!$this->dialog->askConfirmation($this->output, PHP_EOL . "Are You Sure You Want To Add This Site?</question>?  ", false)) {
                 return;
             }
             $newBranch->setSite($this->site);
             $newBranch->setName($newBranchInfo[0]);
             $newBranch->setNmlsId($newBranchInfo[1]);
             $newBranch->setPhone($newBranchInfo[2]);
             $newBranch->setFax($newBranchInfo[3]);
             $newBranch->setEmail($newBranchInfo[4]);
             $newBranch->setLosId($newBranchInfo[6]);
             $newLocation->setAddress1($newBranchInfo[7]);
             $newLocation->setCity($newBranchInfo[8]);
             $stateLookup = $this->em->getRepository('SudouxCmsLocationBundle:State')->findByName($newBranchInfo[9]);
             // print_r($stateLookup['0']);
             $newLocation->setState($stateLookup['0']);
             $newLocation->setZipcode($newBranchInfo[10]);
             $this->em->persist($newLocation);
             $globResults = glob("{$this->uploadPath}/branches/{$newBranchInfo[$picKey]}.*");
             $ext = pathinfo($globResults[0], PATHINFO_EXTENSION);
             if ($globResults) {
                 $savePath = realpath($baseRoot) . "/web/uploads/sites/" . $this->site->getId() . "/public/";
                 $picName = "{$newBranchInfo[$picKey]}.{$ext}";
                 $uploadedPicPath = $globResults[0];
                 $MIMEtype = mime_content_type($uploadedPicPath);
                 while (file_exists($savePath . $picName)) {
                     $picName = $newBranchInfo[$picKey] . "_{$counter}." . $ext;
                     $counter++;
                     $this->output->writeln("File Name Exists - New Name: <fg=blue>{$picName}</fg=blue>");
                 }
                 $openFileName = $zipPicRoot . $picName;
                 rename($openFileName, $savePath . $picName);
                 $photo = new File();
                 $size = filesize($savePath . $picName);
                 $photo->setPath("uploads/sites/" . $this->site->getId() . "/public/" . $picName);
                 $photo->setFilesize($size);
                 $photo->setName($newBranchInfo[0]);
                 $photo->setUser($user);
                 $photo->setMimeType($MIMEtype);
                 $photo->setSite($this->site);
                 $this->em->persist($photo);
                 $newBranch->setBranchPhoto($photo);
             }
             $newBranch->setLocation($newLocation);
             $newBranch->setActive($newBranchInfo[11]);
             $newBranch->setWebsite($newBranchInfo[12]);
             $this->em->persist($newBranch);
             $this->em->flush();
         }
         fclose($file);
     }
 }