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; }
/** * @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()); }
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); }
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; }