OXID eShop CE  4.8.10
 All Classes Files Functions Variables Pages
oxpaymentlist.php
Go to the documentation of this file.
1 <?php
6 class oxPaymentList extends oxList
7 {
12  protected static $_instance = null;
13 
19  protected $_sHomeCountry = null;
20 
26  public function __construct( $sObjectsInListName = 'oxpayment' )
27  {
28  $this->setHomeCountry( $this->getConfig()->getConfigParam( 'aHomeCountry' ) );
29  parent::__construct( 'oxpayment');
30  }
31 
39  public function setHomeCountry( $sHomeCountry )
40  {
41  if ( is_array( $sHomeCountry ) ) {
42  $this->_sHomeCountry = current( $sHomeCountry );
43  } else {
44  $this->_sHomeCountry = $sHomeCountry;
45  }
46  }
47 
55  public static function getInstance()
56  {
57  return oxRegistry::get("oxPaymentList");
58  }
59 
69  protected function _getFilterSelect( $sShipSetId, $dPrice, $oUser )
70  {
71  $oDb = oxDb::getDb();
72  $sBoni = ($oUser && $oUser->oxuser__oxboni->value )?$oUser->oxuser__oxboni->value:0;
73 
74  $sTable = getViewName( 'oxpayments' );
75  $sQ = "select {$sTable}.* from ( select distinct {$sTable}.* from {$sTable} ";
76  $sQ .= "left join oxobject2group ON oxobject2group.oxobjectid = {$sTable}.oxid ";
77  $sQ .= "inner join oxobject2payment ON oxobject2payment.oxobjectid = ".$oDb->quote( $sShipSetId )." and oxobject2payment.oxpaymentid = {$sTable}.oxid ";
78  $sQ .= "where {$sTable}.oxactive='1' ";
79  $sQ .= " and {$sTable}.oxfromboni <= ".$oDb->quote( $sBoni ) ." and {$sTable}.oxfromamount <= ".$oDb->quote( $dPrice ) ." and {$sTable}.oxtoamount >= ".$oDb->quote( $dPrice );
80 
81  // defining initial filter parameters
82  $sGroupIds = '';
83  $sCountryId = $this->getCountryId( $oUser );
84 
85  // checking for current session user which gives additional restrictions for user itself, users group and country
86  if ( $oUser ) {
87  // user groups ( maybe would be better to fetch by function oxuser::getUserGroups() ? )
88  foreach ( $oUser->getUserGroups() as $oGroup ) {
89  if ( $sGroupIds ) {
90  $sGroupIds .= ', ';
91  }
92  $sGroupIds .= "'".$oGroup->getId()."'";
93  }
94  }
95 
96  $sGroupTable = getViewName( 'oxgroups' );
97  $sCountryTable = getViewName( 'oxcountry' );
98 
99  $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';
100  $sGroupSql = $sGroupIds ? "exists( select 1 from oxobject2group as s3 where s3.OXOBJECTID={$sTable}.OXID and s3.OXGROUPSID in ( {$sGroupIds} ) limit 1 )":'0';
101 
102  $sQ .= " ) as $sTable where (
103  select
104  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 ),
105  {$sCountrySql},
106  1) &&
107  if( exists( select 1 from oxobject2group as ss3, $sGroupTable where $sGroupTable.oxid=ss3.oxgroupsid and ss3.OXOBJECTID={$sTable}.OXID limit 1 ),
108  {$sGroupSql},
109  1)
110  ) order by {$sTable}.oxsort asc ";
111  return $sQ;
112  }
113 
121  public function getCountryId( $oUser )
122  {
123  $sCountryId = null;
124  if ( $oUser ) {
125  $sCountryId = $oUser->getActiveCountry();
126  }
127 
128  if ( !$sCountryId ) {
129  $sCountryId = $this->_sHomeCountry;
130  }
131 
132  return $sCountryId;
133  }
134 
144  public function getPaymentList( $sShipSetId, $dPrice, $oUser = null )
145  {
146  $this->selectString( $this->_getFilterSelect( $sShipSetId, $dPrice, $oUser ) );
147  return $this->_aArray;
148  }
149 
156  public function loadNonRDFaPaymentList()
157  {
158  $sTable = getViewName( 'oxpayments' );
159  $sSubSql = "SELECT * FROM oxobject2payment WHERE oxobject2payment.OXPAYMENTID = $sTable.OXID AND oxobject2payment.OXTYPE = 'rdfapayment'";
160  $this->selectString( "SELECT $sTable.* FROM $sTable WHERE NOT EXISTS($sSubSql) AND $sTable.OXACTIVE = 1" );
161  }
162 
171  public function loadRDFaPaymentList($dPrice = null)
172  {
174  $sTable = getViewName( 'oxpayments' );
175  $sQ = "select $sTable.*, oxobject2payment.oxobjectid from $sTable left join (select oxobject2payment.* from oxobject2payment where oxobject2payment.oxtype = 'rdfapayment') as oxobject2payment on oxobject2payment.oxpaymentid=$sTable.oxid ";
176  $sQ .= "where $sTable.oxactive = 1 ";
177  if ( $dPrice !== null ) {
178  $sQ .= "and $sTable.oxfromamount <= ".$oDb->quote( $dPrice ) ." and $sTable.oxtoamount >= ".$oDb->quote( $dPrice );
179  }
180  $rs = $oDb->select( $sQ );
181  if ($rs != false && $rs->recordCount() > 0) {
182  $oSaved = clone $this->getBaseObject();
183  while (!$rs->EOF) {
184  $oListObject = clone $oSaved;
185  $this->_assignElement($oListObject, $rs->fields);
186  $this->_aArray[] = $oListObject;
187  $rs->moveNext();
188  }
189  }
190  }
191 
192 }