OXID eShop CE  4.8.11
 All Classes Files Functions Variables Pages
oxvoucherserie.php
Go to the documentation of this file.
1 <?php
2 
8 class oxVoucherSerie extends oxBase
9 {
10 
15  protected $_oGroups = null;
16 
20  protected $_sClassName = 'oxvoucherserie';
21 
25  public function __construct()
26  {
28  $this->init('oxvoucherseries');
29  }
30 
38  public function delete( $sOxId = null )
39  {
40  if ( !$sOxId ) {
41  $sOxId = $this->getId();
42  }
43 
44 
45  $this->unsetDiscountRelations();
46  $this->unsetUserGroups();
47  $this->deleteVoucherList();
48  return parent::delete( $sOxId );
49  }
50 
56  public function setUserGroups()
57  {
58  if ( $this->_oGroups === null ) {
59  $this->_oGroups = oxNew( 'oxlist' );
60  $this->_oGroups->init( 'oxgroups' );
61  $sViewName = getViewName( "oxgroups" );
62  $sSelect = "select gr.* from {$sViewName} as gr, oxobject2group as o2g where
63  o2g.oxobjectid = ". oxDb::getDb()->quote( $this->getId() ) ." and gr.oxid = o2g.oxgroupsid ";
64  $this->_oGroups->selectString( $sSelect );
65  }
66 
67  return $this->_oGroups;
68  }
69 
75  public function unsetUserGroups()
76  {
77  $oDb = oxDb::getDb();
78  $sDelete = 'delete from oxobject2group where oxobjectid = ' . $oDb->quote( $this->getId() );
79  $oDb->execute( $sDelete );
80  }
81 
87  public function unsetDiscountRelations()
88  {
89  $oDb = oxDb::getDb();
90  $sDelete = 'delete from oxobject2discount where oxobject2discount.oxdiscountid = ' . $oDb->quote( $this->getId() );
91  $oDb->execute( $sDelete );
92  }
93 
99  public function getVoucherList()
100  {
101  $oVoucherList = oxNew( 'oxvoucherlist' );
102  $sSelect = 'select * from oxvouchers where oxvoucherserieid = ' . oxDb::getDb()->quote( $this->getId() );
103  $oVoucherList->selectString( $sSelect );
104  return $oVoucherList;
105  }
106 
112  public function deleteVoucherList()
113  {
114  $oDb = oxDb::getDb();
115  $sDelete = 'delete from oxvouchers where oxvoucherserieid = ' . $oDb->quote( $this->getId() );
116  $oDb->execute( $sDelete );
117  }
118 
124  public function countVouchers()
125  {
126  $aStatus = array();
127 
128  $oDb = oxDb::getDb();
129  $sQuery = 'select count(*) as total from oxvouchers where oxvoucherserieid = ' .$oDb->quote( $this->getId() );
130  $aStatus['total'] = $oDb->getOne( $sQuery );
131 
132  $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))';
133  $aStatus['used'] = $oDb->getOne( $sQuery );
134 
135  $aStatus['available'] = $aStatus['total'] - $aStatus['used'];
136 
137  return $aStatus;
138  }
139 }