Commit 77a59738 authored by bdriesen's avatar bdriesen Committed by Bram Driesen
Browse files

Issue #3278338 by BramDriesen: Update helper class - getMunicipalitiesByPostalCode

parent 37113351
Loading
Loading
Loading
Loading
+17 −3
Original line number Diff line number Diff line
@@ -20,8 +20,12 @@ class PostalCodeHelper implements PostalCodeHelperInterface {

  /**
   * The zipcodes URL from bpost.
   *
   * Unfortunately this is currently hosted on an HTTP only server.
   *
   * @see: https://www.bpost.be/nl/postcodevalidatie-tool
   */
  const ZIPCODES_URL = "http://www.bpost2.be/zipcodes/files/zipcodes_num_nl_new.xls";
  protected const ZIPCODES_URL = "http://www.bpost2.be/zipcodes/files/zipcodes_num_nl_new.xls";

  /**
   * PostalCodeHelper constructor.
@@ -49,8 +53,18 @@ class PostalCodeHelper implements PostalCodeHelperInterface {
  /**
   * {@inheritdoc}
   */
  public function getMunicipalityByPostalCode(string $postalCode) {
    // @todo Implement.
  public function getMunicipalitiesByPostalCode(string $postalCode): array {
    $term_ids = $this->entityTypeManager
      ->getStorage('taxonomy_term')
      ->getQuery()
      ->condition('field_postal_code_be', $postalCode)
      ->execute();

    if ($term_ids) {
      return $this->entityTypeManager->getStorage('taxonomy_term')->loadMultiple($term_ids);
    }

    return [];
  }

  /**
+9 −2
Original line number Diff line number Diff line
@@ -23,11 +23,18 @@ interface PostalCodeHelperInterface {
  public function downloadPostalCodeFile(): mixed;

  /**
   * Loads all municipalities by a given postal code.
   *
   * It's not possible to return a single municipality this way because in
   * Belgium it is possible that multiple cities share the same postal code.
   *
   * @param string $postalCode
   *   The postal code as string.
   *
   * @return mixed
   * @return array
   *   An array of postal code terms if there are results.
   */
  public function getMunicipalityByPostalCode(string $postalCode);
  public function getMunicipalitiesByPostalCode(string $postalCode): array;

  /**
   * @param string $municipality