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