bristol-su /
upload-file
| 1 | <?php |
||
| 2 | |||
|
0 ignored issues
–
show
Coding Style
introduced
by
Loading history...
|
|||
| 3 | namespace BristolSU\Module\UploadFile\Models; |
||
| 4 | |||
| 5 | use BristolSU\Support\ActivityInstance\ActivityInstance; |
||
| 6 | use BristolSU\Support\ActivityInstance\Contracts\ActivityInstanceRepository; |
||
| 7 | use BristolSU\Support\Authentication\HasResource; |
||
| 8 | use BristolSU\ControlDB\Contracts\Repositories\User as UserRepository; |
||
| 9 | use BristolSU\Support\ModuleInstance\Contracts\ModuleInstanceRepository; |
||
| 10 | use BristolSU\Support\ModuleInstance\ModuleInstance; |
||
| 11 | use Illuminate\Database\Eloquent\Model; |
||
| 12 | use Illuminate\Database\Eloquent\SoftDeletes; |
||
| 13 | use Illuminate\Database\Eloquent\Builder; |
||
| 14 | use Illuminate\Support\Facades\Config; |
||
| 15 | |||
| 16 | class File extends Model |
||
|
0 ignored issues
–
show
|
|||
| 17 | { |
||
| 18 | use SoftDeletes, HasResource; |
||
| 19 | |||
| 20 | protected $table = 'uploadfile_files'; |
||
| 21 | |||
| 22 | protected $appends = ['status']; |
||
| 23 | |||
| 24 | protected $fillable = [ |
||
| 25 | 'title', |
||
| 26 | 'description', |
||
| 27 | 'filename', |
||
| 28 | 'mime', |
||
| 29 | 'path', |
||
| 30 | 'size', |
||
| 31 | 'uploaded_by', |
||
| 32 | 'module_instance_id', |
||
| 33 | 'activity_instance_id', |
||
| 34 | 'tags' |
||
| 35 | ]; |
||
| 36 | |||
| 37 | protected $casts = [ |
||
| 38 | 'tags' => 'array' |
||
| 39 | ]; |
||
| 40 | |||
| 41 | 70 | public function getUploadedByAttribute($uploadedById) |
|
|
0 ignored issues
–
show
|
|||
| 42 | { |
||
| 43 | 70 | return app()->make(UserRepository::class)->getById($uploadedById); |
|
| 44 | } |
||
| 45 | |||
| 46 | 2 | public function scopeWithTag(Builder $query, string $tag) |
|
|
0 ignored issues
–
show
|
|||
| 47 | { |
||
| 48 | 2 | $activityInstanceRepository = app(ActivityInstanceRepository::class); |
|
| 49 | 2 | $activityInstance = $activityInstanceRepository->getById(static::activityInstanceId()); |
|
| 50 | $activityInstanceIds = $activityInstanceRepository |
||
| 51 | 2 | ->allForResource($activityInstance->resource_type, $activityInstance->resource_id) |
|
| 52 | ->map(function(ActivityInstance $activityInstance) { |
||
|
0 ignored issues
–
show
|
|||
| 53 | 2 | return $activityInstance->id; |
|
| 54 | 2 | }); |
|
|
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...
|
|||
| 55 | 2 | return $query->whereIn('activity_instance_id', $activityInstanceIds->toArray()) |
|
| 56 | 2 | ->where('tags', 'LIKE', '%"' . $tag . '"%'); |
|
| 57 | } |
||
| 58 | |||
| 59 | /** |
||
|
0 ignored issues
–
show
|
|||
| 60 | * @return ModuleInstance |
||
| 61 | */ |
||
| 62 | 61 | public function moduleInstance() |
|
| 63 | { |
||
| 64 | 61 | return app(ModuleInstanceRepository::class)->getById($this->module_instance_id); |
|
| 65 | } |
||
| 66 | |||
| 67 | /** |
||
|
0 ignored issues
–
show
|
|||
| 68 | * @return ActivityInstance |
||
| 69 | */ |
||
| 70 | 6 | public function activityInstance() |
|
| 71 | { |
||
| 72 | 6 | return app(ActivityInstanceRepository::class)->getById($this->activity_instance_id); |
|
| 73 | } |
||
| 74 | |||
| 75 | 74 | public function statuses() |
|
|
0 ignored issues
–
show
|
|||
| 76 | { |
||
| 77 | 74 | return $this->hasMany(FileStatus::class); |
|
| 78 | } |
||
| 79 | |||
| 80 | 69 | public function getStatusAttribute() |
|
|
0 ignored issues
–
show
|
|||
| 81 | { |
||
| 82 | 69 | if($this->statuses()->count() > 0) { |
|
|
0 ignored issues
–
show
|
|||
| 83 | 9 | return $this->statuses()->latest('created_at')->first()->status; |
|
| 84 | } |
||
| 85 | |||
| 86 | 60 | $statuses = Config::get('uploadfile.statuses'); |
|
| 87 | 60 | if(!is_array($statuses) || count($statuses) === 0) { |
|
|
0 ignored issues
–
show
|
|||
| 88 | 2 | $default = 'Awaiting Approval'; |
|
| 89 | } else { |
||
| 90 | 58 | $default = $statuses[0]; |
|
| 91 | } |
||
| 92 | |||
| 93 | 60 | return $this->moduleInstance()->setting('initial_status', $default); |
|
| 94 | } |
||
| 95 | |||
| 96 | 18 | public function comments() |
|
|
0 ignored issues
–
show
|
|||
| 97 | { |
||
| 98 | 18 | return $this->hasMany(Comment::class); |
|
| 99 | } |
||
| 100 | |||
| 101 | } |