Commit | Line | Data |
---|---|---|
19b53e5b C |
1 | <?php |
2 | ||
380f3545 TO |
3 | /* |
4 | +--------------------------------------------------------------------+ | |
41498ac5 | 5 | | Copyright CiviCRM LLC. All rights reserved. | |
380f3545 | 6 | | | |
41498ac5 TO |
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 | | |
380f3545 TO |
10 | +--------------------------------------------------------------------+ |
11 | */ | |
12 | ||
13 | /** | |
14 | * | |
15 | * @package CRM | |
ca5cec67 | 16 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
380f3545 TO |
17 | */ |
18 | ||
19 | ||
19b53e5b C |
20 | namespace Civi\Api4\Action\Address; |
21 | ||
22 | /** | |
23 | * @inheritDoc | |
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) | |
30 | */ | |
31 | trait AddressSaveTrait { | |
32 | ||
33 | /** | |
34 | * Optional param to indicate you want the street_address field parsed into individual params | |
35 | * | |
36 | * @var bool | |
37 | */ | |
38 | protected $streetParsing = FALSE; | |
39 | ||
40 | /** | |
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) | |
42 | * | |
43 | * @var bool | |
44 | */ | |
45 | protected $skipGeocode = FALSE; | |
46 | ||
47 | /** | |
48 | * When true, apply various fixes to the address before insert. | |
49 | * | |
50 | * @var bool | |
51 | */ | |
52 | protected $fixAddress = TRUE; | |
53 | ||
54 | /** | |
55 | * @inheritDoc | |
56 | */ | |
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'])); | |
61 | } | |
62 | $item['skip_geocode'] = $this->skipGeocode; | |
63 | } | |
64 | return parent::writeObjects($items); | |
65 | } | |
66 | ||
67 | } |