Passed
Push — develop ( db553e...8a684e )
by Nikolay
06:02
created

AssetProvider::initializeClassVariables()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 26
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 22
c 0
b 0
f 0
dl 0
loc 26
rs 9.568
cc 1
nc 1
nop 1
1
<?php
2
/*
3
 * MikoPBX - free phone system for small business
4
 * Copyright © 2017-2023 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 Phalcon\Mvc\Dispatcher;
35
use function MikoPBX\Common\Config\appPath;
36
37
/**
38
 * Prepares list of CSS and JS files according to called controller/action
39
 *
40
 * @package MikoPBX\AdminCabinet\Providers
41
 */
42
class AssetProvider implements ServiceProviderInterface
43
{
44
    public const SERVICE_NAME = 'assets';
45
46
    private Collection $headerCollectionJSForExtensions;
47
    private Collection $footerCollectionJSForExtensions;
48
    private Collection $headerCollectionJS;
49
    private Collection $headerCollectionCSS;
50
    private Collection $footerCollectionJS;
51
    private Collection $semanticCollectionCSS;
52
    private Collection $semanticCollectionJS;
53
    private Collection $footerCollectionACE;
54
    private Collection $footerCollectionLoc;
55
    private Collection $headerCollectionSentryJS;
56
    private string $jsCacheDir;
57
    private Manager $manager;
58
59
    /**
60
     * Registers assets service provider
61
     *
62
     * @param DiInterface $di The DI container.
63
     */
64
    public function register(DiInterface $di): void
65
    {
66
        $di->set(
67
            self::SERVICE_NAME,
68
            function () use ($di) {
69
70
                $session = $di->get(SessionProvider::SERVICE_NAME);
71
72
                $assets = new AssetProvider();
73
                // Module and PBX version caching for proper PBX operation when installing modules.
74
                $version = $session->get(SessionProvider::VERSION_HASH) ?? '';
75
                if (empty($version)) {
76
                    $version = $assets->getVersionsHash();
77
                    $session->set(SessionProvider::VERSION_HASH, $version);
78
                }
79
                $assets->initializeClassVariables($version);
80
                $dispatcher = $di->get(DispatcherProvider::SERVICE_NAME);
81
                $controller = $dispatcher->getControllerName();
82
                $action = $dispatcher->getActionName();
83
84
                if ($action === null) {
85
                    $action = 'index';
86
                }
87
88
                $assets->makeSentryAssets();
89
                $assets->makeHeaderAssets($session, $dispatcher);
90
91
                // Generates Controllers assets
92
                $method_name = "make{$controller}Assets";
93
                if (method_exists($assets, $method_name)) {
94
                    $assets->$method_name($action);
95
                }
96
97
                $assets->makeFooterAssets();
98
                $assets->makeLocalizationAssets($di, $version);
99
100
                $assetsManager = $assets->manager;
101
102
                // Register additional assets from external enabled modules
103
                PBXConfModulesProvider::hookModulesMethod(WebUIConfigInterface::ON_AFTER_ASSETS_PREPARED, [$assetsManager]);
104
105
                return $assetsManager;
106
            }
107
        );
108
    }
109
110
    /**
111
     * Initialize class variables
112
     */
113
    public function initializeClassVariables(string $version)
114
    {
115
        $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

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