00001 <?php
00002
00009 class oxUserPayment extends oxBase
00010 {
00011
00012
00013
00014
00015
00016
00022 protected $_sPaymentKey = 'fq45QS09_fqyx09239QQ';
00023
00029 protected $_sClassName = 'oxuserpayment';
00030
00036 protected $_blStoreCreditCardInfo = null;
00037
00043 protected $_oPayment = null;
00044
00050 protected $_aDynValues = null;
00051
00059 public function __get( $sName )
00060 {
00061
00062 if ( $sName == 'oxpayments__oxdesc' ) {
00063 if ( $this->_oPayment === null ) {
00064 $this->_oPayment = oxNew( 'oxpayment' );
00065 $this->_oPayment->load( $this->oxuserpayments__oxpaymentsid->value );
00066 }
00067 return $this->_oPayment->oxpayments__oxdesc;
00068 }
00069
00070 if ( $sName == 'aDynValues' ) {
00071 if ( $this->_aDynValues === null ) {
00072 $this->_aDynValues = $this->getDynValues();
00073 }
00074 return $this->_aDynValues;
00075 }
00076
00077 return parent::__get( $sName );
00078 }
00079
00083 public function __construct()
00084 {
00085 parent::__construct();
00086 $this->init( 'oxuserpayments' );
00087 $this->_sPaymentKey = oxUtils::getInstance()->strRot13( $this->_sPaymentKey );
00088 $this->setStoreCreditCardInfo( $this->getConfig()->getConfigParam( 'blStoreCreditCardInfo' ) );
00089 }
00090
00096 public function getPaymentKey()
00097 {
00098 return $this->_sPaymentKey;
00099 }
00100
00108 public function load( $sOxId )
00109 {
00110 $sSelect = 'select oxid, oxuserid, oxpaymentsid, DECODE( oxvalue, "'.$this->getPaymentKey().'" ) as oxvalue
00111 from oxuserpayments where oxid = '. oxDb::getDb()->quote( $sOxId );
00112
00113 return $this->assignRecord( $sSelect );
00114 }
00115
00116
00122 protected function _insert()
00123 {
00124
00125
00126 if ( !$this->getStoreCreditCardInfo() && $this->oxuserpayments__oxpaymentsid->value == 'oxidcreditcard' ) {
00127 return true;
00128 }
00129
00130
00131 if ( $sValue = $this->oxuserpayments__oxvalue->value ) {
00132 $sEncodedValue = oxDb::getDb()->getOne( "select encode( '$sValue', '" . $this->getPaymentKey() . "' )" );
00133 $this->oxuserpayments__oxvalue->setValue($sEncodedValue);
00134 }
00135
00136 return parent::_insert();
00137 }
00138
00144 protected function _update()
00145 {
00146
00147 if ( $sValue = $this->oxuserpayments__oxvalue->value ) {
00148 $sEncodedValue = oxDb::getDb()->getOne( "select encode( '$sValue', '" . $this->getPaymentKey() . "' )" );
00149 $this->oxuserpayments__oxvalue->setValue($sEncodedValue);
00150 }
00151
00152 return parent::_update();
00153 }
00154
00162 public function setStoreCreditCardInfo( $blStoreCreditCardInfo )
00163 {
00164 $this->_blStoreCreditCardInfo = $blStoreCreditCardInfo;
00165 }
00166
00172 public function getStoreCreditCardInfo()
00173 {
00174 return $this->_blStoreCreditCardInfo;
00175 }
00176
00185 public function getPaymentByPaymentType( $oUser = null, $sPaymentType = null )
00186 {
00187 $blGet = false;
00188 if ( $oUser && $sPaymentType != null ) {
00189 $sSelect = 'select oxid from oxuserpayments where oxpaymentsid="' . $sPaymentType . '" and oxuserid="' . $oUser->getId() . '" ';
00190 if ( ( $sOxId = oxDb::getDb()->getOne( $sSelect ) ) ) {
00191 $blGet = $this->load( $sOxId );
00192 }
00193 }
00194
00195 return $blGet;
00196 }
00197
00203 public function getDynValues()
00204 {
00205 if ( !$this->getStoreCreditCardInfo() && $this->oxuserpayments__oxpaymentsid->value == 'oxidcreditcard' ) {
00206 return null;
00207 }
00208
00209 if ( !$this->_aDynValues ) {
00210 $this->_aDynValues = oxUtils::getInstance()->assignValuesFromText( $this->oxuserpayments__oxvalue->value );
00211 }
00212 return $this->_aDynValues;
00213 }
00214
00222 public function setDynValues( $aDynValues )
00223 {
00224 $this->_aDynValues = $aDynValues;
00225 }
00226
00227 }