vendor/theatre/core/src/Repository/BannieresRepository.php line 499

Open in your IDE?
  1. <?php
  2. namespace TheatreCore\Repository;
  3. use TheatreCore\Entity\Bannieres;
  4. use TheatreCore\Traits\TheatreTrait;
  5. use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
  6. use Doctrine\Persistence\ManagerRegistry;
  7. use Symfony\Contracts\Translation\TranslatorInterface;
  8. /**
  9.  * BannieresRepository
  10.  *
  11.  * This class was generated by the Doctrine ORM. Add your own custom
  12.  * repository methods below.
  13.  */
  14. class BannieresRepository extends ServiceEntityRepository
  15. {
  16.     use TheatreTrait;
  17.     private $em;
  18.     public $__table;
  19.     public $__table_object;
  20.     public $__idtable;
  21.     public function __construct(ManagerRegistry $registryTranslatorInterface $tr)
  22.     {
  23.         parent::__construct($registryBannieres::class);
  24.         $this->__table $this->getClassMetadata()->getTableName();
  25.         $this->__table_object $this->getClassMetadata()->name;
  26.         $this->__idtable $this->getClassMetadata()->getSingleIdentifierFieldName();
  27.         $this->translator $tr;
  28.     }
  29.     //  {{{ findData()
  30.     /** Recherche d'banniere
  31.      *
  32.      * Permet de rechercher des bannieres selon différents critères
  33.      *
  34.      * @access  public
  35.      * @see     Theatre::find()
  36.      */
  37.     public function findData($idclassification null)
  38.     {
  39.         // parametres
  40.         if (isset($_REQUEST['keywords']) && $_REQUEST['keywords'] != 'nom') {
  41.             $keywords filter_var(trim($_REQUEST['keywords']));
  42.         }
  43.         if (isset($_REQUEST['idbanniere']) && $this->my_is_int($_REQUEST['idbanniere'])) {
  44.             $idbanniere = (int)$_REQUEST['idbanniere'];
  45.         }
  46.         $query $this->createQueryBuilder('e');
  47.         if ($this->getCount()) {
  48.             $query->select('COUNT(e.idbanniere)');
  49.             $this->setCount(false);
  50.             return $query;
  51.         }
  52.         // query perso
  53. //        $query = 'SELECT * FROM '.$this->__table.'
  54. //                    WHERE  1';
  55.         //recherche stricte par id
  56.         if (!empty($idbanniere)) {
  57.             //$query .= ' AND cl.idbanniere='.(int)$idbanniere;
  58.             $query->andWhere('e.idbanniere = :idbanniere')->setParameter(':idbanniere'$idbanniere);
  59.         } else {
  60.             //mots cles
  61.             if (!empty($keywords)) {
  62.                 //$query .= ' AND title LIKE \'%'.$this->escape($keywords).'%\' ';
  63.                 $query->andWhere('e.title LIKE \'%:keywords%\'')->setParameter(':keywords'$keywords);
  64.             }
  65.         }
  66.         $query->orderBy('e.idbanniere''desc');
  67.         // on lance la recherche
  68.         return $query->getQuery();
  69.     }
  70.     // }}}
  71.     //  {{{ setToArray()
  72.     /** Liste des bannieres dans un tableau associatif
  73.      *
  74.      * Tableau associatif notament utilisé pour lister les informations sur des bannieres
  75.      * Utile pour générer les tableaux HTML de listes de bannieres
  76.      *
  77.      * @access  public
  78.      * @return  array
  79.      * @see     findData()
  80.      */
  81.     public function setToArray($spec true)
  82.     {
  83.         if ($spec == true) {
  84.             $this->findData();
  85.         }
  86.         $values = array();
  87.         $color null;
  88.         $nb 0;
  89.         while ($this->fetch()) {
  90.             $values[$nb] = $this->getInfosBanniere(null);
  91.             $values[$nb]['id'] = $this->idbanniere;
  92.             // couleur de ligne alternative
  93.             $color $this->colorAlternate($color);
  94.             $values[$nb]['colorline'] = $color;
  95.             $nb++;
  96.         }
  97.         return $values;
  98.     }
  99.     // }}}
  100.     //  {{{ orderByDefaut()
  101.     /** Classement par défaut
  102.      *
  103.      * Défini le tri par défaut pour les requêtes de type SELECT
  104.      *
  105.      * @access public
  106.      * @return string
  107.      */
  108.     public function orderByDefaut($order null)
  109.     {
  110.         // tri par défaut
  111.         if (empty($order)) {
  112.             $order 'idbanniere';
  113.         }
  114.         return $order;
  115.     }
  116.     // }}}
  117.     //  {{{ getInfosBanniere()
  118.     /** Informations sur une banniere
  119.      *
  120.      * @access public
  121.      * @param int $idbanniere Identifiant de l'banniere
  122.      * @return array
  123.      */
  124.     public function getInfosBanniere($idbanniere null$params = array())
  125.     {
  126.         $infos = array();
  127.         ////////////// infos de la table
  128.         if (empty($this->idbanniere)) {
  129.             $this->get($idbanniere);
  130.         }
  131.         $infos += array(
  132.             'idbanniere' => $this->idbanniere,
  133.             'title' => $this->title,
  134.             'imgfile' => $this->imgfile,
  135.             'url_redirect' => $this->url_redirect,
  136.             'description' => $this->description,
  137.             'date_start' => $this->date_start,
  138.             'date_end' => $this->date_end,
  139.             'dateupdate' => $this->dateupdate,
  140.             'dateinsert' => $this->dateinsert,
  141.             'publish' => $this->publish,
  142.             'is_thnet' => $this->is_thnet,
  143.             'is_bottom' => $this->is_bottom,
  144.             'is_region' => $this->is_region,
  145.             'is_sponsored' => $this->is_sponsored,
  146.             'order' => $this->order,
  147.             'region' => $this->region,
  148.             'is_swf' => $this->is_swf,
  149.         );
  150.         $infos['nameview'] = $this->title;
  151.         return $infos;
  152.     }
  153.     // }}}
  154.     //  {{{ getObjectTitle()
  155.     /** Infos de l'item recherché
  156.      *
  157.      *
  158.      * @access public
  159.      * @param int $idobject Identifiant de l'item
  160.      * @param array $infos_object Informations pour construire le titre
  161.      * @param array $params Paramétres supplémentaires
  162.      * @return string|array
  163.      */
  164.     public function getObjectTitle($idobject null$infos_object = array(), $params = array())
  165.     {
  166.         if (!$idobject && isset($this->idbanniere)) $idobject $this->idbanniere;
  167.         // champs
  168.         $fields = array('idbanniere''title''url_redirect');
  169.         if (!empty($infos_object)) {
  170.             foreach ($fields as $k => $v) {
  171.                 if (array_key_exists($v$infos_object)) {
  172.                     $infos[$v] = $infos_object[$v];
  173.                 } else {
  174.                     $infos[$v] = '';
  175.                 }
  176.             }
  177.         } else {
  178.             //charger les infos que si necessaire
  179.             if (empty($this->title)) {
  180.                 $sql 'SELECT ' implode(','$fields) . '
  181.                         FROM ' $this->__table '
  182.                         WHERE ' $this->__idtable '=' $idobject;
  183.                 $infos $this->queryRow($sql);
  184.             } else {
  185.                 foreach ($fields as $k => $v) {
  186.                     if (isset($this->$v) && $this->$v != '') {
  187.                         $infos[$v] = trim($this->$v);
  188.                     } else {
  189.                         $infos[$v] = '';
  190.                     }
  191.                 }
  192.             }
  193.         }
  194.         // renvoyer un array plutôt que le titre (utile si on veux l'url)
  195.         if (array_key_exists('return_array'$params)) {
  196.             return $infos;
  197.         }
  198.         return $infos['title'];
  199.     }
  200.     // }}}
  201.     //  {{{ getRelationsArray()
  202.     /** Décrit les relations de l'objet
  203.      *
  204.      * @access  public
  205.      * @param string|int $type si on souhaite retourner uniquement un type precis
  206.      * @see     Theatre::getLinkedObject()
  207.      */
  208.     public function getRelationsArray($type)
  209.     {
  210.         // récupérer les relations communes
  211.         $array_types parent::getRelationsArray('all');
  212.         // retourne uniquement un type précis
  213.         if ($type == 'all') {
  214.             return $array_types;
  215.         }
  216.         if (!empty($array_types[$type])) {
  217.             $array_types[$type]['type'] = $type;
  218.             return $array_types[$type];
  219.         } else {
  220.             return null;
  221.         }
  222.     }
  223.     // }}}
  224.     //  {{{ getListSearch()
  225.     /** Liste des bannieres
  226.      *
  227.      * Pour les champs Ajax de relations et les recherches diverses
  228.      *
  229.      * @access  public
  230.      * @param string $lettres Pour la recherche alphabetique
  231.      * @param string $type Pour le type recherche (editeurs, revues...)
  232.      * @param string $keywords Recherche par mots cles
  233.      * @return  array
  234.      */
  235.     public function getListSearch($lettre$type null$keywords null)
  236.     {
  237.         $sql 'SELECT idbanniere, title
  238.                  FROM ' $this->__table '
  239.                  WHERE 1 ';
  240.         // selection par ordre alpha
  241.         if (!empty($lettre) && $lettre != 'tous') {
  242.             $sql_where[] = array('LOWER(LEFT(LTRIM(banniere),1))=\'' $this->escape($lettre) . '\'');
  243.         }
  244.         // recherche avec un mot cle
  245.         $list $this->splitKeywords($keywords);
  246.         if ($list) {
  247.             if (!empty($list[$this->IDSTR])) {
  248.                 // mots clés
  249.                 foreach ($list[$this->IDSTR] as $s) {
  250.                     $sql_more_name[] = 'title LIKE \'%' $s '%\'';
  251.                 }
  252.                 $sql_where[] = array('(' join(' OR '$sql_more_name) . ')');
  253.             }
  254.             if (!empty($list[$this->IDNUM])) {
  255.                 // recherche par numéro d'id pour les mots clés numériques
  256.                 $sql_where[] = array('idbanniere IN (' implode(','$list[$this->IDNUM]) . ')''OR');
  257.             }
  258.         }
  259.         foreach ($sql_where as $k => $v) {
  260.             if (!empty($v[1])) {
  261.                 $sql .= ' ' $v[1] . ' ' $v[0];
  262.             } else {
  263.                 $sql .= ' AND ' $v[0];
  264.             }
  265.         }
  266.         $sql .= ' ORDER BY title';
  267.         $this->query($sql);
  268.         $r = array();
  269.         while ($this->fetch()) {
  270.             $r[$this->idbanniere] = $this->banniere;
  271.             // si trouvé par id, on l'affiche en fin de titre
  272.             if (!empty($list[$this->IDNUM]) && in_array($this->idbanniere$list[$this->IDNUM])) {
  273.                 $r[$this->idbanniere] .= ' - n°' $this->idbanniere;
  274.             }
  275.         }
  276.         $this->free();
  277.         return $r;
  278.     }
  279.     // }}}
  280.     //  {{{ getListBannieres()
  281.     /** Retourne des listes des bannieres
  282.      *
  283.      * Retourne des listes de bannieres au format "standard""
  284.      *
  285.      * @access   public
  286.      * @param array $params_sql paramètre pour la requete SQL
  287.      * @param array $format_vignette de la vignette si pas standard
  288.      * @param array $params_display paramètre pour l'affichage
  289.      * @return   array
  290.      */
  291.     public function getListBannieres($params_sql null$format_vignette = array(), $params_display = array())
  292.     {
  293.         // si pas de tableau
  294.         if (!isset($params_sql['special'])) {
  295.             $params_sql['special'] = array();
  296.         }
  297.         if (!isset($params_sql['params'])) {
  298.             $params_sql['params'] = array();
  299.         }
  300.         // construction de la requête avec le passage de paramètres
  301.         $sql $this->getSQLBannieres($params_sql);
  302.         // vignettes
  303.         if (empty($params['format_vignette'])) {
  304.             $format_vignette = array('width' => 130'height' => 110'direction' => 'thumb');
  305.         }
  306.         // paramètre de debug
  307.         $dbg = (empty($params_sql['dbg'])) ? array() : $dbg $params_sql['dbg'];
  308.         // executer la requete
  309.         $this->query($sql$dbg);
  310.         $videos = array();
  311.         // donnée entières ?
  312.         if (empty($params_display['alldata'])) {
  313.             $params_display['alldata'] = false;
  314.         }
  315.         // debug
  316.         $start_boucle microtime(true);
  317.         $bannieres = array();
  318.         // on boucle
  319.         while ($this->fetch()) {
  320.             $idbanniere $this->idbanniere;
  321.             if (!empty($params_sql['fields'])) {
  322.                 foreach ($params_sql['fields'] as $f) {
  323.                     $bannieres[$idbanniere][$f] = $this->$f;
  324.                 }
  325.             } else {
  326.                 $bannieres[$idbanniere] = $this->getInfosBanniere($idbanniere);
  327.                 $bannieres[$idbanniere]['description_courte'] = $this->cutSentence(strip_tags($bannieres[$idbanniere]['description']), 45true);
  328.             }
  329.         }
  330.         // debug de la boucle
  331.         if ($this->isTraceMode('list_object')) {
  332.             $this->setTraceInfos(array(
  333.                 'execution_time_boucle' => microtime(true) - $start_boucle,
  334.                 'nb_occurence' => count($bannieres),
  335.                 'dbg' => $dbg,
  336.             ));
  337.         }
  338.         $this->free();
  339.         return $bannieres;
  340.     }
  341.     // }}}
  342.     //  {{{ getSQLBannieres()
  343.     /** Générer la requete standard pour des bannieres
  344.      *
  345.      * @access   public
  346.      * @param array $aueru Les paramètres pour la requete
  347.      * @param bool $debug afficher la requête
  348.      * @return   string
  349.      */
  350.     public function getSQLBannieres($query = array(), $debug false)
  351.     {
  352.         // on prepare les tableaux
  353.         foreach (array('select''from''where''order''group''limit') as $t) {
  354.             if (!empty($query[$t])) {
  355.                 if (!is_array($query[$t])) {
  356.                     $query[$t][] = $query[$t];
  357.                 } else {
  358.                     $query[$t] = $query[$t];
  359.                 }
  360.             } else {
  361.                 $query[$t] = array();
  362.             }
  363.         }
  364.         // champs par défaut
  365.         $this->addSQLParams('select'$query, array(
  366.             array('bannieres' => '*')
  367.         ));
  368.         // publié ou pas
  369.         if (empty($query['publish']) && $_ENV['CHECK_IF_ONLINE']) {
  370.             $this->addSQLParams('where'$query, array(
  371.                 array('bannieres''publish'1)
  372.             ));
  373.         } elseif (!empty($query['publish'])) {
  374.             $this->addSQLParams('where'$query, array(
  375.                 array('bannieres''publish'$query['publish'])
  376.             ));
  377.         }
  378.         return $this->getSQLObject($query);
  379.     }
  380.     // }}}
  381.     //  {{{ getCurrentBanniere()
  382.     /** Récupère la bannière courante */
  383.     public function getCurrentBanniere($exclude = array()): array
  384.     {
  385.         $sql 'SELECT * FROM ' $this->__table '
  386.                 WHERE publish=1
  387.                 AND valid=1
  388.                 AND (is_bottom=0 OR is_bottom IS NULL)
  389.                 AND (is_region=0 OR is_region IS NULL)
  390.                 AND (is_national=0 OR is_national IS NULL)
  391.                 AND date_start<=NOW()
  392.                 AND date_end>=NOW()
  393.                 LIMIT 0,1';
  394.         return $this->queryRow($sql) ?: [];
  395.     }
  396.     // }}}
  397.     //  {{{ getRegionBanniere()
  398.     /** Récupèrer la bannière courante des regions
  399.      *
  400.      * @access   public
  401.      * @return   array
  402.      */
  403.     public function getRegionBanniere($idbigregion null)
  404.     {
  405.         $dateNow = new \DateTime();
  406.         $sql 'SELECT * FROM ' $this->__table '
  407.                 WHERE publish=1
  408.                 AND valid=1
  409.                 AND is_region=1
  410.                 AND date_start<=\'' $dateNow->format('Y-m-d') . '\'
  411.                 AND date_end>=\'' $dateNow->format('Y-m-d') . '\'';
  412.         //setDebug($sql);
  413.         if (!is_null($idbigregion)) {
  414.             if (is_numeric($idbigregion)) {
  415.                 $sql .= ' AND region = ' . (int)$idbigregion '';
  416.             } else {
  417.                 $sql .= ' AND country = "' $idbigregion '"';
  418.             }
  419.         } else {
  420.             $sql .= ' AND (region IS NULL AND country IS NULL)';
  421.         }
  422. //        $sql .= ' LIMIT 0,2';
  423.         $sql .= ' ORDER BY bannieres.order ASC ';
  424.         $res $this->queryAll($sql);
  425.         if ($res) {
  426.             return $res;
  427.         } else {
  428.             return array();
  429.         }
  430.     }
  431.     // }}}
  432.     //  {{{ getNationalBanniere()
  433.     /** Récupèrer la bannière courante des regions au national
  434.      *
  435.      * @access   public
  436.      * @return   array
  437.      */
  438.     public function getNationalBanniere()
  439.     {
  440.         $dateNow = new \DateTime();
  441.         $sql 'SELECT * FROM ' $this->__table '
  442.                 WHERE publish=1
  443.                 AND valid=1
  444.                 AND is_national=1
  445.                 AND date_start<=\'' $dateNow->format('Y-m-d') . '\'
  446.                 AND date_end>=\'' $dateNow->format('Y-m-d') . '\'
  447.                 ORDER BY bannieres.order ASC
  448.                 LIMIT 0,10';
  449.         //setDebug($sql);
  450.         $res $this->queryAll($sql);
  451.         if ($res) {
  452.             return $res;
  453.         } else {
  454.             return array();
  455.         }
  456.     }
  457.     // }}}
  458.     //  {{{ getCurrentBanniere()
  459.     /** Récupère la bannière courante du bas */
  460.     public function getBottomBanniere(): array
  461.     {
  462.         $sql 'SELECT * FROM ' $this->__table '
  463.                 WHERE publish=1
  464.                 AND valid=1
  465.                 AND is_bottom=1
  466.                 AND date_start<=NOW()
  467.                 AND date_end>=NOW()
  468.                 ORDER BY bannieres.order ASC
  469.                 LIMIT 0,10';
  470.         return $this->queryRow($sql) ?: [];
  471.     }
  472.     // }}}
  473. }