5 * Copyright 2004, Sung Kim/GForge, LLC
6 * Copyright 2009, Roland Mas
7 * Copyright 2013, Franck Villaume - TrivialDev
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 SurveyQuestionFactory(&$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 if (!$Group->usesSurvey()) {
61 $this->setError(sprintf(_('%s does not use the Survey tool'),
62 $Group->getPublicName()));
65 $this->Group =& $Group;
71 * getGroup - get the Group object this SurveyQuestionFactory is associated with.
73 * @return object The Group object.
75 function &getGroup() {
80 * getSurveyQuestion - get an array of Survey Question objects
81 * for this Group and Survey id if survey_id is given.
83 * @return array The array of Survey Question objects.
85 function &getSurveyQuestions() {
86 /* We alread have it */
87 if ($this->questions) {
88 return $this->questions;
91 $group_id = $this->Group->GetID();
92 $this->questions = array();
93 $result = db_query_params ('SELECT survey_questions.*,survey_question_types.type
94 FROM survey_questions,survey_question_types
95 WHERE survey_question_types.id=survey_questions.question_type
96 AND survey_questions.group_id=$1
97 ORDER BY survey_questions.question_id ASC',
101 while ($arr = db_fetch_array($result)) {
102 $this->questions[] = new SurveyQuestion($this->Group, $arr['question_id'], $arr);
104 db_free_result($result);
106 return $this->questions;
113 // c-file-style: "bsd"