示例#1
0
 /**
  * Transforms an object to a string (id).
  *
  * @param  User|null $user
  * @return string
  */
 public function transform($user)
 {
     if (null === $user) {
         return '';
     }
     return $user->getId();
 }
示例#2
0
 /**
  * Показывает регистрационную форму фармкомпаний если HTTP-метод GET. Обрабатывает форму если HTTP-метод POST
  *
  * @Route("/pharm-register", name = "pharm_register")
  */
 public function pharmRegisterAction()
 {
     $em = $this->getDoctrine()->getManager();
     $company = new Company();
     $builder = $this->createFormBuilder($company);
     $builder->add('title', null, array('label' => 'Название компании'))->add('body', null, array('label' => 'Описание', 'attr' => array('class' => 'ckeditor_less')))->add('phone', null, array('label' => 'Телефон'))->add('fax', null, array('label' => 'Факс'))->add('website', null, array('label' => 'Сайт'))->add('email', null, array('label' => 'Е-mail'))->add('legalAddress', null, array('label' => 'Юридический адрес'))->add('postAddress', null, array('label' => 'Фактический адрес'))->add('imageFile', 'iphp_file', array('label' => 'Загрузить логотип', 'required' => false))->add('firstName', 'text', array('label' => 'Имя', 'mapped' => false, 'constraints' => new NotBlank()))->add('lastName', 'text', array('label' => 'Фамилия', 'mapped' => false, 'constraints' => new NotBlank()))->add('contactPersonPosition', null, array('label' => 'Должность'))->add('username', 'email', array('label' => 'E-mail', 'mapped' => false, 'constraints' => new NotBlank()))->add('password', 'password', array('label' => 'Придумайте пароль', 'mapped' => false, 'constraints' => new NotBlank()));
     $form = $builder->getForm();
     $request = $this->getRequest();
     if ($request->isMethod('POST')) {
         $form->bind($request);
         if ($form->isValid()) {
             $company->setEnabled(false);
             $company->setContactPerson($request->request->get('form')['firstName'] . ' ' . $request->request->get('form')['lastName']);
             $em->persist($company);
             $user = new User();
             $user->setUsername($request->request->get('form')['username'])->setPassword($request->request->get('form')['password'])->setFirstName($request->request->get('form')['firstName'])->setLastName($request->request->get('form')['lastName'])->setRoles('ROLE_UNCONFIRMED')->setCompany($company);
             $em->persist($user);
             $link = new ThematicGroupLink();
             $link->setUser($user)->setThematicGroup($company)->setModerator(true);
             $em->persist($link);
             $em->flush();
             $message = \Swift_Message::newInstance()->setSubject('Вы зарегистрировались на портале «Evrika.ru»')->setContentType('text/html')->setCharset('utf-8')->setFrom('*****@*****.**', 'Редакция портала «Evrika.ru»')->setTo($user->getUsername())->setBody($this->renderView('EvrikaMainBundle:Email:pharm_registration.html.twig', array('company' => $company, 'user' => $user)));
             $headers = $message->getHeaders();
             $headers->addTextHeader('X-Mailru-Msgtype', 'pharm_registered');
             $this->get('mailer')->send($message);
             $message = \Swift_Message::newInstance()->setSubject('Новая фармкопания')->setContentType('text/html')->setCharset('utf-8')->setFrom('*****@*****.**', 'Уведомление «Evrika.ru»')->setTo($this->container->getParameter('manager_emails'))->setBody($this->renderView('EvrikaMainBundle:Email:pharm_registration_notice.html.twig', array('company' => $company)));
             $this->get('mailer')->send($message);
             $this->get('session')->getFlashBag()->add('completed', 'yes');
             return $this->redirect($this->generateUrl('pharm_register'));
         }
     }
     return $this->render('EvrikaMainBundle:Auth:pharm_registration_page.html.twig', array('form' => $form->createView()));
 }
示例#3
0
 public function setAuthor(User $author)
 {
     $this->author = $author;
     $this->authorName = $author->__toString();
     return $this;
 }