Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezvote.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: ezvote.php 6225 2001-07-20 11:22:30Z jakobn $
5 //
6 // Definition of eZVote class
7 //
8 // Created on: <19-Sep-2000 17:37:53 ce>
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
43 // include_once( "classes/ezdb.php" );
44
45 class eZVote
46 {
51 function __construct( $id=-1 )
52 {
53 $this->UserID = 0;
54 if ( $id != -1 )
55 {
56 $this->ID = $id;
57 $this->get( $this->ID );
58 }
59 }
63 function store()
64 {
65 $db =& eZDB::globalDatabase();
66
67 $db->begin();
68
69 $db->lock( "eZPoll_Vote" );
70 $nextID = $db->nextID( "eZPoll_Vote", "ID" );
71
72 $res = $db->query( "INSERT INTO eZPoll_Vote
73 ( ID, VotingIP, PollID, ChoiceID, UserID )
74 VALUES
75 ( '$nextID',
76 '$this->IP',
77 '$this->PollID',
78 '$this->ChoiceID',
79 '$this->UserID' ) ");
80
81 $this->ID = $nextID;
82
83 $db->unlock();
84
85 if ( $res == false )
86 $db->rollback( );
87 else
88 $db->commit();
89
90 return true;
91 }
92
96 function get( $id=-1 )
97 {
98 $db =& eZDB::globalDatabase();
99
100 if ( $id != -1 )
101 {
102 $db->array_query( $vote_array, "SELECT * FROM eZPoll_Vote" );
103
104 if ( count( $vote_array ) > 1 )
105 {
106 die( "Error: Vote's with the same ID was found in the database." );
107 }
108 else if( count( $vote_array ) == 1 )
109 {
110 $this->ID = $vote_array[0][$db->fieldName("ID")];
111 $this->IP = $vote_array[0][$db->fieldName("VotingIP")];
112 $this->PollID = $vote_array[0][$db->fieldName("PollID")];
113 $this->ChoiceID = $vote_array[0][$db->fieldName("ChoiceID")];
114 $this->UserID = $vote_array[0][$db->fieldName("UserID")];
115 }
116
117 }
118 }
119
123 function getAll( $id )
124 {
125 $db =& eZDB::globalDatabase();
126
127 $return_array = array();
128 $vote_array = array();
129
130 $this->Database->array_query( $vote_array, "SELECT ID FROM eZPoll_Vote WHERE PollID='$id'" );
131
132 for ( $i=0; $i<count( $vote_array ); $i++ )
133 {
134 $return_array[$i] = new eZVote( $vote_array[$i][$db->fieldName("ID")], 0 );
135 }
136 }
137
141 function pollID()
142 {
143 return $this->PollID;
144 }
145
149 function choiceID()
150 {
151 return $this->choiceID;
152 }
153
154
158 function votingIP()
159 {
160 return $this->IP;
161 }
162
166 function id()
167 {
168 return $this->ID;
169 }
170
174 function userID()
175 {
176 return $this->userID;
177 }
178
179
183 function setVotingIP( $value )
184 {
185 $this->IP = $value;
186 }
187
191 function setPollID( $value )
192 {
193 $this->PollID = $value;
194 }
195
199 function setChoiceID( $value )
200 {
201 $this->ChoiceID = $value;
202 }
203
207 function setUserID( $value )
208 {
209 $this->UserID = $value;
210 }
211
216 function isVoted( $userID, $pollID )
217 {
218 $ret = true;
219
220 $vote_array = array();
221
222 $db =& eZDB::globalDatabase();
223
224 $db->array_query( $vote_array, "SELECT * FROM eZPoll_Vote
225 WHERE UserID='$userID' AND PollID='$pollID'" );
226 if ( count( $vote_array ) == 0 )
227 {
228 $ret = false;
229 }
230
231 return $ret;
232 }
233
238 function ipHasVoted( $IP, $pollID )
239 {
240 $ret = true;
241
242 $vote_array = array();
243
244 $db =& eZDB::globalDatabase();
245
246 $db->array_query( $vote_array, "SELECT * FROM eZPoll_Vote
247 WHERE VotingIP='$IP' AND PollID='$pollID'" );
248 if ( count( $vote_array ) == 0 )
249 {
250 $ret = false;
251 }
252
253 return $ret;
254 }
255
256 var $ID;
257 var $IP;
258 var $PollID;
259 var $ChoiceIP;
260 var $UserID;
261 }
262
263 ?>
$i
$i
Definition: admin/adlist.php:91
$userID
else $userID
Definition: appointmentedit.php:121
eZDB\globalDatabase
static & globalDatabase()
Definition: ezdb.php:134
eZVote
Definition: ezvote.php:46
eZVote\choiceID
choiceID()
Definition: ezvote.php:149
eZVote\setPollID
setPollID( $value)
Definition: ezvote.php:191
eZVote\__construct
__construct( $id=-1)
Definition: ezvote.php:51
eZVote\isVoted
isVoted( $userID, $pollID)
Definition: ezvote.php:216
eZVote\$PollID
$PollID
Definition: ezvote.php:258
eZVote\pollID
pollID()
Definition: ezvote.php:141
eZVote\setChoiceID
setChoiceID( $value)
Definition: ezvote.php:199
eZVote\$ID
$ID
Definition: ezvote.php:256
eZVote\setVotingIP
setVotingIP( $value)
Definition: ezvote.php:183
eZVote\$ChoiceIP
$ChoiceIP
Definition: ezvote.php:259
eZVote\store
store()
Definition: ezvote.php:63
eZVote\$UserID
$UserID
Definition: ezvote.php:260
eZVote\userID
userID()
Definition: ezvote.php:174
eZVote\setUserID
setUserID( $value)
Definition: ezvote.php:207
eZVote\getAll
getAll( $id)
Definition: ezvote.php:123
eZVote\id
id()
Definition: ezvote.php:166
eZVote\$IP
$IP
Definition: ezvote.php:257
eZVote\ipHasVoted
ipHasVoted( $IP, $pollID)
Definition: ezvote.php:238
eZVote\votingIP
votingIP()
Definition: ezvote.php:158
$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
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.