vendor/theatre/core/src/Repository/TextAideRepository.php line 323

Open in your IDE?
  1. <?php
  2. namespace TheatreCore\Repository;
  3. use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
  4. use Doctrine\Persistence\ManagerRegistry;
  5. use TheatreCore\Entity\Aides;
  6. use TheatreCore\Entity\TextAide;
  7. use TheatreCore\Entity\Texts;
  8. use TheatreCore\Traits\TheatreTrait;
  9. /**
  10.  * TextAideRepository
  11.  *
  12.  * This class was generated by the Doctrine ORM. Add your own custom
  13.  * repository methods below.
  14.  */
  15. class TextAideRepository extends ServiceEntityRepository
  16. {
  17.     use TheatreTrait;
  18.     private $em;
  19.     public $__table;
  20.     public $__table_object;
  21.     public $__idtable;
  22.     public function __construct(ManagerRegistry $registry)
  23.     {
  24.         parent::__construct($registryTextAide::class);
  25.         $this->__table $this->getClassMetadata()->getTableName();
  26.         $this->__table_object $this->getClassMetadata()->name;
  27.         $this->__idtable $this->getClassMetadata()->getSingleIdentifierFieldName();
  28. //        $this->__table = 'persons';
  29. //        $this->__table_object = '\\App\\Entity\\Persons';
  30.     }
  31.     //  {{{ countAides()
  32.     /** Compter le nombre d'aide
  33.      *
  34.      * @access   public
  35.      * param     int idaide identifiant de l'aide
  36.      * @return   int
  37.      */
  38.     public function countAides($idaide null$idtext null$params = array())
  39.     {
  40.         if (!empty($params['count_texts'])) {
  41.             $sql 'SELECT COUNT(DISTINCT(idtext)) 
  42.                     FROM ' $this->__table 
  43.                     WHERE ';
  44.         } else {
  45.             $sql 'SELECT COUNT(*)
  46.                     FROM ' $this->__table 
  47.                     WHERE ';
  48.         }
  49.         if (!empty($idaide)) {
  50.             $sql_where[] = 'idaide IN (' $this->arrayToIn($idaide) . ') ';
  51.         }
  52.         if (!empty($idtext)) {
  53.             $sql_where[] = 'idtext IN (' $this->arrayToIn($idtext) . ') ';
  54.         }
  55.         $sql $sql join(' AND '$sql_where);
  56.         $nb_aides $this->queryOne($sql);
  57.         if ($nb_aides) {
  58.             return $nb_aides;
  59.         }
  60.     }
  61.     // }}}
  62.     //  {{{ getInfosText_aide()
  63.     /** Récupèrer les infos
  64.      *
  65.      * @access   public
  66.      * param     int idaide identifiant de l'aide
  67.      * param     int idtext identifiant du texte
  68.      * @return   array
  69.      */
  70.     public function getInfosText_aide($idtextaide)
  71.     {
  72.         try {
  73.             $sql 'SELECT * FROM ' $this->__table 
  74.                 WHERE idtextaide=' . (int)$idtextaide;
  75.             $infos $this->queryRow($sql);
  76.             if (empty($infos)) {
  77.                 return [];
  78.             }
  79.             $infos['id'] = $infos['idtextaide'];
  80.             if ($infos['date_start'] == '0000-00-00 00:00:00') {
  81.                 $infos['date_start'] = NULL;
  82.             }
  83.             if ($infos['date_end'] == '0000-00-00 00:00:00') {
  84.                 $infos['date_end'] = NULL;
  85.             }
  86.             foreach (array('start''end') as $i) {
  87.                 if (!empty($infos['date_' $i])) {
  88.                     $infos['date_' $i '_year'] = substr($infos['date_' $i], 04);
  89.                     $infos['date_' $i '_month'] = substr($infos['date_' $i], 52);
  90.                     $infos['date_' $i '_day'] = substr($infos['date_' $i], 82);
  91.                 }
  92.             }
  93.             return $infos;
  94.         } catch (\Throwable $e) {
  95.             return [];
  96.         }
  97.     }
  98.     // }}}
  99.     //  {{{ getRelationsArray()
  100.     /** Décrit les relations de l'objet
  101.      *
  102.      * @access  public
  103.      * @param string|int $type si on souhaite retourner uniquement un type precis
  104.      * @see     Theatre::getLinkedObject()
  105.      */
  106.     public function getRelationsArray($type)
  107.     {
  108.         $array_types = array(
  109.             // jointure avec texts
  110.             'idtext' => array(// texts associés
  111.                 'type_join' => 'simple',
  112.                 'dest_table' => 'texts',
  113.                 'join_field_src' => 'idtext',
  114.                 'fields' => array('idtext''title''valid''url_clean'),
  115.                 'silent_delete_relation' => true,
  116.                 'description' => 'Texte associé',
  117.             ),
  118.             // jointure avec aides
  119.             'idaide' => array(// aides associés
  120.                 'type_join' => 'simple',
  121.                 'dest_table' => 'aides',
  122.                 'join_field_src' => 'idaide',
  123.                 'fields' => array('idaide''aide''idcontact'),
  124.                 'silent_delete_relation' => true,
  125.                 'description' => 'Aide associé',
  126.             ),
  127.         );
  128.         // retourne uniquement un type précis
  129.         if ($type == 'all') {
  130.             return $array_types;
  131.         }
  132.         if (!empty($array_types[$type])) {
  133.             $array_types[$type]['type'] = $type;
  134.             return $array_types[$type];
  135.         } else {
  136.             return null;
  137.         }
  138.     }
  139.     // }}}
  140.     //  {{{ deleteTextAide()
  141.     /** Supprime une aide d'un text
  142.      *
  143.      * @access  public
  144.      * @param int $idtextaide l'aide du texte
  145.      * @return bool
  146.      */
  147.     public function deleteTextAide($idtextaide)
  148.     {
  149.         try {
  150.             $sql 'DELETE FROM ' $this->__table 
  151.                 WHERE idtextaide=' . (int)$idtextaide;
  152.             // excute
  153.             $res $this->exec($sql);
  154.             return true;
  155.         } catch (\Throwable $e) {
  156.             return false;
  157.         }
  158.     }
  159.     // }}}
  160.     //  {{{ getAides()
  161.     /** Récupèrer les aides d'un text
  162.      *
  163.      * @access   public
  164.      * @param array $aueru Les paramètres pour la requete
  165.      * @param bool $debug afficher la requête
  166.      * @return   string
  167.      */
  168.     public function getAides($idtext)
  169.     {
  170.         return $this->getEntityManager()->getRepository(Aides::class)->getListAides(array(
  171.             'special' => array(
  172.                 'idtexts' => array($idtext)
  173.             ),
  174.             'dbg' => array('les_aides''Liste des aides du text ' $idtext)
  175.         ));
  176.     }
  177.     // }}}
  178.     //  {{{ getListTextAide()
  179.     /** Texts avec une aide
  180.      *
  181.      * @access   public
  182.      * @param array $params_sql paramètre pour la requete SQL
  183.      * @return   array
  184.      */
  185.     public function getListTextAide($params_sql null$params_display = array())
  186.     {
  187.         // si pas de tableau
  188.         if (!isset($params_sql['special'])) {
  189.             $params_sql['special'] = array();
  190.         }
  191.         if (!isset($params_sql['params'])) {
  192.             $params_sql['params'] = array();
  193.         }
  194.         // construction de la requête avec le passage de paramètres
  195.         $sql $this->getSQLTextAide($params_sql);
  196.         // paramètre de debug
  197.         $dbg = (empty($params_sql['dbg'])) ? array() : $dbg $params_sql['dbg'];
  198.         // executer la requete
  199.         $datas $this->query($sql$dbg);
  200.         // debug
  201.         $start_boucle microtime(true);
  202.         $text_aide = array();
  203.         // on boucle
  204.         foreach ($datas as $data) {
  205.             $this->loadResult($data);
  206.             if (!empty($params_sql['idtext'])) {
  207.                 $id $this->idaide;
  208.             } else {
  209.                 $id $this->idtext;
  210.             }
  211.             if (!empty($params_sql['get_texts_with_aides'])) {
  212.                 $id $this->idtextaide;
  213.             }
  214.             if (empty($text_aide[$id])) {
  215.                 $text_aide[$id] = array(
  216.                     'idtextaide' => $this->idtextaide,
  217.                     'id' => $this->idtextaide,
  218.                     'idtext' => $this->idtext,
  219.                     'object' => 'text_aide',
  220.                     'publish' => $this->text_aide_publish,
  221.                     'valid' => $this->valid,
  222.                     'idaide' => $this->idaide,
  223.                     'date_start' => $this->date_start,
  224.                     'date_end' => $this->date_end,
  225.                     'year_start' => substr($this->date_start04),
  226.                     'comments' => $this->comments,
  227.                     'url' => $this->url,
  228.                     'email_to_get_text' => $this->email_to_get_text,
  229.                     'url_to_get_text' => $this->url_to_get_text,
  230.                     'aide' => $this->getEntityManager()->getRepository(Aides::class)->getInfosAide($this->idaide, array(
  231.                         'get_aidecontact' => true,
  232.                         'get_contact' => true,
  233.                     )),
  234.                 );
  235.                 if ($this->date_end != '' && $this->date_end != '0000-00-00 00:00:00') {
  236.                     $text_aide[$id]['year_end'] = substr($this->date_end04);
  237.                 } else {
  238.                     $text_aide[$id]['year_end'] = null;
  239.                 }
  240.                 $idtexts[$this->idtext] = $this->idtext;
  241.             }
  242.         }
  243.         // debug de la boucle
  244.         if ($this->isTraceMode('list_object')) {
  245.             $this->setTraceInfos(array(
  246.                 'execution_time_boucle' => microtime(true) - $start_boucle,
  247.                 'nb_occurence' => count($text_aide),
  248.                 'dbg' => $dbg,
  249.             ));
  250.         }
  251.         $this->free();
  252.         $text_aide_group = array();
  253.         // récupèrer également les texts
  254.         if (!empty($idtexts)) {
  255.             $params_sql_texts = array(
  256.                 'special' => array(
  257.                     'idtext' => $idtexts,
  258.                     'join' => true,
  259.                 ),
  260.                 'dbg' => array('list_texts_text_aide''Récupération des texts d\'une aide'),
  261.             );
  262.             $params_sql_texts['params']['limit'] = 'all';
  263.             $texts $this->getEntityManager()->getRepository(Texts::class)->getListTexts($params_sql_texts$params_display);
  264.             if (!empty($texts)) {
  265.                 foreach ($texts as $k => $v) {
  266.                     $texts[$v['idtext']]['publisher_first'] = true;
  267.                     if (!empty($v['publisher'])) {
  268.                         foreach ($v['publisher'] as $publisher) {
  269.                             $texts[$v['idtext']]['publisher'] = $publisher;
  270.                         }
  271.                     }
  272.                 }
  273.                 foreach ($text_aide as $k => $v) {
  274.                     if (!empty($texts[$v['idtext']])) {
  275.                         if (!empty($params_sql['group_by_aide_type_aide_text'])) {
  276.                             $key $v['idaide'] . '_' $v['aide']['type_aide'] . '_' $v['idtext'];
  277.                             if (empty($text_aide_group[$key])) {
  278.                                 $text_aide_group[$key] = $v;
  279.                             }
  280.                             $text_aide_group[$key]['texts'][$v['idtext']] = $texts[$v['idtext']];
  281.                         } else {
  282.                             $text_aide[$k]['texts'][$v['idtext']] = $texts[$v['idtext']];
  283.                         }
  284.                     }
  285.                 }
  286.             }
  287.         }
  288.         if (!empty($params_sql['group_by_aide_type_aide_text'])) {
  289.             return $text_aide_group;
  290.         } else {
  291.             return $text_aide;
  292.         }
  293.     }
  294.     // }}}
  295.     //  {{{ countListTextAide()
  296.     /** Compter la liste des aides
  297.      *
  298.      * @access   public
  299.      * @param array $params_sql paramètre pour la requete SQL
  300.      * @param bool $debug mode débugage
  301.      * @return   int
  302.      */
  303.     public function countListTextAide($params_sql null$debug false)
  304.     {
  305.         // si pas de limite => tout
  306.         if (empty($params_sql['limit'])) {
  307.             $params_sql['limit'] = array('all');
  308.         }
  309.         $params_sql['count_only'] = true;
  310.         // construction de la requête avec le passage de paramètres
  311.         return $this->queryOne($this->getSQLTextAide($params_sql$debug));
  312.     }
  313.     // }}}
  314.     //  {{{ getSQLTextAide()
  315.     /** Générer la requete standard pour des aides
  316.      *
  317.      * @access   public
  318.      * @param array $aueru Les paramètres pour la requete
  319.      * @param bool $debug afficher la requête
  320.      * @return   string
  321.      */
  322.     public function getSQLTextAide($query = array(), $debug false)
  323.     {
  324.         // on prepare les tableaux
  325.         foreach (array('select''from''where''order''group''limit') as $t) {
  326.             if (!empty($query[$t])) {
  327.                 if (!is_array($query[$t])) {
  328.                     $query[$t][] = $query[$t];
  329.                 } else {
  330.                     $query[$t] = $query[$t];
  331.                 }
  332.             } else {
  333.                 $query[$t] = array();
  334.             }
  335.         }
  336.         $this->addSQLParams('distinct'$query'no_primary');
  337.         if (empty($query['group'])) {
  338.             $this->addSQLParams('group'$query'no');
  339.         }
  340.         // champs par défaut
  341.         $this->addSQLParams('select'$query, array(
  342.             array('text_aide' => '*'),
  343.             array('aides' => '*')
  344.         ));
  345.         $this->addSQLParams('select_more'$query',`text_aide`.`publish` as text_aide_publish');
  346.         $this->addSQLParams('from'$query, array(
  347.             'aides',
  348.         ));
  349.         $this->addSQLParams('join'$query, array(
  350.             'aides.`idaide`' => 'text_aide.`idaide`',
  351.         ));
  352.         // publié ou pas
  353.         if (empty($query['publish']) && $_ENV['CHECK_IF_ONLINE']) {
  354.             $this->addSQLParams('where'$query, array(
  355.                 array('aides''publish'1)
  356.             ));
  357.         } elseif (!empty($query['publish'])) {
  358.             $this->addSQLParams('where'$query, array(
  359.                 array('aides''publish'$query['publish'])
  360.             ));
  361.         }
  362.         // recherche par contact
  363.         if (!empty($query['special']['aides'])) {
  364.             if (!empty($query['special']['aides']['idcontacts'])) {
  365.                 $this->addSQLParams('where'$query, array(
  366.                     array('aides''idcontact'$query['special']['aides']['idcontacts']),
  367.                 ));
  368.             }
  369.             if (!empty($query['special']['aides']['type_aides']) && !empty($query['special']['aides']['idaidecontact'])) {
  370. //                $this->addSQLParams('where',$query,array(
  371. //                    array('aides','idaidecontact',$query['special']['aides']['idaidecontact']),
  372. //                    array('aides','type_aide',$query['special']['aides']['type_aides']),
  373. //                ));
  374.                 $type_aides $query['special']['aides']['type_aides'];
  375.                 if (is_array($type_aides)) {
  376.                     $type_aides implode(','$type_aides);
  377.                 }
  378.                 $idaidecontact $query['special']['aides']['idaidecontact'];
  379.                 if (is_array($idaidecontact)) {
  380.                     $idaidecontact implode(','$idaidecontact);
  381.                 }
  382.                 $query['where'][] = 'AND (aides.`type_aide` IN (' $type_aides ') OR aides.`idaidecontact` IN (' $idaidecontact ') )';
  383. //                $this->whereAdd('idtext IN ('.implode(',', $list[$this->IDNUM]).')', 'OR');
  384.             } else {
  385.                 if (!empty($query['special']['aides']['idaidecontact'])) {
  386.                     $this->addSQLParams('where'$query, array(
  387.                         array('aides''idaidecontact'$query['special']['aides']['idaidecontact']),
  388.                     ));
  389.                 }
  390.                 if (!empty($query['special']['aides']['type_aides'])) {
  391.                     $this->addSQLParams('where'$query, array(
  392.                         array('aides''type_aide'$query['special']['aides']['type_aides']),
  393.                     ));
  394.                 }
  395.             }
  396.             if (!empty($query['special']['aides']['idaide'])) {
  397.                 $this->addSQLParams('where'$query, array(
  398.                     array('aides''idaide'$query['special']['aides']['idaide']),
  399.                 ));
  400.             }
  401.         }
  402.         // pour un texte
  403.         if (!empty($query['idtext'])) {
  404.             $this->addSQLParams('where'$query, array(
  405.                 array('text_aide''idtext'$query['idtext'])
  406.             ));
  407.         }
  408.         if (!empty($query['idtexts'])) {
  409.             $where_more ' AND texts.idtext IN (' implode(','$query['idtexts']) . ')';
  410.             $this->addSQLParams('where_more'$query$where_more);
  411.         }
  412.         // recherche par année
  413.         if (!empty($query['special']['period'])) {
  414.             if (!empty($query['special']['period']['year'])) {
  415.                 $this->addSQLParams('where_more'$query' AND YEAR(text_aide.`date_start`)=' $query['special']['period']['year']);
  416.             }
  417.             if (!empty($query['special']['period']['years'])) {
  418.                 $where_more ' AND YEAR(text_aide.`date_start`) BETWEEN ' $query['special']['period']['years']['start'] . ' AND ' $query['special']['period']['years']['end'];
  419.                 $this->addSQLParams('where_more'$query$where_more);
  420.             }
  421.         }
  422.         $this->addSQLParams('order'$query, array(
  423.             array('text_aide' => 'date_start'),
  424.         ));
  425.         return $this->getSQLObject($query);
  426.     }
  427.     // }}}
  428.     // {{{ hasEmailToDownloadText
  429.     /**
  430.      * Vérifie qu'un email permettant d'effectuer une demande de téléchargement de texte existe en base de données
  431.      *
  432.      * @access public
  433.      * @param int $idtext
  434.      * @return boolean
  435.      */
  436.     public function hasEmailToDownloadText($idtext)
  437.     {
  438.         $sql 'SELECT COUNT(email_to_get_text)
  439.                     FROM ' $this->__table '
  440.                     WHERE idtext = ' intval($idtext) . '
  441.                     AND email_to_get_text IS NOT NULL
  442.                     AND publish LIKE 1
  443.         ';
  444.         $count $this->queryOne($sql);
  445.         return $count;
  446.     }
  447.     // }}}
  448.     // {{{ getEmailToDownloadText
  449.     /**
  450.      * Récupérer une adresse email permettant d'effectuer une demande de téléchatgement de texte
  451.      *
  452.      * @access public
  453.      * @param int $idtext L'id du texte
  454.      * @return string|null
  455.      */
  456.     public function getEmailToDownloadText($idtext)
  457.     {
  458.         $sql $this->createQueryBuilder('t')
  459.             ->select('t.email_to_get_text')
  460.             ->where('t.idtext = :idtext')
  461.             ->andWhere('t.url_to_get_text IS NOT NULL')
  462.             ->andWhere('t.publish = 1')
  463.             ->orderBy('t.dateupdate''DESC')
  464.             ->setParameter('idtext'intval($idtext));
  465.         $query $sql->getQuery();
  466.         $result $query->setMaxResults(1)->getOneOrNullResult();
  467.         if ($result) {
  468.             return $result['email_to_get_text'];
  469.         } else {
  470.             return null;
  471.         }
  472.     }
  473.     // }}}
  474.     // {{{ getUrlToDownloadText
  475.     /**
  476.      * Récupérer une url permettant de télécharger le texte
  477.      *
  478.      * @access public
  479.      * @param int $idtext L'id du texte
  480.      * @return string|null
  481.      */
  482.     public function getUrlToDownloadText($idtext)
  483.     {
  484.         $sql $this->createQueryBuilder('t')
  485.             ->select('t.url_to_get_text')
  486.             ->where('t.idtext = :idtext')
  487.             ->andWhere('t.url_to_get_text IS NOT NULL')
  488.             ->andWhere('t.publish = 1')
  489.             ->orderBy('t.dateupdate''DESC')
  490.             ->setParameter('idtext'intval($idtext));
  491.         $query $sql->getQuery();
  492.         $result $query->setMaxResults(1)->getOneOrNullResult();
  493.         if ($result) {
  494.             return $result['url_to_get_text'];
  495.         } else {
  496.             return null;
  497.         }
  498.     }
  499.     // }}}
  500.     //  {{{ getYears()
  501.     /** trouver les années où il y a eu des prix
  502.      *
  503.      * @access   public
  504.      * @param array $auery Les paramètres pour la requete
  505.      * @param bool $debug afficher la requête
  506.      * @return   array
  507.      */
  508.     public function getYears($params = array(), $debug false)
  509.     {
  510.         $query 'SELECT DISTINCT YEAR(text_aide.`date_start`) AS idannee, YEAR(text_aide.`date_start`) as annee
  511.                   FROM text_aide
  512.                   JOIN aides ON text_aide.`idaide`=aides.`idaide`
  513.                   WHERE 1 ';
  514.         // type prix ou nominations
  515.         if (!empty($params['special']['aides']['type_aides'])) {
  516.             $query .= ' AND aides.`type_aide` IN (' $this->arrayToIn($params['special']['aides']['type_aides']) . ') ';
  517.         }
  518.         // contact spécifique
  519.         if (!empty($params['special']['aides']['idcontacts'])) {
  520.             $query .= ' AND aides.`idcontact` IN (' $this->arrayToIn($params['special']['aides']['idcontacts']) . ') ';
  521.         }
  522.         if (!empty($params['special']['aides']['idaidecontact'])) {
  523.             if (empty($params['special']['aides']['idaidecontact_or_type_aide'])) {
  524.                 $query .= ' AND ';
  525.             }
  526.             $type_aides $params['special']['aides']['idaidecontact'];
  527.             if (is_array($type_aides)) {
  528.                 $type_aides implode(','$type_aides);
  529.             }
  530.             $query .= '     aides.`idaidecontact` IN (' $type_aides ')';
  531.             if (!empty($params['special']['aides']['idaidecontact_or_type_aide'])) {
  532.                 $query .= ' ) ';
  533.             }
  534.         }
  535.         $query .= ' HAVING annee <> 0 
  536.                     ORDER BY annee DESC';
  537.         $years $this->getEntityManager()->getConnection()->fetchAllKeyValue($query);
  538.         return !empty($years) ? $years : [];
  539.     }
  540.     // }}}
  541.     //  {{{ getIndiceNombresAides()
  542.     /** Récupère la liste des aides disponibles allant de 1 à X.
  543.      *
  544.      * @access   public
  545.      * @param array $auery Les paramètres pour la requete
  546.      * @return   array
  547.      */
  548.     public function getIndiceNombresAides($params = array())
  549.     {
  550.         $from_more '';
  551.         if (!empty($params['playlists'])) {
  552.             $from_more .= ',`playlists`';
  553.             if (!empty($params['playlists']['idclassifications'])) {
  554.                 $from_more .= ' ,`playlist_classification` ';
  555.             }
  556.         }
  557.         $query 'SELECT totalCount.totalAide
  558.             FROM
  559.                 (SELECT 
  560.                     COUNT(DISTINCT text_aide.idtext) AS totalText,
  561.                     COUNT(DISTINCT text_aide.idaide) AS totalAide
  562.                     FROM
  563.                     `aides`,
  564.                     `text_aide`
  565.                     ' $from_more '
  566.                     WHERE
  567.                     1   AND aides.`publish` = 1';
  568.         if (!empty($params['type_aides'])) {
  569.             if (empty($params['idaidecontact_or_type_aide'])) {
  570.                 $query .= ' AND ';
  571.             } else {
  572.                 $query .= ' AND (';
  573.             }
  574.             $type_aides $params['type_aides'];
  575.             if (is_array($type_aides)) {
  576.                 $type_aides implode(','$type_aides);
  577.             }
  578.             $query .= ' aides.`type_aide` IN (' $type_aides ')';
  579.             if (!empty($params['idaidecontact_or_type_aide'])) {
  580.                 $query .= ' OR ';
  581.             }
  582.         }
  583.         if (!empty($params['playlists'])) {
  584.             $query .= ' AND `playlists`.`idtext`=text_aide.idtext ';
  585.             if (!empty($params['playlists']['idclassifications'])) {
  586.                 $query .= ' AND `playlist_classification`.`idplaylist`=`playlists`.`idplaylist` ';
  587.                 $query .= ' AND `playlist_classification`.idclassification IN (' $this->arrayToIn($params['playlists']['idclassifications']) . ') ';
  588.             }
  589.             if (!isset($params['playlists']['publish'])) {
  590.                 $query .= ' AND `playlists`.`publish`=1 ';
  591.             }
  592.         }
  593.         if (!empty($params['idaidecontact'])) {
  594.             if (empty($params['idaidecontact_or_type_aide'])) {
  595.                 $query .= ' AND ';
  596.             }
  597.             $type_aides $params['idaidecontact'];
  598.             if (is_array($type_aides)) {
  599.                 $type_aides implode(','$type_aides);
  600.             }
  601.             $query .= '     aides.`idaidecontact` IN (' $type_aides ')';
  602.             if (!empty($params['idaidecontact_or_type_aide'])) {
  603.                 $query .= ' ) ';
  604.             }
  605.         }
  606.         $query .= ' AND aides.`idaide` = text_aide.`idaide`
  607.                     GROUP BY text_aide.idtext
  608.                     ORDER BY totalAide DESC
  609.                 ) AS totalCount
  610.             GROUP BY totalCount.totalAide
  611.             ORDER BY totalCount.totalAide DESC';
  612. //        AND YEAR(text_aide.`date_start`) BETWEEN 2017 AND 2019
  613.         $topDatas $this->queryAll($query);
  614.         if (!empty($topDatas)) {
  615. //            krsort($topDatas);
  616.             return $topDatas;
  617.         } else {
  618.             return array();
  619.         }
  620.     }
  621.     // }}}
  622. }