-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtripal_hq_email.inc
132 lines (106 loc) · 4.37 KB
/
tripal_hq_email.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?php
/**
* @file
* Mail functions for notifying users and admins of acceptance, submission, etc.
*/
/**
* Implements hook_mail().
*
* @param string $key
* One of the following strings:
* - user_submit_notice
* - admin_submit_notice
* - user_accept_notice
* - admin_accept_notice
* - user_reject_notice
* - admin_reject_notice
* - user_edit_notice
* - admin_edit_notice.
*/
function tripal_hq_mail(string $key, &$message, $params) {
$language = $message['language'];
$site_name = variable_get('site_name');
global $base_url;
$uid = $params->uid;
$user_object = user_load($uid);
$submitter_name = $user_object->name;
$user_dash = $base_url . '/tripal_hq/bio_data';
$admin_dash = $base_url . '/tripal_hq/admin';
$title = $params->title;
$bundle_id = $params->bundle_id;
$bundle = tripal_load_bundle_entity(['id' => $bundle_id]);
$bundle_label = $bundle->label;
$entity_id = $params->entity_id;
$link = $base_url . 'bio_data/' . $entity_id;
switch ($key) {
/*
* Acknowledge user has submitted a content request.
*/
case 'user_submit_notice':
$message['body'][] = t("Dear !user,", ['!user' => $submitter_name]);
$message['subject'] = t('!site Content Submission Request Received', ['!site' => $site_name]);
$message['body'][] = t('You have successfully submitted a request to create the !type record !title .', [
'!type' => $bundle_label,
'!title' => $title,
]);
$message['body'][] = t('You can review your request status at !url', [
'!url' => $user_dash,
]);
break;
/*
* Let relevant admins know a content request has been received.
*/
case 'admin_submit_notice':
$message['subject'] = t('!site Content Submission Request Received', ['!site' => $site_name], ['langcode' => $language->language]);
$message['body'][] = t('Dear !site admin,', ['!site' => $site_name], ['langcode' => $language->language]);
$message['body'][] = t("User !user has submitted the following content creation request:", [
'!user' => $submitter_name,
]);
$message['body'][] = t("Type: !type", ['!type' => $bundle_label]);
$message['body'][] = t("Title: !title", [
'!title' => $title,
]);
$message['body'][] = t("To approve or deny this request, please visit your Tripal HQ content portal, located here: !url", ['!url' => $admin_dash]);
break;
/*
* User's submission has been approved!
*/
case 'user_accept_notice':
$message['subject'] = t('!site Content Submission Request Approved', ['!site' => $site_name], ['langcode' => $language->language]);
$message['body'][] = t("Dear !user,", ['!user' => $submitter_name]);
$message['body'][] = t('Your !type submission titled: !title, has been approved.', [
'!type' => $bundle_label,
'!title' => $title,
]);
$message['body'][] = t('Your newly created content is available here: !url', ['!url' => $link]);
break;
/*
* Admin: submission has been approved!
*/
case 'admin_accept_notice':
$message['body'][] = t('Dear !site admin,', ['!site' => $site_name]);
$message['body'][] = t('The !type submitted by !user, titled: !title , has been approved.', [
'!type' => $bundle_label,
'!title' => $title,
'!user' => $submitter_name,
]);
$message['body'][] = t('The newly created content is available here: !url', ['!url' => $link]);
return;
break;
case 'user_reject_notice':
$message['subject'] = t('!site Content Submission Request Denied', ['!site' => $site_name], ['langcode' => $language->language]);
$message['body'][] = t("Dear !user,", ['!user' => $submitter_name]);
$message['body'][] = t('Your !type submission titled: !title , has been denied.', [
'!type' => $bundle_label,
'!title' => $title,
]);
break;
case 'admin_reject_notice':
$message['body'][] = t('Dear !site admin,', ['!site' => $site_name]);
$message['subject'] = t('!site Content Submission Request Denied', ['!site' => $site_name]);
$message['body'][] = t('The submission !name has been denied.', ['!name' => $title]);
break;
}
$message['body'][] = '<br/>Regards,<br/>The ' . $site_name . ' team';
$message['headers']['Content-Type'] = 'text/html; charset=UTF-8; format=flowed';
}