Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
25.00% |
1 / 4 |
CRAP | |
12.50% |
1 / 8 |
Session | |
0.00% |
0 / 1 |
|
25.00% |
1 / 4 |
30.12 | |
12.50% |
1 / 8 |
resolveRouteBinding | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
serializeDate | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
getUsersIdsNoFiles | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 3 |
|||
getUsersIdsWithFiles | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 3 |
1 | <?php |
2 | |
3 | namespace Qmp\Laravel\Deduplication\Models; |
4 | |
5 | class Session extends \Moloquent |
6 | { |
7 | protected $connection = 'deduplicationMongo'; |
8 | protected $collection = 'sessions'; |
9 | protected $primaryKey = 'id'; |
10 | |
11 | protected $guarded = ['_id']; |
12 | protected $hidden = ['_id']; |
13 | |
14 | protected $casts = [ |
15 | 'availableUntil' => 'datetime', |
16 | ]; |
17 | |
18 | public function resolveRouteBinding($value, $field = null) |
19 | { |
20 | return $this->where('id', $value)->first() ?? abort(422, 'Datas not found'); |
21 | } |
22 | |
23 | /** |
24 | * Prepare a date for array / JSON serialization. |
25 | * |
26 | * @param \DateTimeInterface $date |
27 | * @return string |
28 | */ |
29 | protected function serializeDate(\DateTimeInterface $date) |
30 | { |
31 | return $date->format('Y-m-d H:i:s'); |
32 | } |
33 | |
34 | public function getUsersIdsNoFiles() |
35 | { |
36 | return collect($this)->recursive()->get('sites')->filter(function ($site) { |
37 | return !$site->get('input_file') || $site->get('input_file')->get('errors'); |
38 | })->pluck('user_id')->toArray(); |
39 | } |
40 | |
41 | public function getUsersIdsWithFiles() |
42 | { |
43 | return collect($this)->recursive()->get('sites')->filter(function ($site) { |
44 | return $site->get('output_file') && $site->get('output_file')->get('count') > 0; |
45 | })->pluck('user_id')->toArray(); |
46 | } |
47 | |
48 | } |