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 questionss.
48 * @param object The Group object to which this survey question is associated.
49 * @param int The survey_id
51 function __construct(&$Group) {
53 if (!$Group || !is_object($Group)) {
54 $this->setError(_('No valid Group Object'));
57 if ($Group->isError()) {
58 $this->setError(_('Survey').':: '.$Group->getErrorMessage());
61 if (!$Group->usesSurvey()) {
62 $this->setError(sprintf(_('%s does not use the Survey tool'),
63 $Group->getPublicName()));
66 $this->Group =& $Group;
70 * getGroup - get the Group object this SurveyQuestionFactory is associated with.
72 * @return object The Group object.
74 function &getGroup() {
79 * getSurveyQuestion - get an array of Survey Question objects
80 * for this Group and Survey id if survey_id is given.
82 * @return array The array of Survey Question objects.
84 function &getSurveyQuestions() {
85 /* We alread have it */
86 if ($this->questions) {
87 return $this->questions;
90 $group_id = $this->Group->GetID();
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 $this->setError(_('No Survey Question is found').db_error());
102 while ($arr = db_fetch_array($result)) {
103 $this->questions[] = new SurveyQuestion($this->Group, $arr['question_id'], $arr);
105 db_free_result($result);
107 return $this->questions;
114 // c-file-style: "bsd"