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
9 * http://fusionforge.org
11 * This file is part of FusionForge. FusionForge is free software;
12 * you can redistribute it and/or modify it under the terms of the
13 * GNU General Public License as published by the Free Software
14 * Foundation; either version 2 of the Licence, or (at your option)
17 * FusionForge is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License along
23 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 require_once $gfcommon.'include/Error.class.php';
28 require_once $gfcommon.'survey/Survey.class.php';
30 class SurveyFactory extends Error {
49 * @param object The Group object to which this survey is associated.
50 * @param int The survey_id
52 function __construct(&$Group) {
54 if (!$Group || !is_object($Group)) {
58 if ($Group->isError()) {
59 $this->setError(_('Survey').':: '.$Group->getErrorMessage());
62 if (!$Group->usesSurvey()) {
63 $this->setError(sprintf(_('%s does not use the Survey tool'),
64 $Group->getPublicName()));
67 $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 &getSurveys() {
86 /* We alread have it */
88 return $this->surveys;
90 $result = db_query_params('SELECT * FROM surveys WHERE group_id=$1 ORDER BY survey_id DESC',
91 array ($this->Group->getID()));
94 $this->setError(_('No Survey is found').' '.db_error());
97 $this->surveys = array();
98 while ($arr = db_fetch_array($result)) {
99 $this->surveys[] = new Survey($this->Group, $arr['survey_id'], $arr);
101 db_free_result($result);
103 return $this->surveys;
110 // c-file-style: "bsd"