/**
  * @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'));
 }
 /**
  * @Route("/message/hi/{id}", name="user_message_hi", requirements={"id" = "\d+"})
  * @ParamConverter("User", class="ConnectionUserBundle:User")
  */
 public function removeFavoriteUserAction(User $recipient)
 {
     /* @var $user \Connection\UserBundle\Entity\User */
     $sender = $this->getUser();
     if ($sender->getId() == $recipient->getId()) {
         throw new \Exception('You cannot send message to yourself');
     }
     $threadBuilder = $this->get('fos_message.composer')->newThread();
     $threadBuilder->addRecipient($recipient)->setSender($sender)->setSubject('Hi')->setBody('Hi!');
     $senderService = $this->get('fos_message.sender');
     $senderService->send($threadBuilder->getMessage());
     return new Response();
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $username = $input->getArgument('name');
     $password = $input->getArgument('password');
     $userService = $this->getContainer()->get('connection_user.social.user');
     $user = new User();
     $user->setUsername($username);
     $user->setEmail($username . "@gmail.com");
     $user->setPassword($userService->generatePassword($password, $user));
     $user->setRoles(array('ROLE_USER', 'ROLE_VERIFIED_USER', 'ROLE_ADMIN'));
     $user->setProfile(new Profile());
     $user->setEnabled(1);
     /* @var $em \Doctrine\ORM\EntityManager */
     $em = $this->getContainer()->get('doctrine')->getManager();
     $em->persist($user);
     $em->flush();
     $output->write("Admin User Created: UserName: {$username}, Password: {$password} ");
 }
 /**
  * {@inheritDoc}
  */
 public function __toString()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, '__toString', array());
     return parent::__toString();
 }
 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();
     }
 }