|
1
|
|
|
<?php |
|
2
|
|
|
|
|
|
|
|
|
|
3
|
|
|
namespace BristolSU\Module\StaticPage; |
|
4
|
|
|
|
|
5
|
|
|
use BristolSU\Module\StaticPage\CompletionConditions\HasClickedSubmit; |
|
6
|
|
|
use BristolSU\Module\StaticPage\CompletionConditions\HasViewedPage; |
|
7
|
|
|
use BristolSU\Module\StaticPage\Events\ButtonSubmitted; |
|
8
|
|
|
use BristolSU\Module\StaticPage\Events\ButtonUnsubmitted; |
|
9
|
|
|
use BristolSU\Module\StaticPage\Events\PageViewed; |
|
10
|
|
|
use BristolSU\Module\StaticPage\Models\ButtonClick; |
|
11
|
|
|
use BristolSU\Module\StaticPage\VueFields\HtmlField; |
|
12
|
|
|
use BristolSU\Support\Completion\Contracts\CompletionConditionManager; |
|
13
|
|
|
use BristolSU\Support\Module\ModuleServiceProvider as ServiceProvider; |
|
14
|
|
|
use FormSchema\Generator\Field; |
|
15
|
|
|
use FormSchema\Generator\Group; |
|
16
|
|
|
use FormSchema\Schema\Form; |
|
17
|
|
|
use Illuminate\Database\Eloquent\ModelNotFoundException; |
|
18
|
|
|
use Illuminate\Support\Facades\Route; |
|
19
|
|
|
|
|
20
|
|
|
class ModuleServiceProvider extends ServiceProvider |
|
|
|
|
|
|
21
|
|
|
{ |
|
22
|
|
|
|
|
23
|
|
|
protected $permissions = [ |
|
24
|
|
|
'view-page' => [ |
|
25
|
|
|
'name' => 'View Participant Page', |
|
26
|
|
|
'description' => 'View the main page of the module.', |
|
27
|
|
|
'admin' => false |
|
28
|
|
|
], |
|
29
|
|
|
'click-button' => [ |
|
30
|
|
|
'name' => 'Click Submit Button', |
|
31
|
|
|
'description' => 'Can click the submit button', |
|
32
|
|
|
'admin' => false |
|
33
|
|
|
], |
|
34
|
|
|
'delete-button-click' => [ |
|
35
|
|
|
'name' => 'Unsubmit Submit Button', |
|
36
|
|
|
'description' => 'Can unsubmit the page once already submitted', |
|
37
|
|
|
'admin' => false |
|
38
|
|
|
], |
|
39
|
|
|
'admin.view-page' => [ |
|
40
|
|
|
'name' => 'View Admin Page', |
|
41
|
|
|
'description' => 'View the administrator page of the module.', |
|
42
|
|
|
'admin' => true |
|
43
|
|
|
], |
|
44
|
|
|
'admin.page-view.index' => [ |
|
45
|
|
|
'name' => 'View page views', |
|
46
|
|
|
'description' => 'View all page views for the module.', |
|
47
|
|
|
'admin' => true |
|
48
|
|
|
] |
|
49
|
|
|
]; |
|
50
|
|
|
|
|
51
|
|
|
protected $events = [ |
|
52
|
|
|
PageViewed::class => [ |
|
53
|
|
|
'name' => 'A static page has been viewed', |
|
54
|
|
|
'description' => 'A static page module has been viewed by a participant of the module.' |
|
55
|
|
|
], |
|
56
|
|
|
ButtonSubmitted::class => [ |
|
57
|
|
|
'name' => 'The button has been submitted', |
|
58
|
|
|
'description' => 'The button on a static page has been pressed by a participant' |
|
59
|
|
|
], |
|
60
|
|
|
ButtonUnsubmitted::class => [ |
|
61
|
|
|
'name' => 'The button has been unsubmitted', |
|
62
|
|
|
'description' => 'The button on a static page has been unsubmitted by a participant' |
|
63
|
|
|
] |
|
64
|
|
|
]; |
|
65
|
|
|
|
|
66
|
|
|
protected $commands = [ |
|
67
|
|
|
|
|
68
|
|
|
]; |
|
69
|
|
|
|
|
70
|
52 |
|
public function alias(): string |
|
|
|
|
|
|
71
|
|
|
{ |
|
72
|
52 |
|
return 'static-page'; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
52 |
|
public function namespace() |
|
|
|
|
|
|
76
|
|
|
{ |
|
77
|
52 |
|
return '\BristolSU\Module\StaticPage\Http\Controllers'; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
52 |
|
public function baseDirectory() |
|
|
|
|
|
|
81
|
|
|
{ |
|
82
|
52 |
|
return __DIR__ . '/..'; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
52 |
|
public function boot() |
|
|
|
|
|
|
86
|
|
|
{ |
|
87
|
52 |
|
parent::boot(); |
|
88
|
|
|
|
|
89
|
52 |
|
$this->registerGlobalScript('modules/static-page/js/components.js'); |
|
90
|
|
|
|
|
91
|
52 |
|
app(CompletionConditionManager::class)->register($this->alias(), 'static_page_has_viewed_page', HasViewedPage::class); |
|
92
|
52 |
|
app(CompletionConditionManager::class)->register($this->alias(), 'static_page_has_submitted', HasClickedSubmit::class); |
|
93
|
|
|
|
|
94
|
|
|
Route::bind('static_page_button_click', function($id) { |
|
|
|
|
|
|
95
|
7 |
|
$buttonClick = ButtonClick::findOrFail((int) $id); |
|
96
|
|
|
if( |
|
|
|
|
|
|
97
|
6 |
|
request()->route('module_instance_slug') |
|
|
|
|
|
|
98
|
6 |
|
&& (int) $buttonClick->module_instance_id === request()->route('module_instance_slug')->id()) { |
|
|
|
|
|
|
99
|
5 |
|
return $buttonClick; |
|
100
|
|
|
} |
|
101
|
1 |
|
throw (new ModelNotFoundException())->setModel(ButtonClick::class, $id); |
|
102
|
52 |
|
}); |
|
|
|
|
|
|
103
|
|
|
|
|
104
|
52 |
|
} |
|
105
|
|
|
|
|
106
|
52 |
|
public function register() |
|
|
|
|
|
|
107
|
|
|
{ |
|
108
|
52 |
|
parent::register(); |
|
109
|
52 |
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
|
|
|
|
|
112
|
|
|
* @inheritDoc |
|
113
|
|
|
*/ |
|
|
|
|
|
|
114
|
52 |
|
public function settings(): Form |
|
115
|
|
|
{ |
|
116
|
52 |
|
return \FormSchema\Generator\Form::make()->withGroup( |
|
117
|
52 |
|
Group::make('Layout')->withField( |
|
|
|
|
|
|
118
|
52 |
|
Field::input('title')->inputType('text')->label('Title') |
|
|
|
|
|
|
119
|
52 |
|
->hint('The title of the page')->help('This will appear at the top of the page and in the browser tab.') |
|
|
|
|
|
|
120
|
52 |
|
)->withField( |
|
|
|
|
|
|
121
|
52 |
|
Field::input('subtitle')->inputType('text')->label('Subtitle') |
|
|
|
|
|
|
122
|
52 |
|
->hint('The subtitle of the page')->help('This will appear below the title. You can use this to give more information about the page.') |
|
|
|
|
|
|
123
|
52 |
|
)->withField( |
|
|
|
|
|
|
124
|
52 |
|
Field::make(HtmlField::class, 'html')->label('Page Content') |
|
|
|
|
|
|
125
|
52 |
|
->apiKey(config('static-page.tinymce.apiKey')) |
|
|
|
|
|
|
126
|
52 |
|
->hint('The content of the page')->help('This is the main content of the page.') |
|
|
|
|
|
|
127
|
|
|
) |
|
|
|
|
|
|
128
|
52 |
|
)->withGroup( |
|
129
|
52 |
|
Group::make('Button')->withField( |
|
|
|
|
|
|
130
|
52 |
|
Field::input('button_text')->inputType('text')->label('Button Text')->hint('Text to show on the button') |
|
|
|
|
|
|
131
|
|
|
) |
|
|
|
|
|
|
132
|
52 |
|
)->getSchema(); |
|
133
|
|
|
} |
|
134
|
|
|
} |
|
135
|
|
|
|