<?php
namespace App\Controller;
use Doctrine\DBAL\Driver\Connection;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Security\Core\Security;
use App\Manager\Flotte\FlotteHelper;
use App\Manager\InterlocuteurHelper;
use App\Manager\ClientEodriveHelper;
class AppBaseController extends Controller
{
private $security;
protected $connection;
public function __construct(
Security $security,
Connection $connection
)
{
$this->security = $security;
$this->connection = $connection;
}
protected function getRepository($entity)
{
return $this->getDoctrine()->getRepository($entity);
}
protected function save($entity)
{
$this->getDoctrine()->getManager()->persist($entity);
$this->getDoctrine()->getManager()->flush();
return $this->getDoctrine()->getManager()->contains($entity);
}
protected function delete($entity)
{
try {
$this->getDoctrine()->getManager()->remove($entity);
$this->getDoctrine()->getManager()->flush();
$this->addFlash("success", "Suppression effectuée correctement");
} catch (\Exception $e) {
$this->addFlash("warning", "Impossible de supprimer l'element selectionné");
}
return !$this->getDoctrine()->getManager()->contains($entity);
}
protected function addFlash(string $type, $message)
{
$flashbag = $this->get('session')->getFlashBag();
$flashbag->add($type, $message);
}
protected function normalizeFileName($chaine)
{
$chaine = trim($chaine);
$chaine = strtr($chaine,
"ÀÁÂÃÄÅàáâãäåÒÓÔÕÖØòóôõöøÈÉÊËèéêëÇçÌÍÎÏìíîïÙÚÛÜùúûüÿÑñ",
"aaaaaaaaaaaaooooooooooooeeeeeeeecciiiiiiiiuuuuuuuuynn");
$chaine = strtr($chaine,"ABCDEFGHIJKLMNOPQRSTUVWXYZ","abcdefghijklmnopqrstuvwxyz");
$chaine = preg_replace('#([^.a-z0-9]+)#i', '-', $chaine);
$chaine = preg_replace('#-{2,}#','-',$chaine);
$chaine = preg_replace('#-$#','',$chaine);
$chaine = preg_replace('#^-#','',$chaine);
return $chaine;
}
protected function numberFormatFactory($decimals = 0, $decimalpoint = ',', $separator = ' ', $currency = '')
{
return function ($value, $context) use($decimals, $decimalpoint, $separator, $currency) {
return is_numeric($value) ? number_format($value, $decimals, $decimalpoint, $separator) . ' ' . $currency : '';
};
}
}