Moved multiple choice questions to the data base, and they can now be edited globally from the Survey edito

This commit is contained in:
Kaleb Murphy 2009-03-26 21:02:30 +00:00
parent d0c032625a
commit 046dae4f31
5 changed files with 157 additions and 77 deletions

View file

@ -7,7 +7,7 @@
- rfe #9099: Thingy field-copy function (SDH Consulting Group)
- Keywords are now comma separated rather than space separated.
- added Keywords form control with autocomplete
- Survey: Moved multiple choice questions to the data base, and they can now be edited globally from the Survey editor
7.7.0
- fixed #9913: New Content Side Bar missing in Asset window
- fixed: New Mail macro never returns any messages

View file

@ -35,6 +35,9 @@ adSkuInstall($session);
addWelcomeMessageTemplateToSettings( $session );
addStatisticsCacheTimeoutToMatrix( $session );
#add Survey table
addSurveyQuestionTypes($session);
# image mods
addImageAnnotation($session);
@ -43,6 +46,21 @@ addRssLimit($session);
finish($session); # this line required
sub addSurveyQuestionTypes{
my $session = shift;
print "\tAdding new survey table Survey_questionTypes \n" unless $quiet;
$session->db->write("
CREATE TABLE `Survey_questionTypes` (
`questionType` varchar(56) NOT NULL,
`answers` text NOT NULL,
PRIMARY KEY (`questionType`))
");
$session->db->write("
INSERT INTO `Survey_questionTypes` VALUES ('Scale',''),('Gender','Male,Female'),('Education','Elementary or some high school,High school/GED,Some college/vocational school,College graduate,Some graduate work,Masters degree,Doctorate (of any type),Other degree (verbatim)'),('Importance','Not at all important,,,,,,,,,,Extremely important'),('Yes/No','Yes,No'),('Confidence','Not at all confident,,,,,,,,,,Extremely confident'),('Effectiveness','Not at all effective,,,,,,,,,,Extremely effective'),('Oppose/Support','Strongly oppose,,,,,,Strongly support'),('Certainty','Not at all certain,,,,,,,,,,Extremely certain'),('True/False','True,False'),('Concern','Not at all concerned,,,,,,,,,,Extremely concerned'),('Ideology','Strongly liberal,Liberal,Somewhat liberal,Middle of the road,Slightly conservative,Conservative,Strongly conservative'),('Security','Not at all secure,,,,,,,,,,Extremely secure'),('Risk','No risk,,,,,,,,,,Extreme risk'),('Agree/Disagree','Strongly disagree,,,,,,Strongly agree'),('Race','American Indian,Asian,Black,Hispanic,White non-Hispanic,Something else (verbatim)'),('Threat','No threat,,,,,,,,,,Extreme threat'),('Party','Democratic party,Republican party (or GOP),Independent party,Other party (verbatim)'),('Likelihood','Not at all likely,,,,,,,,,,Extremely likely'),('Multiple Choice',''),('Satisfaction','Not at all satisfied,,,,,,,,,,Extremely satisfied')
");
print "Done.\n" unless $quiet;
}
sub addWelcomeMessageTemplateToSettings {
my $session = shift;
print "\tAdding welcome message template to settings \n" unless $quiet;

View file

@ -195,6 +195,10 @@ sub definition {
},
);
#my $defaultMC = $session->
#%properties = ();
push @{$definition}, {
assetName => $i18n->get('assetName'),
icon => 'survey.gif',
@ -412,6 +416,10 @@ sub www_submitObjectEdit {
}
elsif ( $params->{copy} ) {
return $self->copyObject( \@address );
}elsif( $params->{removetype} ){
return $self->removeType(\@address);
}elsif( $params->{addtype} ){
return $self->addType($params->{addtype},\@address);
}
# Update the addressed object
@ -493,6 +501,27 @@ sub www_jumpTo {
#-------------------------------------------------------------------
sub removeType{
my $self = shift;
my $address = shift;
$self->surveyJSON->removeType($address);
return $self->www_loadSurvey( { address => $address } );
}
#-------------------------------------------------------------------
sub addType{
my $self = shift;
my $name = shift;
my $address = shift;
$self->surveyJSON->addType($name,$address);
$self->persistSurveyJSON();
return $self->www_loadSurvey( { address => $address } );
}
#-------------------------------------------------------------------
=head2 copyObject ( )
Takes the address of a survey object and creates a copy. The copy is placed at the end of this object's parent's list.
@ -1208,13 +1237,13 @@ Sends the processed template and questions structure to the client
sub prepareShowSurveyTemplate {
my ( $self, $section, $questions ) = @_;
my %multipleChoice = (
'Multiple Choice', 1, 'Gender', 1, 'Yes/No', 1, 'True/False', 1, 'Ideology', 1,
'Race', 1, 'Party', 1, 'Education', 1, 'Scale', 1, 'Agree/Disagree', 1,
'Oppose/Support', 1, 'Importance', 1, 'Likelihood', 1, 'Certainty', 1, 'Satisfaction', 1,
'Confidence', 1, 'Effectiveness', 1, 'Concern', 1, 'Risk', 1, 'Threat', 1,
'Security', 1
);
# my %multipleChoice = (
# 'Multiple Choice', 1, 'Gender', 1, 'Yes/No', 1, 'True/False', 1, 'Ideology', 1,
# 'Race', 1, 'Party', 1, 'Education', 1, 'Scale', 1, 'Agree/Disagree', 1,
# 'Oppose/Support', 1, 'Importance', 1, 'Likelihood', 1, 'Certainty', 1, 'Satisfaction', 1,
# 'Confidence', 1, 'Effectiveness', 1, 'Concern', 1, 'Risk', 1, 'Threat', 1,
# 'Security', 1
# );
my %textArea = ( 'TextArea', 1 );
my %text = ( 'Text', 1, 'Email', 1, 'Phone Number', 1, 'Text Date', 1, 'Currency', 1 );
my %slider = ( 'Slider', 1, 'Dual Slider - Range', 1, 'Multi Slider - Allocate', 1 );
@ -1222,14 +1251,13 @@ sub prepareShowSurveyTemplate {
my %dateShort = ( 'Year Month', 1 );
my %fileUpload = ( 'File Upload', 1 );
my %hidden = ( 'Hidden', 1 );
use Data::Dumper;
foreach my $q (@$questions) {
if ( $fileUpload{ $q->{questionType} } ) { $q->{fileLoader} = 1; }
elsif ( $text{ $q->{questionType} } ) { $q->{textType} = 1; }
elsif ( $textArea{ $q->{questionType} } ) { $q->{textAreaType} = 1; }
elsif ( $hidden{ $q->{questionType} } ) { $q->{hidden} = 1; }
elsif ( $multipleChoice{ $q->{questionType} } ) {
elsif ( $self->surveyJSON->multipleChoiceTypes->{ $q->{questionType} } ) {
$q->{multipleChoice} = 1;
if ( $q->{maxAnswers} > 1 ) {
$q->{maxMoreOne} = 1;

View file

@ -59,69 +59,9 @@ use Storable qw/dclone/;
# The maximum value of questionsPerPage is currently hardcoded here
my $MAX_QUESTIONS_PER_PAGE = 20;
my %MULTI_CHOICE_BUNDLES = (
'Agree/Disagree' => [ 'Strongly disagree', (q{}) x 5, 'Strongly agree' ],
Certainty => [ 'Not at all certain', (q{}) x 9, 'Extremely certain' ],
Concern => [ 'Not at all concerned', (q{}) x 9, 'Extremely concerned' ],
Confidence => [ 'Not at all confident', (q{}) x 9, 'Extremely confident' ],
Education => [
'Elementary or some high school',
'High school/GED',
'Some college/vocational school',
'College graduate',
'Some graduate work',
'Master\'s degree',
'Doctorate (of any type)',
'Other degree (verbatim)',
],
Effectiveness => [ 'Not at all effective', (q{}) x 9, 'Extremely effective' ],
Gender => [qw( Male Female )],
Ideology => [
'Strongly liberal',
'Liberal',
'Somewhat liberal',
'Middle of the road',
'Slightly conservative',
'Conservative',
'Strongly conservative'
],
Importance => [ 'Not at all important', (q{}) x 9, 'Extremely important' ],
Likelihood => [ 'Not at all likely', (q{}) x 9, 'Extremely likely' ],
'Oppose/Support' => [ 'Strongly oppose', (q{}) x 5, 'Strongly support' ],
Party =>
[ 'Democratic party', 'Republican party (or GOP)', 'Independent party', 'Other party (verbatim)' ],
Race =>
[ 'American Indian', 'Asian', 'Black', 'Hispanic', 'White non-Hispanic', 'Something else (verbatim)' ],
Risk => [ 'No risk', (q{}) x 9, 'Extreme risk' ],
Satisfaction => [ 'Not at all satisfied', (q{}) x 9, 'Extremely satisfied' ],
Security => [ 'Not at all secure', (q{}) x 9, 'Extremely secure' ],
Threat => [ 'No threat', (q{}) x 9, 'Extreme threat' ],
'True/False' => [qw( True False )],
'Yes/No' => [qw( Yes No )],
Scale => [q{}],
'Multiple Choice' => [q{}],
);
my @SPECIAL_QUESTION_TYPES = (
'Dual Slider - Range',
'Multi Slider - Allocate',
'Slider',
'Currency',
'Email',
'Phone Number',
'Text',
'Text Date',
'TextArea',
'File Upload',
'Date',
'Date Range',
'Year Month',
'Hidden',
);
sub specialQuestionTypes {
return @SPECIAL_QUESTION_TYPES;
}
#sub specialQuestionTypes {
# return @SPECIAL_QUESTION_TYPES;
#}
=head2 new ( $session, json )
@ -154,6 +94,9 @@ sub new {
bless $self, $class;
#Load question types
$self->loadTypes();
# Initialise the survey data structure if empty..
if ( $self->totalSections == 0 ) {
$self->newObject( [] );
@ -161,6 +104,78 @@ sub new {
return $self;
}
=head2 loadTypes
Loads the Multiple Choice and Special Question types
=cut
sub loadTypes {
my $self = shift;
@{$self->{specialQuestionTypes}} = (
'Dual Slider - Range',
'Multi Slider - Allocate',
'Slider',
'Currency',
'Email',
'Phone Number',
'Text',
'Text Date',
'TextArea',
'File Upload',
'Date',
'Date Range',
'Year Month',
'Hidden',
);
my $refs = $self->session->db->buildArrayRefOfHashRefs("SELECT questionType, answers FROM Survey_questionTypes");
map($self->{multipleChoiceTypes}->{$_->{questionType}} = [split/,/,$_->{answers}], @$refs);
}
sub addType {
my $self = shift;
my $name = shift;
my $address = shift;
my $obj = $self->getObject($address);
my @answers;
for my $ans(@{$obj->{answers}}){
push(@answers,$ans->{text});
}
my $ansString = join(',',@answers);
$self->session->db->write("INSERT INTO Survey_questionTypes VALUES(?,?) ON DUPLICATE KEY UPDATE answers = ?",[$name,$ansString,$ansString]);
$self->question($address)->{questionType} = $name;
}
sub removeType {
my $self = shift;
my $address = shift;
my $obj = $self->getObject($address);
$self->session->db->write("DELETE FROM Survey_questionTypes WHERE questionType = ?",[$obj->{questionType}]);
}
=head2 specialQuestionTypes
Returns the arrayref to the special question types
=cut
sub specialQuestionTypes {
my $self = shift;
return $self->{specialQuestionTypes};
}
=head2 multipleChoiceTypes
Returns the hashref to the multiple choice types
=cut
sub multipleChoiceTypes {
my $self = shift;
return $self->{multipleChoiceTypes};
}
=head2 freeze
Serialize this Perl object into a JSON string. The serialized object is made up of the survey and sections
@ -513,7 +528,6 @@ sub getQuestionEditVars {
# Change questionType from a single element into an array of hashrefs which list the available
# question types and which one is currently selected for this question..
for my $qType ($self->getValidQuestionTypes) {
push @{ $var{questionType} }, {
text => $qType,
@ -530,7 +544,8 @@ A convenience method. Returns a list of question types.
=cut
sub getValidQuestionTypes {
return sort (@SPECIAL_QUESTION_TYPES, keys %MULTI_CHOICE_BUNDLES);
my $self = shift;
return sort (@{$self->{specialQuestionTypes}}, keys %{$self->{multipleChoiceTypes}});
}
=head2 getAnswerEditVars ( $address )
@ -1003,7 +1018,7 @@ sub getMultiChoiceBundle {
my $self = shift;
my ($type) = validate_pos( @_, { type => SCALAR | UNDEF } );
return $MULTI_CHOICE_BUNDLES{$type};
return $self->{multipleChoiceTypes}->{$type};
}
=head2 addAnswersToQuestion ($address, $answers, $verbatims)

View file

@ -73,7 +73,26 @@ Survey.ObjectTemplate = (function(){
}
}
}];
if(type === 'question'){
btns[btns.length] = {
text: "Make Default Type",
handler: function(){
var name = prompt("Please change name to new type, or leave to update current type",document.forms[0].questionType.value);
if(name != null){
document.getElementById('addtype').value = name;
this.submit();
}
}
}
btns[btns.length] = {
text: "Remove Default Type",
handler: function(){
document.getElementById('removetype').value = 1;
this.submit();
}
}
}
dialog = new YAHOO.widget.Dialog(type, {
width: "600px",
context: [document.body, 'tr', 'tr'],