3 * Copyright (c) Xerox Corporation, Codendi Team, 2001-2009. All rights reserved
4 * Copyright 2013, 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/SurveySingleton.class.php');
24 require_once 'common/survey/SurveyFactory.class.php';
31 * This needs to be updated manually to display any given survey
32 * Default behavior: get first survey from group #1
35 class Widget_MySurveys extends Widget {
37 var $can_be_displayed;
39 function __construct() {
40 $this->Widget('mysurveys');
43 $user = session_get_user () ;
44 $projects = $user->getGroups() ;
45 sortProjectList ($projects) ;
47 foreach ($projects as $p) {
48 if ($p->usesSurvey()) {
49 $sf = new SurveyFactory($p);
50 foreach ($sf->getSurveys() as $s) {
58 $html_my_surveys = '';
59 if (count ($projects) < 1) {
60 $html_my_surveys .= '<div class="warning">'. _("There are no surveys in your projects.") ."</div>\n";
63 $request =& HTTPRequest::instance();
64 $html_my_surveys .= '<table style="width:100%">';
65 foreach ($projects as $project) {
66 $group_id = $project->getID() ;
67 $surveyfacto = new SurveyFactory($project);
68 $surveys = $surveyfacto->getSurveys();
69 $vItemId = new Valid_UInt('hide_item_id');
71 if($request->valid($vItemId)) {
72 $hide_item_id = $request->get('hide_item_id');
77 $vForum = new Valid_WhiteList('hide_survey', array(0, 1));
79 if($request->valid($vForum)) {
80 $hide_survey = $request->get('hide_survey');
85 list($hide_now,$count_diff,$hide_url) = my_hide_url('survey',$group_id,$hide_item_id,count($surveys),$hide_survey);
87 $html_hdr = '<tr class="boxitem"><td colspan="2">'.
88 $hide_url.'<a href="/survey/?group_id='.$group_id.'">'.
89 $project->getPublicName().'</a> ';
92 $count_new = max(0, $count_diff);
94 foreach ($surveys as $survey) {
97 $group_survey_id= $survey->getId();
98 $survey_title = $survey->getTitle();
99 $devsurvey_is_active = $survey->isActive();
100 if($devsurvey_is_active == 1 ) {
102 <tr '. $HTML->boxGetAltRowStyle($i) .'><td width="99%">'.
103 ' - <a href="/survey/survey.php?group_id='.$group_id.'&survey_id='.$group_survey_id.'">'.
104 $survey_title.'</a></td></tr>';
109 $html_hdr .= '['.count($surveys).($count_new ? ", <b>".sprintf(_('%d new'), $count_new)."</b>]" : ']').'</td></tr>';
110 $html_my_surveys .= $html_hdr.$html;
112 $html_my_surveys .= '</table>';
114 $this->content = $html_my_surveys;
117 function getTitle() {
118 return _("Quick Survey");
120 function getContent() {
121 return $this->content;
123 function getDescription() {
124 return _("List the surveys you have not answered.");