本文整理汇总了PHP中sfCultureInfo::getInstance方法的典型用法代码示例。如果您正苦于以下问题:PHP sfCultureInfo::getInstance方法的具体用法?PHP sfCultureInfo::getInstance怎么用?PHP sfCultureInfo::getInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sfCultureInfo
的用法示例。
在下文中一共展示了sfCultureInfo::getInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addField
protected function addField($name)
{
switch ($name) {
case 'username':
$this->form->setDefault('username', $this->resource->username);
$this->form->setValidator('username', new sfValidatorString(array('required' => true)));
$this->form->setWidget('username', new sfWidgetFormInput());
break;
case 'email':
$this->form->setDefault('email', $this->resource->email);
$this->form->setValidator('email', new sfValidatorEmail(array('required' => true)));
$this->form->setWidget('email', new sfWidgetFormInput());
break;
case 'password':
case 'confirmPassword':
$this->form->setDefault($name, null);
// Required field only if a new user is being created
$this->form->setValidator($name, new sfValidatorString(array('required' => !isset($this->getRoute()->resource))));
$this->form->setWidget($name, new sfWidgetFormInputPassword());
break;
case 'groups':
$values = array();
$criteria = new Criteria();
$criteria->add(QubitAclUserGroup::USER_ID, $this->resource->id);
foreach (QubitAclUserGroup::get($criteria) as $item) {
$values[] = $item->groupId;
}
$choices = array();
$criteria = new Criteria();
$criteria->add(QubitAclGroup::ID, 99, Criteria::GREATER_THAN);
foreach (QubitAclGroup::get($criteria) as $item) {
$choices[$item->id] = $item->getName(array('cultureFallback' => true));
}
$this->form->setDefault('groups', $values);
$this->form->setValidator('groups', new sfValidatorPass());
$this->form->setWidget('groups', new sfWidgetFormSelect(array('choices' => $choices, 'multiple' => true)));
break;
case 'translate':
$c = sfCultureInfo::getInstance($this->context->user->getCulture());
$languages = $c->getLanguages();
$choices = array();
if (0 < count($langSettings = QubitSetting::getByScope('i18n_languages'))) {
foreach ($langSettings as $item) {
$choices[$item->name] = $languages[$item->name];
}
}
// Find existing translate permissions
$criteria = new Criteria();
$criteria->add(QubitAclPermission::USER_ID, $this->resource->id);
$criteria->add(QubitAclPermission::ACTION, 'translate');
$defaults = null;
if (null !== ($permission = QubitAclPermission::getOne($criteria))) {
$defaults = $permission->getConstants(array('name' => 'languages'));
}
$this->form->setDefault('translate', $defaults);
$this->form->setValidator('translate', new sfValidatorPass());
$this->form->setWidget('translate', new sfWidgetFormSelect(array('choices' => $choices, 'multiple' => true)));
break;
}
}
示例2: render_field
function render_field($field, $resource, array $options = array())
{
$options += array('name' => $field->getName());
$div = null;
$culture = sfContext::getInstance()->user->getCulture();
if (isset($resource) && $culture != $resource->sourceCulture && 0 < strlen($source = $resource->__get($options['name'], array('sourceCulture' => true)))) {
// TODO Are there cases where the direction of this <div/>'s containing
// block isn't the direction of the current culture?
$dir = null;
$sourceCultureInfo = sfCultureInfo::getInstance($resource->sourceCulture);
if (sfCultureInfo::getInstance($culture)->direction != $sourceCultureInfo->direction) {
$dir = " dir=\"{$sourceCultureInfo->direction}\"";
}
$div = <<<div
<div class="default-translation"{$dir}>
{$source}
</div>
div;
}
unset($options['name']);
return <<<return
<div class="form-item">
{$field->renderLabel()}
{$field->renderError()}
{$div}
{$field->render($options)}
{$field->renderHelp()}
</div>
return;
}
示例3: getComputedAddress
public function getComputedAddress($culture = 'en')
{
$address = $this->getField(Petition::FIELD_ADDRESS);
$postcode = $this->getField(Petition::FIELD_POSTCODE);
$city = $this->getField(Petition::FIELD_CITY);
try {
$country = sfCultureInfo::getInstance($culture)->getCountry($this->getField(Petition::FIELD_COUNTRY));
} catch (Exception $e) {
$country = $this->getField(Petition::FIELD_COUNTRY);
}
$ret = $this->getComputedName();
if ($address) {
$ret .= "\n" . $address;
}
if ($city) {
if ($postcode) {
$ret .= "\n" . $postcode . ' ' . $city;
} else {
$ret .= "\n" . $city;
}
} else {
if ($postcode) {
$ret .= "\n" . $postcode;
}
}
if ($country) {
$ret .= "\n" . $country;
}
return $ret;
}
示例4: configure
public function configure()
{
unset($this['status'], $this['campaign_id'], $this['first_widget_id'], $this['email']);
$this->widgetSchema->setFormFormatterName('policat');
$countries_false = array_keys(sfCultureInfo::getInstance()->getCountries());
$countries = array();
foreach ($countries_false as $country) {
if (!is_numeric($country)) {
$countries[] = $country;
}
}
$countries = array_diff($countries, array('QU', 'ZZ', 'MF'));
$this->setWidget('country', new sfWidgetFormI18nChoiceCountry(array('countries' => $countries, 'add_empty' => 'Country')));
$this->setValidator('country', new sfValidatorI18nChoiceCountry(array('countries' => $countries, 'required' => true)));
//$this->setValidator('email', new ValidatorEmail());
$this->setWidget('password', new sfWidgetFormInputPassword(array(), array('autocomplete' => 'off')));
$this->setValidator('password', new sfValidatorString(array('min_length' => 20, 'max_length' => 100, 'required' => true)));
$this->setWidget('password_again', new sfWidgetFormInputPassword(array(), array('autocomplete' => 'off')));
$this->setValidator('password_again', new sfValidatorString());
$this->getWidgetSchema()->moveField('password_again', sfWidgetFormSchema::AFTER, 'password');
$this->getValidatorSchema()->setPostValidator(new sfValidatorSchemaCompare('password', '===', 'password_again', array(), array('invalid' => 'passwords do not match')));
$this->getWidgetSchema()->setHelp('password', 'at least 20 characters');
foreach (array('firstname', 'lastname', 'function', 'organisation', 'phone', 'address') as $field) {
$this->getValidator($field)->setOption('required', true);
}
}
示例5: configure
protected function configure($options = array(), $attributes = array())
{
parent::configure($options, $attributes);
$culture = sfContext::getInstance()->getUser()->getCulture();
$this->addOption('culture', $culture);
$this->addOption('languages');
$languages = sfCultureInfo::getInstance($culture)->getLanguages(isset($options['languages']) ? $options['languages'] : null);
$cultures = sfCultureInfo::getInstance($culture)->getCultures();
$countries = sfCultureInfo::getInstance($culture)->getCountries();
$values = array();
foreach ($cultures as $key => $culture_info) {
if (strlen($culture_info) == 5) {
$culture_small = substr($culture_info, 0, 2);
$countrie_small = substr($culture_info, 3, 2);
if (array_key_exists($culture_small, $languages) && array_key_exists($countrie_small, $countries)) {
$select_language = preg_replace('/^[' . $culture_small . ']{2}/i', $languages[$culture_small], $culture_info);
$select = preg_replace('/[' . $countrie_small . ']{2}$/i', '(' . $countries[$countrie_small] . ')', $select_language);
$values[$culture_info] = ucfirst(str_replace('_', ' ', $select));
}
}
}
if (count($values) == 0) {
$values[''] = 'No languages found';
}
asort($values);
$this->setOption('choices', $values);
}
示例6: setup
public function setup()
{
parent::setup();
$culture = sfContext::getInstance()->getUser()->getCulture();
$languages = sfCultureInfo::getInstance($culture)->getLanguages(sfConfig::get('app_a_i18n_languages'));
$this->setWidget('culture', new sfWidgetFormChoice(array('choices' => $languages)));
}
示例7: setup
public function setup()
{
parent::setup();
unset($this['created_at'], $this['updated_at']);
// checking that some polls are available
if (false === aPollToolkit::getAvailablePolls(false)) {
throw new sfException('Cannot find any poll item in apoll_settings_available_polls. Please, define some in app.yml');
}
$available_polls = aPollToolkit::getAvailablePolls();
$choices = array();
$choices_keys = array();
foreach ($available_polls as $key => $poll) {
$choices[$key] = isset($poll['name']) ? $poll['name'] : $key;
$choices_keys[] = $key;
}
$this->widgetSchema['type'] = new sfWidgetFormChoice(array('choices' => $choices));
$this->validatorSchema['type'] = new sfValidatorAnd(array(new sfValidatorChoice(array('choices' => $choices_keys, 'required' => true)), new aPollValidatorPollItem(array('poll_items' => aPollToolkit::getAvailablePolls()))), array('halt_on_error' => true));
$culture = sfContext::getInstance()->getUser()->getCulture();
$date_options = array('image' => '/apostrophePlugin/images/a-icon-datepicker.png', 'culture' => $culture, 'config' => '{changeMonth: true,changeYear: true}');
$time_attributes = array('twenty-four-hour' => true, 'minutes-increment' => 30);
$this->setWidget('published_from', new aWidgetFormJQueryDateTime(array('date' => $date_options), array('time' => $time_attributes)));
$this->setWidget('published_to', new aWidgetFormJQueryDateTime(array('date' => $date_options), array('time' => $time_attributes)));
$this->validatorSchema->setPostValidator(new sfValidatorCallback(array('callback' => array($this, 'validateEndDate'))));
$this->setWidget('submissions_allow_multiple', new aWidgetFormChoice(array('choices' => array(true => 'Yes', false => 'No'))));
$this->setWidget('submissions_delay', new sfWidgetFormTime(array('hours' => self::generateTwoCharsRange(0, 120)), $time_attributes));
// setting translation catalogue
$this->widgetSchema->getFormFormatter()->setTranslationCatalogue('apostrophe');
// embedding i18n fields
$culture = sfContext::getInstance()->getUser()->getCulture();
$languages = sfCultureInfo::getInstance($culture)->getLanguages(sfConfig::get('app_a_i18n_languages'));
$this->embedI18n(array_keys($languages));
foreach ($languages as $key => $value) {
$this->widgetSchema->setLabel($key, ucfirst($value));
}
}
示例8: _current_language
function _current_language()
{
try {
return sfContext::getInstance()->getUser()->getCulture();
} catch (Exception $e) {
return sfCultureInfo::getInstance()->getName();
}
}
示例9: getCultureSelect
protected function getCultureSelect()
{
if ($this->i18n->hasManyCultures()) {
$cultures = array();
foreach ($this->i18n->getCultures() as $key) {
$cultures[$key] = sfCultureInfo::getInstance($key)->getLanguage($key);
}
return new sfWidgetFormSelect(array('choices' => $cultures));
}
}
示例10: format_language
function format_language($language_iso, $culture = null)
{
$c = sfCultureInfo::getInstance($culture === null ? sfContext::getInstance()->getUser()->getCulture() : $culture);
$languages = $c->getLanguages();
if (!isset($languages[$language_iso])) {
$c = new sfCultureInfo(sfConfig::get('sf_default_culture'));
$languages = $c->getLanguages();
}
return isset($languages[$language_iso]) ? $languages[$language_iso] : $language_iso;
}
示例11: embedI18n
/**
* Embed i18n to the given form if it is enabled
*
* @param string $name
* @param sfForm $form
* @return void
*/
public static function embedI18n($name, sfForm $form)
{
if (sfSympalConfig::isI18nEnabled($name)) {
$context = sfContext::getInstance();
$culture = $context->getUser()->getEditCulture();
$form->embedI18n(array(strtolower($culture)));
$widgetSchema = $form->getWidgetSchema();
$context->getConfiguration()->loadHelpers(array('Helper'));
$c = sfCultureInfo::getInstance($culture);
$languages = $c->getLanguages();
$language = isset($languages[$culture]) ? $languages[$culture] : '';
$widgetSchema[$culture]->setLabel($language);
}
}
示例12: configure
/**
* Constructor.
*
* Available options:
*
* * culture: The culture to use for internationalized strings
* * add_empty: Whether to add a first empty value or not (false by default)
* If the option is not a Boolean, the value will be used as the text value
*
* @param array $options An array of options
* @param array $attributes An array of default HTML attributes
*
* @see sfWidgetFormChoice
*/
protected function configure($options = array(), $attributes = array())
{
parent::configure($options, $attributes);
$this->addOption('culture');
$this->addOption('add_empty', false);
$culture = isset($options['culture']) ? $options['culture'] : 'en';
$timezones = array_keys(sfCultureInfo::getInstance($culture)->getTimeZones());
$timezones = array_combine($timezones, $timezones);
$addEmpty = isset($options['add_empty']) ? $options['add_empty'] : false;
if (false !== $addEmpty) {
$timezones = array_merge(array('' => true === $addEmpty ? '' : $addEmpty), $timezones);
}
$this->setOption('choices', $timezones);
}
示例13: configure
/**
* Configures the current validator.
*
* Available options:
*
* * countries: An array of country codes to use (ISO 3166)
*
* @param array $options An array of options
* @param array $messages An array of error messages
*
* @see sfValidatorChoice
*/
protected function configure($options = array(), $messages = array())
{
parent::configure($options, $messages);
$this->addOption('countries');
// populate choices with all countries
$countries = array_keys(sfCultureInfo::getInstance()->getCountries());
// restrict countries to a sub-set
if (isset($options['countries'])) {
if ($problems = array_diff($options['countries'], $countries)) {
throw new InvalidArgumentException(sprintf('The following countries do not exist: %s.', implode(', ', $problems)));
}
$countries = $options['countries'];
}
$this->setOption('choices', $countries);
}
示例14: configure
/**
* Constructor.
*
* Available options:
*
* * culture: The culture to use for internationalized strings
* * countries: An array of country codes to use (ISO 3166)
* * add_empty: Whether to add a first empty value or not (false by default)
* If the option is not a Boolean, the value will be used as the text value
*
* @param array $options An array of options
* @param array $attributes An array of default HTML attributes
*
* @see sfWidgetFormChoice
*/
protected function configure($options = array(), $attributes = array())
{
parent::configure($options, $attributes);
$this->addOption('culture');
$this->addOption('countries');
$this->addOption('add_empty', false);
// populate choices with all countries
$culture = isset($options['culture']) ? $options['culture'] : 'en';
$countries = sfCultureInfo::getInstance($culture)->getCountries(isset($options['countries']) ? $options['countries'] : null);
$addEmpty = isset($options['add_empty']) ? $options['add_empty'] : false;
if (false !== $addEmpty) {
$countries = array_merge(array('' => true === $addEmpty ? '' : $addEmpty), $countries);
}
$this->setOption('choices', $countries);
}
示例15: getChoices
public function getChoices()
{
// populate choices with all languages
$culture = isset($this->options['culture']) ? $this->options['culture'] : 'en';
$languages = sfCultureInfo::getInstance($culture)->getLanguages(isset($this->options['languages']) ? $this->options['languages'] : null);
foreach ($languages as $iso => $language) {
if (!sfCultureInfo::validCulture($iso)) {
unset($languages[$iso]);
}
}
$addEmpty = isset($this->options['add_empty']) ? $this->options['add_empty'] : false;
if (false !== $addEmpty) {
$languages = array('' => true === $addEmpty ? '' : $addEmpty) + $languages;
}
return $languages;
}