OXID eShop CE  4.10.1
 All Classes Namespaces Files Functions Variables Pages
user_payment.php
Go to the documentation of this file.
1 <?php
2 
9 {
10 
16  protected $_blDelete = false;
17 
23  protected $_oActiveUser = null;
24 
30  protected $_sPaymentId = null;
31 
37  protected $_oPaymentTypes = null;
38 
44  protected $_oUserPayment = null;
45 
51  protected $_oUserPayments = null;
52 
59  public function render()
60  {
62  $this->_aViewData["edit"] = $this->getSelUserPayment();
63  $this->_aViewData["oxpaymentid"] = $this->getPaymentId();
64  $this->_aViewData["paymenttypes"] = $this->getPaymentTypes();
65  $this->_aViewData["edituser"] = $this->getUser();
66  $this->_aViewData["userpayments"] = $this->getUserPayments();
67  $sOxId = $this->getEditObjectId();
68 
69  if (!$this->_allowAdminEdit($sOxId)) {
70  $this->_aViewData['readonly'] = true;
71  }
72 
73 
74  return "user_payment.tpl";
75  }
76 
80  public function save()
81  {
82  parent::save();
83 
84  $soxId = $this->getEditObjectId();
85  if ($this->_allowAdminEdit($soxId)) {
86 
87  $aParams = oxRegistry::getConfig()->getRequestParameter("editval");
88  $aDynvalues = oxRegistry::getConfig()->getRequestParameter("dynvalue");
89 
90  if (isset($aDynvalues)) {
91  // store the dynvalues
92  $aParams['oxuserpayments__oxvalue'] = oxRegistry::getUtils()->assignValuesToText($aDynvalues);
93  }
94 
95  if ($aParams['oxuserpayments__oxid'] == "-1") {
96  $aParams['oxuserpayments__oxid'] = null;
97  }
98 
99  $oAdress = oxNew("oxuserpayment");
100  $oAdress->assign($aParams);
101  $oAdress->save();
102  }
103  }
104 
108  public function delPayment()
109  {
110  $aParams = oxRegistry::getConfig()->getRequestParameter("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 
139  return $this->_oActiveUser;
140  }
141 
147  public function getPaymentId()
148  {
149  if ($this->_sPaymentId == null) {
150  $this->_sPaymentId = oxRegistry::getConfig()->getRequestParameter("oxpaymentid");
151  if (!$this->_sPaymentId || $this->_blDelete) {
152  if ($oUser = $this->getUser()) {
153  $oUserPayments = $oUser->getUserPayments();
154  if (isset($oUserPayments[0])) {
155  $this->_sPaymentId = $oUserPayments[0]->oxuserpayments__oxid->value;
156  }
157  }
158  }
159  if (!$this->_sPaymentId) {
160  $this->_sPaymentId = "-1";
161  }
162  }
163 
164  return $this->_sPaymentId;
165  }
166 
172  public function getPaymentTypes()
173  {
174  if ($this->_oPaymentTypes == null) {
175 
176  // all paymenttypes
177  $this->_oPaymentTypes = oxNew("oxlist");
178  $this->_oPaymentTypes->init("oxpayment");
179  $oListObject = $this->_oPaymentTypes->getBaseObject();
180  $oListObject->setLanguage(oxRegistry::getLang()->getObjectTplLanguage());
181  $this->_oPaymentTypes->getList();
182  }
183 
184  return $this->_oPaymentTypes;
185  }
186 
192  public function getSelUserPayment()
193  {
194  if ($this->_oUserPayment == null) {
195  $this->_oUserPayment = false;
196  $sPaymentId = $this->getPaymentId();
197  if ($sPaymentId != "-1" && isset($sPaymentId)) {
198  $this->_oUserPayment = oxNew("oxuserpayment");
199  $this->_oUserPayment->load($sPaymentId);
200  $sTemplate = $this->_oUserPayment->oxuserpayments__oxvalue->value;
201 
202  // generate selected paymenttype
203  $oPaymentTypes = $this->getPaymentTypes();
204  foreach ($oPaymentTypes as $oPayment) {
205  if ($oPayment->oxpayments__oxid->value == $this->_oUserPayment->oxuserpayments__oxpaymentsid->value) {
206  $oPayment->selected = 1;
207  // if there are no values assigned we set default from paymenttype
208  if (!$sTemplate) {
209  $sTemplate = $oPayment->oxpayments__oxvaldesc->value;
210  }
211  break;
212  }
213  }
214  $this->_oUserPayment->setDynValues(oxRegistry::getUtils()->assignValuesFromText($sTemplate));
215  }
216  }
217 
218  return $this->_oUserPayment;
219  }
220 
226  public function getUserPayments()
227  {
228  if ($this->_oUserPayments == null) {
229  $this->_oUserPayments = false;
230  if ($oUser = $this->getUser()) {
231  $sTplLang = oxRegistry::getLang()->getObjectTplLanguage();
232  $sPaymentId = $this->getPaymentId();
233  $this->_oUserPayments = $oUser->getUserPayments();
234  // generate selected
235  foreach ($this->_oUserPayments as $oUserPayment) {
236  $oPayment = oxNew('oxpayment');
237  $oPayment->setLanguage($sTplLang);
238  $oPayment->load($oUserPayment->oxuserpayments__oxpaymentsid->value);
239  $oUserPayment->oxpayments__oxdesc = clone $oPayment->oxpayments__oxdesc;
240  if ($oUserPayment->oxuserpayments__oxid->value == $sPaymentId) {
241  $oUserPayment->selected = 1;
242  break;
243  }
244  }
245  }
246  }
247 
248  return $this->_oUserPayments;
249  }
250 }