Sulu\Bundle\ContactBundle\Contact\AbstractContactManager::createAddress PHP Méthode

createAddress() protected méthode

Creates an address based on the data passed.
protected createAddress ( array $addressData, &$isMain = null ) : Address
$addressData array
$isMain returns if address is main address
Résultat Sulu\Bundle\ContactBundle\Entity\Address
    protected function createAddress($addressData, &$isMain = null)
    {
        $addressType = $this->em->getRepository(self::$addressTypeEntityName)->find($addressData['addressType']['id']);
        $country = $this->em->getRepository(self::$countryEntityName)->find($addressData['country']['id']);
        if (isset($addressData['id'])) {
            throw new EntityIdAlreadySetException(self::$addressEntityName, $addressData['id']);
        } elseif (!$country) {
            throw new EntityNotFoundException(self::$countryEntityName, $addressData['country']['id']);
        } elseif (!$addressType) {
            throw new EntityNotFoundException(self::$addressTypeEntityName, $addressData['addressType']['id']);
        } else {
            $address = new Address();
            $address->setStreet($addressData['street']);
            $address->setNumber($addressData['number']);
            $address->setZip($addressData['zip']);
            $address->setCity($addressData['city']);
            $address->setState($addressData['state']);
            if (isset($addressData['note'])) {
                $address->setNote($addressData['note']);
            }
            if (isset($addressData['title'])) {
                $address->setTitle($addressData['title']);
            }
            if (isset($addressData['primaryAddress'])) {
                $isMain = $this->getBooleanValue($addressData['primaryAddress']);
            } else {
                $isMain = false;
            }
            if (isset($addressData['billingAddress'])) {
                $address->setBillingAddress($this->getBooleanValue($addressData['billingAddress']));
            }
            if (isset($addressData['deliveryAddress'])) {
                $address->setDeliveryAddress($this->getBooleanValue($addressData['deliveryAddress']));
            }
            if (isset($addressData['postboxCity'])) {
                $address->setPostboxCity($addressData['postboxCity']);
            }
            if (isset($addressData['postboxNumber'])) {
                $address->setPostboxNumber($addressData['postboxNumber']);
            }
            if (isset($addressData['postboxPostcode'])) {
                $address->setPostboxPostcode($addressData['postboxPostcode']);
            }
            $address->setCountry($country);
            $address->setAddressType($addressType);
            // add additional fields
            if (isset($addressData['addition'])) {
                $address->setAddition($addressData['addition']);
            }
            $this->em->persist($address);
        }
        return $address;
    }