4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.4 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2013 |
8 +--------------------------------------------------------------------+
9 | This file is a part of CiviCRM. |
11 | CiviCRM is free software; you can copy, modify, and distribute it |
12 | under the terms of the GNU Affero General Public License |
13 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
15 | CiviCRM is distributed in the hope that it will be useful, but |
16 | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. |
20 | You should have received a copy of the GNU Affero General Public |
21 | License and the CiviCRM Licensing Exception along |
22 | with this program; if not, contact CiviCRM LLC |
23 | at info[AT]civicrm[DOT]org. If you have questions about the |
24 | GNU Affero General Public License or the licensing of CiviCRM, |
25 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
26 +--------------------------------------------------------------------+
30 * File for the CiviCRM APIv3 address functions
32 * @package CiviCRM_APIv3
33 * @subpackage API_Address
35 * @copyright CiviCRM LLC (c) 2004-2013
36 * @version $Id: Address.php 2011-02-16 ErikHommel $
40 * Add an Address for a contact
42 * Allowed @params array keys are:
43 * {@getfields address_create}
44 * {@example AddressCreate.php}
46 * @return array of newly created tag property values.
49 function civicrm_api3_address_create(&$params) {
51 * if street_parsing, street_address has to be parsed into
54 if (array_key_exists('street_parsing', $params)) {
55 if ($params['street_parsing'] == 1) {
56 if (array_key_exists('street_address', $params)) {
57 if (!empty($params['street_address'])) {
58 $parsedItems = CRM_Core_BAO_Address
::parseStreetAddress(
59 $params['street_address']
61 if (array_key_exists('street_name', $parsedItems)) {
62 $params['street_name'] = $parsedItems['street_name'];
64 if (array_key_exists('street_unit', $parsedItems)) {
65 $params['street_unit'] = $parsedItems['street_unit'];
67 if (array_key_exists('street_number', $parsedItems)) {
68 $params['street_number'] = $parsedItems['street_number'];
70 if (array_key_exists('street_number_suffix', $parsedItems)) {
71 $params['street_number_suffix'] = $parsedItems['street_number_suffix'];
79 * create array for BAO (expects address params in as an
80 * element in array 'address'
82 $addressBAO = CRM_Core_BAO_Address
::add($params, TRUE);
83 if (empty($addressBAO)) {
84 return civicrm_api3_create_error("Address is not created or updated ");
88 $values = _civicrm_api3_dao_to_array($addressBAO, $params);
89 return civicrm_api3_create_success($values, $params, 'address', $addressBAO);
94 * Adjust Metadata for Create action
96 * @param array $params array or parameters determined by getfields
98 function _civicrm_api3_address_create_spec(&$params) {
99 $params['location_type_id']['api.required'] = 1;
100 $params['contact_id']['api.required'] = 1;
101 $params['country'] = array('title' => 'Name or 2-letter abbreviation of country. Looked up in civicrm_country table');
102 $params['street_parsing'] = array('title' => 'optional param to indicate you want the street_address field parsed into individual params');
106 * Deletes an existing Address
108 * @param array $params
110 * {@getfields address_delete}
111 * {@example AddressDelete.php 0}
113 * @return boolean | error true if successfull, error otherwise
116 function civicrm_api3_address_delete(&$params) {
117 return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__
), $params);
121 * Retrieve one or more addresses on address_id, contact_id, street_name, city
122 * or a combination of those
124 * @param mixed[] (reference ) input parameters
126 * {@example AddressGet.php 0}
127 * @param array $params an associative array of name/value pairs.
129 * @return array details of found addresses else error
130 * {@getfields address_get}
133 function civicrm_api3_address_get(&$params) {
134 return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__
), $params, TRUE, 'Address');