5 * Copyright 2004, Sung Kim/GForge, LLC
6 * Copyright 2009, Roland Mas
7 * Copyright (C) 2012 Alain Peyrat - Alcatel-Lucent
9 * This file is part of FusionForge. FusionForge is free software;
10 * you can redistribute it and/or modify it under the terms of the
11 * GNU General Public License as published by the Free Software
12 * Foundation; either version 2 of the Licence, or (at your option)
15 * FusionForge 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 along
21 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 require_once $gfcommon.'include/Error.class.php';
26 require_once $gfcommon.'survey/SurveyQuestion.class.php';
28 class SurveyQuestionFactory extends Error {
40 * @var array questionss.
47 * @param object The Group object to which this survey question is associated.
48 * @param int The survey_id
50 function __construct(&$Group) {
52 if (!$Group || !is_object($Group)) {
53 $this->setError(_('No valid Group Object'));
56 if ($Group->isError()) {
57 $this->setError(_('Survey').':: '.$Group->getErrorMessage());
60 $this->Group =& $Group;
64 * getGroup - get the Group object this SurveyQuestionFactory is associated with.
66 * @return object The Group object.
68 function &getGroup() {
73 * getSurveyQuestion - get an array of Survey Question objects
74 * for this Group and Survey id if survey_id is given.
76 * @return array The array of Survey Question objects.
78 function &getSurveyQuestions() {
79 /* We alread have it */
80 if ($this->questions) {
81 return $this->questions;
84 $group_id = $this->Group->GetID();
85 $result = db_query_params ('SELECT survey_questions.*,survey_question_types.type
86 FROM survey_questions,survey_question_types
87 WHERE survey_question_types.id=survey_questions.question_type
88 AND survey_questions.group_id=$1
89 ORDER BY survey_questions.question_id ASC',
93 $this->setError(_('No Survey Question is found').db_error());
96 while ($arr = db_fetch_array($result)) {
97 $this->questions[] = new SurveyQuestion($this->Group, $arr['question_id'], $arr);
99 db_free_result($result);
101 return $this->questions;
108 // c-file-style: "bsd"