public function createContactAction() { $em = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager'); $post = $_POST; $firstName = $post['firstname']; $lastName = $post['lastname']; $email = $post['email']; $phone = $post['phone']; $address = $post['address']; $city = $post['city']; $country = $post['country']; $latitude = $post['latitude']; $longitude = $post['longitude']; if ($firstName && $lastName) { $contact = new Contact($firstName, $lastName); $contact->setEmail($email); $contact->setPhone($phone); $contact->setAddress($address); $contact->setCity($city); $contact->setCountry($country); $contact->setLatitude($latitude); $contact->setLongitude($longitude); $container = new Container('User'); $contact->setCreatedBy($em->find('Application\\Entity\\User', $container->id)); $em->persist($contact); $em->flush(); $respond['success'] = '<b>Success</b> : The user "' . $firstName . ' ' . $lastName . '" has been created'; } else { $respond['error'][] = '<b>Error</b> : The user couldn\'t be created because it needs a first name and a last name'; } $viewModel = new ViewModel(array('respond' => json_encode($respond))); $viewModel->setTerminal('ajax/index.php'); return $viewModel; }
public function saveContact(User $user, Contact $contact = null, array $data) { if ($contact == null) { $contact = new Contact(); } $contact->setUser($user); if (isset($data['phone'])) { $contact->setPhone($data['phone']); } if (isset($data['phone2'])) { $contact->setPhone2($data['phone2']); } if (isset($data['email'])) { $contact->setEmail($data['email']); } if (isset($data['email2'])) { $contact->setEmail2($data['email2']); } if (isset($data['url'])) { $contact->setUrl($data['url']); } if (isset($data['postalCode'])) { $contact->setPostalCode($data['postalCode']); } if (isset($data['address'])) { $contact->setAddress($data['address']); } if (isset($data['country'])) { $contact->setCountry($data['country']); } if (isset($data['city'])) { $contact->setCity($data['city']); } // if (isset($data['county']) && $data['county'] > 0) { // $county = $this->entityManager->getRepository(County::getClass())->findOneBy(array('id' => $data['county'])); // $contact->setCounty($county); // } // // if (isset($data['city']) && $data['city'] > 0) { // $city = $this->entityManager->getRepository(City::getClass())->findOneBy(array('id' => $data['city'])); // $contact->setCity($city); // } // // if (isset($data['borough']) && $data['borough'] > 0) { // $borough = $this->entityManager->getRepository(Borough::getClass())->findOneBy(array('id' => $data['borough'])); // $contact->setBorough($borough); // } $this->entityManager->persist($contact); $this->entityManager->persist($user); $this->entityManager->flush($contact); $this->entityManager->flush($user); }