Przeglądaj źródła

Helper : getDayByNumber

reduction
Guillaume 4 lat temu
rodzic
commit
0996e8070c
3 zmienionych plików z 64 dodań i 0 usunięć
  1. +1
    -0
      ShopBundle/Resources/views/backend/default/list_day.html.twig
  2. +26
    -0
      ShopBundle/Services/Utils.php
  3. +37
    -0
      ShopBundle/Twig/BridgeTwigExtension.php

+ 1
- 0
ShopBundle/Resources/views/backend/default/list_day.html.twig Wyświetl plik

@@ -0,0 +1 @@
{{ getDayByNumber(value) }}

+ 26
- 0
ShopBundle/Services/Utils.php Wyświetl plik

@@ -0,0 +1,26 @@
<?php

namespace Lc\ShopBundle\Services;

class Utils
{
public static function getDayByNumber($number)
{
$daysArray = [
1 => 'Lundu',
2 => 'Mardi',
3 => 'Mercredi',
4 => 'Jeudi',
5 => 'Vendredi',
6 => 'Samedi',
7 => 'Dimanche'
] ;

if(isset($daysArray[$number])) {
return $daysArray[$number] ;
}

return '' ;
}

}

+ 37
- 0
ShopBundle/Twig/BridgeTwigExtension.php Wyświetl plik

@@ -0,0 +1,37 @@
<?php

namespace Lc\ShopBundle\Twig;

use Lc\ShopBundle\Services\Utils;
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;
use Twig\TwigFunction;

class BridgeTwigExtension extends AbstractExtension
{
private $utils ;

public function __construct(Utils $utils)
{
$this->utils = $utils ;
}

public function getFunctions()
{
return array(
new TwigFunction('getDayByNumber', [$this, 'getDayByNumber']),
);
}

public function getFilters()
{
return [
];
}

public function getDayByNumber($number)
{
return $this->utils->getDayByNumber($number) ;
}

}

Ładowanie…
Anuluj
Zapisz