/** * */ protected function syncLoanOfficersWithLos($siteId) { $loanUtil = $this->getContainer()->get('sudoux_mortgage.los_util'); $response = $loanUtil->getLoanOfficers($this->site); $batch = 10; //print_r($response['loanOfficers']);exit; if ($response['success']) { $this->output->writeln(sprintf('processing %s loan officers', count($response['loanOfficers']))); $losLoanOfficers = $response['loanOfficers']; $i = 0; //print_r($response['loanOfficers']); exit; foreach ($response['loanOfficers'] as $loData) { $loanOfficer = $this->em->getRepository('SudouxMortgageBundle:LoanOfficer')->findOneBySiteAndLosId($this->site, $loData['username']); if (!isset($loanOfficer)) { $loanOfficer = new LoanOfficer(); $loanOfficer->setSite($this->site); $loanOfficer->setLosId($loData['username']); } $loanOfficer->setFirstName($loData['firstName']); $loanOfficer->setLastName($loData['lastName']); $loanOfficer->setEmail($loData['email']); $loanOfficer->setPhoneMobile($loData['cellPhone']); $loanOfficer->setPhoneOffice($loData['phone']); $loanOfficer->setFax($loData['fax']); $loanOfficer->setNmlsId($loData['nmlsID']); $loanOfficer->setAutoCreateUser(false); // this needs to be set after setSite to override default functionality $loanOfficer->setActive(true); $loanOfficer->setDeleted(false); $loSite = $loanOfficer->getOfficerSite(); if (isset($loSite)) { $loSite->setActive(true); $loSite->setDeleted(false); $this->em->persist($loSite); } //print_r($loData); if (!empty($loData['orgID'])) { // look up branch $branch = $this->em->getRepository('SudouxMortgageBundle:Branch')->findOneBySiteAndLosId($this->site, $loData['orgID']); if (isset($branch)) { $loanOfficer->setBranch($branch); $branchSite = $branch->getBranchSite(); if (isset($branchSite) && isset($loSite)) { $loSite->setParentSite($branchSite); $this->em->persist($loSite); } } } $this->em->persist($loanOfficer); if ($i % $batch == 0) { $this->em->flush(); $this->em->clear(); $this->site = $this->em->getRepository('SudouxCmsSiteBundle:Site')->find($siteId); $this->output->writeln(sprintf('Batch %s of %s complete.', $i, count($response['loanOfficers']))); } $i++; } $this->em->flush(); $this->em->clear(); $this->output->writeln('Processing complete!'); } else { $this->output->writeln('Failed to get a successful response from the LOS'); } }