Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezwishlist.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: ezwishlist.php 8861 2002-01-03 15:39:06Z bf $
5 //
6 // Definition of eZWishList class
7 //
8 // Created on: <21-Oct-2000 18:06:52 bf>
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 //
30
59 // include_once( "classes/ezdb.php" );
60 // include_once( "eztrade/classes/ezwishlistitem.php" );
61
62 class eZWishList
63 {
70 function __construct( $id="" )
71 {
72 $this->IsConnected = false;
73 $this->IsPublic = 0;
74 $this->IsBought = 0;
75
76 if ( $id != "" )
77 {
78 $this->ID = $id;
79 $this->get( $this->ID );
80 }
81 }
82
86 function store()
87 {
88 $db =& eZDB::globalDatabase();
89 $db->begin();
90
91 if ( !isset( $this->ID ) )
92 {
93 $db->lock( "eZTrade_WishList" );
94 $nextID = $db->nextID( "eZTrade_WishList", "ID" );
95
96 $res = $db->query( "INSERT INTO eZTrade_WishList
97 ( ID, UserID, IsPublic )
98 VALUES
99 ( '$nextID',
100 '$this->UserID',
101 '$this->IsPublic' )" );
102 $db->unlock();
103 $this->ID = $nextID;
104 }
105 else
106 {
107 $res = $db->query( "UPDATE eZTrade_WishList SET
108 UserID='$this->UserID',
109 IsPublic='$this->IsPublic'
110 WHERE ID='$this->ID'
111 " );
112 }
113
114 if ( $res == false )
115 $db->rollback( );
116 else
117 $db->commit();
118
119 return true;
120 }
121
125 function get( $id="" )
126 {
127 $db =& eZDB::globalDatabase();
128 $ret = false;
129
130 if ( $id != "" )
131 {
132 $db->array_query( $wishlist_array, "SELECT * FROM eZTrade_WishList WHERE ID='$id'" );
133 if ( count( $wishlist_array ) > 1 )
134 {
135 die( "Error: WishList's with the same ID was found in the database. This shouldent happen." );
136 }
137 else if( count( $wishlist_array ) == 1 )
138 {
139 $this->ID = $wishlist_array[0][$db->fieldName( "ID" )];
140 $this->UserID = $wishlist_array[0][$db->fieldName( "UserID" )];
141 $this->IsPublic = $wishlist_array[0][$db->fieldName( "IsPublic" )];
142 $ret = $this;
143 }
144 }
145 return $ret;
146 }
147
148
152 function getByUser( $user )
153 {
154 $db =& eZDB::globalDatabase();
155
156 $ret = false;
157 if ( is_a( $user, "eZUser" ) )
158 {
159 $sid = $user->id();
160 $db->array_query( $wishlist_array, "SELECT * FROM
161 eZTrade_WishList
162 WHERE UserID='$sid'" );
163
164 if ( count( $wishlist_array ) == 1 )
165 {
166 $ret = new eZWishList( $wishlist_array[0][$db->fieldName( "ID" )] );
167 }
168
169 }
170 return $ret;
171 }
172
177 function delete()
178 {
179 $db =& eZDB::globalDatabase();
180 $db->begin();
181
182 $items = $this->items();
183
184 if ( $items )
185 {
186 $i = 0;
187 foreach ( $items as $item )
188 {
189 $item->delete();
190 }
191 }
192
193 $res = $db->query( "DELETE FROM eZTrade_WishList WHERE ID='$this->ID'" );
194
195 if ( $res == false )
196 $db->rollback( );
197 else
198 $db->commit();
199
200
201 return true;
202 }
203
207 function id( )
208 {
209 return $this->ID;
210 }
211
215 function &user()
216 {
217 $user = new eZUser( $this->UserID );
218
219 return $user;
220 }
221
227 function setUser( $user )
228 {
229 if ( is_a( $user, "eZUser" ) )
230 {
231 $this->UserID = $user->id();
232 }
233 }
234
238 function setIsPublic( $value )
239 {
240 if ( $value == true )
241 $this->IsPublic = 1;
242 else
243 $this->IsPublic = 0;
244 }
245
246
250 function isPublic( )
251 {
252 $ret = 0;
253 if ( $this->IsPublic == 1 )
254 {
255 $ret = true;
256 }
257
258 return $ret;
259 }
260
266 function &items( )
267 {
268 $ret = array();
269
270 $db =& eZDB::globalDatabase();
271
272 $db->array_query( $wishlist_array, "SELECT * FROM
273 eZTrade_WishListItem
274 WHERE WishListID='$this->ID'" );
275
276 if ( count( $wishlist_array ) > 0 )
277 {
278 $return_array = array();
279 foreach ( $wishlist_array as $item )
280 {
281 $ret[] = new eZWishListItem( $item[$db->fieldName( "ID" )] );
282 }
283 }
284
285 return $ret;
286 }
287
291 function clear()
292 {
293 $db =& eZDB::globalDatabase();
294 $db->begin();
295
296 $items = $this->items();
297
298 // delete the option values and wishlist items
299 foreach ( $items as $item )
300 {
301 $itemID = $item->id();
302 $res[] = $db->query( "DELETE FROM
303 eZTrade_WishListOptionValue
304 WHERE WishlistItemID='$itemID'" );
305
306 $res[] = $db->query( "DELETE FROM
307 eZTrade_WishListItem
308 WHERE ID='$itemID'" );
309 }
310 if ( in_array( false, $res ) )
311 $db->rollback( );
312 else
313 $db->commit();
314
315 $this->delete();
316 }
317
322 function search( $queryText )
323 {
324 $ret = array();
325
326 $db =& eZDB::globalDatabase();
327
328 $db->array_query( $wishlist_array,
329 "SELECT eZTrade_WishList.ID AS ID FROM eZTrade_WishList, eZUser_User
330 WHERE eZTrade_WishList.UserID=eZUser_User.ID
331 AND eZTrade_WishList.IsPublic=1
332 AND ( eZUser_User.Email='$queryText'
333 OR eZUser_User.FirstName='$queryText'
334 OR eZUser_User.LastName='$queryText' )
335 GROUP BY eZUser_User.ID, eZTrade_WishList.ID" );
336
337 foreach ( $wishlist_array as $item )
338 {
339 $ret[] = new eZWishList( $item[$db->fieldName( "ID" )] );
340 }
341
342 return $ret;
343
344 }
345
346 var $ID;
347 var $UserID;
348 var $IsPublic;
349 var $IsBought;
350 var $IsConnected;
351 }
352 ?>
$i
$i
Definition: admin/adlist.php:91
$items
$items
Definition: admin/orderview.php:211
eZDB\globalDatabase
static & globalDatabase()
Definition: ezdb.php:134
eZUser
Definition: ezuser.php:76
eZWishListItem
Definition: ezwishlistitem.php:55
eZWishList
Definition: ezwishlist.php:63
eZWishList\items
& items()
Definition: ezwishlist.php:266
eZWishList\isPublic
isPublic()
Definition: ezwishlist.php:250
eZWishList\setUser
setUser( $user)
Definition: ezwishlist.php:227
eZWishList\user
& user()
Definition: ezwishlist.php:215
eZWishList\getByUser
getByUser( $user)
Definition: ezwishlist.php:152
eZWishList\store
store()
Definition: ezwishlist.php:86
eZWishList\clear
clear()
Definition: ezwishlist.php:291
eZWishList\$IsPublic
$IsPublic
Definition: ezwishlist.php:348
eZWishList\$IsBought
$IsBought
Definition: ezwishlist.php:349
eZWishList\id
id()
Definition: ezwishlist.php:207
eZWishList\$ID
$ID
Definition: ezwishlist.php:346
eZWishList\__construct
__construct( $id="")
Definition: ezwishlist.php:70
eZWishList\$IsConnected
$IsConnected
Definition: ezwishlist.php:350
eZWishList\$UserID
$UserID
Definition: ezwishlist.php:347
eZWishList\search
search( $queryText)
Definition: ezwishlist.php:322
eZWishList\setIsPublic
setIsPublic( $value)
Definition: ezwishlist.php:238
$item
$item
Definition: classes/admin/linklist.php:228
$id
$id
Definition: companytypelist.php:193
$db
$db
Definition: ezarticle/user/authorlist.php:53
$ret
$ret
Definition: ezsitemanager/admin/filelist.php:88
$res
$res
Definition: ezstats/admin/cron.php:45
$user
$user
Definition: user/adlist.php:39
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.