src/Controller/AppBaseController.php line 30

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Doctrine\DBAL\Driver\Connection;
  4. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  5. use Symfony\Component\Security\Core\Security;
  6. use App\Manager\Flotte\FlotteHelper;
  7. use App\Manager\InterlocuteurHelper;
  8. use App\Manager\ClientEodriveHelper;
  9. class AppBaseController extends Controller
  10. {
  11.     private $security;
  12.     protected $connection;
  13.     public function __construct(
  14.         Security $security,
  15.         Connection $connection
  16.     )
  17.     {
  18.         $this->security $security;
  19.         $this->connection $connection;
  20.     }
  21.     protected function getRepository($entity)
  22.     {
  23.         return $this->getDoctrine()->getRepository($entity);
  24.     }
  25.     protected function save($entity)
  26.     {
  27.         $this->getDoctrine()->getManager()->persist($entity);
  28.         $this->getDoctrine()->getManager()->flush();
  29.         return $this->getDoctrine()->getManager()->contains($entity);
  30.     }
  31.     protected function delete($entity)
  32.     {
  33.         try {
  34.             $this->getDoctrine()->getManager()->remove($entity);
  35.             $this->getDoctrine()->getManager()->flush();
  36.             $this->addFlash("success""Suppression effectuée correctement");
  37.         } catch (\Exception $e) {
  38.             $this->addFlash("warning""Impossible de supprimer l'element selectionné");
  39.         }
  40.         return !$this->getDoctrine()->getManager()->contains($entity);
  41.     }
  42.     protected function addFlash(string $type$message)
  43.     {
  44.         $flashbag $this->get('session')->getFlashBag();
  45.         $flashbag->add($type$message);
  46.     }
  47.     protected function normalizeFileName($chaine)
  48.     {
  49.         $chaine trim($chaine);
  50.         $chaine strtr($chaine,
  51.             "ÀÁÂÃÄÅàáâãäåÒÓÔÕÖØòóôõöøÈÉÊËèéêëÇçÌÍÎÏìíîïÙÚÛÜùúûüÿÑñ",
  52.             "aaaaaaaaaaaaooooooooooooeeeeeeeecciiiiiiiiuuuuuuuuynn");
  53.         $chaine strtr($chaine,"ABCDEFGHIJKLMNOPQRSTUVWXYZ","abcdefghijklmnopqrstuvwxyz");
  54.         $chaine preg_replace('#([^.a-z0-9]+)#i''-'$chaine);
  55.         $chaine preg_replace('#-{2,}#','-',$chaine);
  56.         $chaine preg_replace('#-$#','',$chaine);
  57.         $chaine preg_replace('#^-#','',$chaine);
  58.         return $chaine;
  59.     }
  60.     protected function numberFormatFactory($decimals 0$decimalpoint ','$separator ' '$currency '')
  61.     {
  62.         return function ($value$context) use($decimals$decimalpoint$separator$currency) {
  63.             return is_numeric($value) ? number_format($value$decimals$decimalpoint$separator) . ' ' $currency '';
  64.         };
  65.     }
  66. }