1 | <?php |
||
2 | |||
0 ignored issues
–
show
Coding Style
introduced
by
![]() |
|||
3 | namespace BristolSU\Module\UploadFile\CompletionConditions; |
||
4 | |||
5 | use BristolSU\Module\UploadFile\Models\File; |
||
6 | use BristolSU\Support\ActivityInstance\ActivityInstance; |
||
7 | use BristolSU\Support\Completion\Contracts\CompletionCondition; |
||
8 | use BristolSU\Support\ModuleInstance\Contracts\ModuleInstance; |
||
9 | use FormSchema\Schema\Form; |
||
10 | |||
11 | class NumberOfDocumentsSubmitted extends CompletionCondition |
||
0 ignored issues
–
show
|
|||
12 | { |
||
13 | |||
14 | 3 | public function isComplete($settings, ActivityInstance $activityInstance, ModuleInstance $moduleInstance): bool |
|
0 ignored issues
–
show
|
|||
15 | { |
||
16 | 3 | return File::forResource($activityInstance->id, $moduleInstance->id())->count() >= $settings['number_of_files']; |
|
17 | } |
||
18 | |||
19 | 5 | public function percentage($settings, ActivityInstance $activityInstance, ModuleInstance $moduleInstance): int |
|
0 ignored issues
–
show
|
|||
20 | { |
||
21 | 5 | $count = File::forResource($activityInstance->id, $moduleInstance->id)->count(); |
|
0 ignored issues
–
show
|
|||
22 | 5 | $needed = ( $settings['number_of_files'] ?? 1); |
|
23 | |||
24 | 5 | $percentage = (int) round(($count/$needed) * 100, 0); |
|
25 | |||
26 | 5 | if($percentage > 100) { |
|
0 ignored issues
–
show
|
|||
27 | 1 | return 100; |
|
28 | } |
||
29 | 4 | return $percentage; |
|
30 | } |
||
31 | |||
32 | |||
33 | 1 | public function options(): Form |
|
0 ignored issues
–
show
|
|||
34 | { |
||
35 | 1 | return \FormSchema\Generator\Form::make()->withField( |
|
36 | 1 | \FormSchema\Generator\Field::input('number_of_files')->inputType('number')->label('Number of Files') |
|
37 | 1 | ->required(true)->default(1)->hint('The number of files that must be submitted') |
|
38 | 1 | ->help('The number of documents that need to be submitted for the module to be marked as complete.') |
|
39 | 1 | )->getSchema(); |
|
40 | } |
||
41 | |||
42 | 1 | public function name(): string |
|
0 ignored issues
–
show
|
|||
43 | { |
||
44 | 1 | return 'A number of documents have been submitted'; |
|
45 | } |
||
46 | |||
47 | 1 | public function description(): string |
|
0 ignored issues
–
show
|
|||
48 | { |
||
49 | 1 | return 'Complete when a given number of documents have been submitted'; |
|
50 | } |
||
51 | |||
52 | 1 | public function alias(): string |
|
0 ignored issues
–
show
|
|||
53 | { |
||
54 | 1 | return 'number_of_files_submitted'; |
|
55 | } |
||
56 | } |