Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezresponse.php
Go to the documentation of this file.
1 <?php
4 // include_once( "ezmail/classes/ezmail.php" );
5 // include_once( "ezbulkmail/classes/ezbulkmailtemplate.php" );
6
7 class eZResponse
8 {
9 function __construct( $id = "-1" )
10 {
11 if ( $id != -1 )
12 {
13 $this->ID = $id;
14 $this->get( $this->ID );
15 }
16 }
17
18 function get( $id = "-1" )
19 {
20 $SqlQuery = "SELECT
21 ID,
22 SurveyID,
23 Submitted,
24 Complete,
25 UserID
26 FROM
27 eZSurvey_Response
28 WHERE
29 ID = '$id'";
30
31 $db =& eZDB::globalDatabase();
32
33 $db->array_query( $object_array, $SqlQuery );
34 if ( count( $object_array ) > 1 )
35 {
36 die( "Error: More than one object with the same ID found." );
37 }
38 elseif ( count( $object_array ) == 1 )
39 {
40 $this->ID = $object_array[ 0 ][ "ID" ];
41 $this->SurveyID = $object_array[ 0 ][ "SurveyID" ];
42 $this->Submitted = $object_array[ 0 ][ "Submitted" ];
43 $this->Complete = $object_array[ 0 ][ "Complete" ];
44 $this->UserID = $object_array[ 0 ][ "UserID" ];
45
46 return $this;
47 }
48 }
49
50 function store()
51 {
52 $ret = false;
53 $db =& eZDB::globalDatabase();
54 $db->begin();
55
56 if ( !isSet( $this->ID) )
57 {
58 // create
59 $db->lock( "eZSurvey_Response" );
60 $this->ID = $db->nextID( "eZSurvey_Response", "ID" );
61 $res[] = $db->query( "INSERT INTO eZSurvey_Response
62 (ID, SurveyID, Submitted, Complete, UserID)
63 VALUES (
64 '$this->ID',
65 '$this->SurveyID',
66 '" . time() . "',
67 '$this->Complete',
68 '$this->UserID'
69 )");
70
71 $db->unlock();
72 }
73 else
74 {
75 // update
76 $db->lock( "eZSurvey_Response" );
77 $res[] = $db->query( "UPDATE eZSurvey_Response set
78 ID = '$this->ID',
79 SurveyID = '$this->SurveyID',
80 Submitted = '" . time() . "',
81 Complete = '$this->Complete',
82 UserID = '$this->UserID'
83 WHERE ID = '$this->ID'");
84
85 $db->unlock();
86 }
87 eZDB::finish( $res, $db );
88 return true;
89 }
90
91 function delete()
92 {
93 $db =& eZDB::globalDatabase();
94 $db->begin();
95
96 $res[] = $db->query( "DELETE FROM eZSurvey_Response WHERE ID='$this->ID'" );
97
98 eZDB::finish( $res, $db );
99 }
100
101 public static function numberOfResponses( $surveyId = "" )
102 {
103 $db =& eZDB::globalDatabase();
104
105 // if ( $surveyId == "" )
106 // {
107 // $surveyId = $this->SurveyID;
108 // }
109
110 $SqlQuery = "SELECT count(*) as A from eZSurvey_Response WHERE SurveyID = '$surveyId'";
111 $db->array_query( $question_array, $SqlQuery );
112
113 return $question_array[ 0 ][ "A" ];
114 }
115
116 function sendMail()
117 {
118 $survey = new eZSurvey( $this->SurveyID );
119 $ini =& eZINI::instance( 'site.ini' );
120
121 if ( trim($survey->email()) != "" )
122 {
123 $question_array =& $survey->surveyQuestions();
124
125 foreach ( $question_array as $questionItem )
126 {
127 $questionResponse = new eZResponseQuestion( $this->ID, $questionItem->id() );
128 $body .= $questionResponse->report() . "\n";
129 }
130
131 $TemplateID = $ini->variable( "eZSurveyMain", "ReportTemplateID" );
132 $mailTemplate = new eZBulkMailTemplate($TemplateID);
133
134 $subjectMail = str_replace ( "%SURVEY%", $survey->title(), $mailTemplate->name() );
135 $bodyMail = str_replace ( "%REPORT%", $body, $mailTemplate->header() );
136
137 $mail = new eZMail();
138 $mail->setTo( $survey->email() );
139 $mail->setSubject( $subjectMail );
140 $mail->setFrom( "nospam@novis.pt" );
141 $mail->setBody( $body );
142
143 $mail->store();
144 $mail->send();
145 }
146 }
147
148 // get functions
149 function id() { return $this->ID; }
150 function surveyID() { return $this->SurveyID; }
151 function submitted() { return $this->Submitted; }
152 function complete() { return $this->Complete; }
153 function userID() { return $this->UserID; }
154
155 // set functions
156 function setID( $value ) { $this->ID = $value; }
157 function setSurveyID( $value ) { $this->SurveyID = $value; }
158 function setSubmitted( $value ) { $this->Submitted = $value; }
159 function setComplete( $value ) { $this->Complete = $value; }
160 function setUserID( $value ) { $this->UserID = $value; }
161
162 // internal variables
163 var $ID;
164 var $SurveyID;
165 var $Submitted;
166 var $Complete;
167 var $UserID;
168 }
169
170 ?>
eZBulkMailTemplate
Definition: ezbulkmailtemplate.php:40
eZDB\finish
static finish(&$resultArray, &$db)
Definition: ezdb.php:204
eZDB\globalDatabase
static & globalDatabase()
Definition: ezdb.php:134
eZMail
Definition: ezmail.php:57
eZResponseQuestion
Definition: ezresponsequestion.php:16
eZResponse
Definition: ezresponse.php:8
eZResponse\sendMail
sendMail()
Definition: ezresponse.php:116
eZResponse\$ID
$ID
Definition: ezresponse.php:163
eZResponse\$Complete
$Complete
Definition: ezresponse.php:166
eZResponse\setSubmitted
setSubmitted( $value)
Definition: ezresponse.php:158
eZResponse\$SurveyID
$SurveyID
Definition: ezresponse.php:164
eZResponse\setUserID
setUserID( $value)
Definition: ezresponse.php:160
eZResponse\setSurveyID
setSurveyID( $value)
Definition: ezresponse.php:157
eZResponse\setComplete
setComplete( $value)
Definition: ezresponse.php:159
eZResponse\surveyID
surveyID()
Definition: ezresponse.php:150
eZResponse\complete
complete()
Definition: ezresponse.php:152
eZResponse\store
store()
Definition: ezresponse.php:50
eZResponse\$Submitted
$Submitted
Definition: ezresponse.php:165
eZResponse\$UserID
$UserID
Definition: ezresponse.php:167
eZResponse\setID
setID( $value)
Definition: ezresponse.php:156
eZResponse\numberOfResponses
static numberOfResponses( $surveyId="")
Definition: ezresponse.php:101
eZResponse\__construct
__construct( $id="-1")
Definition: ezresponse.php:9
eZResponse\userID
userID()
Definition: ezresponse.php:153
eZResponse\id
id()
Definition: ezresponse.php:149
eZResponse\submitted
submitted()
Definition: ezresponse.php:151
eZSurvey
Definition: ezsurvey.php:8
$ini
$ini
Definition: classes/admin/linklist.php:64
$id
$id
Definition: companytypelist.php:193
$db
$db
Definition: ezarticle/user/authorlist.php:53
$mail
$mail
Definition: ezbulkmail/admin/maillist.php:61
$ret
$ret
Definition: ezsitemanager/admin/filelist.php:88
$res
$res
Definition: ezstats/admin/cron.php:45
$question_array
$question_array
Definition: preview.php:88
$survey
if( $Page=="") if(isset( $OK)) if(isset( $NextPage)) if(isset( $PreviousPage)) $survey
Definition: preview.php:72
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.