3 * GForge Survey Facility: Get Survey Questions
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
28 Survery Question Factory
33 require_once $gfcommon.'include/Error.class.php';
34 require_once $gfcommon.'survey/SurveyQuestion.class.php';
36 class SurveyQuestionFactory extends Error {
48 * @var array questionss.
55 * @param object The Group object to which this survey question is associated.
56 * @param int The survey_id
58 function SurveyQuestionFactory(&$Group) {
60 if (!$Group || !is_object($Group)) {
61 $this->setError(_('No valid Group Object'));
64 if ($Group->isError()) {
65 $this->setError(_('Survey').':: '.$Group->getErrorMessage());
68 $this->Group =& $Group;
74 * getGroup - get the Group object this SurveyQuestionFactory is associated with.
76 * @return object The Group object.
78 function &getGroup() {
83 * getSurveyQuestion - get an array of Survey Question objects
84 * for this Group and Survey id if survey_id is given.
86 * @return array The array of Survey Question objects.
88 function &getSurveyQuestions() {
89 /* We alread have it */
90 if ($this->questions) {
91 return $this->questions;
94 $group_id = $this->Group->GetID();
95 $sql="SELECT survey_questions.*,survey_question_types.type ".
96 "FROM survey_questions,survey_question_types ".
97 "WHERE survey_question_types.id=survey_questions.question_type ".
98 "AND survey_questions.group_id='$group_id' ".
99 "ORDER BY survey_questions.question_id DESC";
101 $result = db_query ($sql);
104 $this->setError(_('No Survey Question is found').db_error());
107 while ($arr = db_fetch_array($result)) {
108 $this->questions[] = new SurveyQuestion($this->Group, $arr['question_id'], $arr);
110 db_free_result($result);
112 return $this->questions;
119 // c-file-style: "bsd"