-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSurveyCompleted.php
106 lines (97 loc) · 2.61 KB
/
SurveyCompleted.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
103
104
105
106
<?php
/**
* Class SurveyCompleted
*/
class SurveyCompleted extends PluginBase
{
/**
* @var string
*/
static protected $description = 'Survey completed plugin';
/**
* @var string
*/
static protected $name = 'SurveyCompleted';
/**
* @var string
*/
protected $storage = 'DbStorage';
protected $settings = [
'RedirectUrl' => [
'type' => 'string',
'label' => 'Redirect url',
'help' => 'URL to redirect the form when already filled.',
],
];
/**
* @return void
*/
public function init()
{
$this->subscribe('onSurveyDenied');
$this->subscribe('newSurveySettings');
$this->subscribe('beforeSurveySettings');
}
/**
* @return void
*/
public function onSurveyDenied()
{
$event = $this->getEvent();
$reason = $event->get('reason');
if ($reason !== 'alreadyCompleted') {
return;
}
$surveyId = $event->get('surveyId');
$redirectUrl = $this->get(
'RedirectUrl',
'Survey',
$surveyId, // Survey
$this->get('RedirectUrl') // Global
);
if (!$redirectUrl) {
return;
}
header('Location: ' . $redirectUrl);
}
/**
* @return void
*/
public function newSurveySettings()
{
$event = $this->getEvent();
foreach ($event->get('settings') as $name => $value) {
$this->set($name, $value, 'Survey', $event->get('survey'));
}
}
/**
* @return void
*/
public function beforeSurveySettings()
{
$event = $this->getEvent();
$event->set(
"surveysettings.{$this->id}",
[
'name' => get_class($this),
'settings' => [
'SettingsInfo' => [
'type' => 'info',
'content' => '<legend><small>Redirect URL settings</small></legend>'
],
'RedirectUrl' => [
'type' => 'string',
'label' => $this->settings['RedirectUrl']['help'],
'help' => $this->settings['RedirectUrl']['help'],
'current' => $this->get(
'RedirectUrl',
'Survey',
$event->get('survey'), // Survey
$this->get('RedirectUrl') // Global
),
],
]
]
);
}
}