Merge branch 'master' into survey
* master: (36 commits) Add a mutator for questionsAnswered, with tests. Fix i18n file namespace. Flesh out the recordResponses POD. Almost ready for more in depth testing. recordResponse tests (just a few) goto tests. Add POD stubs, fully document goto. Fix my stupid typo in the Shelf template with div. nextQuestions tests. Add section separator comments between the subroutines. Remove old discussion related items from the Article templates. matrix compare screen bugfix matrix bug fixes Add more AdminBar tests. Add tests for nextSectionid, nextSection, currentSection. Tests for createSurveyOrder and shuffle. Change ResponseJSON to use a proper mutator for startTime. Forward porting site starter css fix for clears and page content positioning. forward porting quotes in asset title fixTitle test forward port syndicated articles i18n template fix Forward port templated ITransact edit credentials screen. ...
This commit is contained in:
commit
7a42b4b241
49 changed files with 1659 additions and 280 deletions
|
|
@ -226,11 +226,78 @@ sub getEditForm {
|
|||
my $session = $self->session;
|
||||
my $db = $session->db;
|
||||
my $matrixId = $self->getParent->getId;
|
||||
my $tabform = $self->next::method();
|
||||
my $i18n = WebGUI::International->new($session, 'Asset_MatrixListing');
|
||||
my $func = $session->form->process("func");
|
||||
|
||||
my $form = WebGUI::HTMLForm->new($session);
|
||||
|
||||
if ($func eq "add" || ( $func eq "editSave" && $session->form->process("assetId") eq "new")) {
|
||||
$form->hidden(
|
||||
-name =>'assetId',
|
||||
-value =>'new',
|
||||
);
|
||||
$form->hidden(
|
||||
-name =>'class',
|
||||
-value =>'WebGUI::Asset::MatrixListing',
|
||||
);
|
||||
}
|
||||
$form->hidden(
|
||||
-name =>'func',
|
||||
-value =>'editSave',
|
||||
);
|
||||
$form->text(
|
||||
-name =>'title',
|
||||
-defaultValue =>'Untitled',
|
||||
-label =>$i18n->get("product name label"),
|
||||
-hoverHelp =>$i18n->get('product name description'),
|
||||
-value =>$self->getValue('title'),
|
||||
);
|
||||
$form->image(
|
||||
-name =>'screenshots',
|
||||
-defaultValue =>undef,
|
||||
-maxAttachments =>20,
|
||||
-label =>$i18n->get("screenshots label"),
|
||||
-hoverHelp =>$i18n->get("screenshots description"),,
|
||||
-value =>$self->getValue('screenshots'),
|
||||
);
|
||||
$form->HTMLArea(
|
||||
-name =>'description',
|
||||
-defaultValue =>undef,
|
||||
-label =>$i18n->get("description label"),
|
||||
-hoverHelp =>$i18n->get("description description"),
|
||||
-value =>$self->getValue('description'),
|
||||
);
|
||||
$form->text(
|
||||
-name =>'version',
|
||||
-defaultValue =>undef,
|
||||
-label =>$i18n->get("version label"),
|
||||
-hoverHelp =>$i18n->get("version description"),
|
||||
-value =>$self->getValue('version'),
|
||||
);
|
||||
$form->text(
|
||||
-name =>'manufacturerName',
|
||||
-defaultValue =>undef,
|
||||
-label =>$i18n->get("manufacturerName label"),
|
||||
-hoverHelp =>$i18n->get("manufacturerName description"),
|
||||
-value =>$self->getValue('manufacturerName'),
|
||||
);
|
||||
$form->url(
|
||||
-name =>'manufacturerURL',
|
||||
-defaultValue =>undef,
|
||||
-label =>$i18n->get("manufacturerURL label"),
|
||||
-hoverHelp =>$i18n->get("manufacturerURL description"),
|
||||
-value =>$self->getValue('manufacturerURL'),
|
||||
);
|
||||
$form->url(
|
||||
-name =>'productURL',
|
||||
-defaultValue =>undef,
|
||||
-label =>$i18n->get("productURL label"),
|
||||
-hoverHelp =>$i18n->get("productURL description"),
|
||||
-value =>$self->getValue('productURL'),
|
||||
);
|
||||
|
||||
foreach my $category (keys %{$self->getParent->getCategories}) {
|
||||
$tabform->getTab('properties')->raw('<tr><td colspan="2"><b>'.$category.'</b></td></tr>');
|
||||
$form->raw('<tr><td colspan="2"><b>'.$category.'</b></td></tr>');
|
||||
my $attributes;
|
||||
if ($session->form->process('func') eq 'add'){
|
||||
$attributes = $db->read("select * from Matrix_attribute where category = ? and assetId = ?",
|
||||
|
|
@ -246,10 +313,13 @@ sub getEditForm {
|
|||
$attribute->{label} = $attribute->{name};
|
||||
$attribute->{subtext} = $attribute->{description};
|
||||
$attribute->{name} = 'attribute_'.$attribute->{attributeId};
|
||||
$tabform->getTab("properties")->dynamicField(%{$attribute});
|
||||
$form->dynamicField(%{$attribute});
|
||||
}
|
||||
}
|
||||
return $tabform;
|
||||
|
||||
$form->submit();
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -777,7 +847,12 @@ sub www_edit {
|
|||
my $i18n = WebGUI::International->new($self->session, "Asset_MatrixListing");
|
||||
return $self->session->privilege->insufficient() unless $self->canEdit;
|
||||
return $self->session->privilege->locked() unless $self->canEditIfLocked;
|
||||
return $self->getAdminConsole->render($self->getEditForm->print,$i18n->get('edit matrix listing title'));
|
||||
|
||||
my $var = $self->get;
|
||||
my $matrix = $self->getParent;
|
||||
$var->{form} = $self->getEditForm->print;
|
||||
|
||||
return $matrix->processStyle($self->processTemplate($var,$matrix->get("editListingTemplateId")));
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -812,6 +887,7 @@ sub www_getAttributes {
|
|||
$attribute->{label} = $attribute->{name};
|
||||
$attribute->{attributeId} =~ s/-/_____/g;
|
||||
if ($attribute->{fieldType} eq 'MatrixCompare'){
|
||||
$attribute->{compareColor} = $self->getParent->getCompareColor($attribute->{value});
|
||||
$attribute->{value} = WebGUI::Form::MatrixCompare->new($self->session,$attribute)->getValueAsHtml;
|
||||
}
|
||||
if($session->scratch->get('stickied_'.$attribute->{attributeId})){
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ use base 'WebGUI::Asset';
|
|||
use WebGUI::International;
|
||||
use WebGUI::Asset::Template::HTMLTemplate;
|
||||
use WebGUI::Utility;
|
||||
use Clone qw/clone/;
|
||||
|
||||
|
||||
=head1 NAME
|
||||
|
|
@ -401,6 +402,30 @@ sub processRaw {
|
|||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 update
|
||||
|
||||
Override update from Asset.pm to handle backwards compatibility with the old
|
||||
packages that contain headBlocks.
|
||||
|
||||
This method is deprecated and will be removed in the future. Don't plan
|
||||
on this being here.
|
||||
|
||||
=cut
|
||||
|
||||
sub update {
|
||||
my $self = shift;
|
||||
my $requestedProperties = shift;
|
||||
my $properties = clone($requestedProperties);
|
||||
if (exists $properties->{headBlock}) {
|
||||
$properties->{extraHeadTags} .= $properties->{headBlock};
|
||||
delete $properties->{headBlock};
|
||||
}
|
||||
$self->SUPER::update($properties);
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_edit {
|
||||
my $self = shift;
|
||||
|
|
|
|||
|
|
@ -1877,13 +1877,15 @@ sub www_ical {
|
|||
# Summary (the title)
|
||||
# Wrapped at 75 columns
|
||||
$ical .= $self->wrapIcal("SUMMARY:".$event->get("title"))."\r\n";
|
||||
|
||||
|
||||
# Description (the text)
|
||||
# Wrapped at 75 columns
|
||||
$ical .= $self->wrapIcal("DESCRIPTION:".$event->get("description"))."\r\n";
|
||||
|
||||
|
||||
|
||||
|
||||
# Location (the text)
|
||||
# Wrapped at 75 columns
|
||||
$ical .= $self->wrapIcal("LOCATION:".$event->get("location"))."\r\n";
|
||||
|
||||
# X-WEBGUI lines
|
||||
if ($event->get("groupIdView")) {
|
||||
$ical .= "X-WEBGUI-GROUPIDVIEW:".$event->get("groupIdView")."\r\n";
|
||||
|
|
@ -1893,11 +1895,11 @@ sub www_ical {
|
|||
}
|
||||
$ical .= "X-WEBGUI-URL:".$event->get("url")."\r\n";
|
||||
$ical .= "X-WEBGUI-MENUTITLE:".$event->get("menuTitle")."\r\n";
|
||||
|
||||
|
||||
$ical .= qq{END:VEVENT\r\n};
|
||||
}
|
||||
# ENDVEVENT
|
||||
|
||||
|
||||
$ical .= qq{END:VCALENDAR\r\n};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -86,6 +86,14 @@ sub definition {
|
|||
hoverHelp =>$i18n->get('compare template description'),
|
||||
label =>$i18n->get('compare template label'),
|
||||
},
|
||||
editListingTemplateId=>{
|
||||
defaultValue =>"matrixtmpl000000000004",
|
||||
fieldType =>"template",
|
||||
tab =>"display",
|
||||
namespace =>"Matrix/EditListing",
|
||||
hoverHelp =>$i18n->get('edit listing template description'),
|
||||
label =>$i18n->get('edit listing template label'),
|
||||
},
|
||||
defaultSort=>{
|
||||
fieldType =>"selectBox",
|
||||
tab =>"display",
|
||||
|
|
@ -326,7 +334,7 @@ sub getCompareColor {
|
|||
elsif($value == 3){
|
||||
return $self->get('compareColorFreeAddOn');
|
||||
}
|
||||
elsif($value == 3){
|
||||
elsif($value == 4){
|
||||
return $self->get('compareColorYes');
|
||||
}
|
||||
|
||||
|
|
@ -656,6 +664,10 @@ sub www_compare {
|
|||
'text/javascript'});
|
||||
$self->session->style->setLink($self->session->url->extras('yui/build/datatable/assets/skins/sam/datatable.css'),
|
||||
{type =>'text/css', rel=>'stylesheet'});
|
||||
$self->session->style->setScript($self->session->url->extras('hoverhelp.js'), {type =>
|
||||
'text/javascript'});
|
||||
$self->session->style->setLink($self->session->url->extras('hoverhelp.css'),
|
||||
{type =>'text/css', rel=>'stylesheet'});
|
||||
|
||||
my $maxComparisons;
|
||||
if($self->session->user->isVisitor){
|
||||
|
|
@ -673,7 +685,7 @@ sub www_compare {
|
|||
|
||||
$var->{javascript} = "<script type='text/javascript'>\n".
|
||||
'var listingIds = new Array('.join(", ",map {'"'.$_.'"'} @listingIds).");\n".
|
||||
'var responseFields = new Array("attributeId", "name", "fieldType", "checked", '.join(", ",map {'"'.$_.'"'} @responseFields).");\n".
|
||||
'var responseFields = new Array("attributeId", "name", "description","fieldType", "checked", '.join(", ",map {'"'.$_.'"'} @responseFields).");\n".
|
||||
"var maxComparisons = ".$maxComparisons.";\n".
|
||||
"var matrixUrl = '".$self->getUrl."';\n".
|
||||
"</script>";
|
||||
|
|
@ -906,11 +918,9 @@ sub www_getCompareFormData {
|
|||
my $form = $session->form;
|
||||
my $sort = shift || $session->scratch->get('matrixSort') || $self->get('defaultSort');
|
||||
my $sortDirection = ' desc';
|
||||
=cut
|
||||
if ( WebGUI::Utility::isIn($sort, qw(revisionDate score)) ) {
|
||||
$sortDirection = " desc";
|
||||
}
|
||||
=cut
|
||||
# if ( WebGUI::Utility::isIn($sort, qw(revisionDate score)) ) {
|
||||
# $sortDirection = " desc";
|
||||
# }
|
||||
my @results;
|
||||
my @listingIds = $self->session->form->checkList("listingId");
|
||||
|
||||
|
|
@ -1024,7 +1034,8 @@ sub www_getCompareListData {
|
|||
$listing->incrementCounter("compares");
|
||||
my $listingId_safe = $listingId;
|
||||
$listingId_safe =~ s/-/_____/g;
|
||||
push(@columnDefs,{key=>$listingId_safe,label=>$listing->get('title'),formatter=>"formatColors"});
|
||||
push(@columnDefs,{key=>$listingId_safe,label=>$listing->get('title'),formatter=>"formatColors",
|
||||
url=>$listing->getUrl});
|
||||
}
|
||||
|
||||
my $jsonOutput;
|
||||
|
|
@ -1032,7 +1043,7 @@ sub www_getCompareListData {
|
|||
|
||||
foreach my $category (keys %{$self->getCategories}) {
|
||||
push(@results,{name=>$category,fieldType=>'category'});
|
||||
my $fields = " a.name, a.fieldType, a.attributeId ";
|
||||
my $fields = " a.name, a.fieldType, a.attributeId, a.description ";
|
||||
my $from = "from Matrix_attribute a";
|
||||
my $tableCount = "b";
|
||||
foreach my $listingId (@listingIds) {
|
||||
|
|
@ -1049,7 +1060,12 @@ sub www_getCompareListData {
|
|||
) });
|
||||
}
|
||||
foreach my $result (@results){
|
||||
unless($result->{fieldType} eq 'category'){
|
||||
if($result->{fieldType} eq 'category'){
|
||||
foreach my $columnDef (@columnDefs) {
|
||||
$result->{$columnDef->{key}} = $columnDef->{label};
|
||||
}
|
||||
}
|
||||
else{
|
||||
foreach my $listingId (@listingIds) {
|
||||
$result->{attributeId} =~ s/-/_____/g;
|
||||
my $listingId_safe = $listingId;
|
||||
|
|
|
|||
|
|
@ -820,7 +820,7 @@ sub prepareShowSurveyTemplate {
|
|||
$section->{'totalQuestions'} = @{$self->response->surveyOrder};
|
||||
$section->{'showProgress'} = $self->get('showProgress');
|
||||
$section->{'showTimeLimit'} = $self->get('showTimeLimit');
|
||||
$section->{'minutesLeft'} = int((($self->response->{startTime} + (60 * $self->get('timeLimit'))) - time())/60);
|
||||
$section->{'minutesLeft'} = int((($self->response->startTime() + (60 * $self->get('timeLimit'))) - time())/60);
|
||||
|
||||
my $out = $self->processTemplate( $section, $self->get("surveyQuestionsId") );
|
||||
|
||||
|
|
@ -953,7 +953,6 @@ sub getResponseId {
|
|||
$self->loadBothJSON($responseId);
|
||||
$self->response->createSurveyOrder();
|
||||
$self->{responseId} = $responseId;
|
||||
$self->response->{startTime} = $time;
|
||||
$self->saveResponseJSON();
|
||||
|
||||
} ## end if ( $haveTaken < $allowedTakes)
|
||||
|
|
|
|||
|
|
@ -32,6 +32,8 @@ use strict;
|
|||
use JSON;
|
||||
use Data::Dumper;
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 new ( $json, $log, $survey )
|
||||
|
||||
Object constructor.
|
||||
|
|
@ -63,13 +65,12 @@ sub new {
|
|||
my $self = defined $temp ? $temp : {};
|
||||
$self->{survey} = $survey;
|
||||
$self->{log} = $log;
|
||||
$self->{surveyOrder}
|
||||
= defined $temp->{surveyOrder}
|
||||
? $temp->{surveyOrder}
|
||||
: []; #an array of question addresses, with the third member being an array of answers
|
||||
$self->{responses} = defined $temp->{responses} ? $temp->{responses} : {};
|
||||
$self->{lastResponse} = defined $temp->{lastResponse} ? $temp->{lastResponse} : -1;
|
||||
$self->{responses} = defined $temp->{responses} ? $temp->{responses} : {};
|
||||
$self->{lastResponse} = defined $temp->{lastResponse} ? $temp->{lastResponse} : -1;
|
||||
$self->{questionsAnswered} = defined $temp->{questionsAnswered} ? $temp->{questionsAnswered} : 0;
|
||||
$self->{startTime} = defined $temp->{startTime} ? $temp->{startTime} : time();
|
||||
#an array of question addresses, with the third member being an array of answers
|
||||
$self->{surveyOrder} = defined $temp->{surveyOrder} ? $temp->{surveyOrder} : [];
|
||||
bless( $self, $class );
|
||||
return $self;
|
||||
} ## end sub new
|
||||
|
|
@ -122,6 +123,14 @@ sub createSurveyOrder {
|
|||
$self->{surveyOrder} = $order;
|
||||
} ## end sub createSurveyOrder
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 shuffle ( @array )
|
||||
|
||||
Returns the contents of @array in a random order.
|
||||
|
||||
=cut
|
||||
|
||||
sub shuffle {
|
||||
my @a = splice @_;
|
||||
for my $i ( 0 .. $#a ) {
|
||||
|
|
@ -131,6 +140,14 @@ sub shuffle {
|
|||
return @a;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 freeze
|
||||
|
||||
Serializes the object to JSON, after deleting the log and survey objects stored in it.
|
||||
|
||||
=cut
|
||||
|
||||
sub freeze {
|
||||
my $self = shift;
|
||||
my %temp = %{$self};
|
||||
|
|
@ -139,16 +156,43 @@ sub freeze {
|
|||
return to_json( \%temp );
|
||||
}
|
||||
|
||||
#Hash the survey timed out?
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
#Has the survey timed out?
|
||||
|
||||
=head2 hasTimedOut ( $limit )
|
||||
|
||||
Checks to see whether this survey has timed out, based on the internally stored starting
|
||||
time, and $limit.
|
||||
|
||||
=head3 $limit
|
||||
|
||||
How long the user has to take the survey, in minutes.
|
||||
|
||||
=cut
|
||||
|
||||
sub hasTimedOut{
|
||||
my $self=shift;
|
||||
my $limit = shift;
|
||||
return 1 if($self->{startTime} + ($limit * 60) < time() and $limit > 0);
|
||||
return 1 if($self->startTime() + ($limit * 60) < time() and $limit > 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
#the index of the last surveyOrder entry shown
|
||||
|
||||
=head2 lastResponse ([ $responseIndex ])
|
||||
|
||||
Mutator for the index of the last surveyOrder entry shown. With no arguments,
|
||||
returns the lastResponse index.
|
||||
|
||||
=head3 $responseIndex
|
||||
|
||||
If defined, sets the lastResponse to $responseIndex.
|
||||
|
||||
=cut
|
||||
|
||||
sub lastResponse {
|
||||
my $self = shift;
|
||||
my $res = shift;
|
||||
|
|
@ -160,27 +204,177 @@ sub lastResponse {
|
|||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 questionsAnswered ([ $questionsAnswered ])
|
||||
|
||||
Mutator for the number of questions answered. With no arguments,
|
||||
does a set.
|
||||
|
||||
=head3 $questionsAnswered.
|
||||
|
||||
If defined, increments the number of questions by $questionsAnswered
|
||||
|
||||
=cut
|
||||
|
||||
sub questionsAnswered {
|
||||
my $self = shift;
|
||||
my $answered = shift;
|
||||
if ( defined $answered ) {
|
||||
$self->{questionsAnswered} += $answered;
|
||||
}
|
||||
else {
|
||||
return $self->{questionsAnswered};
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 startTime ([ $newStartTime ])
|
||||
|
||||
Mutator for the time the user began the survey. With no arguments,
|
||||
returns the startTime.
|
||||
|
||||
=head3 $newStarttime
|
||||
|
||||
If defined, sets the starting time to $newStartTime.
|
||||
|
||||
=cut
|
||||
|
||||
sub startTime {
|
||||
my $self = shift;
|
||||
my $newTime = shift;
|
||||
if ( defined $newTime ) {
|
||||
$self->{startTime} = $newTime;
|
||||
}
|
||||
else {
|
||||
return $self->{startTime};
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
#array of addresses in which the survey should be presented
|
||||
|
||||
=head2 surveyOrder
|
||||
|
||||
Accessor for the survey order data structure. It is a deep set of arrays, similar in
|
||||
structure to a WebGUI::Asset::Wobject::Survey::SurveyJSON address.
|
||||
|
||||
[ $sectionIndex, $questionIndex, [ $answerIndex1, $answerIndex2, ....]
|
||||
|
||||
There is one array element for every section and address in the survey.
|
||||
|
||||
If there are no questions, or no addresses, those array elements will not be present.
|
||||
|
||||
=cut
|
||||
|
||||
sub surveyOrder {
|
||||
my $self = shift;
|
||||
return $self->{surveyOrder};
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 nextSectionId
|
||||
|
||||
Relative to the surveyOrder and the lastResponse index, get the index of the
|
||||
next section. Note, based on the number of questions in an section, this can
|
||||
be the same as the current section index.
|
||||
|
||||
=cut
|
||||
|
||||
sub nextSectionId {
|
||||
my $self = shift;
|
||||
return undef if $self->surveyEnd();
|
||||
return $self->surveyOrder->[ $self->lastResponse + 1 ]->[0];
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 nextSection
|
||||
|
||||
Relative to the surveyOrder and the lastResponse index, gets the next section.
|
||||
Note, based on the number of questions in a section, this can be the same as
|
||||
the current section.
|
||||
|
||||
=cut
|
||||
|
||||
sub nextSection {
|
||||
my $self = shift;
|
||||
return {} if $self->surveyEnd();
|
||||
return $self->survey->section( [ $self->surveyOrder->[ $self->lastResponse + 1 ]->[0] ] );
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 currentSection
|
||||
|
||||
Relative to the surveyOrder and the lastResponse index, get the current section.
|
||||
|
||||
=cut
|
||||
|
||||
sub currentSection {
|
||||
my $self = shift;
|
||||
return $self->survey->section( [ $self->surveyOrder->[ $self->lastResponse ]->[0] ] );
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 recordResponses ($session, $responses)
|
||||
|
||||
Takes survey responses and puts them into the response hash of this object. Does terminal
|
||||
handling for sections and questions, and goto processing. Advances the survey page if
|
||||
all required questions have been answered.
|
||||
|
||||
=head3 $session
|
||||
|
||||
A WebGUI session object
|
||||
|
||||
=head3 $responses
|
||||
|
||||
A hash ref of form param data. Each element will look like:
|
||||
|
||||
{
|
||||
"__qid__comment" => "question comment",
|
||||
"__aid__" => "answer",
|
||||
"__aid__comment" => "answer comment",
|
||||
}
|
||||
|
||||
where __qid__ is a question id, as described in L<nextQuestions>, and __aid__ is an
|
||||
answer id, also described there.
|
||||
|
||||
=head3 terminal processing
|
||||
|
||||
Terminal processing for a section and its questions and answers are handled in
|
||||
order. The terminalUrl setting in a question overrides the terminalUrl setting
|
||||
for its section. Similarly, with questions and answers, the last terminalUrl
|
||||
setting of the set of questions is what is returned for the page, with the questions
|
||||
and answers being answered in surveyOrder.
|
||||
|
||||
=head3 goto processing
|
||||
|
||||
gotos are handled similarly as with terminalUrls. The last goto in the set of questions
|
||||
wins.
|
||||
|
||||
=head3 responses data structure
|
||||
|
||||
This method also builds an internal data structure with the users' responses. It
|
||||
is set up like this:
|
||||
|
||||
responses => {
|
||||
__qid__ => {
|
||||
comment => "question comment",
|
||||
},
|
||||
__aid__ => {
|
||||
time => time(),
|
||||
comment => "answer comment",
|
||||
value => "answer value",
|
||||
},
|
||||
}
|
||||
|
||||
=cut
|
||||
|
||||
sub recordResponses {
|
||||
my $self = shift;
|
||||
my $session = shift;
|
||||
|
|
@ -217,7 +411,7 @@ sub recordResponses {
|
|||
#There were no questions in the section just displayed, so increment the lastResponse by one
|
||||
if ( ref $questions ne 'ARRAY' ) {
|
||||
$self->lastResponse( $self->lastResponse + 1 );
|
||||
return [ $terminal, $terminalUrl ];
|
||||
return [ $sterminal, $terminalUrl ];
|
||||
}
|
||||
|
||||
for my $question (@$questions) {
|
||||
|
|
@ -234,7 +428,7 @@ sub recordResponses {
|
|||
{
|
||||
|
||||
$aAnswered = 1;
|
||||
if ( $mcTypes{ $question->{questionType} } ) {
|
||||
if ( exists $mcTypes{ $question->{questionType} } ) {
|
||||
$self->responses->{ $answer->{id} }->{value} = $answer->{recordedAnswer};
|
||||
}
|
||||
else {
|
||||
|
|
@ -253,7 +447,9 @@ sub recordResponses {
|
|||
} ## end if ( defined( $responses...
|
||||
} ## end for my $answer ( @{ $question...
|
||||
$qAnswered = 0 if ( !$aAnswered and $question->{required} );
|
||||
$self->{questionsAnswered}++ if($aAnswered);
|
||||
if ($aAnswered) {
|
||||
$self->questionsAnswered( +1 );
|
||||
}
|
||||
} ## end for my $question (@$questions)
|
||||
|
||||
#if all responses completed, move the lastResponse index to the last question shown
|
||||
|
|
@ -272,6 +468,20 @@ sub recordResponses {
|
|||
return [ $terminal, $terminalUrl ];
|
||||
} ## end sub recordResponses
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 goto ( $variable )
|
||||
|
||||
Looks through all sections and questions for their variable key, in order. If the requested
|
||||
$variable matches a variable, then the lastResponse is set so that that section or question
|
||||
is the next displayed. If more than one section or question matches, then the first is used.
|
||||
|
||||
=head3 $variable
|
||||
|
||||
The variable to look for in all sections and questions.
|
||||
|
||||
=cut
|
||||
|
||||
sub goto {
|
||||
my $self = shift;
|
||||
my $goto = shift;
|
||||
|
|
@ -289,6 +499,12 @@ sub goto {
|
|||
}
|
||||
} ## end sub goto
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getPreviousAnswer
|
||||
|
||||
=cut
|
||||
|
||||
sub getPreviousAnswer {
|
||||
my $self = shift;
|
||||
my $questionParam = shift;
|
||||
|
|
@ -304,12 +520,33 @@ sub getPreviousAnswer {
|
|||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 nextQuestions
|
||||
|
||||
Returns an array ref of the next questions in the survey. The number of questions
|
||||
returned is set by the questionsPerPage property of the next section, as determined
|
||||
by nextSectionId rather than logical section ordering.
|
||||
|
||||
If no questions are available, then it returns an empty array ref.
|
||||
|
||||
Each element of the array ref is a question data structure, from the
|
||||
WebGUI::Asset::Wobject::Survey::SurveyJSON class, with a section sid field (index of
|
||||
the containing section) and question id (section and question id concatenated with a
|
||||
'-') added. The answers array of the question contains answer data structures, also
|
||||
from WebGUI::Asset::Wobject::Survey::SurveyJSON, with an id field which is the section,
|
||||
question and answer indexes concatentated together with dashes.
|
||||
|
||||
Section and question [[var]] replacements in text fields.
|
||||
|
||||
All questions and answers are safe copies of the survey data.
|
||||
|
||||
=cut
|
||||
|
||||
sub nextQuestions {
|
||||
my $self = shift;
|
||||
|
||||
if ( $self->lastResponse >= $#{ $self->surveyOrder } ) {
|
||||
return [];
|
||||
}
|
||||
return [] if $self->surveyEnd;
|
||||
|
||||
my $nextSectionId = $self->nextSectionId;
|
||||
|
||||
|
|
@ -334,22 +571,37 @@ sub nextQuestions {
|
|||
$question{id} = "$$qAddy[0]-$$qAddy[1]";
|
||||
$question{sid} = "$$qAddy[0]";
|
||||
for ( @{ $$qAddy[2] } ) {
|
||||
my $ans = $self->survey->answer( [ $$qAddy[0], $$qAddy[1], $_ ] );
|
||||
$ans->{'text'} =~ s/\[\[([^\%]*?)\]\]/$self->getPreviousAnswer($1)/eg;
|
||||
$ans->{id} = "$$qAddy[0]-$$qAddy[1]-$_";
|
||||
push( @{ $question{answers} }, $ans );
|
||||
my %ans = %{ $self->survey->answer( [ $$qAddy[0], $$qAddy[1], $_ ] ) };
|
||||
$ans{'text'} =~ s/\[\[([^\%]*?)\]\]/$self->getPreviousAnswer($1)/eg;
|
||||
$ans{id} = "$$qAddy[0]-$$qAddy[1]-$_";
|
||||
push( @{ $question{answers} }, \%ans );
|
||||
}
|
||||
push( @$questions, \%question );
|
||||
} ## end for ( my $i = 1; $i <= ...
|
||||
return $questions;
|
||||
} ## end sub nextQuestions
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 surveyEnd
|
||||
|
||||
Returns true if the current index stored in lastResponse is greater than or
|
||||
equal to the number of sections in the survey order.
|
||||
|
||||
=cut
|
||||
|
||||
sub surveyEnd {
|
||||
my $self = shift;
|
||||
return 1 if ( $self->lastResponse >= $#{ $self->surveyOrder } );
|
||||
return 0;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 returnResponsesForReporting
|
||||
|
||||
=cut
|
||||
|
||||
sub returnResponseForReporting {
|
||||
my $self = shift;
|
||||
my @responses = ();
|
||||
|
|
@ -393,19 +645,51 @@ sub returnResponseForReporting {
|
|||
return \@responses;
|
||||
} ## end sub returnResponseForReporting
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
#the actual responses to the survey. A response is for a question and is accessed by the exact same address as a survey member.
|
||||
#Questions only contain the comment and an array of answer Responses.
|
||||
#Answers only contain, entered text, entered verbatim, their index in the Survey Question Answer array, and the assetId to the uploaded file.
|
||||
|
||||
=head2 responses
|
||||
|
||||
Returns a reference to the actual responses to the survey. A response is for a question and
|
||||
is accessed by the exact same address as a survey member. Questions only contain the comment
|
||||
and an array of answer Responses. Answers only contain, entered text, entered verbatim,
|
||||
their index in the Survey Question Answer array, and the assetId to the uploaded file.
|
||||
|
||||
Note, this is an unsafe reference.
|
||||
|
||||
=cut
|
||||
|
||||
sub responses {
|
||||
my $self = shift;
|
||||
return $self->{responses};
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 responses
|
||||
|
||||
Returns a referece to the SurveyJSON object that this object was created with.
|
||||
|
||||
Note, this is an unsafe reference.
|
||||
|
||||
=cut
|
||||
|
||||
sub survey {
|
||||
my $self = shift;
|
||||
return $self->{survey};
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 log
|
||||
|
||||
Logs an error to the webgui log file, using the session logger.
|
||||
|
||||
=cut
|
||||
|
||||
sub log {
|
||||
my ( $self, $message ) = @_;
|
||||
if ( defined $self->{log} ) {
|
||||
|
|
|
|||
|
|
@ -862,7 +862,7 @@ sub getFormElement {
|
|||
}
|
||||
}
|
||||
|
||||
if (WebGUI::Utility::isIn($data->{fieldType},qw(SelectList CheckList SelectBox Attachments Combo))) {
|
||||
if (WebGUI::Utility::isIn($data->{fieldType},qw(SelectList CheckList SelectBox Attachments))) {
|
||||
my @defaultValues;
|
||||
if ($self->session->form->param($name)) {
|
||||
@defaultValues = $self->session->form->selectList($name);
|
||||
|
|
@ -876,7 +876,9 @@ sub getFormElement {
|
|||
$param{value} = \@defaultValues;
|
||||
}
|
||||
|
||||
if (WebGUI::Utility::isIn($data->{fieldType},qw(SelectList SelectBox CheckList RadioList SelectSlider Combo))) {
|
||||
my $class = 'WebGUI::Form::'. ucfirst $data->{fieldType};
|
||||
eval { WebGUI::Pluggable::load($class) };
|
||||
if ($class->isa('WebGUI::Form::List')) {
|
||||
delete $param{size};
|
||||
|
||||
my $values = WebGUI::Operation::Shared::secureEval($self->session,$data->{possibleValues});
|
||||
|
|
@ -930,7 +932,7 @@ sub getFormElement {
|
|||
$param{value} = $data->{value} || $data->{defaultValue};
|
||||
}
|
||||
|
||||
my $formElement = eval { WebGUI::Pluggable::instanciate("WebGUI::Form::". ucfirst $param{fieldType}, "new", [$self->session, \%param ])};
|
||||
my $formElement = eval { WebGUI::Pluggable::instanciate($class, "new", [$self->session, \%param ])};
|
||||
return $formElement->toHtml();
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue