<?php header('Content-type:text/html;charset=cp1251'); require 'SPSSReader.php'; $SPSS = new SPSSReader('data.sav'); ?> <!DOCTYPE html> <h2>Header</h2> <table border="1" width="100%"> <?php foreach ($SPSS->header as $key => $val) { ?> <tr> <th><?php echo $key; ?> </th> <td><?php echo $val; ?> </td> </tr> <?php } ?> </table> <h2>Variables view</h2> <table border="1" width="100%"> <tr>
private function importAnswers(\SPSSReader $SPSS, Dataset $dataset) { // Loop through the answers $SPSS->loadData(); for ($case = 0; $case < $SPSS->header->numberOfCases; $case++) { $user = new User(); $user->setSessionId(microtime()); $user->setAutoGenerated(true); $toFlush = array($user); foreach ($SPSS->variables as $var) { if ($var->isExtended) { continue; } $index = isset($SPSS->extendedNames[$var->shortName]) ? $SPSS->extendedNames[$var->shortName] : $var->name; if (isset($this->dimensions[$index])) { // This is a dimension attribute // Check if the dimension is a valid profile dimension if ($this->isValidProfileDimension($this->dimensions[$index]->getQuestionId())) { // Set the profile dimension $dimension = $this->dimensionIds[$this->dimensions[$index]->getQuestionId()]; $setter = 'set' . ucfirst($dimension); $user->{$setter}($this->mapProfileDimensionValue($dimension, $var->data[$case] === 'NaN' ? '' : $var->data[$case])); } } else { if ($this->questions[$index]) { // Create a UserAnswer $userAnswer = new UserAnswer(); $userAnswer->setDataset($dataset); $userAnswer->setUser($user); if ($var->data[$case] === 'NaN' || $var->data[$case] == '') { continue; } if (!isset($this->allAnswers[$this->questions[$index]->getQuestionId() . '_' . $var->data[$case]])) { continue; //throw new \Exception('Could not find user answer for '.$index.' ('.$var->data[$case].') given'); } $answer = $this->allAnswers[$this->questions[$index]->getQuestionId() . '_' . $var->data[$case]]; $userAnswer->setAnswer($answer); $this->doctrine->getManager()->persist($userAnswer); $toFlush[] = $userAnswer; } else { throw new \Exception('Answer to a non-existing question! ' . $index); } } } $this->doctrine->getManager()->persist($user); $this->doctrine->getManager()->flush($toFlush); foreach ($toFlush as $curEntity) { $this->doctrine->getManager()->detach($curEntity); // To save memory } } }