-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathImportScope.php
61 lines (54 loc) · 1.39 KB
/
ImportScope.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
namespace Coderflex\LaravelCsv\Scopes;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Foundation\Auth\User;
trait ImportScope
{
/**
* Completed Status Scope
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeCompleted(Builder $builder): Builder
{
return $builder->whereNotNull('completed_at');
}
/**
* Not Completed Status Scope
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeUnCompleted(Builder $builder): Builder
{
return $builder->whereNull('completed_at');
}
/**
* Get the percentage of the model completion
*
* @return int|float
*/
public function percentageComplete(): int|float
{
return floor(($this->processed_rows / $this->total_rows) * 100);
}
/**
* Fetch imports based on the given model
*
* @param string $model
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeForModel(Builder $builder, string $model): Builder
{
return $builder->where('model', $model);
}
/**
* Fetch imports on the user id
*
* @param int $user
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeForUser(Builder $builder, int $user): Builder
{
return $builder->where('user_id', $user);
}
}