Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezquizquestion.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: ezquizquestion.php 8687 2001-12-06 10:19:29Z jhe $
5 //
6 // eZQuizQuestion 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/ezquizalternative.php" );
41 // include_once( "ezquiz/classes/ezquizgame.php" );
42
43 class eZQuizQuestion
44 {
45
52 function __construct( $id = -1, $fetch = true )
53 {
54 $this->Score = 0;
55 if ( is_array( $id ) )
56 {
57 $this->fill( $id );
58 }
59 else if ( $id != -1 )
60 {
61 $this->ID = $id;
62 if ( $fetch == true )
63 {
64 $this->get( $this->ID );
65 }
66 }
67 }
68
72 function store()
73 {
74 $db =& eZDB::globalDatabase();
75 $db->begin();
76
77 $name =& $db->escapeString( $this->Name );
78 $gameID = $this->Game->id();
79
80 $db->query_single( $result, "SELECT MAX(Placement)+1 FROM eZQuiz_Question WHERE GameID='$gameID' " );
81
82 $place = $result[0];
83 if ( $result[0] == NULL )
84 {
85 $place = 1;
86 }
87
88 if ( !isset( $this->ID ) )
89 {
90 $db->lock( "eZQuiz_Question" );
91 $this->ID = $db->nextID( "eZQuiz_Question", "ID" );
92 $queryText = "INSERT INTO eZQuiz_Question
93 (ID, Name, Score, GameID, Placement)
94 VALUES
95 ('$this->ID','$name','$this->Score','$gameID','$place')";
96 // var_dump( $queryText );
97 $res[] = $db->query( $queryText );
98 $db->unlock();
99
100 }
101 elseif ( is_numeric( $this->ID ) )
102 {
103 $res[] = $db->query( "UPDATE eZQuiz_Question SET
104 Name='$name',
105 Score='$this->Score',
106 GameID='$gameID'
107 WHERE ID='$this->ID'" );
108 }
109 eZDB::finish( $res, $db );
110 return true;
111 }
112
116 function delete( $catID = -1 )
117 {
118 if ( $catID == -1 )
119 $catID = $this->ID;
120
121 $db =& eZDB::globalDatabase();
122 $db->begin();
123
124 $alternatives =& $this->alternatives();
125 if ( is_array( $alternatives ) )
126 {
127 foreach ( $alternatives as $alternative )
128 {
129 $alternative->delete();
130 }
131 }
132
133 $res[] = $db->query( "DELETE FROM eZQuiz_Question WHERE ID='$this->ID'" );
134 eZDB::finish( $res, $db );
135
136 }
137
143 function get( $id = -1 )
144 {
145 $db =& eZDB::globalDatabase();
146
147 $ret = false;
148 if ( $id != "" )
149 {
150 $db->array_query( $questionArray, "SELECT * FROM eZQuiz_Question WHERE ID='$id'",
151 0, 1 );
152 if ( count( $questionArray ) == 1 )
153 {
154 $this->fill( $questionArray[0] );
155 $ret = true;
156 }
157 elseif ( count( $questionArray ) == 1 )
158 {
159 $this->ID = 0;
160 }
161 }
162 return $ret;
163 }
164
168 function fill( &$questionArray )
169 {
170 $db =& eZDB::globalDatabase();
171 $this->ID =& $questionArray[$db->fieldName( "ID" )];
172 $this->Name =& $questionArray[$db->fieldName( "Name" )];
173 $this->Description =& $questionArray[$db->fieldName( "Description" )];
174 $this->Game = new eZQuizGame( $questionArray[$db->fieldName( "GameID" )] );
175 }
176
182 function getAll( $offset = 0, $limit = 20 )
183 {
184 $db =& eZDB::globalDatabase();
185
186 $returnArray = array();
187 $questionArray = array();
188
189 $db->array_query( $questionArray, "SELECT ID FROM eZQuiz_Question
190 ORDER BY StartDate DESC",
191 array( "Offset" => $offset, "Limit" => $limit ) );
192
193 for ( $i = 0; $i < count( $questionArray ); $i++ )
194 {
195 $returnArray[$i] = new eZQuizQuestion( $questionArray[$i][$db->fieldName( "ID" )] );
196 }
197
198 return $returnArray;
199 }
200
204 function count()
205 {
206 $db =& eZDB::globalDatabase();
207 $ret = false;
208
209 $db->query_single( $result, "SELECT COUNT(ID) as Count
210 FROM eZQuiz_Question" );
211 $ret = $result[$db->fieldName( "Count" )];
212 return $ret;
213 }
214
218 function id()
219 {
220 return $this->ID;
221 }
222
226 function name()
227 {
228 return htmlspecialchars( $this->Name );
229 }
230
234 function score()
235 {
236 return $this->Score;
237 }
238
242 function game()
243 {
244 return $this->Game;
245 }
246
250 function setName( &$value )
251 {
252 $this->Name = $value;
253 }
254
258 function setScore( &$value )
259 {
260 $this->Score = $value;
261 }
262
266 function setGame( &$game )
267 {
268 if ( is_a( $game, "eZQuizGame" ) )
269 $this->Game = $game;
270 }
271
275 function isAlternative( &$alternative )
276 {
277 $ret = false;
278 $db =& eZDB::globalDatabase();
279 if ( is_a( $alternative, "eZQuizAlternative" ) )
280 {
281 $alternativeID = $alternative->id();
282 $questionID = $this->ID;
283
284 $db->query_single( $result, "SELECT ID
285 FROM eZQuiz_Alternative WHERE QuestionID='$questionID' AND ID='$alternativeID'" );
286
287 if ( is_numeric( $result[$db->fieldName( "ID" )] ) )
288 {
289 $ret = true;
290 }
291 }
292
293 return $ret;
294 }
295
300 function alternatives()
301 {
302 $returnArray = array();
303 $db =& eZDB::globalDatabase();
304 $db->array_query( $questionArray, "SELECT ID FROM eZQuiz_Alternative WHERE QuestionID='$this->ID' ORDER BY ID" );
305
306 for ( $i = 0; $i < count( $questionArray ); $i++ )
307 {
308 $returnArray[$i] = new eZQuizAlternative( $questionArray[$i][$db->fieldName( "ID" )], true );
309 }
310 return $returnArray;
311 }
312
317 function countAlternatives()
318 {
319 $returnArray = array();
320 $db =& eZDB::globalDatabase();
321 $db->query_single( $result, "SELECT count( ID ) AS COUNT FROM eZQuiz_Alternative WHERE QuestionID='$this->ID'" );
322
323 $ret = false;
324
325 if ( is_numeric( $result[$db->fieldName( "COUNT" )] ) )
326 {
327 $ret = $result[$db->fieldName( "COUNT" )];
328 }
329
330 return $ret;
331 }
332
337 function countCorrectAlternatives()
338 {
339 $returnArray = array();
340 $db =& eZDB::globalDatabase();
341 $db->query_single( $result, "SELECT count( ID ) AS COUNT FROM eZQuiz_Alternative WHERE QuestionID='$this->ID' AND IsCorrect=1" );
342
343 $ret = false;
344
345 if ( is_numeric( $result[$db->fieldName( "COUNT" )] ) )
346 {
347 $ret = $result[$db->fieldName( "COUNT" )];
348 }
349
350 return $ret;
351 }
352
353 var $ID;
354 var $Name;
355 var $Description;
356 var $Score;
357 var $Game;
358 }
359
360 ?>
$i
$i
Definition: admin/adlist.php:91
eZDB\finish
static finish(&$resultArray, &$db)
Definition: ezdb.php:204
eZDB\globalDatabase
static & globalDatabase()
Definition: ezdb.php:134
eZQuizAlternative
Definition: ezquizalternative.php:42
eZQuizGame
Definition: ezquizgame.php:43
eZQuizQuestion
Definition: ezquizquestion.php:44
eZQuizQuestion\$ID
$ID
Definition: ezquizquestion.php:353
eZQuizQuestion\$Game
$Game
Definition: ezquizquestion.php:357
eZQuizQuestion\score
score()
Definition: ezquizquestion.php:234
eZQuizQuestion\alternatives
alternatives()
Definition: ezquizquestion.php:300
eZQuizQuestion\setName
setName(&$value)
Definition: ezquizquestion.php:250
eZQuizQuestion\count
count()
Definition: ezquizquestion.php:204
eZQuizQuestion\store
store()
Definition: ezquizquestion.php:72
eZQuizQuestion\countCorrectAlternatives
countCorrectAlternatives()
Definition: ezquizquestion.php:337
eZQuizQuestion\game
game()
Definition: ezquizquestion.php:242
eZQuizQuestion\id
id()
Definition: ezquizquestion.php:218
eZQuizQuestion\getAll
getAll( $offset=0, $limit=20)
Definition: ezquizquestion.php:182
eZQuizQuestion\$Score
$Score
Definition: ezquizquestion.php:356
eZQuizQuestion\isAlternative
isAlternative(&$alternative)
Definition: ezquizquestion.php:275
eZQuizQuestion\__construct
__construct( $id=-1, $fetch=true)
Definition: ezquizquestion.php:52
eZQuizQuestion\setGame
setGame(&$game)
Definition: ezquizquestion.php:266
eZQuizQuestion\fill
fill(&$questionArray)
Definition: ezquizquestion.php:168
eZQuizQuestion\$Description
$Description
Definition: ezquizquestion.php:355
eZQuizQuestion\name
name()
Definition: ezquizquestion.php:226
eZQuizQuestion\$Name
$Name
Definition: ezquizquestion.php:354
eZQuizQuestion\countAlternatives
countAlternatives()
Definition: ezquizquestion.php:317
eZQuizQuestion\setScore
setScore(&$value)
Definition: ezquizquestion.php:258
$result
$result
Definition: companysearch.php:94
$name
$name
Definition: companytypelist.php:194
$id
$id
Definition: companytypelist.php:193
$db
$db
Definition: ezarticle/user/authorlist.php:53
$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
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+.