OXID eShop CE  4.8.11
 All Classes Files Functions Variables Pages
user_payment.php
Go to the documentation of this file.
1 <?php
2 
9 {
14  protected $_blDelete = false;
15 
21  protected $_oActiveUser = null;
22 
28  protected $_sPaymentId = null;
29 
35  protected $_oPaymentTypes = null;
36 
42  protected $_oUserPayment = null;
43 
49  protected $_oUserPayments = null;
50 
57  public function render()
58  {
60  $this->_aViewData["edit"] = $this->getSelUserPayment();
61  $this->_aViewData["oxpaymentid"] = $this->getPaymentId();
62  $this->_aViewData["paymenttypes"] = $this->getPaymentTypes();
63  $this->_aViewData["edituser"] = $this->getUser();
64  $this->_aViewData["userpayments"] = $this->getUserPayments();
65 
66  if (!$this->_allowAdminEdit($soxId))
67  $this->_aViewData['readonly'] = true;
68 
69 
70  return "user_payment.tpl";
71  }
72 
78  public function save()
79  {
80  parent::save();
81 
82  $soxId = $this->getEditObjectId();
83  if ( $this->_allowAdminEdit( $soxId ) ) {
84 
85  $aParams = oxConfig::getParameter( "editval");
86  $aDynvalues = oxConfig::getParameter( "dynvalue");
87 
88  if ( isset( $aDynvalues ) ) {
89  // store the dynvalues
90  $aParams['oxuserpayments__oxvalue'] = oxRegistry::getUtils()->assignValuesToText( $aDynvalues );
91  }
92 
93  if ( $aParams['oxuserpayments__oxid'] == "-1" ) {
94  $aParams['oxuserpayments__oxid'] = null;
95  }
96 
97  $oAdress = oxNew( "oxuserpayment" );
98  $oAdress->assign( $aParams );
99  $oAdress->save();
100  }
101  }
102 
108  public function delPayment()
109  {
110  $aParams = oxConfig::getParameter( "editval" );
111  $soxId = $this->getEditObjectId();
112  if ( $this->_allowAdminEdit( $soxId )) {
113  if ( $aParams['oxuserpayments__oxid'] != "-1") {
114  $oAdress = oxNew( "oxuserpayment" );
115  if ( $oAdress->load( $aParams['oxuserpayments__oxid'] ) ) {
116  $this->_blDelete = ( bool ) $oAdress->delete();
117  }
118  }
119  }
120  }
121 
127  public function getUser()
128  {
129  if ( $this->_oActiveUser == null ) {
130  $this->_oActiveUser = false;
131  $sOxId = $this->getEditObjectId();
132  if ( $sOxId != "-1" && isset( $sOxId)) {
133  // load object
134  $this->_oActiveUser = oxNew( "oxuser" );
135  $this->_oActiveUser->load( $sOxId);
136  }
137  }
138  return $this->_oActiveUser;
139  }
140 
146  public function getPaymentId()
147  {
148  if ( $this->_sPaymentId == null ) {
149  $this->_sPaymentId = oxConfig::getParameter( "oxpaymentid");
150  if ( !$this->_sPaymentId || $this->_blDelete ) {
151  if ( $oUser = $this->getUser() ) {
152  $oUserPayments = $oUser->getUserPayments();
153  if ( isset( $oUserPayments[0]) ) {
154  $this->_sPaymentId = $oUserPayments[0]->oxuserpayments__oxid->value;
155  }
156  }
157  }
158  if ( !$this->_sPaymentId ) {
159  $this->_sPaymentId = "-1";
160  }
161  }
162  return $this->_sPaymentId;
163  }
164 
170  public function getPaymentTypes()
171  {
172  if ( $this->_oPaymentTypes == null ) {
173 
174  // all paymenttypes
175  $this->_oPaymentTypes = oxNew( "oxlist" );
176  $this->_oPaymentTypes->init( "oxpayment");
177  $oListObject = $this->_oPaymentTypes->getBaseObject();
178  $oListObject->setLanguage( oxRegistry::getLang()->getObjectTplLanguage() );
179  $this->_oPaymentTypes->getList();
180  }
181  return $this->_oPaymentTypes;
182  }
183 
189  public function getSelUserPayment()
190  {
191  if ( $this->_oUserPayment == null ) {
192  $this->_oUserPayment = false;
193  $sPaymentId = $this->getPaymentId();
194  if ( $sPaymentId != "-1" && isset( $sPaymentId ) ) {
195  $this->_oUserPayment = oxNew( "oxuserpayment" );
196  $this->_oUserPayment->load( $sPaymentId );
197  $sTemplate = $this->_oUserPayment->oxuserpayments__oxvalue->value;
198 
199  // generate selected paymenttype
200  $oPaymentTypes = $this->getPaymentTypes();
201  foreach ( $oPaymentTypes as $oPayment ) {
202  if ( $oPayment->oxpayments__oxid->value == $this->_oUserPayment->oxuserpayments__oxpaymentsid->value) {
203  $oPayment->selected = 1;
204  // if there are no values assigned we set default from paymenttype
205  if ( !$sTemplate )
206  $sTemplate = $oPayment->oxpayments__oxvaldesc->value;
207  break;
208  }
209  }
210  $this->_oUserPayment->setDynValues( oxRegistry::getUtils()->assignValuesFromText( $sTemplate ) );
211  }
212  }
213  return $this->_oUserPayment;
214  }
215 
221  public function getUserPayments()
222  {
223  if ( $this->_oUserPayments == null ) {
224  $this->_oUserPayments = false;
225  if ( $oUser = $this->getUser() ) {
226  $sTplLang = oxRegistry::getLang()->getObjectTplLanguage();
227  $sPaymentId = $this->getPaymentId();
228  $this->_oUserPayments = $oUser->getUserPayments();
229  // generate selected
230  foreach ( $this->_oUserPayments as $oUserPayment ) {
231  $oPayment = oxNew( 'oxpayment' );
232  $oPayment->setLanguage( $sTplLang );
233  $oPayment->load( $oUserPayment->oxuserpayments__oxpaymentsid->value );
234  $oUserPayment->oxpayments__oxdesc = clone $oPayment->oxpayments__oxdesc;
235  if ( $oUserPayment->oxuserpayments__oxid->value == $sPaymentId ) {
236  $oUserPayment->selected = 1;
237  break;
238  }
239  }
240  }
241  }
242  return $this->_oUserPayments;
243  }
244 
245 }