Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezsurvey.php
Go to the documentation of this file.
1 <?php
4 // include_once( "classes/ezdb.php" );
5 // include_once( "ezsurvey/classes/ezquestion.php" );
6
7 class eZSurvey
8 {
9 // constructor
10 function __construct( $id = "-1" )
11 {
12 if ( $id != -1 )
13 {
14 $this->ID = $id;
15 $this->get( $this->ID );
16 }
17 }
18
19 function get( $id = "-1" )
20 {
21 $SqlQuery = "SELECT
22 ID,
23 UserID,
24 Public,
25 Status,
26 Title,
27 SubTitle,
28 EMail,
29 Info,
30 ThanksPage,
31 ThankHead,
32 ThankBody,
33 Changed,
34 SectionID
35 FROM
36 eZSurvey_Survey
37 WHERE
38 ID = '$id'";
39
40 $db =& eZDB::globalDatabase();
41
42 $db->array_query( $survey_array, $SqlQuery );
43 if ( count( $survey_array ) > 1 )
44 {
45 die( "Error: More than one survey with the same ID found." );
46 }
47 elseif ( count( $survey_array ) == 1 )
48 {
49 $this->ID = $survey_array[ 0 ][ "ID" ];
50 $this->UserID = $survey_array[ 0 ][ "UserID" ];
51 $this->Public = $survey_array[ 0 ][ "Public" ];
52 $this->Status = $survey_array[ 0 ][ "Status" ];
53 $this->Title = $survey_array[ 0 ][ "Title" ];
54 $this->SubTitle = $survey_array[ 0 ][ "SubTitle" ];
55 $this->EMail = $survey_array[ 0 ][ "EMail" ];
56 $this->Info = $survey_array[ 0 ][ "Info" ];
57 $this->ThanksPage = $survey_array[ 0 ][ "ThanksPage" ];
58 $this->ThankHead = $survey_array[ 0 ][ "ThankHead" ];
59 $this->ThankBody = $survey_array[ 0 ][ "ThankBody" ];
60 $this->Changed = $survey_array[ 0 ][ "Changed" ];
61 $this->SectionID = $survey_array[ 0 ][ "SectionID" ];
62
63 return $this;
64 }
65
66 }
67
68 public static function getAll( $OrderBy = "ID", $LimitStart = "None", $LimitBy = "None" )
69 {
70 $db =& eZDB::globalDatabase();
71
72 switch ( strtolower( $OrderBy ) )
73 {
74 default:
75 $OrderBy = "ORDER BY ID";
76 break;
77 }
78
79 if ( is_numeric( $LimitStart ) )
80 {
81 $LimitArray = array( "Offset" => $LimitStart );
82
83 if ( is_numeric( $LimitBy ) )
84 {
85 $LimitArray =& array_merge( $LimitArray, array( "Limit" => $LimitBy ) );
86 }
87 }
88 else
89 {
90 $LimitArray = array();
91 }
92
93 $survey_array = array();
94 $return_array = array();
95
96 $SQLQuery = "SELECT ID as A FROM eZSurvey_Survey";
97
98 $SqlCond = "";
99
100 // TODO: acrescentar condi��es
101
102 if ($SqlCond != "")
103 {
104 $SQLQuery .= " WHERE $SqlCond";
105 }
106
107 $SQLQuery .= " $OrderBy";
108
109 $db->array_query( $survey_array, $SQLQuery, $LimitArray );
110
111 foreach ( $survey_array as $surveyItem )
112 {
113 $return_array[] = new eZSurvey( $surveyItem[ "A" ] );
114 }
115 return $return_array;
116 }
117
118 function store()
119 {
120 $ret = false;
121 $db =& eZDB::globalDatabase();
122 $db->begin();
123
124 if ( !isSet( $this->ID ) )
125 {
126 // create survey
127 $db->lock( "eZSurvey_Survey" );
128 $this->ID = $db->nextID( "eZSurvey_Survey", "ID" );
129 $res[] = $db->query( "INSERT INTO eZSurvey_Survey
130 (ID, UserID, Public, Status, Title, SubTitle, EMail, Info, ThanksPage, ThankHead, ThankBody, Changed, SectionID )
131 VALUES
132 ('$this->ID',
133 '$this->UserID',
134 '$this->Public',
135 'EDIT',
136 '$this->Title',
137 '$this->SubTitle',
138 '$this->EMail',
139 '$this->Info',
140 '$this->ThanksPage',
141 '$this->ThankHead',
142 '$this->ThankBody',
143 '" . time() . "',
144 '$this->SectionID'
145 )");
146
147 $db->unlock();
148 }
149 else
150 {
151 // Update survey
152 $db->lock( "eZSurvey_Survey" );
153 $query = "UPDATE eZSurvey_Survey set UserID='$this->UserID',
154 Public='$this->Public',
155 Status='$this->Status',
156 Title='$this->Title',
157 SubTitle='$this->SubTitle',
158 EMail='$this->EMail',
159 Info='$this->Info',
160 ThanksPage='$this->ThanksPage',
161 ThankHead='$this->ThankHead',
162 ThankBody='$this->ThankBody',
163 Changed='" . time() . "',
164 SectionID='$this->SectionID'
165 WHERE ID='$this->ID'";
166
167 $res[] = $db->query( $query );
168
169
170 $db->unlock();
171 }
172 $ret = $res;
173 eZDB::finish( $res, $db );
174 return true;
175 }
176
177 function delete()
178 {
179 $db =& eZDB::globalDatabase();
180 $db->begin();
181
182 $question_array = $this->surveyQuestions();
183 foreach ( $question_array as $questionItem )
184 {
185 $questionItem->delete();
186 }
187
188 $res[] = $db->query( "DELETE FROM eZSurvey_Survey WHERE ID='$this->ID'" );
189
190 eZDB::finish( $res, $db );
191 }
192
193 function copySurvey( $newTitle )
194 {
195 $newSurvey = new eZSurvey();
196
197 $newSurvey->setPublic( $this->Public );
198 $newSurvey->setStatus( "EDIT" );
199 $newSurvey->setTitle( $newTitle );
200 $newSurvey->setSubTitle( $this->SubTitle );
201 $newSurvey->setEMail( $this->EMail );
202 $newSurvey->setInfo( $this->Info );
203 $newSurvey->setThanksPage( $this->ThanksPage );
204 $newSurvey->setThankHead( $this->ThankHead );
205 $newSurvey->setThankBody( $this->ThankBody );
206
207 $newSurvey->store();
208
209 foreach( $this->surveyQuestions() as $questionItem )
210 {
211 $questionItem->copyQuestion( $newSurvey->id() );
212 }
213
214 return $newSurvey;
215 }
216
217 function surveyQuestions( $OrderBy = "Position", $Page = 0 )
218 {
219 $page_array = array();
220 $SqlCond = "";
221
222 $SqlQuery = "SELECT Position
223 FROM
224 eZSurvey_Question
225 WHERE
226 SurveyID = '$this->ID'
227 and QuestionTypeID = 99
228 ORDER BY
229 Position";
230
231 $db =& eZDB::globalDatabase();
232
233 $db->array_query( $page_array, $SqlQuery );
234
235 $start = "";
236 $end = "";
237
238 if ( $Page > 1 )
239 {
240 $start = $page_array[$Page-2][ "Position" ];
241 }
242 if ( isset( $page_array[$Page-1] ) && $Page <= count($page_array) )
243 {
244 $end = $page_array[$Page-1][ "Position" ];
245 }
246
247 if ($start != "")
248 {
249 $SqlCond .= " AND Position > '$start'";
250 }
251 if ($end != "")
252 {
253 $SqlCond .= " AND Position < '$end'";
254 }
255
256 $SqlQuery = "SELECT ID
257 FROM
258 eZSurvey_Question
259 WHERE
260 SurveyID = '$this->ID'";
261
262 $SqlQuery .= "$SqlCond ORDER BY $OrderBy";
263
264 $db->array_query( $question_array, $SqlQuery );
265
266 $return_array = array();
267
268 foreach( $question_array as $questionItem )
269 {
270 $return_array[] = new eZQuestion( $questionItem[ "ID" ] );
271 }
272
273 return $return_array;
274 }
275
276 public static function numberOfSurveys()
277 {
278 $db =& eZDB::globalDatabase();
279
280 $db->array_query( $count, "SELECT count(*) as A FROM eZSurvey_Survey" );
281
282 return $count[ 0 ][ "A" ];
283 }
284
285 function numberOfQuestions()
286 {
287 $db =& eZDB::globalDatabase();
288
289 $db->array_query( $count, "SELECT count(*) as A FROM eZSurvey_Question WHERE SurveyID = " . $this->ID );
290
291 return $count[ 0 ][ "A" ];
292 }
293
294 function numberOfPages()
295 {
296 $db =& eZDB::globalDatabase();
297
298 $db->array_query( $count, "SELECT count(*) as A FROM eZSurvey_Question WHERE SurveyID = '$this->ID' AND QuestionTypeID = 99" );
299
300 return ($count[ 0 ][ "A" ]+1);
301 }
302
303 public function statusOptions()
304 {
305 switch( $this->Status )
306 {
307 case "EDIT":
308 {
309 return Array( "EDIT", "ACTIVE" );
310 }
311 break;
312
313 case "ACTIVE":
314 {
315 return Array( "ACTIVE", "EDIT", "DONE" );
316 }
317 break;
318
319 case "DONE":
320 {
321 return Array( "DONE" );
322 }
323 break;
324
325 default:
326 {
327 return Array( "EDIT" );
328 }
329 }
330 }
331
332 function hasCompleted( $userID )
333 {
334 $db =& eZDB::globalDatabase();
335
336 $db->array_query( $count, "SELECT Complete FROM eZSurvey_Response WHERE SurveyID = '$this->ID' AND UserID = '$userID' AND Complete = 'Y'" );
337
338 $ret = false;
339
340 if ( count($count) > 0 )
341 {
342 $ret = true;
343 }
344
345 return $ret;
346 }
347
348 public static function existSurvey( $id )
349 {
350 $db =& eZDB::globalDatabase();
351 $SQLQuery ="SELECT ID FROM eZSurvey_Survey where ID = '$id'";
352 $db->array_query( $survey_array, $SQLQuery );
353
354 if (count ($survey_array))
355 {
356 return true;
357 }
358 else
359 {
360 return false;
361 }
362 }
363
364 // get functions
365 function id() { return $this->ID; }
366 function userId() { return $this->UserID; }
367 function public() { return $this->Public; }
368 function status() { return $this->Status; }
369 function title() { return $this->Title; }
370 function subTitle() { return $this->SubTitle; }
371 function email() { return $this->EMail; }
372 function info() { return $this->Info; }
373 function thanksPage() { return $this->ThanksPage; }
374 function thankHead() { return $this->ThankHead; }
375 function thankBody() { return $this->ThankBody; }
376 function changed() { return $this->Changed; }
377 function sectionID() { return $this->SectionID; }
378
379 // set functions
380 function setUserId( $value ) { $this->UserID = $value; }
381 function setPublic( $value ) { $this->Public = $value; }
382 function setStatus( $value ) { $this->Status = $value; }
383 function setTitle( $value ) { $this->Title = $value; }
384 function setSubTitle( $value ) { $this->SubTitle = $value; }
385 function setEMail( $value ) { $this->EMail = $value; }
386 function setInfo( $value ) { $this->Info = $value; }
387 function setThanksPage( $value ) { $this->ThanksPage = $value; }
388 function setThankHead( $value ) { $this->ThankHead = $value; }
389 function setThankBody( $value ) { $this->ThankBody =$value; }
390 function setChanged( $value ) { $this->Changed =$value; }
391 function setSectionID( $value ) { $this->SectionID =$value; }
392
393 var $ID;
394 var $UserID;
395 var string $Public;
396 var $Status;
397 var $Title;
398 var $SubTitle;
399 var $EMail;
400 var $Info;
401 var $ThanksPage;
402 var $ThankHead;
403 var $ThankBody;
404 var $Changed;
405 var $SectionID;
406 }
407
408 ?>
$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
eZQuestion
Definition: ezquestion.php:11
eZSurvey
Definition: ezsurvey.php:8
eZSurvey\setInfo
setInfo( $value)
Definition: ezsurvey.php:386
eZSurvey\$Title
$Title
Definition: ezsurvey.php:397
eZSurvey\changed
changed()
Definition: ezsurvey.php:376
eZSurvey\email
email()
Definition: ezsurvey.php:371
eZSurvey\store
store()
Definition: ezsurvey.php:118
eZSurvey\numberOfSurveys
static numberOfSurveys()
Definition: ezsurvey.php:276
eZSurvey\getAll
static getAll( $OrderBy="ID", $LimitStart="None", $LimitBy="None")
Definition: ezsurvey.php:68
eZSurvey\thanksPage
thanksPage()
Definition: ezsurvey.php:373
eZSurvey\setChanged
setChanged( $value)
Definition: ezsurvey.php:390
eZSurvey\setPublic
setPublic( $value)
Definition: ezsurvey.php:381
eZSurvey\numberOfQuestions
numberOfQuestions()
Definition: ezsurvey.php:285
eZSurvey\$ID
$ID
Definition: ezsurvey.php:393
eZSurvey\hasCompleted
hasCompleted( $userID)
Definition: ezsurvey.php:332
eZSurvey\$Status
$Status
Definition: ezsurvey.php:396
eZSurvey\statusOptions
statusOptions()
Definition: ezsurvey.php:303
eZSurvey\$ThankHead
$ThankHead
Definition: ezsurvey.php:402
eZSurvey\$Public
string $Public
Definition: ezsurvey.php:395
eZSurvey\$SectionID
$SectionID
Definition: ezsurvey.php:405
eZSurvey\sectionID
sectionID()
Definition: ezsurvey.php:377
eZSurvey\setThankHead
setThankHead( $value)
Definition: ezsurvey.php:388
eZSurvey\surveyQuestions
surveyQuestions( $OrderBy="Position", $Page=0)
Definition: ezsurvey.php:217
eZSurvey\$Changed
$Changed
Definition: ezsurvey.php:404
eZSurvey\thankBody
thankBody()
Definition: ezsurvey.php:375
eZSurvey\$ThankBody
$ThankBody
Definition: ezsurvey.php:403
eZSurvey\info
info()
Definition: ezsurvey.php:372
eZSurvey\status
function status()
Definition: ezsurvey.php:368
eZSurvey\$UserID
$UserID
Definition: ezsurvey.php:394
eZSurvey\setEMail
setEMail( $value)
Definition: ezsurvey.php:385
eZSurvey\thankHead
thankHead()
Definition: ezsurvey.php:374
eZSurvey\subTitle
subTitle()
Definition: ezsurvey.php:370
eZSurvey\numberOfPages
numberOfPages()
Definition: ezsurvey.php:294
eZSurvey\setTitle
setTitle( $value)
Definition: ezsurvey.php:383
eZSurvey\copySurvey
copySurvey( $newTitle)
Definition: ezsurvey.php:193
eZSurvey\setSubTitle
setSubTitle( $value)
Definition: ezsurvey.php:384
eZSurvey\__construct
__construct( $id="-1")
Definition: ezsurvey.php:10
eZSurvey\$SubTitle
$SubTitle
Definition: ezsurvey.php:398
eZSurvey\id
id()
Definition: ezsurvey.php:365
eZSurvey\$Info
$Info
Definition: ezsurvey.php:400
eZSurvey\setThankBody
setThankBody( $value)
Definition: ezsurvey.php:389
eZSurvey\$EMail
$EMail
Definition: ezsurvey.php:399
eZSurvey\title
title()
Definition: ezsurvey.php:369
eZSurvey\setStatus
setStatus( $value)
Definition: ezsurvey.php:382
eZSurvey\setSectionID
setSectionID( $value)
Definition: ezsurvey.php:391
eZSurvey\setThanksPage
setThanksPage( $value)
Definition: ezsurvey.php:387
eZSurvey\$ThanksPage
$ThanksPage
Definition: ezsurvey.php:401
eZSurvey\existSurvey
static existSurvey( $id)
Definition: ezsurvey.php:348
eZSurvey\userId
userId()
Definition: ezsurvey.php:366
eZSurvey\setUserId
setUserId( $value)
Definition: ezsurvey.php:380
$id
$id
Definition: companytypelist.php:193
$query
if(isset( $Year) &&!is_numeric( $Year)||isset( $Month) &&!is_numeric( $Month)) $query
Definition: entryexitpages.php:65
$db
$db
Definition: ezarticle/user/authorlist.php:53
$ret
$ret
Definition: ezsitemanager/admin/filelist.php:88
$res
$res
Definition: ezstats/admin/cron.php:45
$count
$count
Definition: onlinetypelist.php:108
$Page
$Page
Definition: preview.php:13
$question_array
$question_array
Definition: preview.php:88
$OrderBy
$OrderBy
Definition: reciverpopup.php:21
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.