Exemple #1
0
 /**
  * creates a new main Account Contacts relation.
  *
  * @param Contact          $contact
  * @param AccountInterface $account
  * @param $position
  *
  * @return AccountContact
  */
 public function createMainAccountContact(Contact $contact, AccountInterface $account, $position = null)
 {
     $accountContact = new AccountContact();
     $accountContact->setAccount($account);
     $accountContact->setContact($contact);
     $accountContact->setMain(true);
     $this->em->persist($accountContact);
     $contact->addAccountContact($accountContact);
     $accountContact->setPosition($position);
     return $accountContact;
 }
 /**
  * Test if deleteinfo returns correct data.
  */
 public function testGetDeleteInfoById()
 {
     // modify test data
     for ($i = 0; $i < 5; ++$i) {
         $contact = new Contact();
         $contact->setFirstName('Vorname ' . $i);
         $contact->setLastName('Nachname ' . $i);
         $contact->setMiddleName('Mittelname ' . $i);
         $contact->setFormOfAddress(0);
         $this->em->persist($contact);
         $accountContact = new AccountContact();
         $accountContact->setContact($contact);
         $accountContact->setAccount($this->account);
         $accountContact->setMain(true);
         $this->em->persist($accountContact);
         $this->account->addAccountContact($accountContact);
     }
     $this->em->flush();
     $numContacts = $this->account->getAccountContacts()->count();
     $client = $this->createAuthenticatedClient();
     $client->request('GET', '/api/accounts/' . $this->account->getId() . '/deleteinfo');
     $this->assertEquals('200', $client->getResponse()->getStatusCode());
     $response = json_decode($client->getResponse()->getContent());
     // number of returned contacts has to be less or equal 3
     $this->assertEquals(3, count($response->contacts));
     // return full number of contacts related to account
     $this->assertEquals($numContacts, $response->numContacts);
     // allowed if no subaccount exists
     $this->assertEquals(0, $response->numChildren);
 }
Exemple #3
0
 /**
  * @param int $accountId
  * @param int j$contactId
  * @param Request $request
  *
  * @throws \Exception
  *
  * @return Response
  */
 public function putContactsAction($accountId, $contactId, Request $request)
 {
     try {
         // Get account.
         /** @var AccountInterface $account */
         $account = $this->getDoctrine()->getRepository($this->getAccountEntityName())->find($accountId);
         if (!$account) {
             throw new EntityNotFoundException('account', $accountId);
         }
         // Get contact.
         $contact = $this->getDoctrine()->getRepository($this->container->getParameter('sulu.model.contact.class'))->find($contactId);
         if (!$contact) {
             throw new EntityNotFoundException('contact', $contactId);
         }
         // Check if relation already exists.
         $accountContact = $this->getDoctrine()->getRepository(self::$accountContactEntityName)->findOneBy(['contact' => $contact, 'account' => $account]);
         if ($accountContact) {
             throw new \Exception('Relation already exists');
         }
         // Create relation.
         $accountContact = new AccountContactEntity();
         // If contact has no main relation - set as main.
         $accountContact->setMain($contact->getAccountContacts()->isEmpty());
         $accountContact->setAccount($account);
         $accountContact->setContact($contact);
         // Set position on contact.
         $position = $this->getAccountManager()->getPosition($request->get('position', null));
         $accountContact->setPosition($position);
         $contact->setCurrentPosition($position);
         $em = $this->getDoctrine()->getManager();
         $em->persist($accountContact);
         $em->flush();
         $isMainContact = false;
         if ($account->getMainContact()) {
             $isMainContact = $account->getMainContact()->getId() === $contact->getId();
         }
         $contactArray = ['id' => $contact->getId(), 'fullName' => $contact->getFullName(), 'isMainContact' => $isMainContact];
         if ($position) {
             $contactArray['position'] = $position->getPosition();
         }
         $view = $this->view($contactArray, 200);
     } catch (EntityNotFoundException $enfe) {
         $view = $this->view($enfe->toArray(), 404);
     } catch (RestException $exc) {
         $view = $this->view($exc->toArray(), 400);
     } catch (\Exception $e) {
         $view = $this->view($e->getMessage(), 400);
     }
     return $this->handleView($view);
 }
