Skip to content

Commit

Permalink
Fixed issue #6502: Unable to import multi-lang surveys (.txt)
Browse files Browse the repository at this point in the history
Dev: groups are now exported with a unique identifier.
Dev: older multi-lang .txt files should also be properly
Dev: imported. Here we make up an identifier during
Dev: import.
  • Loading branch information
mfaber committed Oct 1, 2013
1 parent a3089ad commit 91068ed
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
35 changes: 23 additions & 12 deletions application/helpers/admin/import_helper.php
Expand Up @@ -4384,34 +4384,45 @@ function TSVImportSurvey($sFullFilepath)
// insert group
$insertdata = array();
$insertdata['sid'] = $iNewSID;
$gname = ((isset($row['name']) ? $row['name'] : 'G' . $gseq));
$gname = ((!empty($row['name']) ? $row['name'] : 'G' . $gseq));
$glang = (!empty($row['language']) ? $row['language'] : $baselang);
// when a multi-lang tsv-file without information on the group id/number (old style) is imported,
// we make up this information by giving a number 0..[numberofgroups-1] per language.
// the number and order of groups per language should be the same, so we can also import these files
if ($lastglang!=$glang) //reset couner on language change
{
$iGroupcounter=0;
}
$lastglang=$glang;
//use group id/number from file. if missing, use an increasing number (s.a.)
$sGroupseq=(!empty($row['type/scale']) ? $row['type/scale'] : 'G'.$iGroupcounter++);
$insertdata['group_name'] = $gname;
$insertdata['grelevance'] = (isset($row['relevance']) ? $row['relevance'] : '');
$insertdata['description'] = (isset($row['text']) ? $row['text'] : '');
$insertdata['language'] = (isset($row['language']) ? $row['language'] : $baselang);
// For multi numeric survey : same title
if (isset($ginfo[$gname]))
$insertdata['language'] = $glang;

// For multi language survey: same gid/sort order across all languages
if (isset($ginfo[$sGroupseq]))
{
$gseq = $ginfo[$gname]['group_order'];
$gid = $ginfo[$gname]['gid'];
$gid = $ginfo[$sGroupseq]['gid'];
$insertdata['gid'] = $gid;
$insertdata['group_order'] = $gseq;
$insertdata['group_order'] = $ginfo[$sGroupseq]['group_order'];
}
else
{
{
$insertdata['group_order'] = $gseq;
}
$newgid = Groups::model()->insertRecords($insertdata);
if(!$newgid){
$results['error'][] = $clang->gT("Error")." : ".$clang->gT("Failed to insert group").". ".$clang->gT("Text file row number ").$rownumber." (".$gname.")";
break;
}
if (!isset($ginfo[$gname]))
if (!isset($ginfo[$sGroupseq]))
{
$results['groups']++;
$gid=$newgid; // save this for later
$ginfo[$gname]['gid'] = $gid;
$ginfo[$gname]['group_order'] = $gseq++;
$gid=$newgid;
$ginfo[$sGroupseq]['gid']=$gid;
$ginfo[$sGroupseq]['group_order']=$gseq++;
}
$qseq=0; // reset the question_order
break;
Expand Down
2 changes: 2 additions & 0 deletions application/helpers/expressions/em_manager_helper.php
Expand Up @@ -8760,6 +8760,8 @@ static public function &TSVSurveyExport($sid)

$row = array();
$row['class'] = 'G';
//create a group code to allow proper importing of multi-lang survey TSVs
$row['type/scale']='G'.$gseq;
$row['name'] = $ginfo['group_name'];
$row['relevance'] = $grelevance;
$row['text'] = $gtext;
Expand Down

1 comment on commit 91068ed

@Shnoulle
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not tested (in my todo list), but great \o/

Please sign in to comment.