bristol-su /
upload-file
| 1 | <?php |
||
| 2 | |||
|
0 ignored issues
–
show
Coding Style
introduced
by
Loading history...
|
|||
| 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 NumberOfDocumentsWithStatus extends CompletionCondition |
||
|
0 ignored issues
–
show
|
|||
| 12 | { |
||
| 13 | |||
| 14 | 4 | public function isComplete($settings, ActivityInstance $activityInstance, ModuleInstance $moduleInstance): bool |
|
|
0 ignored issues
–
show
|
|||
| 15 | { |
||
| 16 | return File::forResource($activityInstance->id, $moduleInstance->id())->get()->filter(function(File $file) use ($settings) { |
||
|
0 ignored issues
–
show
|
|||
| 17 | 4 | return $file->status === $settings['status']; |
|
| 18 | 4 | })->count() >= $settings['number_of_files']; |
|
|
0 ignored issues
–
show
For multi-line function calls, the closing parenthesis should be on a new line.
If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line: someFunctionCall(
$firstArgument,
$secondArgument,
$thirdArgument
); // Closing parenthesis on a new line.
Loading history...
|
|||
| 19 | } |
||
| 20 | |||
| 21 | 4 | public function percentage($settings, ActivityInstance $activityInstance, ModuleInstance $moduleInstance): int |
|
|
0 ignored issues
–
show
|
|||
| 22 | { |
||
| 23 | $count = File::forResource($activityInstance->id, $moduleInstance->id())->get()->filter(function(File $file) use ($settings) { |
||
|
0 ignored issues
–
show
|
|||
| 24 | 3 | return $file->status === $settings['status']; |
|
| 25 | 4 | })->count(); |
|
|
0 ignored issues
–
show
For multi-line function calls, the closing parenthesis should be on a new line.
If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line: someFunctionCall(
$firstArgument,
$secondArgument,
$thirdArgument
); // Closing parenthesis on a new line.
Loading history...
|
|||
| 26 | 4 | $needed = ( $settings['number_of_files'] ?? 1); |
|
| 27 | |||
| 28 | 4 | $percentage = (int) round(($count/$needed) * 100, 0); |
|
| 29 | |||
| 30 | 4 | if($percentage > 100) { |
|
|
0 ignored issues
–
show
|
|||
| 31 | 1 | return 100; |
|
| 32 | } |
||
| 33 | 3 | return $percentage; |
|
| 34 | } |
||
| 35 | |||
| 36 | |||
| 37 | 1 | public function options(): Form |
|
|
0 ignored issues
–
show
|
|||
| 38 | { |
||
| 39 | 1 | return \FormSchema\Generator\Form::make()->withField( |
|
| 40 | 1 | \FormSchema\Generator\Field::input('number_of_files')->inputType('number')->label('Number of Files') |
|
| 41 | 1 | ->required(true)->default(1)->hint('The number of files that must be submitted') |
|
| 42 | 1 | ->help('The number of documents that need to be submitted for the module to be marked as complete.') |
|
| 43 | 1 | )->withField( |
|
| 44 | 1 | \FormSchema\Generator\Field::input('status')->inputType('text')->label('Status') |
|
| 45 | 1 | ->required(true)->default('Awaiting Approval')->hint('The status the files must be') |
|
| 46 | 1 | ->help('The status of the files. The module will be complete when the number of files submitted have this status.') |
|
| 47 | 1 | )->getSchema(); |
|
| 48 | } |
||
| 49 | |||
| 50 | 1 | public function name(): string |
|
|
0 ignored issues
–
show
|
|||
| 51 | { |
||
| 52 | 1 | return 'A number of documents with a given status have been submitted'; |
|
| 53 | } |
||
| 54 | |||
| 55 | 1 | public function description(): string |
|
|
0 ignored issues
–
show
|
|||
| 56 | { |
||
| 57 | 1 | return 'Complete when a given number of documents have been submitted and given a specific status'; |
|
| 58 | } |
||
| 59 | |||
| 60 | 1 | public function alias(): string |
|
|
0 ignored issues
–
show
|
|||
| 61 | { |
||
| 62 | 1 | return 'number_of_files_submitted_with_status'; |
|
| 63 | } |
||
| 64 | |||
| 65 | } |