src/Controller/Api/Prive/ApiStatistiqueController.php line 42

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Api\Prive;
  3. use App\Entity\Appel;
  4. use App\Entity\Appelstatut;
  5. use App\Entity\Campagne;
  6. use App\Entity\Campagneprospect;
  7. use App\Entity\Client;
  8. use App\Entity\Codenaf;
  9. use App\Entity\Contact;
  10. use App\Entity\Prospect;
  11. use App\Entity\Rdv;
  12. use App\Entity\Rdvstatut;
  13. use App\Entity\Utilisateur;
  14. use App\Entity\Ville;
  15. use Symfony\Component\HttpFoundation\JsonResponse;
  16. use Symfony\Component\HttpFoundation\Request;
  17. use Symfony\Component\Routing\Annotation\Route;
  18. /**
  19.  * @Route("/statistique")
  20.  */
  21. class ApiStatistiqueController extends ApiController
  22. {
  23.    
  24.     /**
  25.      * @Route("/appelparstatut", name="api_Statistique_appelparstatut", methods={"POST"})
  26.      * @param Request $request
  27.      * @return JsonResponse
  28.      */
  29.     public function appelparstatut(Request $request)
  30.     {
  31.         $data = json_decode($request->getContent(), true);
  32.         $date = date("Ymd", strtotime("-30 days", strtotime(date("Ymd"))));
  33.         $where = " WHERE appel.dateappel >= ".$date;
  34.             if (isset($data['params']['collaborateurId'])) {
  35.                 $where .=  ' AND appel.utilisateur='.$data['params']['collaborateurId'];
  36.             }else {
  37.                 if (isset($data['params']['espaceagent']) && $data['params']['espaceagent']) {
  38.                     $where .=  ' AND appel.utilisateur='.$this->getUtilisateurConnecte()->getId();
  39.                 }
  40.             }
  41.         $sql = "
  42.                 SELECT       
  43.                 DATE_FORMAT(appel.dateappel, '%d/%m/%Y') AS jour,
  44.                 appelstatut.libelle AS statutappel,
  45.                 appelstatut.couleur AS couleurstatut,                
  46.                 count(appel.id) AS nombreappel    
  47.                 FROM ".Appel::class." AS appel
  48.                 LEFT JOIN ".Appelstatut::class." as appelstatut WITH appel.appelstatut = appelstatut.id
  49.                 LEFT JOIN ".Campagneprospect::class." AS campagneprospect WITH appel.campagneprospect = campagneprospect.id
  50.                 LEFT JOIN ".Campagne::class." AS campagne WITH campagneprospect.campagne = campagne.id
  51.                 LEFT JOIN ".Client::class." AS client WITH campagne.client = client.id
  52.                 ".$where."
  53.                 AND (appel.sourceouverture IS NULL OR appel.sourceouverture <> '".Appel::SOURCE_REQUALIFICATION_RESPONSABLE."')
  54.                 GROUP BY jour, statutappel
  55.                 ORDER BY appel.dateappel asc
  56.                 ";
  57.         $query = $this->em->createQuery($sql);
  58.         $reponse = $query->getResult();
  59.         return $this->apiOk($reponse);
  60.     }
  61.     /**
  62.      * @Route("/campagneparstatut/{id}", name="api_Statistique_campagneparstatut", methods={"GET"})
  63.      * @param int $id
  64.      * @return JsonResponse
  65.      */
  66.     public function campagneparstatut(int $id)
  67.     {
  68.         if ($id == null || $id <= 0) {
  69.             return $this->apiKo("Campagne non-trouvĂ©e !");
  70.         }
  71.         $where = "WHERE campagneprospect.campagne = ".$id ;
  72.         $sql = "
  73.                 SELECT 
  74.                 (case when appelstatut.couleur IS NULL then '#7c65ad' ELSE appelstatut.couleur END) AS couleurstatut ,
  75.                 (case when appelstatut.libelle IS NULL then 'Pas encore contactĂ©' ELSE appelstatut.libelle END) AS statutappel ,
  76.                 COUNT(campagneprospect.id) AS nombreprospect
  77.                 FROM
  78.                 ".Campagneprospect::class." AS campagneprospect
  79.                 LEFT join ".Appelstatut::class." AS appelstatut WITH appelstatut.id = campagneprospect.appelstatut
  80.                 ".$where."
  81.                 GROUP BY appelstatut.libelle, appelstatut.couleur
  82.                 ";
  83.         $query = $this->em->createQuery($sql);
  84.         $reponse = $query->getResult();
  85.         return $this->apiOk($reponse);
  86.     }
  87.     /**
  88.      * @Route("/avancementcampagneappel", name="api_Statistique_avancementcampagneappel", methods={"POST"})
  89.      * @param Request $request
  90.      * @return JsonResponse
  91.      */
  92.     public function avancementcampagneappel(Request $request)
  93.     {
  94.         $data = json_decode($request->getContent(), true);
  95.         $where = $this->paramstowhere($data);
  96.         $sql = "SELECT
  97.                 (case when campagneprospect.traitementpar IS NULL then 'NON' ELSE 'OUI' END) AS estcontacte,
  98.                 COUNT(campagneprospect.id) AS nombreprospect
  99.                 FROM
  100.                 ".Campagneprospect::class." AS campagneprospect
  101.                 ".$where."
  102.                 GROUP BY estcontacte
  103.                 ";
  104.         $query = $this->em->createQuery($sql);
  105.         $reponse = $query->getResult();
  106.         return $this->apiOk($reponse);
  107.     }
  108.     /**
  109.      * @Route("/avancementcampagneobjectif", name="api_Statistique_avancementcampagneobjectif", methods={"POST"})
  110.      * @param Request $request
  111.      * @return JsonResponse
  112.      */
  113.     public function avancementcampagneobjectif(Request $request)
  114.     {
  115.         $data = json_decode($request->getContent(), true);
  116.         $where = $this->paramstowhere($data);
  117.         $sql = "SELECT
  118.                 campagne.id AS idcampagne,
  119.                 campagne.objectif AS totalarealiser,
  120.                 COUNT(rdv.id) AS totalrealise
  121.                 FROM
  122.                 ".Rdv::class." AS rdv
  123.                 LEFT JOIN ".Rdvstatut::class." AS rdvstatut WITH rdv.rdvstatut = rdvstatut.id
  124.                 LEFT JOIN ".Campagne::class." AS campagne WITH rdv.campagne = campagne.id
  125.                 ".$where."
  126.                 GROUP BY campagne.id";
  127.         $query = $this->em->createQuery($sql);
  128.         $reponse = $query->getResult();
  129.         return $this->apiOk($reponse);
  130.     }
  131.    /**
  132.      * @Route("/collaborateurappelstatut", name="api_Statistique_collaborateurappelstatut", methods={"POST"})
  133.      * @param Request $request
  134.      * @return JsonResponse
  135.      */
  136.     public function collaborateurappelstatut(Request $request)
  137.     {
  138.         $data = json_decode($request->getContent(), true);
  139.         $where = $this->paramstowhere($data);
  140.         $sql = "SELECT
  141.                 CASE WHEN utilisateur.id IS NULL then 0 ELSE utilisateur.id end AS idcollaborateur , 
  142.                 CASE WHEN utilisateur.id IS NULL then 'PAS ENCORE AFFECTE' ELSE UPPER(concat(utilisateur.nom,' ',utilisateur.prenom)) end AS collaborateur , 
  143.                 CASE WHEN appelstatut.id IS NULL then 0 ELSE appelstatut.id end AS idappelstatut ,
  144.                 CASE WHEN appelstatut.id IS NULL then 'PAS ENCORE APPELE' ELSE UPPER(appelstatut.libelle) end AS statut ,
  145.                 COUNT(campagneprospect.id) AS nombreprospect
  146.                 FROM 
  147.                 ".Campagneprospect::class." AS campagneprospect
  148.                 LEFT JOIN ".Utilisateur::class." AS utilisateur WITH campagneprospect.traitementpar = utilisateur.id
  149.                 LEFT JOIN ".Appelstatut::class." AS appelstatut WITH campagneprospect.appelstatut = appelstatut.id
  150.                 ".$where."
  151.                 GROUP BY utilisateur.id,appelstatut.id";
  152.         $query = $this->em->createQuery($sql);
  153.         $reponse = $query->getResult();
  154.         return $this->apiOk($reponse);
  155.     }
  156.     /**
  157.      * @Route("/previsionrappel", name="api_Statistique_previsionrappel", methods={"POST"})
  158.      * @param Request $request
  159.      * @return JsonResponse
  160.      */
  161.     public function previsionrappel(Request $request)
  162.     {
  163.         $data = json_decode($request->getContent(), true);
  164.         $where = $this->paramstowhere($data);
  165.         // Rappels passĂ©s
  166.         $sql0 = "SELECT
  167.                 'Rappels ratĂ©s' AS periode,
  168.                 COUNT(campagneprospect.id) AS nombre
  169.                 FROM 
  170.                 ".Campagneprospect::class." AS campagneprospect
  171.                 LEFT JOIN ".Appelstatut::class." AS appelstatut WITH campagneprospect.appelstatut = appelstatut.id
  172.                 ".$where."
  173.                 AND appelstatut.rappel=TRUE AND campagneprospect.daterappel < now()
  174.                 GROUP BY periode
  175.                 ";
  176.         $sql0_ids = "SELECT distinct 
  177.                 campagneprospect.id AS ids
  178.                 FROM 
  179.                 ".Campagneprospect::class." AS campagneprospect
  180.                 LEFT JOIN ".Appelstatut::class." AS appelstatut WITH campagneprospect.appelstatut = appelstatut.id
  181.                 ".$where."
  182.                 AND appelstatut.rappel=TRUE AND campagneprospect.daterappel < now()
  183.                 ";
  184.         $query0 = $this->em->createQuery($sql0);
  185.         $query0_ids = $this->em->createQuery($sql0_ids);
  186.         // Prochaine 5jours
  187.         $sql1 = "SELECT
  188.                 DATE(campagneprospect.daterappel) AS periode,
  189.                 COUNT(campagneprospect.id) AS nombre
  190.                 FROM 
  191.                 ".Campagneprospect::class." AS campagneprospect
  192.                 LEFT JOIN ".Appelstatut::class." AS appelstatut WITH campagneprospect.appelstatut = appelstatut.id
  193.                 ".$where."
  194.                 AND appelstatut.rappel=TRUE AND campagneprospect.daterappel >= now()
  195.                 GROUP BY periode
  196.                 ORDER BY periode ASC
  197.                 ";
  198.         $query1 = $this->em->createQuery($sql1);
  199.         $query1->setFirstResult(0);
  200.         $query1->setMaxResults(5);
  201.         // Par mois
  202.         $sql2 = "SELECT
  203.                 date_format(campagneprospect.daterappel,'%Y-%m') AS periode,
  204.                 COUNT(campagneprospect.id) AS nombre
  205.                 FROM 
  206.                 ".Campagneprospect::class." AS campagneprospect
  207.                 LEFT JOIN ".Appelstatut::class." AS appelstatut WITH campagneprospect.appelstatut = appelstatut.id
  208.                 ".$where."
  209.                 AND appelstatut.rappel=TRUE AND campagneprospect.daterappel >= now()
  210.                 GROUP BY periode
  211.                 ORDER BY periode ASC
  212.                 ";
  213.         $query2 = $this->em->createQuery($sql2);
  214.         $reponse0 = $query0->getResult();
  215.         $reponse0_ids = $query0_ids->getResult();
  216.         $reponse1 = $query1->getResult();
  217.         $reponse2 = $query2->getResult();
  218.         $reponse[] = [
  219.             "id" => 1,
  220.             "data"=> $reponse0,
  221.             "ids" => array_column($reponse0_ids, 'ids')
  222.         ];
  223.         $reponse[] = [
  224.             "id" => 2,
  225.             "data"=> $reponse1,
  226.             "ids" => []
  227.         ];
  228.         $reponse[] = [
  229.             "id" => 3,
  230.             "data"=> $reponse2,
  231.             "ids" => []
  232.         ];
  233.         return $this->apiOk($reponse);
  234.     }
  235.     /**
  236.      * @Route("/collaborateurappels", name="api_Statistique_collaborateurappels", methods={"POST"})
  237.      * @param Request $request
  238.      * @return JsonResponse
  239.      */
  240.     public function collaborateurappels(Request $request)
  241.     {
  242.         $data = json_decode($request->getContent(), true);
  243.         $where = $this->paramstowhere($data);
  244.         $sql = "SELECT
  245.                 utilisateur.id AS idutilisateur,
  246.                 CONCAT(utilisateur.nom,' ',utilisateur.prenom) AS nomutilisateur,
  247.                 DATE_FORMAT(appel.dateappel, '%Y-%m-%d') AS datetraitement,
  248.                 COUNT(appel.id) AS nombreappel,
  249.                 SUM(appel.dureeappel) dureetraitement
  250.                 FROM ".Appel::class." as appel
  251.                 LEFT JOIN ".Campagneprospect::class." as campagneprospect WITH campagneprospect.id = appel.campagneprospect
  252.                 LEFT JOIN ".Utilisateur::class." as utilisateur WITH utilisateur.id = appel.utilisateur
  253.                 ".$where."
  254.                 AND (appel.sourceouverture IS NULL OR appel.sourceouverture <> '".Appel::SOURCE_REQUALIFICATION_RESPONSABLE."')
  255.                 GROUP BY idutilisateur,nomutilisateur, datetraitement
  256.                 ORDER BY appel.dateappel asc";
  257.         $query = $this->em->createQuery($sql);
  258.         $reponse = $query->getResult();
  259.         return $this->apiOk($reponse);
  260.     }
  261.     ////////////////////////////STATISTIQUE GLOBAL ////////////////////////
  262.     /**
  263.      * @Route("/prospectsglobal", name="api_Statistique_prospectsglobal", methods={"GET"})
  264.      * @return JsonResponse
  265.      */
  266.     public function prospectsglobal()
  267.     {
  268.         $sqlprospects = "SELECT
  269.                 COUNT(prospect.id) AS total,
  270.                 SUM(CASE WHEN prospect.email IS NOT NULL AND prospect.email <> '' THEN 1 ELSE 0 END) AS avecEmail,
  271.                 SUM(CASE WHEN prospect.standard IS NOT NULL AND prospect.standard <> '' THEN 1 ELSE 0 END) AS avecStandard,
  272.                 SUM(CASE WHEN complement.statutSynchronisation = 'SUCCES' THEN 1 ELSE 0 END) AS enrichis,
  273.                 SUM(CASE WHEN complement.statutSynchronisation = 'SIREN_INVALIDE' THEN 1 ELSE 0 END) AS sirenInvalides
  274.                 FROM ".Prospect::class." prospect
  275.                 LEFT JOIN prospect.prospectcomplement complement
  276.                 WHERE prospect.active = 1";
  277.         $sqlRepartitionStructures = "SELECT
  278.                 CASE
  279.                     WHEN complementStructure.statutSynchronisation = 'SUCCES'
  280.                         AND (complementStructure.estAdministration = true
  281.                             OR complementStructure.natureJuridique LIKE '7%')
  282.                         THEN 'PUBLIC'
  283.                     WHEN complementStructure.statutSynchronisation = 'SUCCES'
  284.                         AND complementStructure.estAdministration = false
  285.                         AND complementStructure.natureJuridique IS NOT NULL
  286.                         THEN 'PRIVE'
  287.                     WHEN prospectStructure.typeStructure IN ('PUBLIC', 'PRIVE')
  288.                         THEN prospectStructure.typeStructure
  289.                     WHEN codenafStructure.classificationStructure IN ('PUBLIC', 'PRIVE')
  290.                         THEN codenafStructure.classificationStructure
  291.                     ELSE 'INDETERMINE'
  292.                 END AS typeStructureEffectif,
  293.                 COUNT(prospectStructure.id) AS nombre
  294.                 FROM ".Prospect::class." prospectStructure
  295.                 LEFT JOIN prospectStructure.prospectcomplement complementStructure
  296.                 LEFT JOIN prospectStructure.codenaf codenafStructure
  297.                 WHERE prospectStructure.active = 1
  298.                 GROUP BY typeStructureEffectif";
  299.         $sqlprospectsInactifs = "SELECT COUNT(prospect.id)
  300.                 FROM ".Prospect::class." prospect
  301.                 WHERE prospect.active = 0";
  302.         $sqlcontacts = "SELECT
  303.                 COUNT(contact.id) AS total,
  304.                 SUM(CASE WHEN contact.email IS NOT NULL AND contact.email <> '' THEN 1 ELSE 0 END) AS avecEmail,
  305.                 SUM(CASE WHEN contact.fixe IS NOT NULL AND contact.fixe <> '' THEN 1 ELSE 0 END) AS avecFixe,
  306.                 SUM(CASE WHEN contact.mobile IS NOT NULL AND contact.mobile <> '' THEN 1 ELSE 0 END) AS avecMobile
  307.                 FROM ".Contact::class." contact
  308.                 INNER JOIN contact.prospect prospect
  309.                 WHERE contact.active = 1
  310.                 AND prospect.active = 1";
  311.         $sqlcontactsInactifs = "SELECT COUNT(contact.id)
  312.                 FROM ".Contact::class." contact
  313.                 INNER JOIN contact.prospect prospect
  314.                 WHERE contact.active <> 2
  315.                 AND prospect.active <> 2
  316.                 AND (contact.active = 0 OR prospect.active = 0)";
  317.         $prospects = $this->normaliserCompteurs(
  318.             $this->em->createQuery($sqlprospects)->getSingleResult()
  319.         );
  320.         $prospects['publics'] = 0;
  321.         $prospects['prives'] = 0;
  322.         $prospects['indetermines'] = 0;
  323.         foreach ($this->em->createQuery($sqlRepartitionStructures)->getArrayResult() as $repartition) {
  324.             $type = strtoupper((string)($repartition['typeStructureEffectif'] ?? 'INDETERMINE'));
  325.             $cle = $type === 'PUBLIC' ? 'publics' : ($type === 'PRIVE' ? 'prives' : 'indetermines');
  326.             $prospects[$cle] += (int)($repartition['nombre'] ?? 0);
  327.         }
  328.         $contacts = $this->normaliserCompteurs(
  329.             $this->em->createQuery($sqlcontacts)->getSingleResult()
  330.         );
  331.         $prospects['inactifs'] = (int)$this->em->createQuery($sqlprospectsInactifs)->getSingleScalarResult();
  332.         $contacts['inactifs'] = (int)$this->em->createQuery($sqlcontactsInactifs)->getSingleScalarResult();
  333.         $prospects['nonEnrichis'] = max(0, $prospects['total'] - $prospects['enrichis']);
  334.         return $this->apiOk([
  335.             "prospects" => $prospects,
  336.             "contacts" => $contacts,
  337.         ]);
  338.     }
  339.     private function normaliserCompteurs(array $compteurs): array
  340.     {
  341.         foreach ($compteurs as $cle => $valeur) {
  342.             $compteurs[$cle] = (int)$valeur;
  343.         }
  344.         return $compteurs;
  345.     }
  346.     /**
  347.      * @Route("/prospectsevolution", name="api_Statistique_prospectsevolution", methods={"POST"})
  348.      * @param Request $request
  349.      * @return JsonResponse
  350.      */
  351.     public function prospectsevolution(Request $request)
  352.     {
  353.         $date = date("Ymd", strtotime("-365 days", strtotime(date("Ymd"))));
  354.         $where = " WHERE appel.dateappel >= ".$date;
  355.         $sqlcreation = "SELECT
  356.                         COUNT(prospect.id) AS total,
  357.                         year(prospect.datecreation) AS annee,
  358.                         month(prospect.datecreation) as mois
  359.                         FROM ".Prospect::class." as prospect
  360.                         WHERE prospect.datecreation >= ".$date."
  361.                         GROUP BY annee,mois
  362.                         ORDER BY annee, mois asc";
  363.         $sqlmodification = "SELECT
  364.                         COUNT(prospect.id) AS total,
  365.                         year(prospect.datemodification) AS annee,
  366.                         month(prospect.datemodification) as mois
  367.                         FROM ".Prospect::class." as prospect
  368.                         WHERE prospect.datemodification >= ".$date."
  369.                         GROUP BY annee,mois
  370.                         ORDER BY annee, mois asc";
  371.         $querycreation = $this->em->createQuery($sqlcreation);
  372.         $querymodification = $this->em->createQuery($sqlmodification);
  373.         $creation = $querycreation->getResult();
  374.         $modification = $querymodification->getResult();
  375.         $reponse = [
  376.             "creation" => $creation,
  377.             "modification" => $modification,
  378.         ];
  379.         return $this->apiOk($reponse);
  380.     }
  381.     /**
  382.      * @Route("/prospectscp", name="api_Statistique_prospectscp", methods={"GET"})
  383.      * Query string:
  384.      * - axe=cp (default): regroupement par code postal + ville
  385.      * - axe=naf: regroupement par code NAF
  386.      * - all=0 (default): top 10; all=1: tous les resultats
  387.      * @return JsonResponse
  388.      */
  389.     public function prospectscp(Request $request)
  390.     {
  391.         $axe = strtolower(trim((string)$request->query->get('axe', 'cp')));
  392.         if (!in_array($axe, ['cp', 'naf'], true)) {
  393.             $axe = 'cp';
  394.         }
  395.         $afficherTout = $request->query->getBoolean('all', false);
  396.         // Keep "cp" key in response for backward compatibility with existing frontend contract.
  397.         $regroupementCodeExpression = "ville.codepostal";
  398.         $regroupementLibelleExpression = "ville.libelle";
  399.         $jointureRegroupement = "LEFT JOIN ".Ville::class." as ville WITH ville.id = prospect.ville";
  400.         if ($axe === 'naf') {
  401.             $regroupementCodeExpression = "codenaf.code";
  402.             $regroupementLibelleExpression = "codenaf.libelle";
  403.             $jointureRegroupement = "LEFT JOIN ".Codenaf::class." as codenaf WITH codenaf.id = prospect.codenaf";
  404.         }
  405.         $sqltotal = "SELECT
  406.                 COUNT(prospect.id) as total,
  407.                 SUM(CASE WHEN prospect.email <> '' THEN 1 ELSE 0 END) as totalavecemail,
  408.                 SUM(CASE WHEN prospect.standard <> '' THEN 1 ELSE 0 END) as totalavecstandard,
  409.                 ".$regroupementCodeExpression." as cp,
  410.                 ".$regroupementLibelleExpression." as libelle
  411.                 FROM ".Prospect::class." as prospect
  412.                 ".$jointureRegroupement."
  413.                 GROUP BY cp, libelle
  414.                 ORDER BY total DESC, cp ASC, libelle ASC";
  415.         $querytotal = $this->em->createQuery($sqltotal);
  416.         if (!$afficherTout) {
  417.             // Retrieve one extra row to tell the frontend whether "Afficher plus" is useful.
  418.             $querytotal->setMaxResults(11);
  419.         }
  420.         $resultats = $querytotal->getResult();
  421.         $hasMore = !$afficherTout && count($resultats) > 10;
  422.         if ($hasMore) {
  423.             $resultats = array_slice($resultats, 0, 10);
  424.         }
  425.         $total = [];
  426.         $totalavecemail = [];
  427.         $totalavecstandard = [];
  428.         foreach ($resultats as $resultat) {
  429.             $groupe = [
  430.                 'cp' => $resultat['cp'],
  431.                 'libelle' => $resultat['libelle'],
  432.             ];
  433.             $total[] = $groupe + ['total' => (int)$resultat['total']];
  434.             $totalavecemail[] = $groupe + ['total' => (int)$resultat['totalavecemail']];
  435.             $totalavecstandard[] = $groupe + ['total' => (int)$resultat['totalavecstandard']];
  436.         }
  437.         $reponse = [
  438.             "total" => $total,
  439.             "totalavecemail" => $totalavecemail,
  440.             "totalavecstandard" => $totalavecstandard,
  441.             "hasMore" => $hasMore,
  442.         ];
  443.         return $this->apiOk($reponse);
  444.     }
  445.     /***************************** HELPERS *****************/
  446.     /**
  447.      * @param array $data
  448.      * @return string
  449.      */
  450.     public function paramstowhere(array $data) : string{
  451.         //AND
  452.         $and = " 1=1";
  453.         if (isset($data['filter']['and'])) {
  454.             $filtres = $data['filter']['and'];
  455.             if (sizeof($filtres) != 0) {
  456.                 $and = "( 1=1";
  457.                 foreach ($filtres as $key => $value) {
  458.                     $and .= " AND " . $key . " " . $value;
  459.                 }
  460.                 $and .= " )";
  461.             }
  462.         }
  463.         //OR
  464.         $or = "";
  465.         if (isset($data['filter']['or'])) {
  466.             $filtres = $data['filter']['or'];
  467.             if (sizeof($filtres) != 0) {
  468.                 $or = " ( 1=0";
  469.                 foreach ($filtres as $key => $value) {
  470.                     $or .= " OR " . $key . " " . $value;
  471.                 }
  472.                 $or .= " )";
  473.             }
  474.         }
  475.         $where = " WHERE ".$and;
  476.         if ($or != "") {
  477.             $where .= " AND " . $or;
  478.         }
  479.         return $where;
  480.     }
  481. }