File Coverage

blib/lib/Labyrinth/Plugin/Survey/YAPC.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::YAPC;
2              
3 2     2   5899 use warnings;
  2         5  
  2         71  
4 2     2   11 use strict;
  2         5  
  2         74  
5              
6 2     2   13 use vars qw($VERSION);
  2         5  
  2         130  
7             $VERSION = '0.06';
8              
9             =head1 NAME
10              
11             Labyrinth::Plugin::Survey::YAPC - YAPC Surveys' Conference Survey management plugin for Labyrinth framework
12              
13             =head1 DESCRIPTION
14              
15             Provides all the main conference 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         4  
  2         270  
23              
24             use Labyrinth::Audit;
25             use Labyrinth::DBUtils;
26             use Labyrinth::DTUtils;
27             use Labyrinth::MLUtils;
28             use Labyrinth::Session;
29             use Labyrinth::Support;
30             use Labyrinth::Users;
31             use Labyrinth::Variables;
32              
33             # -------------------------------------
34             # The Subs
35              
36             =head1 PUBLIC INTERFACE METHODS
37              
38             =over 4
39              
40             =item Check
41              
42             Checks whether the user has signed in, if they have, have they already
43             submitted a response to the main conference survey?
44              
45             If not, then load the survey questions.
46              
47             =item Save
48              
49             Saves the question responses from the given survey.
50              
51             =back
52              
53             =cut
54              
55             sub Check {
56             unless($tvars{loggedin}) {
57             LogDebug("YAPCCheck: user session timed out");
58             $tvars{errcode} = 'FAIL';
59             return;
60             }
61              
62             my @rows = $dbi->GetQuery('hash','SurveyCheck',$tvars{loginid});
63             unless(@rows) {
64             # force failure
65             LogDebug("SurveyCheck: look up failed");
66             $tvars{errcode} = 'FAIL';
67             return;
68             }
69              
70             my $self = shift;
71             $tvars{data}{submitted} = 1 if($rows[0]->{completed} && $rows[0]->{completed} > 0);
72             $tvars{data}{code} = $cgiparams{code};
73             $tvars{survey} = $self->LoadSurvey($settings{'survey'});
74             }
75              
76             sub Save {
77             return if(!$tvars{loggedin});
78             return if($tvars{data}{submitted});
79              
80             my $self = shift;
81              
82             # reload survey with valid inputs
83             $tvars{survey} = $self->LoadSurvey($settings{'survey'});
84             return unless($tvars{survey});
85              
86             my ($all,$man,$collate,$qu) = $self->AnalyseSurvey();
87              
88             # ensure we have a valid survey
89             return if FieldCheck($all,$man);
90              
91             # now save the survey results
92             my $taken = 0;
93             my $idcode = $self->CreateID();
94             for my $name (@$all) {
95             my $c = $collate->{$name} ? $idcode : '';
96             if($qu->{max}) {
97             $cgiparams{$name} = $qu->{max} if($cgiparams{$name} eq 'ALL');
98             $cgiparams{$name} = 0 if($cgiparams{$name} =~ /\D/);
99             $cgiparams{$name} = $qu->{max} if($cgiparams{$name} > $qu->{max});
100             }
101             if($qu->{type} eq 'count') {
102             $cgiparams{$name} = 0 if($cgiparams{$name} =~ /\D/);
103             }
104             $dbi->DoQuery('SaveSurvey',$name,$cgiparams{$name},$c) if($cgiparams{$name});
105             $taken = 1;
106             }
107              
108             if($taken) {
109             my $completed = $self->CreateID();
110             $dbi->DoQuery('SaveSurveyIndex',$completed,$tvars{loginid});
111             $tvars{data}->{thanks} = 1;
112             } else {
113             $tvars{data}->{thanks} = 2;
114             }
115             }
116              
117             1;
118              
119             __END__