Completed
Push — master ( df2023...fa3144 )
by Julito
16:31
created

ChamiloExtension   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Importance

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

6 Methods

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