Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezquizanswer.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: ezquizanswer.php 8687 2001-12-06 10:19:29Z jhe $
5 //
6 // eZQuizAnswer 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/ezquizalternative.php" );
41
42 class eZQuizAnswer
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 $alternativeID = $this->Alternative->id();
77
78 if ( !isset( $this->ID ) )
79 {
80 $db->lock( "eZQuiz_Answer" );
81 $this->ID = $db->nextID( "eZQuiz_Answer", "ID" );
82 $res = $db->query( "INSERT INTO eZQuiz_Answer
83 (ID, UserID, AlternativeID)
84 VALUES
85 ('$this->ID','$userID','$alternativeID')" );
86 $db->unlock();
87
88 }
89 elseif ( is_numeric( $this->ID ) )
90 {
91 $res�= $db->query( "UPDATE eZQuiz_Answer SET
92 UserID='$userID',
93 AlternativeID='$alternativeID'
94 WHERE ID='$this->ID'" );
95 }
96 eZDB::finish( $res, $db );
97 return true;
98 }
99
103 function delete( $catID = -1 )
104 {
105 if ( $catID == -1 )
106 $catID = $this->ID;
107
108 $db =& eZDB::globalDatabase();
109 $db->begin();
110 $res[] = $db->query( "DELETE FROM eZQuiz_Answer WHERE ID='$catID'" );
111 eZDB::finish( $res, $db );
112 }
113
119 function get( $id = -1 )
120 {
121 $db =& eZDB::globalDatabase();
122
123 $ret = false;
124 if ( $id != "" )
125 {
126 $db->array_query( $answerArray, "SELECT * FROM eZQuiz_Answer WHERE ID='$id'",
127 array( "Offset" => 0, "Limit" => 1 ) );
128
129 if ( count( $answerArray ) == 1 )
130 {
131 $this->fill( &$answerArray[0] );
132 $ret = true;
133 }
134 elseif ( count( $answerArray ) == 1 )
135 {
136 $this->ID = 0;
137 }
138 }
139 return $ret;
140 }
141
145 function fill( &$answerArray )
146 {
147 $this->ID =& $answerArray[$db->fieldName( "ID" )];
148 $this->User =& new eZUser( $answerArray[$db->fieldName( "UserID" )] );
149 $this->Alternative = new eZQuizAlternative( $answerArray[$db->fieldName( "QuestionID" )] );
150 }
151
157 function getAll( $offset = 0, $limit = 20)
158 {
159 $db =& eZDB::globalDatabase();
160
161 $returnArray = array();
162 $answerArray = array();
163
164 $db->array_query( $answerArray, "SELECT ID FROM eZQuiz_Answer " );
165
166 for ( $i = 0; $i < count( $answerArray ); $i++ )
167 {
168 $returnArray[$i] = new eZQuizAnswer( $answerArray[$i][$db->fieldName( "ID" )] );
169 }
170
171 return $returnArray;
172 }
173
177 function count()
178 {
179 $db =& eZDB::globalDatabase();
180 $ret = false;
181
182 $db->query_single( $result, "SELECT COUNT(ID) as Count FROM eZQuiz_Answer" );
183 $ret = $result[$db->fieldName( "Count" )];
184 return $ret;
185 }
186
190 function hasAnswered()
191 {
192 $return = false;
193
194 if ( is_a( $this->Alternative, "eZQuizAlternative" ) )
195 {
196 $QuestionID = $this->Alternative->QuestionID();
197 }
198
199 if ( is_a( $this->User, "eZUser" ) )
200 {
201 $UserID = $this->User->id();
202 }
203
204 $db =& eZDB::globalDatabase();
205 $db->array_query( $result, "SELECT * FROM eZQuiz_Answer, eZQuiz_Alternative
206 WHERE eZQuiz_Answer.AlternativeID = eZQuiz_Alternative.ID
207 AND eZQuiz_Alternative.QuestionID = '$QuestionID' AND eZQuiz_Answer.UserID = '$UserID'" );
208
209 if ( count( $result ) >= 1 )
210 {
211 $return = true;
212 }
213
214 return $return;
215 }
216
217
221 function id()
222 {
223 return $this->ID;
224 }
225
229 function alternative()
230 {
231 return $this->Alternative;
232 }
233
237 function user()
238 {
239 return $this->User;
240 }
241
245 function setUser( &$user )
246 {
247 if ( is_a( $user, "eZUser" ) )
248 $this->User = $user;
249 }
250
254 function setAlternative( &$alternative )
255 {
256 if ( is_a( $alternative, "eZQuizAlternative" ) )
257 $this->Alternative = $alternative;
258 }
259
260
261 var $ID;
262 var $User;
263 var $Alternative;
264 }
265
266 ?>
$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
eZQuizAlternative
Definition: ezquizalternative.php:42
eZQuizAnswer
Definition: ezquizanswer.php:43
eZQuizAnswer\alternative
alternative()
Definition: ezquizanswer.php:229
eZQuizAnswer\setUser
setUser(&$user)
Definition: ezquizanswer.php:245
eZQuizAnswer\$ID
$ID
Definition: ezquizanswer.php:261
eZQuizAnswer\user
user()
Definition: ezquizanswer.php:237
eZQuizAnswer\$Alternative
$Alternative
Definition: ezquizanswer.php:263
eZQuizAnswer\__construct
__construct( $id=-1, $fetch=true)
Definition: ezquizanswer.php:51
eZQuizAnswer\id
id()
Definition: ezquizanswer.php:221
eZQuizAnswer\setAlternative
setAlternative(&$alternative)
Definition: ezquizanswer.php:254
eZQuizAnswer\hasAnswered
hasAnswered()
Definition: ezquizanswer.php:190
eZQuizAnswer\store
store()
Definition: ezquizanswer.php:70
eZQuizAnswer\fill
fill(&$answerArray)
Definition: ezquizanswer.php:145
eZQuizAnswer\$User
$User
Definition: ezquizanswer.php:262
eZQuizAnswer\getAll
getAll( $offset=0, $limit=20)
Definition: ezquizanswer.php:157
eZQuizAnswer\count
count()
Definition: ezquizanswer.php:177
eZUser
Definition: ezuser.php:76
$result
$result
Definition: companysearch.php:94
$name
$name
Definition: companytypelist.php:194
$id
$id
Definition: companytypelist.php:193
$QuestionID
$QuestionID
Definition: default.php:30
$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
$UserID
$UserID
Definition: todoedit.php:122
$user
$user
Definition: user/adlist.php:39
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.