AthenaExtension   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 24
c 1
b 0
f 0
dl 0
loc 54
rs 10
wmc 8

6 Methods

Rating   Name   Duplication   Size   Complexity  
A generateQueryString() 0 10 3
A __construct() 0 6 1
A getDashboardLogo() 0 3 1
A getFunctions() 0 8 1
A getFilters() 0 4 1
A getLoginLogo() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * Copyright (C) 2020-2025 Iain Cambridge
7
 *
8
 * This program is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE as published by
10
 * the Free Software Foundation, either version 2.1 of the License, or
11
 * (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU Lesser General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
 */
21
22
namespace Parthenon\Athena\Twig;
23
24
use Parthenon\Athena\Filters\ListFiltersInterface;
25
use Parthenon\Athena\Repository\NotificationRepositoryInterface;
26
use Parthenon\Athena\SectionManager;
27
use Twig\Extension\AbstractExtension;
28
use Twig\TwigFilter;
29
use Twig\TwigFunction;
30
31
final class AthenaExtension extends AbstractExtension
32
{
33
    private SectionManager $sectionManager;
34
35
    private NotificationRepositoryInterface $notificationRepository;
36
    private ?string $loginLogo;
37
    private ?string $dashboardLogo;
38
39
    public function __construct(SectionManager $sectionManager, NotificationRepositoryInterface $notificationRepository, ?string $loginLogo, ?string $dashboardLogo)
40
    {
41
        $this->sectionManager = $sectionManager;
42
        $this->notificationRepository = $notificationRepository;
43
        $this->loginLogo = $loginLogo;
44
        $this->dashboardLogo = $dashboardLogo;
45
    }
46
47
    public function getFilters(): array
48
    {
49
        return [
50
            new TwigFilter('count', 'count'),
51
        ];
52
    }
53
54
    public function getFunctions(): array
55
    {
56
        return [
57
            new TwigFunction('athena_menu', [$this->sectionManager, 'getMenu']),
58
            new TwigFunction('athena_notifications', [$this->notificationRepository, 'getAllUnread']),
59
            new TwigFunction('athena_crud_filters_link', [$this, 'generateQueryString']),
60
            new TwigFunction('athena_login_logo', [$this, 'getLoginLogo']),
61
            new TwigFunction('athena_dashboard_logo', [$this, 'getDashboardLogo']),
62
        ];
63
    }
64
65
    public function generateQueryString(ListFiltersInterface $listFilters): string
66
    {
67
        $output = '';
68
        foreach ($listFilters->getFilters() as $filter) {
69
            if ($filter->hasData()) {
70
                $output .= '&filters['.$filter->getFieldName().']='.$filter->getData();
71
            }
72
        }
73
74
        return $output;
75
    }
76
77
    public function getLoginLogo(): ?string
78
    {
79
        return $this->loginLogo;
80
    }
81
82
    public function getDashboardLogo(): ?string
83
    {
84
        return $this->dashboardLogo;
85
    }
86
}
87