src/Service/FunctionService.php line 635

  1. <?php
  2. /**
  3.  * Created by PhpStorm.
  4.  * User: JMR
  5.  * Date: 16/01/2023
  6.  * Time: 16:28
  7.  */
  8. namespace App\Service;
  9. use Doctrine\ORM\EntityManagerInterface;
  10. use App\Entity\SyntheseConducteur;
  11. class FunctionService
  12. {
  13.     private $em;
  14.     public function __construct(EntityManagerInterface $em)
  15.     {
  16.         $this->em $em;
  17.     }
  18.     public function getListMoisString()
  19.     {
  20.         $list = array();
  21.         for ($i=1$i <= 12$i++ ){
  22.             $list[$i] = self::moisString($i);
  23.         }
  24.         return $list;
  25.     }
  26.     public function moisString($mois)
  27.     {
  28.         $string "";
  29.         if($mois==1)
  30.         {
  31.             $string "Janvier";
  32.         }
  33.         else if($mois==2)
  34.         {
  35.             $string "Février";
  36.         }
  37.         else if($mois==3)
  38.         {
  39.             $string "Mars";
  40.         }
  41.         else if($mois==4)
  42.         {
  43.             $string "Avril";
  44.         }
  45.         else if($mois==5)
  46.         {
  47.             $string "Mai";
  48.         }
  49.         else if($mois==6)
  50.         {
  51.             $string "Juin";
  52.         }
  53.         else if($mois==7)
  54.         {
  55.             $string "Juillet";
  56.         }
  57.         else if($mois==8)
  58.         {
  59.             $string "Aout";
  60.         }
  61.         else if($mois==9)
  62.         {
  63.             $string "Septembre";
  64.         }
  65.         else if($mois==10)
  66.         {
  67.             $string "Octobre";
  68.         }
  69.         else if($mois==11)
  70.         {
  71.             $string "Novembre";
  72.         }
  73.         else if($mois==12)
  74.         {
  75.             $string "Décembre";
  76.         }
  77.         return $string;
  78.     }
  79.     public function moisNumber($mois)
  80.     {
  81.         $string "";
  82.         if($mois=="Janvier")
  83.         {
  84.             $string 1;
  85.         }
  86.         else if($mois=="Février")
  87.         {
  88.             $string 2;
  89.         }
  90.         else if($mois=="Mars")
  91.         {
  92.             $string 3;
  93.         }
  94.         else if($mois=="Avril")
  95.         {
  96.             $string 4;
  97.         }
  98.         else if($mois=="Mai")
  99.         {
  100.             $string 5;
  101.         }
  102.         else if($mois=="Juin")
  103.         {
  104.             $string 6;
  105.         }
  106.         else if($mois=="Juillet")
  107.         {
  108.             $string 7;
  109.         }
  110.         else if($mois=="Aout")
  111.         {
  112.             $string 8;
  113.         }
  114.         else if($mois=="Septembre")
  115.         {
  116.             $string 9;
  117.         }
  118.         else if($mois=="Octobre")
  119.         {
  120.             $string 10;
  121.         }
  122.         else if($mois=="Novembre")
  123.         {
  124.             $string 11;
  125.         }
  126.         else if($mois=="Décembre")
  127.         {
  128.             $string 12;
  129.         }
  130.         return $string;
  131.     }
  132.     public function formatageChiffre($chiffre)
  133.     {
  134.         //var_dump($chiffre);
  135.         $value '';
  136.         $explChi explode('.',$chiffre);
  137.         //ajout espace entre 1 000
  138.         $arrayString str_split($explChi[0]);
  139.         krsort($arrayString);
  140.         if(!empty($arrayString))
  141.         {
  142.             $i 0;
  143.             foreach($arrayString as $str)
  144.             {
  145.                 if($i==3)
  146.                 {
  147.                     $value $str.' '.$value;
  148.                     $i 0;
  149.                 }
  150.                 else
  151.                 {
  152.                     $value $str.$value;
  153.                 }
  154.                 $i++;
  155.             }
  156.         }
  157.         //ajout 00
  158.         if(count($explChi)==2)
  159.         {
  160.             //var_dump($explChi);
  161.             if(strlen($explChi[1])==1)
  162.             {
  163.                 $value $value.'.'.$explChi[1].'0';
  164.             }
  165.             else
  166.             {
  167.                 $value $value.'.'.$explChi[1];
  168.             }
  169.         }
  170.         else if(count($explChi)==1)
  171.         {
  172.             $value $value.'.00';
  173.         }
  174.         return $value;
  175.     }
  176.     public function paginator($repository,$page,$search null,$champTri 'id')
  177.     {
  178.         $limit 10;
  179.         $return = array('nbrPage'=>0);
  180.         $countArray $repository->findCountTotal();
  181.         if(!empty($countArray)) {
  182.             $count $countArray[0]['qte'];
  183.             $return['nbrPage'] = ($count/$limit)+1;
  184.         }
  185.         $return['listNumPage'] = array();
  186.         if($return['nbrPage']>10)
  187.         {
  188.             for ($i=1$i <= $return['nbrPage']; $i++ ){
  189.                 if($i<3)
  190.                 {//pour avoir les 1er
  191.                     $return['listNumPage'][$i] = $i;
  192.                 }
  193.                 if ($i > ($return['nbrPage'] - 3))
  194.                 {//pour avoir les derniers
  195.                     $return['listNumPage'][$i] = $i;
  196.                 }
  197.                 if ($i > ($page 3) && $i < ($page 3))
  198.                 {//pour avoir ceux proche de la page actuelle
  199.                     $return['listNumPage'][$i] = $i;
  200.                 }
  201.             }
  202.             //on boucle pour rajouter des ... en cas de passsage de page
  203.             $lastI 0;
  204.             foreach($return['listNumPage'] as $i => $value)
  205.             {
  206.                 if($lastI<($i-1))
  207.                 {
  208.                     $return['listNumPage'][$i] = '...';
  209.                 }
  210.                 $lastI $i;
  211.             }
  212.         }
  213.         else
  214.         {//si moins de 10 pages, on affiche tous
  215.             for ($i=1$i <= $return['nbrPage']; $i++ ){
  216.                 $return['listNumPage'][$i] = $i;
  217.             }
  218.         }
  219.         if($search != null)
  220.         {
  221.             $return['list'] = $repository->findBy(['id'=>$search], [$champTri=>'DESC'], $limit);
  222.         }
  223.         else
  224.         {
  225.             $return['list'] = $repository->findBy([], [$champTri=>'DESC'], $limit, ($limit * ($page 1)));
  226.         }
  227.         if($champTri=='id')
  228.         {
  229.             rsort($return['list']);
  230.         }
  231.         return $return;
  232.     }
  233.     public function paginatorBySysteme($repository,$page,$systemeClient$search null,$champTri 'id')
  234.     {
  235.         $limit 10;
  236.         $return = array('nbrPage'=>0);
  237.         $countArray $repository->findCountTotal($systemeClient);
  238.         if(!empty($countArray)) {
  239.             $count $countArray[0]['qte'];
  240.             $return['nbrPage'] = ($count/$limit)+1;
  241.         }
  242.         $return['listNumPage'] = array();
  243.         if($return['nbrPage']>10)
  244.         {
  245.             for ($i=1$i <= $return['nbrPage']; $i++ ){
  246.                 if($i<3)
  247.                 {//pour avoir les 1er
  248.                     $return['listNumPage'][$i] = $i;
  249.                 }
  250.                 if ($i > ($return['nbrPage'] - 3))
  251.                 {//pour avoir les derniers
  252.                     $return['listNumPage'][$i] = $i;
  253.                 }
  254.                 if ($i > ($page 3) && $i < ($page 3))
  255.                 {//pour avoir ceux proche de la page actuelle
  256.                     $return['listNumPage'][$i] = $i;
  257.                 }
  258.             }
  259.             //on boucle pour rajouter des ... en cas de passsage de page
  260.             $lastI 0;
  261.             foreach($return['listNumPage'] as $i => $value)
  262.             {
  263.                 if($lastI<($i-1))
  264.                 {
  265.                     $return['listNumPage'][$i] = '...';
  266.                 }
  267.                 $lastI $i;
  268.             }
  269.         }
  270.         else
  271.         {//si moins de 10 pages, on affiche tous
  272.             for ($i=1$i <= $return['nbrPage']; $i++ ){
  273.                 $return['listNumPage'][$i] = $i;
  274.             }
  275.         }
  276.         if($search != null)
  277.         {
  278.             $return['list'] = $repository->findBy(['systemeClient'=>$systemeClient,'id'=>$search], [$champTri=>'DESC'], $limit);
  279.         }
  280.         else
  281.         {
  282.             $return['list'] = $repository->findBy(['systemeClient'=>$systemeClient,], [$champTri=>'DESC'], $limit, ($limit * ($page 1)));
  283.         }
  284.         if($champTri=='id')
  285.         {
  286.             rsort($return['list']);
  287.         }
  288.         return $return;
  289.     }
  290.     public function paginatorUser($repository,$page,$systeme,$search null,$champTri 'id',$user null)
  291.     {
  292.         $limit 10;
  293.         $return = array('nbrPage'=>0);
  294.         $countArray $repository->findCountTotalBySysteme($systeme);
  295.         if(!empty($countArray)) {
  296.             $count $countArray[0]['qte'];
  297.             $return['nbrPage'] = ($count/$limit)+1;
  298.         }
  299.         $return['listNumPage'] = array();
  300.         if($return['nbrPage']>10)
  301.         {
  302.             for ($i=1$i <= $return['nbrPage']; $i++ ){
  303.                 if($i<3)
  304.                 {//pour avoir les 1er
  305.                     $return['listNumPage'][$i] = $i;
  306.                 }
  307.                 if ($i > ($return['nbrPage'] - 3))
  308.                 {//pour avoir les derniers
  309.                     $return['listNumPage'][$i] = $i;
  310.                 }
  311.                 if ($i > ($page 3) && $i < ($page 3))
  312.                 {//pour avoir ceux proche de la page actuelle
  313.                     $return['listNumPage'][$i] = $i;
  314.                 }
  315.             }
  316.             //on boucle pour rajouter des ... en cas de passsage de page
  317.             $lastI 0;
  318.             foreach($return['listNumPage'] as $i => $value)
  319.             {
  320.                 if($lastI<($i-1))
  321.                 {
  322.                     $return['listNumPage'][$i] = '...';
  323.                 }
  324.                 $lastI $i;
  325.             }
  326.         }
  327.         else
  328.         {//si moins de 10 pages, on affiche tous
  329.             for ($i=1$i <= $return['nbrPage']; $i++ ){
  330.                 $return['listNumPage'][$i] = $i;
  331.             }
  332.         }
  333.         if($search != null)
  334.         {
  335.             if($user->getRoleExpl())
  336.             {//si exploit recherchant un user
  337.                 $return['list'] = $repository->findWithCriteria($systeme,$search1$champTri$limit1"ROLE_CHAUFFEUR");
  338.             }
  339.             else
  340.             {//si autre recherchant un user
  341.                 $return['list'] = $repository->findWithCriteria($systeme,$searchnull$champTri$limit1);
  342.             }
  343.         }
  344.         else
  345.         {
  346.             if($user->getRoleExpl())
  347.             {//si exploit
  348.                 $return['list'] = $repository->findWithCriteria($systeme,null1$champTri$limit$page"ROLE_CHAUFFEUR");
  349.             }
  350.             else
  351.             {//si other admin
  352.                 $return['list'] = $repository->findWithCriteria($systemenull,null$champTri$limit$page);
  353.             }
  354.         }
  355.         if($champTri=='id')
  356.         {
  357.             rsort($return['list']);
  358.         }
  359.         return $return;
  360.     }
  361.     public function paginatorAbsence($repository,$page,$search null,$champTri 'id')
  362.     {
  363.         $limit 10;
  364.         $return = array('nbrPage'=>0);
  365.         $countArray $repository->findCountTotal();
  366.         if(!empty($countArray)) {
  367.             $count $countArray[0]['qte'];
  368.             $return['nbrPage'] = ($count/$limit)+1;
  369.         }
  370.         $return['listNumPage'] = array();
  371.         if($return['nbrPage']>10)
  372.         {
  373.             for ($i=1$i <= $return['nbrPage']; $i++ ){
  374.                 if($i<3)
  375.                 {//pour avoir les 1er
  376.                     $return['listNumPage'][$i] = $i;
  377.                 }
  378.                 if ($i > ($return['nbrPage'] - 3))
  379.                 {//pour avoir les derniers
  380.                     $return['listNumPage'][$i] = $i;
  381.                 }
  382.                 if ($i > ($page 3) && $i < ($page 3))
  383.                 {//pour avoir ceux proche de la page actuelle
  384.                     $return['listNumPage'][$i] = $i;
  385.                 }
  386.             }
  387.             //on boucle pour rajouter des ... en cas de passsage de page
  388.             $lastI 0;
  389.             foreach($return['listNumPage'] as $i => $value)
  390.             {
  391.                 if($lastI<($i-1))
  392.                 {
  393.                     $return['listNumPage'][$i] = '...';
  394.                 }
  395.                 $lastI $i;
  396.             }
  397.         }
  398.         else
  399.         {//si moins de 10 pages, on affiche tous
  400.             for ($i=1$i <= $return['nbrPage']; $i++ ){
  401.                 $return['listNumPage'][$i] = $i;
  402.             }
  403.         }
  404.         if($search != null)
  405.         {
  406.             $return['list'] = $repository->findBy(['user'=>$search], [$champTri=>'DESC'], $limit);
  407.         }
  408.         else
  409.         {
  410.             $return['list'] = $repository->findBy([], [$champTri=>'DESC'], $limit, ($limit * ($page 1)));
  411.         }
  412.         if($champTri=='id')
  413.         {
  414.             rsort($return['list']);
  415.         }
  416.         return $return;
  417.     }
  418.     public function paginatorLavage($repository,$page,$systeme,$search null,$champTri 'id')
  419.     {
  420.         $limit 10;
  421.         $return = array('nbrPage'=>0);
  422.         $countArray $repository->findCountTotalClient($systeme->getId());
  423.         //$countArray = $repository->findCountTotal();
  424.         if(!empty($countArray)) {
  425.             $count $countArray[0]['qte'];
  426.             $return['nbrPage'] = ($count/$limit)+1;
  427.         }
  428.         if($search != null)
  429.         {
  430.             $return['list'] = $repository->findBy(['remorque'=>$search], [$champTri=>'DESC'], $limit);
  431.             $count count($repository->findBy(['remorque'=>$search]));
  432.             $return['nbrPage'] = ($count/$limit)+1;
  433.         }
  434.         else
  435.         {
  436.             $return['list'] = $repository->findBy(['systemeClient'=>$systeme], [$champTri=>'DESC'], $limit, ($limit * ($page 1)));
  437.         }
  438.         $return['listNumPage'] = array();
  439.         if($return['nbrPage']>10)
  440.         {
  441.             for ($i=1$i <= $return['nbrPage']; $i++ ){
  442.                 if($i<3)
  443.                 {//pour avoir les 1er
  444.                     $return['listNumPage'][$i] = $i;
  445.                 }
  446.                 if ($i > ($return['nbrPage'] - 3))
  447.                 {//pour avoir les derniers
  448.                     $return['listNumPage'][$i] = $i;
  449.                 }
  450.                 if ($i > ($page 3) && $i < ($page 3))
  451.                 {//pour avoir ceux proche de la page actuelle
  452.                     $return['listNumPage'][$i] = $i;
  453.                 }
  454.             }
  455.             //on boucle pour rajouter des ... en cas de passsage de page
  456.             $lastI 0;
  457.             foreach($return['listNumPage'] as $i => $value)
  458.             {
  459.                 if($lastI<($i-1))
  460.                 {
  461.                     $return['listNumPage'][$i] = '...';
  462.                 }
  463.                 $lastI $i;
  464.             }
  465.         }
  466.         else
  467.         {//si moins de 10 pages, on affiche tous
  468.             for ($i=1$i <= $return['nbrPage']; $i++ ){
  469.                 $return['listNumPage'][$i] = $i;
  470.             }
  471.         }
  472.         if($champTri=='id')
  473.         {
  474.             rsort($return['list']);
  475.         }
  476.         return $return;
  477.     }
  478.     public function paginatorActif($repository,$page,$search null,$actif=1,$champTri 'id')
  479.     {
  480.         $limit 10;
  481.         $return = array('nbrPage'=>0);
  482.         $countArray $repository->findCountTotal();
  483.         if(!empty($countArray)) {
  484.             $count $countArray[0]['qte'];
  485.             $return['nbrPage'] = ($count/$limit)+1;
  486.         }
  487.         $return['listNumPage'] = array();
  488.         if($return['nbrPage']>10)
  489.         {
  490.             for ($i=1$i <= $return['nbrPage']; $i++ ){
  491.                 if($i<3)
  492.                 {//pour avoir les 1er
  493.                     $return['listNumPage'][$i] = $i;
  494.                 }
  495.                 if ($i > ($return['nbrPage'] - 3))
  496.                 {//pour avoir les derniers
  497.                     $return['listNumPage'][$i] = $i;
  498.                 }
  499.                 if ($i > ($page 3) && $i < ($page 3))
  500.                 {//pour avoir ceux proche de la page actuelle
  501.                     $return['listNumPage'][$i] = $i;
  502.                 }
  503.             }
  504.             //on boucle pour rajouter des ... en cas de passsage de page
  505.             $lastI 0;
  506.             foreach($return['listNumPage'] as $i => $value)
  507.             {
  508.                 if($lastI<($i-1))
  509.                 {
  510.                     $return['listNumPage'][$i] = '...';
  511.                 }
  512.                 $lastI $i;
  513.             }
  514.         }
  515.         else
  516.         {//si moins de 10 pages, on affiche tous
  517.             for ($i=1$i <= $return['nbrPage']; $i++ ){
  518.                 $return['listNumPage'][$i] = $i;
  519.             }
  520.         }
  521.         if($search != null)
  522.         {
  523.             $return['list'] = $repository->findBy([$champTri=>$search,'actif'=>$actif], ['id'=>'DESC'], $limit, ($limit * ($page 1)));
  524.         }
  525.         else
  526.         {
  527.             $return['list'] = $repository->findBy(['actif'=>$actif], [$champTri=>'DESC'], $limit, ($limit * ($page 1)));
  528.         }
  529.         if($champTri=='id')
  530.         {
  531.             rsort($return['list']);
  532.         }
  533.         return $return;
  534.     }
  535.     public function paginatorClient($repository,$page,$systeme,$search null,$champTri 'id')
  536.     {
  537.         $limit 10;
  538.         $return = array('nbrPage'=>0);
  539.         $countArray $repository->findCountTotalClient($systeme);
  540.         if(!empty($countArray)) {
  541.             $count $countArray[0]['qte'];
  542.             $return['nbrPage'] = ($count/$limit)+1;
  543.         }
  544.         $return['listNumPage'] = array();
  545.         if($return['nbrPage']>10)
  546.         {
  547.             for ($i=1$i <= $return['nbrPage']; $i++ ){
  548.                 if($i<3)
  549.                 {//pour avoir les 1er
  550.                     $return['listNumPage'][$i] = $i;
  551.                 }
  552.                 if ($i > ($return['nbrPage'] - 3))
  553.                 {//pour avoir les derniers
  554.                     $return['listNumPage'][$i] = $i;
  555.                 }
  556.                 if ($i > ($page 3) && $i < ($page 3))
  557.                 {//pour avoir ceux proche de la page actuelle
  558.                     $return['listNumPage'][$i] = $i;
  559.                 }
  560.             }
  561.             //on boucle pour rajouter des ... en cas de passsage de page
  562.             $lastI 0;
  563.             foreach($return['listNumPage'] as $i => $value)
  564.             {
  565.                 if($lastI<($i-1))
  566.                 {
  567.                     $return['listNumPage'][$i] = '...';
  568.                 }
  569.                 $lastI $i;
  570.             }
  571.         }
  572.         else
  573.         {//si moins de 10 pages, on affiche tous
  574.             for ($i=1$i <= $return['nbrPage']; $i++ ){
  575.                 $return['listNumPage'][$i] = $i;
  576.             }
  577.         }
  578.         if($search != null)
  579.         {
  580.             $return['list'] = $repository->findBy(['id'=>$search], [$champTri=>'DESC'], $limit);
  581.         }
  582.         else
  583.         {
  584.             $return['list'] = $repository->findBy(['systemeClient'=>$systeme], [$champTri=>'DESC'], $limit, ($limit * ($page 1)));
  585.         }
  586.         if($champTri=='id')
  587.         {
  588.             rsort($return['list']);
  589.         }
  590.         return $return;
  591.     }
  592.     public function paginatorPanne($repository$page$filters = [], $champTri 'id',$dateDebut$dateFin)
  593.     {
  594.         $limit 10;
  595.         $return = array('nbrPage' => 0);
  596.         // Count total
  597.         $countArray $repository->findCountTotalWithDate($filters,$dateDebut$dateFin);
  598.         if(!empty($countArray)) {
  599.             $count $countArray[0]['qte'];
  600.             $return['nbrPage'] = ceil($count $limit);
  601.         }
  602.         $return['listNumPage'] = [];
  603.         if($return['nbrPage'] > 10)
  604.         {
  605.             for ($i 1$i <= $return['nbrPage']; $i++) {
  606.                 if($i 3)
  607.                     $return['listNumPage'][$i] = $i;
  608.                 if ($i > ($return['nbrPage'] - 3))
  609.                     $return['listNumPage'][$i] = $i;
  610.                 if ($i > ($page 3) && $i < ($page 3))
  611.                     $return['listNumPage'][$i] = $i;
  612.             }
  613.             $lastI 0;
  614.             foreach($return['listNumPage'] as $i => $value)
  615.             {
  616.                 if($lastI < ($i 1))
  617.                     $return['listNumPage'][$i] = '...';
  618.                 $lastI $i;
  619.             }
  620.         }
  621.         else
  622.         {
  623.             for ($i 1$i <= $return['nbrPage']; $i++) {
  624.                 $return['listNumPage'][$i] = $i;
  625.             }
  626.         }
  627.         // Fetch list
  628.         $return['list'] = $repository->findBy(
  629.             $filters,
  630.             [$champTri => 'DESC'],
  631.             $limit,
  632.             ($limit * ($page 1))
  633.         );
  634.         // Fetch list
  635.         $return['list'] = $repository->findWithFilters(
  636.             $filters,
  637.             $dateDebut,
  638.             $dateFin,
  639.             $limit,
  640.             ($limit * ($page 1))
  641.         );
  642.         return $return;
  643.     }
  644.     function ecart_type ($donnees) {
  645.         //0 - Nombre d’éléments dans le tableau
  646.         $population count($donnees);
  647.         if ($population != 0) {
  648.             //1 - somme du tableau
  649.             $somme_tableau array_sum($donnees);
  650.             //2 - Calcul de la moyenne
  651.             $moyenne $somme_tableau $population;
  652.             //3 - écart pour chaque valeur
  653.             $ecart = [];
  654.             for ($i 0$i $population$i++){
  655.                 //écart entre la valeur et la moyenne
  656.                 $ecart_donnee $donnees[$i] - $moyenne;
  657.                 //carré de l'écart
  658.                 //$ecart_donnee_carre = \bcpow($ecart_donnee, 2, 2);
  659.                 $ecart_donnee_carre $ecart_donnee $ecart_donnee// Equivalent to $ecart_donnee^2
  660.                 //Insertion dans le tableau
  661.                 array_push($ecart$ecart_donnee_carre);
  662.             }
  663.             //4 - somme des écarts
  664.             $somme_ecart array_sum($ecart);
  665.             //5 - division de la somme des écarts par la population
  666.             $division $somme_ecart $population;
  667.             //6 - racine carrée de la division
  668.             //$ecart_type = bcsqrt ($division, 2);
  669.             $ecart_type round(sqrt($division), 2);
  670.         } else {
  671.             $ecart_type "Le tableau est vide";
  672.         }
  673.         //7 - renvoi du résultat
  674.         return $ecart_type;
  675.     }
  676.     /*
  677.      * fonction qui range un tableau multidimensionnel par ordre croissant par rapport � une de ces dimensions
  678.      * @author JM
  679.      */
  680.     public static function array_msort($array$cols)
  681.     {
  682.         $colarr = array();
  683.         foreach ($cols as $col => $order) {
  684.             $colarr[$col] = array();
  685.             foreach ($array as $k => $row) {
  686.                 $colarr[$col]['_'.$k] = strtolower($row[$col]); }
  687.         }
  688.         $eval 'array_multisort(';
  689.         foreach ($cols as $col => $order) {
  690.             $eval .= '$colarr[\''.$col.'\'],'.$order.',';
  691.         }
  692.         $eval substr($eval,0,-1).');';
  693.         eval($eval);
  694.         $ret = array();
  695.         foreach ($colarr as $col => $arr) {
  696.             foreach ($arr as $k => $v) {
  697.                 $k substr($k,1);
  698.                 if (!isset($ret[$k])) $ret[$k] = $array[$k];
  699.                 $ret[$k][$col] = $array[$k][$col];
  700.             }
  701.         }
  702.         return $ret;
  703.     }
  704.     public function dateFRversUS($dateFr)
  705.     {
  706.         $dateUS $dateFr;
  707.         $explod explode('/',$dateFr);
  708.         if(count($explod)>1)
  709.         {
  710.             $dateUS $explod[2].'-'.$explod[1].'-'.$explod[0];
  711.         }
  712.         return $dateUS;
  713.     }
  714.     public function paginatorType($repository,$page,$search null)
  715.     {
  716.         $limit 10;
  717.         $return = array('nbrPage'=>0);
  718.         $countArray $repository->findCountTotal();
  719.         if(!empty($countArray)) {
  720.             $count $countArray[0]['qte'];
  721.             $return['nbrPage'] = ($count/$limit)+1;
  722.         }
  723.         $return['listNumPage'] = array();
  724.         if($return['nbrPage']>10)
  725.         {
  726.             for ($i=1$i <= $return['nbrPage']; $i++ ){
  727.                 if($i<3)
  728.                 {//pour avoir les 1er
  729.                     $return['listNumPage'][$i] = $i;
  730.                 }
  731.                 if ($i > ($return['nbrPage'] - 3))
  732.                 {//pour avoir les derniers
  733.                     $return['listNumPage'][$i] = $i;
  734.                 }
  735.                 if ($i > ($page 3) && $i < ($page 3))
  736.                 {//pour avoir ceux proche de la page actuelle
  737.                     $return['listNumPage'][$i] = $i;
  738.                 }
  739.             }
  740.             //on boucle pour rajouter des ... en cas de passsage de page
  741.             $lastI 0;
  742.             foreach($return['listNumPage'] as $i => $value)
  743.             {
  744.                 if($lastI<($i-1))
  745.                 {
  746.                     $return['listNumPage'][$i] = '...';
  747.                 }
  748.                 $lastI $i;
  749.             }
  750.         }
  751.         else
  752.         {//si moins de 10 pages, on affiche tous
  753.             for ($i=1$i <= $return['nbrPage']; $i++ ){
  754.                 $return['listNumPage'][$i] = $i;
  755.             }
  756.         }
  757.         if($search != null)
  758.         {
  759.             $return['list'] = $repository->findBy(['type'=>$search], ['id'=>'DESC'], $limit);
  760.         }
  761.         else
  762.         {
  763.             $return['list'] = $repository->findBy([], ['id'=>'DESC'], $limit, ($limit * ($page 1)));
  764.         }
  765.         rsort($return['list']);
  766.         return $return;
  767.     }
  768.     public function getNameDay($jour)
  769.     {
  770.         $string "";
  771.         if($jour==1)
  772.         {
  773.             $string "Lundi";
  774.         }
  775.         else if($jour==2)
  776.         {
  777.             $string "Mardi";
  778.         }
  779.         else if($jour==3)
  780.         {
  781.             $string "Mercredi";
  782.         }
  783.         else if($jour==4)
  784.         {
  785.             $string "Jeudi";
  786.         }
  787.         else if($jour==5)
  788.         {
  789.             $string "Vendredi";
  790.         }
  791.         else if($jour==6)
  792.         {
  793.             $string "Samedi";
  794.         }
  795.         else if($jour==0)
  796.         {
  797.             $string "Dimanche";
  798.         }
  799.         else if($jour==7)
  800.         {
  801.             $string "Dimanche";
  802.         }
  803.         return $string;
  804.     }
  805.     public function addHeure($totalHM,$heureHM)
  806.     {
  807.         $total explode(':',$totalHM);
  808.         $heureMin explode(':',$heureHM);
  809.         if(count($total)==2)
  810.         {
  811.             $heure $total[0];
  812.             $minute $total[1];
  813.         }
  814.         if(count($total)==&& count($heureMin)==2)
  815.         {
  816.             $heure $total[0]+$heureMin[0];
  817.             $minute $total[1]+$heureMin[1];
  818.             if($minute>59)
  819.             {
  820.                 $heure++;
  821.                 $minute-=60;
  822.             }
  823.             if($minute<10)
  824.             {
  825.                 $minute '0'.$minute;
  826.             }
  827.         }
  828.         return $heure.':'.$minute;
  829.     }
  830.     public function moisMoins1($mois,$annee)
  831.     {
  832.         $mois--;
  833.         if($mois==0)
  834.         {
  835.             $mois 12;
  836.             $annee--;
  837.         }
  838.         return array('annee'=>$annee,'mois'=>$mois);
  839.     }
  840.     public function moisPlus1($mois,$annee)
  841.     {
  842.         $mois++;
  843.         if($mois==13)
  844.         {
  845.             $mois 1;
  846.             $annee++;
  847.         }
  848.         return array('annee'=>$annee,'mois'=>$mois);
  849.     }
  850.     public function convertionHeureEnMinute($heureHM)
  851.     {
  852.         $heurDeci 0;
  853.         $heureMin explode(':',$heureHM);
  854.         if(count($heureMin)==2) {
  855.             $heurDeci = ($heureMin[0]*60)+$heureMin[1];
  856.         }
  857.         return floatval($heurDeci);
  858.     }
  859.     public function convertionHeureDecimal($heureHM)
  860.     {
  861.         $heurDeci 0;
  862.         $heureMin explode(':',$heureHM);
  863.         if(count($heureMin)==2) {
  864.             $heurDeci $heureMin[0].'.'.round((($heureMin[1]/60)*100),2);
  865.         }
  866.         return floatval($heurDeci);
  867.     }
  868.     public function convertionMinuteToHeure($decimal)
  869.     {
  870.         $min 0;
  871.         $heure 0;
  872.         if($decimal>0) {
  873.             $min $decimal 60;
  874.             $heure floor($decimal 60);
  875.         }
  876.         return ($heure<10?'0'.$heure:$heure).':'.($min<10?'0'.$min:$min);
  877.     }
  878.     public function convertionMinuteToHeureFormatH($decimal)
  879.     {
  880.         $min 0;
  881.         $heure 0;
  882.         if($decimal>0) {
  883.             $min $decimal 60;
  884.             $heure floor($decimal 60);
  885.         }
  886.         return ($heure<10?'0'.$heure:$heure).'h'.($min<10?'0'.$min:$min);
  887.     }
  888.     public function convertionDecimalToDateTime($decimal)
  889.     {
  890.         $dateTimeHM null;
  891.         $value str_replace(',''.'$decimal); // Convert comma to dot for float parsing
  892.         $decimal = (float)$value;
  893.         $hours = (int)$decimal// 0
  894.         $minutes = ($decimal $hours) * 60// 0.017 * 60 = ~1.02
  895.         $minutes round($minutes); // Round if needed
  896.         if(is_numeric($hours) && is_numeric($minutes))
  897.         {
  898.             $dateTimeHM = new \DateTime($hours.':'.$minutes);
  899.         }
  900.         return $dateTimeHM;
  901.     }
  902.     public function convertionDecimalToDateTimePlus24H($decimal): string
  903.     {
  904.         $value str_replace(',''.'$decimal); // Convert comma to dot
  905.         $decimal = (float)$value;
  906.         $hours = (int)$decimal;
  907.         $minutes round(($decimal $hours) * 60);
  908.         // Always return in H:MM format
  909.         return sprintf("%d:%02d"$hours$minutes);
  910.     }
  911.     public function calculHeureDeNuitEnMinute($heure_debut,$heure_fin)
  912.     {
  913. // Convertir en objets DateTime
  914.         $debut \DateTime::createFromFormat('H:i:s'$heure_debut);
  915.         $fin \DateTime::createFromFormat('H:i:s'$heure_fin);
  916. // Heure à laquelle commence la nuit (par exemple, 20:00)
  917.         $heure_debut_nuit \DateTime::createFromFormat('H:i:s''21:00:00');
  918. // Heure à laquelle se termine la nuit (par exemple, 6:00)
  919.         $heure_fin_nuit \DateTime::createFromFormat('H:i:s''06:00:00')->modify('+1 day');
  920. // Vérifier si l'heure de fin est avant l'heure de début
  921.         if ($fin $debut) {
  922.             $fin->modify('+1 day'); // Ajouter un jour si l'heure de fin est le lendemain
  923.         }
  924.         if($debut->format('H')<6)
  925.         {
  926.             $heure_debut_nuit->modify('-1 day');
  927.             $heure_fin_nuit->modify('-1 day');
  928.         }
  929. /*var_dump($debut);
  930. var_dump($fin);
  931. var_dump($heure_debut_nuit);
  932. var_dump($heure_fin_nuit);*/
  933. // Calculer la durée de la nuit
  934.         $duree_nuit null;
  935.         if ($debut $heure_debut_nuit && $fin $heure_fin_nuit) {
  936.             $duree_nuit $heure_fin_nuit->diff($heure_debut_nuit);//echo "A--";
  937.         } elseif ($debut >= $heure_debut_nuit && $fin <= $heure_fin_nuit) {//echo "B--";
  938.             $duree_nuit $fin->diff($debut);
  939.         } elseif ($debut $heure_debut_nuit && $fin >= $heure_debut_nuit &&  $fin <= $heure_fin_nuit) {//echo "C--";
  940.             $duree_nuit $fin->diff($heure_debut_nuit);
  941.         } elseif ($debut >= $heure_debut_nuit && $fin $heure_fin_nuit) {//echo "D--";
  942.             $duree_nuit $heure_fin_nuit->diff($debut);
  943.         }
  944.         $minutes 0;
  945.         if($duree_nuit!=null)
  946.         {
  947.             $minutes = ($duree_nuit->format('%H')*60)+$duree_nuit->format('%I');
  948.         }
  949.         //echo $heure_debut.' '.$heure_fin.' '.$minutes.'<br />';
  950.         return $minutes;
  951.     }
  952.     public function dateExcel($excelDate)
  953.     {
  954.         $unixTimestamp = ($excelDate 25569) * 86400;
  955.         // Adjust for Excel's leap year bug (1900 is incorrectly treated as a leap year)
  956.         if ($excelDate 60) {
  957.             $unixTimestamp -= 86400// Subtract one day
  958.         }
  959.         // Format the timestamp as 'Y-m-d H:i:s'
  960.         $formattedDate gmdate('Y-m-d H:i:s'$unixTimestamp);
  961.         return $formattedDate;
  962.     }
  963.     function getWeeksOfHalfYear($year$half 1) {
  964.         $weeks = [];
  965.         $startMonth = ($half === 1) ? 7// January for first half, July for second half
  966.         $endMonth = ($half === 1) ? 12// June for first half, December for second half
  967.         // Iterate through the months in the selected half
  968.         for ($month $startMonth$month <= $endMonth$month++) {
  969.             // Get the first and last day of the month
  970.             $firstDayOfMonth = new \DateTime("$year-$month-01");
  971.             $lastDayOfMonth = (clone $firstDayOfMonth)->modify('last day of this month');
  972.             // Loop through the weeks of this month
  973.             $currentDate = clone $firstDayOfMonth;
  974.             while ($currentDate <= $lastDayOfMonth) {
  975.                 $weekNumber $currentDate->format('W'); // Get the week number
  976.                 $weekStart = (clone $currentDate)->modify('monday this week')->format('Y-m-d');
  977.                 $weekEnd = (clone $currentDate)->modify('sunday this week')->format('Y-m-d');
  978.                 // Add the week to the list if it hasn't been added yet
  979.                 if (!isset($weeks[$weekNumber])) {
  980.                     $weeks[$weekNumber] = [
  981.                         'week' => $weekNumber,
  982.                         'start' => $weekStart,
  983.                         'end' => $weekEnd
  984.                     ];
  985.                 }
  986.                 // Move to the next week
  987.                 $currentDate->modify('+7 days');
  988.             }
  989.         }
  990.         /*if($half==2)
  991.         {
  992.             $lastDayOfYear = new \DateTime("$year-12-31");
  993.             $lastWeekNumber = $lastDayOfYear->format('W');
  994.             $weekStart = (clone $lastDayOfYear)->modify('monday this week')->format('Y-m-d');
  995.             if (!isset($weeks[$lastWeekNumber])) {
  996.                 $weeks[$lastWeekNumber] = [
  997.                     'week' => $lastWeekNumber,
  998.                     'start' => $weekStart,
  999.                     'end' => $lastDayOfYear
  1000.                 ];
  1001.             }
  1002.         }*/
  1003.         return $weeks;
  1004.     }
  1005.     function getFortnightRange(\DateTime $date): array {
  1006.         $year = (int)$date->format("Y");
  1007.         $month = (int)$date->format("m");
  1008.         $day = (int)$date->format("d");
  1009.         // First fortnight: 1st to 15th
  1010.         $firstStart = new \DateTime("$year-$month-01");
  1011.         $firstEnd = new \DateTime("$year-$month-15");
  1012.         // Second fortnight: 16th to last day of the month
  1013.         $secondStart = new \DateTime("$year-$month-16");
  1014.         $lastDay = (int)$date->format("t"); // Get last day of the month
  1015.         $secondEnd = new \DateTime("$year-$month-$lastDay");
  1016.         // Determine which fortnight the given date falls in
  1017.         if ($day <= 15) {
  1018.             return [
  1019.                 'start' => $firstStart->format("Y-m-d"),
  1020.                 'end' => $firstEnd->format("Y-m-d")
  1021.             ];
  1022.         } else {
  1023.             return [
  1024.                 'start' => $secondStart->format("Y-m-d"),
  1025.                 'end' => $secondEnd->format("Y-m-d")
  1026.             ];
  1027.         }
  1028.     }
  1029.     function normalizeString($string) {
  1030.         // Replace common accented characters manually
  1031.         $replacements = [
  1032.             'à' => 'a''á' => 'a''â' => 'a''ä' => 'a''ã' => 'a''å' => 'a',
  1033.             'è' => 'e''é' => 'e''ê' => 'e''ë' => 'e',
  1034.             'ì' => 'i''í' => 'i''î' => 'i''ï' => 'i',
  1035.             'ò' => 'o''ó' => 'o''ô' => 'o''ö' => 'o''õ' => 'o',
  1036.             'ù' => 'u''ú' => 'u''û' => 'u''ü' => 'u',
  1037.             'ç' => 'c''ñ' => 'n',
  1038.             'À' => 'A''Á' => 'A''Â' => 'A''Ä' => 'A''Ã' => 'A''Å' => 'A',
  1039.             'È' => 'E''É' => 'E''Ê' => 'E''Ë' => 'E',
  1040.             'Ì' => 'I''Í' => 'I''Î' => 'I''Ï' => 'I',
  1041.             'Ò' => 'O''Ó' => 'O''Ô' => 'O''Ö' => 'O''Õ' => 'O',
  1042.             'Ù' => 'U''Ú' => 'U''Û' => 'U''Ü' => 'U',
  1043.             'Ç' => 'C''Ñ' => 'N',
  1044.         ];
  1045.         $string strtr($string$replacements);
  1046.         return strtoupper($string);
  1047.     }
  1048.     function timeToSeconds($time) {
  1049.         list($h$m$s) = explode(':'$time);
  1050.         return ($h 3600) + ($m 60) + $s;
  1051.     }
  1052.     function secondsToTime($seconds) {
  1053.         $h floor($seconds 3600);
  1054.         $m floor(($seconds 3600) / 60);
  1055.         //$s = $seconds % 60;
  1056.         return sprintf('%02d:%02d'$h$m);
  1057.     }
  1058. }