00001 <?php
00002
00008 class oxVoucherSerie extends oxBase
00009 {
00010
00015 protected $_oGroups = null;
00016
00020 protected $_sCoreTbl = 'oxvoucherseries';
00021
00025 protected $_sClassName = 'oxvoucherserie';
00026
00030 public function __construct()
00031 {
00032 parent::__construct();
00033 $this->init( $this->_sCoreTbl);
00034 }
00035
00043 public function delete( $sOxId = null )
00044 {
00045
00046 $this->unsetUserGroups();
00047 $this->deleteVoucherList();
00048 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 $sSelect = 'select gr.* from oxgroups as gr, oxobject2group as o2g where ';
00062 $sSelect .= 'o2g.oxobjectid = "'. $this->getId() .'" and gr.oxid = o2g.oxgroupsid ';
00063 $this->_oGroups->selectString( $sSelect );
00064 }
00065
00066 return $this->_oGroups;
00067 }
00068
00074 public function unsetUserGroups()
00075 {
00076 $sDelete = 'delete from oxobject2group where oxobjectid = "' . $this->getId() . '"';
00077 oxDb::getDb()->execute( $sDelete );
00078 }
00079
00085 public function getVoucherList()
00086 {
00087 $oVoucherList = oxNew( 'oxvoucherlist' );
00088 $sSelect = 'select * from oxvouchers where oxvoucherserieid = "' . $this->getId() . '"';
00089 $oVoucherList->selectString( $sSelect );
00090 return $oVoucherList;
00091 }
00092
00098 public function deleteVoucherList()
00099 {
00100 $sDelete = 'delete from oxvouchers where oxvoucherserieid = "' . $this->getId() . '"';
00101 oxDb::getDb()->execute( $sDelete );
00102 }
00103
00109 public function countVouchers()
00110 {
00111 $aStatus = array();
00112
00113 $oDB = oxDb::getDb();
00114 $sQuery = 'select count(*) as total from oxvouchers where oxvoucherserieid = "' . $this->getId() . '"';
00115 $aStatus['total'] = $oDB->getOne( $sQuery );
00116
00117 $sQuery = 'select count(*) as used from oxvouchers where oxvoucherserieid = "' . $this->getId() . '" and oxorderid is not NULL and oxorderid != ""';
00118 $aStatus['used'] = $oDB->getOne( $sQuery );
00119
00120 $aStatus['available'] = $aStatus['total'] - $aStatus['used'];
00121
00122 return $aStatus;
00123 }
00124 }