Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezresponsequestion.php
Go to the documentation of this file.
1 <?php
4 // include_once( "ezsurvey/classes/ezquestion.php" );
5 // include_once( "ezsurvey/classes/ezquestionchoice.php" );
6
7 // // response types classes
8 // include_once( "ezsurvey/classes/ezresponsebool.php" );
9 // include_once( "ezsurvey/classes/ezresponsedate.php" );
10 // include_once( "ezsurvey/classes/ezresponsemultiple.php" );
11 // include_once( "ezsurvey/classes/ezresponserank.php" );
12 // include_once( "ezsurvey/classes/ezresponsesingle.php" );
13 // include_once( "ezsurvey/classes/ezresponsetext.php" );
14
15 class eZResponseQuestion
16 {
17 function __construct( $response = "", $question = "" )
18 {
19 if ( $response != "" && $question != "" )
20 {
21 $this->get( $response, $question );
22 }
23 }
24
25 function get( $responseID, $questionID )
26 {
27 $this->ResponseID = $responseID;
28 $this->QuestionID = $questionID;
29
30 $question = new eZQuestion( $this->QuestionID );
31
32 switch( $question->responseTable() )
33 {
34 case $question->TABLE_BOOL:
35 {
36 $response = new eZResponseBool();
37 $response_array = $response->getAll( "ID", $this->ResponseID, $this->QuestionID );
38 if ( count($response_array) == 1 )
39 {
40 $ChoiceID = $response_array[0]->choiceID();
41 }
42 }
43 break;
44
45 case $question->TABLE_TEXT:
46 {
47 $response = new eZResponseText();
48 $response_array = $response->getAll( "ID", $this->ResponseID, $this->QuestionID );
49 if ( count($response_array) == 1 )
50 {
51 $ChoiceID = $response_array[0]->response();
52 }
53 }
54 break;
55
56 case $question->TABLE_SINGLE:
57 {
58 $response = new eZResponseSingle();
59 $response_array = $response->getAll( "ID", $this->ResponseID, $this->QuestionID );
60
61 if ( count($response_array) == 1 )
62 {
63 $ChoiceID = $response_array[0]->choiceID();
64 $Other = $response_array[0]->other();
65 }
66 }
67 break;
68
69 case $question->TABLE_MULTIPLE:
70 {
71 $response = new eZResponseMultiple();
72 $response_array = $response->getAll( "ID", $this->ResponseID, $this->QuestionID );
73
74 foreach ( $response_array as $responseItem )
75 {
76 $ChoiceID[] = $responseItem->choiceID();
77 $Other[] = $responseItem->other();
78 }
79 }
80 break;
81
82 case $question->TABLE_RANK:
83 {
84 $response = new eZResponseRank();
85 $response_array = $response->getAll( "ID", $this->ResponseID, $this->QuestionID );
86
87 foreach ( $response_array as $responseItem )
88 {
89 $ChoiceID[] = $responseItem->choiceID();
90 $Other[] = $responseItem->rank();
91 }
92 }
93 break;
94
95 case $question->TABLE_DATE:
96 {
97 $response = new eZResponseDate();
98 $response_array = $response->getAll( "ID", $this->ResponseID, $this->QuestionID );
99 if ( count($response_array) == 1 )
100 {
101 $ChoiceID = $response_array[0]->response();
102 }
103 }
104 break;
105 }
106
107 $this->ChoiceID = $ChoiceID;
108 $this->Other = $Other;
109
110 return $this;
111 }
112
113 function getResponsesByQuestion( $OrderBy = "ID", $QuestionID = "", $LimitStart = "None", $LimitBy = "None" )
114 {
115 $db =& eZDB::globalDatabase();
116
117 if ( is_numeric( $LimitStart ) )
118 {
119 $LimitArray = array( "Offset" => $LimitStart );
120
121 if ( is_numeric( $LimitBy ) )
122 {
123 $LimitArray =& array_merge( $LimitArray, array( "Limit" => $LimitBy ) );
124 }
125 }
126 else
127 {
128 $LimitArray = array();
129 }
130
131 $question = new eZQuestion( $QuestionID );
132
133 switch( $question->responseTable() )
134 {
135 case $question->TABLE_BOOL:
136 {
137 $response = new eZResponseBool();
138 }
139 break;
140
141 case $question->TABLE_TEXT:
142 {
143 $response = new eZResponseText();
144 }
145 break;
146
147 case $question->TABLE_SINGLE:
148 {
149 $response = new eZResponseSingle();
150 }
151 break;
152
153 case $question->TABLE_SINGLE:
154 {
155 $response = new eZResponseMultiple();
156 }
157 break;
158
159 case $question->TABLE_RANK:
160 {
161 $response = new eZResponseRank();
162 }
163 break;
164
165 case $question->TABLE_DATE:
166 {
167 $response = new eZResponseDate();
168 }
169 break;
170 }
171
172 $question_array = Array();
173 $resturn_array = Array();
174
175 $question_array = $response->getAll( $OrderBy, "", $QuestionID );
176 foreach ( $question_array as $questionItem )
177 {
178 $return_array = new eZResponseQuestion( $response->ResponseID(), $QuestionID );
179 }
180
181 return $return_array;
182 }
183
184 function store()
185 {
186 $question = new eZQuestion( $this->QuestionID );
187
188 $this->delete();
189
190 switch( $question->responseTable() )
191 {
192 case $question->TABLE_BOOL:
193 {
194 $response = new eZResponseBool();
195
196 $response->setResponseID( $this->ResponseID );
197 $response->setQuestionID( $this->QuestionID );
198 $response->setChoiceID( $this->ChoiceID );
199
200 $response->store();
201 }
202 break;
203
204 case $question->TABLE_TEXT:
205 {
206 $response = new eZResponseText();
207
208 $response->setResponseID( $this->ResponseID );
209 $response->setQuestionID( $this->QuestionID );
210 $response->setResponse( $this->ChoiceID );
211
212 $response->store();
213 }
214 break;
215
216 case $question->TABLE_SINGLE:
217 {
218 $response = new eZResponseSingle();
219
220 $response->setResponseID( $this->ResponseID );
221 $response->setQuestionID( $this->QuestionID );
222 $response->setChoiceID( $this->ChoiceID );
223 $response->setOther( $this->Other );
224
225 $response->store();
226 }
227 break;
228
229 case $question->TABLE_MULTIPLE:
230 {
231 if ( is_array( $this->ChoiceID ) )
232 {
233 $i = 0;
234 foreach ( $this->ChoiceID as $choiceItem )
235 {
236 $response = new eZResponseMultiple();
237
238 $response->setResponseID( $this->ResponseID );
239 $response->setQuestionID( $this->QuestionID );
240 $response->setChoiceID( $choiceItem );
241 $response->setOther( $this->Other[$i++] );
242
243 $response->store();
244 }
245 }
246 }
247 break;
248
249 case $question->TABLE_RANK:
250 {
251 $i = 0;
252 foreach ( $this->ChoiceID as $choiceItem )
253 {
254 $response = new eZResponseRank();
255
256 $response->setResponseID( $this->ResponseID );
257 $response->setQuestionID( $this->QuestionID );
258 $response->setChoiceID( $choiceItem );
259 $response->setRank( $this->Other[$i++] );
260
261 $response->store();
262 }
263 }
264 break;
265
266 case $question->TABLE_DATE:
267 {
268 $response = new eZResponseDate();
269
270 $response->setResponseID( $this->ResponseID );
271 $response->setQuestionID( $this->QuestionID );
272 $response->setResponse( $this->ChoiceID );
273
274 $response->store();
275 }
276 break;
277 }
278 }
279
280 function delete()
281 {
282 $question = new eZQuestion( $this->QuestionID );
283
284 switch( $question->responseTable() )
285 {
286 case $question->TABLE_BOOL:
287 {
288 $response = new eZResponseBool();
289 }
290 break;
291
292 case $question->TABLE_TEXT:
293 {
294 $response = new eZResponseText();
295 }
296 break;
297
298 case $question->TABLE_SINGLE:
299 {
300 $response = new eZResponseSingle();
301 }
302 break;
303
304 case $question->TABLE_MULTIPLE:
305 {
306 $response = new eZResponseMultiple();
307 }
308 break;
309
310 case $question->TABLE_RANK:
311 {
312 $response = new eZResponseRank();
313 }
314 break;
315
316 case $question->TABLE_DATE:
317 {
318 $response = new eZResponseDate();
319 }
320 break;
321 }
322
323 $response->deleteResponse( $this->ResponseID, $this->QuestionID );
324 }
325
326 public static function deleteByQuestion( $QuestionID )
327 {
328 $question = new eZQuestion( $QuestionID );
329
330 $delete = true;
331
332 switch( $question->responseTable() )
333 {
334 case $question->TABLE_BOOL:
335 {
336 $response = new eZResponseBool();
337 }
338 break;
339
340 case $question->TABLE_TEXT:
341 {
342 $response = new eZResponseText();
343 }
344 break;
345
346 case $question->TABLE_SINGLE:
347 {
348 $response = new eZResponseSingle();
349 }
350 break;
351
352 case $question->TABLE_MULTIPLE:
353 {
354 $response = new eZResponseMultiple();
355 }
356 break;
357
358 case $question->TABLE_RANK:
359 {
360 $response = new eZResponseRank();
361 }
362 break;
363
364 case $question->TABLE_DATE:
365 {
366 $response = new eZResponseDate();
367 }
368 break;
369
370 default:
371 {
372 $delete = false;
373 }
374 }
375
376 if ( $delete )
377 {
378 $response->deleteByQuestion( $QuestionID );
379 }
380 }
381
382 function report()
383 {
384 $question = new eZQuestion( $this->QuestionID );
385
386 // n�o h� report para estes
387 if ( $question->questionTypeID() == $question->TYPE_PAGEBREAK
388 || $question->questionTypeID() == $question->TYPE_SECTIONTEXT )
389 {
390 return;
391 }
392
393 $ret = $question->content() . "\n";
394
395 if ( is_array( $this->ChoiceID ) )
396 {
397 $i = 0;
398
399 foreach ( $this->ChoiceID as $choiceItem )
400 {
401 $choice = new eZQuestionChoice( $choiceItem );
402 $other = $this->Other[$i++];
403 $ret .= "- " . $choice->content();
404 if ( $other != "" )
405 {
406 if ( $question->questionTypeID() == $question->TYPE_RATE )
407 {
408 $other++;
409 }
410 $ret .= ": $other";
411 }
412 $ret .= "\n";
413 }
414 }
415 else
416 {
417 if ( $question->hasChoices() )
418 {
419 $choice = new eZQuestionChoice( $this->ChoiceID );
420 $ret .= "- " . $choice->content();
421 }
422 else
423 {
424 $ret .= "- $this->ChoiceID";
425 }
426
427 if ( $this->Other != "" )
428 {
429 $ret .= ": $this->Order";
430 }
431 $ret .= "\n";
432 }
433
434 return $ret;
435 }
436
437 // get functions
438 function responseID() { return $this->ResponseID; }
439 function questionID() { return $this->QuestionID; }
440 function choiceID() { return $this->ChoiceID; }
441 function other() { return $this->Other; }
442
443 // set functions
444 function setResponseID( $value ) { $this->ResponseID = $value; }
445 function setQuestionID( $value ) { $this->QuestionID = $value; }
446 function setChoiceID( $value ) { $this->ChoiceID = $value; }
447 function setOther( $value ) { $this->Other = $value; }
448
449 var $ResponseID;
450 var $QuestionID;
451 var $ChoiceID;
452 var $Other;
453 }
$i
$i
Definition: admin/adlist.php:91
eZDB\globalDatabase
static & globalDatabase()
Definition: ezdb.php:134
eZQuestion
Definition: ezquestion.php:11
eZResponseDate
Definition: ezresponsedate.php:5
eZResponseQuestion
Definition: ezresponsequestion.php:16
eZResponseQuestion\report
report()
Definition: ezresponsequestion.php:382
eZResponseQuestion\setResponseID
setResponseID( $value)
Definition: ezresponsequestion.php:444
eZResponseQuestion\$Other
$Other
Definition: ezresponsequestion.php:452
eZResponseQuestion\$ChoiceID
$ChoiceID
Definition: ezresponsequestion.php:451
eZResponseQuestion\$ResponseID
$ResponseID
Definition: ezresponsequestion.php:449
eZResponseQuestion\getResponsesByQuestion
getResponsesByQuestion( $OrderBy="ID", $QuestionID="", $LimitStart="None", $LimitBy="None")
Definition: ezresponsequestion.php:113
eZResponseQuestion\__construct
__construct( $response="", $question="")
Definition: ezresponsequestion.php:17
eZResponseQuestion\responseID
responseID()
Definition: ezresponsequestion.php:438
eZResponseQuestion\$QuestionID
$QuestionID
Definition: ezresponsequestion.php:450
eZResponseQuestion\setOther
setOther( $value)
Definition: ezresponsequestion.php:447
eZResponseQuestion\setQuestionID
setQuestionID( $value)
Definition: ezresponsequestion.php:445
eZResponseQuestion\setChoiceID
setChoiceID( $value)
Definition: ezresponsequestion.php:446
eZResponseQuestion\store
store()
Definition: ezresponsequestion.php:184
eZResponseQuestion\other
other()
Definition: ezresponsequestion.php:441
eZResponseQuestion\deleteByQuestion
static deleteByQuestion( $QuestionID)
Definition: ezresponsequestion.php:326
eZResponseQuestion\choiceID
choiceID()
Definition: ezresponsequestion.php:440
eZResponseQuestion\questionID
questionID()
Definition: ezresponsequestion.php:439
$question
$question
Definition: default.php:43
$db
$db
Definition: ezarticle/user/authorlist.php:53
eZQuestionChoice
Class eZQuestionChoice
Definition: ezquestionchoice.php:5
eZResponseBool
Class eZResponseBool
Definition: ezresponsebool.php:5
eZResponseMultiple
Class eZResponseMultiple
Definition: ezresponsemultiple.php:5
eZResponseRank
Class eZResponseRank
Definition: ezresponserank.php:5
eZResponseSingle
Class eZResponseSingle
Definition: ezresponsesingle.php:5
eZResponseText
Class eZResponseText
Definition: ezresponsetext.php:5
$ret
$ret
Definition: ezsitemanager/admin/filelist.php:88
$response
while(!feof($socket)) $response
Definition: paypalnotify.php:196
$question_array
$question_array
Definition: preview.php:88
$OrderBy
$OrderBy
Definition: reciverpopup.php:21
$choice
$choice
Definition: votepage.php:58
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.