Merge pull request #417 from colemanw/CRM-12339
[civicrm-core.git] / api / v2 / Domain.php
1 <?php
2 // $Id: Domain.php 45502 2013-02-08 13:32:55Z kurund $
3
4
5 /*
6 +--------------------------------------------------------------------+
7 | CiviCRM version 4.3 |
8 +--------------------------------------------------------------------+
9 | Copyright CiviCRM LLC (c) 2004-2013 |
10 +--------------------------------------------------------------------+
11 | This file is a part of CiviCRM. |
12 | |
13 | CiviCRM is free software; you can copy, modify, and distribute it |
14 | under the terms of the GNU Affero General Public License |
15 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
16 | |
17 | CiviCRM is distributed in the hope that it will be useful, but |
18 | WITHOUT ANY WARRANTY; without even the implied warranty of |
19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
20 | See the GNU Affero General Public License for more details. |
21 | |
22 | You should have received a copy of the GNU Affero General Public |
23 | License and the CiviCRM Licensing Exception along |
24 | with this program; if not, contact CiviCRM LLC |
25 | at info[AT]civicrm[DOT]org. If you have questions about the |
26 | GNU Affero General Public License or the licensing of CiviCRM, |
27 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
28 +--------------------------------------------------------------------+
29 */
30
31 /**
32 * File for the CiviCRM APIv2 domain functions
33 *
34 * @package CiviCRM_APIv2
35 * @subpackage API_Domain
36 *
37 * @copyright CiviCRM LLC (c) 2004-2013
38 * @version $Id: Domain.php 45502 2013-02-08 13:32:55Z kurund $
39 *
40 */
41
42 /**
43 * Include utility functions
44 */
45 require_once 'api/v2/utils.php';
46
47 /**
48 * Generic file to retrieve all the constants and
49 * pseudo constants used in CiviCRM
50 *
51 */
52 function civicrm_domain_get() {
53 require_once 'CRM/Core/BAO/Domain.php';
54 $dao = CRM_Core_BAO_Domain::getDomain();
55 $values = array();
56 $params = array(
57 'entity_id' => $dao->id,
58 'entity_table' => 'civicrm_domain',
59 );
60 require_once 'CRM/Core/BAO/Location.php';
61 $values['location'] = CRM_Core_BAO_Location::getValues($params, TRUE);
62 $address_array = array(
63 'street_address', 'supplemental_address_1', 'supplemental_address_2',
64 'city', 'state_province_id', 'postal_code', 'country_id', 'geo_code_1', 'geo_code_2',
65 );
66 require_once 'CRM/Core/OptionGroup.php';
67 $domain[$dao->id] = array(
68 'id' => $dao->id,
69 'domain_name' => $dao->name,
70 'description' => $dao->description,
71 'domain_email' => CRM_Utils_Array::value('email', $values['location']['email'][1]),
72 'domain_phone' => array(
73 'phone_type' => CRM_Core_OptionGroup::getLabel('phone_type', CRM_Utils_Array::value('phone_type_id', $values['location']['phone'][1])),
74 'phone' => CRM_Utils_Array::value('phone', $values['location']['phone'][1]),
75 ),
76 );
77 foreach ($address_array as $value) {
78 $domain[$dao->id]['domain_address'][$value] = CRM_Utils_Array::value($value, $values['location']['address'][1]);
79 }
80 list($domain[$dao->id]['from_name'], $domain[$dao->id]['from_email']) = CRM_Core_BAO_Domain::getNameAndEmail();
81 return $domain;
82 }
83
84 /**
85 * Create a new domain
86 *
87 * @param array $params
88 *
89 * @return array
90 */
91 function civicrm_domain_create($params) {
92 require_once 'CRM/Core/BAO/Domain.php';
93
94 if (!is_array($params)) {
95 return civicrm_create_error('Params need to be of type array!');
96 }
97
98 if (empty($params)) {
99 return civicrm_create_error('Params cannot be empty!');
100 }
101
102 $domain = CRM_Core_BAO_Domain::create($params);
103 $domain_array = array();
104 _civicrm_object_to_array($domain, $domain_array);
105 return $domain_array;
106 }
107