Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | // $Id$ | |
3 | ||
4 | /* | |
5 | +--------------------------------------------------------------------+ | |
6 | | CiviCRM version 4.3 | | |
7 | +--------------------------------------------------------------------+ | |
8 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
9 | +--------------------------------------------------------------------+ | |
10 | | This file is a part of CiviCRM. | | |
11 | | | | |
12 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
13 | | under the terms of the GNU Affero General Public License | | |
14 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
15 | | | | |
16 | | CiviCRM is distributed in the hope that it will be useful, but | | |
17 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
18 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
19 | | See the GNU Affero General Public License for more details. | | |
20 | | | | |
21 | | You should have received a copy of the GNU Affero General Public | | |
22 | | License and the CiviCRM Licensing Exception along | | |
23 | | with this program; if not, contact CiviCRM LLC | | |
24 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
25 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
26 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
27 | +--------------------------------------------------------------------+ | |
28 | */ | |
29 | ||
30 | /** | |
31 | * File for the CiviCRM APIv3 domain functions | |
32 | * | |
33 | * @package CiviCRM_APIv3 | |
34 | * @subpackage API_Domain | |
35 | * | |
36 | * @copyright CiviCRM LLC (c) 2004-2013 | |
37 | * @version $Id: Domain.php 30171 2010-10-14 09:11:27Z mover $ | |
38 | * | |
39 | */ | |
40 | ||
41 | /** | |
42 | * Get CiviCRM domain details | |
43 | * {@getfields domain_create} | |
44 | * @example DomainGet.php | |
45 | */ | |
46 | function civicrm_api3_domain_get($params) { | |
47 | ||
48 | $params['version'] = CRM_Utils_array::value('domain_version', $params); | |
49 | unset($params['version']); | |
50 | ||
51 | $bao = new CRM_Core_BAO_Domain(); | |
52 | if (CRM_Utils_Array::value('current_domain', $params)) { | |
53 | $domainBAO = CRM_Core_Config::domainID(); | |
54 | $params['id'] = $domainBAO; | |
55 | } | |
56 | ||
57 | _civicrm_api3_dao_set_filter($bao, $params, true, 'domain'); | |
58 | $domains = _civicrm_api3_dao_to_array($bao, $params, true,'domain'); | |
59 | ||
60 | foreach ($domains as $domain) { | |
61 | if(!empty($domain['contact_id'])){ | |
62 | $values = array(); | |
63 | $locparams = array( | |
64 | 'contact_id' => $domain['contact_id'] | |
65 | ); | |
66 | $values['location'] = CRM_Core_BAO_Location::getValues($locparams, TRUE); | |
67 | ||
68 | $address_array = array( | |
69 | 'street_address', 'supplemental_address_1', 'supplemental_address_2', | |
70 | 'city', 'state_province_id', 'postal_code', 'country_id', | |
71 | 'geo_code_1', 'geo_code_2', | |
72 | ); | |
73 | ||
74 | if ( !empty( $values['location']['email'] ) ) { | |
75 | $domain['domain_email'] = CRM_Utils_Array::value('email', $values['location']['email'][1]); | |
76 | } | |
77 | ||
78 | if ( !empty( $values['location']['phone'] ) ) { | |
79 | $domain['domain_phone'] = array( | |
80 | 'phone_type' => CRM_Core_OptionGroup::getLabel( | |
81 | 'phone_type', | |
82 | CRM_Utils_Array::value( | |
83 | 'phone_type_id', | |
84 | $values['location']['phone'][1] | |
85 | ) | |
86 | ), | |
87 | 'phone' => CRM_Utils_Array::value( | |
88 | 'phone', | |
89 | $values['location']['phone'][1] | |
90 | ) | |
91 | ); | |
92 | } | |
93 | ||
94 | if ( !empty( $values['location']['address'] ) ) { | |
95 | foreach ($address_array as $value) { | |
96 | $domain['domain_address'][$value] = CRM_Utils_Array::value($value, | |
97 | $values['location']['address'][1] | |
98 | ); | |
99 | } | |
100 | } | |
101 | ||
102 | list($domain['from_name'], | |
103 | $domain['from_email'] | |
104 | ) = CRM_Core_BAO_Domain::getNameAndEmail(TRUE); | |
105 | $domains[$domain['id']] = array_merge($domains[$domain['id']], $domain); | |
106 | } | |
107 | } | |
108 | ||
109 | ||
110 | return civicrm_api3_create_success($domains, $params, 'domain', 'get', $bao); | |
111 | } | |
11e09c59 TO |
112 | |
113 | /** | |
6a488035 TO |
114 | * Adjust Metadata for Get action |
115 | * | |
116 | * The metadata is used for setting defaults, documentation & validation | |
117 | * @param array $params array or parameters determined by getfields | |
118 | */ | |
119 | function _civicrm_api3_domain_get_spec(&$params) { | |
120 | $params['current_domain'] = array('title' => "get loaded domain"); | |
121 | } | |
122 | ||
123 | /** | |
124 | * Create a new domain | |
125 | * | |
126 | * @param array $params | |
127 | * | |
128 | * @return array | |
129 | * @example DomainCreate.php | |
130 | * {@getfields domain_create} | |
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 | /** | |
6a488035 TO |
138 | * Adjust Metadata for Create action |
139 | * | |
140 | * The metadata is used for setting defaults, documentation & validation | |
141 | * @param array $params array or parameters determined by getfields | |
142 | */ | |
143 | function _civicrm_api3_domain_create_spec(&$params) { | |
144 | $params['domain_version'] = $params['version']; | |
145 | $params['domain_version']['api.required'] = 1; | |
146 | unset($params['version']); | |
147 | $params['name']['api.required'] = 1; | |
148 | } | |
149 |