1 | <?php |
||
2 | |||
3 | use Illuminate\Support\Arr; |
||
4 | use Illuminate\Support\Facades\Config; |
||
5 | use Jenssegers\Mongodb\Eloquent\Model; |
||
6 | |||
7 | if (! function_exists('getTranslatedContent')) { |
||
8 | /** |
||
9 | * @param array $mlCollection |
||
10 | * @return string |
||
11 | */ |
||
12 | function getTranslatedContent($mlCollection) |
||
13 | { |
||
14 | //Get current Lang |
||
15 | $cl = Config::get('app.locale'); |
||
16 | |||
17 | if (is_array($mlCollection) && (array_key_exists('en_EN', $mlCollection) || array_key_exists('it_IT', $mlCollection) || ! is_null($mlCollection || ! isset($destination)))) { |
||
18 | return $mlCollection[$cl]; |
||
19 | } else { |
||
20 | return ''; |
||
21 | } |
||
22 | } |
||
23 | } |
||
24 | |||
25 | if (! function_exists('cl')) { |
||
26 | /** |
||
27 | * @return string current Lang |
||
28 | */ |
||
29 | function cl() |
||
30 | { |
||
31 | //Get current Lang |
||
32 | return Config::get('app.locale'); |
||
33 | } |
||
34 | } |
||
35 | |||
36 | if (! function_exists('ml')) { |
||
37 | //save a localized field |
||
38 | /** |
||
39 | * @param array $destination |
||
40 | * @param string $input |
||
41 | * @return array ready to be saved |
||
42 | */ |
||
43 | function ml($destination, $input) |
||
44 | { |
||
45 | if (is_null($destination)) { |
||
46 | $destination = []; |
||
47 | } |
||
48 | |||
49 | return array_merge($destination, [cl() => $input]); |
||
50 | } |
||
51 | } |
||
52 | |||
53 | if (! function_exists('isML')) { |
||
54 | function isML($value) |
||
55 | { |
||
56 | if (array_key_exists('is-ml', $value)) { |
||
57 | return $value['is-ml']; |
||
58 | } else { |
||
59 | return false; |
||
60 | } |
||
61 | } |
||
62 | } |
||
63 | |||
64 | if (! function_exists('isMD')) { |
||
65 | function isMD($value) |
||
66 | { |
||
67 | if (array_key_exists('is-md', $value)) { |
||
68 | return $value['is-md']; |
||
69 | } else { |
||
70 | return false; |
||
71 | } |
||
72 | } |
||
73 | } |
||
74 | |||
75 | if (! function_exists('is_EM')) { |
||
76 | function is_EM($value) |
||
77 | { |
||
78 | if ($value === 'EmbedsMany') { |
||
79 | return true; |
||
80 | } else { |
||
81 | return false; |
||
82 | } |
||
83 | } |
||
84 | } |
||
85 | |||
86 | if (! function_exists('is_EO')) { |
||
87 | function is_EO($value) |
||
88 | { |
||
89 | if ($value === 'EmbedsOne') { |
||
90 | return true; |
||
91 | } else { |
||
92 | return false; |
||
93 | } |
||
94 | } |
||
95 | } |
||
96 | |||
97 | if (! function_exists('is_HM')) { |
||
98 | function is_HM($value) |
||
99 | { |
||
100 | if ($value === 'HasMany') { |
||
101 | return true; |
||
102 | } else { |
||
103 | return false; |
||
104 | } |
||
105 | } |
||
106 | } |
||
107 | |||
108 | if (! function_exists('is_HO')) { |
||
109 | function is_HO($value) |
||
110 | { |
||
111 | if ($value === 'HasOne') { |
||
112 | return true; |
||
113 | } else { |
||
114 | return false; |
||
115 | } |
||
116 | } |
||
117 | } |
||
118 | |||
119 | if (! function_exists('isEditable')) { |
||
120 | function isEditable($value) |
||
121 | { |
||
122 | if (array_key_exists('is-editable', $value)) { |
||
123 | return $value['is-editable']; |
||
124 | } else { |
||
125 | return true; |
||
126 | } |
||
127 | } |
||
128 | } |
||
129 | |||
130 | if (! function_exists('hasTarget')) { |
||
131 | function hasTarget($value) |
||
132 | { |
||
133 | if (array_key_exists('has-target', $value)) { |
||
134 | return $value['has-target']; |
||
135 | } else { |
||
136 | return true; |
||
137 | } |
||
138 | } |
||
139 | } |
||
140 | |||
141 | if (! function_exists('isFillable')) { |
||
142 | function isFillable($value, $event) |
||
143 | { |
||
144 | if ($event === 'add') { |
||
145 | return true; |
||
146 | } else { |
||
147 | return isEditable($value); |
||
148 | } |
||
149 | } |
||
150 | } |
||
151 | |||
152 | if (! function_exists('getAID')) { |
||
153 | /** |
||
154 | * @param Model $model |
||
155 | * @return string |
||
156 | */ |
||
157 | function getAID(Model $model) |
||
158 | { |
||
159 | //Get Last Obj |
||
160 | $obj = $model->orderBy('created_at', 'desc')->first(); |
||
161 | |||
162 | return is_null($obj) ? 1 : $obj->autoincrement_id + 1; |
||
163 | } |
||
164 | } |
||
165 | |||
166 | if (! function_exists('getArrayWithEmptyObj')) { |
||
167 | /** |
||
168 | * @param $model |
||
169 | * @return array |
||
170 | */ |
||
171 | function getArrayWithEmptyObj($model, $is_EO, $is_EM) |
||
0 ignored issues
–
show
|
|||
172 | { |
||
173 | $arr = []; |
||
174 | if ($is_EO) { |
||
175 | $obj = new stdClass(); |
||
176 | $embedObj = new $model; |
||
177 | $EOitems = $embedObj->getItems(); |
||
178 | |||
179 | //Current Obj Create |
||
180 | foreach ($EOitems as $EOkey => $item) { |
||
181 | $obj->$EOkey = null; |
||
182 | } |
||
183 | |||
184 | $arr[] = $obj; |
||
185 | }// $is_EM == empty array |
||
186 | |||
187 | return $arr; |
||
188 | } |
||
189 | } |
||
190 | |||
191 | if (! function_exists('getCounterForRelationships')) { |
||
192 | /** |
||
193 | * @param $method |
||
194 | * @param $is_EO |
||
195 | * @param $is_EM |
||
196 | * @param $i |
||
197 | * @return string |
||
198 | */ |
||
199 | function getCounterForRelationships($method, $is_EO, $is_EM, $i) |
||
200 | { |
||
201 | if ($method === '' || ($method !== '' && $is_EO) || ($method === '' && $is_EM)) { |
||
202 | return ''; |
||
203 | } else { |
||
204 | return '-'.$i; |
||
205 | } |
||
206 | } |
||
207 | |||
208 | if (! function_exists('getTypeOnTarget')) { |
||
209 | function getTypeOnTarget($relation) |
||
210 | { |
||
211 | return Arr::has($relation, 'typeOnTarget') ? Arr::get($relation, 'typeOnTarget') : 'EmbedsMany'; |
||
212 | } |
||
213 | } |
||
214 | } |
||
215 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.