3 * GForge Survey Response Facility
5 * Copyright 2004 GForge, LLC
8 * This file is part of GForge.
10 * GForge is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * GForge is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with GForge; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 require_once $gfcommon.'include/Error.class.php';
33 class SurveyResponse extends Error {
35 * Associative array of data from db.
37 * @var array $data_array.
46 var $Group; //group object
51 * @param object The Group object to which this Survey Response is associated.
52 * @param int The questtion_id.
53 * @param array The associative array of data.
54 * @return boolean success.
56 function SurveyResponse(&$Group, $arr=false) {
58 if (!$Group || !is_object($Group)) {
59 $this->setError(sprintf(_('%1$s:: No Valid Group Object'), 'Survey Question'));
62 if ($Group->isError()) {
63 $this->setError('Survey:: '.$Group->getErrorMessage());
66 $this->Group =& $Group;
68 if ($arr && is_array($arr)) {
69 $this->data_array =& $arr;
75 * create - use this function to create a survey response
77 * @param string The question
78 * @param int The question type
79 * 1: Radio Buttons 1-5
81 * 3: Radio Buttons Yes/No
85 * @return boolean success.
87 function create($user_id, $survey_id, $question_id, $response) {
88 $group_id = $this->Group->GetID();
91 $sql="INSERT INTO survey_responses (user_id,group_id,survey_id,question_id,response,post_date) ".
92 "VALUES ('". $user_id. "','" . addslashes($group_id) . "','" .
93 addslashes($survey_id) . "','" . addslashes($question_id) . "','".
94 htmlspecialchars($response) . "','$now')";
97 $this->setError(_('Error').db_error());
104 * getGroup - get the Group object this SurveyResponse is associated with.
106 * @return object The Group object.
108 function &getGroup() {
113 * getUserID - Get the user id of this Survey response
115 * @return int The user_id
117 function getUserID() {
118 return $this->data_array['user_id'];
122 * getGroup - Get the group id of this Survey response
124 * @return int The group_id
126 function getGroupID() {
127 return $this->data_array['group_id'];
131 * getSurveyID - Get the survey id of this Survey response
133 * @return int The survey_id
135 function getSurveyID() {
136 return $this->data_array['survey_id'];
141 * getQuestionID - Get the question id of this Survey response
143 * @return int The question_id
145 function getQuestionID() {
146 return $this->data_array['question_id'];
150 * getUserID - Get the response of this Survey response
152 * @return int The response
154 function getResponse() {
155 return $this->data_array['response'];
160 * getPostDate - Get the post date of this Survey response
162 * @return int The post date
164 function getPostDate() {
165 return $this->data_array['post_date'];
171 // c-file-style: "bsd"