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/FFError.class.php';
27 require_once $gfcommon.'survey/SurveyQuestion.class.php';
29 class SurveyQuestionFactory extends FFError {
41 * @var array questions
46 * @param object $Group The Group object to which this survey question is associated.
48 function __construct(&$Group) {
49 parent::__construct();
50 if (!$Group || !is_object($Group)) {
51 $this->setError(_('Invalid Project'));
54 if ($Group->isError()) {
55 $this->setError(_('Survey')._(': ').$Group->getErrorMessage());
58 if (!$Group->usesSurvey()) {
59 $this->setError(sprintf(_('%s does not use the Survey tool'),
60 $Group->getPublicName()));
63 $this->Group =& $Group;
67 * getGroup - get the Group object this SurveyQuestionFactory is associated with.
69 * @return object The Group object.
71 function &getGroup() {
76 * getSurveyQuestion - get an array of Survey Question objects
77 * for this Group and Survey id if survey_id is given.
79 * @return array The array of Survey Question objects.
81 function &getSurveyQuestions() {
82 /* We already have it */
83 if ($this->questions) {
84 return $this->questions;
87 $group_id = $this->Group->GetID();
88 $this->questions = array();
89 $result = db_query_params ('SELECT survey_questions.*,survey_question_types.type
90 FROM survey_questions,survey_question_types
91 WHERE survey_question_types.id=survey_questions.question_type
92 AND survey_questions.group_id=$1
93 ORDER BY survey_questions.question_id ASC',
97 while ($arr = db_fetch_array($result)) {
98 $this->questions[] = new SurveyQuestion($this->Group, $arr['question_id'], $arr);
100 db_free_result($result);
102 return $this->questions;
109 // c-file-style: "bsd"