Go to the documentation of this file.00001 <?php
00002
00007 class oxVoucherSerie extends oxBase
00008 {
00009
00014 protected $_oGroups = null;
00015
00019 protected $_sClassName = 'oxvoucherserie';
00020
00024 public function __construct()
00025 {
00026 parent::__construct();
00027 $this->init('oxvoucherseries');
00028 }
00029
00037 public function delete( $sOxId = null )
00038 {
00039 if ( !$sOxId ) {
00040 $sOxId = $this->getId();
00041 }
00042
00043
00044 $this->unsetDiscountRelations();
00045 $this->unsetUserGroups();
00046 $this->deleteVoucherList();
00047 return 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 $sViewName = getViewName( "oxgroups" );
00061 $sSelect = "select gr.* from {$sViewName} as gr, oxobject2group as o2g where
00062 o2g.oxobjectid = ". oxDb::getDb()->quote( $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 $oDb = oxDb::getDb();
00077 $sDelete = 'delete from oxobject2group where oxobjectid = ' . $oDb->quote( $this->getId() );
00078 $oDb->execute( $sDelete );
00079 }
00080
00086 public function unsetDiscountRelations()
00087 {
00088 $oDb = oxDb::getDb();
00089 $sDelete = 'delete from oxobject2discount where oxobject2discount.oxdiscountid = ' . $oDb->quote( $this->getId() );
00090 $oDb->execute( $sDelete );
00091 }
00092
00098 public function getVoucherList()
00099 {
00100 $oVoucherList = oxNew( 'oxvoucherlist' );
00101 $sSelect = 'select * from oxvouchers where oxvoucherserieid = ' . oxDb::getDb()->quote( $this->getId() );
00102 $oVoucherList->selectString( $sSelect );
00103 return $oVoucherList;
00104 }
00105
00111 public function deleteVoucherList()
00112 {
00113 $oDb = oxDb::getDb();
00114 $sDelete = 'delete from oxvouchers where oxvoucherserieid = ' . $oDb->quote( $this->getId() );
00115 $oDb->execute( $sDelete );
00116 }
00117
00123 public function countVouchers()
00124 {
00125 $aStatus = array();
00126
00127 $oDb = oxDb::getDb();
00128 $sQuery = 'select count(*) as total from oxvouchers where oxvoucherserieid = ' .$oDb->quote( $this->getId() );
00129 $aStatus['total'] = $oDb->getOne( $sQuery );
00130
00131 $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))';
00132 $aStatus['used'] = $oDb->getOne( $sQuery );
00133
00134 $aStatus['available'] = $aStatus['total'] - $aStatus['used'];
00135
00136 return $aStatus;
00137 }
00138 }