Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
6a488035 TO |
2 | /* |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
731a0992 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
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 | /** | |
29 | * File for the CiviCRM APIv3 address functions | |
30 | * | |
31 | * @package CiviCRM_APIv3 | |
32 | * @subpackage API_Address | |
33 | * | |
731a0992 | 34 | * @copyright CiviCRM LLC (c) 2004-2014 |
6a488035 TO |
35 | * @version $Id: Address.php 2011-02-16 ErikHommel $ |
36 | */ | |
37 | ||
6a488035 | 38 | /** |
22242c87 | 39 | * Add an Address for a contact. |
6a488035 | 40 | * |
c490a46a | 41 | * @param array $params |
2e66abf8 | 42 | * Array per getfields metadata. |
77b97be7 | 43 | * |
a6c01b45 | 44 | * @return array |
16b10e64 | 45 | * Array of newly created tag property values. |
6a488035 TO |
46 | */ |
47 | function civicrm_api3_address_create(&$params) { | |
48 | /** | |
100fef9d | 49 | * If street_parsing, street_address has to be parsed into |
6a488035 TO |
50 | * separate parts |
51 | */ | |
52 | if (array_key_exists('street_parsing', $params)) { | |
53 | if ($params['street_parsing'] == 1) { | |
54 | if (array_key_exists('street_address', $params)) { | |
55 | if (!empty($params['street_address'])) { | |
56 | $parsedItems = CRM_Core_BAO_Address::parseStreetAddress( | |
57 | $params['street_address'] | |
58 | ); | |
59 | if (array_key_exists('street_name', $parsedItems)) { | |
60 | $params['street_name'] = $parsedItems['street_name']; | |
61 | } | |
62 | if (array_key_exists('street_unit', $parsedItems)) { | |
63 | $params['street_unit'] = $parsedItems['street_unit']; | |
64 | } | |
65 | if (array_key_exists('street_number', $parsedItems)) { | |
66 | $params['street_number'] = $parsedItems['street_number']; | |
67 | } | |
68 | if (array_key_exists('street_number_suffix', $parsedItems)) { | |
69 | $params['street_number_suffix'] = $parsedItems['street_number_suffix']; | |
70 | } | |
71 | } | |
72 | } | |
73 | } | |
74 | } | |
75 | ||
76 | /** | |
c490a46a CW |
77 | * Create array for BAO (expects address params in as an |
78 | * element in array 'address' | |
79 | */ | |
6a488035 TO |
80 | $addressBAO = CRM_Core_BAO_Address::add($params, TRUE); |
81 | if (empty($addressBAO)) { | |
82 | return civicrm_api3_create_error("Address is not created or updated "); | |
83 | } | |
84 | else { | |
6a488035 TO |
85 | $values = _civicrm_api3_dao_to_array($addressBAO, $params); |
86 | return civicrm_api3_create_success($values, $params, 'address', $addressBAO); | |
87 | } | |
88 | } | |
89 | ||
11e09c59 | 90 | /** |
0aa0303c | 91 | * Adjust Metadata for Create action. |
6a488035 | 92 | * |
cf470720 TO |
93 | * @param array $params |
94 | * Array or parameters determined by getfields. | |
6a488035 TO |
95 | */ |
96 | function _civicrm_api3_address_create_spec(&$params) { | |
97 | $params['location_type_id']['api.required'] = 1; | |
98 | $params['contact_id']['api.required'] = 1; | |
99 | $params['country'] = array('title' => 'Name or 2-letter abbreviation of country. Looked up in civicrm_country table'); | |
100 | $params['street_parsing'] = array('title' => 'optional param to indicate you want the street_address field parsed into individual params'); | |
c7130c3e CW |
101 | $params['world_region'] = array( |
102 | 'title' => ts('World Region'), | |
103 | 'name' => 'world_region', | |
b8326bd2 | 104 | 'type' => CRM_Utils_Type::T_TEXT, |
c7130c3e CW |
105 | ); |
106 | } | |
107 | /** | |
2e66abf8 | 108 | * Adjust Metadata for Get action. |
c7130c3e | 109 | * |
cf470720 | 110 | * @param array $params |
2e66abf8 | 111 | * Array of parameters determined by getfields. |
c7130c3e CW |
112 | */ |
113 | function _civicrm_api3_address_get_spec(&$params) { | |
114 | $params['world_region'] = array( | |
115 | 'title' => ts('World Region'), | |
116 | 'name' => 'world_region', | |
b8326bd2 | 117 | 'type' => CRM_Utils_Type::T_TEXT, |
c7130c3e | 118 | ); |
6a488035 TO |
119 | } |
120 | ||
121 | /** | |
2e66abf8 | 122 | * Delete an existing Address. |
6a488035 | 123 | * |
cf470720 | 124 | * @param array $params |
2e66abf8 | 125 | * Array per getfields metadata. |
6a488035 | 126 | * |
a6c01b45 | 127 | * @return array |
72b3a70c | 128 | * api result array |
6a488035 | 129 | */ |
7c285037 | 130 | function civicrm_api3_address_delete($params) { |
6a488035 TO |
131 | return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__), $params); |
132 | } | |
133 | ||
134 | /** | |
2e66abf8 | 135 | * Retrieve one or more addresses. |
6a488035 | 136 | * |
cf470720 | 137 | * @param array $params |
2e66abf8 | 138 | * Array per getfields metadata. |
6a488035 | 139 | * |
a6c01b45 | 140 | * @return array |
72b3a70c | 141 | * details of found addresses else error |
6a488035 TO |
142 | */ |
143 | function civicrm_api3_address_get(&$params) { | |
144 | return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params, TRUE, 'Address'); | |
145 | } |