3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
13 * This api exposes CiviCRM Domain configuration settings.
15 * @package CiviCRM_APIv3
19 * Get CiviCRM Domain details.
21 * @param array $params
24 * @throws \API_Exception
26 function civicrm_api3_domain_get($params) {
28 $params['version'] = $params['domain_version'] ??
NULL;
29 unset($params['version']);
31 if (!empty($params['current_domain'])) {
32 $params['id'] = CRM_Core_Config
::domainID();
34 if (!empty($params['options']) && !empty($params['options']['is_count'])) {
35 return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__
), $params);
38 // If requesting current domain, read from cache
39 if (!empty($params['id']) && $params['id'] == CRM_Core_Config
::domainID()) {
40 $bao = CRM_Core_BAO_Domain
::getDomain();
41 $domains = [$params['id'] => $bao->toArray()];
44 $bao = new CRM_Core_BAO_Domain();
45 _civicrm_api3_dao_set_filter($bao, $params, TRUE);
46 $domains = _civicrm_api3_dao_to_array($bao, $params, TRUE, 'Domain');
49 foreach ($domains as $domain) {
50 if (!empty($domain['contact_id'])) {
53 'contact_id' => $domain['contact_id'],
55 $values['location'] = CRM_Core_BAO_Location
::getValues($locparams, TRUE);
57 'street_address', 'supplemental_address_1', 'supplemental_address_2', 'supplemental_address_3',
58 'city', 'state_province_id', 'postal_code', 'country_id',
59 'geo_code_1', 'geo_code_2',
62 if (!empty($values['location']['email'])) {
63 $domain['domain_email'] = $values['location']['email'][1]['email'] ??
NULL;
66 if (!empty($values['location']['phone'])) {
67 $domain['domain_phone'] = [
68 'phone_type' => CRM_Core_PseudoConstant
::getLabel('CRM_Core_BAO_Phone', 'phone_type_id',
69 CRM_Utils_Array
::value('phone_type_id', $values['location']['phone'][1])),
70 'phone' => $values['location']['phone'][1]['phone'] ??
NULL,
74 if (!empty($values['location']['address'])) {
75 foreach ($address_array as $value) {
76 $domain['domain_address'][$value] = CRM_Utils_Array
::value($value,
77 $values['location']['address'][1]
82 list($domain['from_name'],
84 ) = CRM_Core_BAO_Domain
::getNameAndEmail(TRUE);
86 // Rename version to domain_version, see CRM-17430.
87 $domain['domain_version'] = $domain['version'];
88 unset($domain['version']);
89 $domains[$domain['id']] = array_merge($domains[$domain['id']], $domain);
93 return civicrm_api3_create_success($domains, $params, 'Domain', 'get', $bao);
97 * Adjust Metadata for Get action.
99 * The metadata is used for setting defaults, documentation & validation.
101 * @param array $params
102 * Array of parameters determined by getfields.
104 function _civicrm_api3_domain_get_spec(&$params) {
105 $params['current_domain'] = [
106 'title' => "Current Domain",
107 'description' => "get loaded domain",
112 * Create a new Domain.
114 * @param array $params
118 function civicrm_api3_domain_create($params) {
119 if (isset($params['domain_version'])) {
120 $params['version'] = $params['domain_version'];
123 unset($params['version']);
125 $result = _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__
), $params, 'Domain');
127 $result_value = CRM_Utils_Array
::first($result['values']);
128 if (isset($result_value['version'])) {
129 // Rename version to domain_version, see CRM-17430.
130 $result_value['domain_version'] = $result_value['version'];
131 unset($result_value['version']);
132 $result['values'][$result['id']] = $result_value;
138 * Adjust Metadata for Create action.
140 * The metadata is used for setting defaults, documentation & validation.
142 * @param array $params
143 * Array of parameters determined by getfields.
145 function _civicrm_api3_domain_create_spec(&$params) {
146 $params['domain_version'] = [
147 'title' => "CiviCRM Version",
148 'description' => "The civicrm version this instance is running",
149 'type' => CRM_Utils_Type
::T_STRING
,
151 $params['domain_version']['api.required'] = 1;
152 unset($params['version']);
153 $params['name']['api.required'] = 1;