Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezvoucherused.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: ezvoucherused.php 7870 2001-10-16 09:21:05Z ce $
5 //
6 // eZVoucherUsed class
7 //
8 // Christoffer A. Elo <ce@ez.no>
9 // Created on: <06-Sep-2001 09:46:53 ce>
10 //
11 // This source file is part of Exponential Basic, publishing software.
12 // Copyright (C) 1999-2001 eZ systems as
13 //
14 // This program is free software; you can redistribute it and/or
15 // modify it under the terms of the GNU General Public License
16 // as published by the Free Software Foundation; either version 2
17 // of the License, or (at your option) any later version.
18 //
19 // This program is distributed in the hope that it will be useful,
20 // but WITHOUT ANY WARRANTY; without even the implied warranty of
21 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 // GNU General Public License for more details.
23 //
24 // You should have received a copy of the GNU General Public License
25 // along with this program; if not, write to the Free Software
26 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, US
27 //
28
31
44 // include_once( "classes/ezdate.php" );
45 // include_once( "eztrade/classes/ezorder.php" );
46 // include_once( "eztrade/classes/ezvoucher.php" );
47
48 class eZVoucherUsed
49 {
50
57 function __construct( $id=-1 )
58 {
59 if ( is_array( $id ) )
60 {
61 $this->fill( $id );
62 }
63 else if ( $id != -1 )
64 {
65 $this->ID = $id;
66 $this->get( $this->ID );
67 }
68 }
69
73 function store()
74 {
75 $db =& eZDB::globalDatabase();
76 $db->begin();
77
78
79 if ( !isset( $this->ID ) )
80 {
81 $db->lock( "eZTrade_VoucherUsed" );
82 $nextID = $db->nextID( "eZTrade_VoucherUsed", "ID" );
83 $timeStamp =& (new eZDateTime())->timeStamp( true );
84 $password = md5( $this->Password );
85
86 $res = $db->query( "INSERT INTO eZTrade_VoucherUsed
87 ( ID, Used, Price, VoucherID, OrderID, UserID )
88 VALUES
89 ( '$nextID',
90 '$timeStamp',
91 '$this->Price',
92 '$this->VoucherID',
93 '$this->OrderID',
94 '$this->UserID'
95 )" );
96
97 $this->ID = $nextID;
98 }
99 elseif ( is_numeric( $this->ID ) )
100 {
101 $res = $db->query( "UPDATE eZTrade_VoucherUsed SET
102 Used=Used,
103 Price='$this->Price',
104 VoucherID='$this->VoucherID',
105 OrderID='$this->OrderID',
106 UserID='$this->UserID'
107 WHERE ID='$this->ID'" );
108 }
109 $db->unlock();
110
111 if ( $res == false )
112 $db->rollback( );
113 else
114 $db->commit();
115
116 return true;
117 }
118
122 function delete( $catID=-1 )
123 {
124 if ( $catID == -1 )
125 $catID = $this->ID;
126
127 $db =& eZDB::globalDatabase();
128 $db->begin();
129
130 $res = $db->query( "DELETE FROM eZTrade_VoucherUsed WHERE ID='$this->ID'" );
131
132 if ( $ret == false )
133 $db->rollback( );
134 else
135 $db->commit();
136 }
137
143 function get( $id=-1 )
144 {
145 $db =& eZDB::globalDatabase();
146
147 $ret = false;
148 if ( $id != "" )
149 {
150 $db->array_query( $voucherArray, "SELECT * FROM eZTrade_VoucherUsed WHERE ID='$id'",
151 0, 1 );
152 if( count( $voucherArray ) == 1 )
153 {
154 $this->fill( $voucherArray[0] );
155 $ret = true;
156 }
157 elseif( count( $voucherArray ) == 1 )
158 {
159 $this->ID = 0;
160 }
161 }
162 return $ret;
163 }
164
168 function fill( $voucherArray )
169 {
170 $db =& eZDB::globalDatabase();
171 $this->ID = $voucherArray[$db->fieldName( "ID" )];
172 $this->Used = $voucherArray[$db->fieldName( "Used" )];
173 $this->Price = $voucherArray[$db->fieldName( "Price" )];
174 $this->VoucherID = $voucherArray[$db->fieldName( "VoucherID" )];
175 $this->OrderID = $voucherArray[$db->fieldName( "OrderID" )];
176 $this->UserID = $voucherArray[$db->fieldName( "UserID" )];
177 }
178
184 function &getAll( $offset=0, $limit=20 )
185 {
186 $db =& eZDB::globalDatabase();
187
188 $returnArray = array();
189 $voucherArray = array();
190
191 if ( $limit == false )
192 {
193 $db->array_query( $voucherArray, "SELECT ID
194 FROM eZTrade_VoucherUsed
195 " );
196 }
197 else
198 {
199 $db->array_query( $voucherArray, "SELECT ID
200 FROM eZTrade_VoucherUsed
201 ", array( "Limit" => $limit, "Offset" => $offset ) );
202 }
203
204 for ( $i=0; $i < count($voucherArray); $i++ )
205 {
206 $returnArray[$i] = new eZVoucherUsed( $voucherArray[$i][$db->fieldName( "ID" )] );
207 }
208
209 return $returnArray;
210 }
211
215 function count()
216 {
217 $db =& eZDB::globalDatabase();
218 $ret = false;
219
220 $db->query_single( $result, "SELECT COUNT(ID) as Count
221 FROM eZTrade_VoucherUsed" );
222 $ret = $result[$db->fieldName( "Count" )];
223 return $ret;
224 }
225
229 function id()
230 {
231 return $this->ID;
232 }
233
237 function &used()
238 {
239 $dateTime = new eZDateTime();
240 $dateTime->setTimeStamp( $this->Used );
241
242 return $dateTime;
243 }
244
248 function setPrice( $value )
249 {
250 $this->Price = $value;
251 setType( $this->Price, "double" );
252 }
253
257 function setUser( &$value )
258 {
259 if ( get_class ( $value ) )
260 $this->UserID = $value->id();
261 else if ( is_numeric ( $value ) )
262 $this->UserID = $value;
263 }
264
268 function setVoucher( &$value )
269 {
270 if ( get_class ( $value ) )
271 {
272 $this->VoucherID = $value->id();
273 }
274 else if ( is_numeric ( $value ) )
275 {
276 $this->VoucherID = $value;
277 }
278 }
279
283 function setOrder( &$value )
284 {
285 if ( get_class ( $value ) )
286 {
287 $this->OrderID = $value->id();
288 }
289 else if ( is_numeric ( $value ) )
290 {
291 $this->OrderID = $value;
292 }
293 }
294
298 function &voucher( $asObject=true )
299 {
300 if ( $asObject )
301 {
302 $ret = new eZVoucher( $this->VoucherID );
303 }
304 else
305 {
306 $ret = $this->VoucherID;
307 }
308 return $ret;
309 }
310
314 function &order( $asObject=true )
315 {
316 if ( $asObject )
317 {
318 $ret = new eZOrder( $this->OrderID );
319 }
320 else
321 {
322 $ret = $this->OrderID;
323 }
324 return $ret;
325 }
326
330 function &user( $asObject=true )
331 {
332 if ( $asObject )
333 {
334 $ret = new eZUser( $this->UserID );
335 }
336 else
337 {
338 $ret = $this->UserID;
339 }
340 return $ret;
341 }
342
346 function &price( )
347 {
348 return $this->Price;
349 }
350
355 function &correctPrice( $calcVAT )
356 {
357 $voucher =& $this->voucher();
358 $product =& $voucher->product();
359
360 $price = $this->Price;
361
362 $vatType =& $product->vatType();
363
364 if ( $calcVAT == true )
365 {
366 if ( $product->excludedVAT() )
367 {
368 $vatType =& $product->vatType();
369 $vat = 0;
370
371 if ( $vatType )
372 {
373 $vat =& $vatType->value();
374 }
375
376 $price = ( $price * $vat / 100 ) + $price;
377 }
378 }
379 else
380 {
381 if ( $product->includesVAT() )
382 {
383 $vatType =& $product->vatType();
384 $vat = 0;
385
386 if ( $vatType )
387 {
388 $vat =& $vatType->value();
389 }
390
391 $price = $price - ( $price / ( 100 + $vat ) ) * $vat;
392
393 }
394 }
395 return $price;
396 }
397
398
402 function getByUser( &$user )
403 {
404 $db =& eZDB::globalDatabase();
405 $ret = array();
406
407 $userID = $user->id();
408
409 $db->array_query( $res, "SELECT ID FROM eZTrade_VoucherUsed WHERE UserID='$userID' ORDER By Used DESC " );
410
411 foreach( $res as $result )
412 {
413 $ret[] = new eZVoucherUsed( $result[$db->fieldName( "ID" )] );
414 }
415
416 return $ret;
417 }
418
419
420
421 var $ID;
422 var $Used;
423 var $Price;
424 var $UserID;
425 var $OrderID;
426 }
427
428 ?>
$i
$i
Definition: admin/adlist.php:91
$userID
else $userID
Definition: appointmentedit.php:121
$dateTime
$dateTime
Definition: authorview.php:77
eZDB\globalDatabase
static & globalDatabase()
Definition: ezdb.php:134
eZDateTime
Definition: ezdatetime.php:55
eZOrder
Definition: ezorder.php:52
eZUser
Definition: ezuser.php:76
eZVoucherUsed
Definition: ezvoucherused.php:49
eZVoucherUsed\used
& used()
Definition: ezvoucherused.php:237
eZVoucherUsed\$Used
$Used
Definition: ezvoucherused.php:422
eZVoucherUsed\correctPrice
& correctPrice( $calcVAT)
Definition: ezvoucherused.php:355
eZVoucherUsed\store
store()
Definition: ezvoucherused.php:73
eZVoucherUsed\setUser
setUser(&$value)
Definition: ezvoucherused.php:257
eZVoucherUsed\getAll
& getAll( $offset=0, $limit=20)
Definition: ezvoucherused.php:184
eZVoucherUsed\$Price
$Price
Definition: ezvoucherused.php:423
eZVoucherUsed\count
count()
Definition: ezvoucherused.php:215
eZVoucherUsed\order
& order( $asObject=true)
Definition: ezvoucherused.php:314
eZVoucherUsed\setOrder
setOrder(&$value)
Definition: ezvoucherused.php:283
eZVoucherUsed\id
id()
Definition: ezvoucherused.php:229
eZVoucherUsed\$OrderID
$OrderID
Definition: ezvoucherused.php:425
eZVoucherUsed\voucher
& voucher( $asObject=true)
Definition: ezvoucherused.php:298
eZVoucherUsed\$ID
$ID
Definition: ezvoucherused.php:421
eZVoucherUsed\__construct
__construct( $id=-1)
Definition: ezvoucherused.php:57
eZVoucherUsed\setPrice
setPrice( $value)
Definition: ezvoucherused.php:248
eZVoucherUsed\fill
fill( $voucherArray)
Definition: ezvoucherused.php:168
eZVoucherUsed\price
& price()
Definition: ezvoucherused.php:346
eZVoucherUsed\getByUser
getByUser(&$user)
Definition: ezvoucherused.php:402
eZVoucherUsed\setVoucher
setVoucher(&$value)
Definition: ezvoucherused.php:268
eZVoucherUsed\user
& user( $asObject=true)
Definition: ezvoucherused.php:330
eZVoucherUsed\$UserID
$UserID
Definition: ezvoucherused.php:424
eZVoucher
Definition: ezvoucher.php:54
$result
$result
Definition: companysearch.php:94
$id
$id
Definition: companytypelist.php:193
$db
$db
Definition: ezarticle/user/authorlist.php:53
$limit
$limit
Definition: ezimagecatalogue/admin/imagelist.php:312
$ret
$ret
Definition: ezsitemanager/admin/filelist.php:88
$res
$res
Definition: ezstats/admin/cron.php:45
$offset
$offset
Definition: ezstats/admin/cron.php:51
$product
$product
Definition: homepage.php:202
$price
$price
Definition: pricegroupedit.php:39
$vat
foreach( $categoryArray as $catItem) $vat
Definition: productedit.php:1334
Password
</td ></tr >< tr >< td style="color:<?= isset( $error['password1'] ) ?> Password
Definition: step1.php:146
$user
$user
Definition: user/adlist.php:39
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.