Passed
Push — master ( 894ff6...5a2620 )
by Angel Fernando Quiroz
08:41
created

IndexBlocksController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
nc 1
nop 8
dl 0
loc 13
rs 10
c 1
b 0
f 0

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
/* For licensing terms, see /license.txt */
4
5
declare(strict_types=1);
6
7
namespace Chamilo\CoreBundle\Controller\Admin;
8
9
use AppPlugin;
10
use Chamilo\CoreBundle\Controller\BaseController;
11
use Chamilo\CoreBundle\Entity\Page;
12
use Chamilo\CoreBundle\Entity\PageCategory;
13
use Chamilo\CoreBundle\Entity\SequenceResource;
14
use Chamilo\CoreBundle\Event\AbstractEvent;
15
use Chamilo\CoreBundle\Event\AdminBlockDisplayedEvent;
16
use Chamilo\CoreBundle\Event\Events;
17
use Chamilo\CoreBundle\Helpers\AccessUrlHelper;
18
use Chamilo\CoreBundle\Repository\PageCategoryRepository;
19
use Chamilo\CoreBundle\Repository\PageRepository;
20
use Chamilo\CoreBundle\Repository\PluginRepository;
21
use Chamilo\CoreBundle\Settings\SettingsManager;
22
use Plugin;
23
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
24
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
25
use Symfony\Component\HttpFoundation\JsonResponse;
26
use Symfony\Component\Routing\Attribute\Route;
27
use Symfony\Component\Serializer\SerializerInterface;
28
use Symfony\Contracts\Translation\TranslatorInterface;
29
30
#[Security("is_granted('ROLE_ADMIN') or is_granted('ROLE_SESSION_MANAGER')")]
31
#[Route('/admin/index', name: 'admin_index_blocks')]
32
class IndexBlocksController extends BaseController
33
{
34
    private bool $isAdmin = false;
35
    private bool $isSessionAdmin = false;
36
    private array $extAuthSource = [];
37
38
    public function __construct(
39
        private readonly TranslatorInterface $translator,
40
        private readonly SettingsManager $settingsManager,
41
        private readonly PageRepository $pageRepository,
42
        private readonly PageCategoryRepository $pageCategoryRepository,
43
        private readonly SerializerInterface $serializer,
44
        private readonly EventDispatcherInterface $eventDispatcher,
45
        private readonly PluginRepository $pluginRepository,
46
        private readonly AccessUrlHelper $accessUrlHelper,
47
    ) {
48
        $this->extAuthSource = [
49
            'extldap' => [],
50
            'ldap' => [],
51
        ];
52
    }
53
54
    public function __invoke(): JsonResponse
55
    {
56
        $this->isAdmin = $this->isGranted('ROLE_ADMIN');
57
        $this->isSessionAdmin = $this->isGranted('ROLE_SESSION_MANAGER');
58
59
        $json = [];
60
61
        $adminBlockEvent = new AdminBlockDisplayedEvent($json, AbstractEvent::TYPE_PRE);
62
63
        $this->eventDispatcher->dispatch($adminBlockEvent, Events::ADMIN_BLOCK_DISPLAYED);
64
65
        $json = $adminBlockEvent->getData();
66
67
        $json['users'] = [
68
            'id' => 'block-admin-users',
69
            'searchUrl' => '/main/admin/user_list.php',
70
            'editable' => $this->isAdmin,
71
            'items' => $this->getItemsUsers(),
72
            'extraContent' => $this->getExtraContent('block-admin-users'),
73
        ];
74
75
        if ($this->isAdmin) {
76
            $json['courses'] = [
77
                'id' => 'block-admin-courses',
78
                'searchUrl' => '/main/admin/course_list.php',
79
                'editable' => true,
80
                'items' => $this->getItemsCourses(),
81
                'extraContent' => $this->getExtraContent('block-admin-courses'),
82
            ];
83
84
            $json['platform'] = [
85
                'id' => 'block-admin-platform',
86
                'searchUrl' => $this->generateUrl('chamilo_platform_settings_search'),
87
                'editable' => true,
88
                'items' => $this->getItemsPlatform(),
89
                'extraContent' => $this->getExtraContent('block-admin-platform'),
90
            ];
91
92
            /* Settings */
93
            $json['settings'] = [
94
                'id' => 'block-admin-settings',
95
                'editable' => false,
96
                'items' => $this->getItemsSettings(),
97
                'extraContent' => $this->getExtraContent('block-admin-settings'),
98
            ];
99
100
            // Skills
101
            if ('true' === $this->settingsManager->getSetting('skill.allow_skills_tool')) {
102
                $json['skills'] = [
103
                    'id' => 'block-admin-skills',
104
                    'editable' => false,
105
                    'items' => $this->getItemsSkills(),
106
                    'extraContent' => $this->getExtraContent('block-admin-skills'),
107
                ];
108
            }
109
110
            if ('true' === $this->settingsManager->getSetting('gradebook.gradebook_dependency')) {
111
                $json['gradebook'] = [
112
                    'id' => 'block-admin-gradebook',
113
                    'editable' => false,
114
                    'items' => $this->getItemsGradebook(),
115
                    'extraContent' => $this->getExtraContent('block-admin-gradebook'),
116
                ];
117
            }
118
119
            // Data protection
120
            if ('true' !== $this->settingsManager->getSetting('privacy.disable_gdpr')) {
121
                $json['data_privacy'] = [
122
                    'id' => 'block-admin-privacy',
123
                    'editable' => false,
124
                    'items' => $this->getItemsPrivacy(),
125
                    'extraContent' => $this->getExtraContent('block-admin-privacy'),
126
                ];
127
            }
128
129
            $json['security'] = [
130
                'id' => 'block-admin-security',
131
                'editable' => false,
132
                'items' => $this->getItemsSecurity(),
133
                'extraContent' => $this->getExtraContent('block-admin-security'),
134
            ];
135
136
            /* Chamilo.org */
137
            $json['chamilo'] = [
138
                'id' => 'block-admin-chamilo',
139
                'editable' => false,
140
                'items' => $this->getItemsChamilo(),
141
                'extraContent' => $this->getExtraContent('block-admin-chamilo'),
142
            ];
143
144
            $json['plugins'] = [
145
                'id' => 'block-admin-plugins',
146
                'editable' => false,
147
                'items' => $this->getItemsPlugins(),
148
            ];
149
        }
150
151
        /* Sessions */
152
        $json['sessions'] = [
153
            'id' => 'block-admin-sessions',
154
            'searchUrl' => '/main/session/session_list.php',
155
            'editable' => $this->isAdmin,
156
            'items' => $this->getItemsSessions(),
157
            'extraContent' => $this->getExtraContent('block-admin-sessions'),
158
        ];
159
160
        $adminBlockEvent = new AdminBlockDisplayedEvent($json, AbstractEvent::TYPE_POST);
161
162
        $this->eventDispatcher->dispatch($adminBlockEvent, Events::ADMIN_BLOCK_DISPLAYED);
163
164
        $json = $adminBlockEvent->getData();
165
166
        return $this->json($json);
167
    }
168
169
    private function getItemsSecurity(): array
170
    {
171
        return [
172
            [
173
                'class' => 'item-security-login-attempts',
174
                'url' => $this->generateUrl('admin_security_login_attempts'),
175
                'label' => $this->translator->trans('Login attempts'),
176
            ],
177
        ];
178
    }
179
180
    private function getItemsUsers(): array
181
    {
182
        $items = [];
183
        $items[] = [
184
            'class' => 'item-user-list',
185
            'url' => '/main/admin/user_list.php',
186
            'label' => $this->translator->trans('User list'),
187
        ];
188
        $items[] = [
189
            'class' => 'item-user-add',
190
            'url' => '/main/admin/user_add.php',
191
            'label' => $this->translator->trans('Add a user'),
192
        ];
193
194
        if ($this->isAdmin) {
195
            $items[] = [
196
                'class' => 'item-user-export',
197
                'url' => '/main/admin/user_export.php',
198
                'label' => $this->translator->trans('Export users list'),
199
            ];
200
            $items[] = [
201
                'class' => 'item-user-import',
202
                'url' => '/main/admin/user_import.php',
203
                'label' => $this->translator->trans('Import users list'),
204
            ];
205
            $items[] = [
206
                'class' => 'item-user-import-update',
207
                'url' => '/main/admin/user_update_import.php',
208
                'label' => $this->translator->trans('Edit users list'),
209
            ];
210
            $items[] = [
211
                'class' => 'item-user-import-anonymize',
212
                'url' => '/main/admin/user_anonymize_import.php',
213
                'label' => $this->translator->trans('Anonymise users list'),
214
            ];
215
216
            if (\count($this->extAuthSource['extldap']) > 0) {
217
                $items[] = [
218
                    'class' => 'item-user-ldap-list',
219
                    'url' => '/main/admin/ldap_users_list.php',
220
                    'label' => $this->translator->trans('Import LDAP users into the platform'),
221
                ];
222
            }
223
224
            $items[] = [
225
                'class' => 'item-user-field',
226
                'url' => '/main/admin/extra_fields.php?'.http_build_query(['type' => 'user']),
227
                'label' => $this->translator->trans('Profiling'),
228
            ];
229
            $items[] = [
230
                'class' => 'item-user-groups',
231
                'url' => '/main/admin/usergroups.php',
232
                'label' => $this->translator->trans('Classes'),
233
            ];
234
235
            if ('true' === $this->settingsManager->getSetting('admin.show_link_request_hrm_user')) {
236
                $items[] = [
237
                    'class' => 'item-user-linking-requests',
238
                    'url' => '/main/admin/user_linking_requests.php',
239
                    'label' => $this->translator->trans('Student linking requests'),
240
                ];
241
            }
242
        } else {
243
            $items[] = [
244
                'class' => 'item-user-import',
245
                'url' => '/main/admin/user_import.php',
246
                'label' => $this->translator->trans('Import users list'),
247
            ];
248
            $items[] = [
249
                'class' => 'item-user-groups',
250
                'url' => '/main/admin/usergroups.php',
251
                'label' => $this->translator->trans('Classes'),
252
            ];
253
254
            if ('true' === $this->settingsManager->getSetting('session.limit_session_admin_role')) {
255
                $items = array_filter($items, function (array $item) {
256
                    $urls = [
257
                        '/main/admin/user_list.php',
258
                        '/main/admin/user_add.php',
259
                    ];
260
261
                    return \in_array($item['url'], $urls, true);
262
                });
263
            }
264
265
            if ('true' === $this->settingsManager->getSetting('session.limit_session_admin_list_users')) {
266
                $items = array_filter($items, function (array $item): bool {
267
                    $urls = [
268
                        '/main/admin/user_list.php',
269
                    ];
270
271
                    return !\in_array($item['url'], $urls, true);
272
                });
273
            }
274
275
            if ('true' === $this->settingsManager->getSetting('session.allow_session_admin_extra_access')) {
276
                $items[] = [
277
                    'class' => 'item-user-import-update',
278
                    'url' => '/main/admin/user_update_import.php',
279
                    'label' => $this->translator->trans('Edit users list'),
280
                ];
281
                $items[] = [
282
                    'class' => 'item-user-export',
283
                    'url' => '/main/admin/user_export.php',
284
                    'label' => $this->translator->trans('Export users list'),
285
                ];
286
            }
287
        }
288
289
        return array_values($items);
290
    }
291
292
    private function getExtraContent(string $title): ?array
293
    {
294
        /** @var Page|null $page */
295
        $page = $this->pageRepository->findOneBy(['title' => $title]);
296
297
        $pageJsonld = $this->serializer->serialize($page, 'jsonld', ['groups' => ['adminblock:read']]);
298
        $pageArray = json_decode($pageJsonld, true);
299
300
        if ($page) {
301
            return $pageArray;
302
        }
303
304
        /** @var PageCategory $category */
305
        $category = $this->pageCategoryRepository->findOneBy(['title' => $title]);
306
        $categoryJsonld = $this->serializer->serialize($category, 'jsonld', ['groups' => ['page:read']]);
307
        $categoryArray = json_decode($categoryJsonld, true);
308
309
        if (empty($categoryArray)) {
310
            return [];
311
        }
312
313
        return [
314
            'category' => $categoryArray['@id'],
315
        ];
316
    }
317
318
    private function getItemsCourses(): array
319
    {
320
        $items = [];
321
        $items[] = [
322
            'class' => 'item-course-list',
323
            'url' => '/main/admin/course_list.php',
324
            'label' => $this->translator->trans('Course list'),
325
        ];
326
        $items[] = [
327
            'class' => 'item-course-add',
328
            'url' => '/main/admin/course_add.php',
329
            'label' => $this->translator->trans('Add course'),
330
        ];
331
332
        if ('true' === $this->settingsManager->getSetting('course.course_validation')) {
333
            $items[] = [
334
                'class' => 'item-course-request',
335
                'url' => '/main/admin/course_request_review.php',
336
                'label' => $this->translator->trans('Review incoming course requests'),
337
            ];
338
            $items[] = [
339
                'class' => 'item-course-request-accepted',
340
                'url' => '/main/admin/course_request_accepted.php',
341
                'label' => $this->translator->trans('Accepted course requests'),
342
            ];
343
            $items[] = [
344
                'class' => 'item-course-request-rejected',
345
                'url' => '/main/admin/course_request_rejected.php',
346
                'label' => $this->translator->trans('Rejected course requests'),
347
            ];
348
        }
349
350
        $items[] = [
351
            'class' => 'item-course-export',
352
            'url' => '/main/admin/course_export.php',
353
            'label' => $this->translator->trans('Export courses'),
354
        ];
355
        $items[] = [
356
            'class' => 'item-course-import',
357
            'url' => '/main/admin/course_import.php',
358
            'label' => $this->translator->trans('Import courses list'),
359
        ];
360
        $items[] = [
361
            'class' => 'item-course-category',
362
            'url' => '/main/admin/course_category.php',
363
            'label' => $this->translator->trans('Course categories'),
364
        ];
365
        $items[] = [
366
            'class' => 'item-course-subscription',
367
            'url' => '/main/admin/subscribe_user2course.php',
368
            'label' => $this->translator->trans('Add a user to a course'),
369
        ];
370
        $items[] = [
371
            'class' => 'item-course-subscription-import',
372
            'url' => '/main/admin/course_user_import.php',
373
            'label' => $this->translator->trans('Import users list'),
374
        ];
375
        // $items[] = [
376
        //    'url'=>'course_intro_pdf_import.php',
377
        //    'label' => $this->translator->$this->trans('Import PDF introductions into courses'),
378
        // ];
379
380
        if ('true' === $this->settingsManager->getSetting('gradebook.gradebook_enable_grade_model')) {
381
            $items[] = [
382
                'class' => 'item-grade-model',
383
                'url' => '/main/admin/grade_models.php',
384
                'label' => $this->translator->trans('Grading model'),
385
            ];
386
        }
387
388
        if (\count($this->extAuthSource['ldap']) > 0) {
389
            $items[] = [
390
                'class' => 'item-course-subscription-ldap',
391
                'url' => '/main/admin/ldap_import_students.php',
392
                'label' => $this->translator->trans('Import LDAP users into a course'),
393
            ];
394
        }
395
396
        $items[] = [
397
            'class' => 'item-course-field',
398
            'url' => '/main/admin/extra_fields.php?'.http_build_query(['type' => 'course']),
399
            'label' => $this->translator->trans('Manage extra fields for courses'),
400
        ];
401
        $items[] = [
402
            'class' => 'item-question-bank',
403
            'url' => '/main/admin/questions.php',
404
            'label' => $this->translator->trans('Questions'),
405
        ];
406
        $items[] = [
407
            'class' => 'item-resource-sequence',
408
            'url' => '/main/admin/resource_sequence.php?'.http_build_query(['type' => SequenceResource::COURSE_TYPE]),
409
            'label' => $this->translator->trans('Resources sequencing'),
410
        ];
411
412
        return $items;
413
    }
414
415
    private function getItemsPlatform(): array
416
    {
417
        $items = [];
418
        $items[] = [
419
            'class' => 'item-setting-list',
420
            'url' => $this->generateUrl('admin_settings'),
421
            'label' => $this->translator->trans('Configuration settings'),
422
        ];
423
        $items[] = [
424
            'class' => 'item-language-list',
425
            'url' => '/main/admin/languages.php',
426
            'label' => $this->translator->trans('Languages'),
427
        ];
428
        $items[] = [
429
            'class' => 'item-plugin-list',
430
            'url' => '/main/admin/settings.php?'.http_build_query(['category' => 'Plugins']),
431
            'label' => $this->translator->trans('Plugins'),
432
        ];
433
        $items[] = [
434
            'class' => 'item-region-list',
435
            'url' => '/main/admin/settings.php?'.http_build_query(['category' => 'Regions']),
436
            'label' => $this->translator->trans('Regions'),
437
        ];
438
        $items[] = [
439
            'class' => 'item-global-announcement',
440
            'url' => '/main/admin/system_announcements.php',
441
            'label' => $this->translator->trans('Portal news'),
442
        ];
443
        $items[] = [
444
            'class' => 'item-global-agenda',
445
            'route' => ['name' => 'CCalendarEventList', 'query' => ['type' => 'global']],
446
            'label' => $this->translator->trans('Global agenda'),
447
        ];
448
        $items[] = [
449
            'class' => 'item-agenda-reminders',
450
            'url' => '/main/admin/import_course_agenda_reminders.php',
451
            'label' => $this->translator->trans('Import course events'),
452
        ];
453
        $items[] = [
454
            'class' => 'item-pages-list',
455
            'route' => ['name' => 'PageList'],
456
            'label' => $this->translator->trans('Pages'),
457
        ];
458
        /*
459
         * Disabled until differentiated with Pages, and reviewed - see GH#6404
460
        $items[] = [
461
            'class' => 'item-page-layouts',
462
            'route' => ['name' => 'PageLayoutList'],
463
            'label' => $this->translator->trans('Page layouts'),
464
        ];
465
        */
466
        $items[] = [
467
            'class' => 'item-registration-page',
468
            'url' => '/main/auth/registration.php?'.http_build_query(['create_intro_page' => 1]),
469
            'label' => $this->translator->trans('Setting the registration page'),
470
        ];
471
        $items[] = [
472
            'class' => 'item-stats',
473
            'url' => '/main/admin/statistics/index.php',
474
            'label' => $this->translator->trans('Statistics'),
475
        ];
476
        $items[] = [
477
            'class' => 'item-stats-report',
478
            'url' => '/main/my_space/company_reports.php',
479
            'label' => $this->translator->trans('Reports'),
480
        ];
481
        $items[] = [
482
            'class' => 'item-teacher-time-report',
483
            'url' => '/main/admin/teacher_time_report.php',
484
            'label' => $this->translator->trans('Teachers time report'),
485
        ];
486
487
        if (api_get_configuration_value('chamilo_cms')) {
488
            $items[] = [
489
                'class' => 'item-cms',
490
                'url' => api_get_path(WEB_PATH).'web/app_dev.php/administration/dashboard',
491
                'label' => $this->translator->trans('CMS'),
492
            ];
493
        }
494
495
        /* Event settings */
496
497
        $items[] = [
498
            'class' => 'item-field',
499
            'url' => '/main/admin/extra_field_list.php',
500
            'label' => $this->translator->trans('Extra fields'),
501
        ];
502
503
        if (api_is_global_platform_admin()) {
504
            $items[] = [
505
                'class' => 'item-access-url',
506
                'url' => '/main/admin/access_urls.php',
507
                'label' => $this->translator->trans('Configure multiple access URL'),
508
            ];
509
        }
510
511
        if ('true' === api_get_plugin_setting('dictionary', 'enable_plugin_dictionary')) {
512
            $items[] = [
513
                'class' => 'item-dictionary',
514
                'url' => api_get_path(WEB_PLUGIN_PATH).'Dictionary/terms.php',
515
                'label' => $this->translator->trans('Dictionary'),
516
            ];
517
        }
518
519
        if ('true' === $this->settingsManager->getSetting('registration.allow_terms_conditions', true)) {
520
            $items[] = [
521
                'class' => 'item-terms-and-conditions',
522
                'route' => ['name' => 'TermsConditionsList'],
523
                'label' => $this->translator->trans('Terms and Conditions'),
524
            ];
525
        }
526
527
        $items[] = [
528
            'class' => 'item-mail-template',
529
            'url' => '/main/mail_template/list.php',
530
            'label' => $this->translator->trans('Mail templates'),
531
        ];
532
533
        if ('true' === api_get_setting('platform.notification_event')) {
534
            $items[] = [
535
                'class' => 'item-notification-list',
536
                'url' => '/main/notification_event/list.php',
537
                'label' => $this->translator->trans('Notifications'),
538
            ];
539
        }
540
541
        $allowJustification = 'true' === api_get_plugin_setting('justification', 'tool_enable');
542
543
        if ($allowJustification) {
544
            $items[] = [
545
                'class' => 'item-justification-list',
546
                'url' => api_get_path(WEB_PLUGIN_PATH).'Justification/list.php',
547
                'label' => $this->translator->trans('Justification'),
548
            ];
549
        }
550
551
        $items[] = [
552
            'class' => 'item-lti-admin',
553
            'url' => $this->generateUrl('chamilo_lti_admin'),
554
            'label' => $this->translator->trans('External tools (LTI)'),
555
        ];
556
557
        $items[] = [
558
            'class' => 'item-contact-category-admin',
559
            'url' => $this->generateUrl('chamilo_contact_category_index'),
560
            'label' => $this->translator->trans('Contact form categories'),
561
        ];
562
563
        $items[] = [
564
            'class' => 'item-system-template-admin',
565
            'url' => '/main/admin/settings.php?'.http_build_query(['category' => 'Templates']),
566
            'label' => $this->translator->trans('System templates'),
567
        ];
568
569
        return $items;
570
    }
571
572
    private function getItemsSettings(): array
573
    {
574
        $items = [];
575
        $items[] = [
576
            'class' => 'item-cleanup-temp-uploads',
577
            'url' => '/admin/cleanup-temp-uploads',
578
            'label' => $this->translator->trans('Clean temporary files'),
579
        ];
580
581
        $items[] = [
582
            'class' => 'item-special-export',
583
            'url' => '/main/admin/special_exports.php',
584
            'label' => $this->translator->trans('Special exports'),
585
        ];
586
        /*$items[] = [
587
            'url' => '/main/admin/periodic_export.php',
588
            'label' => $this->translator->$this->trans('Periodic export'),
589
        ];*/
590
        $items[] = [
591
            'class' => 'item-system-status',
592
            'url' => '/main/admin/system_status.php',
593
            'label' => $this->translator->trans('System status'),
594
        ];
595
        if (is_dir(api_get_path(SYS_TEST_PATH).'datafiller/')) {
596
            $items[] = [
597
                'class' => 'item-data-filler',
598
                'url' => '/main/admin/filler.php',
599
                'label' => $this->translator->trans('Data filler'),
600
            ];
601
        }
602
603
        if (is_dir(api_get_path(SYS_TEST_PATH))) {
604
            $items[] = [
605
                'class' => 'item-email-tester',
606
                'url' => '/main/admin/email_tester.php',
607
                'label' => $this->translator->trans('E-mail tester'),
608
            ];
609
        }
610
611
        $items[] = [
612
            'class' => 'item-ticket-system',
613
            'url' => '/main/ticket/tickets.php',
614
            'label' => $this->translator->trans('Tickets'),
615
        ];
616
617
        $items[] = [
618
            'url' => '/main/session/cron_status.php',
619
            'label' => $this->translator->trans('Update session status'),
620
        ];
621
622
        $items[] = [
623
            'class' => 'item-colors',
624
            'route' => ['name' => 'AdminConfigurationColors'],
625
            'label' => $this->translator->trans('Colors'),
626
        ];
627
628
        $items[] = [
629
            'class' => 'item-file-info',
630
            'url' => '/admin/files_info',
631
            'label' => $this->translator->trans('File info'),
632
        ];
633
634
        $items[] = [
635
            'class' => 'item-resources-info',
636
            'url' => '/admin/resources_info',
637
            'label' => $this->translator->trans('Resources by type'),
638
        ];
639
640
        return $items;
641
    }
642
643
    private function getItemsSkills(): array
644
    {
645
        $items = [];
646
        $items[] = [
647
            'class' => 'item-skill-wheel',
648
            'route' => ['name' => 'SkillWheel'],
649
            'label' => $this->translator->trans('Skills wheel'),
650
        ];
651
        $items[] = [
652
            'class' => 'item-skill-import',
653
            'url' => '/main/skills/skills_import.php',
654
            'label' => $this->translator->trans('Skills import'),
655
        ];
656
        $items[] = [
657
            'class' => 'item-skill-list',
658
            'url' => '/main/skills/skill_list.php',
659
            'label' => $this->translator->trans('Manage skills'),
660
        ];
661
        $items[] = [
662
            'class' => 'item-skill-level',
663
            'url' => '/main/skills/skill.php',
664
            'label' => $this->translator->trans('Manage skills levels'),
665
        ];
666
667
        $items[] = [
668
            'class' => 'item-skill-ranking',
669
            'url' => '/main/social/skills_ranking.php',
670
            'label' => $this->translator->trans('Skills ranking'),
671
        ];
672
        $items[] = [
673
            'class' => 'item-skill-gradebook',
674
            'url' => '/main/skills/skills_gradebook.php',
675
            'label' => $this->translator->trans('Skills and assessments'),
676
        ];
677
678
        /*$items[] = [
679
            'url' => '/main/admin/skill_badge.php',
680
            'label' => $this->translator->trans('Badges'),
681
        ];*/
682
683
        return $items;
684
    }
685
686
    private function getItemsGradebook(): array
687
    {
688
        $items = [];
689
        $items[] = [
690
            'class' => 'item-gradebook-list',
691
            'url' => '/main/admin/gradebook_list.php',
692
            'label' => $this->translator->trans('List'),
693
        ];
694
695
        return $items;
696
    }
697
698
    private function getItemsPrivacy(): array
699
    {
700
        $items = [];
701
        $items[] = [
702
            'class' => 'item-privacy-consent',
703
            'url' => '/main/admin/user_list_consent.php',
704
            'label' => $this->translator->trans('User list'),
705
        ];
706
        $items[] = [
707
            'class' => 'item-gdpr-parties',
708
            'route' => ['name' => 'ThirdPartyManager'],
709
            'label' => $this->translator->trans('Third parties (GDPR)'),
710
        ];
711
712
        return $items;
713
    }
714
715
    private function getItemsChamilo(): array
716
    {
717
        $languageInterface = api_get_language_isocode();
718
719
        $items = [];
720
        $items[] = [
721
            'class' => 'item-software-homepage',
722
            'url' => 'https://chamilo.org/',
723
            'label' => $this->translator->trans('Chamilo homepage'),
724
        ];
725
726
        // Custom linking to user guides in the existing languages
727
        /*$guideLinks = [
728
            'french' => 'v/1.11.x-fr/',
729
            'spanish' => 'v/1.11.x-es/',
730
            'dutch' => 'v/1.11.x-nl/',
731
            'galician' => 'v/1.11.x-ga/',
732
        ];*/
733
734
        $guideLink = 'https://docs.chamilo.org/';
735
736
        /*if (!empty($guideLinks[$languageInterface])) {
737
            $guideLink .= $guideLinks[$languageInterface];
738
        }*/
739
740
        $items[] = [
741
            'class' => 'item-user-guides',
742
            'url' => $guideLink,
743
            'label' => $this->translator->trans('User guides'),
744
        ];
745
        $items[] = [
746
            'class' => 'item-forum',
747
            'url' => 'https://github.com/chamilo/chamilo-lms/discussions/',
748
            'label' => $this->translator->trans('Chamilo forum'),
749
        ];
750
        $items[] = [
751
            'class' => 'item-installation-guide',
752
            'url' => '/documentation/installation_guide.html',
753
            'label' => $this->translator->trans('Installation guide'),
754
        ];
755
        $items[] = [
756
            'class' => 'item-changelog',
757
            'url' => '/documentation/changelog.html',
758
            'label' => $this->translator->trans('Changes in last version'),
759
        ];
760
        $items[] = [
761
            'class' => 'item-credits',
762
            'url' => '/documentation/credits.html',
763
            'label' => $this->translator->trans('Contributors list'),
764
        ];
765
        $items[] = [
766
            'class' => 'item-security',
767
            'url' => '/documentation/security.html',
768
            'label' => $this->translator->trans('Security guide'),
769
        ];
770
        $items[] = [
771
            'class' => 'item-optimization',
772
            'url' => '/documentation/optimization.html',
773
            'label' => $this->translator->trans('Optimization guide'),
774
        ];
775
        $items[] = [
776
            'class' => 'item-extensions',
777
            'url' => 'https://chamilo.org/extensions',
778
            'label' => $this->translator->trans('Chamilo extensions'),
779
        ];
780
        $items[] = [
781
            'class' => 'item-providers',
782
            'url' => 'https://chamilo.org/providers',
783
            'label' => $this->translator->trans('Chamilo official services providers'),
784
        ];
785
786
        return $items;
787
    }
788
789
    private function getItemsSessions(): array
790
    {
791
        $items = [];
792
        $items[] = [
793
            'class' => 'item-session-list',
794
            'url' => '/main/session/session_list.php',
795
            'label' => $this->translator->trans('Training sessions list'),
796
        ];
797
        $items[] = [
798
            'class' => 'item-session-add',
799
            'url' => '/main/session/session_add.php',
800
            'label' => $this->translator->trans('Add a training session'),
801
        ];
802
        $items[] = [
803
            'class' => 'item-session-category',
804
            'url' => '/main/session/session_category_list.php',
805
            'label' => $this->translator->trans('Sessions categories list'),
806
        ];
807
        $items[] = [
808
            'class' => 'item-session-import',
809
            'url' => '/main/session/session_import.php',
810
            'label' => $this->translator->trans('Import sessions list'),
811
        ];
812
        $items[] = [
813
            'class' => 'item-session-import-hr',
814
            'url' => '/main/session/session_import_drh.php',
815
            'label' => $this->translator->trans('Import list of HR directors into sessions'),
816
        ];
817
        if (\count($this->extAuthSource['ldap']) > 0) {
818
            $items[] = [
819
                'class' => 'item-session-subscription-ldap-import',
820
                'url' => '/main/admin/ldap_import_students_to_session.php',
821
                'label' => $this->translator->trans('Import LDAP users into a session'),
822
            ];
823
        }
824
        $items[] = [
825
            'class' => 'item-session-export',
826
            'url' => '/main/session/session_export.php',
827
            'label' => $this->translator->trans('Export sessions list'),
828
        ];
829
830
        $items[] = [
831
            'class' => 'item-session-course-copy',
832
            'url' => '/main/coursecopy/copy_course_session.php',
833
            'label' => $this->translator->trans('Copy from course in session to another session'),
834
        ];
835
836
        $allowCareer = $this->settingsManager->getSetting('session.allow_session_admin_read_careers');
837
838
        if ($this->isAdmin || ('true' === $allowCareer && $this->isSessionAdmin)) {
839
            // Disabled until it is reemplemented to work with Chamilo 2
840
            /*                $items[] = [
841
                                'class' => 'item-session-user-move-stats',
842
                                'url' => '/main/admin/user_move_stats.php',
843
                                'label' => $this->translator->trans('Move users results from/to a session'),
844
                            ];
845
             */
846
            $items[] = [
847
                'class' => 'item-session-user-move',
848
                'url' => '/main/coursecopy/move_users_from_course_to_session.php',
849
                'label' => $this->translator->trans('Move users results from base course to a session'),
850
            ];
851
852
            $items[] = [
853
                'class' => 'item-career-dashboard',
854
                'url' => '/main/admin/career_dashboard.php',
855
                'label' => $this->translator->trans('Careers and promotions'),
856
            ];
857
            $items[] = [
858
                'class' => 'item-session-field',
859
                'url' => '/main/admin/extra_fields.php?'.http_build_query(['type' => 'session']),
860
                'label' => $this->translator->trans('Manage session fields'),
861
            ];
862
            $items[] = [
863
                'class' => 'item-resource-sequence',
864
                'url' => '/main/admin/resource_sequence.php?'.http_build_query(['type' => SequenceResource::SESSION_TYPE]),
865
                'label' => $this->translator->trans('Resources sequencing'),
866
            ];
867
            $items[] = [
868
                'class' => 'item-export-exercise-results',
869
                'url' => '/main/admin/export_exercise_results.php',
870
                'label' => $this->translator->trans('Export all results from an exercise'),
871
            ];
872
        }
873
874
        return $items;
875
    }
876
877
    private function getItemsPlugins(): array
878
    {
879
        $items = [];
880
881
        $accessUrl = $this->accessUrlHelper->getCurrent();
882
        $appPlugin = new AppPlugin();
883
        $plugins = $this->pluginRepository->getInstalledPlugins();
884
885
        foreach ($plugins as $plugin) {
886
            $pluginInfo = $appPlugin->getPluginInfo($plugin->getTitle());
887
            /** @var Plugin $objPlugin */
888
            $objPlugin = $pluginInfo['obj'];
889
            $pluginInUrl = $plugin->getOrCreatePluginConfiguration($accessUrl);
890
            $configuration = $pluginInUrl->getConfiguration();
891
892
            if (!in_array('menu_administrator', $configuration['regions'] ?? [])) {
893
                continue;
894
            }
895
896
            $items[] = [
897
                'class' => 'item-plugin-'.$pluginInfo['title'],
898
                'url' => $objPlugin->getAdminUrl(),
899
                'label' => $pluginInfo['title'],
900
            ];
901
        }
902
903
        return $items;
904
    }
905
}
906