Merge pull request #17376 from artfulrobot/artfulrobot-public-status-messages
[civicrm-core.git] / api / v3 / MailingEventResubscribe.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 * Subscribe from mailing group.
21 *
22 * @param array $params
23 *
24 * @return array
25 * api result array
26 */
27 function civicrm_api3_mailing_event_resubscribe_create($params) {
28
29 $groups = CRM_Mailing_Event_BAO_Resubscribe::resub_to_mailing(
30 $params['job_id'],
31 $params['event_queue_id'],
32 $params['hash']
33 );
34
35 if (count($groups)) {
36 CRM_Mailing_Event_BAO_Resubscribe::send_resub_response(
37 $params['event_queue_id'],
38 $groups, FALSE,
39 $params['job_id']
40 );
41 return civicrm_api3_create_success($params);
42 }
43 return civicrm_api3_create_error('Queue event could not be found');
44 }
45
46 /**
47 * Adjust Metadata for Create action.
48 *
49 * The metadata is used for setting defaults, documentation & validation.
50 *
51 * @param array $params
52 * Array of parameters determined by getfields.
53 */
54 function _civicrm_api3_mailing_event_resubscribe_create_spec(&$params) {
55 $params['event_queue_id'] = [
56 'api.required' => 1,
57 'title' => 'Event Queue ID',
58 'type' => CRM_Utils_Type::T_INT,
59 ];
60 $params['job_id'] = [
61 'api.required' => 1,
62 'title' => 'Job ID',
63 'type' => CRM_Utils_Type::T_INT,
64 ];
65 $params['hash'] = [
66 'api.required' => 1,
67 'title' => 'Hash',
68 'type' => CRM_Utils_Type::T_STRING,
69 ];
70 }