3 * Copyright (c) Xerox Corporation, Codendi Team, 2001-2009. All rights reserved
5 * This file is a part of Codendi.
7 * Codendi is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * Codendi is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Codendi. If not, see <http://www.gnu.org/licenses/>.
21 require_once('Widget.class.php');
22 //require_once('common/survey/SurveySingleton.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
33 class Widget_MySurveys extends Widget {
35 var $can_be_displayed;
37 function Widget_MySurveys() {
38 $this->Widget('mysurveys');
41 $user = session_get_user () ;
42 $projects = $user->getGroups() ;
43 sortProjectList ($projects) ;
45 foreach ($projects as $p) {
46 $sf = new SurveyFactory($p);
47 foreach ($sf->getSurveys() as $s) {
54 $html_my_surveys = '';
55 if (count ($projects) < 1) {
56 $html_my_surveys .= '<div class="warning">'. _("There are no surveys in your projects.") ."</div>\n";
59 $request =& HTTPRequest::instance();
60 $html_my_surveys .= '<table style="width:100%">';
62 foreach ($projects as $project) {
64 $group_id = $project->getID() ;
65 $surveyfacto = new SurveyFactory($project);
66 $surveys = $surveyfacto->getSurveys();
67 $vItemId = new Valid_UInt('hide_item_id');
69 if($request->valid($vItemId)) {
70 $hide_item_id = $request->get('hide_item_id');
75 $vForum = new Valid_WhiteList('hide_survey', array(0, 1));
77 if($request->valid($vForum)) {
78 $hide_survey = $request->get('hide_survey');
83 list($hide_now,$count_diff,$hide_url) = my_hide_url('survey',$group_id,$hide_item_id,count($surveys),$hide_survey);
85 $html_hdr = ($j ? '<tr class="boxitem"><td colspan="2">' : '').
86 $hide_url.'<a href="/survey/?group_id='.$group_id.'">'.
87 $project->getPublicName().'</a> ';
90 $count_new = max(0, $count_diff);
92 foreach ($surveys as $survey) {
95 $group_survey_id= $survey->getId();
96 $survey_title = $survey->getTitle();
97 $devsurvey_is_active = $survey->isActive();
98 if($devsurvey_is_active == 1 ) {
100 <tr '. $HTML->boxGetAltRowStyle($i) .'><td width="99%">'.
101 ' - <a href="/survey/survey.php?group_id='.$group_id.'&survey_id='.$group_survey_id.'">'.
102 $survey_title.'</a></td></tr>';
107 $html_hdr .= '['.count($surveys).($count_new ? ", <b>".sprintf(_('%d new'), $count_new)."</b>]" : ']').'</td></tr>';
108 $html_my_surveys .= $html_hdr.$html;
110 $html_my_surveys .= '</table>';
112 $this->content = $html_my_surveys;
115 function getTitle() {
116 return _("Quick Survey");
118 function getContent() {
119 return $this->content;
121 function getDescription() {
122 return _("List the surveys you have not answered.");