/** * Adds a new tag to the given contact. * * @param $contact * @param $data * * @return bool * * @throws EntityNotFoundException * @throws EntityIdAlreadySetException */ protected function addUrl($contact, $data) { $success = true; $urlType = $this->em->getRepository(self::$urlTypeEntityName)->find($data['urlType']['id']); if (isset($data['id'])) { throw new EntityIdAlreadySetException(self::$urlEntityName, $data['id']); } elseif (!$urlType) { throw new EntityNotFoundException(self::$urlTypeEntityName, $data['urlType']['id']); } else { $url = new Url(); $url->setUrl($data['url']); $url->setUrlType($urlType); $this->em->persist($url); $contact->addUrl($url); } return $success; }
private function initOrm() { $account = new Account(); $account->setName('Company'); $account->setPlaceOfJurisdiction('Feldkirch'); $parentAccount = new Account(); $parentAccount->setName('Parent'); $parentAccount->setPlaceOfJurisdiction('Feldkirch'); $childAccount = new Account(); $childAccount->setName('Child'); $childAccount->setPlaceOfJurisdiction('Feldkirch'); $childAccount->setParent($parentAccount); $this->account = $account; $this->childAccount = $childAccount; $this->parentAccount = $parentAccount; $urlType = new UrlType(); $urlType->setName('Private'); $this->urlType = $urlType; $url = new Url(); $url->setUrl('http://www.company.example'); $this->url = $url; $url->setUrlType($urlType); $account->addUrl($url); $this->emailType = new EmailType(); $this->emailType->setName('Private'); $this->email = new Email(); $this->email->setEmail('*****@*****.**'); $this->email->setEmailType($this->emailType); $account->addEmail($this->email); $phoneType = new PhoneType(); $phoneType->setName('Private'); $this->phoneType = $phoneType; $phone = new Phone(); $phone->setPhone('123456789'); $phone->setPhoneType($phoneType); $account->addPhone($phone); $faxType = new FaxType(); $faxType->setName('Private'); $this->faxType = $faxType; $fax = new Fax(); $fax->setFax('123654789'); $fax->setFaxType($faxType); $account->addFax($fax); $country = new Country(); $country->setName('Musterland'); $country->setCode('ML'); $this->country = $country; $addressType = new AddressType(); $addressType->setName('Private'); $this->addressType = $addressType; $address = new Address(); $address->setStreet('Musterstraße'); $address->setNumber('1'); $address->setZip('0000'); $address->setCity('Musterstadt'); $address->setState('Musterland'); $address->setCountry($country); $address->setAddition(''); $address->setAddressType($addressType); $address->setBillingAddress(true); $address->setPrimaryAddress(true); $address->setDeliveryAddress(false); $address->setPostboxCity('Dornbirn'); $address->setPostboxPostcode('6850'); $address->setPostboxNumber('4711'); $address->setNote('note'); $this->address = $address; $accountAddress = new AccountAddress(); $accountAddress->setAddress($address); $accountAddress->setAccount($account); $accountAddress->setMain(true); $account->addAccountAddress($accountAddress); $address->addAccountAddress($accountAddress); $contact = new Contact(); $contact->setFirstName('Vorname'); $contact->setLastName('Nachname'); $contact->setMiddleName('Mittelname'); $contact->setFormOfAddress(0); $accountContact = new AccountContact(); $accountContact->setContact($contact); $accountContact->setAccount($account); $accountContact->setMain(true); $account->addAccountContact($accountContact); $note = new Note(); $note->setValue('Note'); $account->addNote($note); $this->initLogo(); $account->setLogo($this->logo); $this->em->persist($account); $this->em->persist($childAccount); $this->em->persist($parentAccount); $this->em->persist($urlType); $this->em->persist($url); $this->em->persist($this->emailType); $this->em->persist($accountContact); $this->em->persist($this->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(); }