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
34 class Widget_MySurveys extends Widget {
36 var $can_be_displayed;
38 function __construct() {
39 $this->Widget('mysurveys');
42 $user = session_get_user () ;
43 $projects = $user->getGroups() ;
44 sortProjectList ($projects) ;
46 foreach ($projects as $p) {
47 $sf = new SurveyFactory($p);
48 foreach ($sf->getSurveys() as $s) {
55 $html_my_surveys = '';
56 if (count ($projects) < 1) {
57 $html_my_surveys .= '<div class="warning">'. _("There are no surveys in your projects.") ."</div>\n";
60 $request =& HTTPRequest::instance();
61 $html_my_surveys .= '<table style="width:100%">';
63 foreach ($projects as $project) {
65 $group_id = $project->getID() ;
66 $surveyfacto = new SurveyFactory($project);
67 $surveys = $surveyfacto->getSurveys();
68 $vItemId = new Valid_UInt('hide_item_id');
70 if($request->valid($vItemId)) {
71 $hide_item_id = $request->get('hide_item_id');
76 $vForum = new Valid_WhiteList('hide_survey', array(0, 1));
78 if($request->valid($vForum)) {
79 $hide_survey = $request->get('hide_survey');
84 list($hide_now,$count_diff,$hide_url) = my_hide_url('survey',$group_id,$hide_item_id,count($surveys),$hide_survey);
86 $html_hdr = ($j ? '<tr class="boxitem"><td colspan="2">' : '').
87 $hide_url.'<a href="/survey/?group_id='.$group_id.'">'.
88 $project->getPublicName().'</a> ';
91 $count_new = max(0, $count_diff);
93 foreach ($surveys as $survey) {
96 $group_survey_id= $survey->getId();
97 $survey_title = $survey->getTitle();
98 $devsurvey_is_active = $survey->isActive();
99 if($devsurvey_is_active == 1 ) {
101 <tr '. $HTML->boxGetAltRowStyle($i) .'><td width="99%">'.
102 ' - <a href="/survey/survey.php?group_id='.$group_id.'&survey_id='.$group_survey_id.'">'.
103 $survey_title.'</a></td></tr>';
108 $html_hdr .= '['.count($surveys).($count_new ? ", <b>".sprintf(_('%d new'), $count_new)."</b>]" : ']').'</td></tr>';
109 $html_my_surveys .= $html_hdr.$html;
111 $html_my_surveys .= '</table>';
113 $this->content = $html_my_surveys;
116 function getTitle() {
117 return _("Quick Survey");
119 function getContent() {
120 return $this->content;
122 function getDescription() {
123 return _("List the surveys you have not answered.");