1
|
|
|
<?php |
2
|
|
|
|
|
|
|
|
3
|
|
|
namespace BristolSU\Module\StaticPage\Events; |
4
|
|
|
|
5
|
|
|
use BristolSU\Module\StaticPage\Models\ButtonClick; |
6
|
|
|
use BristolSU\Module\StaticPage\Models\PageView; |
7
|
|
|
use BristolSU\Support\Action\Contracts\TriggerableEvent; |
8
|
|
|
use BristolSU\Support\ActivityInstance\Contracts\ActivityInstanceRepository; |
9
|
|
|
use BristolSU\Support\ModuleInstance\Contracts\ModuleInstanceRepository; |
10
|
|
|
|
11
|
|
|
class ButtonUnsubmitted implements TriggerableEvent |
|
|
|
|
12
|
|
|
{ |
13
|
|
|
|
14
|
|
|
/** |
|
|
|
|
15
|
|
|
* @var ButtonClick |
16
|
|
|
*/ |
17
|
|
|
private $buttonClick; |
|
|
|
|
18
|
|
|
|
19
|
5 |
|
public function __construct(ButtonClick $buttonClick) |
|
|
|
|
20
|
|
|
{ |
21
|
|
|
|
22
|
5 |
|
$this->buttonClick = $buttonClick; |
23
|
5 |
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Register metadata about the fields the event supplies. |
27
|
|
|
* |
28
|
|
|
* For each field returned in getFields, pass in a label and a helptext. |
29
|
|
|
* e.g. [ |
30
|
|
|
* 'user_id' => [ |
31
|
|
|
* 'label' => 'User ID', |
32
|
|
|
* 'helptext' => 'The ID of the user who posted the comment.' |
33
|
|
|
* ], |
34
|
|
|
* ... |
35
|
|
|
* ] |
36
|
|
|
* @return array |
|
|
|
|
37
|
|
|
*/ |
38
|
1 |
|
public static function getFieldMetaData(): array |
39
|
|
|
{ |
40
|
|
|
return [ |
41
|
|
|
'user_id' => [ |
42
|
1 |
|
'label' => 'User ID', |
43
|
|
|
'helptext' => 'The ID of the user' |
44
|
|
|
], |
45
|
|
|
'user_email' => [ |
46
|
|
|
'label' => 'Email Address', |
47
|
|
|
'helptext' => 'Email Address of the user. May be empty.' |
48
|
|
|
], |
49
|
|
|
'user_first_name' => [ |
50
|
|
|
'label' => 'First Name', |
51
|
|
|
'helptext' => 'First Name of the user. May be empty.' |
52
|
|
|
], |
53
|
|
|
'user_last_name' => [ |
54
|
|
|
'label' => 'Last Name', |
55
|
|
|
'helptext' => 'Last Name of the user. May be empty.' |
56
|
|
|
], |
57
|
|
|
'user_preferred_name' => [ |
58
|
|
|
'label' => 'Preferred Name', |
59
|
|
|
'helptext' => 'Preferred Name of the user. May be empty.' |
60
|
|
|
], |
61
|
|
|
'module_instance_id' => [ |
62
|
|
|
'label' => 'Module Instance ID', |
63
|
|
|
'helptext' => 'ID of the module instance viewed' |
64
|
|
|
], |
65
|
|
|
'module_instance_name' => [ |
66
|
|
|
'label' => 'Module Instance Name', |
67
|
|
|
'helptext' => 'Name of the module instance viewed.' |
68
|
|
|
], |
69
|
|
|
'activity_instance_id' => [ |
70
|
|
|
'label' => 'Activity Instance ID', |
71
|
|
|
'helptext' => 'The id of the activity instance viewed.' |
72
|
|
|
], |
73
|
|
|
'activity_instance_name' => [ |
74
|
|
|
'label' => 'Activity Instance Name', |
75
|
|
|
'helptext' => 'The name of the activity instance viewed.' |
76
|
|
|
], |
77
|
|
|
'clicked_at' => [ |
78
|
|
|
'label' => 'Button Clicked At', |
79
|
|
|
'helptext' => 'The date and time the button was clicked at' |
80
|
|
|
], |
81
|
|
|
'unsubmitted_at' => [ |
82
|
|
|
'label' => 'Button Unsubmitted At', |
83
|
|
|
'helptext' => 'The date and time the button was unsubmitted at' |
84
|
|
|
], |
85
|
|
|
]; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Get the fields that the event registers. |
90
|
|
|
* |
91
|
|
|
* If the event has parameters which should be used in the framework, return them here. |
92
|
|
|
* |
93
|
|
|
* e.g. [ |
94
|
|
|
* 'user_id' => 1, |
95
|
|
|
* 'comment_id' => 4, |
96
|
|
|
* 'post_id' => 3 |
97
|
|
|
* ] |
98
|
|
|
* @return array |
|
|
|
|
99
|
|
|
*/ |
100
|
2 |
|
public function getFields(): array |
101
|
|
|
{ |
102
|
2 |
|
$moduleInstance = app(ModuleInstanceRepository::class)->getById($this->buttonClick->module_instance_id); |
103
|
2 |
|
$activityInstance = app(ActivityInstanceRepository::class)->getById($this->buttonClick->activity_instance_id); |
104
|
|
|
return [ |
105
|
2 |
|
'user_id' => $this->buttonClick->user->id(), |
106
|
2 |
|
'user_email' => $this->buttonClick->user->data()->email(), |
107
|
2 |
|
'user_first_name' => $this->buttonClick->user->data()->firstName(), |
108
|
2 |
|
'user_last_name' => $this->buttonClick->user->data()->lastName(), |
109
|
2 |
|
'user_preferred_name' => $this->buttonClick->user->data()->preferredName(), |
110
|
2 |
|
'clicked_at' => $this->buttonClick->created_at->format('Y-m-d H:i:s'), |
111
|
2 |
|
'unsubmitted_at' => $this->buttonClick->deleted_at->format('Y-m-d H:i:s'), |
112
|
2 |
|
'module_instance_id' => $moduleInstance->id, |
|
|
|
|
113
|
2 |
|
'module_instance_name' => $moduleInstance->name, |
|
|
|
|
114
|
2 |
|
'activity_instance_id' => $activityInstance->id, |
115
|
2 |
|
'activity_instance_name' => $activityInstance->name, |
116
|
|
|
]; |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
|