/** * @return string */ private function _getCountryList() { $countries = $this->locationService->getActiveCountries(); $result = array(); foreach ($countries as $each) { $result[] = array('id' => $each['id'], 'custom_label' => "<span class='flag16 " . strtolower($each['ccIso']) . "'> </span> " . "<span class='item-label'>" . $each['name'] . "</span>", 'label' => $each['name']); } return \json_encode($result, JSON_HEX_APOS); }
public function setDefaultOptions(OptionsResolverInterface $resolver) { $countries = $this->locationService->getGlobalCountries(); $choices = array(); foreach ($countries['data'] as $country) { $choices[$country['id']] = $country['name']; } $resolver->setDefaults(array('choices' => $choices)); }
public function reverseTransform($id) { if (!$id) { return null; } $state = $this->locationService->getStateById($id); if (!$state) { $globalStateData = $this->locationService->getGlobalStateById($id); if (null === $globalStateData) { throw new \Exception('Failed to transform invalid state id: ' . $id); } $state = $this->locationService->createStateFromArray($globalStateData); } return $state; }
public function buildForm(FormBuilderInterface $builder, array $options = array()) { $builder->addEventSubscriber(new ContactDetailDataSubscriber()); $countryChoices = array(); foreach ($this->locationService->getActiveCountries() as $country) { $code = (int) $country['countryCode']; $countryChoices[$country['id']] = $country['name'] . " (+{$code})"; } $countryList = $builder->create('country', 'choice', array('label' => "Country", 'choices' => $countryChoices))->addModelTransformer(new CountryTransformer($this->locationService)); $builder->add('type', 'hidden'); $builder->add($countryList); $builder->add('area_code', 'text', array('required' => false, 'attr' => array('placeholder' => 'Area Code'))); $builder->add('number', 'text', array('required' => false, 'attr' => array('placeholder' => 'Phone Number'))); $builder->add('ext', 'text', array('required' => false)); $builder->add('type', 'hidden', array('required' => false)); }
protected function execute(InputInterface $input, OutputInterface $output) { $this->output = $output; $this->locationService = $this->getContainer()->get('services.location'); // Fetching GlobalCountries form ChromediaApi $this->output->write("\nFetching countries from ChromediaApi... "); $countries = $this->locationService->getGlobalCountries(); $this->output->writeln(count($countries['data']) . " countries\n"); $connection = $this->getContainer()->get('doctrine')->getConnection(); foreach ($countries['data'] as $id => $each) { // Query get_cities By countryId $sql = "SELECT a.* FROM `chromedia_global`.`geo_cities` a WHERE a.`geo_country_id` = :countryId and a.`status` = :status ORDER BY a.name ASC"; $statement = $connection->prepare($sql); $statement->bindValue('countryId', $id); $statement->bindValue('status', 1); $statement->execute(); // Initialize document $data to be saved. $cities = array(); $globalCitiesData = $statement->fetchAll(); foreach ($globalCitiesData as $city) { $cities[$city['id']] = array('id' => $city['id'], 'name' => $city['name'], 'slug' => $city['slug']); } $data['data']['data'] = $cities; $data['data']['country'] = $each; $data['data']['totalResults'] = count($globalCitiesData); $citiesDocId = "country_{$id}"; $citiesDoc = \json_decode($this->locationService->couchDbService->get("country_{$id}"), true); if ($citiesDoc) { $data['_rev'] = $citiesDoc['_rev']; $this->output->write("Updating cities: {$citiesDocId} (rev: " . $data['_rev'] . ') ... '); } else { $this->output->write("Adding new cities: {$citiesDocId} ... "); } $result = $this->locationService->couchDbService->put($citiesDocId, $data); if (isset($result['id']) && isset($result['rev'])) { $this->output->writeln('SAVED - count: ' . $data['data']['totalResults']); } else { $this->output->writeln('FAILED.'); } } $this->output->writeln("\nEnd of Script."); }
/** * * @param array $globaStateData * @return State */ private function getHcaState($globalStateData, Country $country) { $hcaState = $this->locationService->getStateById($globalStateData['id']); if (!$hcaState) { // create new hca state $hcaState = new State(); $hcaState->setId($globalStateData['id']); $hcaState->setName($globalStateData['name']); $hcaState->setCountry($country); } return $hcaState; }
public function prebind(DataEvent $event) { $data = $event->getData(); $form = $event->getForm(); $locationService = LocationService::getCurrentInstance(); $countryId = !empty($data) && $data['country'] ? $data['country'] : 0; $choices = array(0 => null); if ($countryId) { $cities = $locationService->getGlobalCitiesListByContry($countryId); foreach ($cities['data'] as $id => $value) { $choices[$id] = $value['name']; } } $form->add($this->factory->createNamed('city', GlobalCityListType::NAME, null, compact('choices'))); }