コード例 #1
0
ファイル: ContactService.php プロジェクト: Wbondar/Buddies
 /**
  * Creates bidirectional contact between $initiator
  * and person of id $idOfTarget.
  * If there is no person of id $idOfTarget
  * throw an exception.
  * If those have the same id's, do nothing.
  * @param Person $initiator
  * @param unknown $idOfTarget
  * @throws \Exception
  */
 public function create(Person $initiator, $idOfTarget)
 {
     $target = $this->personRepo->find($idOfTarget);
     if ($target == null) {
         throw new \Exception("There is no person of id \"" . $idOfTarget . "\".");
     }
     if ($target->getId() == $initiator->getId()) {
         /* You cannot contact yourself. */
         return null;
     }
     $contact = new Contact();
     $contact->setSource($initiator);
     $contact->setTarget($target);
     $contact->setDateEstablished(new \DateTime());
     /*
      * Note: This does not look pretty, but in order to 
      * save room for different types of contacts,
      * which might not be bidiretional,
      * database entry duplicated.
      */
     $reflectedContact = new Contact();
     $reflectedContact->setSource($target);
     $reflectedContact->setTarget($initiator);
     $reflectedContact->setDateEstablished(new \DateTime());
     $this->objectManager->persist($contact);
     $this->objectManager->persist($reflectedContact);
     $this->objectManager->flush();
     return $contact;
 }
コード例 #2
0
 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;
 }
コード例 #3
0
ファイル: UserService.php プロジェクト: kristjanAnd/SimpleIV
 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);
 }
コード例 #4
0
 /**
  * Contact form, validate and send mail
  * @return array
  */
 public function indexAction()
 {
     $formManager = $this->serviceLocator->get('FormElementManager');
     $form = $formManager->get('contactForm');
     $session = new Container('user');
     if (isset($session->identity)) {
         $user = $session->identity;
         if (is_object($user)) {
             $userData = array('company' => $user->getCompany(), 'first_name' => $user->getFirstName(), 'last_name' => $user->getLastName());
             $form->setData($userData);
         }
     }
     $request = $this->getRequest();
     if ($request->isPost()) {
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $contact = new Contact();
             if (is_object($user)) {
                 $contact->setCompany($user->getCompany());
                 $contact->setFirstName($user->getFirstName());
                 $contact->setLastName($user->getLastName());
             } else {
                 $contact->setCompany($this->getRequest()->getPost('company'));
                 $contact->setFirstName($this->getRequest()->getPost('first_name'));
                 $contact->setLastName($this->getRequest()->getPost('last_name'));
             }
             $contact->setMessage($this->getRequest()->getPost('message'));
             $contact->setUserId(0);
             $contact->setStatus(0);
             $contact->setCreated(new \DateTime("now"));
             $contact->setLastModified(new \DateTime("now"));
             $this->getObjectManager()->persist($contact);
             $this->getObjectManager()->flush();
             // $newId = $user->getId();
             $translator = $this->getServiceLocator()->get('translator');
             $textContent = sprintf($translator->translate("contact_mail_text"), $contact->getCompany(), $contact->getFirstName(), $contact->getLastName(), $contact->getMessage());
             $htmlMarkup = sprintf($translator->translate("contact_mail_html"), $contact->getCompany(), $contact->getFirstName(), $contact->getLastName(), $contact->getMessage());
             $text = new MimePart($textContent);
             $text->type = "text/plain";
             $html = new MimePart($htmlMarkup);
             $html->type = "text/html";
             $body = new MimeMessage();
             $body->setParts(array($text, $html));
             $message = new Message();
             $message->addFrom("*****@*****.**", "example.net")->addTo("*****@*****.**", "example.net")->setSubject($translator->translate("contact_mail_subject"));
             $message->setBody($body);
             $message->setEncoding("UTF-8");
             //Debug mail: echo $message->toString();
             /*$transport = new SmtpTransport();
               $options   = new SmtpOptions(array(
               'name'              => 'localhost.localdomain',
               'host'              => '127.0.0.1',
               'connection_class'  => 'login',
               'connection_config' => array(
                       'username' => 'user',
                       'password' => 'pass',
               ),
               ));
               $transport->setOptions($options);*/
             $transport = new SendmailTransport();
             $transport->send($message);
             return $this->redirect()->toRoute('home');
         }
     }
     return array('form' => $form);
 }