1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Translation\Repositories; |
4
|
|
|
|
5
|
|
|
use Illuminate\Database\Query\JoinClause; |
6
|
|
|
use Illuminate\Foundation\Application; |
|
|
|
|
7
|
|
|
use Illuminate\Support\NamespacedItemResolver; |
8
|
|
|
use Translation\Models\ModelTranslation; |
9
|
|
|
use Carbon\Carbon; |
10
|
|
|
use Translation; |
11
|
|
|
|
12
|
|
|
class ModelTranslationRepository |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* Peguei do Siravel |
16
|
|
|
*/ |
17
|
|
|
|
18
|
|
|
public $model; |
19
|
|
|
|
20
|
|
|
public function __construct(ModelTranslation $translation) |
21
|
|
|
{ |
22
|
|
|
$this->model = $translation; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function getTranslation($code, $type, $lang) |
26
|
|
|
{ |
27
|
|
|
list($language, $country) = [ |
28
|
|
|
Translation::getLanguageCode($lang), |
29
|
|
|
Translation::getCountryCode($lang) |
30
|
|
|
]; |
31
|
|
|
if ($trans = ModelTranslation::where('entity_id', $code)->where('entity_type', $type)->where('language_code', $language)->where('country_code', $country) |
32
|
|
|
// ->where('entity_data', 'LIKE', '%"lang":"'.$lang.'"%') |
33
|
|
|
->first() |
34
|
|
|
) { |
35
|
|
|
return $trans; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
return ModelTranslation::where('entity_id', $code) |
39
|
|
|
->where('entity_type', $type) |
40
|
|
|
->where('language_code', $language) |
41
|
|
|
->first(); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Create or Update an entry |
46
|
|
|
* |
47
|
|
|
* @param integer $entityId |
48
|
|
|
* @param string $entityType |
49
|
|
|
* @param string $lang |
50
|
|
|
* @param array $payload |
51
|
|
|
* |
52
|
|
|
* @return boolean |
53
|
|
|
*/ |
54
|
|
|
public function createOrUpdate($entityId, $entityType, $lang, $payload) |
55
|
|
|
{ |
56
|
|
|
list($language, $country) = [ |
57
|
|
|
Translation::getLanguageCode($lang), |
58
|
|
|
Translation::getCountryCode($lang) |
59
|
|
|
]; |
60
|
|
|
$translation = $this->model->firstOrCreate( |
61
|
|
|
[ |
62
|
|
|
'entity_id' => $entityId, |
63
|
|
|
'entity_type' => $entityType, |
64
|
|
|
'language_code' => $language, |
65
|
|
|
'country_code' => $country, |
66
|
|
|
] |
67
|
|
|
); |
68
|
|
|
|
69
|
|
|
unset($payload['_method']); |
70
|
|
|
unset($payload['_token']); |
71
|
|
|
|
72
|
|
|
$translation->entity_data = json_encode($payload); |
73
|
|
|
|
74
|
|
|
return $translation->save(); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Find by URL |
79
|
|
|
* |
80
|
|
|
* @param string $url |
81
|
|
|
* @param string $type |
82
|
|
|
* |
83
|
|
|
* @return Object|null |
84
|
|
|
*/ |
85
|
|
|
public function findByUrl($url, $type) |
86
|
|
|
{ |
87
|
|
|
$item = $this->model->where('entity_type', $type)->where('entity_data', 'LIKE', '%"url":"'.$url.'"%')->first(); |
88
|
|
|
|
89
|
|
|
if ($item && ($item->data->is_published == 1 || $item->data->is_published == 'on') && $item->data->published_at <= Carbon::now(\Illuminate\Support\Facades\Config::get('app.timezone'))->format('Y-m-d H:i:s')) { |
90
|
|
|
return $item->data; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
return null; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Find an entity by its Id |
98
|
|
|
* |
99
|
|
|
* @param integer $entityId |
100
|
|
|
* @param string $entityType |
101
|
|
|
* |
102
|
|
|
* @return Object|null |
103
|
|
|
*/ |
104
|
|
|
public function findByEntityId($entityId, $entityType) |
105
|
|
|
{ |
106
|
|
|
$item = $this->model->where('entity_type', $entityType)->where('entity_id', $entityId)->first(); |
107
|
|
|
|
108
|
|
|
if ($item && ($item->data->is_published == 1 || $item->data->is_published == 'on') && $item->data->published_at <= Carbon::now(\Illuminate\Support\Facades\Config::get('app.timezone'))->format('Y-m-d H:i:s')) { |
109
|
|
|
return $item->data; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
return null; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* Get entities by type and language |
117
|
|
|
* |
118
|
|
|
* @param string $lang |
119
|
|
|
* @param string $type |
120
|
|
|
* |
121
|
|
|
* @return Illuminate\Support\Collection |
|
|
|
|
122
|
|
|
*/ |
123
|
|
|
public function getEntitiesByTypeAndLang($lang, $type) |
124
|
|
|
{ |
125
|
|
|
$entities = collect(); |
126
|
|
|
$collection = $this->model->where('entity_type', $type)->where('entity_data', 'LIKE', '%"lang":"'.$lang.'"%')->get(); |
127
|
|
|
|
128
|
|
|
foreach ($collection as $item) { |
129
|
|
|
$instance = app($item->type)->attributes = $item->data; |
|
|
|
|
130
|
|
|
$entities->push($instance); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
return $entities; |
134
|
|
|
} |
135
|
|
|
} |
136
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths