user_payment.php

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 
00081         $soxId = oxConfig::getParameter( "oxid");
00082         if ( $this->_allowAdminEdit( $soxId ) ) {
00083 
00084             $aParams    = oxConfig::getParameter( "editval");
00085             $aDynvalues = oxConfig::getParameter( "dynvalue");
00086 
00087             if ( isset( $aDynvalues ) ) {
00088                 // store the dynvalues
00089                 $aParams['oxuserpayments__oxvalue'] = oxUtils::getInstance()->assignValuesToText( $aDynvalues );
00090             }
00091 
00092             if ( $aParams['oxuserpayments__oxid'] == "-1" ) {
00093                 $aParams['oxuserpayments__oxid'] = null;
00094             }
00095 
00096             $oAdress = oxNew( "oxuserpayment" );
00097             $oAdress->assign( $aParams );
00098             $oAdress->save();
00099         }
00100     }
00101 
00107     public function delPayment()
00108     {
00109         $aParams = oxConfig::getParameter( "editval" );
00110         $soxId   = oxConfig::getParameter( "oxid" );
00111         if ( $this->_allowAdminEdit( $soxId )) {
00112             if ( $aParams['oxuserpayments__oxid'] != "-1") {
00113                 $oAdress = oxNew( "oxuserpayment" );
00114                 if ( $oAdress->load( $aParams['oxuserpayments__oxid'] ) ) {
00115                     $this->_blDelete = ( bool ) $oAdress->delete();
00116                 }
00117             }
00118         }
00119     }
00120 
00126     public function getUser()
00127     {
00128         if ( $this->_oActiveUser == null ) {
00129             $this->_oActiveUser = false;
00130             $sOxId = oxConfig::getParameter( "oxid");
00131             if ( $sOxId != "-1" && isset( $sOxId)) {
00132                 // load object
00133                 $this->_oActiveUser = oxNew( "oxuser" );
00134                 $this->_oActiveUser->load( $sOxId);
00135             }
00136         }
00137         return $this->_oActiveUser;
00138     }
00139 
00145     public function getPaymentId()
00146     {
00147         if ( $this->_sPaymentId == null ) {
00148             $this->_sPaymentId = oxConfig::getParameter( "oxpaymentid");
00149             if ( !$this->_sPaymentId || $this->_blDelete ) {
00150                 if ( $oUser = $this->getUser() ) {
00151                    $oUserPayments = $oUser->getUserPayments();
00152                    if ( isset( $oUserPayments[0]) ) {
00153                        $this->_sPaymentId = $oUserPayments[0]->oxuserpayments__oxid->value;
00154                    }
00155                 }
00156             }
00157             if ( !$this->_sPaymentId ) {
00158                 $this->_sPaymentId = "-1";
00159             }
00160         }
00161         return $this->_sPaymentId;
00162     }
00163 
00169     public function getPaymentTypes()
00170     {
00171         if ( $this->_oPaymentTypes == null ) {
00172 
00173             // all paymenttypes
00174             $this->_oPaymentTypes = oxNew( "oxlist" );
00175             $this->_oPaymentTypes->init( "oxpayment");
00176             $oListObject = $this->_oPaymentTypes->getBaseObject();
00177             $oListObject->setLanguage( oxLang::getInstance()->getObjectTplLanguage() );
00178             $this->_oPaymentTypes->getList();
00179         }
00180         return $this->_oPaymentTypes;
00181     }
00182 
00188     public function getSelUserPayment()
00189     {
00190         if ( $this->_oUserPayment == null ) {
00191             $this->_oUserPayment = false;
00192             $sPaymentId = $this->getPaymentId();
00193             if ( $sPaymentId != "-1" && isset( $sPaymentId ) ) {
00194                 $this->_oUserPayment = oxNew( "oxuserpayment" );
00195                 $this->_oUserPayment->load( $sPaymentId );
00196                 $sTemplate = $this->_oUserPayment->oxuserpayments__oxvalue->value;
00197 
00198                 // generate selected paymenttype
00199                 $oPaymentTypes = $this->getPaymentTypes();
00200                 foreach ( $oPaymentTypes as $oPayment ) {
00201                     if ( $oPayment->oxpayments__oxid->value == $this->_oUserPayment->oxuserpayments__oxpaymentsid->value) {
00202                         $oPayment->selected = 1;
00203                         // if there are no values assigned we set default from paymenttype
00204                         if ( !$sTemplate )
00205                             $sTemplate = $oPayment->oxpayments__oxvaldesc->value;
00206                         break;
00207                     }
00208                 }
00209                 $this->_oUserPayment->setDynValues( oxUtils::getInstance()->assignValuesFromText( $sTemplate ) );
00210             }
00211         }
00212         return $this->_oUserPayment;
00213     }
00214 
00220     public function getUserPayments()
00221     {
00222         if ( $this->_oUserPayments == null ) {
00223             $this->_oUserPayments = false;
00224             if ( $oUser = $this->getUser() ) {
00225                 $sTplLang = oxLang::getInstance()->getObjectTplLanguage();
00226                 $sPaymentId = $this->getPaymentId();
00227                 $this->_oUserPayments = $oUser->getUserPayments();
00228                 // generate selected
00229                 foreach ( $this->_oUserPayments as $oUserPayment ) {
00230                     $oPayment = oxNew( 'oxpayment' );
00231                     $oPayment->setLanguage( $sTplLang );
00232                     $oPayment->load( $oUserPayment->oxuserpayments__oxpaymentsid->value );
00233                     $oUserPayment->oxpayments__oxdesc = clone $oPayment->oxpayments__oxdesc;
00234                     if ( $oUserPayment->oxuserpayments__oxid->value == $sPaymentId ) {
00235                         $oUserPayment->selected = 1;
00236                         break;
00237                     }
00238                 }
00239             }
00240         }
00241         return $this->_oUserPayments;
00242     }
00243 
00244 }