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( isset( $this->_oGroups ) ) { 00059 return $this->_oGroups; 00060 } 00061 00062 $this->_oGroups = oxNew( 'oxlist' ); 00063 $this->_oGroups->init( 'oxgroups' ); 00064 $sSelect = 'select gr.* from oxgroups as gr, oxobject2group as o2g where '; 00065 $sSelect .= 'o2g.oxobjectid = "'. $this->getId() .'" and gr.oxid = o2g.oxgroupsid '; 00066 $this->_oGroups->selectString( $sSelect ); 00067 00068 return $this->_oGroups; 00069 } 00070 00076 public function unsetUserGroups() 00077 { 00078 $sDelete = 'delete from oxobject2group where oxobjectid = "' . $this->getId() . '"'; 00079 oxDb::getDb()->execute( $sDelete ); 00080 } 00081 00087 public function getVoucherList() 00088 { 00089 $oVoucherList = oxNew( 'oxvoucherlist' ); 00090 $sSelect = 'select * from oxvouchers where oxvoucherserieid = "' . $this->getId() . '"'; 00091 $oVoucherList->selectString( $sSelect ); 00092 return $oVoucherList; 00093 } 00094 00100 public function deleteVoucherList() 00101 { 00102 $sDelete = 'delete from oxvouchers where oxvoucherserieid = "' . $this->getId() . '"'; 00103 oxDb::getDb()->execute( $sDelete ); 00104 } 00105 00111 public function countVouchers() 00112 { 00113 $aStatus = array(); 00114 00115 $oDB = oxDb::getDb(); 00116 $sQuery = 'select count(*) as total from oxvouchers where oxvoucherserieid = "' . $this->getId() . '"'; 00117 $aStatus['total'] = $oDB->getOne( $sQuery ); 00118 00119 $sQuery = 'select count(*) as used from oxvouchers where oxvoucherserieid = "' . $this->getId() . '" and oxorderid is not NULL and oxorderid != ""'; 00120 $aStatus['used'] = $oDB->getOne( $sQuery ); 00121 00122 $aStatus['available'] = $aStatus['total'] - $aStatus['used']; 00123 00124 return $aStatus; 00125 } 00126 }