3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
29 * This api exposes CiviCRM address.
31 * @package CiviCRM_APIv3
32 * @subpackage API_Address
37 * Add an Address for a contact.
39 * @param array $params
40 * Array per getfields metadata.
43 * Array of newly created tag property values.
45 function civicrm_api3_address_create(&$params) {
47 * If street_parsing, street_address has to be parsed into
50 if (array_key_exists('street_parsing', $params)) {
51 if ($params['street_parsing'] == 1) {
52 if (array_key_exists('street_address', $params)) {
53 if (!empty($params['street_address'])) {
54 $parsedItems = CRM_Core_BAO_Address
::parseStreetAddress(
55 $params['street_address']
57 if (array_key_exists('street_name', $parsedItems)) {
58 $params['street_name'] = $parsedItems['street_name'];
60 if (array_key_exists('street_unit', $parsedItems)) {
61 $params['street_unit'] = $parsedItems['street_unit'];
63 if (array_key_exists('street_number', $parsedItems)) {
64 $params['street_number'] = $parsedItems['street_number'];
66 if (array_key_exists('street_number_suffix', $parsedItems)) {
67 $params['street_number_suffix'] = $parsedItems['street_number_suffix'];
75 * Create array for BAO (expects address params in as an
76 * element in array 'address'
78 $addressBAO = CRM_Core_BAO_Address
::add($params, TRUE);
79 if (empty($addressBAO)) {
80 return civicrm_api3_create_error("Address is not created or updated ");
83 $values = _civicrm_api3_dao_to_array($addressBAO, $params);
84 return civicrm_api3_create_success($values, $params, 'address', $addressBAO);
89 * Adjust Metadata for Create action.
91 * @param array $params
92 * Array or parameters determined by getfields.
94 function _civicrm_api3_address_create_spec(&$params) {
95 $params['location_type_id']['api.required'] = 1;
96 $params['contact_id']['api.required'] = 1;
97 $params['country'] = array('title' => 'Name or 2-letter abbreviation of country. Looked up in civicrm_country table');
98 $params['street_parsing'] = array('title' => 'optional param to indicate you want the street_address field parsed into individual params');
99 $params['world_region'] = array(
100 'title' => ts('World Region'),
101 'name' => 'world_region',
102 'type' => CRM_Utils_Type
::T_TEXT
,
106 * Adjust Metadata for Get action.
108 * @param array $params
109 * Array of parameters determined by getfields.
111 function _civicrm_api3_address_get_spec(&$params) {
112 $params['world_region'] = array(
113 'title' => ts('World Region'),
114 'name' => 'world_region',
115 'type' => CRM_Utils_Type
::T_TEXT
,
120 * Delete an existing Address.
122 * @param array $params
123 * Array per getfields metadata.
128 function civicrm_api3_address_delete($params) {
129 return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__
), $params);
133 * Retrieve one or more addresses.
135 * @param array $params
136 * Array per getfields metadata.
139 * details of found addresses else error
141 function civicrm_api3_address_get(&$params) {
142 return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__
), $params, TRUE, 'Address');