Exemple #4
0
 /**
  * Creates account contact relation.
  *
  * @param AccountInterface $account
  * @param ContactInterface $contact
  * @param bool $isMain
  *
  * @return AccountContact
  */
 protected function createAccountContact(AccountInterface $account, ContactInterface $contact, $isMain = true)
 {
     $accountContact = new AccountContact();
     $accountContact->setAccount($account);
     $accountContact->setContact($contact);
     $accountContact->setMain($isMain);
     $this->contact->addAccountContact($accountContact);
     $this->em->persist($accountContact);
     return $accountContact;
 }
 private function initOrm()
 {
     $this->account = new Account();
     $this->account->setName('Company');
     $this->account->setDisabled(0);
     $this->account->setPlaceOfJurisdiction('Feldkirch');
     $urlType = new UrlType();
     $urlType->setName('Private');
     $url = new Url();
     $url->setUrl('http://www.company.example');
     $url->setUrlType($urlType);
     $this->account->addUrl($url);
     $emailType = new EmailType();
     $emailType->setName('Private');
     $email = new Email();
     $email->setEmail('*****@*****.**');
     $email->setEmailType($emailType);
     $this->account->addEmail($email);
     $phoneType = new PhoneType();
     $phoneType->setName('Private');
     $phone = new Phone();
     $phone->setPhone('123456789');
     $phone->setPhoneType($phoneType);
     $this->account->addPhone($phone);
     $faxType = new FaxType();
     $faxType->setName('Private');
     $fax = new Fax();
     $fax->setFax('123654789');
     $fax->setFaxType($faxType);
     $this->account->addFax($fax);
     $country = new Country();
     $country->setName('Musterland');
     $country->setCode('ML');
     $addressType = new AddressType();
     $addressType->setName('Private');
     $address = new Address();
     $address->setStreet('Musterstraße');
     $address->setNumber('1');
     $address->setZip('0000');
     $address->setCity('Musterstadt');
     $address->setState('Musterland');
     $address->setCountry($country);
     $address->setAddressType($addressType);
     $address->setBillingAddress(true);
     $address->setPrimaryAddress(true);
     $address->setDeliveryAddress(false);
     $address->setPostboxCity('Dornbirn');
     $address->setPostboxPostcode('6850');
     $address->setPostboxNumber('4711');
     $accountAddress = new AccountAddress();
     $accountAddress->setAddress($address);
     $accountAddress->setAccount($this->account);
     $accountAddress->setMain(true);
     $this->account->addAccountAddress($accountAddress);
     $address->addAccountAddress($accountAddress);
     $contact = new Contact();
     $contact->setFirstName('Vorname');
     $contact->setLastName('Nachname');
     $contact->setMiddleName('Mittelname');
     $contact->setDisabled(0);
     $contact->setFormOfAddress(0);
     $accountContact = new AccountContact();
     $accountContact->setContact($contact);
     $accountContact->setAccount($this->account);
     $accountContact->setMain(true);
     $this->account->addAccountContact($accountContact);
     $note = new Note();
     $note->setValue('Note');
     $this->account->addNote($note);
     $this->setUpMediaEntities();
     $this->em->persist($this->account);
     $this->em->persist($urlType);
     $this->em->persist($url);
     $this->em->persist($emailType);
     $this->em->persist($accountContact);
     $this->em->persist($email);
     $this->em->persist($phoneType);
     $this->em->persist($phone);
     $this->em->persist($country);
     $this->em->persist($addressType);
     $this->em->persist($address);
     $this->em->persist($accountAddress);
     $this->em->persist($note);
     $this->em->persist($faxType);
     $this->em->persist($fax);
     $this->em->persist($contact);
     $this->em->flush();
 }