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 | /** | |
c28e1768 | 29 | * This api exposes CiviCRM domain. |
6a488035 TO |
30 | * |
31 | * @package CiviCRM_APIv3 | |
32 | * @subpackage API_Domain | |
33 | * | |
6a488035 TO |
34 | */ |
35 | ||
36 | /** | |
9d32e6f7 EM |
37 | * Get CiviCRM domain details. |
38 | * | |
d0997921 | 39 | * @param array $params |
9d32e6f7 | 40 | * |
645ee340 EM |
41 | * @return array |
42 | * @throws \API_Exception | |
6a488035 TO |
43 | */ |
44 | function civicrm_api3_domain_get($params) { | |
45 | ||
395d8dc6 | 46 | $params['version'] = CRM_Utils_Array::value('domain_version', $params); |
6a488035 TO |
47 | unset($params['version']); |
48 | ||
49 | $bao = new CRM_Core_BAO_Domain(); | |
a7488080 | 50 | if (!empty($params['current_domain'])) { |
6a488035 TO |
51 | $domainBAO = CRM_Core_Config::domainID(); |
52 | $params['id'] = $domainBAO; | |
53 | } | |
461c9a60 EM |
54 | if (!empty($params['options']) && !empty($params['options']['is_count'])) { |
55 | return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params); | |
56 | } | |
6a488035 | 57 | |
35671d00 TO |
58 | _civicrm_api3_dao_set_filter($bao, $params, TRUE, 'domain'); |
59 | $domains = _civicrm_api3_dao_to_array($bao, $params, TRUE, 'domain'); | |
6a488035 TO |
60 | |
61 | foreach ($domains as $domain) { | |
9b873358 | 62 | if (!empty($domain['contact_id'])) { |
6a488035 TO |
63 | $values = array(); |
64 | $locparams = array( | |
21dfd5f5 | 65 | 'contact_id' => $domain['contact_id'], |
6a488035 TO |
66 | ); |
67 | $values['location'] = CRM_Core_BAO_Location::getValues($locparams, TRUE); | |
68 | ||
69 | $address_array = array( | |
70 | 'street_address', 'supplemental_address_1', 'supplemental_address_2', | |
71 | 'city', 'state_province_id', 'postal_code', 'country_id', | |
72 | 'geo_code_1', 'geo_code_2', | |
73 | ); | |
74 | ||
481a74f4 | 75 | if (!empty($values['location']['email'])) { |
6a488035 TO |
76 | $domain['domain_email'] = CRM_Utils_Array::value('email', $values['location']['email'][1]); |
77 | } | |
78 | ||
481a74f4 | 79 | if (!empty($values['location']['phone'])) { |
6a488035 TO |
80 | $domain['domain_phone'] = array( |
81 | 'phone_type' => CRM_Core_OptionGroup::getLabel( | |
82 | 'phone_type', | |
83 | CRM_Utils_Array::value( | |
84 | 'phone_type_id', | |
85 | $values['location']['phone'][1] | |
e70a7fc0 | 86 | ) |
28a04ea9 | 87 | ), |
88 | 'phone' => CRM_Utils_Array::value( | |
6a488035 | 89 | 'phone', |
e70a7fc0 | 90 | $values['location']['phone'][1] |
28a04ea9 | 91 | ), |
35671d00 TO |
92 | ); |
93 | } | |
6a488035 | 94 | |
481a74f4 | 95 | if (!empty($values['location']['address'])) { |
35671d00 TO |
96 | foreach ($address_array as $value) { |
97 | $domain['domain_address'][$value] = CRM_Utils_Array::value($value, | |
6a488035 | 98 | $values['location']['address'][1] |
35671d00 TO |
99 | ); |
100 | } | |
6a488035 | 101 | } |
6a488035 TO |
102 | |
103 | list($domain['from_name'], | |
104 | $domain['from_email'] | |
105 | ) = CRM_Core_BAO_Domain::getNameAndEmail(TRUE); | |
106 | $domains[$domain['id']] = array_merge($domains[$domain['id']], $domain); | |
107 | } | |
108 | } | |
109 | ||
6a488035 TO |
110 | return civicrm_api3_create_success($domains, $params, 'domain', 'get', $bao); |
111 | } | |
11e09c59 TO |
112 | |
113 | /** | |
9d32e6f7 | 114 | * Adjust Metadata for Get action. |
6a488035 | 115 | * |
0aa0303c EM |
116 | * The metadata is used for setting defaults, documentation & validation. |
117 | * | |
cf470720 TO |
118 | * @param array $params |
119 | * Array or parameters determined by getfields. | |
6a488035 TO |
120 | */ |
121 | function _civicrm_api3_domain_get_spec(&$params) { | |
122 | $params['current_domain'] = array('title' => "get loaded domain"); | |
123 | } | |
124 | ||
125 | /** | |
9d32e6f7 | 126 | * Create a new domain. |
6a488035 TO |
127 | * |
128 | * @param array $params | |
129 | * | |
130 | * @return array | |
6a488035 TO |
131 | */ |
132 | function civicrm_api3_domain_create($params) { | |
133 | $params['version'] = $params['domain_version']; | |
134 | return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params); | |
135 | } | |
11e09c59 TO |
136 | |
137 | /** | |
0aa0303c EM |
138 | * Adjust Metadata for Create action. |
139 | * | |
140 | * The metadata is used for setting defaults, documentation & validation. | |
6a488035 | 141 | * |
cf470720 TO |
142 | * @param array $params |
143 | * Array or parameters determined by getfields. | |
6a488035 TO |
144 | */ |
145 | function _civicrm_api3_domain_create_spec(&$params) { | |
146 | $params['domain_version'] = $params['version']; | |
147 | $params['domain_version']['api.required'] = 1; | |
148 | unset($params['version']); | |
149 | $params['name']['api.required'] = 1; | |
150 | } |