Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
6a488035 TO |
2 | /* |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
e7112fa7 | 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
10 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
11 | | under the terms of the GNU Affero General Public License | | |
12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
13 | | | | |
14 | | CiviCRM is distributed in the hope that it will be useful, but | | |
15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
17 | | See the GNU Affero General Public License for more details. | | |
18 | | | | |
19 | | You should have received a copy of the GNU Affero General Public | | |
20 | | License and the CiviCRM Licensing Exception along | | |
21 | | with this program; if not, contact CiviCRM LLC | | |
22 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
23 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
24 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
25 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
244bbdd8 | 29 | * This api exposes CiviCRM Address records. |
6a488035 TO |
30 | * |
31 | * @package CiviCRM_APIv3 | |
6a488035 TO |
32 | */ |
33 | ||
6a488035 | 34 | /** |
22242c87 | 35 | * Add an Address for a contact. |
6a488035 | 36 | * |
c490a46a | 37 | * @param array $params |
2e66abf8 | 38 | * Array per getfields metadata. |
77b97be7 | 39 | * |
a6c01b45 | 40 | * @return array |
00f8641b | 41 | * API result array |
6a488035 TO |
42 | */ |
43 | function civicrm_api3_address_create(&$params) { | |
44 | /** | |
100fef9d | 45 | * If street_parsing, street_address has to be parsed into |
6a488035 TO |
46 | * separate parts |
47 | */ | |
48 | if (array_key_exists('street_parsing', $params)) { | |
49 | if ($params['street_parsing'] == 1) { | |
50 | if (array_key_exists('street_address', $params)) { | |
51 | if (!empty($params['street_address'])) { | |
52 | $parsedItems = CRM_Core_BAO_Address::parseStreetAddress( | |
53 | $params['street_address'] | |
54 | ); | |
55 | if (array_key_exists('street_name', $parsedItems)) { | |
56 | $params['street_name'] = $parsedItems['street_name']; | |
57 | } | |
58 | if (array_key_exists('street_unit', $parsedItems)) { | |
59 | $params['street_unit'] = $parsedItems['street_unit']; | |
60 | } | |
61 | if (array_key_exists('street_number', $parsedItems)) { | |
62 | $params['street_number'] = $parsedItems['street_number']; | |
63 | } | |
64 | if (array_key_exists('street_number_suffix', $parsedItems)) { | |
65 | $params['street_number_suffix'] = $parsedItems['street_number_suffix']; | |
66 | } | |
67 | } | |
68 | } | |
69 | } | |
70 | } | |
71 | ||
72 | /** | |
c490a46a CW |
73 | * Create array for BAO (expects address params in as an |
74 | * element in array 'address' | |
75 | */ | |
6a488035 TO |
76 | $addressBAO = CRM_Core_BAO_Address::add($params, TRUE); |
77 | if (empty($addressBAO)) { | |
78 | return civicrm_api3_create_error("Address is not created or updated "); | |
79 | } | |
80 | else { | |
6a488035 | 81 | $values = _civicrm_api3_dao_to_array($addressBAO, $params); |
244bbdd8 | 82 | return civicrm_api3_create_success($values, $params, 'Address', $addressBAO); |
6a488035 TO |
83 | } |
84 | } | |
85 | ||
11e09c59 | 86 | /** |
0aa0303c | 87 | * Adjust Metadata for Create action. |
6a488035 | 88 | * |
cf470720 | 89 | * @param array $params |
b081365f | 90 | * Array of parameters determined by getfields. |
6a488035 TO |
91 | */ |
92 | function _civicrm_api3_address_create_spec(&$params) { | |
93 | $params['location_type_id']['api.required'] = 1; | |
94 | $params['contact_id']['api.required'] = 1; | |
b2ed8e73 CW |
95 | $params['street_parsing'] = array( |
96 | 'title' => 'Street Address Parsing', | |
97 | 'description' => 'Optional param to indicate you want the street_address field parsed into individual params', | |
d142432b | 98 | 'type' => CRM_Utils_Type::T_BOOLEAN, |
b2ed8e73 | 99 | ); |
c7130c3e CW |
100 | $params['world_region'] = array( |
101 | 'title' => ts('World Region'), | |
102 | 'name' => 'world_region', | |
b8326bd2 | 103 | 'type' => CRM_Utils_Type::T_TEXT, |
c7130c3e CW |
104 | ); |
105 | } | |
106 | /** | |
2e66abf8 | 107 | * Adjust Metadata for Get action. |
c7130c3e | 108 | * |
cf470720 | 109 | * @param array $params |
2e66abf8 | 110 | * Array of parameters determined by getfields. |
c7130c3e CW |
111 | */ |
112 | function _civicrm_api3_address_get_spec(&$params) { | |
113 | $params['world_region'] = array( | |
114 | 'title' => ts('World Region'), | |
115 | 'name' => 'world_region', | |
b8326bd2 | 116 | 'type' => CRM_Utils_Type::T_TEXT, |
c7130c3e | 117 | ); |
6a488035 TO |
118 | } |
119 | ||
120 | /** | |
2e66abf8 | 121 | * Delete an existing Address. |
6a488035 | 122 | * |
cf470720 | 123 | * @param array $params |
2e66abf8 | 124 | * Array per getfields metadata. |
6a488035 | 125 | * |
a6c01b45 | 126 | * @return array |
00f8641b | 127 | * API result array |
6a488035 | 128 | */ |
7c285037 | 129 | function civicrm_api3_address_delete($params) { |
6a488035 TO |
130 | return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__), $params); |
131 | } | |
132 | ||
133 | /** | |
2e66abf8 | 134 | * Retrieve one or more addresses. |
6a488035 | 135 | * |
cf470720 | 136 | * @param array $params |
2e66abf8 | 137 | * Array per getfields metadata. |
6a488035 | 138 | * |
a6c01b45 | 139 | * @return array |
00f8641b | 140 | * API result array |
6a488035 TO |
141 | */ |
142 | function civicrm_api3_address_get(&$params) { | |
143 | return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params, TRUE, 'Address'); | |
144 | } |