Browse Source

Helper : getDayByNumber

reduction
Guillaume 4 years ago
parent
commit
0996e8070c
3 changed files with 64 additions and 0 deletions
  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 View File

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

+ 26
- 0
ShopBundle/Services/Utils.php View File

@@ -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 View File

@@ -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) ;
}

}

Loading…
Cancel
Save