Go to the documentation of this file.00001 <?php
00006 class oxPaymentList extends oxList
00007 {
00008
00014 protected $_sHomeCountry = null;
00015
00021 public function __construct()
00022 {
00023 $this->setHomeCountry($this->getConfig()->getConfigParam('aHomeCountry'));
00024 parent::__construct('oxpayment');
00025 }
00026
00032 public function setHomeCountry($sHomeCountry)
00033 {
00034 if (is_array($sHomeCountry)) {
00035 $this->_sHomeCountry = current($sHomeCountry);
00036 } else {
00037 $this->_sHomeCountry = $sHomeCountry;
00038 }
00039 }
00040
00050 protected function _getFilterSelect($sShipSetId, $dPrice, $oUser)
00051 {
00052 $oDb = oxDb::getDb();
00053 $sBoni = ($oUser && $oUser->oxuser__oxboni->value) ? $oUser->oxuser__oxboni->value : 0;
00054
00055 $sTable = getViewName('oxpayments');
00056 $sQ = "select {$sTable}.* from ( select distinct {$sTable}.* from {$sTable} ";
00057 $sQ .= "left join oxobject2group ON oxobject2group.oxobjectid = {$sTable}.oxid ";
00058 $sQ .= "inner join oxobject2payment ON oxobject2payment.oxobjectid = " . $oDb->quote($sShipSetId) . " and oxobject2payment.oxpaymentid = {$sTable}.oxid ";
00059 $sQ .= "where {$sTable}.oxactive='1' ";
00060 $sQ .= " and {$sTable}.oxfromboni <= " . $oDb->quote($sBoni) . " and {$sTable}.oxfromamount <= " . $oDb->quote($dPrice) . " and {$sTable}.oxtoamount >= " . $oDb->quote($dPrice);
00061
00062
00063 $sGroupIds = '';
00064 $sCountryId = $this->getCountryId($oUser);
00065
00066
00067 if ($oUser) {
00068
00069 foreach ($oUser->getUserGroups() as $oGroup) {
00070 if ($sGroupIds) {
00071 $sGroupIds .= ', ';
00072 }
00073 $sGroupIds .= "'" . $oGroup->getId() . "'";
00074 }
00075 }
00076
00077 $sGroupTable = getViewName('oxgroups');
00078 $sCountryTable = getViewName('oxcountry');
00079
00080 $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';
00081 $sGroupSql = $sGroupIds ? "exists( select 1 from oxobject2group as s3 where s3.OXOBJECTID={$sTable}.OXID and s3.OXGROUPSID in ( {$sGroupIds} ) limit 1 )" : '0';
00082
00083 $sQ .= " ) as $sTable where (
00084 select
00085 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 ),
00086 {$sCountrySql},
00087 1) &&
00088 if( exists( select 1 from oxobject2group as ss3, $sGroupTable where $sGroupTable.oxid=ss3.oxgroupsid and ss3.OXOBJECTID={$sTable}.OXID limit 1 ),
00089 {$sGroupSql},
00090 1)
00091 ) order by {$sTable}.oxsort asc ";
00092
00093 return $sQ;
00094 }
00095
00103 public function getCountryId($oUser)
00104 {
00105 $sCountryId = null;
00106 if ($oUser) {
00107 $sCountryId = $oUser->getActiveCountry();
00108 }
00109
00110 if (!$sCountryId) {
00111 $sCountryId = $this->_sHomeCountry;
00112 }
00113
00114 return $sCountryId;
00115 }
00116
00126 public function getPaymentList($sShipSetId, $dPrice, $oUser = null)
00127 {
00128 $this->selectString($this->_getFilterSelect($sShipSetId, $dPrice, $oUser));
00129
00130 return $this->_aArray;
00131 }
00132
00137 public function loadNonRDFaPaymentList()
00138 {
00139 $sTable = getViewName('oxpayments');
00140 $sSubSql = "SELECT * FROM oxobject2payment WHERE oxobject2payment.OXPAYMENTID = $sTable.OXID AND oxobject2payment.OXTYPE = 'rdfapayment'";
00141 $this->selectString("SELECT $sTable.* FROM $sTable WHERE NOT EXISTS($sSubSql) AND $sTable.OXACTIVE = 1");
00142 }
00143
00150 public function loadRDFaPaymentList($dPrice = null)
00151 {
00152 $oDb = oxDb::getDb(oxDb::FETCH_MODE_ASSOC);
00153 $sTable = getViewName('oxpayments');
00154 $sQ = "select $sTable.*, oxobject2payment.oxobjectid from $sTable left join (select oxobject2payment.* from oxobject2payment where oxobject2payment.oxtype = 'rdfapayment') as oxobject2payment on oxobject2payment.oxpaymentid=$sTable.oxid ";
00155 $sQ .= "where $sTable.oxactive = 1 ";
00156 if ($dPrice !== null) {
00157 $sQ .= "and $sTable.oxfromamount <= " . $oDb->quote($dPrice) . " and $sTable.oxtoamount >= " . $oDb->quote($dPrice);
00158 }
00159 $rs = $oDb->select($sQ);
00160 if ($rs != false && $rs->recordCount() > 0) {
00161 $oSaved = clone $this->getBaseObject();
00162 while (!$rs->EOF) {
00163 $oListObject = clone $oSaved;
00164 $this->_assignElement($oListObject, $rs->fields);
00165 $this->_aArray[] = $oListObject;
00166 $rs->moveNext();
00167 }
00168 }
00169 }
00170 }