OXID eShop CE  4.9.5
 All Classes Files Functions Variables Pages
oxpaymentlist.php
Go to the documentation of this file.
1 <?php
6 class oxPaymentList extends oxList
7 {
8 
14  protected $_sHomeCountry = null;
15 
21  public function __construct()
22  {
23  $this->setHomeCountry($this->getConfig()->getConfigParam('aHomeCountry'));
24  parent::__construct('oxpayment');
25  }
26 
32  public function setHomeCountry($sHomeCountry)
33  {
34  if (is_array($sHomeCountry)) {
35  $this->_sHomeCountry = current($sHomeCountry);
36  } else {
37  $this->_sHomeCountry = $sHomeCountry;
38  }
39  }
40 
50  protected function _getFilterSelect($sShipSetId, $dPrice, $oUser)
51  {
52  $oDb = oxDb::getDb();
53  $sBoni = ($oUser && $oUser->oxuser__oxboni->value) ? $oUser->oxuser__oxboni->value : 0;
54 
55  $sTable = getViewName('oxpayments');
56  $sQ = "select {$sTable}.* from ( select distinct {$sTable}.* from {$sTable} ";
57  $sQ .= "left join oxobject2group ON oxobject2group.oxobjectid = {$sTable}.oxid ";
58  $sQ .= "inner join oxobject2payment ON oxobject2payment.oxobjectid = " . $oDb->quote($sShipSetId) . " and oxobject2payment.oxpaymentid = {$sTable}.oxid ";
59  $sQ .= "where {$sTable}.oxactive='1' ";
60  $sQ .= " and {$sTable}.oxfromboni <= " . $oDb->quote($sBoni) . " and {$sTable}.oxfromamount <= " . $oDb->quote($dPrice) . " and {$sTable}.oxtoamount >= " . $oDb->quote($dPrice);
61 
62  // defining initial filter parameters
63  $sGroupIds = '';
64  $sCountryId = $this->getCountryId($oUser);
65 
66  // checking for current session user which gives additional restrictions for user itself, users group and country
67  if ($oUser) {
68  // user groups ( maybe would be better to fetch by function oxuser::getUserGroups() ? )
69  foreach ($oUser->getUserGroups() as $oGroup) {
70  if ($sGroupIds) {
71  $sGroupIds .= ', ';
72  }
73  $sGroupIds .= "'" . $oGroup->getId() . "'";
74  }
75  }
76 
77  $sGroupTable = getViewName('oxgroups');
78  $sCountryTable = getViewName('oxcountry');
79 
80  $sCountrySql = $sCountryId ? "exists( select 1 from oxobject2payment as s1 where s1.oxpaymentid={$sTable}.OXID and s1.oxtype='oxcountry' and s1.OXOBJECTID=" . $oDb->quote($sCountryId) . " limit 1 )" : '0';
81  $sGroupSql = $sGroupIds ? "exists( select 1 from oxobject2group as s3 where s3.OXOBJECTID={$sTable}.OXID and s3.OXGROUPSID in ( {$sGroupIds} ) limit 1 )" : '0';
82 
83  $sQ .= " ) as $sTable where (
84  select
85  if( exists( select 1 from oxobject2payment as ss1, $sCountryTable where $sCountryTable.oxid=ss1.oxobjectid and ss1.oxpaymentid={$sTable}.OXID and ss1.oxtype='oxcountry' limit 1 ),
86  {$sCountrySql},
87  1) &&
88  if( exists( select 1 from oxobject2group as ss3, $sGroupTable where $sGroupTable.oxid=ss3.oxgroupsid and ss3.OXOBJECTID={$sTable}.OXID limit 1 ),
89  {$sGroupSql},
90  1)
91  ) order by {$sTable}.oxsort asc ";
92 
93  return $sQ;
94  }
95 
103  public function getCountryId($oUser)
104  {
105  $sCountryId = null;
106  if ($oUser) {
107  $sCountryId = $oUser->getActiveCountry();
108  }
109 
110  if (!$sCountryId) {
111  $sCountryId = $this->_sHomeCountry;
112  }
113 
114  return $sCountryId;
115  }
116 
126  public function getPaymentList($sShipSetId, $dPrice, $oUser = null)
127  {
128  $this->selectString($this->_getFilterSelect($sShipSetId, $dPrice, $oUser));
129 
130  return $this->_aArray;
131  }
132 
137  public function loadNonRDFaPaymentList()
138  {
139  $sTable = getViewName('oxpayments');
140  $sSubSql = "SELECT * FROM oxobject2payment WHERE oxobject2payment.OXPAYMENTID = $sTable.OXID AND oxobject2payment.OXTYPE = 'rdfapayment'";
141  $this->selectString("SELECT $sTable.* FROM $sTable WHERE NOT EXISTS($sSubSql) AND $sTable.OXACTIVE = 1");
142  }
143 
150  public function loadRDFaPaymentList($dPrice = null)
151  {
153  $sTable = getViewName('oxpayments');
154  $sQ = "select $sTable.*, oxobject2payment.oxobjectid from $sTable left join (select oxobject2payment.* from oxobject2payment where oxobject2payment.oxtype = 'rdfapayment') as oxobject2payment on oxobject2payment.oxpaymentid=$sTable.oxid ";
155  $sQ .= "where $sTable.oxactive = 1 ";
156  if ($dPrice !== null) {
157  $sQ .= "and $sTable.oxfromamount <= " . $oDb->quote($dPrice) . " and $sTable.oxtoamount >= " . $oDb->quote($dPrice);
158  }
159  $rs = $oDb->select($sQ);
160  if ($rs != false && $rs->recordCount() > 0) {
161  $oSaved = clone $this->getBaseObject();
162  while (!$rs->EOF) {
163  $oListObject = clone $oSaved;
164  $this->_assignElement($oListObject, $rs->fields);
165  $this->_aArray[] = $oListObject;
166  $rs->moveNext();
167  }
168  }
169  }
170 }