oxpaymentlist.php

Go to the documentation of this file.
00001 <?php
00005 class oxPaymentList extends oxList
00006 {
00011     protected static $_instance = null;
00012 
00018     protected $_sHomeCountry = null;
00019 
00025     public function __construct( $sObjectsInListName = 'oxpayment' )
00026     {
00027         $this->setHomeCountry( $this->getConfig()->getConfigParam( 'aHomeCountry' ) );
00028         parent::__construct( 'oxpayment');
00029     }
00030 
00038     public function setHomeCountry( $sHomeCountry )
00039     {
00040         if ( is_array( $sHomeCountry ) ) {
00041             $this->_sHomeCountry = current( $sHomeCountry );
00042         } else {
00043             $this->_sHomeCountry = $sHomeCountry;
00044         }
00045     }
00046 
00052     public static function getInstance()
00053     {
00054         // disable cashing for test modules
00055         if ( defined( 'OXID_PHP_UNIT' ) ) {
00056             self::$_instance = modInstances::getMod( __CLASS__ );
00057         }
00058 
00059         if ( !isset( self::$_instance ) ) {
00060             // allow modules
00061             self::$_instance = oxNew( 'oxPaymentList' );
00062 
00063             if ( defined( 'OXID_PHP_UNIT' ) ) {
00064                 modInstances::addMod( __CLASS__, self::$_instance);
00065             }
00066         }
00067         return self::$_instance;
00068     }
00069 
00079     protected function _getFilterSelect( $sShipSetId, $dPrice, $oUser )
00080     {
00081         $oDb = oxDb::getDb();
00082         $sBoni = ($oUser && $oUser->oxuser__oxboni->value )?$oUser->oxuser__oxboni->value:0;
00083 
00084         $sTable = getViewName( 'oxpayments' );
00085         $sQ  = "select {$sTable}.* from ( select distinct {$sTable}.* from {$sTable}, oxobject2group, oxobject2payment ";
00086         $sQ .= "where {$sTable}.oxactive='1' and oxobject2group.oxobjectid = {$sTable}.oxid ";
00087         $sQ .= "and oxobject2payment.oxpaymentid = {$sTable}.oxid and oxobject2payment.oxobjectid = ".$oDb->quote( $sShipSetId );
00088         $sQ .= " and {$sTable}.oxfromboni <= ".$oDb->quote( $sBoni ) ." and {$sTable}.oxfromamount <= ".$oDb->quote( $dPrice ) ." and {$sTable}.oxtoamount >= ".$oDb->quote( $dPrice );
00089 
00090         // defining initial filter parameters
00091         $sGroupIds  = '';
00092         $sCountryId = $this->getCountryId( $oUser );
00093 
00094         // checking for current session user which gives additional restrictions for user itself, users group and country
00095         if ( $oUser ) {
00096             // user groups ( maybe would be better to fetch by function oxuser::getUserGroups() ? )
00097             foreach ( $oUser->getUserGroups() as $oGroup ) {
00098                 if ( $sGroupIds ) {
00099                     $sGroupIds .= ', ';
00100                 }
00101                 $sGroupIds .= "'".$oGroup->getId()."'";
00102             }
00103         }
00104 
00105         $sGroupTable   = getViewName( 'oxgroups' );
00106         $sCountryTable = getViewName( 'oxcountry' );
00107 
00108         $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';
00109         $sGroupSql   = $sGroupIds ? "exists( select 1 from oxobject2group as s3 where s3.OXOBJECTID={$sTable}.OXID and s3.OXGROUPSID in ( {$sGroupIds} ) limit 1 )":'0';
00110 
00111         $sQ .= " ) as $sTable where (
00112             select
00113                 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 ),
00114                     {$sCountrySql},
00115                     1) &&
00116                 if( exists( select 1 from oxobject2group as ss3, $sGroupTable where $sGroupTable.oxid=ss3.oxgroupsid and ss3.OXOBJECTID={$sTable}.OXID limit 1 ),
00117                     {$sGroupSql},
00118                     1)
00119                 )  order by {$sTable}.oxsort asc ";
00120 
00121         return $sQ;
00122     }
00123 
00131     public function getCountryId( $oUser )
00132     {
00133         $sCountryId = null;
00134         if ( $oUser ) {
00135             $sCountryId = $oUser->getActiveCountry();
00136         }
00137 
00138         if ( !$sCountryId ) {
00139             $sCountryId = $this->_sHomeCountry;
00140         }
00141 
00142         return $sCountryId;
00143     }
00144 
00154     public function getPaymentList( $sShipSetId, $dPrice, $oUser = null )
00155     {
00156         $this->selectString( $this->_getFilterSelect( $sShipSetId, $dPrice, $oUser ) );
00157         return $this->_aArray;
00158     }
00159 
00166     public function loadNonRDFaPaymentList()
00167     {
00168         $sTable = getViewName( 'oxpayments' );
00169         $sSubSql = "SELECT * FROM oxobject2payment WHERE oxobject2payment.OXPAYMENTID = $sTable.OXID AND oxobject2payment.OXTYPE = 'rdfapayment'";
00170         $this->selectString( "SELECT $sTable.* FROM $sTable WHERE NOT EXISTS($sSubSql) AND $sTable.OXACTIVE = 1" );
00171     }
00172 
00181     public function loadRDFaPaymentList($dPrice = null)
00182     {
00183         $oDb = oxDb::getDb( oxDb::FETCH_MODE_ASSOC );
00184         $sTable = getViewName( 'oxpayments' );
00185         $sQ  = "select $sTable.*, oxobject2payment.oxobjectid from $sTable left join (select oxobject2payment.* from oxobject2payment where oxobject2payment.oxtype = 'rdfapayment') as oxobject2payment on oxobject2payment.oxpaymentid=$sTable.oxid ";
00186         $sQ .= "where $sTable.oxactive = 1 ";
00187         if ( $dPrice !== null ) {
00188             $sQ .= "and $sTable.oxfromamount <= ".$oDb->quote( $dPrice ) ." and $sTable.oxtoamount >= ".$oDb->quote( $dPrice );
00189         }
00190         $rs = $oDb->select( $sQ );
00191         if ($rs != false && $rs->recordCount() > 0) {
00192             $oSaved = clone $this->getBaseObject();
00193             while (!$rs->EOF) {
00194                 $oListObject = clone $oSaved;
00195                 $this->_assignElement($oListObject, $rs->fields);
00196                 $this->_aArray[] = $oListObject;
00197                 $rs->moveNext();
00198             }
00199         }
00200     }
00201 
00202 }