Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezquizgame.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: ezquizgame.php 9344 2002-03-06 08:56:33Z jhe $
5 //
6 // ezquizgame class
7 //
8 // Created on: <22-May-2001 13:45:37 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
39 // include_once( "classes/ezdate.php" );
40 // include_once( "ezquiz/classes/ezquizquestion.php" );
41
42 class eZQuizGame
43 {
44
51 function __construct( $id = -1, $fetch = true )
52 {
53 if ( is_array( $id ) )
54 {
55 $this->fill( $id );
56 }
57 else if ( $id != -1 )
58 {
59 $this->ID = $id;
60 if ( $fetch == true )
61 {
62 $this->get( $this->ID );
63 }
64 }
65 }
66
70 function store()
71 {
72 $db =& eZDB::globalDatabase();
73 $db->begin();
74 $name =& $db->escapeString( $this->Name );
75 $description =& $db->escapeString( $this->Description );
76 $startDate =& $this->StartDate->timeStamp();
77 $stopDate =& $this->StopDate->timeStamp();
78
79 if ( !isset( $this->ID ) )
80 {
81 $db->lock( "eZQuiz_Game" );
82 $this->ID = $db->nextID( "eZQuiz_Game", "ID" );
83 $res[] = $db->query( "INSERT INTO eZQuiz_Game
84 (ID, Name, Description, StartDate, StopDate)
85 VALUES
86 ('$this->ID','$name','$description','$startDate','$stopDate')" );
87 $db->unlock();
88 }
89 elseif ( is_numeric( $this->ID ) )
90 {
91 $res[] = $db->query( "UPDATE eZQuiz_Game SET
92 Name='$name',
93 Description='$description',
94 StartDate='$startDate',
95 StopDate='$stopDate'
96 WHERE ID='$this->ID'" );
97 }
98 eZDB::finish( $res, $db );
99 return true;
100 }
101
105 function delete( $catID = -1 )
106 {
107 if ( $catID == -1 )
108 $catID = $this->ID;
109
110 $db =& eZDB::globalDatabase();
111 $db->begin();
112 $questions =& $this->questions();
113 if ( is_array( $questions ) )
114 {
115 foreach ( $questions as $question )
116 {
117 $question->delete();
118 }
119 }
120
121 $res[] = $db->query( "DELETE FROM eZQuiz_Game WHERE ID='$this->ID'" );
122 eZDB::finish( $res, $db );
123 }
124
130 function get( $id=-1 )
131 {
132 $db =& eZDB::globalDatabase();
133
134 $ret = false;
135 if ( $id != "" )
136 {
137 $db->array_query( $quizArray, "SELECT * FROM eZQuiz_Game WHERE ID='$id'",
138 array( "Offset" => 0, "Limit" => 1 ) );
139
140 if ( count( $quizArray ) == 1 )
141 {
142 $this->fill( $quizArray[0] );
143 $ret = true;
144 }
145 elseif ( count( $quizArray ) == 1 )
146 {
147 $this->ID = 0;
148 }
149 }
150 return $ret;
151 }
152
156 function fill( &$quizArray )
157 {
158 $db =& eZDB::globalDatabase();
159 $this->ID =& $quizArray[$db->fieldName( "ID" )];
160 $this->Name =& $quizArray[$db->fieldName( "Name" )];
161 $this->Description =& $quizArray[$db->fieldName( "Description" )];
162 $this->StartDate = new eZDate();
163 if( isset( $quizArray[$db->fieldName( "StartDate" )] ) )
164 $this->StartDate->setTimeStamp( $quizArray[$db->fieldName( "StartDate" )] );
165 $this->StopDate = new eZDate();
166 if( isset( $quizArray[$db->fieldName( "StopDate" )] ) )
167 $this->StopDate->setTimeStamp( $quizArray[$db->fieldName( "StopDate" )] );
168 }
169
175 static public function &getAll( $offset = 0, $limit = 20 )
176 {
177 $db =& eZDB::globalDatabase();
178
179 $returnArray = array();
180 $quizArray = array();
181
182 if ( $limit == false )
183 {
184 $db->array_query( $quizArray, "SELECT ID
185 FROM eZQuiz_Game
186 ORDER BY StartDate DESC" );
187
188 }
189 else
190 {
191 $db->array_query( $quizArray, "SELECT ID
192 FROM eZQuiz_Game
193 ORDER BY StartDate DESC",
194 array( "Offset" => $offset, "Limit" => $limit ) );
195 }
196
197 for ( $i = 0; $i < count( $quizArray ); $i++ )
198 {
199 $returnArray[$i] = new eZQuizGame( $quizArray[$i][$db->fieldName( "ID" )] );
200 }
201
202 return $returnArray;
203 }
204
208 static public function count()
209 {
210 $db =& eZDB::globalDatabase();
211 $ret = false;
212
213 $db->query_single( $result, "SELECT COUNT(ID) as Count FROM eZQuiz_Game" );
214 $ret = $result[$db->fieldName( "Count" )];
215 return $ret;
216 }
217
221 function id()
222 {
223 return $this->ID;
224 }
225
229 function &name()
230 {
231 if( !is_null( $this->Name ) )
232 return htmlspecialchars( $this->Name );
233 else
234 return $this->Name;
235 }
236
240 function &description()
241 {
242 return htmlspecialchars( $this->Description );
243 }
244
248 function &startDate()
249 {
250 return $this->StartDate;
251 }
252
256 function &stopDate()
257 {
258 return $this->StopDate;
259 }
260
264 function setName( &$value )
265 {
266 $this->Name = $value;
267 }
268
272 function setDescription( &$value )
273 {
274 $this->Description = $value;
275 }
276
280 function setStartDate( &$date )
281 {
282 if ( is_a( $date, "eZDate" ) )
283 $this->StartDate = $date;
284 }
285
289 function setStopDate( &$date )
290 {
291 if ( is_a( $date, "eZDate" ) )
292 $this->StopDate = $date;
293 }
294
298 function isClosed()
299 {
300 $db =& eZDB::globalDatabase();
301 $now = (new eZDateTime())->timeStamp( true );
302
303 $ret = false;
304 $quizArray = array();
305
306 $db->array_query( $quizArray, "SELECT ID FROM eZQuiz_Game
307 WHERE StopDate < '$now' AND ID = '$this->ID'" );
308
309 $ret = $quizArray[0][$db->fieldName( "ID" )];
310
311 if ( $ret == $this->ID )
312 {
313 $ret = true;
314 }
315 return $ret;
316 }
317
321 function isFutureGame()
322 {
323 $db =& eZDB::globalDatabase();
324 $now = (new eZDateTime())->timeStamp( true );
325
326 $ret = false;
327 $quizArray = array();
328
329 $db->array_query( $quizArray, "SELECT ID FROM eZQuiz_Game
330 WHERE StartDate > '$now' AND ID = '$this->ID'" );
331
332 $ret = $quizArray[0][$db->fieldName( "ID" )];
333
334 if ( $ret == $this->ID )
335 {
336 $ret = true;
337 }
338 return $ret;
339 }
340
345 function &questions()
346 {
347 $returnArray = array();
348 $db =& eZDB::globalDatabase();
349 $db->array_query( $questionArray, "SELECT ID FROM eZQuiz_Question WHERE GameID='$this->ID'" );
350
351 for ( $i = 0; $i < count( $questionArray ); $i++ )
352 {
353 $returnArray[$i] = new eZQuizQuestion( $questionArray[$i][$db->fieldName( "ID" )], true );
354 }
355 return $returnArray;
356 }
357
362 function &question( $placement )
363 {
364 $db =& eZDB::globalDatabase();
365 $db->query_single( $question, "SELECT ID FROM eZQuiz_Question WHERE GameID='$this->ID' AND Placement='$placement'" );
366
367 $return = new eZQuizQuestion( $question[$db->fieldName( "ID" )], true );
368
369 return $return;
370 }
371
372
373
377 function &numberOfQuestions()
378 {
379 $db =& eZDB::globalDatabase();
380 $ret = false;
381
382 $db->query_single( $result, "SELECT COUNT(ID) as Count
383 FROM eZQuiz_Question WHERE GameID='$this->ID'" );
384 $ret = $result[$db->fieldName( "Count" )];
385
386 return $ret;
387 }
388
392 function &numberOfPlayers()
393 {
394 $db =& eZDB::globalDatabase();
395 $ret = false;
396
397 $db->query_single( $result, "SELECT COUNT(ID) as Count
398 FROM eZQuiz_Score WHERE GameID='$this->ID' AND FinishedGame=1" );
399 $ret = $result[$db->fieldName( "Count" )];
400 return $ret;
401 }
402
406 function &openGames( $offset = 0, $limit = 20 )
407 {
408 $db =& eZDB::globalDatabase();
409 $now = (new eZDateTime())->timeStamp( true );
410 $returnArray = array();
411 $quizArray = array();
412
413 $db->array_query( $quizArray, "SELECT ID FROM eZQuiz_Game
414 WHERE StartDate <= '$now' AND StopDate >= '$now'
415 ORDER BY StartDate DESC",
416 array( "Offset" => $offset, "Limit" => $limit ) );
417
418 for ( $i = 0; $i < count( $quizArray ); $i++ )
419 {
420 $returnArray[$i] = new eZQuizGame( $quizArray[$i][$db->fieldName( "ID" )] );
421 }
422
423 return $returnArray;
424 }
425
429 function &numberOfOpenGames()
430 {
431 $db =& eZDB::globalDatabase();
432 $now = (new eZDateTime())->timeStamp( true );
433 $quizArray = array();
434
435 $db->array_query( $quizArray, "SELECT count(ID) as Count FROM eZQuiz_Game
436 WHERE StartDate <= '$now' AND StopDate >= '$now'" );
437
438 $ret = $quizArray[0][$db->fieldName( "Count" )];
439
440 return $ret;
441 }
442
446 function &opensNext( $offset = 0, $limit = 20 )
447 {
448 $db =& eZDB::globalDatabase();
449 $now = (new eZDateTime())->timeStamp( true );
450
451 $returnArray = array();
452 $quizArray = array();
453
454 $db->array_query( $quizArray, "SELECT ID FROM eZQuiz_Game
455 WHERE StartDate > '$now'
456 ORDER BY StartDate DESC",
457 array( "Offset" => $offset, "Limit" => $limit ) );
458 for ( $i = 0; $i < count( $quizArray ); $i++ )
459 {
460 $returnArray[$i] = new eZQuizGame( $quizArray[$i][$db->fieldName( "ID" )] );
461 }
462
463 return $returnArray;
464 }
465
469 function &closedGames( $offset = 0, $limit = 20 )
470 {
471 $db =& eZDB::globalDatabase();
472 $now = (new eZDateTime())->timeStamp( true );
473 $returnArray = array();
474 $quizArray = array();
475
476 $db->array_query( $quizArray, "SELECT ID FROM eZQuiz_Game
477 WHERE StopDate < '$now'
478 ORDER BY StartDate DESC",
479 array( "Offset" => $offset, "Limit" => $limit ) );
480
481 for ( $i = 0; $i < count( $quizArray ); $i++ )
482 {
483 $returnArray[$i] = new eZQuizGame( $quizArray[$i][$db->fieldName( "ID" )] );
484 }
485
486 return $returnArray;
487 }
488
492 function &numberOfClosedGames()
493 {
494 $db =& eZDB::globalDatabase();
495 $now = (new eZDateTime())->timeStamp( true );
496 $quizArray = array();
497
498 $db->array_query( $quizArray, "SELECT count(ID) as Count FROM eZQuiz_Game
499 WHERE StopDate < '$now'" );
500 $ret = $quizArray[0][$db->fieldName( "Count" )];
501
502 return $ret;
503 }
504
508 static public function &startedInPeriod( &$inStartDate, &$inStopDate )
509 {
510 $db =& eZDB::globalDatabase();
511
512 $result = array();
513 $returnArray = array();
514 $quizArray = array();
515
516 $stopDate = $inStopDate->timeStamp();
517 $startDate = $inStartDate->timeStamp();
518
519 $db->array_query( $quizArray, "SELECT ID FROM eZQuiz_Game
520 WHERE StartDate >= '$startDate' AND StartDate <= '$stopDate'
521 ORDER BY StartDate" );
522 //$ret = $result[$db->fieldName( "Count" )];
523
524 for ( $i = 0; $i < count( $quizArray ); $i++ )
525 {
526 $returnArray[$i] = new eZQuizGame( $quizArray[$i] );
527 }
528
529 return $returnArray;
530 }
531
535 static public function &endedInPeriod( &$inStartDate, &$inStopDate )
536 {
537 $db =& eZDB::globalDatabase();
538 $result = array();
539 $returnArray = array();
540 $quizArray = array();
541
542 $startDate = $inStartDate->timeStamp();
543 $stopDate = $inStopDate->timeStamp();
544
545 $db->array_query( $quizArray, "SELECT * FROM eZQuiz_Game
546 WHERE StopDate >= '$startDate' AND StopDate <= '$stopDate'
547 ORDER BY StartDate" );
548 //$ret = $result[$db->fieldName( "Count" )];
549
550 for ( $i = 0; $i < count( $quizArray ); $i++ )
551 {
552 $returnArray[$i] = new eZQuizGame( $quizArray[$i] );
553 }
554
555 return $returnArray;
556 }
557
561 static public function &embracingPeriod( &$inStartDate, &$inStopDate )
562 {
563 $db =& eZDB::globalDatabase();
564
565 $result = array();
566 $returnArray = array();
567 $quizArray = array();
568
569 $startDate = $inStartDate->timeStamp();
570 $stopDate = $inStopDate->timeStamp();
571
572 $db->array_query( $quizArray, "SELECT ID FROM eZQuiz_Game
573 WHERE StartDate <= '$startDate' AND StopDate >= '$stopDate'
574 ORDER BY StartDate" );
575 //$ret = $result[$db->fieldName( "Count" )];
576
577 for ( $i = 0; $i < count( $quizArray ); $i++ )
578 {
579 $returnArray[$i] = new eZQuizGame( $quizArray[$i] );
580 }
581
582 return $returnArray;
583 }
584
585
586
587
588 var $ID;
589 var $Name;
590 var $Description;
591 var $StartDate;
592 var $StopDate;
593 }
594
595 ?>
$i
$i
Definition: admin/adlist.php:91
$date
$date
Definition: bugpreview.php:66
eZDB\finish
static finish(&$resultArray, &$db)
Definition: ezdb.php:204
eZDB\globalDatabase
static & globalDatabase()
Definition: ezdb.php:134
eZDateTime
Definition: ezdatetime.php:55
eZDate
Definition: ezdate.php:46
eZQuizGame
Definition: ezquizgame.php:43
eZQuizGame\embracingPeriod
static & embracingPeriod(&$inStartDate, &$inStopDate)
Definition: ezquizgame.php:561
eZQuizGame\$StartDate
$StartDate
Definition: ezquizgame.php:591
eZQuizGame\closedGames
& closedGames( $offset=0, $limit=20)
Definition: ezquizgame.php:469
eZQuizGame\startedInPeriod
static & startedInPeriod(&$inStartDate, &$inStopDate)
Definition: ezquizgame.php:508
eZQuizGame\question
& question( $placement)
Definition: ezquizgame.php:362
eZQuizGame\store
store()
Definition: ezquizgame.php:70
eZQuizGame\questions
& questions()
Definition: ezquizgame.php:345
eZQuizGame\getAll
static & getAll( $offset=0, $limit=20)
Definition: ezquizgame.php:175
eZQuizGame\id
id()
Definition: ezquizgame.php:221
eZQuizGame\stopDate
& stopDate()
Definition: ezquizgame.php:256
eZQuizGame\$StopDate
$StopDate
Definition: ezquizgame.php:592
eZQuizGame\endedInPeriod
static & endedInPeriod(&$inStartDate, &$inStopDate)
Definition: ezquizgame.php:535
eZQuizGame\startDate
& startDate()
Definition: ezquizgame.php:248
eZQuizGame\$Description
$Description
Definition: ezquizgame.php:590
eZQuizGame\numberOfClosedGames
& numberOfClosedGames()
Definition: ezquizgame.php:492
eZQuizGame\isFutureGame
isFutureGame()
Definition: ezquizgame.php:321
eZQuizGame\fill
fill(&$quizArray)
Definition: ezquizgame.php:156
eZQuizGame\$Name
$Name
Definition: ezquizgame.php:589
eZQuizGame\openGames
& openGames( $offset=0, $limit=20)
Definition: ezquizgame.php:406
eZQuizGame\numberOfPlayers
& numberOfPlayers()
Definition: ezquizgame.php:392
eZQuizGame\setDescription
setDescription(&$value)
Definition: ezquizgame.php:272
eZQuizGame\numberOfQuestions
& numberOfQuestions()
Definition: ezquizgame.php:377
eZQuizGame\name
& name()
Definition: ezquizgame.php:229
eZQuizGame\__construct
__construct( $id=-1, $fetch=true)
Definition: ezquizgame.php:51
eZQuizGame\numberOfOpenGames
& numberOfOpenGames()
Definition: ezquizgame.php:429
eZQuizGame\setStopDate
setStopDate(&$date)
Definition: ezquizgame.php:289
eZQuizGame\$ID
$ID
Definition: ezquizgame.php:588
eZQuizGame\setStartDate
setStartDate(&$date)
Definition: ezquizgame.php:280
eZQuizGame\setName
setName(&$value)
Definition: ezquizgame.php:264
eZQuizGame\isClosed
isClosed()
Definition: ezquizgame.php:298
eZQuizGame\opensNext
& opensNext( $offset=0, $limit=20)
Definition: ezquizgame.php:446
eZQuizGame\count
static count()
Definition: ezquizgame.php:208
eZQuizGame\description
& description()
Definition: ezquizgame.php:240
eZQuizQuestion
Definition: ezquizquestion.php:44
$result
$result
Definition: companysearch.php:94
$name
$name
Definition: companytypelist.php:194
$id
$id
Definition: companytypelist.php:193
$question
$question
Definition: default.php:43
$db
$db
Definition: ezarticle/user/authorlist.php:53
$now
$now
Definition: ezcalendar/user/dayview.php:401
$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
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+.