File Coverage

blib/lib/Labyrinth/Plugin/Survey/Talk.pm
Criterion Covered Total %
statement 12 12 100.0
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 16 16 100.0


line stmt bran cond sub pod time code
1             package Labyrinth::Plugin::Survey::Talk;
2              
3 2     2   5001 use warnings;
  2         2  
  2         71  
4 2     2   11 use strict;
  2         2  
  2         71  
5              
6 2     2   10 use vars qw($VERSION);
  2         3  
  2         122  
7             $VERSION = '0.08';
8              
9             =head1 NAME
10              
11             Labyrinth::Plugin::Survey::Talk - YAPC Surveys' Talk management plugin for Labyrinth framework
12              
13             =head1 DESCRIPTION
14              
15             Provides all the talk evaluation survey handling functionality for YAPC Surveys.
16              
17             =cut
18              
19             # -------------------------------------
20             # Library Modules
21              
22 2     2   10 use base qw(Labyrinth::Plugin::Survey);
  2         2  
  2         193  
23              
24             use Labyrinth::Audit;
25             use Labyrinth::DBUtils;
26             use Labyrinth::DTUtils;
27             use Labyrinth::MLUtils;
28             use Labyrinth::Support;
29             use Labyrinth::Users;
30             use Labyrinth::Variables;
31              
32             # -------------------------------------
33             # Variables
34              
35             # type: 0 = optional, 1 = mandatory
36             # html: 0 = none, 1 = text, 2 = textarea
37              
38             my %fields = (
39             courseid => { type => 1, html => 0 },
40             tutor => { type => 1, html => 1 },
41             course => { type => 1, html => 1 },
42             );
43              
44             my (@mandatory,@allfields);
45             for(keys %fields) {
46             push @mandatory, $_ if($fields{$_}->{type});
47             push @allfields, $_;
48             }
49              
50             my $LEVEL = ADMIN;
51              
52             # -------------------------------------
53             # The Subs
54              
55             =head1 PUBLIC INTERFACE METHODS
56              
57             =over 4
58              
59             =item Check
60              
61             Checks whether the user has signed in, if they have, have they already
62             submitted a response to this talk evaluation survey?
63              
64             If not, then load the evaluation questions.
65              
66             =item Save
67              
68             Saves the question responses from the given talk evaluation.
69              
70             =back
71              
72             =cut
73              
74             sub Check {
75             my $self = shift;
76              
77             unless($tvars{loggedin}) {
78             LogDebug("TalkCheck: user session timed out");
79             $tvars{errcode} = 'FAIL';
80             return;
81             }
82              
83             unless($cgiparams{courseid}) {
84             LogDebug("TalkCheck: missing courseid");
85             $tvars{errcode} = 'FAIL';
86             return;
87             }
88              
89             my @rows = $dbi->GetQuery('hash','TalkCheck',$tvars{loginid},$cgiparams{courseid});
90             unless(@rows) {
91             # force failure
92             LogDebug("TalkCheck: course not found");
93             $tvars{errcode} = 'FAIL';
94             return;
95             }
96              
97             $tvars{course}{tutor} = $self->TutorFixes($rows[0]->{tutor});
98             $tvars{course}{title} = $self->CourseFixes($rows[0]->{course});
99              
100             if(@rows && $rows[0]->{completed} && $rows[0]->{completed} > 0) {
101             # force failure
102             LogDebug("TalkCheck: user already submitted assessment for this talk");
103             $tvars{data}->{submitted} = 1;
104             return;
105             }
106              
107             $tvars{data}{userid} = $tvars{loginid};
108             $tvars{data}{courseid} = $cgiparams{courseid};
109              
110             $tvars{survey} = $self->LoadSurvey($settings{'evaluate'});
111             }
112              
113             sub Save {
114             return if($tvars{data}->{submitted});
115              
116             my $self = shift;
117              
118             # reload survey with valid inputs
119             $tvars{survey} = $self->LoadSurvey($settings{'evaluate'});
120             return unless($tvars{survey});
121              
122             my ($all,$man,$collate,$qu) = $self->AnalyseSurvey();
123              
124             # ensure we have a valid survey
125             return if FieldCheck($all,$man);
126              
127             # now save the survey results
128             my $taken = 0;
129             my $idcode = $self->CreateID();
130             for my $name (@$all) {
131             my $c = $idcode if($collate->{$name});
132              
133             if($qu->{$name}{tag}) {
134             if($cgiparams{$name}) {
135             $cgiparams{$name} = sprintf "%s <%s>", $tvars{user}{name}, $tvars{user}{email};
136             }
137             }
138              
139             $dbi->DoQuery('SaveEvaluation',$cgiparams{courseid},$name,$cgiparams{$name},$c) if($cgiparams{$name});
140             $taken = 1;
141             }
142              
143             if($taken) {
144             my $completed = $self->CreateID();
145             $dbi->DoQuery('SaveTalkIndex',$completed,$cgiparams{courseid},$tvars{loginid});
146             $tvars{data}->{thanks} = 1;
147             } else {
148             $tvars{data}->{thanks} = 2;
149             }
150             }
151              
152             =head1 ADMIN INTERFACE METHODS
153              
154             =over 4
155              
156             =item Admin
157              
158             Provides talk and course management for the administrator.
159              
160             =item Update
161              
162             Updates type setting for the given course or talk.
163              
164             There are 4 settings for each course or talk:
165              
166             =over 4
167              
168             =item * Course
169              
170             =item * Talk
171              
172             =item * Lightning Talk
173              
174             =item * Ignore
175              
176             =back
177              
178             =item Edit
179              
180             Edit details for the given course or talk.
181              
182             =item AdminSave
183              
184             Save edits for the given course or talk.
185              
186             =item TalkTypeSelect
187              
188             Provides dropdown code for the list of talk types.
189              
190             =back
191              
192             =cut
193              
194             sub Admin {
195             my (@rows_lt,@rows_rt,@rows_mc,@rows_ig);
196             my @lt = ({id => -1, value => 'Ignore'},{id => 0, value => 'Course'}, {id => 1, value => 'Regular Talk'});
197             my @rows = $dbi->GetQuery('hash','AdminTalkList');
198             for my $talk (@rows) {
199             next unless($talk->{course} =~ /Lightning Talk/);
200             push @lt, {id => $talk->{datetime}, value => $talk->{course}};
201             }
202             for my $talk (@rows) {
203             my $type = $talk->{talk};
204             $type = $talk->{datetime} if($talk->{talk} == 2);
205             $talk->{ddtype} = TalkTypeSelect($type,$talk->{courseid},@lt);
206              
207             $tvars{count1}++ if($talk->{talk} == 2);
208             $tvars{count2}++ if($talk->{talk} == 1);
209             $tvars{count3}++ if($talk->{talk} == 0);
210             $tvars{count4}++ if($talk->{talk} == -1);
211              
212             push @rows_lt, $talk if($talk->{talk} == 2);
213             push @rows_rt, $talk if($talk->{talk} == 1);
214             push @rows_mc, $talk if($talk->{talk} == 0);
215             push @rows_ig, $talk if($talk->{talk} == -1);
216             }
217              
218             $tvars{talks} = \@rows if(@rows);
219             $tvars{talks_lt} = \@rows_lt if(@rows_lt);
220             $tvars{talks_rt} = \@rows_rt if(@rows_rt);
221             $tvars{talks_mc} = \@rows_mc if(@rows_mc);
222             $tvars{talks_ig} = \@rows_ig if(@rows_ig);
223             }
224              
225             sub Update {
226             my @rows = $dbi->GetQuery('hash','AdminTalkList');
227             for my $talk (@rows) {
228             my $type = $cgiparams{'TYPE'.$talk->{courseid}};
229             next if($talk->{talk} == $type);
230             next if($talk->{talk} == 2 && $talk->{datetime} == $type);
231              
232             if($type < 2) {
233             $talk->{talk} = $type;
234             } else {
235             $talk->{talk} = 2;
236             $talk->{datetime} = $type;
237             }
238              
239             # do query
240             $dbi->DoQuery('SaveCourse',$talk->{course},$talk->{tutor},$talk->{room},$talk->{datetime},$talk->{talk},$talk->{courseid});
241             }
242             }
243              
244             sub Edit {
245             my $self = shift;
246             return unless $cgiparams{'courseid'};
247             my @rows = $dbi->GetQuery('hash','GetTalkByID',$cgiparams{courseid});
248             return unless(@rows);
249              
250             my @lt = ({id => 0, value => 'Course'}, {id => 1, value => 'Regular Talk'});
251             my @lts = $dbi->GetQuery('hash','AdminTalkList');
252             for my $talk (@lts) {
253             next unless($talk->{course} =~ /Lightning Talk/);
254             push @lt, {id => $talk->{datetime}, value => $talk->{course}};
255             }
256              
257             my $type = $rows[0]->{talk};
258             $type = $rows[0]->{datetime} if($rows[0]->{talk} == 2);
259              
260             $tvars{data}{courseid} = $rows[0]->{courseid};
261             $tvars{data}{tutor} = $self->TutorFixes($rows[0]->{tutor});
262             $tvars{data}{course} = $self->CourseFixes($rows[0]->{course});
263             $tvars{data}{ddtype} = TalkTypeSelect($type,$rows[0]->{courseid},@lt);
264             }
265              
266             sub AdminSave {
267             return unless $cgiparams{'courseid'};
268             return unless AuthorCheck('GetTalkByID','courseid',$LEVEL);
269              
270             for(keys %fields) {
271             if($fields{$_}->{html} == 1) { $cgiparams{$_} = CleanHTML($cgiparams{$_}) }
272             elsif($fields{$_}->{html} == 2) { $cgiparams{$_} = CleanTags($cgiparams{$_}) }
273             elsif($fields{$_}->{html} == 3) { $cgiparams{$_} = CleanLink($cgiparams{$_}) }
274             }
275              
276             return if FieldCheck(\@allfields,\@mandatory);
277              
278             my $datetime = $tvars{data}{datetime};
279             my $talk = $tvars{data}{talk};
280             my $type = $cgiparams{'TYPE' . $cgiparams{'courseid'}};
281              
282             if($type < 2) {
283             $talk = $type;
284             } else {
285             $talk = 2;
286             $datetime = $type;
287             }
288              
289             $cgiparams{'datetime'} = $datetime;
290             $cgiparams{'talk'} = $talk;
291              
292             $dbi->DoQuery('SaveTalk', $cgiparams{'tutor'}, $cgiparams{'course'}, $cgiparams{'datetime'},
293             $cgiparams{'talk'}, $cgiparams{'courseid'});
294              
295             }
296              
297             sub TalkTypeSelect {
298             my ($opt,$id,@list) = @_;
299             DropDownRows($opt,'TYPE'.$id,'id','value',@list);
300             }
301              
302              
303             1;
304              
305             __END__