4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC. All rights reserved. |
7 | This work is published under the GNU AGPLv3 license with some |
8 | permitted exceptions and without any warranty. For full license |
9 | and copyright information, see https://civicrm.org/licensing |
10 +--------------------------------------------------------------------+
16 * @copyright CiviCRM LLC https://civicrm.org/licensing
20 namespace Civi\Api4\Action\Address
;
24 * @method bool getStreetParsing()
25 * @method $this setStreetParsing(bool $streetParsing)
26 * @method bool getSkipGeocode()
27 * @method $this setSkipGeocode(bool $skipGeocode)
28 * @method bool getFixAddress()
29 * @method $this setFixAddress(bool $fixAddress)
31 trait AddressSaveTrait
{
34 * Optional param to indicate you want the street_address field parsed into individual params
38 protected $streetParsing = FALSE;
41 * Optional param to indicate you want to skip geocoding (useful when importing a lot of addresses at once, the job Geocode and Parse Addresses can execute this task after the import)
45 protected $skipGeocode = FALSE;
48 * When true, apply various fixes to the address before insert.
52 protected $fixAddress = TRUE;
57 protected function writeObjects($items) {
58 foreach ($items as &$item) {
59 if ($this->streetParsing
&& !empty($item['street_address'])) {
60 $item = array_merge($item, \CRM_Core_BAO_Address
::parseStreetAddress($item['street_address']));
62 $item['skip_geocode'] = $this->skipGeocode
;
64 return parent
::writeObjects($items);