00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 class Mage_Directory_Model_Mysql4_Currency_Collection extends Varien_Data_Collection_Db
00035 {
00036 protected $_currencyTable;
00037 protected $_currencyNameTable;
00038 protected $_currencyRateTable;
00039
00040 public function __construct()
00041 {
00042 $resource = Mage::getSingleton('core/resource');
00043 parent::__construct($resource->getConnection('directory_read'));
00044 $this->_currencyTable = $resource->getTableName('directory/currency');
00045 $this->_currencyNameTable = $resource->getTableName('directory/currency_name');
00046 $this->_currencyRateTable = $resource->getTableName('directory/currency_rate');
00047
00048 $this->_select->from(array('main_table'=>$this->_currencyNameTable));
00049
00050
00051
00052 $this->setItemObjectClass(Mage::getConfig()->getModelClassName('directory/currency'));
00053 }
00054
00055 public function joinRates($currency)
00056 {
00057 $alias = $currency.'_rate';
00058 $this->_select->joinLeft(array($alias=>$this->_currencyRateTable),
00059 $this->getConnection()->quoteInto("$alias.currency_to=main_table.currency_code AND $alias.currency_from=?", $currency),
00060 'rate');
00061 return $this;
00062 }
00063
00064
00065
00066
00067
00068
00069
00070 public function addLanguageFilter($lang=null)
00071 {
00072 if (is_null($lang)) {
00073 $lang = Mage::app()->getStore()->getLanguageCode();
00074 }
00075 $this->addFilter('language', "main_table.language_code='$lang'", 'string');
00076 return $this;
00077 }
00078
00079
00080
00081
00082
00083
00084
00085 public function addCodeFilter($code)
00086 {
00087 if (is_array($code)) {
00088 $this->addFilter("codes",
00089 $this->getConnection()->quoteInto("main_table.currency_code IN (?)", $code),
00090 'string'
00091 );
00092 }
00093 else {
00094 $this->addFilter("code_$code", "main_table.currency_code='$code'", 'string');
00095 }
00096 return $this;
00097 }
00098
00099 public function toOptionArray()
00100 {
00101 return $this->_toOptionArray('currency_code', 'currency_name');
00102 }
00103 }