-
Notifications
You must be signed in to change notification settings - Fork 0
/
SSEventsMessageMapping.php
102 lines (86 loc) · 2.92 KB
/
SSEventsMessageMapping.php
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
<?php
require_once('SSUtilities.php');
class SSEventsMessageMapping {
/**
* Compose a ready to use in MEAN network intex a styled message.
* Consists of two part: colored Font Awesome icon and text description
* @param array $event array(
* 'action', // 'created', 'deleted', 'updated', 'added', 'activated', 'deactivated', 'accessed', 'file_updated', 'logged_in', 'logged_out', 'wrong_password', 'installed', etc...
* 'object_type', // 'Attachment', 'Menu', 'Options', 'Plugin', 'Post', 'Taxonomy', 'Theme', 'User', 'Widget', etc...
* 'object_subtype', // Page, image. May not be applicable
* 'object_id', // id of the object
* 'object_name' // name of the object
* )
* @return array array(
* 'design' => array(
* 'icon' => 'fa-file-text', // Font Awesome icon name
* 'color' => '#8FD5FF' // Color
* ),
* 'message' => 'A new user "test (email@domain.com)" has been registered'
* )
*/
static function composeEventData($event, $default_message = '') {
if (!is_array($event)) {
SSUtilities::error_log('Expected to get an array', 'error');
return;
}
if (empty($event)) {
SSUtilities::error_log('Empty an array', 'warn');
return;
}
$design = array();
$message = '';
$color_created = '#238a36';
$color_updated = '#8FD5FF';
$color_deleted = '#9f253f';
switch ($event['object_type']) {
case 'content':
$design['icon'] = 'fa-file-text';
switch ($event['action']) {
case 'created':
$design['color'] = $color_created;
break;
case 'updated':
$design['color'] = $color_updated;
break;
case 'deleted':
$design['color'] = $color_deleted;
break;
}
$message = SSUtilities::t('{type} "{name}" has been {action}.', array(
'{type}' => ucfirst($event['object_subtype']),
'{name}' => $event['object_name'],
'{action}' => $event['action']
));
break;
case 'user':
$design['icon'] = 'fa-user';
$design['color'] = '#8664aa';
break;
case 'system':
$design['icon'] = 'fa-cubes';
$design['color'] = '#c79696';
break;
case 'actions':
$design['icon'] = 'fa-certificate';
$design['color'] = '#fd8e00';
break;
case 'cron':
$design['icon'] = 'fa-cogs';
$design['color'] = '#de1b16';
$message = SSUtilities::t('Cron run completed.');
break;
default:
$design['color'] = '#19617a';
$design['icon'] = 'fa-bars';
break;
}
$message = $message ? $message : $default_message;
$data = array();
$data['key'] = $event['object_type'];
$data['name'] = $message;
$data['data']['description'] = $message;
$data['design'] = $design;
return $data;
}
}