oxvoucherserie.php

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         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             $sSelect  = 'select gr.* from oxgroups as gr, oxobject2group as o2g where ';
00066             $sSelect .= 'o2g.oxobjectid = "'. $this->getId() .'" and gr.oxid = o2g.oxgroupsid ';
00067             $this->_oGroups->selectString( $sSelect );
00068         }
00069 
00070         return $this->_oGroups;
00071     }
00072 
00078     public function unsetUserGroups()
00079     {
00080         $sDelete = 'delete from oxobject2group where oxobjectid = "' . $this->getId() . '"';
00081         oxDb::getDb()->execute( $sDelete );
00082     }
00083 
00089     public function unsetDiscountRelations()
00090     {
00091         $sDelete = 'delete from oxobject2discount where oxobject2discount.oxdiscountid = "' . $this->getId() . '"';
00092         oxDb::getDb()->execute( $sDelete );
00093     }
00094 
00100     public function getVoucherList()
00101     {
00102         $oVoucherList = oxNew( 'oxvoucherlist' );
00103         $sSelect = 'select * from oxvouchers where oxvoucherserieid = "' . $this->getId() . '"';
00104         $oVoucherList->selectString( $sSelect );
00105         return $oVoucherList;
00106     }
00107 
00113     public function deleteVoucherList()
00114     {
00115         $sDelete = 'delete from oxvouchers where oxvoucherserieid = "' . $this->getId() . '"';
00116         oxDb::getDb()->execute( $sDelete );
00117     }
00118 
00124     public function countVouchers()
00125     {
00126         $aStatus = array();
00127 
00128         $oDB = oxDb::getDb();
00129         $sQuery = 'select count(*) as total from oxvouchers where oxvoucherserieid = "' . $this->getId() . '"';
00130         $aStatus['total'] = $oDB->getOne( $sQuery );
00131 
00132         $sQuery = 'select count(*) as used from oxvouchers where oxvoucherserieid = "' . $this->getId()  . '" and oxorderid is not NULL and oxorderid != ""';
00133         $aStatus['used'] = $oDB->getOne( $sQuery );
00134 
00135         $aStatus['available'] = $aStatus['total'] - $aStatus['used'];
00136 
00137         return $aStatus;
00138     }
00139 }

Generated by  doxygen 1.6.2