oxpaymentlist.php

Go to the documentation of this file.
00001 <?php
00006 class oxPaymentList extends oxList
00007 {
00012     protected static $_instance = null;
00013 
00019     protected $_sHomeCountry = null;
00020 
00026     public function __construct( $sObjectsInListName = 'oxpayment' )
00027     {
00028         $this->setHomeCountry( $this->getConfig()->getConfigParam( 'aHomeCountry' ) );
00029         parent::__construct( 'oxpayment');
00030     }
00031 
00039     public function setHomeCountry( $sHomeCountry )
00040     {
00041         if ( is_array( $sHomeCountry ) ) {
00042             $this->_sHomeCountry = current( $sHomeCountry );
00043         } else {
00044             $this->_sHomeCountry = $sHomeCountry;
00045         }
00046     }
00047 
00055     public static function getInstance()
00056     {
00057         return oxRegistry::get("oxPaymentList");
00058     }
00059 
00069     protected function _getFilterSelect( $sShipSetId, $dPrice, $oUser )
00070     {
00071         $oDb = oxDb::getDb();
00072         $sBoni = ($oUser && $oUser->oxuser__oxboni->value )?$oUser->oxuser__oxboni->value:0;
00073 
00074         $sTable = getViewName( 'oxpayments' );
00075         $sQ  = "select {$sTable}.* from ( select distinct {$sTable}.* from {$sTable} ";
00076         $sQ .= "left join oxobject2group ON oxobject2group.oxobjectid = {$sTable}.oxid ";
00077         $sQ .= "inner join oxobject2payment ON oxobject2payment.oxobjectid = ".$oDb->quote( $sShipSetId )." and oxobject2payment.oxpaymentid = {$sTable}.oxid ";
00078         $sQ .= "where {$sTable}.oxactive='1' ";
00079         $sQ .= " and {$sTable}.oxfromboni <= ".$oDb->quote( $sBoni ) ." and {$sTable}.oxfromamount <= ".$oDb->quote( $dPrice ) ." and {$sTable}.oxtoamount >= ".$oDb->quote( $dPrice );
00080 
00081         // defining initial filter parameters
00082         $sGroupIds  = '';
00083         $sCountryId = $this->getCountryId( $oUser );
00084 
00085         // checking for current session user which gives additional restrictions for user itself, users group and country
00086         if ( $oUser ) {
00087             // user groups ( maybe would be better to fetch by function oxuser::getUserGroups() ? )
00088             foreach ( $oUser->getUserGroups() as $oGroup ) {
00089                 if ( $sGroupIds ) {
00090                     $sGroupIds .= ', ';
00091                 }
00092                 $sGroupIds .= "'".$oGroup->getId()."'";
00093             }
00094         }
00095 
00096         $sGroupTable   = getViewName( 'oxgroups' );
00097         $sCountryTable = getViewName( 'oxcountry' );
00098 
00099         $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';
00100         $sGroupSql   = $sGroupIds ? "exists( select 1 from oxobject2group as s3 where s3.OXOBJECTID={$sTable}.OXID and s3.OXGROUPSID in ( {$sGroupIds} ) limit 1 )":'0';
00101 
00102         $sQ .= " ) as $sTable where (
00103             select
00104                 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 ),
00105                     {$sCountrySql},
00106                     1) &&
00107                 if( exists( select 1 from oxobject2group as ss3, $sGroupTable where $sGroupTable.oxid=ss3.oxgroupsid and ss3.OXOBJECTID={$sTable}.OXID limit 1 ),
00108                     {$sGroupSql},
00109                     1)
00110                 )  order by {$sTable}.oxsort asc ";
00111         return $sQ;
00112     }
00113 
00121     public function getCountryId( $oUser )
00122     {
00123         $sCountryId = null;
00124         if ( $oUser ) {
00125             $sCountryId = $oUser->getActiveCountry();
00126         }
00127 
00128         if ( !$sCountryId ) {
00129             $sCountryId = $this->_sHomeCountry;
00130         }
00131 
00132         return $sCountryId;
00133     }
00134 
00144     public function getPaymentList( $sShipSetId, $dPrice, $oUser = null )
00145     {
00146         $this->selectString( $this->_getFilterSelect( $sShipSetId, $dPrice, $oUser ) );
00147         return $this->_aArray;
00148     }
00149 
00156     public function loadNonRDFaPaymentList()
00157     {
00158         $sTable = getViewName( 'oxpayments' );
00159         $sSubSql = "SELECT * FROM oxobject2payment WHERE oxobject2payment.OXPAYMENTID = $sTable.OXID AND oxobject2payment.OXTYPE = 'rdfapayment'";
00160         $this->selectString( "SELECT $sTable.* FROM $sTable WHERE NOT EXISTS($sSubSql) AND $sTable.OXACTIVE = 1" );
00161     }
00162 
00171     public function loadRDFaPaymentList($dPrice = null)
00172     {
00173         $oDb = oxDb::getDb( oxDb::FETCH_MODE_ASSOC );
00174         $sTable = getViewName( 'oxpayments' );
00175         $sQ  = "select $sTable.*, oxobject2payment.oxobjectid from $sTable left join (select oxobject2payment.* from oxobject2payment where oxobject2payment.oxtype = 'rdfapayment') as oxobject2payment on oxobject2payment.oxpaymentid=$sTable.oxid ";
00176         $sQ .= "where $sTable.oxactive = 1 ";
00177         if ( $dPrice !== null ) {
00178             $sQ .= "and $sTable.oxfromamount <= ".$oDb->quote( $dPrice ) ." and $sTable.oxtoamount >= ".$oDb->quote( $dPrice );
00179         }
00180         $rs = $oDb->select( $sQ );
00181         if ($rs != false && $rs->recordCount() > 0) {
00182             $oSaved = clone $this->getBaseObject();
00183             while (!$rs->EOF) {
00184                 $oListObject = clone $oSaved;
00185                 $this->_assignElement($oListObject, $rs->fields);
00186                 $this->_aArray[] = $oListObject;
00187                 $rs->moveNext();
00188             }
00189         }
00190     }
00191 
00192 }