Skip to content
Permalink
Browse files

Fixed issue #6501 : Import excel with same title for 2 group make Dup…

…licate entry

Fixed issue : Import excel make multi sub question with the same code for additional langage
Dev : put an error control on group insertion, don't change excel system : group title have to be the same
Dev : use $gid in fullqname to have same code for question on different group.
Dev : some warning for attribute or default value, don't delete the survey
  • Loading branch information...
Shnoulle committed Aug 19, 2012
1 parent 7fb3d28 commit 11365e29ae1f0766d95d657ea051322bcc9b57f9
Showing with 54 additions and 32 deletions.
  1. +54 −32 application/helpers/admin/import_helper.php
@@ -4307,7 +4307,11 @@ function ExcelImportSurvey($sFullFilepath)
}
$result = Surveys_languagesettings::model()->insertNewSurvey($insertdata) or safeDie("<br />".$clang->gT("Import of this survey file failed")."<br />");
$result = Surveys_languagesettings::model()->insertNewSurvey($insertdata);//
if(!$result){
$results['error'][] = $clang->gT("Error")." : ".$clang->gT("Failed to insert survey language");
break;
}
$results['languages']++;
}
@@ -4336,7 +4340,7 @@ function ExcelImportSurvey($sFullFilepath)
$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]))
{
$gseq = $ginfo[$gname]['group_order'];
@@ -4348,19 +4352,21 @@ function ExcelImportSurvey($sFullFilepath)
{
$insertdata['group_order'] = $gseq;
}
$newgid = Groups::model()->insertRecords($insertdata) or safeDie($clang->gT('Error').": Failed to insert group<br />\<br />\n");
$newgid = Groups::model()->insertRecords($insertdata);
if(!$newgid){
$results['error'][] = $clang->gT("Error")." : ".$clang->gT("Failed to insert group").". ".$clang->gT("Excel row number ").$rownumber." (".$gname.")";
break;
}
if (!isset($ginfo[$gname]))
{
$results['groups']++;
$gid=$newgid; // save this for later
$ginfo[$gname]['gid'] = $gid;
$ginfo[$gname]['group_order'] = $gseq++;
}
$qseq=0; // reset the question_order
break;
case 'Q':
// insert question
$insertdata = array();
@@ -4380,35 +4386,35 @@ function ExcelImportSurvey($sFullFilepath)
$insertdata['same_default'] = (isset($row['same_default']) ? $row['same_default'] : 0);
$insertdata['parent_qid'] = 0;
if (isset($qinfo[$qname]))
// For multi numeric survey : same name, add the gid to have same name on different gid. Bad for EM.
$fullqname="G{$gid}_".$qname;
if (isset($qinfo[$fullqname]))
{
$qseq = $qinfo[$qname]['question_order'];
$qid = $qinfo[$qname]['qid'];
$qseq = $qinfo[$fullqname]['question_order'];
$qid = $qinfo[$fullqname]['qid'];
$insertdata['qid'] = $qid;
$insertdata['question_order'] = $qseq;
}
else
{
$insertdata['question_order'] = $qseq;
}
$result = Questions::model()->insertRecords($insertdata); //or safeDie ($clang->gT("Error").": Failed to insert question<br />");
// Insert question and keep the qid for multi language survey
$result = Questions::model()->insertRecords($insertdata);
if(!$result){
$results['error'][] = $clang->gT("Error")." : ".$clang->gT("Could not insert question").". ".$clang->gT("Excel row number ").$rownumber." (".$qname.")";
break;
}
$newqid = $result;
if (!isset($qinfo[$qname]))
if (!isset($qinfo[$fullqname]))
{
$results['questions']++;
$qid=$newqid; // save this for later
$qinfo[$qname]['qid'] = $qid;
$qinfo[$qname]['question_order'] = $qseq++;
$qinfo[$fullqname]['qid'] = $qid;
$qinfo[$fullqname]['question_order'] = $qseq++;
}
$aseq=0; //reset the answer sortorder
$sqseq = 0; //reset the sub question sortorder
// insert question attributes
foreach ($row as $key=>$val)
{
@@ -4435,7 +4441,11 @@ function ExcelImportSurvey($sFullFilepath)
$insertdata['language'] = (isset($row['language']) ? $row['language'] : $baselang);
$insertdata['attribute'] = $key;
$insertdata['value'] = $val;
$result=Question_attributes::model()->insertRecords($insertdata);
$result=Question_attributes::model()->insertRecords($insertdata);//
if(!$result){
$results['importwarnings'][] = $clang->gT("Warning")." : ".$clang->gT("Failed to insert question attribute").". ".$clang->gT("Excel row number ").$rownumber." ({$key})";
break;
}
$results['question_attributes']++;
}
break;
@@ -4449,19 +4459,22 @@ function ExcelImportSurvey($sFullFilepath)
$insertdata['qid'] = $qid;
$insertdata['language'] = (isset($row['language']) ? $row['language'] : $baselang);
$insertdata['defaultvalue'] = $row['default'];
$result = Defaultvalues::model()->insertRecords($insertdata) or safeDie ("Error: Failed to insert defaultvalue <br />");
$result = Defaultvalues::model()->insertRecords($insertdata);
if(!$result){
$results['importwarnings'][] = $clang->gT("Warning")." : ".$clang->gT("Failed to insert default value").". ".$clang->gT("Excel row number ").$rownumber;
break;
}
$results['defaultvalues']++;
}
$sqseq = 0;
break;
case 'SQ':
$sqname = (isset($row['name']) ? $row['name'] : 'SQ' . $sqseq);
if ($qtype == 'O' || $qtype == '|')
{
; // these are fake rows to show naming of comment and filecount fields
}
else if ($sqname == 'other' && ($qtype == '!' || $qtype == 'L'))
elseif ($sqname == 'other' && ($qtype == '!' || $qtype == 'L'))
{
// only want to set default value for 'other' in these cases - not a real SQ row
// TODO - this isn't working
@@ -4472,7 +4485,11 @@ function ExcelImportSurvey($sFullFilepath)
$insertdata['specialtype'] = 'other';
$insertdata['language'] = (isset($row['language']) ? $row['language'] : $baselang);
$insertdata['defaultvalue'] = $row['default'];
$result = Defaultvalues::model()->insertRecords($insertdata) or safeDie ("Error: Failed to insert defaultvalue <br />");
$result = Defaultvalues::model()->insertRecords($insertdata);
if(!$result){
$results['importwarnings'][] = $clang->gT("Warning")." : ".$clang->gT("Failed to insert default value").". ".$clang->gT("Excel row number ").$rownumber;
break;
}
$results['defaultvalues']++;
}
}
@@ -4492,23 +4509,25 @@ function ExcelImportSurvey($sFullFilepath)
$insertdata['language'] = (isset($row['language']) ? $row['language'] : $baselang);
$insertdata['mandatory'] = (isset($row['mandatory']) ? $row['mandatory'] : '');
$insertdata['scale_id'] = $scale_id;
$fullsqname = $qid . '_' . $sqname;
// For multi nueric language, qid is needed, why not gid. name is not unique.
$fullsqname = "G{$gid}Q{$qid}_{$sqname}";
if (isset($sqinfo[$fullsqname]))
{
$qseq = $sqinfo[$fullsqname]['question_order'];
$sqid = $sqinfo[$fullsqname]['sqid'];
$insertdata['question_order'] = $qseq;
// $insertdata['qid'] = $sqid; // this was causing key duplications - removing it seems to have fixed that
$insertdata['qid'] = $sqid;
}
else
{
$insertdata['question_order'] = $qseq;
}
$newsqid = Questions::model()->insertRecords($insertdata) or safeDie ($clang->gT("Error").": Failed to insert question<br />");
// Insert sub question and keep the sqid for multi language survey
$newsqid = Questions::model()->insertRecords($insertdata);
if(!$newsqid){
$results['error'][] = $clang->gT("Error")." : ".$clang->gT("Could not insert sub question").". ".$clang->gT("Excel row number ").$rownumber." (".$qname.")";
break;
}
if (!isset($sqinfo[$fullsqname]))
{
$sqinfo[$fullsqname]['question_order'] = $qseq++;
@@ -4526,7 +4545,11 @@ function ExcelImportSurvey($sFullFilepath)
$insertdata['scale_id'] = $scale_id;
$insertdata['language'] = (isset($row['language']) ? $row['language'] : $baselang);
$insertdata['defaultvalue'] = $row['default'];
$result = Defaultvalues::model()->insertRecords($insertdata) or safeDie ("Error: Failed to insert defaultvalue <br />");
$result = Defaultvalues::model()->insertRecords($insertdata);
if(!$result){
$results['importwarnings'][] = $clang->gT("Warning")." : ".$clang->gT("Failed to insert default value").". ".$clang->gT("Excel row number ").$rownumber;
break;
}
$results['defaultvalues']++;
}
}
@@ -4540,7 +4563,6 @@ function ExcelImportSurvey($sFullFilepath)
$insertdata['language']= (isset($row['language']) ? $row['language'] : $baselang);
$insertdata['assessment_value'] = (isset($row['relevance']) ? $row['relevance'] : '');
$insertdata['sortorder'] = ++$aseq;
$result = Answers::model()->insertRecords($insertdata); // or safeDie("Error: Failed to insert answer<br />");
if(!$result){
$results['error'][] = $clang->gT("Error")." : ".$clang->gT("Could not insert answer").". ".$clang->gT("Excel row number ").$rownumber;

0 comments on commit 11365e2

Please sign in to comment.
You can’t perform that action at this time.