oxpaymentlist.php

Go to the documentation of this file.
00001 <?php
00002 
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 
00053     public static function getInstance()
00054     {
00055         // disable cashing for test modules
00056         if ( defined( 'OXID_PHP_UNIT' ) ) {
00057             self::$_instance = modInstances::getMod( __CLASS__ );
00058         }
00059 
00060         if ( !isset( self::$_instance ) ) {
00061             // allow modules
00062             self::$_instance = oxNew( 'oxPaymentList' );
00063 
00064             if ( defined( 'OXID_PHP_UNIT' ) ) {
00065                 modInstances::addMod( __CLASS__, self::$_instance);
00066             }
00067         }
00068         return self::$_instance;
00069     }
00070 
00080     protected function _getFilterSelect( $sShipSetId, $dPrice, $oUser )
00081     {
00082         $oDb = oxDb::getDb();
00083         $sBoni = ($oUser && $oUser->oxuser__oxboni->value )?$oUser->oxuser__oxboni->value:0;
00084 
00085         $sTable = getViewName( 'oxpayments' );
00086         $sQ  = "select {$sTable}.* from ( select distinct {$sTable}.* from {$sTable}, oxobject2group, oxobject2payment ";
00087         $sQ .= "where {$sTable}.oxactive='1' and oxobject2group.oxobjectid = {$sTable}.oxid ";
00088         $sQ .= "and oxobject2payment.oxpaymentid = {$sTable}.oxid and oxobject2payment.oxobjectid = ".$oDb->quote( $sShipSetId );
00089         $sQ .= " and oxpayments.oxfromboni <= ".$oDb->quote( $sBoni ) ." and oxpayments.oxfromamount <= ".$oDb->quote( $dPrice ) ." and oxpayments.oxtoamount >= ".$oDb->quote( $dPrice );
00090 
00091         // defining initial filter parameters
00092         $sGroupIds  = '';
00093         $sCountryId = $this->getCountryId( $oUser );
00094 
00095         // checking for current session user which gives additional restrictions for user itself, users group and country
00096         if ( $oUser ) {
00097             // user groups ( maybe would be better to fetch by function oxuser::getUserGroups() ? )
00098             foreach ( $oUser->getUserGroups() as $oGroup ) {
00099                 if ( $sGroupIds ) {
00100                     $sGroupIds .= ', ';
00101                 }
00102                 $sGroupIds .= "'".$oGroup->getId()."'";
00103             }
00104         }
00105 
00106         $sGroupTable   = getViewName( 'oxgroups' );
00107         $sCountryTable = getViewName( 'oxcountry' );
00108 
00109         $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';
00110         $sGroupSql   = $sGroupIds ? "exists( select 1 from oxobject2group as s3 where s3.OXOBJECTID={$sTable}.OXID and s3.OXGROUPSID in ( {$sGroupIds} ) limit 1 )":'0';
00111 
00112         $sQ .= " ) as $sTable where (
00113             select
00114                 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 ),
00115                     {$sCountrySql},
00116                     1) &&
00117                 if( exists( select 1 from oxobject2group as ss3, $sGroupTable where $sGroupTable.oxid=ss3.oxgroupsid and ss3.OXOBJECTID={$sTable}.OXID limit 1 ),
00118                     {$sGroupSql},
00119                     1)
00120                 )  order by {$sTable}.oxsort asc ";
00121 
00122         return $sQ;
00123     }
00124 
00132     public function getCountryId( $oUser )
00133     {
00134         $sCountryId = null;
00135         if ( $oUser ) {
00136             $sCountryId = $oUser->getActiveCountry();
00137         }
00138 
00139         if ( !$sCountryId ) {
00140             $sCountryId = $this->_sHomeCountry;
00141         }
00142 
00143         return $sCountryId;
00144     }
00145 
00155     public function getPaymentList( $sShipSetId, $dPrice, $oUser = null )
00156     {
00157         $this->selectString( $this->_getFilterSelect( $sShipSetId, $dPrice, $oUser ) );
00158         return $this->_aArray;
00159     }
00160 }