Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezquizalternative.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: ezquizalternative.php 8687 2001-12-06 10:19:29Z jhe $
5 //
6 // eZQuizAlternative class
7 //
8 // Created on: <22-May-2001 16:22:08 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
41 class eZQuizAlternative
42 {
43
50 function __construct( $id = -1 )
51 {
52 if ( is_array( $id ) )
53 {
54 $this->fill( $id );
55 }
56 else if ( $id != -1 )
57 {
58 $this->ID = $id;
59 $this->get( $this->ID );
60 }
61 else
62 {
63 $this->Name = "";
64 $this->IsCorrect = 0;
65 }
66 }
67
71 function store()
72 {
73 $db =& eZDB::globalDatabase();
74 $db->begin();
75
76 $name =& $db->escapeString( $this->Name );
77 $questionID = $this->Question->id();
78
79
80 if ( !isset( $this->ID ) )
81 {
82 $db->lock( "eZQuiz_Alternative" );
83 $this->ID = $db->nextID( "eZQuiz_Alternative", "ID" );
84 $res[] = $db->query( "INSERT INTO eZQuiz_Alternative
85 (ID, Name, QuestionID, IsCorrect)
86 VALUES
87 ('$this->ID', '$name', '$questionID', '$this->IsCorrect')" );
88 $db->unlock();
89 }
90 elseif ( is_numeric( $this->ID ) )
91 {
92 $res[] = $db->query( "UPDATE eZQuiz_Alternative SET
93 Name='$name',
94 QuestionID='$questionID',
95 IsCorrect='$this->IsCorrect'
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
113 // $answers =& $this->answers();
114
115 if ( is_array ( $answers ) )
116 {
117 foreach ( $answers as $answer )
118 {
119 $answer->delete();
120 }
121 }
122
123 $res[] = $db->query( "DELETE FROM eZQuiz_Alternative WHERE ID='$catID'" );
124 eZDB::finish( $res, $db );
125 }
126
132 function get( $id = -1 )
133 {
134 $db =& eZDB::globalDatabase();
135
136 $ret = false;
137
138 if( $id == -1 )
139 {
140 $id = $this->ID;
141 }
142
143 if ( $id != "" )
144 {
145 $db->array_query( $alternativeArray, "SELECT * FROM eZQuiz_Alternative WHERE ID='$id'",
146 array( "Offset" => 0, "Limit" => 1 ) );
147
148 if ( count( $alternativeArray ) == 1 )
149 {
150 $this->fill( $alternativeArray[0] );
151 $ret = true;
152 }
153 elseif ( count( $alternativeArray ) == 1 )
154 {
155 $this->ID = 0;
156 }
157 }
158 return $ret;
159 }
160
164 function fill( &$alternativeArray )
165 {
166 $db =& eZDB::globalDatabase();
167 $this->ID =& $alternativeArray[$db->fieldName( "ID" )];
168 $this->Name =& $alternativeArray[$db->fieldName( "Name" )];
169 $this->IsCorrect =& $alternativeArray[$db->fieldName( "IsCorrect" )];
170 $this->Question = new eZQuizQuestion( $alternativeArray[$db->fieldName( "QuestionID" )] );
171 }
172
178 function getAll( $offset = 0, $limit = 20)
179 {
180 $db =& eZDB::globalDatabase();
181
182 $returnArray = array();
183 $alternativeArray = array();
184
185 $db->array_query( $alternativeArray, "SELECT ID FROM eZQuiz_Alternative" );
186
187 for ( $i = 0; $i < count( $alternativeArray ); $i++ )
188 {
189 $returnArray[$i] = new eZQuizAlternative( $alternativeArray[$i][$db->fieldName( "ID" )] );
190 }
191
192 return $returnArray;
193 }
194
198 function count()
199 {
200 $db =& eZDB::globalDatabase();
201 $ret = false;
202
203 $db->query_single( $result, "SELECT COUNT(ID) as Count FROM eZQuiz_Alternative" );
204 $ret = $result[$db->fieldName( "Count" )];
205 return $ret;
206 }
207
211 function id()
212 {
213 return $this->ID;
214 }
215
219 function name()
220 {
221 return htmlspecialchars( $this->Name );
222 }
223
227 function isCorrect()
228 {
229 if ( $this->IsCorrect == 1 )
230 return true;
231 elseif ( $this->IsCorrect == 0 )
232 return false;
233 }
234
238 function question()
239 {
240 return $this->Question;
241 }
242
246 function setName( &$value )
247 {
248 $this->Name = $value;
249 }
250
254 function setIsCorrect( $value )
255 {
256 if ( $value == true )
257 $this->IsCorrect = 1;
258 else
259 $this->IsCorrect = 0;
260 }
261
265 function questionID()
266 {
267 $ret = 0;
268
269 if ( is_a( $this->Question, "eZQuizQuestion" ) )
270 {
271 $ret = $this->Question->id();
272 }
273
274 return $ret;
275 }
276
280 function setQuestion( &$question )
281 {
282 if ( is_a( $question, "eZQuizQuestion" ) )
283 $this->Question = $question;
284 }
285
290 function answers()
291 {
292 $returnArray = array();
293 $db =& eZDB::globalDatabase();
294 $db->array_query( $questionArray, "SELECT ID FROM eZQuiz_Answer WHERE AlternativeID='$this->ID'" );
295
296 for ( $i = 0; $i < count( $questionArray ); $i++ )
297 {
298 $returnArray[$i] = new eZQuizAnswer( $questionArray[$i][$db->fieldName( "ID" )], true );
299 }
300 return $returnArray;
301 }
302
303 var $ID;
304 var $Name;
305 var $IsCorrect;
306 var $Question;
307 }
308
309 ?>
$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
eZQuizAlternative\store
store()
Definition: ezquizalternative.php:71
eZQuizAlternative\$Question
$Question
Definition: ezquizalternative.php:306
eZQuizAlternative\count
count()
Definition: ezquizalternative.php:198
eZQuizAlternative\__construct
__construct( $id=-1)
Definition: ezquizalternative.php:50
eZQuizAlternative\id
id()
Definition: ezquizalternative.php:211
eZQuizAlternative\name
name()
Definition: ezquizalternative.php:219
eZQuizAlternative\setQuestion
setQuestion(&$question)
Definition: ezquizalternative.php:280
eZQuizAlternative\setIsCorrect
setIsCorrect( $value)
Definition: ezquizalternative.php:254
eZQuizAlternative\$IsCorrect
$IsCorrect
Definition: ezquizalternative.php:305
eZQuizAlternative\fill
fill(&$alternativeArray)
Definition: ezquizalternative.php:164
eZQuizAlternative\setName
setName(&$value)
Definition: ezquizalternative.php:246
eZQuizAlternative\question
question()
Definition: ezquizalternative.php:238
eZQuizAlternative\getAll
getAll( $offset=0, $limit=20)
Definition: ezquizalternative.php:178
eZQuizAlternative\questionID
questionID()
Definition: ezquizalternative.php:265
eZQuizAlternative\$Name
$Name
Definition: ezquizalternative.php:304
eZQuizAlternative\isCorrect
isCorrect()
Definition: ezquizalternative.php:227
eZQuizAlternative\$ID
$ID
Definition: ezquizalternative.php:303
eZQuizAlternative\answers
answers()
Definition: ezquizalternative.php:290
eZQuizAnswer
Definition: ezquizanswer.php:43
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
$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+.