File Coverage

blib/lib/Labyrinth/Plugin/Survey/Course.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::Course;
2              
3 2     2   6437 use warnings;
  2         6  
  2         75  
4 2     2   11 use strict;
  2         3  
  2         72  
5              
6 2     2   10 use vars qw($VERSION);
  2         4  
  2         119  
7             $VERSION = '0.05';
8              
9             =head1 NAME
10              
11             Labyrinth::Plugin::Survey::Course - YAPC Surveys' Course management plugin for Labyrinth framework
12              
13             =head1 DESCRIPTION
14              
15             Provides all the course evaluation survey handling functionality for YAPC Surveys.
16              
17             =cut
18              
19             # -------------------------------------
20             # Library Modules
21              
22 2     2   21 use base qw(Labyrinth::Plugin::Survey);
  2         3  
  2         267  
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             # The Subs
34              
35             =head1 PUBLIC INTERFACE METHODS
36              
37             =over 4
38              
39             =item Check
40              
41             Checks whether the user has signed in, if they have, have they already
42             submitted a response to this course evaluation survey?
43              
44             If not, then load the evaluation questions.
45              
46             =item Save
47              
48             Saves the question responses from the given course evaluation.
49              
50             =back
51              
52             =cut
53              
54             sub Check {
55             my $self = shift;
56              
57             unless($tvars{loggedin}) {
58             LogDebug("CourseCheck: user session timed out");
59             $tvars{errcode} = 'FAIL';
60             return;
61             }
62              
63             unless($cgiparams{courseid}) {
64             LogDebug("CourseCheck: missing courseid");
65             $tvars{errcode} = 'FAIL';
66             return;
67             }
68              
69             my @rows = $dbi->GetQuery('hash','CourseCheck',$cgiparams{courseid},$tvars{loginid});
70             unless(@rows) {
71             # force failure
72             LogDebug("CourseCheck: course look up failed");
73             $tvars{errcode} = 'FAIL';
74             return;
75             }
76              
77             $tvars{course}{tutor} = $self->TutorFixes($rows[0]->{tutor});
78             $tvars{course}{title} = $self->CourseFixes($rows[0]->{course});
79              
80             if($rows[0]->{userid} != $tvars{loginid}) {
81             # force failure
82             LogDebug("CourseCheck: userid look up failed");
83             $tvars{errcode} = 'FAIL';
84             return;
85             }
86              
87             $tvars{data}{userid} = $rows[0]->{userid};
88             $tvars{data}{courseid} = $cgiparams{courseid};
89             $tvars{data}{submitted} = 1 if($rows[0]->{completed} && $rows[0]->{completed} > 0);
90              
91             $tvars{survey} = $self->LoadSurvey($settings{'evaluate'});
92             }
93              
94             sub Save {
95             return if($tvars{data}->{submitted});
96              
97             my $self = shift;
98              
99             # reload survey with valid inputs
100             $tvars{survey} = $self->LoadSurvey($settings{'evaluate'});
101             return unless($tvars{survey});
102              
103             my ($all,$man,$collate,$qu) = $self->AnalyseSurvey();
104              
105             # ensure we have a valid survey
106             return if FieldCheck($all,$man);
107              
108             # now save the survey results
109             my $taken = 0;
110             my $idcode = $self->CreateID();
111             for my $name (@$all) {
112             my $c = $idcode if($collate->{$name});
113              
114             if($qu->{$name}{tag}) {
115             if($cgiparams{$name}) {
116             $cgiparams{$name} = sprintf "%s <%s>", $tvars{user}{name}, $tvars{user}{email};
117             }
118             }
119              
120             $dbi->DoQuery('SaveEvaluation',$cgiparams{courseid},$name,$cgiparams{$name},$c) if($cgiparams{$name});
121             $taken = 1;
122             }
123              
124             if($taken) {
125             my $completed = $self->CreateID();
126             $dbi->DoQuery('SaveEvaluationIndex',$completed,$cgiparams{courseid},$tvars{loginid});
127             $tvars{data}->{thanks} = 1;
128             } else {
129             $tvars{data}->{thanks} = 2;
130             }
131             }
132              
133             1;
134              
135             __END__