瀏覽代碼

Helper : getDayByNumber

reduction
Guillaume 4 年之前
父節點
當前提交
0996e8070c
共有 3 個文件被更改,包括 64 次插入0 次删除
  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 查看文件

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

+ 26
- 0
ShopBundle/Services/Utils.php 查看文件

@@ -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 查看文件

@@ -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…
取消
儲存