user_payment.php

Go to the documentation of this file.
00001 <?php
00002 
00008 class User_Payment extends oxAdminDetails
00009 {
00010 
00016     protected $_blDelete = false;
00017 
00023     protected $_oActiveUser = null;
00024 
00030     protected $_sPaymentId = null;
00031 
00037     protected $_oPaymentTypes = null;
00038 
00044     protected $_oUserPayment = null;
00045 
00051     protected $_oUserPayments = null;
00052 
00059     public function render()
00060     {
00061         parent::render();
00062         $this->_aViewData["edit"] = $this->getSelUserPayment();
00063         $this->_aViewData["oxpaymentid"] = $this->getPaymentId();
00064         $this->_aViewData["paymenttypes"] = $this->getPaymentTypes();
00065         $this->_aViewData["edituser"] = $this->getUser();
00066         $this->_aViewData["userpayments"] = $this->getUserPayments();
00067         $sOxId = $this->getEditObjectId();
00068 
00069         if (!$this->_allowAdminEdit($sOxId)) {
00070             $this->_aViewData['readonly'] = true;
00071         }
00072 
00073 
00074         return "user_payment.tpl";
00075     }
00076 
00080     public function save()
00081     {
00082         parent::save();
00083 
00084         $soxId = $this->getEditObjectId();
00085         if ($this->_allowAdminEdit($soxId)) {
00086 
00087             $aParams = oxRegistry::getConfig()->getRequestParameter("editval");
00088             $aDynvalues = oxRegistry::getConfig()->getRequestParameter("dynvalue");
00089 
00090             if (isset($aDynvalues)) {
00091                 // store the dynvalues
00092                 $aParams['oxuserpayments__oxvalue'] = oxRegistry::getUtils()->assignValuesToText($aDynvalues);
00093             }
00094 
00095             if ($aParams['oxuserpayments__oxid'] == "-1") {
00096                 $aParams['oxuserpayments__oxid'] = null;
00097             }
00098 
00099             $oAdress = oxNew("oxuserpayment");
00100             $oAdress->assign($aParams);
00101             $oAdress->save();
00102         }
00103     }
00104 
00108     public function delPayment()
00109     {
00110         $aParams = oxRegistry::getConfig()->getRequestParameter("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                 // load object
00134                 $this->_oActiveUser = oxNew("oxuser");
00135                 $this->_oActiveUser->load($sOxId);
00136             }
00137         }
00138 
00139         return $this->_oActiveUser;
00140     }
00141 
00147     public function getPaymentId()
00148     {
00149         if ($this->_sPaymentId == null) {
00150             $this->_sPaymentId = oxRegistry::getConfig()->getRequestParameter("oxpaymentid");
00151             if (!$this->_sPaymentId || $this->_blDelete) {
00152                 if ($oUser = $this->getUser()) {
00153                     $oUserPayments = $oUser->getUserPayments();
00154                     if (isset($oUserPayments[0])) {
00155                         $this->_sPaymentId = $oUserPayments[0]->oxuserpayments__oxid->value;
00156                     }
00157                 }
00158             }
00159             if (!$this->_sPaymentId) {
00160                 $this->_sPaymentId = "-1";
00161             }
00162         }
00163 
00164         return $this->_sPaymentId;
00165     }
00166 
00172     public function getPaymentTypes()
00173     {
00174         if ($this->_oPaymentTypes == null) {
00175 
00176             // all paymenttypes
00177             $this->_oPaymentTypes = oxNew("oxlist");
00178             $this->_oPaymentTypes->init("oxpayment");
00179             $oListObject = $this->_oPaymentTypes->getBaseObject();
00180             $oListObject->setLanguage(oxRegistry::getLang()->getObjectTplLanguage());
00181             $this->_oPaymentTypes->getList();
00182         }
00183 
00184         return $this->_oPaymentTypes;
00185     }
00186 
00192     public function getSelUserPayment()
00193     {
00194         if ($this->_oUserPayment == null) {
00195             $this->_oUserPayment = false;
00196             $sPaymentId = $this->getPaymentId();
00197             if ($sPaymentId != "-1" && isset($sPaymentId)) {
00198                 $this->_oUserPayment = oxNew("oxuserpayment");
00199                 $this->_oUserPayment->load($sPaymentId);
00200                 $sTemplate = $this->_oUserPayment->oxuserpayments__oxvalue->value;
00201 
00202                 // generate selected paymenttype
00203                 $oPaymentTypes = $this->getPaymentTypes();
00204                 foreach ($oPaymentTypes as $oPayment) {
00205                     if ($oPayment->oxpayments__oxid->value == $this->_oUserPayment->oxuserpayments__oxpaymentsid->value) {
00206                         $oPayment->selected = 1;
00207                         // if there are no values assigned we set default from paymenttype
00208                         if (!$sTemplate) {
00209                             $sTemplate = $oPayment->oxpayments__oxvaldesc->value;
00210                         }
00211                         break;
00212                     }
00213                 }
00214                 $this->_oUserPayment->setDynValues(oxRegistry::getUtils()->assignValuesFromText($sTemplate));
00215             }
00216         }
00217 
00218         return $this->_oUserPayment;
00219     }
00220 
00226     public function getUserPayments()
00227     {
00228         if ($this->_oUserPayments == null) {
00229             $this->_oUserPayments = false;
00230             if ($oUser = $this->getUser()) {
00231                 $sTplLang = oxRegistry::getLang()->getObjectTplLanguage();
00232                 $sPaymentId = $this->getPaymentId();
00233                 $this->_oUserPayments = $oUser->getUserPayments();
00234                 // generate selected
00235                 foreach ($this->_oUserPayments as $oUserPayment) {
00236                     $oPayment = oxNew('oxpayment');
00237                     $oPayment->setLanguage($sTplLang);
00238                     $oPayment->load($oUserPayment->oxuserpayments__oxpaymentsid->value);
00239                     $oUserPayment->oxpayments__oxdesc = clone $oPayment->oxpayments__oxdesc;
00240                     if ($oUserPayment->oxuserpayments__oxid->value == $sPaymentId) {
00241                         $oUserPayment->selected = 1;
00242                         break;
00243                     }
00244                 }
00245             }
00246         }
00247 
00248         return $this->_oUserPayments;
00249     }
00250 }