コード例 #1
0
ファイル: Item.php プロジェクト: bluesnowman/Chimera
 /**
  * This method return a new object with the transliterated value.
  *
  * @access public
  * @return MappingService\Data\Field\Item                   a new object with the transliterated
  *                                                          value
  *
  */
 public function transliterate()
 {
     if ($this->info->type == 'string') {
         $value = Common\String::transliterate($this->value)->__toString();
         return static::factory($this->name, $value);
     }
     return $this;
 }
コード例 #2
0
ファイル: Currency.php プロジェクト: bluesnowman/Chimera
 /**
  * This method returns ISO data for the specified currency.
  *
  * @access protected
  * @param string $currency                                  the currency to be queried
  * @return array                                            the data
  */
 protected function getCurrencyData($currency)
 {
     if (is_string($currency) || is_integer($currency)) {
         $currency = Core\Convert::toString($currency);
         $currency = preg_replace('/\\s+/', ' ', trim($currency));
         $length = strlen($currency);
         if ($length == 3) {
             $records = DB\SQL::select('locale')->from('Currencies')->where('CurrencyNumeric3', '=', $currency)->where('CurrencyAlpha3', '=', strtoupper($currency), 'OR')->limit(1)->query();
             if ($records->is_loaded()) {
                 return $records->current();
             }
         } else {
             $records = DB\SQL::select('locale')->before(function (DB\Connection\Driver $driver) {
                 $driver->get_resource()->createFunction('TRANSLITERATE', function ($string) {
                     return Common\String::transliterate($string)->__toString();
                 }, 1);
             })->from('Currencies')->where(DB\SQL::expr('LOWER([CurrencyName])'), '=', strtolower($currency))->where(DB\SQL::expr("LOWER(TRANSLITERATE([CurrencyName]))"), '=', Common\String::transliterate($currency)->toLowerCase()->__toString(), 'OR')->where(DB\SQL::expr('LOWER([CurrencySymbol])'), '=', strtolower($currency))->limit(1)->query();
             if ($records->is_loaded()) {
                 return $records->current();
             }
             $records = DB\SQL::select('locale')->before(function (DB\Connection\Driver $driver) {
                 $driver->get_resource()->createFunction('PREG_REPLACE', 'preg_replace', 3);
             })->from('Currencies')->where(DB\SQL::expr("LOWER(PREG_REPLACE('/[^a-z]/i', '', [CurrencyName]))"), '=', strtolower(preg_replace('/[^a-z]/i', '', $currency)))->limit(1)->query();
             if ($records->is_loaded()) {
                 return $records->current();
             }
             $records = DB\SQL::select('locale')->before(function (DB\Connection\Driver $driver) {
                 $driver->get_resource()->createFunction('TRANSLITERATE', function ($string) {
                     return Common\String::transliterate($string)->__toString();
                 }, 1);
             })->from('Currencies')->where(DB\SQL::expr('LOWER([CurrencyName])'), 'LIKE', '%' . strtolower($currency) . '%')->where(DB\SQL::expr("LOWER(TRANSLITERATE([CurrencyName]))"), 'LIKE', '%' . Common\String::transliterate($currency)->toLowerCase() . '%', 'OR')->limit(1)->query();
             if ($records->is_loaded()) {
                 return $records->current();
             }
             $records = DB\SQL::select('locale')->before(function (DB\Connection\Driver $driver) {
                 $driver->get_resource()->createFunction('SOUNDEX', 'soundex', 1);
             })->from('Currencies')->where(DB\SQL::expr("SOUNDEX([CurrencyName])"), '=', DB\SQL::expr("SOUNDEX('{$currency}')"))->limit(1)->query();
             if ($records->is_loaded()) {
                 return $records->current();
             }
         }
     }
     return array('CurrencyID' => 0, 'CurrencyName' => null, 'CurrencyNumeric3' => null, 'CurrencyAlpha3' => null, 'CurrencySymbol' => null, 'CurrencyDecimals' => -1);
 }