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('common/include/Error.class');
34 require_once('common/survey/SurveyQuestion.class');
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) {
61 if (!$Group || !is_object($Group)) {
62 $this->setError(_('No valid Group Object'));
65 if ($Group->isError()) {
66 $this->setError(_('MISSINGTEXT:survey/survey:TEXTMISSING').':: '.$Group->getErrorMessage());
69 $this->Group =& $Group;
75 * getGroup - get the Group object this SurveyQuestionFactory is associated with.
77 * @return object The Group object.
79 function &getGroup() {
84 * getSurveyQuestion - get an array of Survey Question objects
85 * for this Group and Survey id if survey_id is given.
87 * @return array The array of Survey Question objects.
89 function &getSurveyQuestions() {
92 /* We alread have it */
93 if ($this->questions) {
94 return $this->questions;
97 $group_id = $this->Group->GetID();
98 $sql="SELECT survey_questions.*,survey_question_types.type ".
99 "FROM survey_questions,survey_question_types ".
100 "WHERE survey_question_types.id=survey_questions.question_type ".
101 "AND survey_questions.group_id='$group_id' ".
102 "ORDER BY survey_questions.question_id DESC";
104 $result = db_query ($sql);
107 $this->setError(_('No Survey Question is found').db_error());
110 while ($arr = db_fetch_array($result)) {
111 $this->questions[] = new SurveyQuestion($this->Group, $arr['question_id'], $arr);
113 db_free_result($result);
115 return $this->questions;
122 // c-file-style: "bsd"