| @@ 82-100 (lines=19) @@ | ||
| 79 | public function createFromCountryCode($CNT_ISO = null) |
|
| 80 | { |
|
| 81 | $CNT_ISO = $CNT_ISO !== null ? $CNT_ISO : $this->organization_config->CNT_ISO; |
|
| 82 | if(isset($this->countries_by_iso_code[ $CNT_ISO])) { |
|
| 83 | $country = $this->countries_by_iso_code[ $CNT_ISO ]; |
|
| 84 | } else { |
|
| 85 | /** @var EE_Country $country */ |
|
| 86 | $country = $this->country_model->get_one_by_ID($CNT_ISO); |
|
| 87 | if (! $country instanceof EE_Country) { |
|
| 88 | throw new InvalidArgumentException( |
|
| 89 | sprintf( |
|
| 90 | esc_html__( |
|
| 91 | 'A valid country could not be found for the "%1$s" country code;', |
|
| 92 | 'event_espresso' |
|
| 93 | ), |
|
| 94 | $CNT_ISO |
|
| 95 | ) |
|
| 96 | ); |
|
| 97 | } |
|
| 98 | $this->countries_by_iso_code[ $CNT_ISO ] = $country; |
|
| 99 | $this->countries_by_currency[ $country->currency_code() ] = $country; |
|
| 100 | } |
|
| 101 | return new Currency( |
|
| 102 | $country->currency_code(), |
|
| 103 | new Label( |
|
| @@ 131-149 (lines=19) @@ | ||
| 128 | */ |
|
| 129 | public function createFromCode($code) |
|
| 130 | { |
|
| 131 | if (isset($this->countries_by_currency[ $code ])) { |
|
| 132 | $country = $this->countries_by_currency[ $code ]; |
|
| 133 | } else { |
|
| 134 | /** @var EE_Country $country */ |
|
| 135 | $country = $this->country_model->get_one(array(array('CNT_cur_code' => $code))); |
|
| 136 | if (! $country instanceof EE_Country) { |
|
| 137 | throw new InvalidArgumentException( |
|
| 138 | sprintf( |
|
| 139 | esc_html__( |
|
| 140 | 'A valid currency could not be found for the "%1$s" currency code;', |
|
| 141 | 'event_espresso' |
|
| 142 | ), |
|
| 143 | $code |
|
| 144 | ) |
|
| 145 | ); |
|
| 146 | } |
|
| 147 | $this->countries_by_iso_code[ $country->ID() ] = $country; |
|
| 148 | $this->countries_by_currency[ $code ] = $country; |
|
| 149 | } |
|
| 150 | return new Currency( |
|
| 151 | $country->currency_code(), |
|
| 152 | new Label( |
|