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 00045 $this->unsetUserGroups(); 00046 $this->deleteVoucherList(); 00047 parent::delete( $sOxId ); 00048 } 00049 00055 public function setUserGroups() 00056 { 00057 if ( $this->_oGroups === null ) { 00058 $this->_oGroups = oxNew( 'oxlist' ); 00059 $this->_oGroups->init( 'oxgroups' ); 00060 $sSelect = 'select gr.* from oxgroups as gr, oxobject2group as o2g where '; 00061 $sSelect .= 'o2g.oxobjectid = "'. $this->getId() .'" and gr.oxid = o2g.oxgroupsid '; 00062 $this->_oGroups->selectString( $sSelect ); 00063 } 00064 00065 return $this->_oGroups; 00066 } 00067 00073 public function unsetUserGroups() 00074 { 00075 $sDelete = 'delete from oxobject2group where oxobjectid = "' . $this->getId() . '"'; 00076 oxDb::getDb()->execute( $sDelete ); 00077 } 00078 00084 public function getVoucherList() 00085 { 00086 $oVoucherList = oxNew( 'oxvoucherlist' ); 00087 $sSelect = 'select * from oxvouchers where oxvoucherserieid = "' . $this->getId() . '"'; 00088 $oVoucherList->selectString( $sSelect ); 00089 return $oVoucherList; 00090 } 00091 00097 public function deleteVoucherList() 00098 { 00099 $sDelete = 'delete from oxvouchers where oxvoucherserieid = "' . $this->getId() . '"'; 00100 oxDb::getDb()->execute( $sDelete ); 00101 } 00102 00108 public function countVouchers() 00109 { 00110 $aStatus = array(); 00111 00112 $oDB = oxDb::getDb(); 00113 $sQuery = 'select count(*) as total from oxvouchers where oxvoucherserieid = "' . $this->getId() . '"'; 00114 $aStatus['total'] = $oDB->getOne( $sQuery ); 00115 00116 $sQuery = 'select count(*) as used from oxvouchers where oxvoucherserieid = "' . $this->getId() . '" and oxorderid is not NULL and oxorderid != ""'; 00117 $aStatus['used'] = $oDB->getOne( $sQuery ); 00118 00119 $aStatus['available'] = $aStatus['total'] - $aStatus['used']; 00120 00121 return $aStatus; 00122 } 00123 }