|
eZ Publish
[trunk]
|
00001 <?php 00002 /** 00003 * File containing the eZExchangeRatesUpdateHandler class. 00004 * 00005 * @copyright Copyright (C) 1999-2012 eZ Systems AS. All rights reserved. 00006 * @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2 00007 * @version //autogentag// 00008 * @package kernel 00009 */ 00010 00011 class eZExchangeRatesUpdateHandler 00012 { 00013 const OK = 0; 00014 const CANT_CREATE_HANDLER = 1; 00015 const FAILED = 2; 00016 const EMPTY_RATE_LIST = 3; 00017 const UNKNOWN_BASE_CURRENCY = 4; 00018 const INVALID_BASE_CROSS_RATE = 5; 00019 00020 function eZExchangeRatesUpdateHandler() 00021 { 00022 $this->RateList = false; 00023 $this->BaseCurrency = false; 00024 00025 $this->initialize(); 00026 } 00027 00028 function initialize( $params = array() ) 00029 { 00030 if ( !isset( $params['BaseCurrency'] ) ) 00031 $params['BaseCurrency'] = ''; 00032 00033 $this->setBaseCurrency( $params['BaseCurrency'] ); 00034 } 00035 00036 /*! 00037 \static 00038 */ 00039 static function create( $handlerName = false ) 00040 { 00041 $shopINI = eZINI::instance( 'shop.ini' ); 00042 if ( $handlerName === false) 00043 { 00044 if ( $shopINI->hasVariable( 'ExchangeRatesSettings', 'ExchangeRatesUpdateHandler' ) ) 00045 $handlerName = $shopINI->variable( 'ExchangeRatesSettings', 'ExchangeRatesUpdateHandler' ); 00046 } 00047 00048 $handlerName = strtolower( $handlerName ); 00049 00050 $dirList = array(); 00051 $repositoryDirectories = $shopINI->variable( 'ExchangeRatesSettings', 'RepositoryDirectories' ); 00052 $extensionDirectories = $shopINI->variable( 'ExchangeRatesSettings', 'ExtensionDirectories' ); 00053 00054 $baseDirectory = eZExtension::baseDirectory(); 00055 foreach ( $extensionDirectories as $extensionDirectory ) 00056 { 00057 if ( !empty( $extensionDirectory ) ) 00058 $dirList[] = $baseDirectory . '/' . $extensionDirectory . '/exchangeratehandlers'; 00059 } 00060 00061 foreach ( $repositoryDirectories as $repositoryDirectory ) 00062 { 00063 if ( !empty( $repositoryDirectory ) ) 00064 $dirList[] = $repositoryDirectory; 00065 } 00066 00067 $foundHandler = false; 00068 foreach ( $dirList as $dir ) 00069 { 00070 $includeFile = "$dir/$handlerName/{$handlerName}handler.php"; 00071 00072 if ( file_exists( $includeFile ) ) 00073 { 00074 $foundHandler = true; 00075 break; 00076 } 00077 } 00078 00079 if ( !$foundHandler ) 00080 { 00081 eZDebug::writeError( "Exchange rates update handler '$handlerName' not found, " . 00082 "searched in these directories: " . 00083 implode( ', ', $dirList ), 00084 'eZExchangeRatesUpdateHandler::create' ); 00085 return false; 00086 } 00087 00088 require_once( $includeFile ); 00089 $className = $handlerName . 'handler'; 00090 return new $className; 00091 } 00092 00093 function rateList() 00094 { 00095 return $this->RateList; 00096 } 00097 00098 function setRateList( $rateList ) 00099 { 00100 $this->RateList = $rateList; 00101 } 00102 00103 function baseCurrency() 00104 { 00105 return $this->BaseCurrency; 00106 } 00107 00108 function setBaseCurrency( $baseCurrency ) 00109 { 00110 $this->BaseCurrency = $baseCurrency; 00111 } 00112 00113 function requestRates() 00114 { 00115 $error = array( 'code' => self::FAILED, 00116 'description' => ezpI18n::tr( 'kernel/shop', "eZExchangeRatesUpdateHandler: you should reimplement 'requestRates' method" ) ); 00117 00118 return $error; 00119 } 00120 00121 public $RateList; 00122 public $BaseCurrency; 00123 } 00124 00125 ?>