00001 <?php
00002
00007 class oxPaymentList extends oxList
00008 {
00013 protected static $_instance = null;
00014
00020 protected $_sHomeCountry = null;
00021
00027 public function __construct( $sObjectsInListName = 'oxpayment' )
00028 {
00029 $this->setHomeCountry( $this->getConfig()->getConfigParam( 'aHomeCountry' ) );
00030 parent::__construct( 'oxpayment');
00031 }
00032
00040 public function setHomeCountry( $sHomeCountry )
00041 {
00042 if ( is_array( $sHomeCountry ) ) {
00043 $this->_sHomeCountry = current( $sHomeCountry );
00044 } else {
00045 $this->_sHomeCountry = $sHomeCountry;
00046 }
00047 }
00048
00054 public static function getInstance()
00055 {
00056
00057 if ( defined( 'OXID_PHP_UNIT' ) ) {
00058 static $inst = array();
00059 self::$_instance = $inst[oxClassCacheKey()];
00060 }
00061
00062 if ( !isset( self::$_instance ) ) {
00063
00064 self::$_instance = oxNew( 'oxPaymentList' );
00065
00066 if ( defined( 'OXID_PHP_UNIT' ) ) {
00067 $inst[oxClassCacheKey()] = self::$_instance;
00068 }
00069 }
00070 return self::$_instance;
00071 }
00072
00082 protected function _getFilterSelect( $sShipSetId, $dPrice, $oUser )
00083 {
00084 $sBoni = ($oUser && $oUser->oxuser__oxboni->value )?$oUser->oxuser__oxboni->value:0;
00085
00086 $sTable = getViewName( 'oxpayments' );
00087 $sQ = "select $sTable.* from ( select distinct $sTable.* from $sTable, oxobject2group, oxobject2payment ";
00088 $sQ .= "where $sTable.oxactive='1' and oxobject2group.oxobjectid = $sTable.oxid ";
00089 $sQ .= "and oxobject2payment.oxpaymentid = $sTable.oxid and oxobject2payment.oxobjectid = '$sShipSetId' ";
00090 $sQ .= "and oxpayments.oxfromboni <= $sBoni and oxpayments.oxfromamount <= $dPrice and oxpayments.oxtoamount >= $dPrice ";
00091
00092
00093 $sGroupIds = '';
00094 $sCountryId = $this->getCountryId( $oUser );
00095
00096
00097 if ( $oUser ) {
00098
00099 foreach ( $oUser->getUserGroups() as $oGroup ) {
00100 if ( $sGroupIds ) {
00101 $sGroupIds .= ', ';
00102 }
00103 $sGroupIds .= "'".$oGroup->getId()."'";
00104 }
00105 }
00106
00107 $sCountrySql = $sCountryId?"exists( select 1 from oxobject2payment as s1 where s1.oxpaymentid=$sTable.OXID and s1.oxtype='oxcountry' and s1.OXOBJECTID='$sCountryId' limit 1 )":'0';
00108 $sGroupSql = $sGroupIds ?"exists( select 1 from oxobject2group as s3 where s3.OXOBJECTID=$sTable.OXID and s3.OXGROUPSID in ( $sGroupIds ) limit 1 )":'0';
00109
00110 $sQ .= "and (
00111 select
00112 if( exists( select 1 from oxobject2payment as ss1 where ss1.oxpaymentid=$sTable.OXID and ss1.oxtype='oxcountry' limit 1 ),
00113 $sCountrySql,
00114 1) &&
00115 if( exists( select 1 from oxobject2group as ss3 where ss3.OXOBJECTID=$sTable.OXID limit 1 ),
00116 $sGroupSql,
00117 1)
00118 ) ) as $sTable order by $sTable.oxsort asc ";
00119
00120 return $sQ;
00121 }
00122
00130 public function getCountryId( $oUser )
00131 {
00132 $sCountryId = null;
00133 if ( $oUser ) {
00134 $sCountryId = $oUser->getActiveCountry();
00135 }
00136
00137 if ( !$sCountryId ) {
00138 $sCountryId = $this->_sHomeCountry;
00139 }
00140
00141 return $sCountryId;
00142 }
00143
00153 public function getPaymentList( $sShipSetId, $dPrice, $oUser = null )
00154 {
00155 $this->selectString( $this->_getFilterSelect( $sShipSetId, $dPrice, $oUser ) );
00156 return $this->_aArray;
00157 }
00158 }