oxvoucherserie.php

Go to the documentation of this file.
00001 <?php
00002 
00008 class oxVoucherSerie extends oxBase
00009 {
00010 
00015     protected $_oGroups = null;
00016 
00020     protected $_sClassName = 'oxvoucherserie';
00021 
00025     public function __construct()
00026     {
00027         parent::__construct();
00028         $this->init('oxvoucherseries');
00029     }
00030 
00038     public function delete( $sOxId = null )
00039     {
00040         if ( !$sOxId ) {
00041             $sOxId = $this->getId();
00042         }
00043 
00044 
00045         $this->unsetDiscountRelations();
00046         $this->unsetUserGroups();
00047         $this->deleteVoucherList();
00048         return parent::delete( $sOxId );
00049     }
00050 
00056     public function setUserGroups()
00057     {
00058         if ( $this->_oGroups === null ) {
00059             $this->_oGroups = oxNew( 'oxlist' );
00060             $this->_oGroups->init( 'oxgroups' );
00061             $sViewName = getViewName( "oxgroups" );
00062             $sSelect  = "select gr.* from {$sViewName} as gr, oxobject2group as o2g where
00063                          o2g.oxobjectid = ". oxDb::getDb()->quote( $this->getId() ) ." and gr.oxid = o2g.oxgroupsid ";
00064             $this->_oGroups->selectString( $sSelect );
00065         }
00066 
00067         return $this->_oGroups;
00068     }
00069 
00075     public function unsetUserGroups()
00076     {
00077         $oDb = oxDb::getDb();
00078         $sDelete = 'delete from oxobject2group where oxobjectid = ' . $oDb->quote( $this->getId() );
00079         $oDb->execute( $sDelete );
00080     }
00081 
00087     public function unsetDiscountRelations()
00088     {
00089         $oDb = oxDb::getDb();
00090         $sDelete = 'delete from oxobject2discount where oxobject2discount.oxdiscountid = ' . $oDb->quote( $this->getId() );
00091         $oDb->execute( $sDelete );
00092     }
00093 
00099     public function getVoucherList()
00100     {
00101         $oVoucherList = oxNew( 'oxvoucherlist' );
00102         $sSelect = 'select * from oxvouchers where oxvoucherserieid = ' . oxDb::getDb()->quote( $this->getId() );
00103         $oVoucherList->selectString( $sSelect );
00104         return $oVoucherList;
00105     }
00106 
00112     public function deleteVoucherList()
00113     {
00114         $oDb = oxDb::getDb();
00115         $sDelete = 'delete from oxvouchers where oxvoucherserieid = ' . $oDb->quote( $this->getId() );
00116         $oDb->execute( $sDelete );
00117     }
00118 
00124     public function countVouchers()
00125     {
00126         $aStatus = array();
00127 
00128         $oDb = oxDb::getDb();
00129         $sQuery = 'select count(*) as total from oxvouchers where oxvoucherserieid = ' .$oDb->quote( $this->getId() );
00130         $aStatus['total'] = $oDb->getOne( $sQuery );
00131 
00132         $sQuery = 'select count(*) as used from oxvouchers where oxvoucherserieid = ' . $oDb->quote( $this->getId() ) . ' and ((oxorderid is not NULL and oxorderid != "") or (oxdateused is not NULL and oxdateused != 0))';
00133         $aStatus['used'] = $oDb->getOne( $sQuery );
00134 
00135         $aStatus['available'] = $aStatus['total'] - $aStatus['used'];
00136 
00137         return $aStatus;
00138     }
00139 }