Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
6a488035 TO |
2 | /* |
3 | +--------------------------------------------------------------------+ | |
a30c801b | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 5 | | | |
a30c801b TO |
6 | | This work is published under the GNU AGPLv3 license with some | |
7 | | permitted exceptions and without any warranty. For full license | | |
8 | | and copyright information, see https://civicrm.org/licensing | | |
6a488035 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
6a488035 TO |
11 | |
12 | /** | |
13 | * | |
14 | * APIv3 functions for registering/processing mailing group events. | |
15 | * | |
16 | * @package CiviCRM_APIv3 | |
6a488035 TO |
17 | */ |
18 | ||
19 | /** | |
22242c87 | 20 | * Unsubscribe from mailing group. |
6a488035 | 21 | * |
cf470720 | 22 | * @param array $params |
22242c87 | 23 | * Array per getfields metadata. |
6a488035 | 24 | * |
22242c87 | 25 | * @return array |
78373706 | 26 | * Api result array |
6a488035 TO |
27 | */ |
28 | function civicrm_api3_mailing_event_unsubscribe_create($params) { | |
29 | ||
ef170fe0 | 30 | $job = $params['job_id']; |
6a488035 | 31 | $queue = $params['event_queue_id']; |
ef170fe0 | 32 | $hash = $params['hash']; |
6a488035 TO |
33 | if (empty($params['org_unsubscribe'])) { |
34 | $groups = CRM_Mailing_Event_BAO_Unsubscribe::unsub_from_mailing($job, $queue, $hash); | |
35 | if (count($groups)) { | |
36 | CRM_Mailing_Event_BAO_Unsubscribe::send_unsub_response($queue, $groups, FALSE, $job); | |
37 | return civicrm_api3_create_success($params); | |
38 | } | |
6a488035 TO |
39 | } |
40 | else { | |
41 | $unsubs = CRM_Mailing_Event_BAO_Unsubscribe::unsub_from_domain($job, $queue, $hash); | |
42 | if (!$unsubs) { | |
43 | return civicrm_api3_create_error('Domain Queue event could not be found'); | |
44 | } | |
45 | ||
46 | CRM_Mailing_Event_BAO_Unsubscribe::send_unsub_response($queue, NULL, TRUE, $job); | |
47 | return civicrm_api3_create_success($params); | |
48 | } | |
49 | ||
6a488035 TO |
50 | return civicrm_api3_create_error('Queue event could not be found'); |
51 | } | |
11e09c59 TO |
52 | |
53 | /** | |
0aa0303c EM |
54 | * Adjust Metadata for Create action. |
55 | * | |
56 | * The metadata is used for setting defaults, documentation & validation. | |
1c88e578 | 57 | * |
cf470720 | 58 | * @param array $params |
b081365f | 59 | * Array of parameters determined by getfields. |
6a488035 TO |
60 | */ |
61 | function _civicrm_api3_mailing_event_unsubscribe_create_spec(&$params) { | |
cf8f0fff | 62 | $params['job_id'] = [ |
d142432b EM |
63 | 'api.required' => 1, |
64 | 'title' => 'Mailing Job ID', | |
65 | 'type' => CRM_Utils_Type::T_INT, | |
cf8f0fff CW |
66 | ]; |
67 | $params['hash'] = [ | |
d142432b EM |
68 | 'api.required' => 1, |
69 | 'title' => 'Mailing Hash', | |
70 | 'type' => CRM_Utils_Type::T_STRING, | |
cf8f0fff CW |
71 | ]; |
72 | $params['event_queue_id'] = [ | |
d142432b EM |
73 | 'api.required' => 1, |
74 | 'title' => 'Mailing Queue ID', | |
75 | 'type' => CRM_Utils_Type::T_INT, | |
cf8f0fff | 76 | ]; |
6a488035 | 77 | } |