5 * Copyright 2004, Sung Kim/GForge, LLC
6 * Copyright 2009, Roland Mas
7 * Copyright (C) 2012 Alain Peyrat - Alcatel-Lucent
8 * Copyright 2013, Franck Villaume - TrivialDev
10 * This file is part of FusionForge. FusionForge is free software;
11 * you can redistribute it and/or modify it under the terms of the
12 * GNU General Public License as published by the Free Software
13 * Foundation; either version 2 of the Licence, or (at your option)
16 * FusionForge is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License along
22 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 require_once $gfcommon.'include/Error.class.php';
27 require_once $gfcommon.'survey/SurveyQuestion.class.php';
29 class SurveyQuestionFactory extends Error {
41 * @var array questions
48 * @param object $Group The Group object to which this survey question is associated.
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 if (!$Group->usesSurvey()) {
61 $this->setError(sprintf(_('%s does not use the Survey tool'),
62 $Group->getPublicName()));
65 $this->Group =& $Group;
69 * getGroup - get the Group object this SurveyQuestionFactory is associated with.
71 * @return object The Group object.
73 function &getGroup() {
78 * getSurveyQuestion - get an array of Survey Question objects
79 * for this Group and Survey id if survey_id is given.
81 * @return array The array of Survey Question objects.
83 function &getSurveyQuestions() {
84 /* We already have it */
85 if ($this->questions) {
86 return $this->questions;
89 $group_id = $this->Group->GetID();
90 $this->questions = array();
91 $result = db_query_params ('SELECT survey_questions.*,survey_question_types.type
92 FROM survey_questions,survey_question_types
93 WHERE survey_question_types.id=survey_questions.question_type
94 AND survey_questions.group_id=$1
95 ORDER BY survey_questions.question_id ASC',
99 while ($arr = db_fetch_array($result)) {
100 $this->questions[] = new SurveyQuestion($this->Group, $arr['question_id'], $arr);
102 db_free_result($result);
104 return $this->questions;
111 // c-file-style: "bsd"