/**
  * @Route("/user/unban/{id}", name="admin_user_unban", requirements={"id" = "\d+"})
  * @Template()
  * @ParamConverter("Event", class="ConnectionUserBundle:User")
  */
 public function unBanAction(User $user)
 {
     $em = $this->getDoctrine()->getManager();
     $user->setEnabled(1);
     $em->persist($user);
     $em->flush();
     return $this->redirect($this->generateUrl('admin_user_index'));
 }
 /**
  * {@inheritDoc}
  */
 public function setEnabled($boolean)
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'setEnabled', array($boolean));
     return parent::setEnabled($boolean);
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     /* @var $em \Doctrine\ORM\EntityManager */
     $em = $this->getContainer()->get('doctrine')->getManager();
     $userRepo = $em->getRepository('ConnectionUserBundle:User');
     $countryRepo = $em->getRepository('ConnectionCoreBundle:Country');
     $stateRepo = $em->getRepository('ConnectionCoreBundle:State');
     $genderRepo = $em->getRepository('ConnectionUserBundle:Profile\\Gender');
     $eventCategoryRepo = $em->getRepository('ConnectionEventBundle:Category');
     $userManager = $this->getContainer()->get('fos_user.user_manager');
     $rootDir = $this->getContainer()->get('kernel')->getRootDir() . '/../web/';
     $userArray = $this->_getUserArray();
     foreach ($userArray as $userItem) {
         $output->writeln('Creating user: '******'username']);
         $user = $userRepo->findOneBy(array('username' => $userItem['username']));
         if ($user) {
             $em->remove($user);
             $em->flush();
         }
         $email = strtolower($userItem['username']) . '@mail.com';
         $user = new User();
         $user->setUsername($userItem['username']);
         $user->setEmail($email);
         $user->setPlainPassword('123456');
         $user->setEnabled(true);
         $profile = new Profile();
         $gender = $genderRepo->find($userItem['profile']['gender']);
         $profile->setGender($gender);
         $seek = $genderRepo->find($userItem['profile']['seek']);
         $profile->setSeek($seek);
         $profile->setBirthdate($userItem['profile']['birthdate']);
         $country = $countryRepo->findOneBy(array('iso' => $userItem['profile']['country']));
         $profile->setCountry($country);
         $state = $stateRepo->findOneBy(array('name' => $userItem['profile']['state']));
         $profile->setState($state);
         $user->setProfile($profile);
         $em->persist($user);
         $em->flush();
         foreach ($userItem['events'] as $eventItem) {
             $event = new Event();
             $event->setContactName($userItem['username']);
             $event->setTitle($eventItem['title']);
             $event->setDescription($eventItem['description']);
             $event->setEventDate($eventItem['date']);
             $event->setEmail($email);
             $event->setPhone('12345678');
             $event->setUser($user);
             $collection = new ArrayCollection();
             foreach ($eventItem['categories'] as $categoryItem) {
                 $category = $eventCategoryRepo->findOneBy(array('name' => $categoryItem));
                 $collection->add($category);
             }
             $event->setCategory($collection);
             $image = new Image();
             $imageName = $userItem['username'] . 'Event.jpeg';
             $imagePath = 'uploads/user/event/' . $user->getId();
             $pathFrom = $rootDir . 'uploads/user/fixtures/' . $imageName;
             $pathTo = $rootDir . $imagePath . '/' . $imageName;
             mkdir($rootDir . $imagePath);
             copy($pathFrom, $pathTo);
             $image->setName($imageName);
             $image->setPath('/' . $imagePath . '/' . $imageName);
             $event->setImage($image);
             $em->persist($event);
             $em->flush();
         }
         $gallery = $user->getGalleries()->first();
         $gallery->setUser($user);
         $gallery->setTitle('Profile Images');
         $gallery->setDefault(true);
         $image = new Image();
         $imageName = $userItem['username'] . '.jpeg';
         $imagePath = 'uploads/user/profile/' . $user->getId();
         $pathFrom = $rootDir . 'uploads/user/fixtures/' . $imageName;
         $pathTo = $rootDir . $imagePath . '/' . $imageName;
         mkdir($rootDir . $imagePath);
         copy($pathFrom, $pathTo);
         $image->setName($imageName);
         $image->setPath('/' . $imagePath . '/' . $imageName);
         $profile->setAvatar('/' . $imagePath . '/' . $imageName);
         $image->setGallery($gallery);
         $collection = new ArrayCollection();
         $collection->add($image);
         $gallery->setImages($collection);
         $em->persist($gallery);
         $em->flush();
     }
 }