3 * Copyright (c) Xerox Corporation, Codendi Team, 2001-2009. All rights reserved
4 * Copyright 2013-2014,2021, Franck Villaume - TrivialDev
6 * This file is a part of Fusionforge.
8 * Fusionforge is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * Fusionforge is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with Fusionforge. If not, see <http://www.gnu.org/licenses/>.
22 require_once 'Widget.class.php';
23 require_once 'common/survey/SurveyFactory.class.php';
30 * This needs to be updated manually to display any given survey
31 * Default behavior: get first survey from group #1
34 class Widget_MySurveys extends Widget {
36 var $can_be_displayed;
39 function __construct() {
41 parent::__construct('mysurveys');
42 $user = session_get_user();
43 $this->_survey_show = $user->getPreference('my_surveys_show');
44 if($this->_survey_show === false) {
45 $this->_survey_show = 'AN';
46 $user->setPreference('my_surveys_show', $this->_survey_show);
48 $projects = $user->getGroups();
49 sortProjectList($projects);
51 foreach ($projects as $p) {
52 if ($p->usesSurvey()) {
53 $sf = new SurveyFactory($p);
54 $sfids = $sf->getSurveysIds();
62 $html_my_surveys = '';
63 if (count ($projects) < 1) {
64 $html_my_surveys .= $HTML->warning_msg(_('There are no surveys in your projects.'));
67 $html_my_surveys .= $HTML->listTableTop();
68 foreach ($projects as $project) {
69 $group_id = $project->getID();
70 $surveyfacto = new SurveyFactory($project);
71 $surveys = $surveyfacto->getSurveys();
72 for ($i = 0; $i < count($surveys); $i++) {
73 if ($surveys[$i]->isActive()) {
74 switch ($this->_survey_show) {
76 if (!$surveys[$i]->isUserVote($user->getID())) {
81 if ($surveys[$i]->isUserVote($user->getID())) {
93 $surveys = array_values($surveys);
94 $hide_item_id = getIntFromRequest('hide_item_id', 0);
95 $hide_survey = getIntFromRequest('hide_survey', 0);
97 list($hide_now,$count_diff,$hide_url) = my_hide_url('survey',$group_id,$hide_item_id,count($surveys),$hide_survey);
99 $html_hdr = '<tr class="boxitem"><td colspan="2">'.
100 $hide_url.util_make_link('/survey/?group_id='.$group_id, $project->getPublicName()).' ';
103 $count_new = max(0, $count_diff);
105 foreach ($surveys as $survey) {
108 $group_survey_id = $survey->getID();
109 $survey_title = $survey->getTitle();
111 <tr><td style="width:99%">'.
112 ' - '.
113 util_make_link('/survey/survey.php?group_id='.$group_id.'&survey_id='.$group_survey_id, $survey_title).
118 $html_hdr .= '['.count($surveys).($count_new ? ", <b>".sprintf(_('%d new'), $count_new)."</b>]" : ']').'</td></tr>';
119 $html_my_surveys .= $html_hdr.$html;
121 $html_my_surveys .= $HTML->listTableBottom();
123 $this->content = $html_my_surveys;
126 function getTitle() {
127 return _('Quick Survey');
130 function getContent() {
131 return $this->content;
134 function getDescription() {
135 return _('List the surveys in your projects.');
138 function hasPreferences() {
142 function getPreferences() {
143 $optionsArray = array('A','N','AN');
144 $textsArray = array();
145 $textsArray[] = _('answered [A]');
146 $textsArray[] = _('not yet answered [N]');
147 $textsArray[] = _('any status [AN]');
148 return _('Display surveys:').html_build_select_box_from_arrays($optionsArray, $textsArray, "show", $this->_survey_show);
151 function updatePreferences() {
152 $cancel = getStringFromRequest('cancel');
153 if (strlen($cancel) > 0) {
154 $show = getStringFromRequest('show');
157 $this->_survey_show = 'A';
160 $this->_survey_show = 'N';
164 $this->_survey_show = 'AN';
167 $user = session_get_user();
168 $user->setPreference('my_surveys_show', $this->_survey_show);