Esempio n. 1
0
 /**
  * Import TOEFL scores from ETS formated flat file
  * @param FormInput $input
  */
 protected function etstoeflScores($input)
 {
     $fileArr = $input->get('file');
     $file = file($fileArr['tmp_name'], FILE_IGNORE_NEW_LINES);
     switch (strlen($file[0])) {
         case 590:
             $scores = $this->parseTOEFLVersion1($file);
             break;
         case 900:
             $scores = $this->parseTOEFLVersion2($file);
             break;
         default:
             $this->addMessage('error', "Unrecognized TOEFL format:  ({$fileArr['name']}) has " . strlen($file[0]) . ' characters per line.');
             return false;
     }
     $new = 0;
     $count = 0;
     //we have to look for cases of the same score appearing twice in the same file
     $used = array();
     foreach ($scores as $arr) {
         $count++;
         $parameters = array('registrationNumber' => $arr['registrationNumber'], 'testMonth' => $arr['testMonth'], 'testYear' => $arr['testYear']);
         //these fields should not be null, but sometimes ETS messes it up
         $requiredFields = array('id', 'registrationNumber', 'testMonth', 'testYear', 'lastName', 'birthDate', 'nativeCountry', 'nativeLanguage', 'testDate', 'testType');
         foreach ($arr as $name => $value) {
             if (in_array($name, $requiredFields) and is_null($value)) {
                 $this->addMessage('error', "{$name} was not set on line {$count} for {$arr['firstName']} {$arr['lastName']}");
                 $this->redirectPath('manage/scores');
             }
         }
         if (!($score = $this->_em->getRepository('\\Jazzee\\Entity\\TOEFLScore')->findOneBy($parameters)) and !in_array($arr['registrationNumber'] . $arr['testMonth'] . $arr['testYear'], $used)) {
             $used[] = $arr['registrationNumber'] . $arr['testMonth'] . $arr['testYear'];
             $score = new \Jazzee\Entity\TOEFLScore();
             $score->setRegistrationNumber($arr['registrationNumber'], $arr['testMonth'], $arr['testYear']);
             $score->setDepartmentCode($arr['departmentCode']);
             $score->setFirstName($arr['firstName']);
             $score->setMiddleName($arr['middleName']);
             $score->setLastName($arr['lastName']);
             $score->setBirthDate($arr['birthDate']);
             if (!is_null($arr['gender'])) {
                 $score->setGender($arr['gender']);
             }
             $score->setNativeCountry($arr['nativeCountry']);
             $score->setNativeLanguage($arr['nativeLanguage']);
             $score->setTestDate($arr['testDate']);
             $score->setTestType($arr['testType']);
             $score->setListeningIndicator($arr['listeningIndicator']);
             $score->setSpeakingIndicator($arr['speakingIndicator']);
             $score->setIBTListening($arr['IBTListening']);
             $score->setIBTReading($arr['IBTReading']);
             $score->setIBTSpeaking($arr['IBTSpeaking']);
             $score->setIBTWriting($arr['IBTWriting']);
             $score->setIBTTotal($arr['IBTTotal']);
             $score->setTSEScore($arr['TSEScore']);
             $score->setListening($arr['listening']);
             $score->setWriting($arr['writing']);
             $score->setReading($arr['reading']);
             $score->setEssay($arr['essay']);
             $score->setTotal($arr['total']);
             $score->setTimesTaken($arr['timesTaken']);
             $score->setOffTopic($arr['offTopic']);
             $new++;
             $this->_em->persist($score);
         }
     }
     $this->addMessage('success', count($scores) . " scores read from file, {$new} of them were new.");
     $this->redirectPath('manage/scores');
 }