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( |
|
|
|
|
22
|
|
|
'is_safe' => array('html'), |
23
|
|
|
'needs_environment' => true |
24
|
|
|
)), |
25
|
|
|
new \Twig_SimpleFunction('elastica_clear_sort', array($this, 'clearSort'), array( |
|
|
|
|
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
|
|
|
|
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.