1
|
|
|
<?php |
2
|
|
|
|
|
|
|
|
3
|
|
|
namespace BristolSU\Module\Typeform\Events; |
4
|
|
|
|
5
|
|
|
use BristolSU\ControlDB\Contracts\Repositories\User; |
6
|
|
|
use BristolSU\Module\Typeform\Models\Response; |
7
|
|
|
use BristolSU\Support\Action\Contracts\TriggerableEvent; |
8
|
|
|
|
9
|
|
|
class ResponseApproved implements TriggerableEvent |
|
|
|
|
10
|
|
|
{ |
11
|
|
|
|
12
|
|
|
/** |
|
|
|
|
13
|
|
|
* @var Response |
14
|
|
|
*/ |
15
|
|
|
public $response; |
16
|
|
|
|
17
|
|
|
public function __construct(Response $response) |
|
|
|
|
18
|
|
|
{ |
19
|
|
|
$this->response = $response; |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
/** |
|
|
|
|
23
|
|
|
* @inheritDoc |
24
|
|
|
*/ |
|
|
|
|
25
|
|
|
public function getFields(): array |
26
|
|
|
{ |
27
|
|
|
$user = app(User::class)->getById($this->response->submitted_by); |
28
|
|
|
return [ |
29
|
|
|
'id' => $this->response->id, |
30
|
|
|
'form_id' => $this->response->form_id, |
31
|
|
|
'submitted_by_id' => $this->response->submitted_by, |
32
|
|
|
'submitted_by_email' => $user->data()->email(), |
33
|
|
|
'submitted_by_first_name' => $user->data()->firstName(), |
34
|
|
|
'submitted_by_last_name' => $user->data()->lastName(), |
35
|
|
|
'submitted_by_preferred_name' => $user->data()->preferredName(), |
36
|
|
|
'submitted_at' => $this->response->submitted_at->format('Y-m-d H:i:s'), |
37
|
|
|
'module_instance_id' => $this->response->module_instance_id, |
38
|
|
|
'activity_instance_id' => $this->response->activity_instance_id |
39
|
|
|
]; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
|
|
|
|
43
|
|
|
* @inheritDoc |
44
|
|
|
*/ |
|
|
|
|
45
|
|
|
public static function getFieldMetaData(): array |
46
|
|
|
{ |
47
|
|
|
return [ |
48
|
|
|
'id' => [ |
49
|
|
|
'label' => 'Response ID', |
50
|
|
|
'helptext' => 'The ID of the response as given by Typeform' |
51
|
|
|
], |
52
|
|
|
'form_id' => [ |
53
|
|
|
'label' => 'Form ID', |
54
|
|
|
'helptext' => 'The ID of the Typeform form' |
55
|
|
|
], |
56
|
|
|
'submitted_by_id' => [ |
57
|
|
|
'label' => 'Form Submitted By', |
58
|
|
|
'helptext' => 'ID of the user who submitted the form' |
59
|
|
|
], |
60
|
|
|
'submitted_by_email' => [ |
61
|
|
|
'label' => 'Form Submitted By Email', |
62
|
|
|
'helptext' => 'Email of the user who submitted the form' |
63
|
|
|
], |
64
|
|
|
'submitted_by_first_name' => [ |
65
|
|
|
'label' => 'Form Submitted By First Name', |
66
|
|
|
'helptext' => 'First Name of the user who submitted the form' |
67
|
|
|
], |
68
|
|
|
'submitted_by_last_name' => [ |
69
|
|
|
'label' => 'Form Submitted By Last Name', |
70
|
|
|
'helptext' => 'Last Name of the user who submitted the form' |
71
|
|
|
], |
72
|
|
|
'submitted_by_preferred_name' => [ |
73
|
|
|
'label' => 'Form Submitted By Preferred Name', |
74
|
|
|
'helptext' => 'Preferred Name of the user who submitted the form' |
75
|
|
|
], |
76
|
|
|
'submitted_at' => [ |
77
|
|
|
'label' => 'Form Submitted At', |
78
|
|
|
'helptext' => 'The date and time at which the form_was_filled_in' |
79
|
|
|
], |
80
|
|
|
'module_instance_id' => [ |
81
|
|
|
'label' => 'Module Instance ID', |
82
|
|
|
'helptext' => 'ID of the module instance the form was submitted in' |
83
|
|
|
], |
84
|
|
|
'activity_instance_id' => [ |
85
|
|
|
'label' => 'Activity Instance ID', |
86
|
|
|
'helptext' => 'ID of the activity instance that submitted the form' |
87
|
|
|
], |
88
|
|
|
]; |
89
|
|
|
} |
90
|
|
|
} |