vendor/theatre/core/src/Repository/AidesRepository.php line 460

Open in your IDE?
  1. <?php
  2. namespace TheatreCore\Repository;
  3. use TheatreCore\Entity\Aidecontacts;
  4. use TheatreCore\Entity\Aides;
  5. use TheatreCore\Traits\TheatreTrait;
  6. use TheatreCore\Entity\Contacts;
  7. use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
  8. use Doctrine\Persistence\ManagerRegistry;
  9. use Doctrine\ORM\Query;
  10. use Symfony\Contracts\Translation\TranslatorInterface;
  11. /**
  12.  * AidesRepository
  13.  *
  14.  * This class was generated by the Doctrine ORM. Add your own custom
  15.  * repository methods below.
  16.  */
  17. class AidesRepository extends ServiceEntityRepository
  18. {
  19.     use TheatreTrait;
  20.     private $em;
  21.     public $__table;
  22.     public $__table_object;
  23.     public $__idtable;
  24.     public function __construct(ManagerRegistry $registryTranslatorInterface $translator)
  25.     {
  26.         parent::__construct($registryAides::class);
  27.         $this->__table $this->getClassMetadata()->getTableName();
  28.         $this->__table_object $this->getClassMetadata()->name;
  29.         $this->__idtable $this->getClassMetadata()->getSingleIdentifierFieldName();
  30.         $this->translator $translator;
  31.     }
  32.     //  {{{ findData()
  33.     /** Recherche d'aide
  34.      *
  35.      * Permet de rechercher des aides selon différents critères
  36.      *
  37.      * @access  public
  38.      * @see     Theatre::find()
  39.      */
  40.     public function findData($idclassification null)
  41.     {
  42.         $query $this->createQueryBuilder('e');
  43.         if ($this->getCount()) {
  44.             $query->select('COUNT(e.idaide)');
  45.             $this->setCount(false);
  46.             return $query;
  47.         }
  48. //
  49. //        // parametres
  50. //        if(isset($_REQUEST['keywords']) && $_REQUEST['keywords']!='nom') {
  51. //            $keywords = filter_var(trim($_REQUEST['keywords']));
  52. //        }
  53. //        if(isset($_REQUEST['idaide']) && my_is_int($_REQUEST['idaide'])) {
  54. //            $idaide = (int)$_REQUEST['idaide'];
  55. //        }
  56. //
  57. //        // query perso
  58. //        $query = 'SELECT '.$this->__table.'.* FROM '.$this->__table.'
  59. //                    LEFT JOIN aidecontacts ON aidecontacts.idaidecontact = aides.idaidecontact
  60. //                    LEFT JOIN contacts ON contacts.idcontact = aides.idcontact
  61. //                    WHERE  1';
  62. //
  63. //        //recherche stricte par id
  64. //        if(!empty($idaide)) {
  65. //            $query .= ' AND cl.idaide='.(int)$idaide;
  66. //        } else {
  67. //            // mots cles
  68. //            if (!empty($keywords)) {
  69. //                $query .= ' AND (aide LIKE \'%'.$this->escape($keywords).'%\' OR aidecontacts.title LIKE \'%'.$this->escape($keywords).'%\' OR contacts.organisation LIKE \'%'.$this->escape($keywords).'%\') ';
  70. //            }
  71. //        }
  72.         // on lance la recherche
  73.         return $query->getQuery();
  74.     }
  75.     // }}}
  76.     //  {{{ setToArray()
  77.     /** Liste des aides dans un tableau associatif
  78.      *
  79.      * Tableau associatif notament utilisé pour lister les informations sur des aides
  80.      * Utile pour générer les tableaux HTML de listes de aides
  81.      *
  82.      * @access  public
  83.      * @return  array
  84.      * @see     findData()
  85.      */
  86.     public function setToArray($spec true)
  87.     {
  88.         if ($spec == true) {
  89.             $this->findData();
  90.         }
  91.         $values = array();
  92.         $color null;
  93.         $nb 0;
  94.         while ($this->fetch()) {
  95.             $values[$nb] = $this->getInfosAide(null, array('get_contact' => true'get_aidecontact' => true));
  96.             $values[$nb]['id'] = $this->idaide;
  97.             // couleur de ligne alternative
  98.             $color $this->colorAlternate($color);
  99.             $values[$nb]['colorline'] = $color;
  100.             $nb++;
  101.         }
  102.         return $values;
  103.     }
  104.     // }}}
  105.     //  {{{ getInfosAide()
  106.     /** Informations sur une aide
  107.      *
  108.      * @access public
  109.      * @param int $idaide Identifiant de l'aide
  110.      * @return array
  111.      */
  112.     public function getInfosAide($idaide null$params = array())
  113.     {
  114.         $infos = array();
  115.         ////////////// infos de la table
  116.         if (empty($this->idaide) || $idaide) {
  117.             $infos $this->createQueryBuilder('u')
  118.                 ->select('u, ac, uc')
  119.                 ->leftJoin('u.idaidecontact''ac')
  120.                 ->leftJoin('u.idcontact''uc')
  121.                 ->where('u.' $this->__idtable ' =:value')->setParameter('value'$idaide)
  122.                 ->getQuery()
  123.                 ->getOneOrNullResult(Query::HYDRATE_ARRAY);
  124.             $this->loadResult($infos);
  125.         }
  126.         $infos += array(
  127.             'idaide' => $this->idaide,
  128.             'idcontact' => $this->idcontact,
  129.             'type_aide' => $this->typeAide,
  130.             'idaidecontact' => $this->idaidecontact,
  131.             'aide' => $this->aide,
  132.             'description' => $this->description,
  133.             'url_clean' => $this->urlClean,
  134.             'dateupdate' => $this->dateupdate,
  135.             'dateinsert' => $this->dateinsert,
  136.             'publish' => $this->publish,
  137.         );
  138.         if (!empty($infos['typeAide'])) {
  139.             $infos['type_aide_label'] = $this->getAideTypes($infos['typeAide']);
  140.             $infos['type_aide_infos'] = $this->getAideTypes($infos['typeAide'], false);
  141.         } else {
  142.             $infos['type_aide_label'] = null;
  143.         }
  144.         $mentions = array(
  145.             'Spectacles' => 'le spectacle',
  146.             'Texts' => 'le texte',
  147.             'Contacts' => 'la structure',
  148.             'Persons' => 'la biographie',
  149.         );
  150.         foreach ($mentions as $f => $v) {
  151.             $infos['mention_' $f] = $this->{'mention' ucfirst($f)};
  152.         }
  153.         $con $this->getEntityManager();
  154.         // récupère les infos sur le contact
  155.         if (!empty($params['get_contact']) && $infos['idcontact'] != '') {
  156.             $infos['contact'] = $con->getRepository(Contacts::class)->getInfosContact($infos['idcontact'], array('get_profile_picture' => true));
  157.         }
  158.         // récupère les infos sur la catégorie
  159.         if (!empty($params['get_aidecontact']) && !empty($infos['idaidecontact'])) {
  160.             $infos['aidecontact'] = $con->getRepository(Aidecontacts::class)->getInfosAidecontact($infos['idaidecontact']['idaidecontact']);
  161.         }
  162.         $infos['nameview'] = $infos['aide'];
  163.         return $infos;
  164.     }
  165.     // }}}
  166.     //  {{{ getObjectTitle()
  167.     /** Infos de l'item recherché
  168.      *
  169.      *
  170.      * @access public
  171.      * @param int $idobject Identifiant de l'item
  172.      * @param array $infos_object Informations pour construire le titre
  173.      * @param array $params Paramétres supplémentaires
  174.      * @return string|array
  175.      */
  176.     public function getObjectTitle($idobject null$infos_object = array(), $params = array())
  177.     {
  178.         if (!$idobject && isset($this->idaide)) $idobject $this->idaide;
  179.         // champs
  180.         $fields = array('idaide''aide''url_clean');
  181.         if (!empty($infos_object)) {
  182.             foreach ($fields as $k => $v) {
  183.                 if (array_key_exists($v$infos_object)) {
  184.                     $infos[$v] = $infos_object[$v];
  185.                 } else {
  186.                     $infos[$v] = '';
  187.                 }
  188.             }
  189.         } else {
  190.             //charger les infos que si necessaire
  191.             if (empty($this->aide)) {
  192.                 $sql 'SELECT ' implode(','$fields) . '
  193.                         FROM ' $this->__table '
  194.                         WHERE ' $this->__idtable '=' $idobject;
  195.                 $infos $this->queryRow($sql);
  196.             } else {
  197.                 foreach ($fields as $k => $v) {
  198.                     if (isset($this->$v) && $this->$v != '') {
  199.                         $infos[$v] = trim($this->$v);
  200.                     } else {
  201.                         $infos[$v] = '';
  202.                     }
  203.                 }
  204.             }
  205.         }
  206.         $infos $this->getInfosAide($idobject, array(
  207.             'get_contact' => true,
  208.             'get_aidecontact' => true,
  209.         ));
  210.         // catégorie
  211.         if (!empty($infos['aidecontact'])) {
  212.             $title[] = $infos['aidecontact']['title'];
  213.         }
  214.         $title[] = $infos['aide'];
  215.         if (!empty($infos['type_aide_label'])) {
  216.             $title[] = $infos['type_aide_label'];
  217.         }
  218.         // contact
  219.         if (!empty($infos['contact'])) {
  220.             $title[] = $infos['contact']['organisation'];
  221.         }
  222.         $infos['title'] = join(' / '$title);
  223.         // renvoyer un array plutôt que le titre (utile si on veux l'url)
  224.         if (array_key_exists('return_array'$params)) {
  225.             return $infos;
  226.         }
  227.         return $infos['title'];
  228.     }
  229.     // }}}
  230.     //  {{{ getRelationsArray()
  231.     /** Décrit les relations de l'objet
  232.      *
  233.      * @access  public
  234.      * @param string|int $type si on souhaite retourner uniquement un type precis
  235.      * @see     Theatre::getLinkedObject()
  236.      */
  237.     public function getRelationsArray($type)
  238.     {
  239.         $array_types = array(
  240.             'idcontact' => array(// contacts associés ?
  241.                 'type_join' => 'simple',
  242.                 'dest_table' => 'contacts',
  243.                 'fields' => array('idcontact''organisation''lastname''firstname''type''url_clean''valid'),
  244.                 'join_field_src' => 'idcontact',
  245.                 'description' => 'Contact associé à l\'aide',
  246.                 'silent_delete_relation' => true,
  247.             ),
  248.             'text_aide' => array(// text associés ?
  249.                 'type_join' => 'multiple',
  250.                 'dest_table' => 'texts',
  251.                 'fields' => array('idtext''title''publish''url_clean''valid'),
  252.                 'join_table' => 'text_aide',
  253.                 'description' => 'Textes associé à l\'aide',
  254.                 'silent_delete_relation' => true,
  255.             ),
  256.         );
  257.         // retourne uniquement un type précis
  258.         if ($type == 'all') {
  259.             return $array_types;
  260.         }
  261.         if (!empty($array_types[$type])) {
  262.             $array_types[$type]['type'] = $type;
  263.             return $array_types[$type];
  264.         } else {
  265.             return null;
  266.         }
  267.     }
  268.     // }}}
  269.     //  {{{ getListSearch()
  270.     /** Liste des aides
  271.      *
  272.      * Pour les champs Ajax de relations et les recherches diverses
  273.      *
  274.      * @access  public
  275.      * @param string $lettres Pour la recherche alphabetique
  276.      * @param string $type Pour le type recherche (editeurs, revues...)
  277.      * @param string $keywords Recherche par mots cles
  278.      * @return  array
  279.      */
  280.     public function getListSearch($lettre$type null$keywords null)
  281.     {
  282.         $sql 'SELECT a.idaide, a.aide, a.type_aide, c.organisation, ac.title
  283.                  FROM ' $this->__table ' a
  284.                  JOIN contacts c ON c.idcontact=a.idcontact
  285.                  LEFT JOIN aidecontacts ac ON a.idaidecontact=ac.idaidecontact
  286.                  WHERE 1 ';
  287.         // selection par ordre alpha
  288.         if (!empty($lettre) && $lettre != 'tous') {
  289.             $sql_where[] = array('LOWER(LEFT(LTRIM(aide),1))=\'' $this->escape($lettre) . '\'');
  290.         }
  291.         // recherche avec un mot cle
  292.         $list $this->splitKeywords($keywords);
  293.         if ($list) {
  294.             if (!empty($list[$this->IDSTR])) {
  295.                 // mots clés
  296.                 foreach ($list[$this->IDSTR] as $s) {
  297.                     $sql_more_name[] = 'aide LIKE \'%' $s '%\'';
  298.                 }
  299.                 $sql_where[] = array('(' join(' OR '$sql_more_name) . ')');
  300.             }
  301.             if (!empty($list[$this->IDNUM])) {
  302.                 // recherche par numéro d'id pour les mots clés numériques
  303.                 $sql_where[] = array('idaide IN (' implode(','$list[$this->IDNUM]) . ')''OR');
  304.             }
  305.         }
  306.         if (!empty($sql_where)) {
  307.             foreach ($sql_where as $k => $v) {
  308.                 if (!empty($v[1])) {
  309.                     $sql .= ' ' $v[1] . ' ' $v[0];
  310.                 } else {
  311.                     $sql .= ' AND ' $v[0];
  312.                 }
  313.             }
  314.         }
  315.         $sql .= ' ORDER BY title';
  316.         $this->query($sql);
  317.         $r = array();
  318.         while ($this->fetch()) {
  319.             $infos = array();
  320.             foreach (array('title''aide''type_aide''organisation') as $f) {
  321.                 if (!empty($this->$f)) {
  322.                     if ($f == 'type_aide') {
  323.                         $infos[$f] = $this->getAideTypes($this->$f);
  324.                     } else {
  325.                         $infos[] = $this->$f;
  326.                     }
  327.                 }
  328.             }
  329.             $r[$this->idaide] = join(' / '$infos);
  330.             // si trouvé par id, on l'affiche en fin de titre
  331.             if (!empty($list[$this->IDNUM]) && in_array($this->idaide$list[$this->IDNUM])) {
  332.                 $r[$this->idaide] .= ' - n°' $this->idaide;
  333.             }
  334.         }
  335.         $this->free();
  336.         return $r;
  337.     }
  338.     // }}}
  339.     //  {{{ getListAides()
  340.     /** Retourne des listes des aides
  341.      *
  342.      * Retourne des listes de aides au format "standard""
  343.      *
  344.      * @access   public
  345.      * @param array $params_sql paramètre pour la requete SQL
  346.      * @param array $format_vignette de la vignette si pas standard
  347.      * @param array $params_display paramètre pour l'affichage
  348.      * @return   array
  349.      */
  350.     public function getListAides($params_sql null$format_vignette = array(), $params_display = array())
  351.     {
  352.         $conn $this->getEntityManager();
  353.         // si pas de tableau
  354.         if (!isset($params_sql['special'])) {
  355.             $params_sql['special'] = array();
  356.         }
  357.         if (!isset($params_sql['params'])) {
  358.             $params_sql['params'] = array();
  359.         }
  360.         // construction de la requête avec le passage de paramètres
  361.         $sql $this->getSQLAides($params_sql);
  362.         // vignettes
  363.         if (empty($params['format_vignette'])) {
  364.             $format_vignette = array('width' => 130'height' => 110'direction' => 'thumb');
  365.         }
  366.         // paramètre de debug
  367.         $dbg = (empty($params_sql['dbg'])) ? array() : $dbg $params_sql['dbg'];
  368.         // executer la requete
  369.         $this->query($sql$dbg);
  370.         $videos = array();
  371.         // donnée entières ?
  372.         if (empty($params_display['alldata'])) {
  373.             $params_display['alldata'] = false;
  374.         }
  375.         // debug
  376.         $start_boucle microtime(true);
  377.         $aides = array();
  378.         // on boucle
  379.         while ($this->fetch()) {
  380.             $idaide $this->idaide;
  381.             if (!empty($params_sql['fields'])) {
  382.                 foreach ($params_sql['fields'] as $f) {
  383.                     $aides[$idaide][$f] = $this->$f;
  384.                 }
  385.             } else {
  386.                 $aides[$idaide] = $this->getInfosAide($idaide, array('get_contact' => true'get_aidecontact' => true));
  387.                 $aides[$idaide]['description_courte'] = $this->cutSentence(strip_tags($aides[$idaide]['description']), 45true);
  388.             }
  389.         }
  390.         // debug de la boucle
  391.         if ($this->isTraceMode('list_object')) {
  392.             $this->setTraceInfos(array(
  393.                 'execution_time_boucle' => microtime(true) - $start_boucle,
  394.                 'nb_occurence' => count($aides),
  395.                 'dbg' => $dbg,
  396.             ));
  397.         }
  398.         $this->free();
  399.         // grouper par contact
  400.         if (!empty($params_display['group_by_contact']) && !empty($aides)) {
  401.             foreach ($aides as $k => $v) {
  402.                 $aides_by_contact[$v['contact']['idcontact']] = $v['contact'];
  403.                 $aides_by_contact[$v['contact']['idcontact']]['profile_picture'] = $conn->getRepository(Contacts::class)->getVignetteContact($v['contact']['idcontact'], array(), 'class_pp');
  404.                 if (strpos($aides_by_contact[$v['contact']['idcontact']]['profile_picture'], 'normal-def.jpg') !== false) {
  405.                     $aides_by_contact[$v['contact']['idcontact']]['profile_picture'] = $_ENV['URL_THNET'] . '/images/menu/interface/no_contact-100x100.png';
  406.                 }
  407.             }
  408.             return $aides_by_contact;
  409.         }
  410.         // grouper par type d'aides
  411.         if (!empty($params_display['groupe_by_type']) && !empty($aides)) {
  412.             foreach ($aides as $k => $v) {
  413.                 if (empty($aides_by_type[$this->getAideTypes($v['type_aide'], falsetrue)]['type_aide'])) {
  414.                     $aides_by_type[$this->getAideTypes($v['type_aide'], falsetrue)] = array(
  415.                         'type_aide' => $v['type_aide'],
  416.                         'type_aide_label' => $this->getAideTypes($v['type_aide'], truefalse),
  417.                     );
  418.                 }
  419.                 $aides_by_type[$this->getAideTypes($v['type_aide'], falsetrue)]['datas'][$v['idaide']] = $v;
  420.             }
  421.             return $aides_by_type;
  422.         }
  423.         return $aides;
  424.     }
  425.     // }}}
  426.     //  {{{ countListAides()
  427.     /** Compter la liste des aides
  428.      *
  429.      * @access   public
  430.      * @param array $params_sql paramètre pour la requete SQL
  431.      * @param bool $debug mode débugage
  432.      * @return   int
  433.      */
  434.     public function countListAides($params_sql null$debug false)
  435.     {
  436.         // si pas de limite => tout
  437.         if (empty($params_sql['limit'])) {
  438.             $params_sql['limit'] = array('all');
  439.         }
  440.         $params_sql['special']['count_only'] = true;
  441.         // construction de la requête avec le passage de paramètres
  442.         return $this->queryOne($this->getSQLAides($params_sql$debug));
  443.     }
  444.     // }}}
  445.     //  {{{ getSQLAides()
  446.     /** Générer la requete standard pour des aides
  447.      *
  448.      * @access   public
  449.      * @param array $aueru Les paramètres pour la requete
  450.      * @param bool $debug afficher la requête
  451.      * @return   string
  452.      */
  453.     public function getSQLAides($query = array(), $debug false)
  454.     {
  455.         // on prepare les tableaux
  456.         foreach (array('select''from''where''order''group''limit') as $t) {
  457.             if (!empty($query[$t])) {
  458.                 if (!is_array($query[$t])) {
  459.                     $query[$t][] = $query[$t];
  460.                 } else {
  461.                     $query[$t] = $query[$t];
  462.                 }
  463.             } else {
  464.                 $query[$t] = array();
  465.             }
  466.         }
  467.         // champs par défaut
  468.         $this->addSQLParams('select'$query, array(
  469.             array('aides' => '*')
  470.         ));
  471.         $this->addSQLParams('from'$query, array(
  472.             'contacts',
  473.         ));
  474.         $this->addSQLParams('join'$query, array(
  475.             'aides.`idcontact`' => 'contacts.`idcontact`',
  476.         ));
  477.         // publié ou pas
  478.         if (empty($query['publish']) && $_ENV['CHECK_IF_ONLINE']) {
  479.             $this->addSQLParams('where'$query, array(
  480.                 array('aides''publish'1)
  481.             ));
  482.         } elseif (!empty($query['publish'])) {
  483.             $this->addSQLParams('where'$query, array(
  484.                 array('aides''publish'$query['publish'])
  485.             ));
  486.         }
  487.         // recherche par liaison via text_aide
  488.         if (!empty($query['special']['idtexts']) || !empty($query['special']['text_aide'])) {
  489.             $this->addSQLParams('from'$query, array(
  490.                 'text_aide',
  491.             ));
  492.             // jointure entre les 3 tables
  493.             $this->addSQLParams('join'$query, array(
  494.                 'aides.`idaide`' => 'text_aide.`idaide`',
  495.             ));
  496.         }
  497.         if (!empty($query['special']['idtexts'])) {
  498.             if (is_array($query['special']['idtexts'])) {
  499.                 $this->addSQLParams('where'$query, array(
  500.                     array('text_aide''idtext'$query['special']['idtexts']),
  501.                 ));
  502.             } else {
  503.                 $this->addSQLParams('group'$query'no');
  504.                 $this->addSQLParams('distinct'$query'no');
  505.                 $this->addSQLParams('select'$query, array(
  506.                     array('text_aide' => '*')
  507.                 ));
  508.             }
  509.         }
  510.         // recherche des aides d'un contact
  511.         if (!empty($query['special']['aides']['idcontacts'])) {
  512.             $this->addSQLParams('where'$query, array(
  513.                 array('aides''idcontact'$query['special']['aides']['idcontacts']),
  514.             ));
  515.         }
  516.         // recherche par type
  517.         if (!empty($query['special']['type_aides'])) {
  518.             $query['special']['type_aide'] = $query['special']['type_aides'];
  519.         }
  520.         if (!empty($query['special']['type_aide'])) {
  521.             $this->addSQLParams('where'$query, array(
  522.                 array('aides''type_aide'$query['special']['type_aide']),
  523.             ));
  524.         }
  525.         // recherche par type
  526.         if (!empty($query['special']['idaidecontact'])) {
  527.             $this->addSQLParams('where'$query, array(
  528.                 array('aides''idaidecontact'$query['special']['idaidecontact']),
  529.             ));
  530.         }
  531.         // si object => liaison
  532.         if (!empty($query['special']['contact_aide']) || !empty($query['special']['idcontacts'])) {
  533.             $this->addSQLParams('from'$query, array(
  534.                 'contact_aide',
  535.             ));
  536.             // jointure entre les 3 tables
  537.             $this->addSQLParams('join'$query, array(
  538.                 'aides.`idaide`' => 'contact_aide.`idaide`',
  539.             ));
  540.         }
  541.         // recherche par liaison via contact_aide
  542.         if (!empty($query['special']['idcontacts'])) {
  543.             $this->addSQLParams('where'$query, array(
  544.                 array('contact_aide''idcontact'$query['special']['idcontacts']),
  545.             ));
  546.         }
  547.         // si object => liaison
  548.         if (!empty($query['special']['spectacle_aide']) || !empty($query['special']['idspectacles'])) {
  549.             $this->addSQLParams('from'$query, array(
  550.                 'spectacle_aide',
  551.             ));
  552.             // jointure entre les 3 tables
  553.             $this->addSQLParams('join'$query, array(
  554.                 'aides.`idaide`' => 'spectacle_aide.`idaide`',
  555.             ));
  556.         }
  557.         // recherche par liaison via _aide
  558.         if (!empty($query['special']['idspectacles'])) {
  559.             $this->addSQLParams('where'$query, array(
  560.                 array('spectacle_aide''idspectacle'$query['special']['idspectacles']),
  561.             ));
  562.         }
  563.         return $this->getSQLObject($query);
  564.     }
  565.     // }}}
  566.     //  {{{ countAides()
  567.     /** Compter la liste des aides nominations ou laureats
  568.      *
  569.      * @access   public
  570.      * @param array $params_sql paramètre pour la requete SQL
  571.      * @param bool $debug mode débugage
  572.      * @return   int
  573.      */
  574.     public function countAides($params_sql null$debug false)
  575.     {
  576.         $nb 0;
  577.         foreach (array('spectacle''text''person''contact') as $t) {
  578.             $sql 'SELECT COUNT(' $t '_aide.`idaide`)
  579.                     FROM aides
  580.                     JOIN ' $t '_aide ON ' $t '_aide.`idaide`=aides.`idaide`
  581.                     WHERE aides.`idcontact`=' . (int)$params_sql['special']['aides']['idcontacts'] . '
  582.                     AND aides.`type_aide`=' . (int)$params_sql['special']['type_aide'] . ' ';
  583.             $nb $nb $this->queryOne($sql);
  584.         }
  585.         return $nb;
  586.     }
  587.     // }}}
  588.     //  {{{ getAides()
  589.     /** Retourne des listes des aides
  590.      *
  591.      * Retourne des listes de aides au format "standard""
  592.      *
  593.      * @access   public
  594.      * @return   array
  595.      */
  596.     public function getAides()
  597.     {
  598.         $sql 'SELECT idaide,aide
  599.                 FROM ' $this->__table ' WHERE 1 ';
  600.         return $this->queryAll($sql, array(), nulltrue);
  601.     }
  602.     // }}}
  603.     //  {{{ getAideTypes()
  604.     /** Retourne des listes des types
  605.      *
  606.      * Retourne des listes de type d'aide'
  607.      *
  608.      * @access   public
  609.      * @return   array
  610.      */
  611.     public function getAideTypes($type_aide null$label true$name false$params = array())
  612.     {
  613.         $types_aide = array(
  614.             => array(
  615.                 'label' => 'Aide/soutien',
  616.                 'contact_link' => '',
  617.                 'name' => 'aides',
  618.             ),
  619.             => array(
  620.                 'label' => 'Lauréat',
  621.                 'contact_link' => 'laureats',
  622.                 'name' => 'prix',
  623.             ),
  624.             => array(
  625.                 'label' => 'Nomination',
  626.                 'contact_link' => 'nominations',
  627.                 'name' => 'nomination',
  628.             ),
  629.             => array(
  630.                 'label' => 'Sélection',
  631.                 'contact_link' => 'selections',
  632.                 'name' => 'selection',
  633.             )
  634.         );
  635.         if ($label) {
  636.             foreach ($types_aide as $k => $v) {
  637.                 $types_aide_label[$k] = $v['label'];
  638.             }
  639.             $types_aide $types_aide_label;
  640.         }
  641.         if ($name) {
  642.             foreach ($types_aide as $k => $v) {
  643.                 $types_aide_label[$k] = $v['name'];
  644.             }
  645.             $types_aide $types_aide_label;
  646.         }
  647.         if (!empty($type_aide)) {
  648.             if (isset($types_aide[$type_aide])) {
  649.                 return $types_aide[$type_aide];
  650.             } else {
  651.                 return null;
  652.             }
  653.         }
  654.         return $types_aide;
  655.     }
  656.     // }}}
  657.     // {{{ getAidesByYearContact()
  658.     /** Récupérer les derniers laureats
  659.      *
  660.      *
  661.      * @access public
  662.      * @return array
  663.      */
  664.     public function getAidesByYearContact($idcontact$periode 'current'$type_aide 0$params_display = array())
  665.     {
  666.         $types_object = array(
  667.             'text' => array('name' => 'Les textes'),
  668.             'spectacle' => array('name' => 'Les spectacles'),
  669.             'person' => array('name' => 'Les artistes'),
  670.         );
  671.         $aides['nb_laureats'] = 0;
  672.         $conn $this->getEntityManager();
  673.         foreach ($types_object as $t => $v) {
  674.             // récupèrer les prix associés au contact
  675.             $object_aide $conn->getRepository('TheatreCore\Entity\\' ucfirst($t) . 'Aide');
  676.             // si current, trouver l'année de l'aide la plus proche
  677.             if ($periode == 'current') {
  678.                 $params_sql_year_aide = array(
  679.                     'special' => array(
  680.                         'aides' => array(
  681.                             'idcontacts' => $idcontact,
  682.                             'type_aides' => array($type_aide), // Prix
  683.                         ),
  684.                     ),
  685.                     'limit' => array(01),
  686.                     'dbg' => array($t '_year_aide''Année la plus proche de ' $t ' lauréats'),
  687.                 );
  688.                 $years $object_aide->{'getList' ucfirst($t) . 'Aide'}($params_sql_year_aide);
  689.                 foreach ($years as $year) {
  690.                     $periode $year['year_start'];
  691.                     break;
  692.                 }
  693.             }
  694.             $params_sql_aide = array(
  695.                 'special' => array(
  696.                     'aides' => array(
  697.                         'idcontacts' => $idcontact,
  698.                         'type_aides' => array($type_aide), // Prix
  699.                     ),
  700.                 ),
  701.                 'dbg' => array($t '_aide''Nombre de ' $t ' lauréats'),
  702.             );
  703.             // compter le nombre total de lauréats
  704.             $nb_list $object_aide->{'countList' ucfirst($t) . 'Aide'}($params_sql_aide);
  705.             // trouver les nominations de cette année
  706.             $params_sql_aide['special']['period']['year'] = $periode;
  707.             $aides[$t] = $object_aide->{'getList' ucfirst($t) . 'Aide'}($params_sql_aide$params_display);
  708.             $aides['year'] = $periode;
  709.             $aides['nb_laureats'] = count($aides[$t]) + $aides['nb_laureats'];
  710.         }
  711.         return $aides;
  712.     }
  713.     // }}}
  714.     // {{{ countTextAuthors()
  715.     /** Compter les auteurs ayant reçus une aide pour leurs texts
  716.      *
  717.      *
  718.      * @access public
  719.      * @return array
  720.      */
  721.     public function countTextAuthors($idaidecontact null)
  722.     {
  723.         $sql 'SELECT COUNT(DISTINCT(ta.`idperson`)) as total
  724.                 FROM text_aide tai JOIN aides ai
  725.                 ON ai.`idaide`=tai.`idaide`JOIN text_author ta
  726.                 ON ta.`idtext`=tai.`idtext`
  727.                 WHERE ai.`idaidecontact`=' $idaidecontact;
  728.         $res $this->queryOne($sql);
  729.         if ($res) {
  730.             return $res;
  731.         } else {
  732.             return 0;
  733.         }
  734.     }
  735.     // }}}
  736.     // {{{ countTexts()
  737.     /** Compter les texts qui ont reçus une aide
  738.      *
  739.      *
  740.      * @access public
  741.      * @return array
  742.      */
  743.     public function countTexts($idaidecontact null)
  744.     {
  745.         $sql 'SELECT COUNT(DISTINCT(tai.`idtext`))
  746.                 FROM text_aide tai JOIN aides ai
  747.                 ON ai.`idaide`=tai.`idaide`
  748.                 WHERE ai.`idaidecontact`=' $idaidecontact;
  749.         $res $this->queryOne($sql);
  750.         if ($res) {
  751.             return $res;
  752.         } else {
  753.             return 0;
  754.         }
  755.     }
  756.     // }}}
  757.     // {{{ getAuthorsTexts()
  758.     /** trouver les auteurs ayant reçus une aide pour leurs texts
  759.      *
  760.      *
  761.      * @access public
  762.      * @return array
  763.      */
  764.     public function getAuthorsTexts($idaidecontact null)
  765.     {
  766.         $sql 'SELECT p.`idperson`,p.`lastname`,p.`firstname`,p.`url_clean`, LEFT(p.`lastname`, 1) AS letter
  767.                 FROM text_aide tai
  768.                 JOIN aides ai ON ai.`idaide`=tai.`idaide`
  769.                 JOIN text_author ta ON ta.`idtext`=tai.`idtext`
  770.                 JOIN persons p ON ta.`idperson`=p.`idperson`
  771.                 WHERE ai.`idaidecontact`=' $idaidecontact '
  772.                 GROUP BY p.`idperson`';
  773.         $authors $this->queryAll($sql);
  774.         if (!empty($authors)) {
  775.             return $authors;
  776.         } else {
  777.             return array();
  778.         }
  779.     }
  780.     // }}}
  781.     // {{{ countTextsSpectacles()
  782.     /** Compter les spectacles montés à partir d'un texte ayant bénéficié de l'aide à la création
  783.      *
  784.      *
  785.      * @access public
  786.      * @return array
  787.      */
  788.     public function countTextsSpectacles($idaidecontact null)
  789.     {
  790.         $sql 'SELECT COUNT(DISTINCT(ts.`idspectacle`))
  791.                 FROM text_spectacle ts
  792.                     JOIN text_aide tai  ON tai.`idtext`=ts.`idtext`
  793.                     JOIN aides ai ON ai.`idaide`=tai.`idaide`
  794.                 WHERE ai.`idaidecontact`=' $idaidecontact;
  795.         try {
  796.             $res $this->queryOne($sql);
  797.             return $res;
  798.         } catch (\Throwable $e) {
  799.             return 0;
  800.         }
  801.     }
  802.     // }}}
  803. }