ソースを参照

CityUtils, DateUtils

feature/export_comptable
Guillaume 4年前
コミット
f5532935fe
4個のファイルの変更74行の追加4行の削除
  1. +2
    -2
      ShopBundle/Controller/CitiesController.php
  2. +17
    -1
      ShopBundle/Services/CityUtils.php
  3. +54
    -0
      ShopBundle/Services/DateUtils.php
  4. +1
    -1
      ShopBundle/Services/Utils.php

+ 2
- 2
ShopBundle/Controller/CitiesController.php ファイルの表示

@@ -2,7 +2,7 @@

namespace Lc\ShopBundle\Controller ;

use Lc\ShopBundle\Services\Cities;
use Lc\ShopBundle\Services\CityUtils;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
@@ -11,7 +11,7 @@ class CitiesController extends AbstractController
{
protected $cities ;

public function __construct(Cities $cities)
public function __construct(CityUtils $cities)
{
$this->cities = $cities ;
}

ShopBundle/Services/Cities.php → ShopBundle/Services/CityUtils.php ファイルの表示

@@ -2,7 +2,7 @@

namespace Lc\ShopBundle\Services ;

class Cities
class CityUtils
{

function callApi($method, $url, $data = false)
@@ -39,4 +39,20 @@ class Cities

return $result;
}

public function getZipByCity($city)
{
$zip = null ;
$returnCitiesSearchZip = json_decode($this->callApi('get', 'communes', ['nom' => $city, 'fields' => 'nom,codesPostaux'])) ;

if($returnCitiesSearchZip) {
foreach($returnCitiesSearchZip as $citySearchZip) {
if(strtolower(trim($city)) == strtolower(trim($citySearchZip->nom))) {
$zip = $citySearchZip->codesPostaux[0] ;
}
}
}

return $zip ;
}
}

+ 54
- 0
ShopBundle/Services/DateUtils.php ファイルの表示

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

namespace Lc\ShopBundle\Services ;

class DateUtils
{
public function date($format, $timestamp)
{
setlocale(LC_TIME, 'fr_FR.UTF8', 'fr.UTF8', 'fr_FR.UTF-8', 'fr.UTF-8');
return strftime($format, $timestamp) ;
}

public function getNextDay($day)
{
return new \DateTime('next '.$day) ;
}

public function getNextDayByNumber($number)
{
return $this->getNextDay($this->getDayByNumber($number, 'en')) ;
}

public function getDayByNumber($number, $lang = 'fr')
{
if($lang == 'fr') {
$daysArray = [
1 => 'Lundi',
2 => 'Mardi',
3 => 'Mercredi',
4 => 'Jeudi',
5 => 'Vendredi',
6 => 'Samedi',
7 => 'Dimanche'
] ;
}
else {
$daysArray = [
1 => 'Monday',
2 => 'Tuesday',
3 => 'Wednesday',
4 => 'Thursday',
5 => 'Friday',
6 => 'Saturday',
7 => 'Sunday',
] ;
}

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

return '' ;
}
}

+ 1
- 1
ShopBundle/Services/Utils.php ファイルの表示

@@ -22,6 +22,7 @@ class Utils
$this->parameterBag = $parameterBag ;
}

// @todo : À supprimer et passer dans DateUtils (gérer du coup le cas du modèle DeliverySlot qui dépend de cette fonction)
public static function getDayByNumber($number, $lang = 'fr')
{
if($lang == 'fr') {
@@ -54,7 +55,6 @@ class Utils
return '' ;
}


public function getElementByDevAlias($devAlias, $class = PageInterface::class)
{
$class = $this->em->getClassMetadata($class)->getName();

読み込み中…
キャンセル
保存