Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezvoucher.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: ezvoucher.php 9327 2002-03-04 12:43:38Z ce $
5 //
6 // eZVoucher class
7 //
8 // Christoffer A. Elo <ce@ez.no>
9 // Created on: <19-Jun-2001 17:41:06 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
48 // include_once( "classes/ezdate.php" );
49
50 // include_once( "eztrade/classes/ezvoucherinformation.php" );
51 // include_once( "eztrade/classes/ezvoucherused.php" );
52
53 class eZVoucher
54 {
55
62 function __construct( $id=-1 )
63 {
64 if ( is_array( $id ) )
65 {
66 $this->fill( $id );
67 }
68 else if ( $id != -1 )
69 {
70 $this->ID = $id;
71 $this->get( $this->ID );
72 }
73 }
74
78 function store()
79 {
80 $db =& eZDB::globalDatabase();
81 $db->begin();
82
83
84 if ( !isset( $this->ID ) )
85 {
86 $db->lock( "eZTrade_Voucher" );
87 $nextID = $db->nextID( "eZTrade_Voucher", "ID" );
88 $timeStamp =& (new eZDateTime())->timeStamp( true );
89 $password = md5( $this->Password );
90
91 $res = $db->query( "INSERT INTO eZTrade_Voucher
92 ( ID, Created, Price, Available, KeyNumber, UserID, ProductID, TotalValue )
93 VALUES
94 ( '$nextID',
95 '$timeStamp',
96 '$this->Price',
97 '$this->Available',
98 '$this->KeyNumber',
99 '$this->UserID',
100 '$this->ProductID',
101 '$this->TotalValue'
102 )" );
103
104 $this->ID = $nextID;
105 }
106 elseif ( is_numeric( $this->ID ) )
107 {
108 $res = $db->query( "UPDATE eZTrade_Voucher SET
109 Created=Created,
110 Price='$this->Price',
111 Available='$this->Available',
112 KeyNumber='$this->KeyNumber',
113 UserID='$this->UserID',
114 ProductID='$this->ProductID',
115 TotalValue='$this->TotalValue'
116 WHERE ID='$this->ID'" );
117 }
118 $db->unlock();
119
120 if ( $res == false )
121 $db->rollback( );
122 else
123 $db->commit();
124
125 return true;
126 }
127
131 function delete( $catID=-1 )
132 {
133 if ( $catID == -1 )
134 $catID = $this->ID;
135
136 $db =& eZDB::globalDatabase();
137 $db->begin();
138
139 $res = $db->query( "DELETE FROM eZTrade_Voucher WHERE ID='$this->ID'" );
140
141 if ( $ret == false )
142 $db->rollback( );
143 else
144 $db->commit();
145 }
146
152 function get( $id=-1 )
153 {
154 $db =& eZDB::globalDatabase();
155
156 $ret = false;
157 if ( $id != "" )
158 {
159 $db->array_query( $voucherArray, "SELECT * FROM eZTrade_Voucher WHERE ID='$id'",
160 0, 1 );
161
162 if( count( $voucherArray ) == 1 )
163 {
164 $this->fill( $voucherArray[0] );
165 $ret = true;
166 }
167 elseif( count( $voucherArray ) == 1 )
168 {
169 $this->ID = 0;
170 }
171 }
172 return $ret;
173 }
174
178 function fill( &$voucherArray )
179 {
180 $db =& eZDB::globalDatabase();
181 $this->ID =& $voucherArray[$db->fieldName( "ID" )];
182 $this->Created =& $voucherArray[$db->fieldName( "Created" )];
183 $this->Price =& $voucherArray[$db->fieldName( "Price" )];
184 $this->Available =& $voucherArray[$db->fieldName( "Available" )];
185 $this->KeyNumber =& $voucherArray[$db->fieldName( "KeyNumber" )];
186 $this->UserID =& $voucherArray[$db->fieldName( "UserID" )];
187 $this->ProductID =& $voucherArray[$db->fieldName( "ProductID" )];
188 $this->TotalValue =& $voucherArray[$db->fieldName( "TotalValue" )];
189 }
190
196 static public function &getAll( $offset=0, $limit=20 )
197 {
198 $db =& eZDB::globalDatabase();
199
200 $returnArray = array();
201 $voucherArray = array();
202
203 if ( $limit == false )
204 {
205 $db->array_query( $voucherArray, "SELECT ID
206 FROM eZTrade_Voucher
207 " );
208
209 }
210 else
211 {
212 $db->array_query( $voucherArray, "SELECT ID
213 FROM eZTrade_Voucher ORDER BY Created DESC
214 ", array( "Limit" => $limit, "Offset" => $offset ) );
215 }
216
217 for ( $i=0; $i < count($voucherArray); $i++ )
218 {
219 $returnArray[$i] = new eZVoucher( $voucherArray[$i][$db->fieldName( "ID" )] );
220 }
221
222 return $returnArray;
223 }
224
228 function count()
229 {
230 $db =& eZDB::globalDatabase();
231 $ret = false;
232
233 $db->query_single( $result, "SELECT COUNT(ID) as Count
234 FROM eZTrade_Voucher" );
235 $ret = $result[$db->fieldName( "Count" )];
236 return $ret;
237 }
238
242 function id()
243 {
244 return $this->ID;
245 }
246
250 function &created()
251 {
252 $dateTime = new eZDateTime();
253 $dateTime->setTimeStamp( $this->Created );
254
255 return $dateTime;
256 }
257
261 function generateKey( $length=15 )
262 {
263 $this->KeyNumber = substr( md5( microtime() ), 0, $length );
264 }
265
269 function keyNumber( )
270 {
271 return $this->KeyNumber;
272 }
273
277 function &user( $asObject=true )
278 {
279 if ( $asObject )
280 $ret = new eZUser( $this->UserID );
281 else
282 $ret = $this->UserID;
283
284 return $ret;
285 }
286
290 function &product( $asObject=true )
291 {
292 if ( $asObject )
293 $ret = new eZProduct( $this->ProductID );
294 else
295 $ret = $this->ProductID;
296
297 return $ret;
298 }
299
303 function setAvailable( $value )
304 {
305 if ( $value == true )
306 $this->Available = 1;
307 else
308 $this->Available = 0;
309 }
310
314 function isAvailable()
315 {
316 if ( $this->Available == 1 )
317 return true;
318 else
319 return false;
320 }
321
325 function setPrice( $value )
326 {
327 $this->Price = $value;
328 setType( $this->Price, "integer" );
329 }
330
334 function setTotalValue( $value )
335 {
336 $this->TotalValue = $value;
337 setType( $this->TotalValue, "integer" );
338 }
339
343 function setUser( &$user )
344 {
345 if ( is_a ( $user, "eZUser" ) )
346 $this->UserID = $user->id();
347 elseif ( is_numeric ( $user ) )
348 $this->UserID = $user;
349 }
350
354 function setProduct( &$product )
355 {
356 if ( is_a ( $product, "eZProduct" ) )
357 $this->ProductID = $product->id();
358 elseif ( is_numeric ( $user ) )
359 $this->ProductID = $product;
360 }
361
365 function &price( )
366 {
367 return $this->Price;
368 }
369
373 function &totalValue( )
374 {
375 return $this->TotalValue;
376 }
377
382 function &correctPrice( $calcVAT )
383 {
384 $product =& $this->product();
385
386 $price = $this->Price;
387
388 $vatType =& $product->vatType();
389
390 if ( $calcVAT == true )
391 {
392 if ( $product->excludedVAT() )
393 {
394 $vatType =& $product->vatType();
395 $vat = 0;
396
397 if ( $vatType )
398 {
399 $vat =& $vatType->value();
400 }
401
402 $price = ( $price * $vat / 100 ) + $price;
403 }
404 }
405 else
406 {
407 if ( $product->includesVAT() )
408 {
409 $vatType =& $product->vatType();
410 $vat = 0;
411
412 if ( $vatType )
413 {
414 $vat =& $vatType->value();
415 }
416
417 $price = $price - ( $price / ( 100 + $vat ) ) * $vat;
418
419 }
420 }
421 return $price;
422 }
423
424
428 function getFromKeyNumber( &$key, $available=true )
429 {
430 $db =& eZDB::globalDatabase();
431 $ret = false;
432 if ( !$key )
433 return false;
434
435 if ( $available )
436 $db->query_single( $res, "SELECT ID FROM eZTrade_Voucher WHERE KeyNumber='$key' AND Available='1'" );
437 else
438 $db->query_single( $res, "SELECT ID FROM eZTrade_Voucher WHERE KeyNumber='$key'" );
439
440 if ( $res[$db->fieldName( "ID" )] )
441 {
442 $ret = new eZVoucher( $res[$db->fieldName( "ID" )] );
443 }
444
445 return $ret;
446 }
447
451 function getByUser( &$user, $available=true )
452 {
453 $db =& eZDB::globalDatabase();
454 $ret = array();
455
456 $userID = $user->id();
457
458 if ( $available )
459 $db->array_query( $res, "SELECT ID FROM eZTrade_Voucher WHERE UserID='$userID' AND Available='1' ORDER By Created DESC" );
460 else
461 $db->array_query( $res, "SELECT ID FROM eZTrade_Voucher WHERE UserID='$userID' ORDER By Created DESC " );
462
463 foreach( $res as $result )
464 {
465 $ret[] = new eZVoucher( $result[$db->fieldName( "ID" )] );
466 }
467
468 return $ret;
469 }
470
474 function information( )
475 {
476 $db =& eZDB::globalDatabase();
477 $ret = false;
478 $res = array();
479
480 $query = "SELECT ID FROM eZTrade_VoucherInformation WHERE VoucherID='$this->ID'";
481 $db->query_single( $res, $query );
482
483 if ( $res[$db->fieldName( "ID" )] )
484 {
485 $ret = new eZVoucherInformation( $res[$db->fieldName( "ID" )] );
486 }
487
488 return $ret;
489 }
490
494 function usedList( $id=false )
495 {
496 $db =& eZDB::globalDatabase();
497 $ret = array();
498
499 if ( !$id )
500 $id = $this->ID;
501
502 $db->array_query( $res, "SELECT ID FROM eZTrade_VoucherUsed WHERE VoucherID='$id'" );
503
504 foreach( $res as $used )
505 {
506 $ret[] = new eZVoucherUsed( $used[$db->fieldName( "ID" )] );
507 }
508
509 return $ret;
510 }
511
512 var $ID;
513 var $KeyNumber;
514 var $Created;
515 var $Available;
516 var $Price;
517 var $UserID;
518 var $ProductID;
519 var $TotalValue;
520 }
521
522 ?>
$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
eZProduct
Definition: ezproduct.php:71
eZUser
Definition: ezuser.php:76
eZVoucherInformation
Definition: ezvoucherinformation.php:55
eZVoucherUsed
Definition: ezvoucherused.php:49
eZVoucher
Definition: ezvoucher.php:54
eZVoucher\$UserID
$UserID
Definition: ezvoucher.php:517
eZVoucher\keyNumber
keyNumber()
Definition: ezvoucher.php:269
eZVoucher\user
& user( $asObject=true)
Definition: ezvoucher.php:277
eZVoucher\$Price
$Price
Definition: ezvoucher.php:516
eZVoucher\setPrice
setPrice( $value)
Definition: ezvoucher.php:325
eZVoucher\price
& price()
Definition: ezvoucher.php:365
eZVoucher\usedList
usedList( $id=false)
Definition: ezvoucher.php:494
eZVoucher\getFromKeyNumber
getFromKeyNumber(&$key, $available=true)
Definition: ezvoucher.php:428
eZVoucher\$Available
$Available
Definition: ezvoucher.php:515
eZVoucher\getAll
static & getAll( $offset=0, $limit=20)
Definition: ezvoucher.php:196
eZVoucher\$ProductID
$ProductID
Definition: ezvoucher.php:518
eZVoucher\generateKey
generateKey( $length=15)
Definition: ezvoucher.php:261
eZVoucher\information
information()
Definition: ezvoucher.php:474
eZVoucher\setProduct
setProduct(&$product)
Definition: ezvoucher.php:354
eZVoucher\setTotalValue
setTotalValue( $value)
Definition: ezvoucher.php:334
eZVoucher\isAvailable
isAvailable()
Definition: ezvoucher.php:314
eZVoucher\getByUser
getByUser(&$user, $available=true)
Definition: ezvoucher.php:451
eZVoucher\$Created
$Created
Definition: ezvoucher.php:514
eZVoucher\count
count()
Definition: ezvoucher.php:228
eZVoucher\created
& created()
Definition: ezvoucher.php:250
eZVoucher\$TotalValue
$TotalValue
Definition: ezvoucher.php:519
eZVoucher\id
id()
Definition: ezvoucher.php:242
eZVoucher\$KeyNumber
$KeyNumber
Definition: ezvoucher.php:513
eZVoucher\$ID
$ID
Definition: ezvoucher.php:512
eZVoucher\__construct
__construct( $id=-1)
Definition: ezvoucher.php:62
eZVoucher\setAvailable
setAvailable( $value)
Definition: ezvoucher.php:303
eZVoucher\totalValue
& totalValue()
Definition: ezvoucher.php:373
eZVoucher\setUser
setUser(&$user)
Definition: ezvoucher.php:343
eZVoucher\product
& product( $asObject=true)
Definition: ezvoucher.php:290
eZVoucher\fill
fill(&$voucherArray)
Definition: ezvoucher.php:178
eZVoucher\store
store()
Definition: ezvoucher.php:78
eZVoucher\correctPrice
& correctPrice( $calcVAT)
Definition: ezvoucher.php:382
$result
$result
Definition: companysearch.php:94
$id
$id
Definition: companytypelist.php:193
$query
if(isset( $Year) &&!is_numeric( $Year)||isset( $Month) &&!is_numeric( $Month)) $query
Definition: entryexitpages.php:65
$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+.