Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
6a488035 TO |
2 | |
3 | /* | |
4 | +--------------------------------------------------------------------+ | |
39de6fd5 | 5 | | CiviCRM version 4.6 | |
6a488035 | 6 | +--------------------------------------------------------------------+ |
731a0992 | 7 | | Copyright CiviCRM LLC (c) 2004-2014 | |
6a488035 TO |
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 domain functions | |
31 | * | |
32 | * @package CiviCRM_APIv3 | |
33 | * @subpackage API_Domain | |
34 | * | |
731a0992 | 35 | * @copyright CiviCRM LLC (c) 2004-2014 |
6a488035 TO |
36 | * @version $Id: Domain.php 30171 2010-10-14 09:11:27Z mover $ |
37 | * | |
38 | */ | |
39 | ||
40 | /** | |
41 | * Get CiviCRM domain details | |
42 | * {@getfields domain_create} | |
43 | * @example DomainGet.php | |
44 | */ | |
45 | function civicrm_api3_domain_get($params) { | |
46 | ||
395d8dc6 | 47 | $params['version'] = CRM_Utils_Array::value('domain_version', $params); |
6a488035 TO |
48 | unset($params['version']); |
49 | ||
50 | $bao = new CRM_Core_BAO_Domain(); | |
a7488080 | 51 | if (!empty($params['current_domain'])) { |
6a488035 TO |
52 | $domainBAO = CRM_Core_Config::domainID(); |
53 | $params['id'] = $domainBAO; | |
54 | } | |
461c9a60 EM |
55 | if (!empty($params['options']) && !empty($params['options']['is_count'])) { |
56 | return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params); | |
57 | } | |
6a488035 | 58 | |
35671d00 TO |
59 | _civicrm_api3_dao_set_filter($bao, $params, TRUE, 'domain'); |
60 | $domains = _civicrm_api3_dao_to_array($bao, $params, TRUE, 'domain'); | |
6a488035 TO |
61 | |
62 | foreach ($domains as $domain) { | |
9b873358 | 63 | if (!empty($domain['contact_id'])) { |
6a488035 TO |
64 | $values = array(); |
65 | $locparams = array( | |
66 | 'contact_id' => $domain['contact_id'] | |
67 | ); | |
68 | $values['location'] = CRM_Core_BAO_Location::getValues($locparams, TRUE); | |
69 | ||
70 | $address_array = array( | |
71 | 'street_address', 'supplemental_address_1', 'supplemental_address_2', | |
72 | 'city', 'state_province_id', 'postal_code', 'country_id', | |
73 | 'geo_code_1', 'geo_code_2', | |
74 | ); | |
75 | ||
481a74f4 | 76 | if (!empty($values['location']['email'])) { |
6a488035 TO |
77 | $domain['domain_email'] = CRM_Utils_Array::value('email', $values['location']['email'][1]); |
78 | } | |
79 | ||
481a74f4 | 80 | if (!empty($values['location']['phone'])) { |
6a488035 TO |
81 | $domain['domain_phone'] = array( |
82 | 'phone_type' => CRM_Core_OptionGroup::getLabel( | |
83 | 'phone_type', | |
84 | CRM_Utils_Array::value( | |
85 | 'phone_type_id', | |
86 | $values['location']['phone'][1] | |
87 | ) | |
35671d00 | 88 | ), |
6a488035 TO |
89 | 'phone' => CRM_Utils_Array::value( |
90 | 'phone', | |
91 | $values['location']['phone'][1] | |
92 | ) | |
35671d00 TO |
93 | ); |
94 | } | |
6a488035 | 95 | |
481a74f4 | 96 | if (!empty($values['location']['address'])) { |
35671d00 TO |
97 | foreach ($address_array as $value) { |
98 | $domain['domain_address'][$value] = CRM_Utils_Array::value($value, | |
6a488035 | 99 | $values['location']['address'][1] |
35671d00 TO |
100 | ); |
101 | } | |
6a488035 | 102 | } |
6a488035 TO |
103 | |
104 | list($domain['from_name'], | |
105 | $domain['from_email'] | |
106 | ) = CRM_Core_BAO_Domain::getNameAndEmail(TRUE); | |
107 | $domains[$domain['id']] = array_merge($domains[$domain['id']], $domain); | |
108 | } | |
109 | } | |
110 | ||
6a488035 TO |
111 | return civicrm_api3_create_success($domains, $params, 'domain', 'get', $bao); |
112 | } | |
11e09c59 TO |
113 | |
114 | /** | |
6a488035 TO |
115 | * Adjust Metadata for Get action |
116 | * | |
117 | * The metadata is used for setting defaults, documentation & validation | |
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 | /** | |
126 | * Create a new domain | |
127 | * | |
128 | * @param array $params | |
129 | * | |
130 | * @return array | |
131 | * @example DomainCreate.php | |
132 | * {@getfields domain_create} | |
133 | */ | |
134 | function civicrm_api3_domain_create($params) { | |
135 | $params['version'] = $params['domain_version']; | |
136 | return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params); | |
137 | } | |
11e09c59 TO |
138 | |
139 | /** | |
6a488035 TO |
140 | * Adjust Metadata for Create action |
141 | * | |
142 | * The metadata is used for setting defaults, documentation & validation | |
cf470720 TO |
143 | * @param array $params |
144 | * Array or parameters determined by getfields. | |
6a488035 TO |
145 | */ |
146 | function _civicrm_api3_domain_create_spec(&$params) { | |
147 | $params['domain_version'] = $params['version']; | |
148 | $params['domain_version']['api.required'] = 1; | |
149 | unset($params['version']); | |
150 | $params['name']['api.required'] = 1; | |
151 | } |