Browse Source

CityUtils, DateUtils

feature/export_comptable
Guillaume 4 years ago
parent
commit
f5532935fe
4 changed files with 74 additions and 4 deletions
  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 View File



namespace Lc\ShopBundle\Controller ; namespace Lc\ShopBundle\Controller ;


use Lc\ShopBundle\Services\Cities;
use Lc\ShopBundle\Services\CityUtils;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
{ {
protected $cities ; protected $cities ;


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

ShopBundle/Services/Cities.php → ShopBundle/Services/CityUtils.php View File



namespace Lc\ShopBundle\Services ; namespace Lc\ShopBundle\Services ;


class Cities
class CityUtils
{ {


function callApi($method, $url, $data = false) function callApi($method, $url, $data = false)


return $result; 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 View File

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

$this->parameterBag = $parameterBag ; $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') public static function getDayByNumber($number, $lang = 'fr')
{ {
if($lang == 'fr') { if($lang == 'fr') {
return '' ; return '' ;
} }



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

Loading…
Cancel
Save