当前位置: 首页>>代码示例>>PHP>>正文


PHP sfCultureInfo::getInstance方法代码示例

本文整理汇总了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;
     }
 }
开发者ID:nurfiantara,项目名称:ehri-ica-atom,代码行数:60,代码来源:editAction.class.php

示例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;
}
开发者ID:nurfiantara,项目名称:ehri-ica-atom,代码行数:32,代码来源:QubitHelper.php

示例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;
 }
开发者ID:uniteddiversity,项目名称:policat,代码行数:30,代码来源:PetitionSigningWave.class.php

示例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);
     }
 }
开发者ID:uniteddiversity,项目名称:policat,代码行数:26,代码来源:OwnerForm.class.php

示例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);
 }
开发者ID:alexhandzhiev,项目名称:sifact,代码行数:27,代码来源:sfExtraWidgetFormSelectCulture.class.php

示例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)));
 }
开发者ID:rbolliger,项目名称:apostrophePollPlugin,代码行数:7,代码来源:PluginaPollAnswerForm.class.php

示例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));
     }
 }
开发者ID:rbolliger,项目名称:apostrophePollPlugin,代码行数:35,代码来源:PluginaPollPollForm.class.php

示例8: _current_language

 function _current_language()
 {
     try {
         return sfContext::getInstance()->getUser()->getCulture();
     } catch (Exception $e) {
         return sfCultureInfo::getInstance()->getName();
     }
 }
开发者ID:rafaelgou,项目名称:brFormExtraPlugin,代码行数:8,代码来源:sfWidgetFormI18nNumber.php

示例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));
     }
 }
开发者ID:jdart,项目名称:diem,代码行数:10,代码来源:dmToolBarView.php

示例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;
}
开发者ID:nurfiantara,项目名称:ehri-ica-atom,代码行数:10,代码来源:I18NHelper.php

示例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);
     }
 }
开发者ID:RafalJachimczyk,项目名称:sympal,代码行数:21,代码来源:sfSympalFormToolkit.class.php

示例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);
 }
开发者ID:bigcalm,项目名称:urlcatcher,代码行数:28,代码来源:sfWidgetFormI18nChoiceTimezone.class.php

示例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);
 }
开发者ID:Phennim,项目名称:symfony1,代码行数:27,代码来源:sfValidatorI18nChoiceCountry.class.php

示例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);
 }
开发者ID:Phennim,项目名称:symfony1,代码行数:30,代码来源:sfWidgetFormI18nChoiceCountry.class.php

示例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;
 }
开发者ID:noreiller,项目名称:sfPlopPlugin,代码行数:16,代码来源:sfWidgetFormPlopI18nChoiceLanguage.class.php


注:本文中的sfCultureInfo::getInstance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。