Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezquizscore.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: ezquizscore.php 8687 2001-12-06 10:19:29Z jhe $
5 //
6 // eZQuizScore class
7 //
8 // Created on: <29-May-2001 14:01:35 pkej>
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( "ezuser/classes/ezuser.php" );
40 // include_once( "ezquiz/classes/ezquizgame.php" );
41
42 class eZQuizScore
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 $userID = $this->User->id();
76 $gameID = $this->Game->id();
77
78 if ( !isset( $this->ID ) || $this->ID == 0 )
79 {
80 $db->lock( "eZQuiz_Score" );
81 $this->ID = $db->nextID( "eZQuiz_Score", "ID" );
82
83 $res[] = $db->query( "INSERT INTO eZQuiz_Score
84 (ID, GameID, UserID, TotalScore, LastQuestion, FinishedGame)
85 VALUES
86 ('$this->ID','$gameID','$userID','$this->TotalScore','$this->LastQuestion','$this->FinishedGame')" );
87 $db->unlock();
88 }
89 else if ( is_numeric( $this->ID ) )
90 {
91 $res[] = $db->query( "UPDATE eZQuiz_Score SET
92 UserID='$userID',
93 GameID='$gameID',
94 TotalScore='$this->TotalScore',
95 LastQuestion='$this->LastQuestion',
96 FinishedGame='$this->FinishedGame'
97 WHERE ID='$this->ID'" );
98 }
99 eZDB::finish( $res, $db );
100 return true;
101 }
102
106 function delete( $catID = -1 )
107 {
108 if ( $catID == -1 )
109 $catID = $this->ID;
110
111 $db =& eZDB::globalDatabase();
112 $db->begin();
113
114 $res[] = $db->query( "DELETE FROM eZQuiz_Score WHERE ID='$catID'" );
115 eZDB::finish( $res, $db );
116 }
117
123 function get( $id = -1 )
124 {
125 $db =& eZDB::globalDatabase();
126
127 $ret = false;
128 if ( $id != "" )
129 {
130 $db->array_query( $scoreArray, "SELECT * FROM eZQuiz_Score WHERE ID='$id'",
131 array( "Offset" => 0, "Limit" => 1 ) );
132
133 if ( count( $scoreArray ) == 1 )
134 {
135 $this->fill( &$scoreArray[0] );
136 $ret = true;
137 }
138 elseif ( count( $scoreArray ) == 0 )
139 {
140 $this->ID = 0;
141 }
142 }
143 return $ret;
144 }
145
153 function getUserGame( $user, $game )
154 {
155 if ( is_a( $user, "eZUser" ) )
156 $userID = $user->id();
157
158 if ( is_a( $game, "eZQuizGame" ) )
159 $gameID = $game->id();
160
161 $db =& eZDB::globalDatabase();
162
163 $ret = false;
164 if ( $gameID != "" && $userID != "" )
165 {
166 $db->array_query( $scoreArray, "SELECT * FROM eZQuiz_Score WHERE GameID='$gameID' AND UserID='$userID'",
167 array( "Offset" => 0, "Limit" => 1 ) );
168
169 if ( count( $scoreArray ) == 1 )
170 {
171 $this->fill( &$scoreArray[0] );
172 $ret = true;
173 }
174 elseif ( count( $scoreArray ) == 0 )
175 {
176 $this->ID = 0;
177 }
178 }
179
180 return $ret;
181 }
182
186 function fill( &$scoreArray )
187 {
188 $db =& eZDB::globalDatabase();
189 $this->ID =& $scoreArray[$db->fieldName( "ID" )];
190 $this->User =& new eZUser( $scoreArray[$db->fieldName( "UserID" )] );
191 $this->Game =& new eZQuizGame( $scoreArray[$db->fieldName( "GameID" )] );
192 $this->TotalScore = $scoreArray[$db->fieldName( "TotalScore" )];
193 $this->LastQuestion = $scoreArray[$db->fieldName( "LastQuestion" )];
194 $this->FinishedGame = $scoreArray[$db->fieldName( "FinishedGame" )];
195 }
196
202 function getAll( $offset = 0, $limit = 20 )
203 {
204 $db =& eZDB::globalDatabase();
205
206 $returnArray = array();
207 $scoreArray = array();
208
209 $db->array_query( $scoreArray, "SELECT ID FROM eZQuiz_Score
210 DESC LIMIT $offset, $limit" );
211
212 for ( $i = 0; $i < count( $scoreArray ); $i++ )
213 {
214 $returnArray[$i] = new eZQuizScore( $scoreArray[$i][$db->fieldName( "ID" )] );
215 }
216
217 return $returnArray;
218 }
219
223 function count()
224 {
225 $db =& eZDB::globalDatabase();
226 $ret = false;
227
228 $db->query_single( $result, "SELECT COUNT(ID) as Count FROM eZQuiz_Score" );
229 $ret = $result[$db->fieldName( "Count" )];
230 return $ret;
231 }
232
236 function id()
237 {
238 return $this->ID;
239 }
240
244 function user()
245 {
246 return $this->User;
247 }
248
252 function game()
253 {
254 return $this->Game;
255 }
256
260 function setUser( &$user )
261 {
262 if ( is_a( $user, "eZUser" ) )
263 $this->User = $user;
264 }
265
269 function setGame( &$game )
270 {
271 if ( is_a( $game, "eZQuizGame" ) )
272 $this->Game = $game;
273 }
274
278 function setTotalScore( $score )
279 {
280 $this->TotalScore = $score;
281 }
282
286 function totalScore()
287 {
288 return $this->TotalScore;
289 }
290
294 function setLastQuestion( $question )
295 {
296 $this->LastQuestion = $question;
297 }
298
302 function setNextQuestion( $question )
303 {
304 $this->LastQuestion = $question - 1;
305 }
306
307
311 function lastQuestion()
312 {
313 return $this->LastQuestion;
314 }
315
319 function nextQuestion()
320 {
321 $ret = $this->LastQuestion;
322 $ret++;
323 return $ret;
324 }
325
329 function setFinishedGame( $finished = true )
330 {
331 if ( $finished )
332 {
333 $this->FinishedGame = 1;
334 }
335 else
336 {
337 $this->FinishedGame = 0;
338 }
339 }
340
344 function isFinishedGame()
345 {
346 $ret = false;
347 if ( $this->FinishedGame )
348 {
349 $ret = true;
350 }
351
352 return $ret;
353 }
354
358 function scores( &$game )
359 {
360 $db =& eZDB::globalDatabase();
361
362 if ( is_a( $game, "eZQuizGame" ) )
363 $gameID = $game->id();
364
365
366 $returnArray = array();
367 $scoreArray = array();
368
369 $db->array_query( $scoreArray, "SELECT ID FROM eZQuiz_Score WHERE GameID='$gameID' AND FinishedGame=1 ORDER BY TotalScore DESC" );
370
371 for ( $i = 0; $i < count( $scoreArray ); $i++ )
372 {
373 $returnArray[$i] = new eZQuizScore( $scoreArray[$i][$db->fieldName( "ID" )] );
374 }
375
376 return $returnArray;
377 }
378
382 function highScore( &$game )
383 {
384 $db =& eZDB::globalDatabase();
385
386 if ( is_a( $game, "eZQuizGame" ) )
387 $gameID = $game->id();
388
389 $scoreArray = array();
390
391 $db->array_query( $scoreArray, "SELECT ID FROM eZQuiz_Score WHERE GameID='$gameID' AND FinishedGame=1 ORDER BY TotalScore DESC" );
392
393 $returnObject = new eZQuizScore( $scoreArray[0][$db->fieldName( "ID" )] );
394 return $returnObject;
395 }
396
402 function getAllByGame( &$game, $offset = 0, $limit = 20 )
403 {
404 $db =& eZDB::globalDatabase();
405
406 $returnArray = array();
407 $scoreArray = array();
408
409 if ( is_a( $game, "eZQuizGame" ) )
410 $gameID = $game->id();
411
412 $db->array_query( $scoreArray, "SELECT ID FROM eZQuiz_Score
413 WHERE GameID='$gameID' AND FinishedGame=1 ORDER BY TotalScore DESC",
414 array( "Offset" => $offset, "Limit" => $limit ) );
415
416 for ( $i = 0; $i < count( $scoreArray ); $i++ )
417 {
418 $returnArray[$i] = new eZQuizScore( $scoreArray[$i][$db->fieldName( "ID" )] );
419 }
420
421 return $returnArray;
422 }
423
424
428 function countAllByGame( &$game )
429 {
430 $db =& eZDB::globalDatabase();
431
432 $scoreArray = array();
433
434 if ( is_a( $game, "eZQuizGame" ) )
435 $gameID = $game->id();
436
437 $db->array_query( $scoreArray, "SELECT count(ID) as Count FROM eZQuiz_Score
438 WHERE GameID='$gameID' AND FinishedGame=1" );
439
440 $ret = $scoreArray[0][$db->fieldName( "Count" )];
441
442 return $ret;
443 }
444
450 function getAllByUser( &$user, $offset = 0, $limit = 20 )
451 {
452 $db =& eZDB::globalDatabase();
453
454 $returnArray = array();
455 $scoreArray = array();
456
457 if ( is_a( $user, "eZUser" ) )
458 $userID = $user->id();
459
460 $db->array_query( $scoreArray, "SELECT ID FROM eZQuiz_Score
461 WHERE UserID='$userID' AND FinishedGame=1 ORDER BY TotalScore DESC",
462 array( "Limit" => $limit, "Offset" => $offset ) );
463
464 for ( $i = 0; $i < count( $scoreArray ); $i++ )
465 {
466 $returnArray[$i] = new eZQuizScore( $scoreArray[$i][$db->fieldName( "ID" )] );
467 }
468
469 return $returnArray;
470 }
471
475 function countAllByUser( &$user )
476 {
477 $db =& eZDB::globalDatabase();
478
479 $scoreArray = array();
480
481 if ( is_a( $user, "eZUser" ) )
482 $userID = $user->id();
483
484 $db->array_query( $scoreArray, "SELECT count(ID) AS Count FROM eZQuiz_Score
485 WHERE UserID='$userID' AND FinishedGame=1" );
486
487 $ret = $scoreArray[0][$db->fieldName( "Count" )];
488
489 return $ret;
490 }
496 function getAllSavedByUser( &$user, $offset = 0, $limit = 20, $latestOnly = true )
497 {
498 $db =& eZDB::globalDatabase();
499 $now = (new eZDateTime())->timeStamp( true );
500 $returnArray = array();
501 $scoreArray = array();
502
503 if ( is_a( $user, "eZUser" ) )
504 $userID = $user->id();
505
506 if ( $latestOnly == true )
507 {
508 $db->array_query( $scoreArray, "SELECT Score.ID FROM eZQuiz_Score AS Score, eZQuiz_Game AS Game
509 WHERE Game.StartDate <= '$now' AND Game.StopDate >= '$now' AND
510 Score.UserID='$userID' AND Score.FinishedGame=0" );
511 }
512 else
513 {
514 $db->array_query( $scoreArray, "SELECT ID FROM eZQuiz_Score
515 WHERE UserID='$userID' AND FinishedGame=0 ORDER BY TotalScore
516 DESC", array( "Limit" => $limit, "Offset" => $offset ) );
517 }
518 for ( $i = 0; $i < count( $scoreArray ); $i++ )
519 {
520 $returnArray[$i] = new eZQuizScore( $scoreArray[$i][$db->fieldName( "ID" )] );
521 }
522
523 return $returnArray;
524 }
525
529 function countAllSavedByUser( &$user, $latestOnly = true )
530 {
531 $db =& eZDB::globalDatabase();
532 $now = (new eZDateTime())->timeStamp( true );
533 $scoreArray = array();
534
535 if ( is_a( $user, "eZUser" ) )
536 $userID = $user->id();
537
538 if ( $latestOnly == true )
539 {
540 $db->array_query( $scoreArray, "SELECT count(Score.ID) AS Count FROM eZQuiz_Score AS Score, eZQuiz_Game AS Game
541 WHERE Game.StartDate <= '$now' AND Game.StopDate >= '$now' AND Score.UserID='$userID' AND Score.FinishedGame=0" );
542 }
543 else
544 {
545 $db->array_query( $scoreArray, "SELECT count(ID) AS Count FROM eZQuiz_Score
546 WHERE UserID='$userID' AND FinishedGame=0" );
547 }
548 $ret = $scoreArray[0][$db->fieldName( "Count" )];
549
550 return $ret;
551 }
552
553
554 var $ID;
555 var $User;
556 var $Game;
557 var $TotalScore;
558 var $LastQuestion;
559 var $FinishedGame;
560 }
561
562 ?>
$i
$i
Definition: admin/adlist.php:91
$userID
else $userID
Definition: appointmentedit.php:121
eZDB\finish
static finish(&$resultArray, &$db)
Definition: ezdb.php:204
eZDB\globalDatabase
static & globalDatabase()
Definition: ezdb.php:134
eZDateTime
Definition: ezdatetime.php:55
eZQuizGame
Definition: ezquizgame.php:43
eZQuizScore
Definition: ezquizscore.php:43
eZQuizScore\getAllSavedByUser
getAllSavedByUser(&$user, $offset=0, $limit=20, $latestOnly=true)
Definition: ezquizscore.php:496
eZQuizScore\setNextQuestion
setNextQuestion( $question)
Definition: ezquizscore.php:302
eZQuizScore\fill
fill(&$scoreArray)
Definition: ezquizscore.php:186
eZQuizScore\highScore
highScore(&$game)
Definition: ezquizscore.php:382
eZQuizScore\countAllByGame
countAllByGame(&$game)
Definition: ezquizscore.php:428
eZQuizScore\$ID
$ID
Definition: ezquizscore.php:554
eZQuizScore\setUser
setUser(&$user)
Definition: ezquizscore.php:260
eZQuizScore\totalScore
totalScore()
Definition: ezquizscore.php:286
eZQuizScore\getAllByUser
getAllByUser(&$user, $offset=0, $limit=20)
Definition: ezquizscore.php:450
eZQuizScore\$User
$User
Definition: ezquizscore.php:555
eZQuizScore\countAllSavedByUser
countAllSavedByUser(&$user, $latestOnly=true)
Definition: ezquizscore.php:529
eZQuizScore\countAllByUser
countAllByUser(&$user)
Definition: ezquizscore.php:475
eZQuizScore\game
game()
Definition: ezquizscore.php:252
eZQuizScore\setGame
setGame(&$game)
Definition: ezquizscore.php:269
eZQuizScore\isFinishedGame
isFinishedGame()
Definition: ezquizscore.php:344
eZQuizScore\setTotalScore
setTotalScore( $score)
Definition: ezquizscore.php:278
eZQuizScore\store
store()
Definition: ezquizscore.php:70
eZQuizScore\$LastQuestion
$LastQuestion
Definition: ezquizscore.php:558
eZQuizScore\$FinishedGame
$FinishedGame
Definition: ezquizscore.php:559
eZQuizScore\setLastQuestion
setLastQuestion( $question)
Definition: ezquizscore.php:294
eZQuizScore\getAllByGame
getAllByGame(&$game, $offset=0, $limit=20)
Definition: ezquizscore.php:402
eZQuizScore\user
user()
Definition: ezquizscore.php:244
eZQuizScore\getUserGame
getUserGame( $user, $game)
Definition: ezquizscore.php:153
eZQuizScore\setFinishedGame
setFinishedGame( $finished=true)
Definition: ezquizscore.php:329
eZQuizScore\scores
scores(&$game)
Definition: ezquizscore.php:358
eZQuizScore\count
count()
Definition: ezquizscore.php:223
eZQuizScore\lastQuestion
lastQuestion()
Definition: ezquizscore.php:311
eZQuizScore\$Game
$Game
Definition: ezquizscore.php:556
eZQuizScore\getAll
getAll( $offset=0, $limit=20)
Definition: ezquizscore.php:202
eZQuizScore\id
id()
Definition: ezquizscore.php:236
eZQuizScore\__construct
__construct( $id=-1, $fetch=true)
Definition: ezquizscore.php:51
eZQuizScore\nextQuestion
nextQuestion()
Definition: ezquizscore.php:319
eZQuizScore\$TotalScore
$TotalScore
Definition: ezquizscore.php:557
eZUser
Definition: ezuser.php:76
$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
$game
$game
Definition: quizlist.php:60
$score
$score
Definition: quizlist.php:61
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+.