Skip to content

Commit

Permalink
New feature: Define level of variable to make SPSS export easier Fixe…
Browse files Browse the repository at this point in the history
…d bug #2984

git-svn-id: file:///Users/Shitiz/Downloads/lssvn/source/limesurvey@7043 b72ed6b6-b9f8-46b5-92b4-906544132732
  • Loading branch information
mennodekker committed Jun 8, 2009
1 parent 52891a4 commit 7e4b2d7
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 20 deletions.
28 changes: 18 additions & 10 deletions admin/export_data_functions.php
Expand Up @@ -115,6 +115,8 @@ function spss_fieldmap($prefix = 'V') {
$fieldtype = '';
$val_size = 1;
$hide = 0;
$export_scale = '';
$code='';

#Determine field type
if ($fieldname=='submitdate' || $fieldname=='startdate' || $fieldname == 'datestamp') {
Expand Down Expand Up @@ -142,7 +144,6 @@ function spss_fieldmap($prefix = 'V') {
}

#Get qid (question id)
$code='';
$noQID = Array('id', 'token', 'datestamp', 'submitdate', 'startdate', 'startlanguage', 'ipaddr', 'refurl');
if (in_array($fieldname, $noQID) || substr($fieldname,0,10)=='attribute_'){
$qid = 0;
Expand All @@ -169,16 +170,21 @@ function spss_fieldmap($prefix = 'V') {
$hide = $typeMap[$ftype]['hide'];
$diff++;
}
//Get default scale for this type
if (isset($typeMap[$ftype]['Scale'])) $export_scale = $typeMap[$ftype]['Scale'];
//But allow override
$aQuestionAttribs = getQAttributes($qid);
if (isset($aQuestionAttribs['scale_export'])) $export_scale = $aQuestionAttribs['scale_export'];
}

}
$fieldno++;
$fid = $fieldno - $diff;
$lsLong = isset($typeMap[$ftype]["name"])?$typeMap[$ftype]["name"]:$ftype;
$tempArray = array('id'=>"$prefix$fid",'name'=>mb_substr($fieldname, 0, 8),
'qid'=>$qid, 'code'=>$code,'SPSStype'=>$fieldtype,'LStype'=>$ftype,"LSlong"=>$lsLong,
'qid'=>$qid,'code'=>$code,'SPSStype'=>$fieldtype,'LStype'=>$ftype,"LSlong"=>$lsLong,
'ValueLabels'=>'','VariableLabel'=>$varlabel,"sql_name"=>$fieldname,"size"=>$val_size,
'title'=>$ftitle, 'hide'=>$hide);
'title'=>$ftitle,'hide'=>$hide,'scale'=>$export_scale);
$fields[] = $tempArray;
}
return $fields;
Expand All @@ -205,17 +211,19 @@ function spss_getquery() {
$query .= ",\n {$dbprefix}survey_$surveyid.*
FROM {$dbprefix}survey_$surveyid
LEFT JOIN {$dbprefix}tokens_$surveyid ON {$dbprefix}survey_$surveyid.token = {$dbprefix}tokens_$surveyid.token";
if (incompleteAnsFilterstate() === true)
{
$query .= " WHERE {$dbprefix}survey_$surveyid.submitdate is not null ";
}
} else {
$query = "SELECT *
FROM {$dbprefix}survey_$surveyid";
if (incompleteAnsFilterstate() === true)
{
}
switch (incompleteAnsFilterstate()) {
case 'inc':
//Inclomplete answers only
$query .= ' WHERE submitdate is null ';
break;
case 'filter':
//Inclomplete answers only
$query .= ' WHERE submitdate is not null ';
}
break;
}
return $query;
}
Expand Down
2 changes: 1 addition & 1 deletion admin/export_data_r.php
Expand Up @@ -294,7 +294,7 @@
foreach ($fields as $field)
{
$answers=array();
if (strpos("!LO",$field['LStype']) !== false) {
if (strpos("!LOR",$field['LStype']) !== false) {
if (substr($field['code'],-5) == 'other' || substr($field['code'],-7) == 'comment') {
//We have a comment field, so free text
} else {
Expand Down
30 changes: 21 additions & 9 deletions admin/export_data_spss.php
Expand Up @@ -37,15 +37,15 @@
$tempFile = '';

include_once('login_check.php');

//for scale 1=nominal, 2=ordinal, 3=scale
$typeMap = array(
'5'=>Array('name'=>'5 Point Choice','size'=>1,'SPSStype'=>'F'),
'B'=>Array('name'=>'Array (10 Point Choice)','size'=>1,'SPSStype'=>'F'),
'A'=>Array('name'=>'Array (5 Point Choice)','size'=>1,'SPSStype'=>'F'),
'5'=>Array('name'=>'5 Point Choice','size'=>1,'SPSStype'=>'F','Scale'=>3),
'B'=>Array('name'=>'Array (10 Point Choice)','size'=>1,'SPSStype'=>'F','Scale'=>3),
'A'=>Array('name'=>'Array (5 Point Choice)','size'=>1,'SPSStype'=>'F','Scale'=>3),
'F'=>Array('name'=>'Array (Flexible Labels)','size'=>1,'SPSStype'=>'F'),
'1'=>Array('name'=>'Array (Flexible Labels) Dual Scale','size'=>1,'SPSStype'=>'F'),
'H'=>Array('name'=>'Array (Flexible Labels) by Column','size'=>1,'SPSStype'=>'F'),
'E'=>Array('name'=>'Array (Increase, Same, Decrease)','size'=>1,'SPSStype'=>'F'),
'E'=>Array('name'=>'Array (Increase, Same, Decrease)','size'=>1,'SPSStype'=>'F','Scale'=>2),
'C'=>Array('name'=>'Array (Yes/No/Uncertain)','size'=>1,'SPSStype'=>'F'),
'X'=>Array('name'=>'Boilerplate Question','size'=>1,'SPSStype'=>'A','hide'=>1),
'D'=>Array('name'=>'Date','size'=>10,'SPSStype'=>'SDATE'),
Expand All @@ -62,11 +62,11 @@
'M'=>Array('name'=>'Multiple Options','size'=>1,'SPSStype'=>'F'),
'P'=>Array('name'=>'Multiple Options With Comments','size'=>1,'SPSStype'=>'F'),
'Q'=>Array('name'=>'Multiple Short Text','size'=>1,'SPSStype'=>'F'),
'N'=>Array('name'=>'Numerical Input','size'=>3,'SPSStype'=>'F'),
'N'=>Array('name'=>'Numerical Input','size'=>3,'SPSStype'=>'F','Scale'=>3),
'R'=>Array('name'=>'Ranking','size'=>1,'SPSStype'=>'F'),
'S'=>Array('name'=>'Short free text','size'=>1,'SPSStype'=>'F'),
'Y'=>Array('name'=>'Yes/No','size'=>1,'SPSStype'=>'F'),
':'=>Array('name'=>'Multi flexi numbers','size'=>1,'SPSStype'=>'F'),
':'=>Array('name'=>'Multi flexi numbers','size'=>1,'SPSStype'=>'F','Scale'=>3),
';'=>Array('name'=>'Multi flexi text','size'=>1,'SPSStype'=>'A'),
);

Expand Down Expand Up @@ -299,7 +299,7 @@
foreach ($fields as $field)
{
$answers=array();
if (strpos("!LO",$field['LStype']) !== false) {
if (strpos("!LOR",$field['LStype']) !== false) {
if (substr($field['code'],-5) == 'other' || substr($field['code'],-7) == 'comment') {
//We have a comment field, so free text
} else {
Expand Down Expand Up @@ -416,7 +416,19 @@
}
}
}
}
}

foreach ($fields as $field){
if($field['scale']!=='') {
switch ($field['scale']) {
case 2:
echo "VARIABLE LEVEL {$field['id']}(ORDINAL).\n";
break;
case 3:
echo "VARIABLE LEVEL {$field['id']}(SCALE).\n";
}
}
}

//Rename the Variables (in case somethings goes wrong, we still have the OLD values
foreach ($fields as $field){
Expand Down
5 changes: 5 additions & 0 deletions common.php
Expand Up @@ -3456,6 +3456,11 @@ function questionAttributes($returnByName=false)
"types"=>"15ABCEFGHKLMNOPRWYZ!:",
"help"=>$clang->gT('Insert a page break before this question in printable view by setting this to 1.'),
"caption"=>$clang->gT('Insert page break in printable view'));

$qattributes["scale_export"]=array(
"types"=>"!LOFWZWH1:MPOGYCE",
"help"=>$clang->gT("1=nominal 2=ordinal 3=scale."),
"caption"=>$clang->gT('Export scale type 1=nominal 2=ordinal 3=scale.'));
//This builds a more useful array (don't modify)
if ($returnByName!=true)
{
Expand Down

0 comments on commit 7e4b2d7

Please sign in to comment.