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

Generated on Mon Oct 26 20:07:16 2009 for OXID eShop CE by  doxygen 1.5.5