oxvoucherserie.php

Go to the documentation of this file.
00001 <?php
00002 
00007 class oxVoucherSerie extends oxBase
00008 {
00009 
00014     protected $_oGroups = null;
00015 
00019     protected $_sCoreTbl = 'oxvoucherseries';
00020 
00024     protected $_sClassName = 'oxvoucherserie';
00025 
00029     public function __construct()
00030     {
00031         parent::__construct();
00032         $this->init( $this->_sCoreTbl);
00033     }
00034 
00042     public function delete( $sOxId = null )
00043     {
00044         if ( !$sOxId ) {
00045             $sOxId = $this->getId();
00046         }
00047 
00048 
00049         $this->unsetDiscountRelations();
00050         $this->unsetUserGroups();
00051         $this->deleteVoucherList();
00052         return parent::delete( $sOxId );
00053     }
00054 
00060     public function setUserGroups()
00061     {
00062         if ( $this->_oGroups === null ) {
00063             $this->_oGroups = oxNew( 'oxlist' );
00064             $this->_oGroups->init( 'oxgroups' );
00065             $sViewName = getViewName( "oxgroups" );
00066             $sSelect  = "select gr.* from {$sViewName} as gr, oxobject2group as o2g where
00067                          o2g.oxobjectid = ". oxDb::getDb()->quote( $this->getId() ) ." and gr.oxid = o2g.oxgroupsid ";
00068             $this->_oGroups->selectString( $sSelect );
00069         }
00070 
00071         return $this->_oGroups;
00072     }
00073 
00079     public function unsetUserGroups()
00080     {
00081         $oDB = oxDb::getDb();
00082         $sDelete = 'delete from oxobject2group where oxobjectid = ' . $oDB->quote( $this->getId() );
00083         $oDB->execute( $sDelete );
00084     }
00085 
00091     public function unsetDiscountRelations()
00092     {
00093         $oDB = oxDb::getDb();
00094         $sDelete = 'delete from oxobject2discount where oxobject2discount.oxdiscountid = ' . $oDB->quote( $this->getId() );
00095         $oDB->execute( $sDelete );
00096     }
00097 
00103     public function getVoucherList()
00104     {
00105         $oVoucherList = oxNew( 'oxvoucherlist' );
00106         $sSelect = 'select * from oxvouchers where oxvoucherserieid = ' . oxDb::getDb()->quote( $this->getId() );
00107         $oVoucherList->selectString( $sSelect );
00108         return $oVoucherList;
00109     }
00110 
00116     public function deleteVoucherList()
00117     {
00118         $oDB = oxDb::getDb();
00119         $sDelete = 'delete from oxvouchers where oxvoucherserieid = ' . $oDB->quote( $this->getId() );
00120         $oDB->execute( $sDelete );
00121     }
00122 
00128     public function countVouchers()
00129     {
00130         $aStatus = array();
00131 
00132         $oDB = oxDb::getDb();
00133         $sQuery = 'select count(*) as total from oxvouchers where oxvoucherserieid = ' .$oDB->quote( $this->getId() );
00134         $aStatus['total'] = $oDB->getOne( $sQuery );
00135 
00136         $sQuery = 'select count(*) as used from oxvouchers where oxvoucherserieid = ' . $oDB->quote( $this->getId() ) . ' and oxorderid is not NULL and oxorderid != ""';
00137         $aStatus['used'] = $oDB->getOne( $sQuery );
00138 
00139         $aStatus['available'] = $aStatus['total'] - $aStatus['used'];
00140 
00141         return $aStatus;
00142     }
00143 }