Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
100.00% |
1 / 1 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
30 / 30 |
Site | |
100.00% |
1 / 1 |
|
100.00% |
5 / 5 |
13 | |
100.00% |
30 / 30 |
getProgressAttribute | |
100.00% |
1 / 1 |
9 | |
100.00% |
11 / 11 |
|||
getBlocksAttribute | |
100.00% |
1 / 1 |
1 | |
100.00% |
8 / 8 |
|||
getOffersAttribute | |
100.00% |
1 / 1 |
1 | |
100.00% |
9 / 9 |
|||
resolveRouteBinding | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
serializeDate | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
1 | <?php |
2 | |
3 | namespace Qmp\Laravel\SiteGeneratorDetail\Models; |
4 | |
5 | use Illuminate\Support\Facades\Log; |
6 | use Illuminate\Support\Facades\Validator; |
7 | use Qmp\Laravel\SiteGeneratorDetail\Resources\SiteList; |
8 | |
9 | class Site extends \Moloquent |
10 | { |
11 | protected $connection = 'siteGeneratorMongo'; |
12 | protected $collection = 'sites'; |
13 | protected $primaryKey = 'id'; |
14 | protected $guarded = ['_id']; |
15 | protected $hidden = ['_id']; |
16 | |
17 | public function getProgressAttribute() |
18 | { |
19 | $errorsCounts = 0; |
20 | $totalFieldsToTest = 10; |
21 | if (empty($this->text)) { $errorsCounts++; } |
22 | if (empty($this->config['domain']['id'])) { $errorsCounts++; } |
23 | if (empty($this->config['url'])) { $errorsCounts++; } |
24 | if (empty($this->config['urlHash'])) { $errorsCounts++; } |
25 | if (empty($this->config['date']['start'])) { $errorsCounts++; } |
26 | if (empty($this->config['date']['end'])) { $errorsCounts++; } |
27 | // if (empty($this->template['name'])) { $errorsCounts++; } |
28 | // if (empty($this->template['siteType'])) { $errorsCounts++; } |
29 | if (empty($this->template['images']['list'])) { $errorsCounts++; } |
30 | if (empty($this->template['images']['affectation'])) { $errorsCounts++; } |
31 | |
32 | return 100 - (int) ($errorsCounts / $totalFieldsToTest * 100); |
33 | } |
34 | |
35 | public function getBlocksAttribute() |
36 | { |
37 | return Site::pipeline() |
38 | ->match('id', $this->id) |
39 | ->unwind('routes') |
40 | ->unwind('routes.pages') |
41 | ->unwind('routes.pages.blocks') |
42 | ->project('{ |
43 | "routeId": "$routes.id", |
44 | "pageId": "$routes.pages.id", |
45 | "id": "$routes.pages.blocks.id", |
46 | "value": "$routes.pages.blocks.value", |
47 | "name": "$routes.pages.blocks.block.text", |
48 | "source": "$routes.pages.blocks.block.source", |
49 | "_id": 0}') |
50 | ->aggregate() |
51 | ->toArray(); |
52 | } |
53 | |
54 | public function getOffersAttribute() |
55 | { |
56 | return Site::pipeline() |
57 | ->match('id', $this->id) |
58 | ->unwind('routes') |
59 | ->unwind('routes.pages') |
60 | ->unwind('routes.pages.blocks') |
61 | ->unwind('routes.pages.blocks.block.offers') |
62 | ->project('{ |
63 | "routeId": "$routes.id", |
64 | "pageId": "$routes.pages.id", |
65 | "blockId": "$routes.pages.blocks.id", |
66 | "id" : "$routes.pages.blocks.block.offers.value", |
67 | "_id": 0}') |
68 | ->aggregate() |
69 | ->toArray(); |
70 | } |
71 | |
72 | public function resolveRouteBinding($value, $field = null) |
73 | { |
74 | return $this->where('id', $value)->first() ?? abort(422, 'Datas not found'); |
75 | } |
76 | |
77 | /** |
78 | * Prepare a date for array / JSON serialization. |
79 | * |
80 | * @param \DateTimeInterface $date |
81 | * @return string |
82 | */ |
83 | protected function serializeDate(\DateTimeInterface $date) |
84 | { |
85 | return $date->format('Y-m-d H:i:s'); |
86 | } |
87 | |
88 | } |