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