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 = '". $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 $sDelete = 'delete from oxobject2group where oxobjectid = "' . $this->getId() . '"';
00082 oxDb::getDb()->execute( $sDelete );
00083 }
00084
00090 public function unsetDiscountRelations()
00091 {
00092 $sDelete = 'delete from oxobject2discount where oxobject2discount.oxdiscountid = "' . $this->getId() . '"';
00093 oxDb::getDb()->execute( $sDelete );
00094 }
00095
00101 public function getVoucherList()
00102 {
00103 $oVoucherList = oxNew( 'oxvoucherlist' );
00104 $sSelect = 'select * from oxvouchers where oxvoucherserieid = "' . $this->getId() . '"';
00105 $oVoucherList->selectString( $sSelect );
00106 return $oVoucherList;
00107 }
00108
00114 public function deleteVoucherList()
00115 {
00116 $sDelete = 'delete from oxvouchers where oxvoucherserieid = "' . $this->getId() . '"';
00117 oxDb::getDb()->execute( $sDelete );
00118 }
00119
00125 public function countVouchers()
00126 {
00127 $aStatus = array();
00128
00129 $oDB = oxDb::getDb();
00130 $sQuery = 'select count(*) as total from oxvouchers where oxvoucherserieid = "' . $this->getId() . '"';
00131 $aStatus['total'] = $oDB->getOne( $sQuery );
00132
00133 $sQuery = 'select count(*) as used from oxvouchers where oxvoucherserieid = "' . $this->getId() . '" and oxorderid is not NULL and oxorderid != ""';
00134 $aStatus['used'] = $oDB->getOne( $sQuery );
00135
00136 $aStatus['available'] = $aStatus['total'] - $aStatus['used'];
00137
00138 return $aStatus;
00139 }
00140 }