private function importQuestions(\SPSSReader $SPSS, Dataset $dataset) { $toFlush = array(); foreach ($SPSS->variables as $var) { if ($var->isExtended) { continue; } $index = isset($SPSS->extendedNames[$var->shortName]) ? $SPSS->extendedNames[$var->shortName] : $var->name; // -- Split question id -- $questionSplitted = explode(' ', mb_convert_encoding($var->label, 'UTF-8', 'ISO-8859-7'), 2); $questionSplitted[0] = rtrim($questionSplitted[0], '.'); $tmpSplit = explode('.', $questionSplitted[0], 2); if ($tmpSplit[0] == '3') { $tmpSplit[0] = '9'; } else { if ($tmpSplit[0] == '4') { $tmpSplit[0] = '8'; } else { if ($tmpSplit[0] == '5') { $tmpSplit[0] = '10'; } else { if ($tmpSplit[0] == '6') { $tmpSplit[0] = '12'; } else { if ($tmpSplit[0] == '7') { $tmpSplit[0] = '13'; } else { if ($tmpSplit[0] == '8') { $tmpSplit[0] = '19'; } else { if ($tmpSplit[0] == '9') { $tmpSplit[0] = '23'; } else { if ($tmpSplit[0] == '10') { $tmpSplit[0] = '24'; } else { if ($tmpSplit[0] == '11') { $tmpSplit[0] = '25'; } else { if ($tmpSplit[0] == '12') { $tmpSplit[0] = '36'; } else { if ($tmpSplit[0] == '13') { $tmpSplit[0] = '37'; } else { if ($tmpSplit[0] == '14') { $tmpSplit[0] = '38'; } else { if ($tmpSplit[0] == '15') { $tmpSplit[0] = '53'; } else { if ($tmpSplit[0] == '16') { $tmpSplit[0] = '56'; } } } } } } } } } } } } } } // C $questionSplitted[0] = implode('.', $tmpSplit); // ----------------------- $allQuestions = $this->doctrine->getRepository('AppBundle\\Entity\\Question')->findAll(); foreach ($allQuestions as $curQuestion) { $this->allQuestions[$curQuestion->getQuestionId()] = $curQuestion; } $allAnswers = $this->doctrine->getRepository('AppBundle\\Entity\\Answer')->findAll(); foreach ($allAnswers as $curAnswer) { $this->allAnswers[$curAnswer->getQuestion()->getQuestionId() . '_' . $curAnswer->getAnswerId()] = $curAnswer; } if (!isset($this->allQuestions[$questionSplitted[0]])) { $question = new Question(); $question->setQuestionId($questionSplitted[0]); $question->setQuestion($questionSplitted[1]); $question->setDataset($dataset); $this->allQuestions[$questionSplitted[0]] = $question; } else { $question = $this->allQuestions[$questionSplitted[0]]; $question->getAnswers()->clear(); } if (!$this->isDimension($question->getQuestionId())) { $this->doctrine->getManager()->persist($question); $toFlush[] = $question; $this->questions[$index] = $question; } else { $this->dimensions[$index] = $question; } foreach ($var->valueLabels as $lkey => $lval) { if (!isset($this->allAnswers[$questionSplitted[0] . '_' . $lkey])) { $answer = new Answer(); $answer->setAnswerId($lkey); $this->allAnswers[$questionSplitted[0] . '_' . $lkey] = $answer; } else { $answer = $this->allAnswers[$questionSplitted[0] . '_' . $lkey]; } $answer->setAnswer(mb_convert_encoding($lval, 'UTF-8', 'ISO-8859-7')); $answer->setQuestion($question); $question->getAnswers()->add($answer); if (!$this->isDimension($question->getQuestionId())) { $this->doctrine->getManager()->persist($answer); $toFlush[] = $answer; } } } if (count($toFlush) > 0) { $this->doctrine->getManager()->flush($toFlush); } }