Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezpricegroup.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: ezpricegroup.php 9210 2002-02-13 09:14:20Z br $
5 //
6 // Definition of eZPriceGroup class
7 //
8 // Created on: <23-Feb-2001 12:57:01 amos>
9 //
10 // This source file is part of Exponential Basic, publishing software.
11 //
12 // Copyright (C) 1999-2001 eZ Systems. All rights reserved.
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
35 // include_once( "classes/ezdb.php" );
36
37 class eZPriceGroup
38 {
39 function __construct( $id = false )
40 {
41 if ( is_array( $id ) )
42 $this->fill( $id );
43 else if ( $id )
44 $this->get( $id );
45 }
46
47 function get( $id = false )
48 {
49 if ( !$id )
50 $id = $this->ID;
51 $db =& eZDB::globalDatabase();
52 $db->query_single( $array, "SELECT ID, Name, Description, Placement FROM eZTrade_PriceGroup
53 WHERE ID='$id'" );
54 $this->fill( $array );
55 }
56
57 function store()
58 {
59 $db =& eZDB::globalDatabase();
60 $db->begin();
61
62 $this->Name = $db->escapeString( $this->Name );
63 $this->Description = $db->escapeString( $this->Description );
64
65 if ( !isset( $this->Placement ) or !is_numeric( $this->Placement ) )
66 {
67 $db->query_single( $place, "SELECT max( Placement ) AS Placement
68 FROM eZTrade_PriceGroup" );
69 $this->Placement = $place[$db->fieldName("Placement")] == "NULL" ? 1 : $place[$db->fieldName("Placement")] + 1;
70 }
71
72 if ( is_numeric( $this->ID) )
73 {
74 $ret[] = $db->query( "UPDATE eZTrade_PriceGroup SET
75 Name='$this->Name',
76 Description='$this->Description',
77 Placement='$this->Placement'
78 WHERE
79 ID='$this->ID'" );
80 }
81 else
82 {
83 $db->lock( "eZTrade_PriceGroup" );
84 $nextID = $db->nextID( "eZTrade_PriceGroup", "ID" );
85 $ret[] = $db->query( "INSERT INTO eZTrade_PriceGroup
86 ( ID,
87 Name,
88 Description,
89 Placement )
90 VALUES
91 ( '$nextID',
92 '$this->Name',
93 '$this->Description',
94 '$this->Placement' )" );
95 $db->unlock();
96 $this->ID = $nextID;
97 }
98
99 eZDB::finish( $ret, $db );
100 }
101
102 function delete( $id = false )
103 {
104 if ( !$id )
105 $id = $this->ID;
106
107 $db =& eZDB::globalDatabase();
108 $db->begin();
109 $ret[] = $db->query( "DELETE FROM eZTrade_ProductPriceLink WHERE PriceID='$id'" );
110 $ret[] = $db->query( "DELETE FROM eZTrade_GroupPriceLink WHERE PriceID='$id'" );
111 $ret[] = $db->query( "DELETE FROM eZTrade_PriceGroup WHERE ID='$id'" );
112 eZDB::finish( $ret, $db );
113 }
114
115 function fill( $array )
116 {
117 $db =& eZDB::globalDatabase();
118 $this->ID = $array[$db->fieldName("ID")];
119 $this->Name = $array[$db->fieldName("Name")];
120 $this->Description = $array[$db->fieldName("Description")];
121 $this->Placement = $array[$db->fieldName("Placement")];
122 }
123
127 static public function &getAll( $as_object = true )
128 {
129 $db =& eZDB::globalDatabase();
130 $db->array_query( $array, "SELECT ID FROM eZTrade_PriceGroup
131 ORDER BY Placement" );
132 $ret = array();
133 foreach( $array as $row )
134 {
135 $ret[] = $as_object ? new eZPriceGroup( $row[$db->fieldName("ID")] ) : $row[$db->fieldName("ID")];
136 }
137 return $ret;
138 }
139
143 function &userGroups( $id = false, $as_object = true )
144 {
145 if ( !$id )
146 $id = $this->ID;
147 $db =& eZDB::globalDatabase();
148 $db->array_query( $array, "SELECT GroupID AS ID FROM eZTrade_GroupPriceLink
149 WHERE PriceID='$id'" );
150 $ret = array();
151 foreach( $array as $row )
152 {
153 $ret[] = $as_object ? new eZUserGroup( $row[$db->fieldName("ID")] ) : $row[$db->fieldName("ID")];
154 }
155 return $ret;
156 }
157
161 static public function &priceGroups( $inUser, $as_object = true )
162 {
163 $group_string = false;
164 if ( is_a( $inUser, "eZUser" ) )
165 {
166 $user =& $inUser;
167 }
168 else if ( is_numeric( $inUser ) )
169 {
170 $user = new eZUser( $inUser );
171 }
172
173 $groups = $user->groups( false );
174 $i = 0;
175 foreach( $groups as $group )
176 {
177 if ( $i == 0 )
178 {
179 $group_string = "GroupID=$group";
180 }
181 else
182 {
183 $group_string = $group_string . " OR GroupID=$group";
184 }
185 $i++;
186 }
187
188 $ret = array();
189 if ( $group_string != "" )
190 {
191 $db =& eZDB::globalDatabase();
192 $db->array_query( $array, "SELECT PriceID AS ID FROM eZTrade_GroupPriceLink
193 WHERE $group_string" );
194 foreach( $array as $row )
195 {
196 $ret[] = $as_object ? new eZPriceGroup( $row[$db->fieldName("ID")] ) : $row[$db->fieldName("ID")];
197 }
198 }
199 return $ret;
200 }
201
205 function addUserGroup( $group_id, $id = false )
206 {
207 if ( !$id )
208 $id = $this->ID;
209 if ( is_a( $group_id, "eZUserGroup" ) )
210 $group_id = $group_id->id();
211
212 $db =& eZDB::globalDatabase();
213 $db->begin();
214 $ret[] = $db->query( "INSERT INTO eZTrade_GroupPriceLink
215 ( GroupID,
216 PriceID )
217 VALUES
218 ( '$group_id',
219 '$id' )" );
220 eZDB::finish( $ret, $db );
221 }
222
226 function removeUserGroups( $id = false )
227 {
228 if ( !$id )
229 $id = $this->ID;
230
231 $db =& eZDB::globalDatabase();
232 $db->begin();
233 $ret[] = $db->query( "DELETE FROM eZTrade_GroupPriceLink WHERE PriceID='$id'" );
234 eZDB::finish( $ret, $db );
235 }
236
240 static public function correctPriceGroup( $group_id, $debug=false )
241 {
242 $db =& eZDB::globalDatabase();
243 if ( is_array( $group_id ) )
244 {
245 $first = true;
246 $group_text = '';
247 foreach( $group_id as $group )
248 {
249 $first ? $group_text = "GroupID='$group'" : $group_text .= "OR GroupID='$group'";
250 $first = false;
251 }
252 if ( $group_text )
253 $group_text = " AND ( $group_text )";
254 }
255 else
256 {
257 $group_text = "AND GroupID='$group_id'";
258 }
259
260 $db->array_query( $array, "SELECT PriceID
261 FROM eZTrade_GroupPriceLink, eZTrade_PriceGroup
262 WHERE PriceID=ID $group_text
263 ORDER BY Placement", array( "Limit" => 1, "Offset" => 0 ) );
264
265 if ( count( $array ) == 1 )
266 return $array[0][$db->fieldName("PriceID")];
267 return false;
268 }
269
270 /*
271 Returns the lowest price for an option.
272 */
273 static public function lowestPrice( $productid, $priceid, $optionid )
274 {
275 $db =& eZDB::globalDatabase();
276
277 $ini =& eZINI::instance( 'site.ini' );
278 $ret = false;
279 $ShowPriceGroups = $ini->variable( "eZTradeMain", "PriceGroupsEnabled" ) == "true" ? true : false;
280
281 if ( $ShowPriceGroups == true )
282 {
283 if ( is_array( $priceid ) )
284 {
285 $first = true;
286 foreach( $priceid as $group )
287 {
288 $first ? $group_text = "PriceID='$group'" : $group_text .= "OR PriceID='$group'";
289 $first = false;
290 }
291
292 if ( isset($group_text) )
293 $group_text = " AND ( $group_text )";
294 else
295 $group_text = "";
296 }
297 else
298 {
299 $group_text = "AND PriceID='$priceid'";
300 }
301
302 $db->array_query( $array, "SELECT Price, PriceID FROM eZTrade_ProductPriceLink
303 WHERE ProductID='$productid' $group_text
304 AND OptionID='$optionid' ORDER BY Price" );
305
306 if ( count( $array ) > 0 )
307 {
308 for($i=0;$i < count( $array ); $i++ )
309 {
310 $priceID = $array[$i][$db->fieldName("PriceID")];
311 if ( in_array( $priceID , $priceid ) )
312 {
313 $ret = $array[$i][$db->fieldName("Price")];
314 break;
315 }
316 }
317 }
318
319 if ( $ret == false )
320 {
321 $db->array_query( $array, "SELECT Price FROM eZTrade_OptionValue
322 WHERE OptionID='$optionid' ORDER BY Price" );
323
324 if ( count( $array ) > 0 )
325 $ret = $array[0][$db->fieldName("Price")];
326 }
327 }
328 else
329 {
330 $db->array_query( $array, "SELECT Price FROM eZTrade_OptionValue
331 WHERE OptionID='$optionid' ORDER BY Price" );
332 if ( count( $array ) > 0 )
333 $ret = $array[0][$db->fieldName("Price")];
334 }
335
336 return $ret;
337 }
338
339 /*
340 Returns the highest price for an option.
341 */
342 static public function highestPrice( $productid, $priceid, $optionid )
343 {
344 $db =& eZDB::globalDatabase();
345
346 $ini =& eZINI::instance( 'site.ini' );
347 $ret = false;
348 $ShowPriceGroups = $ini->variable( "eZTradeMain", "PriceGroupsEnabled" ) == "true" ? true : false;
349
350 if ( $ShowPriceGroups == true )
351 {
352 if ( is_array( $priceid ) )
353 {
354 $first = true;
355 foreach( $priceid as $group )
356 {
357 $first ? $group_text = "PriceID='$group'" : $group_text .= "OR PriceID='$group'";
358 $first = false;
359 }
360 if ( isset($group_text) )
361 $group_text = " AND ( $group_text )";
362 else
363 $group_text = "";
364 }
365 else
366 {
367 $group_text = "AND PriceID='$priceid'";
368 }
369
370 $db->array_query( $array, "SELECT Price, PriceID FROM eZTrade_ProductPriceLink
371 WHERE ProductID='$productid' $group_text
372 AND OptionID='$optionid' ORDER BY Price DESC" );
373
374 if ( count( $array ) > 0 )
375 {
376 for($i=0;$i < count( $array ); $i++ )
377 {
378 $priceID = $array[$i][$db->fieldName("PriceID")];
379
380 if ( in_array( $priceID , $priceid ) )
381 {
382 $ret = $array[$i][$db->fieldName("Price")];
383 break;
384 }
385 }
386 }
387
388 if ( $ret == false )
389 {
390 $db->array_query( $array, "SELECT Price FROM eZTrade_OptionValue
391 WHERE OptionID='$optionid' ORDER BY Price DESC" );
392
393 if ( count( $array ) > 0 )
394 {
395 $ret = $array[0][$db->fieldName("Price")];
396 }
397
398 }
399 }
400 else
401 {
402 $db->array_query( $array, "SELECT Price FROM eZTrade_OptionValue
403 WHERE OptionID='$optionid' ORDER BY Price DESC" );
404
405 if ( count( $array ) > 0 )
406 $ret = $array[0][$db->fieldName("Price")];
407 }
408 return $ret;
409 }
410
414 static public function correctPrice( $productid, $priceid, $optionid = 0, $valueid = 0 )
415 {
416 $db =& eZDB::globalDatabase();
417
418 $ini =& eZINI::instance( 'site.ini' );
419 $ShowPriceGroups = $ini->variable( "eZTradeMain", "PriceGroupsEnabled" ) == "true" ? true : false;
420 $group_text = false;
421 if ( $ShowPriceGroups == true )
422 {
423 if ( is_array( $priceid ) )
424 {
425 $first = true;
426 foreach( $priceid as $group )
427 {
428 $first ? $group_text = "PriceID='$group'" : $group_text .= "OR PriceID='$group'";
429 $first = false;
430 }
431 if ( isset( $group_text ) && $group_text != "" )
432 $group_text = " AND ( $group_text )";
433 else
434 $group_text = "";
435
436 }
437 else
438 {
439 $group_text = "AND PriceID='$priceid'";
440 }
441
442 $array = array();
443
444 // don't give better price unless you're a part of a price group
445 if ( $group_text != "" )
446 {
447 $db->array_query( $array, "SELECT Price FROM eZTrade_ProductPriceLink
448 WHERE ProductID='$productid' $group_text
449 AND OptionID='$optionid' AND ValueID='$valueid' ORDER BY Price" );
450
451 }
452 if ( isset( $array ) && count( $array ) == 1 )
453 return $array[0][$db->fieldName("Price")];
454 }
455 return false;
456 }
457
461 static public function prices( $productid, $optionid = 0, $valueid = 0 )
462 {
463 $db =& eZDB::globalDatabase();
464 $db->array_query( $array, "SELECT PriceID, Price FROM eZTrade_ProductPriceLink
465 WHERE ProductID='$productid' AND OptionID='$optionid'
466 AND ValueID='$valueid'" );
467 return $array;
468 }
469
473 function addPrice( $productid, $priceid, $price, $optionid = 0, $valueid = 0 )
474 {
475 $db =& eZDB::globalDatabase();
476 $db->begin();
477 $ret = array();
478 $query = "INSERT INTO eZTrade_ProductPriceLink
479 ( PriceID,
480 ProductID,
481 Price,
482 OptionID,
483 ValueID )
484 VALUES
485 ( '$priceid',
486 '$productid',
487 '$price',
488 '$optionid',
489 '$valueid' );";
490
491 $ret[] = $db->query( $query );
492
493 eZDB::finish( $ret, $db );
494 }
495
499 static public function removePrices( $productid, $optionid = 0, $valueid = 0, $priceid='' )
500 {
501 $db = eZDB::globalDatabase();
502 $db->begin();
503 if ( $optionid >= 0 )
504 $option_text = "AND OptionID='$optionid'";
505 if ( $valueid >= 0 )
506 $value_text = "AND ValueID='$valueid'";
507 if ( $priceid != '' )
508 $priceid_text = "AND PriceID='$priceid'";
509 else
510 $priceid_text = '';
511 $ret[] = $db->query( "DELETE FROM eZTrade_ProductPriceLink
512 WHERE ProductID='$productid' $option_text $value_text $priceid_text" );
513 eZDB::finish( $ret, $db );
514 }
515
519 function id()
520 {
521 return $this->ID;
522 }
523
527 function name()
528 {
529 return $this->Name;
530 }
531
535 function description()
536 {
537 return $this->Description;
538 }
539
543 function placement()
544 {
545 return $this->Placement;
546 }
547
551 function setName( $name )
552 {
553 $this->Name = $name;
554 }
555
559 function setDescription( $desc )
560 {
561 $this->Description = $desc;
562 }
563
567 function setPlacement( $place )
568 {
569 $this->Placement = $place;
570 }
571
572 var $ID;
573 var $Name;
574 var $Description;
575 var $Placement;
576 }
577
578 ?>
$i
$i
Definition: admin/adlist.php:91
$group
$group
Definition: admin/articleedit.php:799
eZDB\finish
static finish(&$resultArray, &$db)
Definition: ezdb.php:204
eZDB\globalDatabase
static & globalDatabase()
Definition: ezdb.php:134
eZPriceGroup
Definition: ezpricegroup.php:38
eZPriceGroup\$Name
$Name
Definition: ezpricegroup.php:573
eZPriceGroup\getAll
static & getAll( $as_object=true)
Definition: ezpricegroup.php:127
eZPriceGroup\highestPrice
static highestPrice( $productid, $priceid, $optionid)
Definition: ezpricegroup.php:342
eZPriceGroup\correctPriceGroup
static correctPriceGroup( $group_id, $debug=false)
Definition: ezpricegroup.php:240
eZPriceGroup\placement
placement()
Definition: ezpricegroup.php:543
eZPriceGroup\addUserGroup
addUserGroup( $group_id, $id=false)
Definition: ezpricegroup.php:205
eZPriceGroup\setDescription
setDescription( $desc)
Definition: ezpricegroup.php:559
eZPriceGroup\removeUserGroups
removeUserGroups( $id=false)
Definition: ezpricegroup.php:226
eZPriceGroup\$Description
$Description
Definition: ezpricegroup.php:574
eZPriceGroup\description
description()
Definition: ezpricegroup.php:535
eZPriceGroup\$ID
$ID
Definition: ezpricegroup.php:572
eZPriceGroup\correctPrice
static correctPrice( $productid, $priceid, $optionid=0, $valueid=0)
Definition: ezpricegroup.php:414
eZPriceGroup\setPlacement
setPlacement( $place)
Definition: ezpricegroup.php:567
eZPriceGroup\userGroups
& userGroups( $id=false, $as_object=true)
Definition: ezpricegroup.php:143
eZPriceGroup\removePrices
static removePrices( $productid, $optionid=0, $valueid=0, $priceid='')
Definition: ezpricegroup.php:499
eZPriceGroup\addPrice
addPrice( $productid, $priceid, $price, $optionid=0, $valueid=0)
Definition: ezpricegroup.php:473
eZPriceGroup\store
store()
Definition: ezpricegroup.php:57
eZPriceGroup\$Placement
$Placement
Definition: ezpricegroup.php:575
eZPriceGroup\name
name()
Definition: ezpricegroup.php:527
eZPriceGroup\prices
static prices( $productid, $optionid=0, $valueid=0)
Definition: ezpricegroup.php:461
eZPriceGroup\priceGroups
static & priceGroups( $inUser, $as_object=true)
Definition: ezpricegroup.php:161
eZPriceGroup\fill
fill( $array)
Definition: ezpricegroup.php:115
eZPriceGroup\setName
setName( $name)
Definition: ezpricegroup.php:551
eZPriceGroup\__construct
__construct( $id=false)
Definition: ezpricegroup.php:39
eZPriceGroup\lowestPrice
static lowestPrice( $productid, $priceid, $optionid)
Definition: ezpricegroup.php:273
eZPriceGroup\id
id()
Definition: ezpricegroup.php:519
eZUserGroup
Definition: ezusergroup.php:66
eZUser
Definition: ezuser.php:76
$ini
$ini
Definition: classes/admin/linklist.php:64
$desc
$desc
Definition: companytypelist.php:195
$name
$name
Definition: companytypelist.php:194
$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
$groups
if( $CategoryID !=0) $groups
Definition: ezbulkmail/admin/categoryedit.php:108
$row
$row
Definition: ezcalendar/user/dayview.php:403
$ret
$ret
Definition: ezsitemanager/admin/filelist.php:88
$debug
$debug
Definition: ezstats/admin/cron.php:36
$ShowPriceGroups
$ShowPriceGroups
Definition: orderedit.php:44
$price
$price
Definition: pricegroupedit.php:39
Name
if($user) if(isset( $next) && $next)<?=isset($all_fields_error) &&$all_fields_error ?><?=isset($password_error) &&$password_error ?></p ><? endif;?>< form method="post">< table border="0" cellspacing="2" cellpadding="2" class="boxtext" style="font-size=13;">< tr >< td style="color:<?= isset( $error['first_name'] ) ?> First Name
Definition: step1.php:127
$user
$user
Definition: user/adlist.php:39
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.