/** * Formats an address on an array. * * @param AddressInterface $address The address to format * * @return array */ public function toArray(AddressInterface $address) { $cityLocationId = $address->getCity(); $cityHierarchy = $this->locationProvider->getHierarchy($cityLocationId); $cityHierarchyAsc = array_reverse($cityHierarchy); $addressArray = ['id' => $address->getId(), 'name' => $address->getName(), 'recipientName' => $address->getRecipientName(), 'recipientSurname' => $address->getRecipientSurname(), 'address' => $address->getAddress(), 'addressMore' => $address->getAddressMore(), 'postalCode' => $address->getPostalcode(), 'phone' => $address->getPhone(), 'mobile' => $address->getMobile(), 'comment' => $address->getComments()]; foreach ($cityHierarchyAsc as $cityLocationNode) { /** * @var LocationData $cityLocationNode */ $addressArray['city'][$cityLocationNode->getType()] = $cityLocationNode->getName(); } $addressArray['fullAddress'] = $this->buildFullAddressString($address, $addressArray['city']); return $addressArray; }
/** * Get the hierarchy given a location sorted from root to the given * location. * * @return Response Data serialized in json */ public function getHierarchyAction() { $id = $this->request->query->get('id'); return $this->createResponseObject(function () use($id) { return $this->normalizeLocationDataArray($this->locationProvider->getHierarchy($id)); }); }
/** * Gets the location hierarchy. * * @param string $locationId The location identifier * * @return \Elcodi\Component\Geo\ValueObject\LocationData[] */ protected function getHierarchy($locationId) { try { $hierarchy = $this->locationProvider->getHierarchy($locationId); } catch (EntityNotFoundException $e) { $hierarchy = []; } return $hierarchy; }
/** * Gets the address hierarchy. * * @param AddressInterface $address * * @return LocationData[] Addres hierarchy */ private function getAddressHierarchy(AddressInterface $address) { return $this->locationProvider->getHierarchy($address->getCity()); }
/** * Public function test get hierarchy not found. */ public function testGetHierarchyNotFound() { $this->setExpectedException('Doctrine\\ORM\\EntityNotFoundException'); $this->locationProviderAdapter->getHierarchy('UNEXISTENT'); }