Completed
Push — master ( d8eac9...db9f4a )
by Alexis
03:52
created

ElasticaSorterExtension::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Alpixel\Bundle\ElasticaQuerySorterBundle\Twig\Extension;
4
5
use Alpixel\Bundle\ElasticaQuerySorterBundle\Services\ElasticaQuerySorter;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
use Symfony\Component\Yaml\Parser;
8
9
class ElasticaSorterExtension extends \Twig_Extension
10
{
11
    protected $sorter;
12
13
    public function __construct(ElasticaQuerySorter $sorter)
14
    {
15
        $this->sorter = $sorter;
16
    }
17
18
    public function getFunctions()
19
    {
20
        return array(
21
            new \Twig_SimpleFunction('elastica_sort', array($this, 'displaySort'), array(
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFunction has been deprecated with message: to be removed in 3.0

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
22
                'is_safe' => array('html'),
23
                'needs_environment' => true
24
            )),
25
            new \Twig_SimpleFunction('elastica_clear_sort', array($this, 'clearSort'), array(
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFunction has been deprecated with message: to be removed in 3.0

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
26
                'is_safe' => array('html'),
27
                'needs_environment' => true
28
            )),
29
        );
30
    }
31
32
    public function clearSort(\Twig_Environment $twig)
33
    {
34
        return $twig->render('AlpixelElasticaQuerySorterBundle:blocks:clear_sort.html.twig');
35
    }
36
37
    public function displaySort(\Twig_Environment $twig, $label, $sortKey)
38
    {
39
        $isCurrentSort = ($this->sorter->fetchData('sortBy') == $sortKey);
40
41
        return $twig->render('AlpixelElasticaQuerySorterBundle:blocks:sort_link.html.twig', array(
42
            'label'     => $label,
43
            'isCurrent' => $isCurrentSort,
44
            'sortKey'   => $sortKey,
45
            'sortOrder' => $this->sorter->fetchData('sortOrder'),
46
        ));
47
    }
48
49
    public function getName()
50
    {
51
        return 'alpixel_elastica_sorter_extension';
52
    }
53
}
54