{{ __('Geocoding converts a location into a ISO 3166 (3 letters) country code. Boavizta needs this to determine usage impacts of assets. This feature sends the address stored in a location to nominatim.org service. If this is an issue, you can disable it below, and fill the coutry code manually.', 'carbon') }}
+ + + {{ fields.checkboxField( + 'geocoding_enabled', + current_config['geocoding_enabled'], + __('Enable geocoding', 'carbon') + ) }} +TWIG; + + return $twig; + } + + public function configUpdate(array $input): array + { + if (isset($input['boaviztapi_base_url']) && (string) $input['boaviztapi_base_url'] !== '') { + $old_url = PluginConfig::getPluginConfigurationValue('boaviztapi_base_url'); + if ($old_url != $input['boaviztapi_base_url']) { + $boavizta = new Client(new RestApiClient(), $input['boaviztapi_base_url']); + $zones = []; + try { + $zones = $boavizta->queryZones(); + } catch (Exception $e) { + unset($input['boaviztapi_base_url']); + Session::addMessageAfterRedirect(__('Invalid Boavizta API URL', 'carbon'), false, ERROR); + } + if (count($zones) > 0) { + // Create the source if it does not exists already + if ($boavizta->createSource()) { + // Save zones into database + $boavizta->saveZones($zones); + } + Session::addMessageAfterRedirect(__('Connection to Boavizta API established', 'carbon'), false, INFO); + } + } + } + + return $input; + } + + public static function getConfigurationValue(string $name) + { + if ($name === 'boaviztapi_base_url') { + $value = getenv(self::ENV_BOAVIZTAPI_BASE_URL); + if ($value !== false) { + return $value; + } + } + + return PluginConfig::getPluginConfigurationValue($name); + } +} diff --git a/src/DataSource/Lca/ClientFactory.php b/src/DataSource/Lca/ClientFactory.php new file mode 100644 index 00000000..6426e137 --- /dev/null +++ b/src/DataSource/Lca/ClientFactory.php @@ -0,0 +1,149 @@ +. + * + * ------------------------------------------------------------------------- + */ + +namespace GlpiPlugin\Carbon\DataSource\Lca; + +use GlpiPlugin\Carbon\DataSource\ConfigInterface; +use GlpiPlugin\Carbon\DataSource\RestApiClient; +use InvalidArgumentException; + +class ClientFactory +{ + /** + * Get available client types + * + * @return class-string{{ __('Geocoding converts a location into a ISO 3166 (3 letters) code. Boavizta needs this to determine usage impacts of assets. This feature sends the address stored in a location to nominatim.org service. If this is an issue, you can disable it below, and fill the coutry code manually.', 'carbon') }}
-