Completed
Push — master ( fc1588...7621d0 )
by Julito
16:55
created

ChamiloExtension   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 26
dl 0
loc 66
rs 10
c 3
b 0
f 0
wmc 7

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getFilters() 0 17 1
A __construct() 0 3 1
A getUserIllustration() 0 9 2
A getIllustration() 0 5 1
A getFunctions() 0 3 1
A getName() 0 3 1
1
<?php
2
/* For licensing terms, see /license.txt */
3
4
namespace Chamilo\CoreBundle\Twig\Extension;
5
6
use Chamilo\CoreBundle\Repository\IllustrationRepository;
7
use Chamilo\SettingsBundle\Templating\Helper\SettingsHelper;
8
use Twig\Extension\AbstractExtension;
9
use Twig\TwigFilter;
10
11
/**
12
 * Class ChamiloExtension.
13
 */
14
class ChamiloExtension extends AbstractExtension
15
{
16
    private $illustrationRepository;
17
18
    /**
19
     * @param SettingsHelper $helper
20
     */
21
    public function __construct(IllustrationRepository $illustrationRepository)
22
    {
23
        $this->illustrationRepository = $illustrationRepository;
24
    }
25
26
    public function getFilters(): array
27
    {
28
        return [
29
            new TwigFilter('var_dump', 'var_dump'),
30
            new TwigFilter('icon', 'Display::get_icon_path'),
31
            new TwigFilter('get_lang', 'get_lang'),
32
            new TwigFilter('get_plugin_lang', 'get_plugin_lang'),
33
            new TwigFilter('icon', 'Display::get_icon_path'),
34
            new TwigFilter('img', 'Display::get_image'),
35
            new TwigFilter('api_get_local_time', 'api_get_local_time'),
36
            new TwigFilter('api_convert_and_format_date', 'api_convert_and_format_date'),
37
            new TwigFilter('format_date', 'api_format_date'),
38
            new TwigFilter('date_to_time_ago', 'Display::dateToStringAgoAndLongDate'),
39
            new TwigFilter('api_get_configuration_value', 'api_get_configuration_value'),
40
            new TwigFilter('format_user_full_name', 'UserManager::formatUserFullName'),
41
            new TwigFilter('illustration', [$this, 'getIllustration']),
42
            new TwigFilter('user_illustration', [$this, 'getUserIllustration']),
43
        ];
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49
    public function getFunctions()
50
    {
51
        return [];
52
    }
53
54
    public function getIllustration($node)
55
    {
56
        $url = $this->illustrationRepository->getIllustrationUrlFromNode($node);
57
58
        return $url;
59
    }
60
61
    public function getUserIllustration($node)
62
    {
63
        $url = $this->getIllustration($node);
64
65
        if (empty($url)) {
66
            return 'img/icons/32/unknown.png';
67
        }
68
69
        return $url;
70
    }
71
72
    /**
73
     * Returns the name of the extension.
74
     *
75
     * @return string The extension name
76
     */
77
    public function getName()
78
    {
79
        return 'chamilo_extension';
80
    }
81
}
82