Passed
Push — develop ( 4df8ba...2db068 )
by Nikolay
04:59
created

AssetProvider::getVersionsHash()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
c 0
b 0
f 0
dl 0
loc 8
rs 10
cc 2
nc 2
nop 0
1
<?php
2
/*
3
 * MikoPBX - free phone system for small business
4
 * Copyright (C) 2017-2020 Alexey Portnov and Nikolay Beketov
5
 *
6
 * This program is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation; either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License along with this program.
17
 * If not, see <https://www.gnu.org/licenses/>.
18
 */
19
20
declare(strict_types=1);
21
22
namespace MikoPBX\AdminCabinet\Providers;
23
24
use MikoPBX\AdminCabinet\Controllers\SessionController;
25
use MikoPBX\AdminCabinet\Plugins\AssetManager as Manager;
26
use MikoPBX\Common\Models\PbxExtensionModules;
27
use MikoPBX\Common\Models\PbxSettings;
28
use MikoPBX\Common\Providers\PBXConfModulesProvider;
29
use MikoPBX\Common\Providers\SessionProvider;
30
use MikoPBX\Modules\Config\WebUIConfigInterface;
31
use Phalcon\Assets\Collection;
32
use Phalcon\Di\DiInterface;
33
use Phalcon\Di\ServiceProviderInterface;
34
use function MikoPBX\Common\Config\appPath;
35
36
class AssetProvider implements ServiceProviderInterface
37
{
38
    public const SERVICE_NAME = 'assets';
39
40
    private Collection $headerCollectionJSForExtensions;
41
    private Collection $footerCollectionJSForExtensions;
42
    private Collection $headerCollectionJS;
43
    private Collection $headerCollectionCSS;
44
    private Collection $footerCollectionJS;
45
    private Collection $semanticCollectionCSS;
46
    private Collection $semanticCollectionJS;
47
    private Collection $footerCollectionACE;
48
    private Collection $footerCollectionLoc;
49
    private Collection $headerCollectionSentryJS;
50
    private string $jsCacheDir;
51
    private Manager $manager;
52
53
    /**
54
     * Registers assets service provider
55
     *
56
     * @param \Phalcon\Di\DiInterface $di
57
     */
58
    public function register(DiInterface $di): void
59
    {
60
        $di->set(
61
            self::SERVICE_NAME,
62
            function () use ($di) {
63
64
                $session = $di->get(SessionProvider::SERVICE_NAME);
65
66
                // Module and PBX version caching for proper PBX operation when installing modules.
67
                $version = $session->get(SessionProvider::VERSION_HASH) ?? '';
68
                if (empty($version)) {
69
                    $version = $this->getVersionsHash();
70
                    $session->set(SessionProvider::VERSION_HASH, $version);
71
                }
72
73
                $assets = new AssetProvider();
74
                $assets->initializeClassVariables($version);
75
                $dispatcher = $di->get(DispatcherProvider::SERVICE_NAME);
76
                $controller = $dispatcher->getControllerName();
77
                $action = $dispatcher->getActionName();
78
                $isExternalModulePage = stripos($dispatcher->getNamespaceName(), '\\Module') === 0;
79
80
                if ($action === null) {
81
                    $action = 'index';
82
                }
83
84
                $assets->makeSentryAssets();
85
                $assets->makeHeaderAssets($session, $isExternalModulePage);
86
87
                // Generates Controllers assets
88
                $method_name = "make{$controller}Assets";
89
                if (method_exists($assets, $method_name)) {
90
                    $assets->$method_name($action);
91
                }
92
93
                $assets->makeFooterAssets();
94
                $assets->makeLocalizationAssets($di, $version);
95
96
                $assetsManager = $assets->manager;
97
98
                // Register additional assets from external enabled modules
99
                PBXConfModulesProvider::hookModulesProcedure(WebUIConfigInterface::ON_AFTER_ASSETS_PREPARED, [$assetsManager]);
100
101
                return $assetsManager;
102
            }
103
        );
104
    }
105
106
    /**
107
     * Initialize class variables
108
     */
109
    public function initializeClassVariables(string $version)
110
    {
111
        $this->manager = new Manager();
0 ignored issues
show
Bug introduced by
The call to MikoPBX\AdminCabinet\Plu...tManager::__construct() has too few arguments starting with tagFactory. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

111
        $this->manager = /** @scrutinizer ignore-call */ new Manager();

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
112
        $this->manager->setVersion($version);
113
114
        $this->jsCacheDir = appPath('sites/admin-cabinet/assets/js/cache');
115
116
        $this->headerCollectionJSForExtensions = $this->manager->collection('headerJS');
117
        $this->headerCollectionJSForExtensions->setPrefix('assets/');
118
        $this->footerCollectionJSForExtensions = $this->manager->collection('footerJS');
119
        $this->footerCollectionJSForExtensions->setPrefix('assets/');
120
        $this->headerCollectionJS = $this->manager->collection('headerPBXJS');
121
        $this->headerCollectionJS->setPrefix('assets/');
122
        $this->headerCollectionCSS = $this->manager->collection('headerCSS');
123
        $this->headerCollectionCSS->setPrefix('assets/');
124
        $this->footerCollectionJS = $this->manager->collection('footerPBXJS');
125
        $this->footerCollectionJS->setPrefix('assets/');
126
        $this->headerCollectionSentryJS = $this->manager->collection('headerSentryJS');
127
        $this->semanticCollectionCSS = $this->manager->collection('SemanticUICSS');
128
        $this->semanticCollectionCSS->setPrefix('assets/');
129
        $this->semanticCollectionJS = $this->manager->collection('SemanticUIJS');
130
        $this->semanticCollectionJS->setPrefix('assets/');
131
        $this->footerCollectionACE = $this->manager->collection('footerACE');
132
        $this->footerCollectionACE->setPrefix('assets/');
133
        $this->footerCollectionLoc = $this->manager->collection('footerLoc');
134
        $this->footerCollectionLoc->setPrefix('assets/');
135
    }
136
137
    /**
138
     * Makes assets for the Sentry error logger
139
     *
140
     */
141
    private function makeSentryAssets(): void
142
    {
143
        if (file_exists('/tmp/sendmetrics')) {
144
            $this->headerCollectionSentryJS->addjs(
145
                'assets/js/vendor/sentry/bundle.min.js',
146
                true
147
            );
148
            $this->headerCollectionSentryJS->addJs(
149
                "assets/js/pbx/main/sentry-error-logger.js",
150
                true
151
            );
152
        }
153
    }
154
155
    /**
156
     * Makes assets for all controllers. Base set of scripts and styles
157
     *
158
     * @param $session
159
     * @param bool $isExternalModulePage
160
     */
161
    private function makeHeaderAssets($session, bool $isExternalModulePage): void
162
    {
163
        $this->semanticCollectionCSS
164
            ->addCss('css/vendor/semantic/grid.min.css', true)
165
            ->addCss('css/vendor/semantic/divider.min.css', true)
166
            ->addCss('css/vendor/semantic/container.min.css', true)
167
            ->addCss('css/vendor/semantic/header.min.css', true)
168
            ->addCss('css/vendor/semantic/button.min.css', true)
169
            ->addCss('css/vendor/semantic/form.min.css', true)
170
            ->addCss('css/vendor/semantic/icon.min.css', true)
171
            ->addCss('css/vendor/semantic/flag.min.css', true)
172
            ->addCss('css/vendor/semantic/image.min.css', true)
173
            ->addCss('css/vendor/semantic/input.min.css', true)
174
            ->addCss('css/vendor/semantic/message.min.css', true)
175
            ->addCss('css/vendor/semantic/segment.min.css', true)
176
            ->addCss('css/vendor/semantic/site.min.css', true)
177
            ->addCss('css/vendor/semantic/reset.min.css', true)
178
            ->addCss('css/vendor/semantic/transition.min.css', true)
179
            ->addCss('css/vendor/semantic/dropdown.min.css', true)
180
            ->addCss('css/vendor/semantic/checkbox.min.css', true);
181
182
        $this->headerCollectionJS
183
            ->addJs('js/pbx/main/header.js', true)
184
            ->addJs('js/vendor/jquery.min.js', true);
185
186
        $this->footerCollectionJS
187
            ->addJs('js/pbx/main/language-select.js', true);
188
189
        $this->semanticCollectionJS
190
            ->addJs('js/vendor/semantic/form.min.js', true)
191
            ->addJs('js/vendor/semantic/api.min.js', true)
192
            ->addJs('js/vendor/semantic/site.min.js', true)
193
            ->addJs('js/vendor/semantic/popup.min.js', true)
194
            ->addJs('js/vendor/semantic/dropdown.min.js', true)
195
            ->addJs('js/vendor/semantic/transition.min.js', true)
196
            ->addJs('js/vendor/semantic/checkbox.min.js', true);
197
198
        // Если пользователь залогинился, сформируем необходимые CSS кеши
199
        if ($session->has(SessionController::SESSION_ID)) {
200
            $this->semanticCollectionCSS
201
                ->addCss('css/vendor/semantic/menu.min.css', true)
202
                ->addCss('css/vendor/semantic/sidebar.min.css', true)
203
                ->addCss('css/vendor/semantic/table.min.css', true)
204
                ->addCss('css/vendor/semantic/loader.min.css', true)
205
                ->addCss('css/vendor/semantic/label.min.css', true)
206
                ->addCss('css/vendor/semantic/dimmer.min.css', true)
207
                ->addCss('css/vendor/semantic/accordion.min.css', true)
208
                ->addCss('css/vendor/semantic/placeholder.min.css', true)
209
                ->addCss('css/vendor/semantic/item.min.css', true)
210
                ->addCss('css/vendor/semantic/tab.min.css', true)
211
                ->addCss('css/vendor/semantic/popup.min.css', true)
212
                ->addCss('css/vendor/semantic/toast.min.css', true);
213
214
            $this->semanticCollectionJS
215
                ->addJs('js/vendor/semantic/accordion.min.js', true)
216
                ->addJs('js/vendor/semantic/dimmer.min.js', true)
217
                ->addJs('js/vendor/semantic/sidebar.min.js', true)
218
                ->addJs('js/vendor/semantic/toast.min.js', true)
219
                ->addJs('js/vendor/semantic/tab.min.js', true);
220
221
            $this->footerCollectionJS
222
                ->addJs('js/pbx/main/config.js', true)
223
                ->addJs('js/pbx/main/pbxapi.js', true)
224
                ->addJs('js/pbx/main/connection-check-worker.js', true)
225
                ->addJs('js/pbx/main/semantic-localization.js', true)
226
                ->addJs('js/pbx/Advices/advices-worker.js', true)
227
                ->addJs('js/pbx/Security/check-passwords.js', true)
228
                ->addJs('js/pbx/SendMetrics/send-metrics-index.js', true)
229
                ->addJs('js/pbx/main/ssh-console.js', true)
230
                ->addJs('js/pbx/main/delete-something.js', true)
231
                ->addJs('js/pbx/main/user-message.js', true)
232
                ->addJs('js/pbx/Extensions/extensions.js', true)
233
                ->addJs('js/pbx/PbxExtensionModules/pbx-extension-menu-addition.js', true)
234
                ->addJs('js/pbx/TopMenuSearch/top-menu-search.js', true);
235
236
            if ($isExternalModulePage) {
237
                $this->footerCollectionJS->addJs(
238
                    'js/pbx/PbxExtensionModules/pbx-extension-module-status.js',
239
                    true
240
                );
241
            }
242
        }
243
    }
244
245
    /**
246
     * Makes footer assets
247
     */
248
    private function makeFooterAssets(): void
249
    {
250
        $this->headerCollectionCSS
251
            ->addCss('css/custom.css', true);
252
253
        $this->footerCollectionJS->addJs(
254
            'js/pbx/main/footer.js',
255
            true
256
        );
257
    }
258
259
    /**
260
     * Makes Language cache for browser JS scripts
261
     *
262
     * @param \Phalcon\Di\DiInterface $di
263
     * @param string $version
264
     */
265
    private function makeLocalizationAssets(DiInterface $di, string $version): void
266
    {
267
        $language = $di->getShared('language');
268
        $fileName = "{$this->jsCacheDir}/localization-{$language}-{$version}.min.js";
269
        if (!file_exists($fileName)) {
270
            $arrStr = [];
271
            foreach ($di->getShared('messages') as $key => $value) {
272
                $arrStr[$key] = str_replace(
273
                    "'",
274
                    "\\'",
275
                    str_replace(["\n", '  '], '', $value)
276
                );
277
            }
278
            $scriptArray = json_encode($arrStr);
279
            file_put_contents($fileName, "globalTranslate = {$scriptArray}");
280
        }
281
282
        $langJSFile = "js/cache/localization-{$language}-{$version}.min.js";
283
        $this->footerCollectionLoc->addJs($langJSFile, true);
284
    }
285
286
    /**
287
     * Makes assets for the CallQueues controller
288
     *
289
     * @param string $action
290
     */
291
    private function makeCallQueuesAssets(string $action)
292
    {
293
        if ($action === 'index') {
294
            $this->headerCollectionCSS
295
                ->addCss('css/vendor/datatable/dataTables.semanticui.css', true);
296
            $this->footerCollectionJS
297
                ->addJs('js/vendor/datatable/dataTables.semanticui.js', true)
298
                ->addJs('js/pbx/CallQueues/callqueues-index.js', true);
299
        } elseif ($action === 'modify') {
300
            $this->footerCollectionJS
301
                ->addJs('js/vendor/jquery.debounce-1.0.5.js', true)
302
                ->addJs('js/vendor/jquery.tablednd.js', true)
303
                ->addJs('js/pbx/main/form.js', true)
304
                ->addJs('js/pbx/CallQueues/callqueue-modify.js', true)
305
                ->addJs('js/pbx/SoundFiles/sound-files-selector.js', true)
306
                ->addJs('js/pbx/SoundFiles/one-button-sound-player.js', true);
307
        }
308
    }
309
310
    /**
311
     * Makes assets for the ConferenceRooms controller
312
     *
313
     * @param string $action
314
     */
315
    private function makeConferenceRoomsAssets(string $action)
316
    {
317
        if ($action === 'index') {
318
            $this->footerCollectionJS
319
                ->addJs('js/pbx/ConferenceRooms/conference-rooms-index.js', true);
320
        } elseif ($action === 'modify') {
321
            $this->footerCollectionJS
322
                ->addJs('js/pbx/main/form.js', true)
323
                ->addJs('js/pbx/ConferenceRooms/conference-room-modify.js', true);
324
        }
325
    }
326
327
    /**
328
     * Makes assets for the SystemDiagnostic controller
329
     *
330
     * @param string $action
331
     */
332
    private function makeSystemDiagnosticAssets(string $action): void
333
    {
334
        if ($action === 'index') {
335
            $this->footerCollectionJS
336
                ->addJs('js/vendor/semantic/popup.min.js', true)
337
                ->addJs('js/vendor/semantic/dropdown.min.js', true)
338
                ->addJs('js/pbx/main/form.js', true)
339
                ->addJs('js/pbx/SystemDiagnostic/system-diagnostic-index.js', true)
340
                ->addJs('js/pbx/SystemDiagnostic/system-diagnostic-index-showlogs.js', true)
341
                ->addJs('js/pbx/SystemDiagnostic/system-diagnostic-index-sysinfo.js', true)
342
                ->addJs('js/pbx/SystemDiagnostic/system-diagnostic-index-logcapture.js', true);
343
            $this->footerCollectionACE
344
                ->addJs('js/vendor/ace/ace.js', true)
345
                ->addJs('js/vendor/ace/mode-julia.js', true);
346
        }
347
    }
348
349
    /**
350
     * Makes assets for the SoundFiles controller
351
     *
352
     * @param string $action
353
     */
354
    private function makeSoundFilesAssets(string $action): void
355
    {
356
        if ($action === 'index') {
357
            $this->headerCollectionCSS
358
                ->addCss('css/vendor/range/range.css')
359
                ->addCss(
360
                    'css/vendor/datatable/dataTables.semanticui.css',
361
                    true
362
                );
363
            $this->footerCollectionJS->addJs('js/vendor/datatable/dataTables.semanticui.js', true)
364
                ->addJs('js/vendor/range/range.min.js', true)
365
                ->addJs('js/vendor/jquery.address.min.js', true)
366
                ->addJs('js/pbx/SoundFiles/sound-files-index-player.js', true)
367
                ->addJs('js/pbx/SoundFiles/sound-files-index.js', true);
368
        } elseif ($action === 'modify') {
369
            $this->headerCollectionCSS->addCss('css/vendor/range/range.css');
370
371
            $this->headerCollectionJS
372
                ->addJs(
373
                    'js/vendor/webrtc/MediaStreamRecorder.min.js',
374
                    true
375
                )
376
                ->addJs('js/vendor/webrtc/adapter-latest.min.js', true);
377
378
            $this->footerCollectionJS
379
                ->addJs('js/vendor/range/range.min.js', true)
380
                ->addJs('js/pbx/main/form.js', true)
381
                ->addJs('js/vendor/resumable.js', true)
382
                ->addJs('js/pbx/SoundFiles/sound-file-modify-player.js', true)
383
                ->addJs('js/pbx/SoundFiles/sound-file-modify-upload-worker.js', true)
384
                ->addJs('js/pbx/SoundFiles/sound-file-modify-webkit-recorder.js', true)
385
                ->addJs('js/pbx/SoundFiles/sound-file-modify.js', true);
386
        }
387
    }
388
389
    /**
390
     * Makes assets for the TimeSettings controller
391
     *
392
     * @param string $action
393
     */
394
    private function makeTimeSettingsAssets(string $action): void
395
    {
396
        if ($action === 'modify') {
397
            $this->footerCollectionJS
398
                ->addJs('js/pbx/main/form.js', true)
399
                ->addJs('js/vendor/moment/moment-with-locales.min.js', true)
400
                ->addJs('js/vendor/moment-timezone/moment-timezone-with-data.min.js', true)
401
                ->addJs('js/pbx/TimeSettings/time-settings-worker.js', true)
402
                ->addJs('js/pbx/TimeSettings/time-settings-modify.js', true);
403
        }
404
    }
405
406
    /**
407
     * Makes assets for the Update controller
408
     *
409
     * @param string $action
410
     */
411
    private function makeUpdateAssets(string $action): void
412
    {
413
        if ($action === 'index') {
414
            $this->footerCollectionJS
415
                ->addJs('js/pbx/main/version-compare.js', true)
416
                ->addJs('js/pbx/main/form.js', true)
417
                ->addJs('js/vendor/resumable.js', true)
418
                ->addJs('js/vendor/showdown/showdown.min.js', true)
419
                ->addJs('js/pbx/Update/update-status-worker.js', true)
420
                ->addJs('js/pbx/Update/update-merging-worker.js', true)
421
                ->addJs('js/pbx/Update/update-index.js', true);
422
            $this->semanticCollectionCSS
423
                ->addCss('css/vendor/semantic/progress.min.css', true)
424
                ->addCss('css/vendor/semantic/modal.min.css', true);
425
426
            $this->semanticCollectionJS
427
                ->addJs('js/vendor/semantic/progress.min.js', true)
428
                ->addJs('js/vendor/semantic/modal.min.js', true);
429
        }
430
    }
431
432
    /**
433
     * Makes assets for the Session controller
434
     *
435
     * @param string $action
436
     */
437
    private function makeSessionAssets(string $action): void
438
    {
439
        if ($action === 'index') {
440
            $this->footerCollectionJS
441
                ->addJs('js/pbx/main/form.js', true)
442
                ->addJs('js/pbx/Session/login-form.js', true);
443
        }
444
    }
445
446
    /**
447
     * Makes assets for the Restart controller
448
     *
449
     * @param string $action
450
     */
451
    private function makeRestartAssets(string $action): void
452
    {
453
        if ($action === 'index') {
454
            $this->footerCollectionJS
455
                ->addJs('js/pbx/Restart/restart-index.js', true);
456
        }
457
    }
458
459
    /**
460
     * Makes assets for the Providers controller
461
     *
462
     * @param string $action
463
     */
464
    private function makeProvidersAssets(string $action): void
465
    {
466
        if ($action === 'index') {
467
            $this->semanticCollectionCSS
468
                ->addCss('css/vendor/datatable/dataTables.semanticui.css', true)
469
                ->addCss('css/vendor/semantic/modal.min.css', true);
470
471
            $this->semanticCollectionJS
472
                ->addJs('js/vendor/semantic/modal.min.js', true);
473
            $this->footerCollectionJS
474
                ->addJs('js/pbx/main/debugger-info.js', true)
475
                ->addJs('js/vendor/datatable/dataTables.semanticui.js', true)
476
                ->addJs('js/pbx/Providers/providers-index.js', true);
477
        } elseif ($action === 'modifysip' || $action === 'modifyiax') {
478
            $this->footerCollectionJS
479
                ->addJs('js/pbx/main/form.js', true)
480
                ->addJs('js/pbx/main/debugger-info.js', true)
481
                ->addJs('js/vendor/clipboard/clipboard.js', true)
482
                ->addJs('js/pbx/Providers/provider-modify-status-worker.js', true)
483
                ->addJs('js/pbx/Providers/provider-modify.js', true);
484
        }
485
    }
486
487
    /**
488
     *  Makes assets for the PbxExtensionModules controller
489
     *
490
     * @param string $action
491
     */
492
    private function makePbxExtensionModulesAssets(string $action): void
493
    {
494
        if ($action === 'index') {
495
            $this->semanticCollectionJS->addJs('js/vendor/semantic/modal.min.js', true);
496
            $this->footerCollectionJS
497
                ->addJs('js/pbx/Update/update-api.js', true)
498
                ->addJs('js/vendor/datatable/dataTables.semanticui.js', true)
499
                ->addJs('js/vendor/resumable.js', true)
500
                ->addJs('js/pbx/PbxExtensionModules/pbx-extension-module-upgrade-status-worker.js', true)
501
                ->addJs('js/pbx/PbxExtensionModules/pbx-extension-module-install-status-worker.js', true)
502
                ->addJs('js/pbx/PbxExtensionModules/pbx-extension-module-merging-status-worker.js', true)
503
                ->addJs('js/pbx/PbxExtensionModules/pbx-extension-module-status.js', true)
504
                ->addJs('js/pbx/PbxExtensionModules/pbx-extension-modules-index.js', true)
505
                ->addJs('js/vendor/semantic/progress.min.js', true)
506
                ->addJs('js/pbx/PbxExtensionModules/pbx-extension-module-add-new.js', true);
507
            $this->semanticCollectionCSS
508
                ->addCss('css/vendor/datatable/dataTables.semanticui.min.css', true)
509
                ->addCss('css/vendor/semantic/modal.min.css', true)
510
                ->addCss('css/vendor/semantic/progress.min.css', true);
511
        } elseif ($action === 'modify') {
512
            $this->footerCollectionJS
513
                ->addJs('js/pbx/main/form.js', true)
514
                ->addJs('js/pbx/PbxExtensionModules/pbx-extension-module-modify.js', true);
515
        }
516
    }
517
518
    /**
519
     * Makes assets for the OutOffWorkTime controller
520
     *
521
     * @param string $action
522
     */
523
    private function makeOutOffWorkTimeAssets(string $action): void
524
    {
525
        if ($action === 'index') {
526
            $this->headerCollectionCSS->addCss('css/vendor/datatable/dataTables.semanticui.min.css', true);
527
            $this->footerCollectionJS
528
                ->addJs('js/vendor/datatable/dataTables.semanticui.js', true)
529
                ->addJs('js/pbx/OutOffWorkTime/out-of-work-times-index.js', true);
530
        } elseif ($action === 'modify') {
531
            $this->semanticCollectionCSS->addCss('css/vendor/semantic/calendar.min.css', true);
532
            $this->semanticCollectionJS->addJs('js/vendor/semantic/calendar.min.js', true);
533
            $this->footerCollectionJS
534
                ->addJs('js/pbx/main/form.js', true)
535
                ->addJs('js/pbx/OutOffWorkTime/out-of-work-time-modify.js', true)
536
                ->addJs('js/pbx/SoundFiles/sound-files-selector.js', true)
537
                ->addJs('js/pbx/SoundFiles/one-button-sound-player.js', true);
538
        }
539
    }
540
541
    /**
542
     * Makes assets for the OutboundRoutes controller
543
     *
544
     * @param string $action
545
     */
546
    private function makeOutboundRoutesAssets(string $action): void
547
    {
548
        if ($action === 'index') {
549
            $this->footerCollectionJS
550
                ->addJs('js/vendor/jquery.tablednd.min.js', true)
551
                ->addJs('js/pbx/OutboundRoutes/outbound-routes-index.js', true);
552
        } elseif ($action === 'modify') {
553
            $this->footerCollectionJS->addJs('js/pbx/main/form.js', true)
554
                ->addJs('js/pbx/OutboundRoutes/outbound-route-modify.js', true);
555
        }
556
    }
557
558
    /**
559
     * Makes assets for the Network controller
560
     *
561
     * @param string $action
562
     */
563
    private function makeNetworkAssets(string $action): void
564
    {
565
        if ($action === 'modify') {
566
            $this->footerCollectionJS
567
                //->addJs('js/vendor/inputmask/inputmask.js', true)
568
                ->addJs('js/vendor/inputmask/jquery.inputmask.min.js', true)
569
                ->addJs('js/vendor/inputmask/bindings/inputmask.binding.js', true)
570
                ->addJs('js/vendor/inputmask/init.js', true)
571
                ->addJs('js/pbx/main/form.js', true)
572
                ->addJs('js/pbx/Network/network-modify.js', true);
573
        }
574
    }
575
576
    /**
577
     * Makes assets for the MailSettings controller
578
     *
579
     * @param string $action
580
     */
581
    private function makeMailSettingsAssets(string $action): void
582
    {
583
        if ($action === 'modify') {
584
            $this->footerCollectionJS
585
                ->addJs('js/pbx/main/form.js', true)
586
                ->addJs('js/pbx/MailSettings/mail-settings-modify.js', true);
587
        }
588
    }
589
590
    /**
591
     * Makes assets for the Licensing controller
592
     *
593
     * @param string $action
594
     */
595
    private function makeLicensingAssets(string $action): void
596
    {
597
        if ($action === 'modify') {
598
            $this->footerCollectionJS
599
                //->addJs('js/vendor/inputmask/inputmask.js', true)
600
                ->addJs('js/vendor/inputmask/jquery.inputmask.min.js', true)
601
                ->addJs('js/vendor/inputmask/bindings/inputmask.binding.js', true)
602
                ->addJs('js/vendor/inputmask/init.js', true)
603
                ->addJs('js/pbx/main/form.js', true)
604
                ->addJs('js/pbx/Licensing/licensing-modify.js', true);
605
        }
606
    }
607
608
    /**
609
     * Makes assets for the IvrMenu controller
610
     *
611
     * @param string $action
612
     */
613
    private function makeIvrMenuAssets(string $action): void
614
    {
615
        if ($action === 'index') {
616
            $this->headerCollectionCSS
617
                ->addCss('css/vendor/datatable/dataTables.semanticui.css', true);
618
            $this->footerCollectionJS
619
                ->addJs('js/vendor/datatable/dataTables.semanticui.js', true)
620
                ->addJs('js/pbx/IvrMenu/ivrmenu-index.js', true);
621
        } elseif ($action === 'modify') {
622
            $this->footerCollectionJS->addJs('js/pbx/main/form.js', true)
623
                ->addJs('js/pbx/SoundFiles/sound-files-selector.js', true)
624
                ->addJs('js/pbx/SoundFiles/one-button-sound-player.js', true)
625
                ->addJs('js/pbx/IvrMenu/ivrmenu-modify.js', true);
626
        }
627
    }
628
629
    /**
630
     * Makes assets for the IncomingRoutes controller
631
     *
632
     * @param string $action
633
     */
634
    private function makeIncomingRoutesAssets(string $action): void
635
    {
636
        if ($action === 'index') {
637
            $this->footerCollectionJS->addJs('js/vendor/jquery.tablednd.js', true)
638
                ->addJs('js/pbx/main/form.js', true)
639
                ->addJs('js/pbx/IncomingRoutes/incoming-route-index.js', true);
640
        } elseif ($action === 'modify') {
641
            $this->footerCollectionJS->addJs('js/pbx/main/form.js', true)
642
                ->addJs('js/pbx/IncomingRoutes/incoming-route-modify.js', true);
643
        }
644
    }
645
646
    /**
647
     * Makes assets for the GeneralSettings controller
648
     *
649
     * @param string $action
650
     */
651
    private function makeGeneralSettingsAssets(string $action): void
652
    {
653
        if ($action === 'modify') {
654
            $this->semanticCollectionCSS
655
                ->addCss('css/vendor/semantic/slider.min.css', true)
656
                ->addCss('css/vendor/semantic/progress.min.css', true);
657
            $this->semanticCollectionJS
658
                ->addJs('js/vendor/semantic/slider.min.js', true)
659
                ->addJs('js/vendor/semantic/progress.min.js', true);
660
661
            $this->footerCollectionJS
662
                ->addJs('js/vendor/jquery.address.min.js', true)
663
                ->addJs('js/vendor/jquery.tablednd.js', true)
664
                ->addJs('js/pbx/SoundFiles/sound-files-selector.js', true)
665
                ->addJs('js/pbx/SoundFiles/one-button-sound-player.js', true)
666
                ->addJs('js/pbx/main/form.js', true)
667
                ->addJs('js/pbx/main/password-score.js', true)
668
                ->addJs(
669
                    'js/pbx/GeneralSettings/general-settings-modify.js',
670
                    true
671
                );
672
        }
673
    }
674
675
    /**
676
     * Makes assets for the Firewall controller
677
     *
678
     * @param string $action
679
     */
680
    private function makeFirewallAssets(string $action): void
681
    {
682
        if ($action === 'index') {
683
            $this->footerCollectionJS
684
                ->addJs('js/pbx/Firewall/firewall-index.js', true);
685
        } elseif ($action === 'modify') {
686
            $this->footerCollectionJS
687
                ->addJs('js/pbx/main/form.js', true)
688
                ->addJs('js/pbx/Firewall/firewall-modify.js', true);
689
        }
690
    }
691
692
    /**
693
     * Makes assets for the Fail2Ban controller
694
     *
695
     * @param string $action
696
     */
697
    private function makeFail2BanAssets(string $action): void
698
    {
699
        if ($action === 'index') {
700
            $this->footerCollectionJS
701
                ->addJs('js/pbx/main/form.js', true)
702
                ->addJs('js/pbx/Fail2Ban/fail-to-ban-index.js', true);
703
        }
704
    }
705
706
    /**
707
     * Makes assets for the Extensions controller
708
     *
709
     * @param string $action
710
     */
711
    private function makeExtensionsAssets(string $action): void
712
    {
713
        if ($action === 'index') {
714
            $this->headerCollectionCSS->addCss('css/vendor/datatable/dataTables.semanticui.min.css', true);
715
716
            $this->footerCollectionJS
717
                ->addJs('js/vendor/datatable/dataTables.semanticui.js', true)
718
                //->addJs('js/vendor/inputmask/inputmask.js', true)
719
                ->addJs('js/vendor/inputmask/jquery.inputmask.min.js', true)
720
                ->addJs('js/vendor/inputmask/jquery.inputmask-multi.js', true)
721
                ->addJs('js/vendor/inputmask/bindings/inputmask.binding.js', true)
722
                ->addJs('js/vendor/inputmask/init.js', true)
723
                ->addJs('js/pbx/Extensions/input-mask-patterns.js', true)
724
                ->addJs('js/pbx/Extensions/extensions-index.js', true)
725
                ->addJs('js/pbx/Extensions/extensions-index-status-worker.js', true)
726
                ->addJs('js/pbx/main/debugger-info.js', true)
727
                ->addJs('js/vendor/clipboard/clipboard.js', true);
728
        } elseif ($action === 'modify') {
729
            $this->semanticCollectionCSS->addCss('css/vendor/semantic/card.min.css', true);
730
            $this->footerCollectionJS
731
                //->addJs('js/vendor/inputmask/inputmask.js', true)
732
                ->addJs('js/vendor/inputmask/jquery.inputmask.min.js', true)
733
                ->addJs('js/vendor/inputmask/jquery.inputmask-multi.js', true)
734
                ->addJs('js/vendor/inputmask/bindings/inputmask.binding.js', true)
735
                ->addJs('js/vendor/inputmask/init.js', true)
736
                ->addJs('js/pbx/Extensions/input-mask-patterns.js', true)
737
                ->addJs('js/pbx/main/form.js', true)
738
                ->addJs('js/pbx/main/debugger-info.js', true)
739
                ->addJs('js/pbx/Extensions/extension-modify-avatar.js', true)
740
                ->addJs('js/pbx/Extensions/extension-modify-status-worker.js', true)
741
                ->addJs('js/pbx/Extensions/extension-modify.js', true);
742
        }
743
    }
744
745
    /**
746
     *  Makes assets for the DialplanApplications controller
747
     *
748
     * @param string $action
749
     */
750
    private function makeDialplanApplicationsAssets(string $action): void
751
    {
752
        if ($action === 'index') {
753
            $this->headerCollectionCSS
754
                ->addCss('css/vendor/datatable/dataTables.semanticui.css', true);
755
            $this->footerCollectionJS
756
                ->addJs('js/vendor/datatable/dataTables.semanticui.js', true)
757
                ->addJs('js/pbx/DialplanApplications/dialplan-applications-index.js', true);
758
        } elseif ($action === 'modify') {
759
            $this->footerCollectionACE
760
                ->addJs('js/vendor/ace/ace.js', true)
761
                ->addJs('js/vendor/ace/mode-php.js', true)
762
                ->addJs('js/vendor/ace/mode-julia.js', true);
763
            $this->footerCollectionJS
764
                ->addJs('js/pbx/main/form.js', true)
765
                ->addJs('js/pbx/DialplanApplications/dialplan-applications-modify.js', true);
766
        }
767
    }
768
769
    /**
770
     * Makes assets for the CustomFiles controller
771
     *
772
     * @param string $action
773
     */
774
    private function makeCustomFilesAssets(string $action): void
775
    {
776
        if ($action === 'index') {
777
            $this->headerCollectionCSS
778
                ->addCss('css/vendor/datatable/dataTables.semanticui.css', true);
779
            $this->footerCollectionJS
780
                ->addJs('js/vendor/datatable/dataTables.semanticui.js', true)
781
                ->addJs('js/pbx/CustomFiles/custom-files-index.js', true);
782
        } elseif ($action === 'modify') {
783
            $this->footerCollectionJS
784
                ->addJs('js/pbx/main/form.js', true)
785
                ->addJs('js/pbx/CustomFiles/custom-files-modify.js', true);
786
            $this->footerCollectionACE
787
                ->addJs('js/vendor/ace/ace.js', true)
788
                ->addJs('js/vendor/ace/mode-julia.js', true);
789
        }
790
    }
791
792
    /**
793
     * Makes assets for the CallDetailRecords controller
794
     *
795
     * @param string $action
796
     */
797
    private function makeCallDetailRecordsAssets(string $action): void
798
    {
799
        if ($action === 'index') {
800
            $this->semanticCollectionJS->addJs('js/vendor/semantic/progress.min.js', true);
801
802
            $this->semanticCollectionCSS
803
                ->addCss('css/vendor/range/range.min.css', true)
804
                ->addCss('css/vendor/datatable/scroller.dataTables.min.css', true)
805
                ->addCss('css/vendor/datepicker/daterangepicker.css', true)
806
                ->addCss('css/vendor/datatable/dataTables.semanticui.min.css', true);
807
808
            $this->semanticCollectionJS
809
                ->addJs('js/vendor/datatable/dataTables.semanticui.js', true)
810
                ->addJs('js/vendor/datatable/dataTables.scroller.min.js', true)
811
                ->addJs('js/vendor/datatable/scroller.semanticui.js', true)
812
                //->addJs('js/vendor/datatable/dataTables.pageResize.min.js', TRUE)
813
                ->addJs('js/vendor/range/range.min.js', true)
814
                ->addJS('js/vendor/moment/moment.min.js', true)
815
                ->addJS('js/vendor/datepicker/daterangepicker.js', true);
816
817
            $this->footerCollectionJS
818
                ->addJs(
819
                    'js/pbx/CallDetailRecords/call-detail-records-index.js',
820
                    true
821
                );
822
        }
823
    }
824
825
    /**
826
     * Makes assets for the AsteriskManagers controller
827
     *
828
     * @param string $action
829
     */
830
    private function makeAsteriskManagersAssets(string $action): void
831
    {
832
        if ($action === 'index') {
833
            $this->footerCollectionJS->addJs('js/pbx/AsteriskManagers/managers-index.js', true);
834
        } elseif ($action === 'modify') {
835
            $this->footerCollectionJS
836
                ->addJs('js/pbx/main/form.js', true)
837
                ->addJs('js/pbx/AsteriskManagers/manager-modify.js', true);
838
        }
839
    }
840
841
    /**
842
     * Generates common hash sum for correct combine CSS and JS according to installed modules
843
     *
844
     */
845
    private function getVersionsHash(): string
846
    {
847
        $result = PbxSettings::getValueByKey('PBXVersion');
848
        $modulesVersions = PbxExtensionModules::getModulesArray();
849
        foreach ($modulesVersions as $module) {
850
            $result .= "{$module['id']}{$module['version']}";
851
        }
852
        return md5($result);
853
    }
854
855
}