/** * {@inheritdoc} */ public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(array( 'choices' => Intl::getRegionBundle()->getCountryNames(), 'choice_translation_domain' => false, )); }
/** * Load the form */ private function loadForm() { // gender dropdown values $genderValues = array('male' => \SpoonFilter::ucfirst(BL::getLabel('Male')), 'female' => \SpoonFilter::ucfirst(BL::getLabel('Female'))); // birthdate dropdown values $days = range(1, 31); $months = \SpoonLocale::getMonths(BL::getInterfaceLanguage()); $years = range(date('Y'), 1900); // create form $this->frm = new BackendForm('add'); // create elements $this->frm->addText('email')->setAttribute('type', 'email'); $this->frm->addPassword('password'); $this->frm->addText('display_name'); $this->frm->addText('first_name'); $this->frm->addText('last_name'); $this->frm->addText('city'); $this->frm->addDropdown('gender', $genderValues); $this->frm->addDropdown('day', array_combine($days, $days)); $this->frm->addDropdown('month', $months); $this->frm->addDropdown('year', array_combine($years, $years)); $this->frm->addDropdown('country', Intl::getRegionBundle()->getCountryNames(BL::getInterfaceLanguage())); // set default elements dropdowns $this->frm->getField('gender')->setDefaultElement(''); $this->frm->getField('day')->setDefaultElement(''); $this->frm->getField('month')->setDefaultElement(''); $this->frm->getField('year')->setDefaultElement(''); $this->frm->getField('country')->setDefaultElement(''); }
public static function validateUPU_S10($track) { if (!preg_match("/^([A-Z]{2})(\\d{8})(\\d{1})([A-Z]{2})\$/", $track, $matches)) { return false; } list($track, $serviceIndicator, $serialNumber, $checkDigit, $countryCode) = $matches; // Check $serviceIndicator if (!preg_match("/([ELMRUVCHABDNPZ][A-Z])|(Q[A-M])|(G[AD])/", $serviceIndicator)) { return false; } // Check $checkDigit $serialNumberDigits = str_split($serialNumber); $weightFactors = array(8, 6, 4, 2, 3, 5, 9, 7); $weightedSum = array_reduce(range(0, 7), function ($sum, $i) use($serialNumberDigits, $weightFactors) { return $sum + $serialNumberDigits[$i] * $weightFactors[$i]; }); $res = 11 - $weightedSum % 11; $appropriateCheckDigit = $res >= 1 && $res <= 9 ? $res : ($res == 11 ? 5 : 0); if ($appropriateCheckDigit != $checkDigit) { return false; } // Check $countryCode $countryCodes = array_keys(Intl::getRegionBundle()->getCountryNames()); if (!in_array($countryCode, $countryCodes)) { return false; } return true; }
/** * {@inheritdoc} */ public function validate($value, Constraint $constraint) { if (!$constraint instanceof Country) { throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Country'); } if (null === $value || '' === $value) { return; } if (!is_scalar($value) && !(is_object($value) && method_exists($value, '__toString'))) { throw new UnexpectedTypeException($value, 'string'); } $value = (string) $value; $countries = Intl::getRegionBundle()->getCountryNames(); if (!isset($countries[$value])) { if ($this->context instanceof ExecutionContextInterface) { $this->context->buildViolation($constraint->message) ->setParameter('{{ value }}', $this->formatValue($value)) ->setCode(Country::NO_SUCH_COUNTRY_ERROR) ->addViolation(); } else { $this->buildViolation($constraint->message) ->setParameter('{{ value }}', $this->formatValue($value)) ->setCode(Country::NO_SUCH_COUNTRY_ERROR) ->addViolation(); } } }
/** * {@inheritdoc} */ public function loadChoiceList($value = null) { if (null !== $this->choiceList) { return $this->choiceList; } return $this->choiceList = new ArrayChoiceList(array_flip(Intl::getRegionBundle()->getCountryNames()), $value); }
/** * @param mixed $country * @param string $locale * * @return string */ public function translateCountryIsoCode($country, $locale = null) { if ($country instanceof CountryInterface) { return Intl::getRegionBundle()->getCountryName($country->getCode(), $locale); } return Intl::getRegionBundle()->getCountryName($country, $locale); }
/** * Returns the country names for a locale. * * @param string $locale The locale to use for the country names * * @return array The country names with their codes as keys * * @throws \RuntimeException When the resource bundles cannot be loaded */ public static function getDisplayCountries($locale) { if (!isset(self::$countries[$locale])) { self::$countries[$locale] = Intl::getRegionBundle()->getCountryNames($locale); } return self::$countries[$locale]; }
/** * {@inheritdoc} */ public function buildForm(FormBuilderInterface $builder, array $options) { if (self::WIDGET_COUNTRY_CHOICE === $options['widget']) { $util = PhoneNumberUtil::getInstance(); $countries = array(); if (is_array($options['country_choices'])) { foreach ($options['country_choices'] as $country) { $code = $util->getCountryCodeForRegion($country); if ($code) { $countries[$country] = $code; } } } if (empty($countries)) { foreach ($util->getSupportedRegions() as $country) { $countries[$country] = $util->getCountryCodeForRegion($country); } } $countryChoices = array(); foreach (Intl::getRegionBundle()->getCountryNames() as $region => $name) { if (false === isset($countries[$region])) { continue; } $countryChoices[$region] = sprintf('%s (+%s)', $name, $countries[$region]); } $countryOptions = $numberOptions = array('error_bubbling' => true, 'required' => $options['required'], 'disabled' => $options['disabled'], 'translation_domain' => $options['translation_domain']); $countryOptions['required'] = true; $countryOptions['choices'] = $countryChoices; $countryOptions['preferred_choices'] = $options['preferred_country_choices']; $countryOptions['choice_translation_domain'] = false; $builder->add('country', 'choice', $countryOptions)->add('number', 'text', $numberOptions)->addViewTransformer(new PhoneNumberToArrayTransformer(array_keys($countryChoices))); } else { $builder->addViewTransformer(new PhoneNumberToStringTransformer($options['default_region'], $options['format'])); } }
public function buildForm(FormBuilderInterface $builder, array $options) { parent::buildForm($builder, $options); $countries = Intl::getRegionBundle()->getCountryNames(); // add your custom field $builder->add('email', 'email', array('label' => 'form.email', 'translation_domain' => 'FOSUserBundle'))->add('username', null, array('label' => 'form.username', 'translation_domain' => 'FOSUserBundle'))->add('plainPassword', 'repeated', array('type' => 'password', 'options' => array('translation_domain' => 'FOSUserBundle'), 'first_options' => array('label' => 'form.password'), 'second_options' => array('label' => 'form.password_confirmation'), 'invalid_message' => 'fos_user.password.mismatch'))->add('lastname', 'text')->add('firstname', 'text')->add('image', new AetImageType())->add('pays', 'country', array('expanded' => false, 'multiple' => false))->add('matricule', 'text')->add('whoami', 'textarea', array('required' => false))->add('ville', 'text')->add('code_postale', 'text')->add('telephone', 'text')->add('activite_principale', 'choice', array('choices' => array('Art, Design' => 'Art, Design', 'Audiovisuel - Spectacle' => 'Audiovisuel - Spectacle', 'Audit, gestion' => 'Audit, gestion', 'Automobile' => 'Automobile', 'Banque, assurance' => 'Banque, assurance', 'Bois (filière)' => 'Bois (filière)', 'BTP, architecture' => 'BTP, architecture', 'Chimie, pharmacie' => 'Chimie, pharmacie', 'Commerce, distribution' => 'Commerce, distribution', 'Communication - Marketing, publicité' => 'Communication - Marketing, publicité', 'Construction aéronautique, ferroviaire et navale' => 'Construction aéronautique, ferroviaire et navale', 'Culture - Artisanat d\'art' => 'Culture - Artisanat d\'art', 'Droit, justice' => 'Droit, justice', 'Edition, Journalisme' => 'Edition, Journalisme', 'Électronique' => 'Électronique', 'Énergie' => 'Énergie', 'Enseignement' => 'Enseignement', 'Environnement' => 'Environnement', 'Fonction publique' => 'Fonction publique', 'Hôtellerie, restauration' => 'Hôtellerie, restauration', 'Industrie alimentaire' => 'Industrie alimentaire', 'Informatique, internet et télécom' => 'Informatique, internet et télécom', 'Logistique, transport' => 'Logistique, transport', 'Maintenance, entretien' => 'Maintenance, entretien', 'Mécanique' => 'Mécanique', 'Mode et industrie textile' => 'Mode et industrie textile', 'Recherche' => 'Recherche', 'Santé' => 'Santé', 'Social' => 'Social', 'Sport, loisirs – Tourisme' => 'Sport, loisirs – Tourisme', 'Traduction - interprétariat' => 'Traduction - interprétariat'), 'required' => false, 'mapped' => true))->add('promotion', 'birthday', array('widget' => 'choice', 'years' => range(date('Y') - 110, date('Y')), 'empty_value' => array('year' => '----'))); }
/** * {@inheritdoc} */ public function load(ObjectManager $manager) { $countryRepository = $this->getCountryRepository(); $countries = Intl::getRegionBundle()->getCountryNames($this->defaultLocale); if (Intl::isExtensionLoaded()) { $localisedCountries = array('es_ES' => Intl::getRegionBundle()->getCountryNames('es_ES')); } else { $localisedCountries = array(); } foreach ($countries as $isoName => $name) { $country = $countryRepository->createNew(); $country->setCurrentLocale($this->defaultLocale); $country->setName($name); foreach ($localisedCountries as $locale => $translatedCountries) { $country->setCurrentLocale($locale); $country->setName($translatedCountries[$isoName]); } $country->setIsoName($isoName); if ('US' === $isoName) { $this->addUsStates($country); } $manager->persist($country); $this->setReference('Sylius.Country.' . $isoName, $country); } $manager->flush(); }
/** * Return the country name using the Locale class. * * @param string $isoCode Country ISO 3166-1 alpha 2 code * @param null|string $locale Locale code * * @return null|string Country name */ public function getCountryName($isoCode, $locale = null) { if ($isoCode === null) { return; } return $locale === null ? Intl::getRegionBundle()->getCountryName($isoCode) : Intl::getRegionBundle()->getCountryName($isoCode, $locale); }
/** * @param mixed $value * * @throws InvalidCountryCodeException */ protected function guard($value) { $countryName = Intl::getRegionBundle()->getCountryName($value); if (null === $countryName) { throw new InvalidCountryCodeException($value); } }
/** * Load the form */ protected function loadForm() { $rbtHiddenValues[] = array('label' => BL::lbl('Published'), 'value' => 'N'); $rbtHiddenValues[] = array('label' => BL::lbl('Hidden'), 'value' => 'Y'); $this->frm = new BackendForm('edit'); $this->frm->addText('company', $this->record['company']); $this->frm->addText('name', $this->record['name']); $this->frm->addText('firstname', $this->record['firstname']); $this->frm->addText('email', $this->record['email']); $this->frm->addText('address', $this->record['address']); $this->frm->addText('zipcode', $this->record['zipcode']); $this->frm->addText('city', $this->record['city']); // $this->frm->addText('country', $this->record['country']); $this->frm->addDropdown('country', Intl::getRegionBundle()->getCountryNames(BL::getInterfaceLanguage()), $this->record['country']); $this->frm->addText('phone', $this->record['phone']); $this->frm->addText('fax', $this->record['fax']); $this->frm->addText('website', $this->record['website']); $this->frm->addText('vat', $this->record['vat']); $this->frm->addTextArea('zipcodes', $this->record['zipcodes']); $this->frm->addText('remark', $this->record['remark']); //$this->frm->addText('assort', $this->record['assort']); //$this->frm->addText('open', $this->record['open']); //$this->frm->addText('closed', $this->record['closed']); //$this->frm->addText('visit', $this->record['visit']); //$this->frm->addText('size', $this->record['size']); //$this->frm->addEditor('text', $this->record['text']); $this->frm->addImage('image'); $this->frm->addCheckbox('delete_image'); $this->frm->addRadiobutton('hidden', $rbtHiddenValues, $this->record['hidden']); foreach ((array) BackendModel::get('fork.settings')->get('Core', 'languages') as $key => $language) { $addressesLanguage = BackendAddressesModel::getLanguage($this->id, $language); $fieldText = $this->frm->addEditor("text_" . strtolower($language), $addressesLanguage['text']); $fieldOpeningHours = $this->frm->addEditor("opening_hours_" . strtolower($language), $addressesLanguage['opening_hours']); $this->fieldLanguages[$key]["key"] = $key; $this->fieldLanguages[$key]["language"] = $language; $this->fieldLanguages[$key]["text"] = $fieldText->parse(); $this->fieldLanguages[$key]["opening_hours"] = $fieldOpeningHours->parse(); } //--Get all the groups $groups = BackendAddressesModel::getAllGroups(); if (!empty($groups)) { //--Loop all the users foreach ($groups as &$group) { $groupCheckboxes[] = array("label" => $group["title"], "value" => $group["id"]); } //--Get the users from the group $groupsAddress = BackendAddressesModel::getGroupsForAddress($this->id); //--Create a selected-array $groupCheckboxesSelected = count($groupsAddress) > 0 ? array_keys($groupsAddress) : null; //--Add multicheckboxes to form $this->frm->addMultiCheckbox("groups", $groupCheckboxes, $groupCheckboxesSelected); } $groups2 = BackendAddressesModel::getAllGroupsTreeArray(); $this->tpl->assign('groups2', $groups2); $this->tpl->assign('groups2selected', $groupCheckboxesSelected == null ? array() : $groupCheckboxesSelected); // meta $this->meta = new BackendMeta($this->frm, $this->record['meta_id'], 'company', true); $this->meta->setUrlCallback('Backend\\Modules\\Addresses\\Engine\\Model', 'getUrl', array($this->record['id'])); }
/** * Returns template for event detail * * @return \Symfony\Component\HttpFoundation\Response */ public function eventDetailAction() { $countries = array(); foreach (Intl::getRegionBundle()->getCountryNames() as $alpha2 => $country) { $countries[] = array('id' => $alpha2, 'name' => $country); } return $this->render('SuluEventBundle:Event:detail.html.twig', array('countries' => $countries)); }
/** * @param CountryInterface[] $countries * * @return array */ private function getCountryCodes(array $countries) { $countryCodes = []; /* @var CountryInterface $country */ foreach ($countries as $country) { $countryCodes[$country->getCode()] = Intl::getRegionBundle()->getCountryName($country->getCode()); } return $countryCodes; }
/** * {@inheritdoc} */ public function convertToCode($name, $locale = 'en') { $names = Intl::getRegionBundle()->getCountryNames($locale); $countryCode = array_search($name, $names, true); if (false === $countryCode) { throw new \InvalidArgumentException(sprintf('Country "%s" not found! Available names: %s.', $name, implode(', ', $names))); } return $countryCode; }
/** * @param string $name * * @return string * * @throws \InvalidArgumentException If name is not found in country code registry. */ private function getCountryCodeByEnglishCountryName($name) { $names = Intl::getRegionBundle()->getCountryNames('en'); $countryCode = array_search($name, $names, true); if (null === $countryCode) { throw new \InvalidArgumentException(sprintf('Country "%s" not found! Available names: %s.', $name, implode(', ', $names))); } return $countryCode; }
/** * @Given /^there is a zone "The Rest of the World" containing all other countries$/ */ public function thereIsAZoneTheRestOfTheWorldContainingAllOtherCountries() { $restOfWorldCountries = array_diff(array_keys(Intl::getRegionBundle()->getCountryNames('en')), array_merge($this->euMembers, ['US'])); $zone = $this->zoneFactory->createWithMembers($restOfWorldCountries); $zone->setType(ZoneInterface::TYPE_COUNTRY); $zone->setCode('RoW'); $zone->setName('The Rest of the World'); $this->zoneRepository->add($zone); }
function country_name($code) { $countries = Intl::getRegionBundle()->getCountryNames(); $name = $countries[$code]; if (!$name) { $name = $code; } return $name; }
/** * {@inheritdoc} */ public function buildViewCell(Cell $cell, Table $table, array $options) { parent::buildViewCell($cell, $table, $options); $label = ' '; if (array_key_exists($cell->vars['value'], $options['choices'])) { $label = Intl::getRegionBundle()->getCountryName($cell->vars['value']); } $cell->setVars(['label' => $label, 'type' => 'choice']); }
/** * Should be private, used public to support PHP 5.3 * * @internal * * @return array */ public function getAvailableCountries() { $availableCountries = Intl::getRegionBundle()->getCountryNames(); /** @var CountryInterface[] $definedCountries */ $definedCountries = $this->countryRepository->findAll(); foreach ($definedCountries as $country) { unset($availableCountries[$country->getIsoName()]); } return $availableCountries; }
/** * Load the form */ private function loadForm() { $this->frm = new BackendForm('add'); $this->frm->addText('title', null, null, 'inputText title', 'inputTextError title'); $this->frm->addText('street'); $this->frm->addText('number'); $this->frm->addText('zip'); $this->frm->addText('city'); $this->frm->addDropdown('country', Intl::getRegionBundle()->getCountryNames(BL::getInterfaceLanguage()), 'BE'); }
/** * Installs the given countries by codes. * * @param array $codes * * @throws \Exception */ public function installCountries($codes = array('US')) { if (empty($codes)) { throw new \Exception("Expected non empty array of enabled country codes."); } $countryNames = Intl::getRegionBundle()->getCountryNames(); // TODO locale asort($countryNames); $this->generate(Country::class, $countryNames, $codes); }
/** * Creates a CountryRepository instance. */ public function __construct() { if (class_exists('\\CommerceGuys\\Intl\\Country\\CountryRepository')) { $this->countryRepository = new \CommerceGuys\Intl\Country\CountryRepository(); } elseif (class_exists('\\Symfony\\Component\\Intl\\Intl')) { $this->regionBundle = \Symfony\Component\Intl\Intl::getRegionBundle(); } else { throw new \RuntimeException('No source of country data found: symfony/intl or commerceguys/intl must be installed.'); } }
/** * Gets country name by code. * * @param string $code * @param string $culture * * @return string */ public function country($code, $culture = null) { if (!$code) { return; } if (!$this->countries) { $this->countries = Intl::getRegionBundle()->getCountryNames($culture); } return $this->countries[strtoupper($code)]; }
/** * @param GenderizeClient $genderizeClient */ public function __construct(GenderizeClient $genderizeClient = null) { if ($genderizeClient) { $this->genderizeClient = $genderizeClient; } else { // create default client $this->genderizeClient = new GenderizeClient('https://api.genderize.io/'); } $this->validCountries = Intl::getRegionBundle()->getCountryNames(); $this->validLanguages = Intl::getLanguageBundle()->getLanguageNames(); }
/** * @param ObjectManager $objectManager */ public function load(ObjectManager $objectManager) { $csvIterator = new CsvIterator($this->container->getParameter('sulu_event.csv_import_file')); \Locale::setDefault('de'); $countries = Intl::getRegionBundle()->getCountryNames(); $geocoder = new GoogleMaps(new GuzzleHttpAdapter(), true, $this->container->getParameter('sulu_event.google_maps_api_key')); $output = $this->getConsoleOutput(); foreach ($csvIterator as $row => $data) { if (empty($data)) { break; } if ($row == 1) { continue; } // sleep 1 second to prevent Google Geocode API from going OVER_QUERY_LIMIT sleep(1); $event = new Event(); $event->setTitle(trim($data[0]) === '' ? 'Nicht definierter Event-Titel' : $data[0]); $event->setStartDate(new \DateTime($data[1])); if (!empty($data[2])) { $event->setStartTime(new \DateTime($data[2])); } $event->setDescription('<p>' . $data[3] . '</p>'); $event->setDescriptionVenue('<p>' . $data[4] . '</p>'); $event->setZip($data[5]); $event->setCity($data[6]); $countryAlpha2 = array_keys($countries, $data[7]); $event->setCountry(isset($countryAlpha2[0]) ? $countryAlpha2[0] : 'DE'); $organizer = new EventOrganizer(); $organizer->setTitle($data[10]); $organizer->setFirstName($data[11]); $organizer->setLastName($data[12]); $organizer->setStreet($data[13]); $organizer->setZip($data[14]); $organizer->setCity($data[15]); $organizer->setPhone($data[16]); $organizer->setFax($data[17]); $organizer->setEmail($data[18]); $event->setOrganizer($organizer); $result = $geocoder->geocode($data[4] . '+' . $data[5]); if (isset($result->results[0])) { $event->setLatitude($result->results[0]->geometry->location->lat); $event->setLongitude($result->results[0]->geometry->location->lng); } else { $error = 'No geocoding data at event ' . $data[0] . '(row ' . $row . ') with status' . $result->status; $output->writeln($error); $event->setLatitude(0); $event->setLongitude(0); } $event->setWebsite($data[19]); $objectManager->persist($event); } $objectManager->flush(); }
/** * {@inheritdoc} */ public function load(ObjectManager $manager) { $restOfWorldCountries = array_diff(array_keys(Intl::getRegionBundle()->getCountryNames($this->container->getParameter('sylius.locale'))), $this->euCountries + array('US')); $manager->persist($eu = $this->createZone('EU', ZoneInterface::TYPE_COUNTRY, $this->euCountries)); $manager->persist($this->createZone('USA', ZoneInterface::TYPE_COUNTRY, array('US'))); $manager->persist($this->createZone('EU + USA', ZoneInterface::TYPE_ZONE, array('EU', 'USA'))); $manager->persist($this->createZone('Rest of World', ZoneInterface::TYPE_COUNTRY, $restOfWorldCountries)); $manager->flush(); $settingsManager = $this->get('sylius.settings.manager'); $settings = $settingsManager->loadSettings('sylius_taxation'); $settings->set('default_tax_zone', $eu); $settingsManager->saveSettings('sylius_taxation', $settings); }
/** * {@inheritdoc} */ public function load(ObjectManager $manager) { $restOfWorldCountries = array_diff(array_keys(Intl::getRegionBundle()->getCountryNames($this->container->getParameter('locale'))), array_merge($this->euCountries, ['US'])); $manager->persist($eu = $this->createZone('EU', 'European Union', ZoneInterface::TYPE_COUNTRY, $this->euCountries)); $manager->persist($this->createZone('USA', 'United States of America', ZoneInterface::TYPE_COUNTRY, ['US'])); $manager->persist($this->createZone('EUSA', 'EU + USA', ZoneInterface::TYPE_ZONE, ['EU', 'USA'])); $manager->persist($this->createZone('RoW', 'Rest of World', ZoneInterface::TYPE_COUNTRY, $restOfWorldCountries)); $manager->flush(); $settingsManager = $this->get('sylius.settings.manager'); $settings = $settingsManager->load('sylius_taxation'); $settings->set('default_tax_zone', $eu); $settingsManager->save($settings); }
/** * {@inheritdoc} */ public function validate($value, Constraint $constraint) { if (null === $value || '' === $value) { return; } if (!is_scalar($value) && !(is_object($value) && method_exists($value, '__toString'))) { throw new UnexpectedTypeException($value, 'string'); } $value = (string) $value; $countries = Intl::getRegionBundle()->getCountryNames(); if (!isset($countries[$value])) { $this->context->addViolation($constraint->message, array('{{ value }}' => $value)); } }