Go to the documentation of this file.00001 <?php
00002
00008 class User_Payment extends oxAdminDetails
00009 {
00014 protected $_blDelete = false;
00015
00021 protected $_oActiveUser = null;
00022
00028 protected $_sPaymentId = null;
00029
00035 protected $_oPaymentTypes = null;
00036
00042 protected $_oUserPayment = null;
00043
00049 protected $_oUserPayments = null;
00050
00057 public function render()
00058 {
00059 parent::render();
00060 $this->_aViewData["edit"] = $this->getSelUserPayment();
00061 $this->_aViewData["oxpaymentid"] = $this->getPaymentId();
00062 $this->_aViewData["paymenttypes"] = $this->getPaymentTypes();
00063 $this->_aViewData["edituser"] = $this->getUser();
00064 $this->_aViewData["userpayments"] = $this->getUserPayments();
00065
00066 if (!$this->_allowAdminEdit($soxId))
00067 $this->_aViewData['readonly'] = true;
00068
00069
00070 return "user_payment.tpl";
00071 }
00072
00078 public function save()
00079 {
00080 parent::save();
00081
00082 $soxId = $this->getEditObjectId();
00083 if ( $this->_allowAdminEdit( $soxId ) ) {
00084
00085 $aParams = oxConfig::getParameter( "editval");
00086 $aDynvalues = oxConfig::getParameter( "dynvalue");
00087
00088 if ( isset( $aDynvalues ) ) {
00089
00090 $aParams['oxuserpayments__oxvalue'] = oxUtils::getInstance()->assignValuesToText( $aDynvalues );
00091 }
00092
00093 if ( $aParams['oxuserpayments__oxid'] == "-1" ) {
00094 $aParams['oxuserpayments__oxid'] = null;
00095 }
00096
00097 $oAdress = oxNew( "oxuserpayment" );
00098 $oAdress->assign( $aParams );
00099 $oAdress->save();
00100 }
00101 }
00102
00108 public function delPayment()
00109 {
00110 $aParams = oxConfig::getParameter( "editval" );
00111 $soxId = $this->getEditObjectId();
00112 if ( $this->_allowAdminEdit( $soxId )) {
00113 if ( $aParams['oxuserpayments__oxid'] != "-1") {
00114 $oAdress = oxNew( "oxuserpayment" );
00115 if ( $oAdress->load( $aParams['oxuserpayments__oxid'] ) ) {
00116 $this->_blDelete = ( bool ) $oAdress->delete();
00117 }
00118 }
00119 }
00120 }
00121
00127 public function getUser()
00128 {
00129 if ( $this->_oActiveUser == null ) {
00130 $this->_oActiveUser = false;
00131 $sOxId = $this->getEditObjectId();
00132 if ( $sOxId != "-1" && isset( $sOxId)) {
00133
00134 $this->_oActiveUser = oxNew( "oxuser" );
00135 $this->_oActiveUser->load( $sOxId);
00136 }
00137 }
00138 return $this->_oActiveUser;
00139 }
00140
00146 public function getPaymentId()
00147 {
00148 if ( $this->_sPaymentId == null ) {
00149 $this->_sPaymentId = oxConfig::getParameter( "oxpaymentid");
00150 if ( !$this->_sPaymentId || $this->_blDelete ) {
00151 if ( $oUser = $this->getUser() ) {
00152 $oUserPayments = $oUser->getUserPayments();
00153 if ( isset( $oUserPayments[0]) ) {
00154 $this->_sPaymentId = $oUserPayments[0]->oxuserpayments__oxid->value;
00155 }
00156 }
00157 }
00158 if ( !$this->_sPaymentId ) {
00159 $this->_sPaymentId = "-1";
00160 }
00161 }
00162 return $this->_sPaymentId;
00163 }
00164
00170 public function getPaymentTypes()
00171 {
00172 if ( $this->_oPaymentTypes == null ) {
00173
00174
00175 $this->_oPaymentTypes = oxNew( "oxlist" );
00176 $this->_oPaymentTypes->init( "oxpayment");
00177 $oListObject = $this->_oPaymentTypes->getBaseObject();
00178 $oListObject->setLanguage( oxLang::getInstance()->getObjectTplLanguage() );
00179 $this->_oPaymentTypes->getList();
00180 }
00181 return $this->_oPaymentTypes;
00182 }
00183
00189 public function getSelUserPayment()
00190 {
00191 if ( $this->_oUserPayment == null ) {
00192 $this->_oUserPayment = false;
00193 $sPaymentId = $this->getPaymentId();
00194 if ( $sPaymentId != "-1" && isset( $sPaymentId ) ) {
00195 $this->_oUserPayment = oxNew( "oxuserpayment" );
00196 $this->_oUserPayment->load( $sPaymentId );
00197 $sTemplate = $this->_oUserPayment->oxuserpayments__oxvalue->value;
00198
00199
00200 $oPaymentTypes = $this->getPaymentTypes();
00201 foreach ( $oPaymentTypes as $oPayment ) {
00202 if ( $oPayment->oxpayments__oxid->value == $this->_oUserPayment->oxuserpayments__oxpaymentsid->value) {
00203 $oPayment->selected = 1;
00204
00205 if ( !$sTemplate )
00206 $sTemplate = $oPayment->oxpayments__oxvaldesc->value;
00207 break;
00208 }
00209 }
00210 $this->_oUserPayment->setDynValues( oxUtils::getInstance()->assignValuesFromText( $sTemplate ) );
00211 }
00212 }
00213 return $this->_oUserPayment;
00214 }
00215
00221 public function getUserPayments()
00222 {
00223 if ( $this->_oUserPayments == null ) {
00224 $this->_oUserPayments = false;
00225 if ( $oUser = $this->getUser() ) {
00226 $sTplLang = oxLang::getInstance()->getObjectTplLanguage();
00227 $sPaymentId = $this->getPaymentId();
00228 $this->_oUserPayments = $oUser->getUserPayments();
00229
00230 foreach ( $this->_oUserPayments as $oUserPayment ) {
00231 $oPayment = oxNew( 'oxpayment' );
00232 $oPayment->setLanguage( $sTplLang );
00233 $oPayment->load( $oUserPayment->oxuserpayments__oxpaymentsid->value );
00234 $oUserPayment->oxpayments__oxdesc = clone $oPayment->oxpayments__oxdesc;
00235 if ( $oUserPayment->oxuserpayments__oxid->value == $sPaymentId ) {
00236 $oUserPayment->selected = 1;
00237 break;
00238 }
00239 }
00240 }
00241 }
00242 return $this->_oUserPayments;
00243 }
00244
00245 }