3 * Copyright (c) Xerox Corporation, Codendi Team, 2001-2009. All rights reserved
4 * Copyright 2013-2014, 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 $this->Widget('mysurveys');
42 $this->_survey_show = UserManager::instance()->getCurrentUser()->getPreference('my_surveys_show');
43 if($this->_survey_show === false) {
44 $this->_survey_show = 'AN';
45 UserManager::instance()->getCurrentUser()->setPreference('my_surveys_show', $this->_survey_show);
47 $user = session_get_user();
48 $projects = $user->getGroups();
49 sortProjectList($projects);
51 foreach ($projects as $p) {
52 if ($p->usesSurvey()) {
53 $sf = new SurveyFactory($p);
54 foreach ($sf->getSurveys() as $s) {
62 $html_my_surveys = '';
63 if (count ($projects) < 1) {
64 $html_my_surveys .= $HTML->warning_msg(_('There are no surveys in your projects.'));
67 $request =& HTTPRequest::instance();
68 $html_my_surveys .= '<table style="width:100%">';
69 foreach ($projects as $project) {
70 $group_id = $project->getID();
71 $surveyfacto = new SurveyFactory($project);
72 $surveys = $surveyfacto->getSurveys();
73 for ($i = 0; $i < count($surveys); $i++) {
74 if ($surveys[$i]->isActive()) {
75 switch ($this->_survey_show) {
77 if (!$surveys[$i]->isUserVote($user->getID())) {
82 if ($surveys[$i]->isUserVote($user->getID())) {
94 $surveys = array_values($surveys);
95 $vItemId = new Valid_UInt('hide_item_id');
97 if($request->valid($vItemId)) {
98 $hide_item_id = $request->get('hide_item_id');
100 $hide_item_id = null;
103 $vForum = new Valid_WhiteList('hide_survey', array(0, 1));
105 if($request->valid($vForum)) {
106 $hide_survey = $request->get('hide_survey');
111 list($hide_now,$count_diff,$hide_url) = my_hide_url('survey',$group_id,$hide_item_id,count($surveys),$hide_survey);
113 $html_hdr = '<tr class="boxitem"><td colspan="2">'.
114 $hide_url.util_make_link('/survey/?group_id='.$group_id, $project->getPublicName()).' ';
117 $count_new = max(0, $count_diff);
119 foreach ($surveys as $survey) {
122 $group_survey_id = $survey->getId();
123 $survey_title = $survey->getTitle();
125 <tr '. $HTML->boxGetAltRowStyle($i) .'><td style="width:99%">'.
126 ' - '.
127 util_make_link('/survey/survey.php?group_id='.$group_id.'&survey_id='.$group_survey_id, $survey_title).
132 $html_hdr .= '['.count($surveys).($count_new ? ", <b>".sprintf(_('%d new'), $count_new)."</b>]" : ']').'</td></tr>';
133 $html_my_surveys .= $html_hdr.$html;
135 $html_my_surveys .= '</table>';
137 $this->content = $html_my_surveys;
140 function getTitle() {
141 return _('Quick Survey');
144 function getContent() {
145 return $this->content;
148 function getDescription() {
149 return _('List the surveys in your projects.');
152 function hasPreferences() {
156 function getPreferences() {
157 $optionsArray = array('A','N','AN');
158 $textsArray = array();
159 $textsArray[] = _('answered [A]');
160 $textsArray[] = _('not yet answered [N]');
161 $textsArray[] = _('any status [AN]');
162 $prefs = _('Display surveys:').html_build_select_box_from_arrays($optionsArray, $textsArray, "show", $this->_survey_show);
166 function updatePreferences(&$request) {
167 $request->valid(new Valid_String('cancel'));
168 $vShow = new Valid_WhiteList('show', array('A', 'N', 'AN'));
170 if (!$request->exist('cancel')) {
171 if ($request->valid($vShow)) {
172 switch($request->get('show')) {
174 $this->_survey_show = 'A';
177 $this->_survey_show = 'N';
181 $this->_survey_show = 'AN';
184 UserManager::instance()->getCurrentUser()->setPreference('my_surveys_show', $this->_survey_show);