Skip to content

Commit

Permalink
Merge pull request #1344 from evarisk-micka/add_info_import
Browse files Browse the repository at this point in the history
#1131 [Tools] add: ref_ext and import_key when import
  • Loading branch information
nicolas-eoxia authored Jul 6, 2023
2 parents 94c1083 + cfbd2a8 commit bc6a2c1
Showing 1 changed file with 24 additions and 19 deletions.
43 changes: 24 additions & 19 deletions view/dolismqtools.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
}

require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
require_once DOL_DOCUMENT_ROOT . '/core/lib/ticket.lib.php';

require_once __DIR__ . '/../class/answer.class.php';
require_once __DIR__ . '/../class/question.class.php';
Expand All @@ -44,7 +45,7 @@
// Global variables definitions
global $conf, $db, $langs, $user;

saturne_load_langs();
saturne_load_langs(['exports']);

// Get parameters
$action = GETPOST('action', 'alpha');
Expand Down Expand Up @@ -204,37 +205,38 @@
}
$fileName = preg_replace('/\.zip/', '.json', $_FILES['dataMigrationImportZipFile']['name'][0]);

$json = file_get_contents($fileDir . $fileName);
$dolismqExportArray = json_decode($json, true);
$error = 0;

$json = file_get_contents($fileDir . $fileName);
$dolismqExportArray = json_decode($json, true);
$importKey = dol_print_date($now, 'dayhourlog');
$idCorrespondanceArray = [];

$error = 0;
$error = 0;

if (is_array($dolismqExportArray['questions']) && !empty($dolismqExportArray['questions'])) {
foreach ($dolismqExportArray['questions'] as $questionSingle) {

$question->type = $questionSingle['type'];
$question->label = $questionSingle['label'];
$question->description = $questionSingle['description'];
$question->show_photo = $questionSingle['show_photo'];
$question->ref_ext = $questionSingle['ref'];
$question->type = $questionSingle['type'];
$question->label = $questionSingle['label'];
$question->description = $questionSingle['description'];
$question->show_photo = $questionSingle['show_photo'];
$question->authorize_answer_photo = $questionSingle['authorize_answer_photo'];
$question->enter_comment = $questionSingle['enter_comment'];
$question->status = $questionSingle['status'];
$question->enter_comment = $questionSingle['enter_comment'];
$question->status = $questionSingle['status'];
$question->import_key = $importKey;

$questionId = $question->create($user);

if ($questionId > 0) {
$idCorrespondanceArray['question'][$questionSingle['rowid']] = $questionId;
if (array_key_exists('answers', $questionSingle) && !empty($questionSingle['answers'])) {
foreach ($questionSingle['answers'] as $answerSingle) {
$answer->status = $answerSingle['status'];
$answer->value = $answerSingle['value'];
$answer->position = $answerSingle['position'];
$answer->pictogram = $answerSingle['pictogram'];
$answer->color = $answerSingle['color'];
$answer->ref_ext = $answerSingle['ref'];
$answer->status = $answerSingle['status'];
$answer->value = $answerSingle['value'];
$answer->position = $answerSingle['position'];
$answer->pictogram = $answerSingle['pictogram'];
$answer->color = $answerSingle['color'];
$answer->fk_question = $questionId;
$answer->import_key = $importKey;

$answerId = $answer->create($user);

Expand All @@ -251,11 +253,13 @@

if (is_array($dolismqExportArray['sheets']) && !empty($dolismqExportArray['sheets'])) {
foreach ($dolismqExportArray['sheets'] as $sheetSingle) {
$sheet->ref_ext = $sheetSingle['ref'];
$sheet->label = $sheetSingle['label'];
$sheet->description = $sheetSingle['description'];
$sheet->element_linked = $sheetSingle['element_linked'];
$sheet->mandatory_questions = $sheetSingle['mandatory_questions'];
$sheet->status = $sheetSingle['status'];
$sheet->import_key = $importKey;

$sheetMandatoryQuestions = json_decode($sheetSingle['mandatory_questions']);

Expand Down Expand Up @@ -303,6 +307,7 @@

$questionCount = count($dolismqExportArray['questions']);
setEventMessage($langs->transnoentities("ImportFinishWith", $langs->trans('Questions'), $error, $questionCount));
setEventMessage($langs->transnoentities("FileWasImported", $importKey));
}
}
}
Expand Down

0 comments on commit bc6a2c1

Please sign in to comment.