public function parseStudents($str) { $students = array(); $manager = $this->getContainer()->get('doctrine.orm.entity_manager'); $studentRepo = $manager->getRepository('TSK\\StudentBundle\\Entity\\Student'); $studentStatusRepo = $manager->getRepository('TSK\\StudentBundle\\Entity\\StudentStatus'); $activeStatus = $studentStatusRepo->findOneBy(array('name' => 'active')); $studentLegacyIds = preg_split('/;/', $str); foreach ($studentLegacyIds as $studentLegacyId) { $studentLegacyId = preg_replace('/-/', '', $studentLegacyId); $student = $studentRepo->findOneBy(array('legacyStudentId' => $studentLegacyId)); if (!$student) { $student = new Student(); $student->setLegacyStudentId($studentLegacyId); $contact = new Contact(); $contact->setFirstName('dummy'); $contact->setLastName('record'); $contact->setOrganization($this->org); $student->setContact($contact); $student->setStudentStatus($activeStatus); $manager->persist($student); $manager->flush(); } $students[] = $student; } return $students; }