public function registrationAction()
 {
     $userRegForm = new UserRegistrationForm($this->getEntityManager());
     $userRegForm->getInputFilter()->remove('roles');
     $userRegForm->get('submit')->setValue('Sign Up');
     $userRegForm->setAttribute('action', '/user/registration')->prepare();
     $request = $this->getRequest();
     if (!$request->isPost()) {
         return new ViewModel(array('userRegForm' => $userRegForm));
     }
     $userFormData = $request->getPost();
     $userRegForm->setData($userFormData);
     if (!$userRegForm->isValid()) {
         return new ViewModel(array('userRegForm' => $userRegForm));
     }
     $entityManager = $this->getEntityManager();
     $email = $entityManager->getRepository('Application\\Entity\\User')->findOneByEmail($userFormData['user']['email']);
     if (!empty($email)) {
         $this->flashmessenger()->addMessage('Email already exist.');
         return new ViewModel(array('userRegForm' => $userRegForm, 'messages' => $this->flashmessenger()->getMessages()));
     }
     $userEntity = new UserEntity();
     $userEntity->setEmail($userFormData['user']['email']);
     $userEntity->setPassword($userFormData['user']['password']);
     $userEntity->setCreatedAt();
     $userEntity->setUpdatedAt();
     $userEntity->addRole($entityManager->getRepository('Application\\Entity\\Role')->findOneById($userFormData['roles']['roles']));
     $entityManager->persist($userEntity);
     $entityManager->flush();
     $userProfileEntity = new UserProfileEntity();
     $userProfileEntity->setFirstName($userFormData['profile']['firstname']);
     $userProfileEntity->setLastName($userFormData['profile']['lastname']);
     $userProfileEntity->setPhone($userFormData['profile']['phone']);
     $userProfileEntity->setWebsite($userFormData['profile']['website']);
     $userProfileEntity->setBirthdate(new \DateTime($userFormData['profile']['birthdate']));
     $userProfileEntity->setUser($userEntity);
     $userProfileEntity->setCreatedAt();
     $userProfileEntity->setUpdatedAt();
     $entityManager->persist($userProfileEntity);
     $entityManager->flush();
     $entityManager->clear();
     return new ViewModel(array('userRegForm' => $userRegForm, 'messages' => $this->flashmessenger()->getMessages()));
 }
 /**
  * {@inheritDoc}
  */
 public function setUpdatedAt()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'setUpdatedAt', array());
     return parent::setUpdatedAt();
 }