-
Notifications
You must be signed in to change notification settings - Fork 219
/
Copy pathhelpers.php
278 lines (248 loc) · 6.13 KB
/
helpers.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
<?php
use Illuminate\Support\Facades\Auth;
use Laravel\Horizon\Repositories\RedisJobRepository;
use ProcessMaker\Events\MarkArtisanCachesAsInvalid;
use ProcessMaker\SanitizeHelper;
if (!function_exists('job_pending')) {
/**
* Check if a given job (by instance or class) is already pending in the queue.
*
* @param $job
*
* @return bool
*/
function job_pending($job): bool
{
if (is_object($job)) {
$job = class_basename($job);
}
$queue = app(RedisJobRepository::class)->getRecent();
return $queue->filter(
function ($queued) use ($job) {
return $queued->name === $job
&& ('delayed' === $queued->status
|| 'pending' === $queued->status);
}
)->isNotEmpty();
}
}
if (!function_exists('settings')) {
/**
* Forwards call to the config() helper.
*
* TODO Remove this helper function as it exists now only for backwards compatability
*
* @param $key
*
* @throws \Psr\Container\ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface
*
* @return array|mixed
*/
function settings($key = null)
{
return $key ? config()->get($key) : config()->all();
}
}
if (!function_exists('default_color')) {
/**
* Returns the default color value.
*
* @param $key
*
* @return string
*/
function default_color($key)
{
return config('app.default_colors.' . $key);
}
}
if (!function_exists('color')) {
/**
* Returns the color value from the settings.
*
* @param $key
*
* @return string
*/
function color($key)
{
if ($colors = config('css-override.variables')) {
$colors = json_decode($colors);
foreach ($colors as $color) {
if ($color->id === '$' . $key) {
return $color->value;
}
}
}
return default_color($key);
}
}
if (!function_exists('sidebar_class')) {
/**
* Returns the class for the sidebar based on admin settings.
*
* @return boolean
*/
function sidebar_class()
{
if (config('css-override.variables')) {
$defaults = ['#0872C2', '#2773F3'];
if (! in_array(color('primary'), $defaults)) {
return 'sidebar-custom';
}
}
return 'sidebar-default';
}
}
if (!function_exists('refresh_artisan_caches')) {
/**
* Re-caches artisan config, routes, and/or events when they are already cached.
*/
function refresh_artisan_caches(): void
{
MarkArtisanCachesAsInvalid::dispatch();
}
}
if (!function_exists('lavaryMenuArray')) {
/**
* Convert the Laravy menu into associative array.
*
* @param \Lavary\Menu\Item $menu
* @param mixed $includeSubMenus
*
* @return array
*/
function lavaryMenuArray($menu, $includeSubMenus = false)
{
$children = [];
$subMenus = $includeSubMenus ? $menu->children() : null;
if ($subMenus) {
foreach ($subMenus as $child) {
$children[] = lavaryMenuArray($child);
}
}
return [
'title' => __($menu->title),
'id' => $menu->id,
'attributes' => $menu->attributes,
'url' => $menu->url(),
'children' => $children,
];
}
}
if (!function_exists('lavaryMenuJson')) {
/**
* Convert the Laravy menu into json string.
*
* @param \Lavary\Menu\Item $menu
*
* @return false|string
*/
function lavaryMenuJson($menu)
{
return json_encode(lavaryMenuArray($menu, true));
}
}
if (!function_exists('hasPackage')) {
/**
* Check if a package exists based on its provider name.
*
* @param $name
*
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*
* @return bool
*/
function hasPackage($name)
{
$list = app()->make(ProcessMaker\Managers\PackageManager::class)->listPackages();
return in_array($name, $list);
}
}
if (!function_exists('pmUser')) {
/**
* Check both the web and api middleware for an existing user.
*
* @return null|\ProcessMaker\Models\User
*/
function pmUser()
{
if (Auth::user()) {
return Auth::user();
}
if (Auth::guard('api')->user()) {
return Auth::guard('api')->user();
}
return null;
}
}
if (!function_exists('sanitizeVueExp')) {
/**
* @param $expression
*
* @return array|string|string[]
*/
function sanitizeVueExp($expression)
{
return SanitizeHelper::sanitizeVueExp($expression);
}
}
if (!function_exists('packTemporalData')) {
/**
* Store data into store/app/private.
*
* @param $data
*
* @return string
*/
function packTemporalData($data)
{
$uid = uniqid('data_', true);
$path = storage_path('app/private/' . $uid);
file_put_contents($path, json_encode($data));
return $uid;
}
}
if (!function_exists('unpackTemporalData')) {
/**
* @param $uid
*
* @return array|mixed
*/
function unpackTemporalData($uid)
{
$path = storage_path('app/private/' . $uid);
if (file_exists($path)) {
return json_decode(file_get_contents($path), true);
}
return [];
}
}
if (!function_exists('removeTemporalData')) {
/**
* @param $uid
*/
function removeTemporalData($uid)
{
$path = storage_path('app/private/' . $uid);
if (file_exists($path)) {
@unlink($path);
}
}
}
if (!function_exists('shouldShow')) {
/**
* @param string $element
*
* @return bool
*/
function shouldShow($element)
{
if (Session::has('visibilitySettings')) {
return Session::get('visibilitySettings')->{$element} ?? true;
} else {
return true;
}
}
}