/** * @Route("/contact", name="contact_route") * @param Request $request * @return \Symfony\Component\HttpFoundation\Response */ public function contactAction(Request $request) { /** @var AnonymousToken $token */ $token = $this->tokenStorage->getToken(); /** @var User $user */ $user = $token->getUser(); $contact = new Contact(); if ($user !== 'anon.') { /** @var User $user */ $contact->setEmail($user->getEmail()); $contact->setUser($user); } $emailGetParam = $request->query->get('email'); if (!empty($emailGetParam)) { $contact->setEmail($emailGetParam); } $form = $this->formFactory->createBuilder(FormType::class, $contact)->add('email', TextType::class, ['attr' => ['placeholder' => '*****@*****.**']])->add('message', TextareaType::class, ['attr' => ['maxlength' => 1000, 'rows' => 10]])->add('submit', SubmitType::class, ['label' => 'Envoyer'])->getForm(); $form->handleRequest($request); if ($form->isValid()) { $this->contactService->record($contact); $this->session->getFlashBag()->add(static::FLASH_BAG_EMAIL, $contact->getEmail()); return new RedirectResponse($this->router->generate('confirmation_contact_route')); } else { return new Response($this->templating->render('base.html.twig', [TwigNodeTemplateTreeSection::TEMPLATE_TREE_BRANCH => 'contact', 'form' => $form->createView()]), $form->isSubmitted() ? Response::HTTP_BAD_REQUEST : Response::HTTP_OK); } }
private function createFakeProvider() { $provider = new Provider(); $baseFaker = \Faker\Factory::create(); $provider->setName($baseFaker->company); $provider->setCountry($baseFaker->country); $provider->setType($this->getRandomType()); $provider->setDescription($baseFaker->text(500)); $provider->setUrl($baseFaker->url); $provider->setLastModification($baseFaker->dateTime); $nb = rand(1, 5); for ($x = 0; $x <= $nb; $x++) { $contactFaker = \Faker\Factory::create(); $c = new Contact(); $c->setProvider($provider); $c->setFirstName($contactFaker->firstName); $c->setLastName($contactFaker->lastName); $c->setGender(Personne::GENDER_MALE); $c->setEmail($contactFaker->email); $c->setTelephone($contactFaker->phoneNumber); $c->setDescription($contactFaker->text(300)); $c->setComment($contactFaker->text(100)); $this->output('create fake contact'); $this->em->persist($c); } $this->em->persist($provider); $this->output('create fake provider'); return $provider; }
public function testSetBody() { // new assistantHistory entity $contact = new Contact(); // Use the setBody method $contact->setBody("This is a long dummy text that is suppose to be somewhat long and somewhat short"); // Assert the result $this->assertEquals("This is a long dummy text that is suppose to be somewhat long and somewhat short", $contact->getBody()); }
/** * @Route("/api/contact/create") */ public function apiCreateAction() { $contact = new Contact(); $contact->setName('test'); $contact->setEmail('*****@*****.**'); $contact->setTelephone('0775872554'); $em = $this->getDoctrine()->getManager(); $em->persist($contact); $em->flush(); return new Response('Created product id ' . $contact->getId()); }
/** * @Route("/ajout/{id}", name="ajout") */ public function ajoutAction($id) { $em = $this->get("doctrine")->getManager(); //$contactrepo=$this->get("doctrine")->getRepository("AppBundle:Contact"); $userrepo = $this->get("doctrine")->getRepository("AppBundle:User"); $new = $userrepo->find($id); $user = $this->getUser(); $contact = new Contact(); $contact->setDateAjout(new \DateTime()); $contact->setProprietaire($user); $contact->setContact($new); $em->persist($contact); $em->flush(); return $this->redirectToRoute('affichage'); }
/** * @Route("/contact", name="info_contact") */ public function contact(Request $request) { $target = (new Person())->setEmail("*****@*****.**")->setFirstname("Vrijwilligerswerk")->setLastname("Roeselare"); $defaults = new Contact(); if ($user = $this->getUser()) { $defaults->setEmail($user->getEmail())->setName($user->getFirstname() . " " . $user->getLastname())->setTelephone($user->getTelephone()); } $form = $this->createForm(ContactType::class, $defaults); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $contact = $form->getData(); $info = array('subject' => "Contactformulier roeselarevrijwilligt.be", 'template' => 'contact.html.twig', 'txt/plain' => 'contact.txt.twig', 'data' => array('contact' => $contact)); $this->sendMail($target, $info); $this->addFlash('approve_message', "Uw bericht werd succesvol verstuurd. Bedankt! "); } return $this->render("info/contact.html.twig", ["form" => $form->createView()]); }
/** * @Route("/contacts", name="contacts") */ public function contactsAction(Request $request) { $contacts = new Contacts(); $formContacts = $this->createForm(new ContactsType(), $contacts); if ($request->isMethod('POST')) { $formContacts->handleRequest($request); if ($formContacts->isValid()) { $em = $this->getDoctrine()->getManager(); foreach ($contacts->getContacts() as $el) { $contact = new Contact(); $em->persist($contact->setEmail($el['email'])->setFirstName($el['firstName'])->setCreatedAt(new \DateTime())); $em->flush(); } return $this->render('default/success.html.twig'); } return $this->render('default/contacts-bootstrap.html.twig', array('form' => $formContacts->createView(), 'contacts' => $contacts, 'posted' => true)); } return $this->render('default/contacts-bootstrap.html.twig', array('form' => $formContacts->createView(), 'posted' => false)); }
protected function createAndPersistData() { for ($i = 1; $i <= self::CONTACTS_COUNT; $i++) { $contact = new Contact(); $contact->setName(sprintf('contact %s', $i)); $contact->setEmail(sprintf('*****@*****.**', $i)); $contact->setMobilePhone(rand(1111111111, 9999999999)); $contact->setPhone(rand(1111111111, 9999999999)); $this->manager->persist($contact); $this->setReference(sprintf('contact_%s', $i), $contact); } }
public function findAllContacts() { $contact = new Contact(); $contact->setName("Isaac"); $contact->setSurname("Fullana"); $contact->setSurname2("Melis"); $contact->setEmail("*****@*****.**"); $contact->setTelephone("665551517"); $contact2 = new Contact(); $contact2->setName("Raquel"); $contact2->setSurname("Torres"); $contact2->setSurname2("Rodriguez"); $contact2->setTelephone("12345678"); $contact2->setEmail("*****@*****.**"); return array($contact, $contact2); }
/** * Creates a form to delete a Contact entity. * * @param Contact $contact The Contact entity * * @return \Symfony\Component\Form\Form The form */ private function createDeleteForm(Contact $contact) { return $this->createFormBuilder()->setAction($this->generateUrl('contact_delete', array('id' => $contact->getId())))->setMethod('DELETE')->getForm(); }
/** * Deletes a Contact entity. * * @param Contact $contact Contact * * @throws NotFoundHttpException * * @return RedirectResponse * * @Route("/contact/delete/{id}", name="contact_delete") * @ParamConverter("contact", class="AppBundle:Contact") */ public function deleteAction(Contact $contact) { if ($this->getUser() !== $contact->getUser()) { throw $this->createNotFoundException('Unable to find Contact entity.'); } $em = $this->getDoctrine()->getManager(); $em->remove($contact); $em->flush(); return $this->redirect($this->generateUrl('contact_list')); }
/** * Set contact * * @param \AppBundle\Entity\Contact $contact * * @return Application */ public function setContact(\AppBundle\Entity\Contact $contact = null) { $this->contact = $contact; $this->contact->addApplication($this); return $this; }
/** * Creates a form to delete a Contact entity. * * @param Contact $contact The Contact entity * * @return \Symfony\Component\Form\Form The form */ private function createDeleteForm(Contact $contact = null) { if ($contact === null) { return $this->render('contact/not_found.html.twig'); } return $this->createFormBuilder()->setAction($this->generateUrl('crud_contact_delete', array('id' => $contact->getId())))->setMethod('DELETE')->getForm(); }
private function createContact($contactInfo) { $c = new Contact(); $c->setAdresse($contactInfo); $c->setFirstName('to complet'); $c->setLastName('to complet'); $c->setComment($contactInfo); $pattern_email = '/[a-z0-9_\\-\\+]+@[a-z0-9\\-]+\\.([a-z]{2,3})(?:\\.[a-z]{2})?/i'; preg_match_all($pattern_email, $contactInfo, $matches); if (isset($matches[0]) && isset($matches[0][0])) { if (filter_var($matches[0][0], FILTER_VALIDATE_EMAIL)) { $c->setEmail($matches[0][0]); } } $pattern_phone = '/\\b\\d{2,6}[-. ]?\\d{2,6}[-. ]?\\d{2,5}([-. ]?\\d{2,5})*([-. ]?\\d{2,5})*\\b/'; preg_match_all($pattern_phone, $contactInfo, $matches); if (isset($matches[0]) && isset($matches[0][0])) { $c->setTelephone($matches[0][0]); } $this->em->persist($c); $this->em->flush(); return $c; }