Merge pull request #15475 from mecachisenros/externUrl
[civicrm-core.git] / api / v3 / MailingEventUnsubscribe.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
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 |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * APIv3 functions for registering/processing mailing group events.
15 *
16 * @package CiviCRM_APIv3
17 */
18
19 /**
20 * Unsubscribe from mailing group.
21 *
22 * @param array $params
23 * Array per getfields metadata.
24 *
25 * @return array
26 * Api result array
27 */
28 function civicrm_api3_mailing_event_unsubscribe_create($params) {
29
30 $job = $params['job_id'];
31 $queue = $params['event_queue_id'];
32 $hash = $params['hash'];
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 }
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
50 return civicrm_api3_create_error('Queue event could not be found');
51 }
52
53 /**
54 * Adjust Metadata for Create action.
55 *
56 * The metadata is used for setting defaults, documentation & validation.
57 *
58 * @param array $params
59 * Array of parameters determined by getfields.
60 */
61 function _civicrm_api3_mailing_event_unsubscribe_create_spec(&$params) {
62 $params['job_id'] = [
63 'api.required' => 1,
64 'title' => 'Mailing Job ID',
65 'type' => CRM_Utils_Type::T_INT,
66 ];
67 $params['hash'] = [
68 'api.required' => 1,
69 'title' => 'Mailing Hash',
70 'type' => CRM_Utils_Type::T_STRING,
71 ];
72 $params['event_queue_id'] = [
73 'api.required' => 1,
74 'title' => 'Mailing Queue ID',
75 'type' => CRM_Utils_Type::T_INT,
76 ];
77 }