Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezpoll.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: ezpoll.php 8744 2001-12-12 15:26:03Z br $
5 //
6 // Definition of eZPoll 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
60 // include_once( "classes/ezdb.php" );
61 // include_once( "ezforum/classes/ezforum.php" );
62
63 class eZPoll
64 {
69 function __construct( $id=-1 )
70 {
71 if ( $id != -1 )
72 {
73 $this->ID = $id;
74 $this->get( $this->ID );
75 }
76 }
77
81 function store()
82 {
83 $db =& eZDB::globalDatabase();
84
85 $dbError = false;
86 $db->begin( );
87
88 $name = $db->escapeString( $this->Name );
89 $description = $db->escapeString( $this->Description );
90
91 if ( !isset( $this->ID ) )
92 {
93 $db->lock( "eZPoll_Poll" );
94
95 $nextID = $db->nextID( "eZPoll_Poll", "ID" );
96
97 $res = $db->query( "INSERT INTO eZPoll_Poll
98 ( ID, Name, Description, IsEnabled, ShowResult, Anonymous, IsClosed )
99 VALUES
100 ( '$nextID',
101 '$name',
102 '$description',
103 '$this->IsEnabled',
104 '$this->ShowResult',
105 '$this->Anonymous',
106 '$this->IsClosed' ) ");
107
108 $this->ID = $nextID;
109 }
110 else
111 {
112 $res = $db->query( "UPDATE eZPoll_Poll SET
113 Name='$name',
114 Description='$description',
115 IsEnabled='$this->IsEnabled',
116 ShowResult='$this->ShowResult',
117 Anonymous='$this->Anonymous',
118 IsClosed='$this->IsClosed' WHERE ID='$this->ID'" );
119
120 }
121
122 $db->unlock();
123
124 if ( $res == false )
125 $db->rollback( );
126 else
127 $db->commit();
128
129 return true;
130 }
131
135 function delete()
136 {
137 $db =& eZDB::globalDatabase();
138
139 if ( isset( $this->ID ) )
140 {
141 $db->query( "DELETE FROM eZPoll_Vote WHERE PollID='$this->ID'" );
142 $db->query( "DELETE FROM eZPoll_PollChoice WHERE PollID='$this->ID'" );
143 $db->query( "DELETE FROM eZPoll_Poll WHERE ID='$this->ID'" );
144 $db->query( "DELETE FROM eZPoll_PollForumLink WHERE PollID='$this->ID'" );
145 }
146 return true;
147 }
148
152 function get( $id=-1 )
153 {
154 $ret = false;
155 $db =& eZDB::globalDatabase();
156
157 if ( $id != -1 )
158 {
159 $db->array_query( $poll_array, "SELECT * FROM eZPoll_Poll WHERE ID='$id'" );
160
161 if ( count( $poll_array ) > 1 )
162 {
163 die( "Error: Poll's with the same ID was found in the database." );
164 }
165
166 else if ( count( $poll_array ) == 1 )
167 {
168 $ret = true;
169 $this->ID = $poll_array[0][$db->fieldName("ID")];
170 $this->Name = $poll_array[0][$db->fieldName("Name")];
171 $this->Description = $poll_array[0][$db->fieldName("Description")];
172 $this->Anonymous = $poll_array[0][$db->fieldName("Anonymous")];
173 $this->IsEnabled = $poll_array[0][$db->fieldName("IsEnabled")];
174 $this->IsClosed = $poll_array[0][$db->fieldName("IsClosed")];
175 $this->ShowResult = $poll_array[0][$db->fieldName("ShowResult")];
176 }
177 }
178 return $ret;
179 }
180
184 function getAll()
185 {
186 $db =& eZDB::globalDatabase();
187
188 $return_array = array();
189 $poll_array = array();
190
191 $db->array_query( $poll_array, "SELECT ID, Name FROM eZPoll_Poll ORDER BY Name" );
192
193 for ( $i=0; $i<count( $poll_array ); $i++ )
194 {
195 $return_array[$i] = new eZPoll( $poll_array[$i][$db->fieldName("ID")], 0 );
196 }
197
198 return $return_array;
199 }
200
204 function getAllActive()
205 {
206 $db =& eZDB::globalDatabase();
207
208 $return_array = array();
209 $poll_array = array();
210
211 $db->array_query( $poll_array, "SELECT ID,Name FROM eZPoll_Poll WHERE IsEnabled='1' ORDER BY Name" );
212
213 for ( $i=0; $i<count( $poll_array ); $i++ )
214 {
215 $return_array[$i] = new eZPoll( $poll_array[$i][$db->fieldName("ID")], 0 );
216 }
217
218 return $return_array;
219 }
220
221
225 function id()
226 {
227 return $this->ID;
228 }
229
230
234 function name( $html = true )
235 {
236 if( $html )
237 return htmlspecialchars( $this->Name );
238 else
239 return $this->Name;
240 }
241
245 function description( $html = true )
246 {
247 if( $html )
248 return htmlspecialchars( $this->Description );
249 else
250 return $this->Description;
251 }
252
256 function isEnabled()
257 {
258 if ( $this->IsEnabled == 1 )
259 return true;
260 else
261 return false;
262 }
263
267 function isClosed()
268 {
269 if ( $this->IsClosed == 1 )
270 return true;
271 else
272 return false;
273 }
274
278 function showResult()
279 {
280 if ( $this->ShowResult == 1 )
281 return true;
282 else
283 return false;
284 }
285
289 function anonymous()
290 {
291 if ( $this->Anonymous == 1 )
292 return true;
293 else
294 return false;
295 }
296
297
303 function mainPoll( )
304 {
305 $db =& eZDB::globalDatabase();
306
307 // sets the current poll as main poll
308 $db->array_query( $poll_array, "SELECT PollID FROM eZPoll_MainPoll" );
309
310 $ret = false;
311 if ( count( $poll_array ) == 1 )
312 {
313 $ret = new eZPoll( $poll_array[0][$db->fieldName("PollID")] );
314 }
315 return $ret;
316 }
317
321 function setName( $value )
322 {
323 $this->Name = $value;
324 }
325
329 function setDescription( $value )
330 {
331 $this->Description = $value;
332 }
333
337 function setIsEnabled( $value )
338 {
339 if ( $value )
340 $this->IsEnabled = 1;
341 else
342 $this->IsEnabled = 0;
343 }
344
348 function setIsClosed( $value )
349 {
350 if ( $value )
351 $this->IsClosed = 1;
352 else
353 $this->IsClosed = 0;
354 }
355
359 function setShowResult( $value )
360 {
361 if ( $value )
362 $this->ShowResult = 1;
363 else
364 $this->ShowResult = 0;
365 }
366
370 function setAnonymous( $value )
371 {
372 if ( $value )
373 $this->Anonymous = 1;
374 else
375 $this->Anonymous = 0;
376 }
377
381 function totalVotes( )
382 {
383 $db =& eZDB::globalDatabase();
384
385 $db->array_query( $votecount, "SELECT COUNT(*) AS NUMBER FROM eZPoll_Vote WHERE PollID='$this->ID'" );
386
387 return (int)$votecount[0][$db->fieldName("NUMBER")];
388 }
389
393 function setMainPoll( $poll )
394 {
395 if ( is_a( $poll, "eZPoll" ) )
396 {
397 $db =& eZDB::globalDatabase();
398
399 // delete old main poll
400 $db->query( "DELETE FROM eZPoll_MainPoll" );
401
402 // sets the current poll as main poll
403 $db->query( "INSERT INTO eZPoll_MainPoll ( ID, PollID ) VALUES ( '1', '$this->ID' )" );
404 }
405 }
406
407
411 function &forum()
412 {
413 $db =& eZDB::globalDatabase();
414
415 $db->array_query( $res, "SELECT ForumID FROM
416 eZPoll_PollForumLink
417 WHERE PollID='$this->ID'" );
418
419 $forum = false;
420 if ( count( $res ) == 1 )
421 {
422 $forum = new eZForum( $res[0][$db->fieldName("ForumID")] );
423 }
424 else
425 {
426 $forum = new eZForum();
427 $forum->setName( $db->escapeString( $this->Name ) );
428 $forum->store();
429
430 $forumID = $forum->id();
431
432 $db->begin( );
433
434 $db->lock( "eZPoll_PollForumLink" );
435
436 $nextID = $db->nextID( "eZPoll_PollForumLink", "ID" );
437
438 $res = $db->query( "INSERT INTO eZPoll_PollForumLink
439 ( ID, PollID, ForumID )
440 VALUES
441 ( '$nextID', '$this->ID', '$forumID' )" );
442
443 $db->unlock();
444
445 if ( $res == false )
446 $db->rollback( );
447 else
448 $db->commit();
449
450
451 $forum = new eZForum( $forumID );
452 }
453
454 return $forum;
455 }
456
457 var $ID;
458 var $Name;
459 var $Description;
460 var $IsEnabled;
461 var $IsClosed;
462 var $ShowResult;
463 var $Anonymous;
464
465 }
466
467 ?>
$i
$i
Definition: admin/adlist.php:91
$forum
$forum
Definition: admin/forumlist.php:50
$poll
$poll
Definition: admin/pollist.php:114
eZDB\globalDatabase
static & globalDatabase()
Definition: ezdb.php:134
eZForum
Definition: ezforum.php:44
eZPoll
Definition: ezpoll.php:64
eZPoll\$IsClosed
$IsClosed
Definition: ezpoll.php:461
eZPoll\$IsEnabled
$IsEnabled
Definition: ezpoll.php:460
eZPoll\$ShowResult
$ShowResult
Definition: ezpoll.php:462
eZPoll\forum
& forum()
Definition: ezpoll.php:411
eZPoll\totalVotes
totalVotes()
Definition: ezpoll.php:381
eZPoll\__construct
__construct( $id=-1)
Definition: ezpoll.php:69
eZPoll\id
id()
Definition: ezpoll.php:225
eZPoll\showResult
showResult()
Definition: ezpoll.php:278
eZPoll\isClosed
isClosed()
Definition: ezpoll.php:267
eZPoll\setName
setName( $value)
Definition: ezpoll.php:321
eZPoll\store
store()
Definition: ezpoll.php:81
eZPoll\name
name( $html=true)
Definition: ezpoll.php:234
eZPoll\getAllActive
getAllActive()
Definition: ezpoll.php:204
eZPoll\mainPoll
mainPoll()
Definition: ezpoll.php:303
eZPoll\setDescription
setDescription( $value)
Definition: ezpoll.php:329
eZPoll\$Description
$Description
Definition: ezpoll.php:459
eZPoll\isEnabled
isEnabled()
Definition: ezpoll.php:256
eZPoll\anonymous
anonymous()
Definition: ezpoll.php:289
eZPoll\description
description( $html=true)
Definition: ezpoll.php:245
eZPoll\setIsEnabled
setIsEnabled( $value)
Definition: ezpoll.php:337
eZPoll\setIsClosed
setIsClosed( $value)
Definition: ezpoll.php:348
eZPoll\setShowResult
setShowResult( $value)
Definition: ezpoll.php:359
eZPoll\getAll
getAll()
Definition: ezpoll.php:184
eZPoll\$Name
$Name
Definition: ezpoll.php:458
eZPoll\setAnonymous
setAnonymous( $value)
Definition: ezpoll.php:370
eZPoll\$ID
$ID
Definition: ezpoll.php:457
eZPoll\$Anonymous
$Anonymous
Definition: ezpoll.php:463
eZPoll\setMainPoll
setMainPoll( $poll)
Definition: ezpoll.php:393
$name
$name
Definition: companytypelist.php:194
$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
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
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.