vendor/theatre/core/src/Repository/AidecontactsRepository.php line 237

Open in your IDE?
  1. <?php
  2. namespace TheatreCore\Repository;
  3. use TheatreCore\Entity\Aidecontacts;
  4. use TheatreCore\Traits\TheatreTrait;
  5. use TheatreCore\Entity\Aides;
  6. use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
  7. use Doctrine\Persistence\ManagerRegistry;
  8. use Symfony\Contracts\Translation\TranslatorInterface;
  9. /**
  10.  * AidecontactsRepository
  11.  *
  12.  * This class was generated by the Doctrine ORM. Add your own custom
  13.  * repository methods below.
  14.  */
  15. class AidecontactsRepository extends ServiceEntityRepository
  16. {
  17.     use TheatreTrait;
  18.     private $em;
  19.     public $__table;
  20.     public $__table_object;
  21.     public $__idtable;
  22.     public function __construct(ManagerRegistry $registryTranslatorInterface $translator)
  23.     {
  24.         parent::__construct($registryAidecontacts::class);
  25.         $this->__table $this->getClassMetadata()->getTableName();
  26.         $this->__table_object $this->getClassMetadata()->name;
  27.         $this->__idtable $this->getClassMetadata()->getSingleIdentifierFieldName();
  28.         $this->translator $translator;
  29.     }
  30.     //  {{{ findData()
  31.     /** Recherche d'aide
  32.      *
  33.      * Permet de rechercher des aides selon différents critères
  34.      *
  35.      * @access  public
  36.      * @see     Theatre::find()
  37.      */
  38.     public function findData($idclassification null)
  39.     {
  40.         $query $this->createQueryBuilder('e');
  41.         // parametres
  42.         if (isset($_REQUEST['keywords']) && $_REQUEST['keywords'] != 'nom') {
  43.             $keywords filter_var(trim($_REQUEST['keywords']));
  44.         }
  45.         if (isset($_REQUEST['idaidecontact']) && my_is_int($_REQUEST['idaidecontact'])) {
  46.             $idaide = (int)$_REQUEST['idaidecontact'];
  47.         }
  48.         //recherche stricte par id
  49.         if (!empty($idaide)) {
  50.             $query->andWhere(' e.idaidecontact=' . (int)$idaide);
  51.         } else {
  52.             // mots cles
  53.             if (!empty($keywords)) {
  54.                 $query->andWhere(' e.title LIKE \'%' $this->escape($keywords) . '%\' ');
  55.             }
  56.         }
  57.         // on lance la recherche
  58.         return $query->getQuery();
  59.     }
  60.     // }}}
  61.     //  {{{ setToArray()
  62.     /** Liste des aides dans un tableau associatif
  63.      *
  64.      * Tableau associatif notament utilisé pour lister les informations sur des aides
  65.      * Utile pour générer les tableaux HTML de listes de aides
  66.      *
  67.      * @access  public
  68.      * @return  array
  69.      * @see     findData()
  70.      */
  71.     public function setToArray($spec true)
  72.     {
  73.         if ($spec == true) {
  74.             $this->findData();
  75.         }
  76.         $values = array();
  77.         $color null;
  78.         $nb 0;
  79.         while ($this->fetch()) {
  80.             $values[$nb] = $this->getInfosAidecontact($this->idaidecontact);
  81.             $values[$nb]['id'] = $this->idaidecontact;
  82.             // couleur de ligne alternative
  83.             $color $this->colorAlternate($color);
  84.             $values[$nb]['colorline'] = $color;
  85.             $nb++;
  86.         }
  87.         return $values;
  88.     }
  89.     // }}}
  90.     //  {{{ getInfosAidecontact()
  91.     /** Informations sur une catégorie d'aide
  92.      *
  93.      * @access public
  94.      * @param int $idaidecontact Identifiant de la catégorie d'aide
  95.      * @return array
  96.      */
  97.     public function getInfosAidecontact($idaidecontact null$params = array())
  98.     {
  99.         $infos = array();
  100.         ////////////// infos de la table
  101.         if (empty($this->idaidecontact) || $this->idaidecontact != $idaidecontact) {
  102.             $this->loadResult($this->get($idaidecontact));
  103.         }
  104.         $infos += array(
  105.             'idaidecontact' => $this->idaidecontact,
  106.             'title' => $this->title,
  107.             'url_clean' => (!empty($this->urlClean)) ? $this->urlClean $this->url_clean,
  108.             'dateupdate' => $this->dateupdate,
  109.             'dateinsert' => $this->dateinsert,
  110.             'publish' => $this->publish,
  111.         );
  112.         $infos['nameview'] = $this->title;
  113.         return $infos;
  114.     }
  115.     // }}}
  116.     //  {{{ getAidecontacts()
  117.     /** Retourne des listes des genre d'aide
  118.      *
  119.      * Retourne des listes
  120.      *
  121.      * @access   public
  122.      * @return   array
  123.      */
  124.     public function getAidecontacts()
  125.     {
  126.         $sql 'SELECT idaidecontact,title
  127.                 FROM ' $this->__table ' WHERE 1 ';
  128.         return $this->queryAll($sql, array(), nulltrue);
  129.     }
  130.     // }}}
  131.     //  {{{ getListAidecontacts()
  132.     /** les catégories d'aide
  133.      *
  134.      * @access   public
  135.      * @param array $params_sql paramètre pour la requete SQL
  136.      * @return   array
  137.      */
  138.     public function getListAidecontacts($params_sql null$params_display = array())
  139.     {
  140.         $conn $this->getEntityManager();
  141.         // si pas de tableau
  142.         if (!isset($params_sql['special'])) {
  143.             $params_sql['special'] = array();
  144.         }
  145.         if (!isset($params_sql['params'])) {
  146.             $params_sql['params'] = array();
  147.         }
  148.         // construction de la requête avec le passage de paramètres
  149.         $sql $this->getSQLAidecontacts($params_sql);
  150.         // paramètre de debug
  151.         $dbg = (empty($params_sql['dbg'])) ? array() : $dbg $params_sql['dbg'];
  152.         // executer la requete
  153.         $datas $this->query($sql$dbg);
  154.         // debug
  155.         $start_boucle microtime(true);
  156.         $aidecontacts = array();
  157.         $aides $conn->getRepository(Aides::class);
  158.         // on boucle
  159.         foreach ($datas as $value) {
  160.             $this->loadResult($value);
  161.             $aidecontacts[$this->idaidecontact] = $this->getInfosAidecontact();
  162.             $params_sql_aide = array(
  163.                 'special' => array(
  164.                     'idaidecontact' => $this->idaidecontact,
  165.                 ),
  166.                 'fields' => array(
  167.                     'aide''url_clean''idaide''mention_contacts'
  168.                 ),
  169.                 'limit' => array(0100),
  170.                 'dbg' => array('aides_aidescontacts''Les aides associés à aidecontact')
  171.             );
  172.             if (!empty($params_sql['special']['aides']['type_aides'])) {
  173.                 $params_sql_aide['special']['type_aide'] = $params_sql['special']['aides']['type_aides'];
  174.             }
  175.             if (!empty($params_sql['special']['aides']['idcontacts'])) {
  176.                 $params_sql_aide['special']['aides']['idcontacts'] = $params_sql['special']['aides']['idcontacts'];
  177.             }
  178.             if (!empty($params_sql['special']['object'])) {
  179.                 $params_sql_aide['special'][$params_sql['special']['object'] . '_aide'] = true;
  180.             }
  181.             // trouver également les aides associées
  182.             $aidecontacts[$this->idaidecontact]['aides'] = $aides->getListAides($params_sql_aide);
  183.         }
  184.         // debug de la boucle
  185.         if ($this->isTraceMode('list_object')) {
  186.             $this->setTraceInfos(array(
  187.                 'execution_time_boucle' => microtime(true) - $start_boucle,
  188.                 'nb_occurence' => count($aidecontacts),
  189.                 'dbg' => $dbg,
  190.             ));
  191.         }
  192.         $this->free();
  193.         return $aidecontacts;
  194.     }
  195.     // }}}
  196.     //  {{{ countListAidecontacts()
  197.     /** Compter la liste des catégories d'aide
  198.      *
  199.      * @access   public
  200.      * @param array $params_sql paramètre pour la requete SQL
  201.      * @param bool $debug mode débugage
  202.      * @return   int
  203.      */
  204.     public function countListAidecontacts($params_sql null$debug false)
  205.     {
  206.         // si pas de limite => tout
  207.         if (empty($params_sql['limit'])) {
  208.             $params_sql['limit'] = array('all');
  209.         }
  210.         $params_sql['count_only'] = true;
  211.         // construction de la requête avec le passage de paramètres
  212.         return $this->db->queryOne($this->getSQLAidecontacts($params_sql$debug));
  213.     }
  214.     // }}}
  215.     //  {{{ getSQLAidecontacts()
  216.     /** Générer la requete standard pour des catégories d'aide
  217.      *
  218.      * @access   public
  219.      * @param array $aueru Les paramètres pour la requete
  220.      * @param bool $debug afficher la requête
  221.      * @return   string
  222.      */
  223.     public function getSQLAidecontacts($query = array(), $debug false)
  224.     {
  225.         // on prepare les tableaux
  226.         foreach (array('select''from''where''order''group''limit') as $t) {
  227.             if (!empty($query[$t])) {
  228.                 if (!is_array($query[$t])) {
  229.                     $query[$t][] = $query[$t];
  230.                 } else {
  231.                     $query[$t] = $query[$t];
  232.                 }
  233.             } else {
  234.                 $query[$t] = array();
  235.             }
  236.         }
  237.         $this->addSQLParams('distinct'$query'no_primary');
  238.         if (empty($query['group'])) {
  239.             $this->addSQLParams('group'$query'no');
  240.         }
  241.         // champs par défaut
  242.         $this->addSQLParams('select'$query, array(
  243.             array('aidecontacts' => '*'),
  244.             array('aides' => '*')
  245.         ));
  246.         $this->addSQLParams('from'$query, array(
  247.             'aides',
  248.         ));
  249.         $this->addSQLParams('join'$query, array(
  250.             'aides.`idaidecontact`' => 'aidecontacts.`idaidecontact`',
  251.         ));
  252.         // uniquement pour certains objets ?
  253.         if (!empty($query['special']['object'])) {
  254.             $object $query['special']['object'];
  255.             $this->addSQLParams('from'$query, array(
  256.                 $object '_aide',
  257.             ));
  258.             $this->addSQLParams('join'$query, array(
  259.                 'aides.`idaide`' => $object '_aide.`idaide`',
  260.             ));
  261.         } else {
  262.             $object 'text';
  263.         }
  264.         // publié ou pas
  265.         if (empty($query['publish']) && $_ENV['CHECK_IF_ONLINE']) {
  266.             $this->addSQLParams('where'$query, array(
  267.                 array('aides''publish'1)
  268.             ));
  269.         } elseif (!empty($query['publish'])) {
  270.             $this->addSQLParams('where'$query, array(
  271.                 array('aides''publish'$query['publish'])
  272.             ));
  273.         }
  274.         // recherche par contact
  275.         if (!empty($query['special']['aides'])) {
  276.             if (!empty($query['special']['aides']['idcontacts'])) {
  277.                 $this->addSQLParams('where'$query, array(
  278.                     array('aides''idcontact'$query['special']['aides']['idcontacts']),
  279.                 ));
  280.             }
  281.             if (!empty($query['special']['idaidecontact'])) {
  282.                 $this->addSQLParams('where'$query, array(
  283.                     array('aides''idaidecontact'$query['special']['aides']['idaidecontact']),
  284.                 ));
  285.             }
  286.             if (!empty($query['special']['aides']['type_aides'])) {
  287.                 $this->addSQLParams('where'$query, array(
  288.                     array('aides''type_aide'$query['special']['aides']['type_aides']),
  289.                 ));
  290.             }
  291.             if (!empty($query['aide_is_null'])) {
  292.                 $query['where'][] = ' AND (aides.aide != "" OR aides.aide IS NULL)';
  293.             } else {
  294.                 $this->addSQLParams('where'$query, array(
  295.                     array('aides''aide''''AND''!='),
  296.                 ));
  297.             }
  298.         }
  299.         // pour un texte
  300.         if (!empty($query['idtext'])) {
  301.             $this->addSQLParams('where'$query, array(
  302.                 array('text_aide''idtext'$query['idtext'])
  303.             ));
  304.         }
  305.         // recherche par année
  306.         if (!empty($query['special']['period'])) {
  307.             if (!empty($query['special']['period']['year'])) {
  308.                 $this->addSQLParams('where_more'$query' AND YEAR(' $object '_aide.`date_start`)=' $query['special']['period']['year']);
  309.             }
  310.             if (!empty($query['special']['period']['years'])) {
  311.                 $where_more ' AND YEAR(' $object '_aide.`date_start`) BETWEEN ' $query['special']['period']['years']['start'] . ' AND ' $query['special']['period']['years']['end'];
  312.                 $this->addSQLParams('where_more'$query$where_more);
  313.             }
  314.         }
  315.         if (empty($query['special']['no_order'])) {
  316.             $this->addSQLParams('order'$query, array(
  317.                 array($object '_aide' => 'date_start'),
  318.             ));
  319.         }
  320.         return $this->getSQLObject($query);
  321.     }
  322.     // }}}
  323. }