getfields api - ensure 'name' property is set for every field
[civicrm-core.git] / api / v3 / MailingGroup.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 +--------------------------------------------------------------------+
d25dd0ee 26 */
6a488035
TO
27
28/**
29 *
30 * APIv3 functions for registering/processing mailing group events.
31 *
32 * @package CiviCRM_APIv3
33 * @subpackage API_MailerGroup
731a0992 34 * @copyright CiviCRM LLC (c) 2004-2014
6a488035 35 * $Id$
6a488035
TO
36 */
37
a14e9d08 38/**
22242c87
EM
39 * Declare deprecated functions.
40 *
a14e9d08 41 * @deprecated api notice
a6c01b45 42 * @return string
72b3a70c 43 * to indicate this entire api entity is deprecated
a14e9d08
CW
44 */
45function _civicrm_api3_mailing_group_deprecation() {
46 return 'The mailing_group api is deprecated. Use the mailing_event apis instead.';
47}
48
6a488035 49/**
9d32e6f7
EM
50 * Handle an unsubscribe event.
51 *
6a488035
TO
52 * @deprecated
53 *
54 * @param array $params
55 *
56 * @return array
57 */
58function civicrm_api3_mailing_group_event_unsubscribe($params) {
7e6e8bd6 59 return civicrm_api('mailing_event_unsubscribe', 'create', $params);
6a488035
TO
60}
61
62/**
9d32e6f7
EM
63 * Handle a site-level unsubscribe event.
64 *
bafd17fb 65 * @deprecated
6a488035
TO
66 *
67 * @param array $params
68 *
69 * @return array
70 */
71function civicrm_api3_mailing_group_event_domain_unsubscribe($params) {
7e6e8bd6
TO
72 $params['org_unsubscribe'] = 1;
73 return civicrm_api('mailing_event_unsubscribe', 'create', $params);
6a488035
TO
74}
75
76/**
d1b0d05e
EM
77 * Handle a re-subscription event.
78 *
6a488035
TO
79 * @deprecated
80 *
81 * @param array $params
82 *
83 * @return array
84 */
85function civicrm_api3_mailing_group_event_resubscribe($params) {
7e6e8bd6 86 return civicrm_api('mailing_event_resubscribe', 'create', $params);
6a488035
TO
87}
88
89/**
dc64d047
EM
90 * Handle a subscription event.
91 *
6a488035
TO
92 * @deprecated
93 *
94 * @param array $params
95 *
96 * @return array
97 */
98function civicrm_api3_mailing_group_event_subscribe($params) {
7e6e8bd6 99 return civicrm_api('mailing_event_subscribe', 'create', $params);
6a488035
TO
100}
101
c23f45d3 102/**
dc64d047
EM
103 * Create mailing group.
104 *
c23f45d3 105 * @param array $params
dc64d047 106 *
c23f45d3
EM
107 * @return array
108 * @throws \API_Exception
109 */
21eb0c57
TO
110function civicrm_api3_mailing_group_create($params) {
111 return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params);
112}
113
aa1b1481 114/**
dc64d047
EM
115 * Get mailing group.
116 *
c490a46a 117 * @param array $params
aa1b1481
EM
118 *
119 * @return array
120 */
f27a0a8e 121function civicrm_api3_mailing_group_get($params) {
122 return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params);
123}
124
c23f45d3 125/**
22242c87
EM
126 * Delete mailing group.
127 *
c23f45d3 128 * @param array $params
22242c87 129 *
c23f45d3
EM
130 * @return array
131 * @throws \API_Exception
132 */
133function civicrm_api3_mailing_group_delete($params) {
f27a0a8e 134 return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__), $params);
135}
136
c23f45d3 137/**
dc64d047
EM
138 * Get metadata for mailing group functions.
139 *
c23f45d3 140 * @param array $params
22242c87 141 *
c23f45d3
EM
142 * @return array
143 */
6a488035 144function civicrm_api3_mailing_group_getfields($params) {
7e6e8bd6
TO
145 $dao = _civicrm_api3_get_DAO('Subscribe');
146 $d = new $dao();
147 $fields = $d->fields();
148 $d->free();
6a488035 149
7e6e8bd6
TO
150 $dao = _civicrm_api3_get_DAO('Unsubscribe');
151 $d = new $dao();
152 $fields = $fields + $d->fields();
153 $d->free();
6a488035 154
7e6e8bd6
TO
155 // CRM-13830 - prevent the api wrapper from helping out with pseudoconstants
156 // Since these fields don't belong to this entity it will fail
157 foreach ($fields as &$field) {
158 unset($field['pseudoconstant']);
159 }
bafd17fb 160
77d80c9f 161 return civicrm_api3_create_success($fields, $params, 'mailing_group', 'getfields');
6a488035 162}