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 | +--------------------------------------------------------------------+ | |
26 | */ | |
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 TO |
38 | /** |
39 | * Add an Address for a contact | |
40 | * | |
41 | * Allowed @params array keys are: | |
42 | * {@getfields address_create} | |
43 | * {@example AddressCreate.php} | |
44 | * | |
c490a46a | 45 | * @param array $params |
77b97be7 | 46 | * |
a6c01b45 | 47 | * @return array |
16b10e64 | 48 | * Array of newly created tag property values. |
6a488035 TO |
49 | * @access public |
50 | */ | |
51 | function civicrm_api3_address_create(&$params) { | |
52 | /** | |
100fef9d | 53 | * If street_parsing, street_address has to be parsed into |
6a488035 TO |
54 | * separate parts |
55 | */ | |
56 | if (array_key_exists('street_parsing', $params)) { | |
57 | if ($params['street_parsing'] == 1) { | |
58 | if (array_key_exists('street_address', $params)) { | |
59 | if (!empty($params['street_address'])) { | |
60 | $parsedItems = CRM_Core_BAO_Address::parseStreetAddress( | |
61 | $params['street_address'] | |
62 | ); | |
63 | if (array_key_exists('street_name', $parsedItems)) { | |
64 | $params['street_name'] = $parsedItems['street_name']; | |
65 | } | |
66 | if (array_key_exists('street_unit', $parsedItems)) { | |
67 | $params['street_unit'] = $parsedItems['street_unit']; | |
68 | } | |
69 | if (array_key_exists('street_number', $parsedItems)) { | |
70 | $params['street_number'] = $parsedItems['street_number']; | |
71 | } | |
72 | if (array_key_exists('street_number_suffix', $parsedItems)) { | |
73 | $params['street_number_suffix'] = $parsedItems['street_number_suffix']; | |
74 | } | |
75 | } | |
76 | } | |
77 | } | |
78 | } | |
79 | ||
80 | /** | |
c490a46a CW |
81 | * Create array for BAO (expects address params in as an |
82 | * element in array 'address' | |
83 | */ | |
6a488035 TO |
84 | $addressBAO = CRM_Core_BAO_Address::add($params, TRUE); |
85 | if (empty($addressBAO)) { | |
86 | return civicrm_api3_create_error("Address is not created or updated "); | |
87 | } | |
88 | else { | |
89 | $values = array(); | |
90 | $values = _civicrm_api3_dao_to_array($addressBAO, $params); | |
91 | return civicrm_api3_create_success($values, $params, 'address', $addressBAO); | |
92 | } | |
93 | } | |
94 | ||
11e09c59 | 95 | /** |
6a488035 TO |
96 | * Adjust Metadata for Create action |
97 | * | |
cf470720 TO |
98 | * @param array $params |
99 | * Array or parameters determined by getfields. | |
6a488035 TO |
100 | */ |
101 | function _civicrm_api3_address_create_spec(&$params) { | |
102 | $params['location_type_id']['api.required'] = 1; | |
103 | $params['contact_id']['api.required'] = 1; | |
104 | $params['country'] = array('title' => 'Name or 2-letter abbreviation of country. Looked up in civicrm_country table'); | |
105 | $params['street_parsing'] = array('title' => 'optional param to indicate you want the street_address field parsed into individual params'); | |
c7130c3e CW |
106 | $params['world_region'] = array( |
107 | 'title' => ts('World Region'), | |
108 | 'name' => 'world_region', | |
b8326bd2 | 109 | 'type' => CRM_Utils_Type::T_TEXT, |
c7130c3e CW |
110 | ); |
111 | } | |
112 | /** | |
113 | * Adjust Metadata for Get action | |
114 | * | |
cf470720 TO |
115 | * @param array $params |
116 | * Array or parameters determined by getfields. | |
c7130c3e CW |
117 | */ |
118 | function _civicrm_api3_address_get_spec(&$params) { | |
119 | $params['world_region'] = array( | |
120 | 'title' => ts('World Region'), | |
121 | 'name' => 'world_region', | |
b8326bd2 | 122 | 'type' => CRM_Utils_Type::T_TEXT, |
c7130c3e | 123 | ); |
6a488035 TO |
124 | } |
125 | ||
126 | /** | |
127 | * Deletes an existing Address | |
128 | * | |
cf470720 | 129 | * @param array $params |
6a488035 TO |
130 | * |
131 | * {@getfields address_delete} | |
132 | * {@example AddressDelete.php 0} | |
133 | * | |
a6c01b45 | 134 | * @return array |
72b3a70c | 135 | * api result array |
6a488035 TO |
136 | * @access public |
137 | */ | |
7c285037 | 138 | function civicrm_api3_address_delete($params) { |
6a488035 TO |
139 | return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__), $params); |
140 | } | |
141 | ||
142 | /** | |
143 | * Retrieve one or more addresses on address_id, contact_id, street_name, city | |
144 | * or a combination of those | |
145 | * | |
cf470720 | 146 | * @param mixed[] (reference ) input parameters |
6a488035 TO |
147 | * |
148 | * {@example AddressGet.php 0} | |
cf470720 TO |
149 | * @param array $params |
150 | * An associative array of name/value pairs. | |
6a488035 | 151 | * |
a6c01b45 | 152 | * @return array |
72b3a70c | 153 | * details of found addresses else error |
6a488035 TO |
154 | * {@getfields address_get} |
155 | * @access public | |
156 | */ | |
157 | function civicrm_api3_address_get(&$params) { | |
158 | return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params, TRUE, 'Address'); | |
159 | } |