protected function execute(InputInterface $input, OutputInterface $output) { $countryFilePath = ''; if (!$countryFilePath) { $countryFilePath = $this->getContainer()->getParameter('country_file_path'); } $file = new File($countryFilePath); $contents = file_get_contents($file); $fileContents = explode("\n", $contents); $em = $this->getContainer()->get('doctrine')->getEntityManager(); $em->getConnection()->getConfiguration()->setSQLLogger(null); $em->getRepository('HelperBundle:Country'); echo "Memory: " . \memory_get_usage() . "\n"; $countries = $this->getAllCountries('abbr'); //parameter is the field to be check in Entity Country $finishedNames = array(); $code = ''; foreach ($fileContents as $lineContent) { $line = explode(",", trim($lineContent)); if (!isset($line[4])) { continue; } $abbr = str_replace('"', '', $line[4]); $name = str_replace('"', '', $line[5]); if ($countries) { if (\in_array($name, $countries)) { continue; } } if (\in_array($name, $finishedNames)) { continue; } //persist data to db $country = new Country(); $country->setAbbr($abbr); $country->setName($name); $country->setStatus(Country::STATUS_ACTIVE); $country->setCode($code); $em->persist($country); $finishedNames[] = $name; echo "Memory: " . \memory_get_usage() . "\n"; } $em->flush(); //load country code $this->loadCountryCode(); echo "successfully loaded"; exit; }
/** * Check if user has a contact details (mobile or phone). * @param InstitutionUser $user * @return InstitutionUser * @author Chaztine Blance */ public function initializeContactDetails($parentObject, $types, Country $country = null) { $types = array_flip($types); foreach ($parentObject->getContactDetails() as $contact) { unset($types[$contact->getType()]); } foreach ($types as $type => $dummy) { $number = new ContactDetail(); $number->setType($type); if ($country) { $number->setCountryCode($country->getCountryCode()); $number->setCountry($country); } $parentObject->addContactDetail($number); } return $parentObject; }
/** * Get query builder by destination * We may not be able to mix query with getQueryBuilderByDocumentIdAndType since this will be grouped by institution and not by clinic * @param Country $country * @param City $city * @return \Doctrine\ORM\QueryBuilder */ public function getQueryBuilderByDestination(Country $country, City $city = null) { $qb = $this->getEntityManager()->createQueryBuilder(); $qb->select('a, imc, inst, co, ci, instLogo')->from('TermBundle:SearchTerm', 'a')->innerJoin('a.institutionMedicalCenter', 'imc')->innerJoin('a.institution', 'inst')->leftJoin('inst.logo', 'instLogo')->innerJoin('inst.country', 'co')->leftJoin('inst.city', 'ci')->where('co.id = :countryId')->andWhere('a.status = :searchTermActiveStatus')->setParameter('countryId', $country->getId())->setParameter('searchTermActiveStatus', SearchTerm::STATUS_ACTIVE); if (!\is_null($city)) { $qb->andWhere('ci.id = :cityId')->setParameter('cityId', $city->getId()); } // we may not need this? $qb->groupBy('inst.id'); // order by totalRankingPoints $qb->orderBy('inst.totalClinicRankingPoints', 'DESC'); return $qb; }
/** * Create Country instance from array $data * * @param array $data * @return \HealthCareAbroad\HelperBundle\Entity\Country */ public function createCountryFromArray(array $data) { $requiredFields = array('id', 'name', 'slug'); foreach ($requiredFields as $key) { if (!isset($data[$key])) { throw LocationServiceException::missingRequiredCountryDataKey($key); } } $country = new Country(); $country->setId($data['id']); $country->setName($data['name']); $country->setSlug($data['slug']); $country->setCcIso(isset($data['ccIso']) ? $data['ccIso'] : ''); $country->setCountryCode(isset($data['countryCode']) ? $data['countryCode'] : ''); $country->setStatus(isset($data['code']) ? $data['code'] : Country::STATUS_ACTIVE); return $country; }
private function _updateCountryFieldOfContactDetailsByCountry(Country $country, $contactDetails = array(), $em) { foreach ($contactDetails as $contactDetail) { $this->output->write(" #{$contactDetail->getId()} -> {$contactDetail->__toString()} ["); if (!$contactDetail->getCountry()) { $code = (int) $contactDetail->getCountryCode(); if ($code && $code == $country->getCode()) { $contactDetail->setCountry($country); $em->persist($contactDetail); $this->output->writeln("OK]"); } else { $this->output->writeln("Invalid CC {$code} == {$country->getCode()}] C.id={$country->getId()}"); } } } }
public function get_country_url(Country $country) { $params = array('country' => $country->getSlug()); return $this->generator->generate('frontend_search_results_countries', $params, true); }