Пример #1
0
 /**
  * Test the toArray method
  */
 public function testFormatToArray()
 {
     $city = new LocationData('city_id', 'Estudis de TV3', '22', 'city');
     $country = new LocationData('country_id', 'Catalunya', '23', 'country');
     $address = $this->getAddress('42', 'My home', 'Marc', 'Robirosa', 'C/ engonga', '43', '06580', '958652654', '647852365', 'Aixo en el basquetbol es veu molt clar', 'city_id');
     $expectedFullAddress = 'C/ engonga 43, Estudis de TV3, Catalunya 06580';
     $expectedResponse = ['id' => '42', 'name' => 'My home', 'recipientName' => 'Marc', 'recipientSurname' => 'Robirosa', 'address' => 'C/ engonga', 'addressMore' => '43', 'postalCode' => '06580', 'phone' => '958652654', 'mobile' => '647852365', 'comment' => 'Aixo en el basquetbol es veu molt clar', 'city' => ['city' => 'Estudis de TV3', 'country' => 'Catalunya'], 'fullAddress' => $expectedFullAddress];
     $this->locationProvider->expects($this->once())->method('getHierarchy')->with('city_id')->will($this->returnValue([$country, $city]));
     $response = $this->addressFormatter->toArray($address);
     $this->assertSame($expectedResponse, $response, 'Unexpected method response');
 }
Пример #2
0
 /**
  * Checks if an specific Address is contained in a Zone. For an Address, to
  * be contained in a Zone means that belongs to one (at least) of this Zone
  * locations.
  *
  * @param AddressInterface $address Address
  * @param ZoneInterface    $zone    Zone
  *
  * @return bool Address is contained in zone
  */
 public function isAddressContainedInZone(AddressInterface $address, ZoneInterface $zone)
 {
     $locations = $zone->getLocations();
     $cityId = $address->getCity();
     $found = false;
     try {
         $found = $this->locationProvider->in($cityId, $locations);
     } catch (Exception $e) {
         // Silent pass
     }
     return $found;
 }
Пример #3
0
 /**
  * Checks if the passed value is valid.
  *
  * @param mixed      $value      The value that should be validated
  * @param Constraint $constraint The constraint for the validation
  */
 public function validate($value, Constraint $constraint)
 {
     /**
      * @var LocationData $location
      */
     try {
         $location = $this->locationProvider->getLocation($value);
     } catch (EntityNotFoundException $e) {
         $location = null;
     }
     if (!$location instanceof LocationData || 'city' != $location->getType()) {
         $this->context->addViolation('Select a city');
     }
 }
Пример #4
0
 /**
  * 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;
 }
Пример #5
0
 /**
  * Checks if the first received id is contained between the rest of ids
  * received as second parameter.
  *
  * @return Response Data serialized in json
  */
 public function inAction()
 {
     $id = $this->request->query->get('id');
     $ids = explode(',', $this->request->query->get('ids'));
     $result = $this->locationProvider->in($id, $ids);
     return $this->createResponseObject(function () use($result) {
         return ['result' => $result];
     });
 }
Пример #6
0
 /**
  * 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;
 }
Пример #7
0
 /**
  * Gets the address hierarchy.
  *
  * @param AddressInterface $address
  *
  * @return LocationData[] Addres hierarchy
  */
 private function getAddressHierarchy(AddressInterface $address)
 {
     return $this->locationProvider->getHierarchy($address->getCity());
 }
 /**
  * Test in with a non-existent location
  */
 public function testInLocationNotFound()
 {
     $this->setExpectedException('Doctrine\\ORM\\EntityNotFoundException');
     $this->locationProviderAdapter->in('UNEXISTENT', ['ES_CA_VO_SantCeloni', 'ES_CA']);
 }