Merge pull request #15921 from civicrm/5.20
[civicrm-core.git] / Civi / Api4 / Action / Address / AddressSaveTrait.php
1 <?php
2
3 /*
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC. All rights reserved. |
6 | |
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 +--------------------------------------------------------------------+
11 */
12
13 /**
14 *
15 * @package CRM
16 * @copyright CiviCRM LLC https://civicrm.org/licensing
17 * $Id$
18 *
19 */
20
21
22 namespace Civi\Api4\Action\Address;
23
24 /**
25 * @inheritDoc
26 * @method bool getStreetParsing()
27 * @method $this setStreetParsing(bool $streetParsing)
28 * @method bool getSkipGeocode()
29 * @method $this setSkipGeocode(bool $skipGeocode)
30 * @method bool getFixAddress()
31 * @method $this setFixAddress(bool $fixAddress)
32 */
33 trait AddressSaveTrait {
34
35 /**
36 * Optional param to indicate you want the street_address field parsed into individual params
37 *
38 * @var bool
39 */
40 protected $streetParsing = FALSE;
41
42 /**
43 * 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)
44 *
45 * @var bool
46 */
47 protected $skipGeocode = FALSE;
48
49 /**
50 * When true, apply various fixes to the address before insert.
51 *
52 * @var bool
53 */
54 protected $fixAddress = TRUE;
55
56 /**
57 * @inheritDoc
58 */
59 protected function writeObjects($items) {
60 foreach ($items as &$item) {
61 if ($this->streetParsing && !empty($item['street_address'])) {
62 $item = array_merge($item, \CRM_Core_BAO_Address::parseStreetAddress($item['street_address']));
63 }
64 $item['skip_geocode'] = $this->skipGeocode;
65 }
66 return parent::writeObjects($items);
67 }
68
69 }