Passed
Push — master ( 241d97...92d87b )
by Julito
09:22
created

ChamiloExtension::getFunctions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
/* For licensing terms, see /license.txt */
4
5
namespace Chamilo\CoreBundle\Twig\Extension;
6
7
use Chamilo\CoreBundle\Entity\ResourceIllustrationInterface;
8
use Chamilo\CoreBundle\Repository\Node\IllustrationRepository;
9
use Chamilo\CoreBundle\Twig\SettingsHelper;
10
use Twig\Extension\AbstractExtension;
11
use Twig\TwigFilter;
12
use Twig\TwigFunction;
13
14
/**
15
 * Class ChamiloExtension.
16
 */
17
class ChamiloExtension extends AbstractExtension
18
{
19
    private IllustrationRepository $illustrationRepository;
20
    private SettingsHelper $helper;
21
22
    public function __construct(IllustrationRepository $illustrationRepository, SettingsHelper $helper)
23
    {
24
        $this->illustrationRepository = $illustrationRepository;
25
        $this->helper = $helper;
26
    }
27
28
    public function getFilters(): array
29
    {
30
        return [
31
            new TwigFilter('var_dump', 'var_dump'),
32
            new TwigFilter('icon', 'Display::get_icon_path'),
33
            new TwigFilter('get_lang', 'get_lang'),
34
            new TwigFilter('get_plugin_lang', 'get_plugin_lang'),
35
            new TwigFilter('icon', 'Display::get_icon_path'),
36
            new TwigFilter('img', 'Display::get_image'),
37
            new TwigFilter('api_get_local_time', 'api_get_local_time'),
38
            new TwigFilter('api_convert_and_format_date', 'api_convert_and_format_date'),
39
            new TwigFilter('format_date', 'api_format_date'),
40
            new TwigFilter('format_file_size', 'format_file_size'),
41
            new TwigFilter('date_to_time_ago', 'Display::dateToStringAgoAndLongDate'),
42
            new TwigFilter('api_get_configuration_value', 'api_get_configuration_value'),
43
            new TwigFilter('remove_xss', 'Security::remove_XSS'),
44
            new TwigFilter('format_user_full_name', 'UserManager::formatUserFullName'),
45
            new TwigFilter('illustration', [$this, 'getIllustration']),
46
47
            //new \Twig_SimpleFunction('chamilo_settings_all', array($this, 'getSettings')),
48
            new TwigFilter('get_setting', [$this, 'getSettingsParameter']),
49
            new TwigFilter('api_get_setting', [$this, 'getSettingsParameter']),
50
            //new \Twig_SimpleFunction('chamilo_settings_has', [$this, 'hasSettingsParameter']),
51
        ];
52
    }
53
54
    public function getFunctions()
55
    {
56
        return [
57
            new TwigFunction('chamilo_settings_all', [$this, 'getSettings']),
58
            new TwigFunction('chamilo_settings_get', [$this, 'getSettingsParameter']),
59
            new TwigFunction('chamilo_settings_has', [$this, 'hasSettingsParameter']),
60
        ];
61
    }
62
63
    public function getIllustration(ResourceIllustrationInterface $resource): string
64
    {
65
        return $this->illustrationRepository->getIllustrationUrl($resource);
66
    }
67
68
    public function getSettings($namespace)
69
    {
70
        return $this->helper->getSettings($namespace);
71
    }
72
73
    public function getSettingsParameter($name)
74
    {
75
        return $this->helper->getSettingsParameter($name);
76
    }
77
78
    /**
79
     * Returns the name of the extension.
80
     *
81
     * @return string The extension name
82
     */
83
    public function getName()
84
    {
85
        return 'chamilo_extension';
86
    }
87
}
88