Пример #1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $container = $this->getContainer();
     $em = $container->get('doctrine')->getManager();
     $txt = file_get_contents('/var/www/teva/current/Teva2.csv');
     $array1 = explode("\n", $txt);
     foreach ($array1 as $val) {
         $array2 = explode(',', $val);
         //			$output->writeln($array2[4]);
         $user = $em->getRepository('LearningMainBundle:User')->findOneByUsername($array2[4]);
         if (!$user) {
             $fio = explode(' ', $array2[2]);
             if (isset($fio[2]) && $fio[2] && $fio[2] != '') {
                 $surname = $fio[2];
             } else {
                 $surname = '';
             }
             $pass = $this->generatePassword();
             if (strripos($array2[0], 'МП') !== false) {
                 $roles = 'ROLE_MEDREP;ROLE_NOTDEFAULT;';
             } elseif (strripos($array2[0], 'РМ') !== false) {
                 $roles = 'ROLE_MEDREP_ADMIN;ROLE_NOTDEFAULT;';
             } else {
                 $roles = '';
             }
             $user = new User();
             $city = $em->getRepository('LearningMainBundle:City')->find($array2[1]);
             $user->setUsername($array2[4]);
             $user->setCity($city);
             $user->setLastName($fio[0]);
             $user->setFirstName($fio[1]);
             $user->setSurName($surname);
             $user->setEnabled(true);
             $user->setPassword($pass);
             $user->setRoles($roles);
             $user->setEmailConfirmed(true);
             $em->persist($user);
             $em->flush($user);
             $em->refresh($user);
             $container->get('email.service')->send($user->getUsername(), array('LearningMainBundle:Email:registration.html.twig', array('user' => $user, 'password_orig' => $user->getPassword())), 'Благодарим за регистрацию на нашем портале!');
             $txt = "INSERT `user` SET username='******'4']}', city_id={$array2['1']} , lastName = '{$fio['0']}', firstName='{$fio['1']}', surName='{$surname}', password='******', roles='{$roles}';";
             $output->writeln($txt);
         }
     }
 }