コード例 #1
0
 function onInit() {
   parent::onInit();
   
   try {
     I18N::getCountries();
   } catch(Exception $e) {
     $this->available = false;
     return;
   }
   
   $this->form = new Form($this->getRequest(), new Location($this), Request::METHOD_GET);
   
   // Add the country select field
   $countries = I18N::getCountries();  // This returns all countries in form of cc => I18NCountry object pairs
   ksort($countries);                  // Sort the list by country code 
   foreach($countries as $k=>$v) {
     $countries[$k] = $v->getCode() . ' - ' . $v->getName();
   }
   // Now $countries is an array of cc => 'code - country' pairs
   $this->form->addField('country', new SelectInputField($this->getRequest()->getParameter('country'), $countries, '...'));
   
   // Add the lang select field
   $dialects = I18N::getDialects(); // This returns all dialects in form of cc_dc => I18NDialect object
   ksort($dialects);                // sorting by key will assure that dialects are sorted by their lang codes
   foreach($dialects as $k=>$v) {   // Create the dropdown select box for dialects
     $colls = $v->getCollations();  // We will add collations too
     foreach($colls as $collc=>$coll) {
       $dials[$k . '_' . $collc] = $v->getLanguage()->getCode() . ' - ' . $v->getName() . ' / ' . $coll->getName();
     }
     // Now $dials holds an array in form lc_dc_collc => 'lc - dialect / collation' pairs
   }
   $this->form->addField('dialect', new SelectInputField($this->getRequest()->getParameter('dialect'), $dials, '...'));    
   
   // Add the timezone select field
   $tzs = I18N::getTimeZones();     // This returns all timezones in form code => I18NTimeZone object
   uasort($tzs, array($this, 'tzSort'));  // We sort this array with the user function to have timezones sorted by GMT offset
   foreach($tzs as $k=>$v) {
     $tzs1[$k] = I18NTimeZone::formatOffset($v->getUTCOffset()) . ': ' . join(', ', $v->getLocations());
   }
   // Now $tzs1 is an array of code => '+HH:MM: locations' pairs  
   $this->form->addField('tz', new SelectInputField($this->getRequest()->getParameter('tz'), $tzs1, '...'));
   
   // Add the 'case sensitive collate' checkbox
   $this->form->addField('caseSensitive', new CheckBoxInputField($this->getRequest()->getParameter('caseSensitive')));
 }