AdvertRegionAddressTrait
Splits the advert address into city, postcode and country on save, on the server, by the selected municipality.
The suggest JS fills these fields only as a preview; this trait decides. The second step of the same
address, the coordinates (applyCoordinates()), is computed by Api\System\…\GeocodingManager from
the parameters after the split; precision follows the module setting geocoding.precise_address.
When no coordinates result, logGeocodingMiss() writes a row to log/geocoding-miss.log after the commit.
Shared by the Api\Bazaar and Api\Comcat AdvertManager (same parameter keys regionId, street,
city, zip, country, latitude, longitude). The host must provide:
$parameterManager(Api moduleParameterManager),$regionManager(RegionManager),$geocodingManager(GeocodingManager),- upsertRegionAddressValue(), a typed write into the
parameterRelsobject graph (moduleAdvert/Parameterclasses the Core trait does not know), - getAdvertSettingModule() and getAdvertModuleName() (module index in settings, name for the log),
getSettingContext()(base Api manager).
Order in beforeSave: applyRegionAddress() → applyCoordinates() → reattachRelReferences().
findAll() of parameters in both steps clears the Doctrine identity map, so the reattach must follow them.
The region is read with raw sql (RegionManager::findLocality()), which leaves the identity map alone.
Applies only when a municipality (tree leaf) is selected in the parameters. An old advert placed on
a country or county (SELECT_REGION) stays unchanged; its city is free text.
Table of Contents
Constants
- PRECISE_ADDRESS_SETTING_KEY : string = 'geocoding.precise_address'
- Module setting key (dot convention).
- GEOCODING_MISS_META_KEY : string = '__geocodingMiss'
Methods
- getAdvertModuleName() : string
- Module name for the geocoding miss log (`bazaar`, `comcat`).
- getAdvertSettingModule() : int
- Module index in `cms_system_settings` (Bazaar 5, Comcat 6).
- upsertRegionAddressValue() : void
- Writes a parameter value into the advert `parameterRels` (the host verifies the module types).
- applyCoordinates() : void
- Computes the advert coordinates (`latitude`/`longitude` parameters) from the selected municipality, street and postcode through `GeocodingManager`. Runs only when the form sent the parameters (`parametersTouched`); otherwise an external geocoder would be called even for a quick-action save without a form. When nothing is found, the old values stay and the reason is stored in `$meta` for {@see logGeocodingMiss()} (the id of a new advert is known only after the save; a canceled save logs nothing).
- applyRegionAddress() : void
- collectParameterRelValues() : array<int, string>
- Returns the first value of each parameter from the merged `parameterRels` collection (`beforeSave` runs after hydration, so the collection already carries the submitted values).
- isPreciseAddressEnabled() : bool
- Switch of the module setting `geocoding.precise_address` (off by default in Bazaar, on in Comcat).
- logGeocodingMiss() : void
- Writes a row to `log/geocoding-miss.log` (channel `geocoding-miss`); the host calls it at the start of `completedSave` (after the commit, the advert id already exists). For manual review: advertiser typo versus a municipality missing from the data.
Constants
PRECISE_ADDRESS_SETTING_KEY
Module setting key (dot convention).
public
string
PRECISE_ADDRESS_SETTING_KEY
= 'geocoding.precise_address'
GEOCODING_MISS_META_KEY
private
string
GEOCODING_MISS_META_KEY
= '__geocodingMiss'
Methods
getAdvertModuleName()
Module name for the geocoding miss log (`bazaar`, `comcat`).
protected
abstract getAdvertModuleName() : string
Return values
stringgetAdvertSettingModule()
Module index in `cms_system_settings` (Bazaar 5, Comcat 6).
protected
abstract getAdvertSettingModule() : int
Return values
intupsertRegionAddressValue()
Writes a parameter value into the advert `parameterRels` (the host verifies the module types).
protected
abstract upsertRegionAddressValue(object $advert, object $parameter, string $value) : void
Parameters
- $advert : object
- $parameter : object
- $value : string
applyCoordinates()
Computes the advert coordinates (`latitude`/`longitude` parameters) from the selected municipality, street and postcode through `GeocodingManager`. Runs only when the form sent the parameters (`parametersTouched`); otherwise an external geocoder would be called even for a quick-action save without a form. When nothing is found, the old values stay and the reason is stored in `$meta` for {@see logGeocodingMiss()} (the id of a new advert is known only after the save; a canceled save logs nothing).
private
applyCoordinates(object $advert, array<string, mixed> &$meta) : void
A coordinate parameter with "always regenerate" (always_regenerate) off is computed only while it is empty.
Parameters
- $advert : object
- $meta : array<string, mixed>
applyRegionAddress()
private
applyRegionAddress(object $advert, array<string, mixed> $meta) : void
Parameters
- $advert : object
- $meta : array<string, mixed>
collectParameterRelValues()
Returns the first value of each parameter from the merged `parameterRels` collection (`beforeSave` runs after hydration, so the collection already carries the submitted values).
private
collectParameterRelValues(object $advert) : array<int, string>
Parameters
- $advert : object
Return values
array<int, string> —parameterId => value
isPreciseAddressEnabled()
Switch of the module setting `geocoding.precise_address` (off by default in Bazaar, on in Comcat).
private
isPreciseAddressEnabled() : bool
A missing key means off: Google is not paid for unless enabled on purpose.
Return values
boollogGeocodingMiss()
Writes a row to `log/geocoding-miss.log` (channel `geocoding-miss`); the host calls it at the start of `completedSave` (after the commit, the advert id already exists). For manual review: advertiser typo versus a municipality missing from the data.
private
logGeocodingMiss(object $advert, array<string, mixed> $meta) : void
Parameters
- $advert : object
- $meta : array<string, mixed>