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         $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 = '$sShipSetId' ";
00089         $sQ .= "and oxpayments.oxfromboni <= $sBoni and oxpayments.oxfromamount <= $dPrice and oxpayments.oxtoamount >= $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         $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';
00107         $sGroupSql   = $sGroupIds ?"exists( select 1 from oxobject2group as s3 where s3.OXOBJECTID=$sTable.OXID and s3.OXGROUPSID in ( $sGroupIds ) limit 1 )":'0';
00108 
00109         $sQ .= "and (
00110             select
00111                 if( exists( select 1 from oxobject2payment as ss1 where ss1.oxpaymentid=$sTable.OXID and ss1.oxtype='oxcountry' limit 1 ),
00112                     $sCountrySql,
00113                     1) &&
00114                 if( exists( select 1 from oxobject2group as ss3 where ss3.OXOBJECTID=$sTable.OXID limit 1 ),
00115                     $sGroupSql,
00116                     1)
00117                 ) ) as $sTable order by $sTable.oxsort asc ";
00118 
00119         return $sQ;
00120     }
00121 
00129     public function getCountryId( $oUser )
00130     {
00131         $sCountryId = null;
00132         if ( $oUser ) {
00133             $sCountryId = $oUser->getActiveCountry();
00134         }
00135 
00136         if ( !$sCountryId ) {
00137             $sCountryId = $this->_sHomeCountry;
00138         }
00139 
00140         return $sCountryId;
00141     }
00142 
00152     public function getPaymentList( $sShipSetId, $dPrice, $oUser = null )
00153     {
00154         $this->selectString( $this->_getFilterSelect( $sShipSetId, $dPrice, $oUser ) );
00155         return $this->_aArray;
00156     }
00157 }

Generated on Wed Apr 22 12:26:31 2009 for OXID eShop CE by  doxygen 1.5.5