bristol-su /
static-page
| 1 | <?php |
||
| 2 | |||
|
0 ignored issues
–
show
Coding Style
introduced
by
Loading history...
|
|||
| 3 | |||
| 4 | namespace BristolSU\Module\StaticPage\CompletionConditions; |
||
| 5 | |||
| 6 | |||
| 7 | use BristolSU\Module\StaticPage\Models\ButtonClick; |
||
| 8 | use BristolSU\Module\StaticPage\Models\PageView; |
||
| 9 | use BristolSU\Support\ActivityInstance\ActivityInstance; |
||
| 10 | use BristolSU\Support\Completion\Contracts\CompletionCondition; |
||
| 11 | use BristolSU\Support\ModuleInstance\Contracts\ModuleInstance; |
||
| 12 | use FormSchema\Schema\Form; |
||
| 13 | |||
| 14 | class HasClickedSubmit extends CompletionCondition |
||
|
0 ignored issues
–
show
|
|||
| 15 | { |
||
| 16 | |||
| 17 | /** |
||
| 18 | * Is the condition fully complete? |
||
| 19 | * |
||
| 20 | * @param array $settings Settings of the completion condition |
||
|
0 ignored issues
–
show
|
|||
| 21 | * @param ActivityInstance $activityInstance Activity instance to test |
||
|
0 ignored issues
–
show
|
|||
| 22 | * @param ModuleInstance $moduleInstance Module instance to test |
||
|
0 ignored issues
–
show
|
|||
| 23 | * @return bool If the condition is complete |
||
|
0 ignored issues
–
show
|
|||
| 24 | */ |
||
| 25 | public function isComplete($settings, ActivityInstance $activityInstance, ModuleInstance $moduleInstance): bool |
||
| 26 | { |
||
| 27 | return ButtonClick::forResource($activityInstance->id, $moduleInstance->id)->count() > 0; |
||
|
0 ignored issues
–
show
|
|||
| 28 | } |
||
| 29 | |||
| 30 | public function percentage($settings, ActivityInstance $activityInstance, ModuleInstance $moduleInstance): int |
||
|
0 ignored issues
–
show
|
|||
| 31 | { |
||
| 32 | if($this->isComplete($settings, $activityInstance, $moduleInstance)) { |
||
|
0 ignored issues
–
show
|
|||
| 33 | return 100; |
||
| 34 | } |
||
| 35 | return 0; |
||
| 36 | } |
||
| 37 | |||
| 38 | /** |
||
| 39 | * Options required by the completion condition. |
||
| 40 | * |
||
| 41 | * Any settings requested in here will be passed into the percentage or isComplete methods. |
||
| 42 | * |
||
| 43 | * @return Form |
||
| 44 | * @throws \Exception |
||
| 45 | */ |
||
| 46 | public function options(): Form |
||
| 47 | { |
||
| 48 | return \FormSchema\Generator\Form::make()->getSchema(); |
||
| 49 | } |
||
| 50 | |||
| 51 | /** |
||
| 52 | * A name for the completion condition |
||
| 53 | * |
||
| 54 | * @return string |
||
| 55 | */ |
||
| 56 | public function name(): string |
||
| 57 | { |
||
| 58 | return 'Has clicked the submit button'; |
||
| 59 | } |
||
| 60 | |||
| 61 | /** |
||
| 62 | * A description of the completion condition |
||
| 63 | * |
||
| 64 | * @return string |
||
| 65 | */ |
||
| 66 | public function description(): string |
||
| 67 | { |
||
| 68 | return 'Marked as complete when the user/group/role has clicked the submit button.'; |
||
| 69 | } |
||
| 70 | |||
| 71 | /** |
||
| 72 | * The alias of the completion condition |
||
| 73 | * |
||
| 74 | * @return string |
||
| 75 | */ |
||
| 76 | public function alias(): string |
||
| 77 | { |
||
| 78 | return 'static_page_has_submitted'; |
||
| 79 | } |
||
| 80 | } |