vendor/theatre/core/src/Repository/PodcastsRepository.php line 250

Open in your IDE?
  1. <?php
  2. namespace TheatreCore\Repository;
  3. use Doctrine\ORM\AbstractQuery;
  4. use TheatreCore\Classes\Images\Images;
  5. use TheatreCore\Entity\Files;
  6. use TheatreCore\Entity\Podcasts;
  7. use TheatreCore\Traits\TheatreTrait;
  8. use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
  9. use Doctrine\Persistence\ManagerRegistry;
  10. use DateInterval;
  11. use DateTime;
  12. /**
  13.  * PodcastsRepository
  14.  *
  15.  * This class was generated by the Doctrine ORM. Add your own custom
  16.  * repository methods below.
  17.  */
  18. class PodcastsRepository extends ServiceEntityRepository
  19. {
  20.     use TheatreTrait {
  21.         getRelationsArray as protected getRelationsArrayTrait;
  22.     }
  23.     private $em;
  24.     public $__table;
  25.     public $__table_object;
  26.     public $__idtable;
  27.     public function __construct(ManagerRegistry $registryImages $images)
  28.     {
  29.         parent::__construct($registryPodcasts::class);
  30.         $this->__table $this->getClassMetadata()->getTableName();
  31.         $this->__table_object $this->getClassMetadata()->name;
  32.         $this->__idtable $this->getClassMetadata()->getSingleIdentifierFieldName();
  33.         $this->images $images;
  34.     }
  35.     // les relations
  36.     public $array_types = array('podcast_spectacle''podcast_contact''podcast_person''podcast_text');
  37.     public $franceinter_types = array(=> 'franceculture'=> 'franceinter');
  38.     //  {{{ findData()
  39.     /** Recherche des podcasts
  40.      *
  41.      * Permet de rechercher des podcasts en fonction de certains critères :
  42.      * la première lettre, un bout du nom, le type de multimedia, si il est en ligne ou pas
  43.      *
  44.      * @access  public
  45.      * @see     Theatre::find()
  46.      */
  47.     public function findData($publish null$keywords null$idobject null$object null$options null)
  48.     {
  49.         // requete perso
  50.         $query null;
  51.         $query $this->createQueryBuilder('e');
  52.         if ($this->getCount()) {
  53.             $query->select('COUNT(e.idpodcast)');
  54.             $this->setCount(false);
  55.             return $query;
  56.         }
  57.         if (!empty($options['type_franceinter'])) {
  58.             $query->andWhere('e.typeFranceinter = \'' $options['type_franceinter'] . '\'');
  59.         }
  60.         if (!empty($options['group_by'])) {
  61.             $query->groupBy($options['group_by']);
  62.         }
  63. //        $this->addSQLParams('where',$query,array(
  64. //            array('podcasts','type_franceinter', (int)$query['special']['type_franceinter']),
  65. //        ));
  66.         // parametre
  67. //        if(isset($_REQUEST['idpodcast']) && !empty($_REQUEST['idpodcast'])) {
  68. //            $idpodcast = $_REQUEST['idpodcast'];
  69. //        }
  70. //
  71. //        if(isset($_REQUEST['keywords']) && $_REQUEST['keywords']!='nom' && !empty($_REQUEST['keywords'])) {
  72. //            $keywords = $_REQUEST['keywords'];
  73. //        }
  74. //
  75. //        if(isset($_REQUEST['publish']) && !empty($_REQUEST['publish'])) {
  76. //            $publish = $_REQUEST['publish'];
  77. //        }
  78. //
  79. //        //recherche stricte par id
  80. //        if(!empty($idpodcast)) {
  81. //            $this->whereAdd($this->__table.'.'.$this->__idtable.'='.((int)$idpodcast));
  82. //        }
  83. //
  84. //        // mots cles
  85. //        if (!empty($keywords)) {
  86. //            $this->whereAdd($this->__table.'.title LIKE \'%'.$this->escape($keywords).'%\'');
  87. //        }
  88. //
  89. //        // selectionne les fiches hors ligne
  90. //        if (!empty($publish) && $publish=='no') {
  91. //            $this->whereAdd($this->__table.'.publish=0');
  92. //        }
  93.         // on lance la recherche
  94.         return $query->getQuery();
  95.     }
  96.     // }}}
  97.     //  {{{ setToArray()
  98.     /** Liste des multimedias dans un tableau associatif
  99.      *
  100.      * Tableau associatif notament utilisé pour lister les informations sur les multimedias
  101.      * Utile pour générer les tableaux HTML de listes de multimedias
  102.      *
  103.      * @access  public
  104.      * @return  array
  105.      * @see     findData()
  106.      */
  107.     public function setToArray($spec true)
  108.     {
  109.         if ($spec == true) {
  110.             $this->findData();
  111.         }
  112.         $values = array();
  113.         $color null;
  114.         $nb 0;
  115.         while ($this->fetch()) {
  116.             // valeurs de l'enregistrement
  117.             $values[$nb] = $this->getInfosPodcast();
  118.             // couleur de ligne alternative
  119.             $color $this->colorAlternate($color);
  120.             $values[$nb]['colorline'] = $color;
  121.             $values[$nb]['id'] = $this->idpodcast;
  122.             $nb++;
  123.         }
  124.         return $values;
  125.     }
  126.     // }}}
  127.     //  {{{ orderByDefaut()
  128.     /** Classement par défaut
  129.      *
  130.      * Défini le tri par défaut pour les requêtes de type SELECT
  131.      *
  132.      * @access public
  133.      * @return string
  134.      */
  135.     public function orderByDefaut($order null)
  136.     {
  137.         // tri par défaut
  138.         if (empty($order)) {
  139.             $order 'idpodcast';
  140.         }
  141.         return $order;
  142.     }
  143.     // }}}
  144.     //  {{{ getInfosPodcast()
  145.     /** Informations sur un podcast
  146.      *
  147.      * @access public
  148.      * @param int $idpodcast numero de la fiche podcast
  149.      * @return array  les infos sous forme de tableau
  150.      */
  151.     public function getInfosPodcast($idpodcast null$params_data = array(), $params_display = array())
  152.     {
  153.         $infos = array();
  154.         ////////////// infos de la table
  155.         if (!isset($this->idpodcast) || empty($this->idpodcast)) {
  156.             if (!empty($idpodcast)) {
  157. //                if(!$this->get($idpodcast)) {
  158. //                    return array();
  159. //                } else {
  160. //                    $infos = $this->objToArray();
  161. //                }
  162.                 $con $this->getEntityManager();
  163.                 $infos $con->getRepository(Podcasts::class)
  164.                     ->createQueryBuilder('e')
  165.                     ->select('e')
  166.                     ->andWhere('e.idpodcast = :idpodcast')
  167.                     ->setParameter('idpodcast'$idpodcast)
  168.                     ->getQuery()
  169.                     ->getSingleResult(AbstractQuery::HYDRATE_ARRAY);
  170.                 foreach ($infos as $key => $value) {
  171.                     $this->$key $value;
  172.                 }
  173.             }
  174.         } else {
  175.             $idpodcast $this->idpodcast;
  176.             $con $this->getEntityManager();
  177.             $infos $con->getRepository(Podcasts::class)
  178.                 ->createQueryBuilder('e')
  179.                 ->select('e')
  180.                 ->andWhere('e.idpodcast = :idpodcast')
  181.                 ->setParameter('idpodcast'$idpodcast)
  182.                 ->getQuery()
  183.                 ->getSingleResult(\Doctrine\ORM\Query::HYDRATE_ARRAY);
  184.             foreach ($infos as $key => $value) {
  185.                 $this->$key $value;
  186.             }
  187.         }
  188.         // retourne toutes les infos liées
  189.         if (!empty($params_data['all'])) {
  190.             // les ralations
  191.             $infos['count_infos_total'] = 0;
  192.             foreach ($this->array_types as $t) {
  193.                 $infos[$t] = $this->noPunct($this->getLinkedObject($this->getRelationsArray($t), $idpodcast$t'podcasts'));
  194.                 $infos['count_infos_total'] += count($infos[$t]);
  195.             }
  196.         }
  197.         if (empty($params_display['format_vignette'])) {
  198.             $params_display['format_vignette'] = array();
  199.         }
  200.         $params_flou_display $params_display['format_vignette'];
  201.         $params_flou_display['blur'] = true;
  202.         $infos['vignette'] = $this->getVignettePodcast($infos['idpodcast'], $params_display['format_vignette']);
  203.         $infos['vignette_flou'] = $this->getVignettePodcast($infos['idpodcast'], $params_display['format_vignette']);
  204.         // si code franceinter
  205.         if (!empty($infos['codeFranceinter']) && !empty($infos['integratePlayer'])) {
  206.             if (strlen($infos['codeFranceinter']) == 38) {
  207.                 $infos['codeFranceinter'] = substr($infos['codeFranceinter'], 0, -2);
  208.             }
  209.             $franceculture_width '100%';
  210.             if (!empty($params_display['format_vignette']['franceculture_width'])) {
  211.                 $franceculture_width $params_display['franceculture_width'];
  212.             }
  213.             if (!empty($infos['typeFranceinter']) && !is_null($infos['typeFranceinter']) && $this->franceinter_types[$infos['typeFranceinter']] == 'franceinter') {
  214.                 $infos['player'] = '<iframe src="https://www.franceinter.fr/embed/player/aod/' $infos['codeFranceinter'] . '" width="100%" height="64" frameborder="0" scrolling="no"></iframe>';
  215.             } else {
  216.                 $infos['player'] = '<iframe src="https://www.franceculture.fr/player/export-reecouter?content=' $infos['codeFranceinter'] . '" width="' $franceculture_width '" frameborder="0" scrolling="no" height="139"></iframe>';
  217.             }
  218.         }
  219.         // culturebox
  220.         if (!empty($infos['codeFt'])) {
  221.             $infos['player'] = '<iframe src="https://culturebox.francetvinfo.fr/resultats/widgets/external.html?source_type=live&id=' $infos['codeFt'] . '&player=simple&width=530&height=300&size=auto" width="550" height="520" frameborder="0" scrolling="no"></iframe>';
  222.         }
  223.         // soundcloud
  224.         if (!empty($infos['codeSoundcloud'])) {
  225.             $infos['player'] = '<iframe width="100%" height="166" scrolling="no" frameborder="no" allow="autoplay" src="https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/tracks/' $infos['codeSoundcloud'] . '&color=%23307088&auto_play=false&hide_related=false&show_comments=true&show_user=true&show_reposts=false&show_teaser=true"></iframe>';
  226.         }
  227.         // spotify
  228.         if (!empty($infos['codeSpotify'])) {
  229.             $infos['player'] = '<iframe src="https://open.spotify.com/embed-podcast/show/' $infos['codeSpotify'] . '" width="100%" height="232" frameborder="0" allowtransparency="true" allow="encrypted-media"></iframe>';
  230.         }
  231.         // arte
  232.         if (!empty($infos['codeArte'])) {
  233.             $infos['player'] = '<iframe allowfullscreen="true" style="transition-duration:0s;transition-property:no;margin:0 auto;position:relative;display:block;background-color:#000000;" frameborder="0" scrolling="no" width="100%" height="480" src="https://www.arte.tv/player/v5/index.php?lang=fr_FR&json_url=https%3A%2F%2Fapi.arte.tv%2Fapi%2Fplayer%2Fv2%2Fconfig%2Ffr%2F' $infos['codeArte'] . '&autoplay=false&amp;mute=0"></iframe>';
  234.         }
  235.         // date au bon format
  236.         $infos['date_podcast_str'] = $this->getFormeDate($infos['datePodcast'], "D d F Y");
  237.         // date en FR
  238.         foreach (array('date_captation_ft''fin_visionnage_ft''debut_visionnage_ft') as $f) {
  239.             if (!empty($infos[$f]) && $infos[$f] != '0000-00-00 00:00:00') {
  240.                 $infos[$f '_str'] = $this->getFormeDate($infos[$f], '%a %d/%m/%Y'true);
  241.             }
  242.         }
  243.         if (!empty($infos['duration']) && empty($infos['isIntegrale'])) {
  244.             if (!empty($infos['datePodcast']) && !is_null($infos['datePodcast'])) {
  245.                 // calcul du nombre de jour restant
  246.                 $date_podcast = clone($infos['datePodcast']);
  247.                 $date_podcast->add(new DateInterval('P' $infos['duration'] . 'D'));
  248.                 $date_jour = new DateTime(date('Y-m-d'));
  249.                 $interval $date_jour->diff($date_podcast);
  250.                 $day_left_sign $interval->format('%R');
  251.                 if ($day_left_sign == '+') {
  252.                     $infos['day_left'] = $interval->format('%a');
  253.                 } else {
  254.                     $infos['day_left'] = 0;
  255.                 }
  256.             }
  257.         } else {
  258.             $infos['is_permanent'] = 1;
  259.         }
  260.         // pour culturebox, si fin_visionnage_ft inférieur à la date du jour, on supprime
  261.         if (!empty($infos['finVisionnageFt']) && $infos['finVisionnageFt']->format('Y-m-d h:i:m') != '0000-00-00 00:00:00') {
  262.             $fin_visionnage_ft $infos['finVisionnageFt'];
  263.             $date_jour = new DateTime(date('Y-m-d'));
  264.             $interval $date_jour->diff($fin_visionnage_ft);
  265.             $day_left_sign $interval->format('%R');
  266.             if ($day_left_sign == '+') {
  267.                 $infos['day_left'] = $interval->format('%a');
  268.             } else {
  269.                 $infos['day_left'] = 0;
  270.             }
  271.         }
  272.         return $infos;
  273.     }
  274.     // }}}
  275.     //  {{{ getItemsList()
  276.     /** Liste des items pour les champs relationnels
  277.      *
  278.      * Retourne un tableau associatif contenant la liste des items d'une relation
  279.      *
  280.      * @access  public
  281.      * @param string $type Ce qu'on recherche
  282.      * @param string $idtext L'id de l'objet
  283.      * @return  array
  284.      */
  285.     public function getItemsList($idpodcast$type)
  286.     {
  287.         if (in_array($type$this->array_types)) {
  288.             return $this->getLinkedObject($this->getRelationsArray($type), $idpodcast$type'podcasts');
  289.         } else {
  290.             return 'Aucune fonction de recherche pour le type <strong>' $type '</strong> dans la méthode !';
  291.         }
  292.     }
  293.     // }}}
  294.     //  {{{ getRelationsArray()
  295.     /** Tableau des relations
  296.      *
  297.      * @access  public
  298.      * @param string|int $type le type de champ
  299.      */
  300.     public function getRelationsArray($type null)
  301.     {
  302.         // récupérer les relations communes
  303.         $array_types $this->getRelationsArrayTrait('all');
  304.         $array_types += array(
  305.             'podcast_spectacle' => array(
  306.                 'type_join' => 'multiple',
  307.                 'dest_table' => 'spectacles',
  308.                 'fields' => array('idspectacle''title''url_clean'),
  309.                 'join_table' => 'podcast_spectacle',
  310.                 'hide_relation' => true,
  311.                 'silent_delete_relation' => true,
  312.                 'description' => 'Spectacle(s) associé(s) à ce podcast',
  313.             ),
  314.             'podcast_contact' => array(
  315.                 'type_join' => 'multiple',
  316.                 'dest_table' => 'contacts',
  317.                 'fields' => array('idcontact''organisation''url_clean'),
  318.                 'join_table' => 'podcast_contact',
  319.                 'hide_relation' => true,
  320.                 'silent_delete_relation' => true,
  321.                 'description' => 'Structure(s) associée(s) à ce podcast',
  322.             ),
  323.             'podcast_person' => array(
  324.                 'type_join' => 'multiple',
  325.                 'dest_table' => 'persons',
  326.                 'fields' => array('idperson''lastname''firstname''url_clean'),
  327.                 'join_table' => 'podcast_person',
  328.                 'hide_relation' => true,
  329.                 'silent_delete_relation' => true,
  330.                 'description' => 'Personne(s) associée(s) à ce podcast',
  331.             ),
  332.             'podcast_text' => array(
  333.                 'type_join' => 'multiple',
  334.                 'dest_table' => 'texts',
  335.                 'fields' => array('idtext''title''url_clean'),
  336.                 'join_table' => 'podcast_text',
  337.                 'hide_relation' => true,
  338.                 'silent_delete_relation' => true,
  339.                 'description' => 'Texte(s) associé(s) à ce podcast',
  340.             )
  341.         );
  342.         if (!empty($array_types[$type])) {
  343.             $array_types[$type]['type'] = $type;
  344.             return $array_types[$type];
  345.         } else {
  346.             return $array_types;
  347.         }
  348.     }
  349.     // }}}
  350.     //  {{{ getSQLPodcasts()
  351.     /** Générer la requete standard pour des podcasts
  352.      *
  353.      * $params = array(
  354.      *  'select' => champs en plus pour le select,
  355.      *  'from' => champs en plus pour le from,
  356.      *  'where' => paramètres en plus le where,
  357.      *  'order' => classement des résultats,
  358.      *  'limit' => limiter le nb de résultats array(debut,fin), (all pour pas de limit)
  359.      * )
  360.      * $special = array(
  361.      *  'select_by_text_or_adaptation' => text et adaptation,
  362.      *  'prochains' => true = date dans le future, un entier = fait un between
  363.      *  'anciens' =>
  364.      *  'join' => jointure gauche sur contacts et schedules
  365.      * )
  366.      *
  367.      *
  368.      * @access   public
  369.      * @param array $params Les paramètres pour la requete
  370.      * @param array $special Les paramètres supplémentaires
  371.      * @param bool $debug afficher la requête TODO
  372.      * @return   string
  373.      */
  374.     public function getSQLPodcasts($query = array(), $debug false)
  375.     {
  376.         // on prepare les tableaux
  377.         foreach (array('select''from''where''order''group''limit') as $t) {
  378.             if (!empty($query[$t])) {
  379.                 if (!is_array($query[$t])) {
  380.                     $query[$t][] = $query[$t];
  381.                 } else {
  382.                     $query[$t] = $query[$t];
  383.                 }
  384.             } else {
  385.                 $query[$t] = array();
  386.             }
  387.         }
  388.         // champs par défaut
  389.         $this->addSQLParams('select'$query, array(
  390.             array('podcasts' => '*')
  391.         ));
  392.         // publié ou pas
  393.         if (empty($query['publish']) && $_ENV['CHECK_IF_ONLINE']) {
  394.             $this->addSQLParams('where'$query, array(
  395.                 array('podcasts''publish'1)
  396.             ));
  397.         } elseif (!empty($query['publish'])) {
  398.             $this->addSQLParams('where'$query, array(
  399.                 array('podcasts''publish'$query['publish'])
  400.             ));
  401.         }
  402.         // recherche par liaison via podcast_person
  403.         if (!empty($query['special']['idpersons'])) {
  404.             $this->addSQLParams('from'$query, array(
  405.                 'podcast_person',
  406.             ));
  407.             // jointure entre les 3 tables
  408.             $this->addSQLParams('join'$query, array(
  409.                 'podcasts.`idpodcast`' => 'podcast_person.`idpodcast`',
  410.             ));
  411.             $this->addSQLParams('where'$query, array(
  412.                 array('podcast_person''idperson'$query['special']['idpersons']),
  413.             ));
  414.         }
  415.         // recherche par liaison via podcast_contact
  416.         if (!empty($query['special']['idcontacts'])) {
  417.             $this->addSQLParams('from'$query, array(
  418.                 'podcast_contact',
  419.             ));
  420.             // jointure entre les 3 tables
  421.             $this->addSQLParams('join'$query, array(
  422.                 'podcasts.`idpodcast`' => 'podcast_contact.`idpodcast`',
  423.             ));
  424.             $this->addSQLParams('where'$query, array(
  425.                 array('podcast_contact''idcontact'$query['special']['idcontacts']),
  426.             ));
  427.         }
  428.         // recherche par liaison via podcast_spectacle
  429.         if (!empty($query['special']['search_spectacles'])) {
  430.             $this->addSQLParams('from'$query, array(
  431.                 'podcast_spectacle',
  432.             ));
  433.             // jointure entre les 3 tables
  434.             $this->addSQLParams('join'$query, array(
  435.                 'podcasts.`idpodcast`' => 'podcast_spectacle.`idpodcast`',
  436.             ));
  437. //            $this->addSQLParams('where',$query,array(
  438. //                array('podcast_spectacle','idspectacle',$query['special']['idspectacles']),
  439. //                'podcasts.`idpodcast`' => 'podcast_spectacle.`idpodcast`',
  440. //            ));
  441.         }
  442.         // recherche par liaison via podcast_spectacle
  443.         if (!empty($query['special']['idspectacles'])) {
  444.             $this->addSQLParams('from'$query, array(
  445.                 'podcast_spectacle',
  446.             ));
  447.             // jointure entre les 3 tables
  448.             $this->addSQLParams('join'$query, array(
  449.                 'podcasts.`idpodcast`' => 'podcast_spectacle.`idpodcast`',
  450.             ));
  451.             $this->addSQLParams('where'$query, array(
  452.                 array('podcast_spectacle''idspectacle'$query['special']['idspectacles']),
  453.             ));
  454.         }
  455.         // recherche par liaison via podcast_text
  456.         if (!empty($query['special']['idtexts'])) {
  457.             $this->addSQLParams('from'$query, array(
  458.                 'podcast_text',
  459.             ));
  460.             // jointure entre les 3 tables
  461.             $this->addSQLParams('join'$query, array(
  462.                 'podcasts.`idpodcast`' => 'podcast_text.`idpodcast`',
  463.             ));
  464.             $this->addSQLParams('where'$query, array(
  465.                 array('podcast_text''idtext'$query['special']['idtexts']),
  466.             ));
  467.         }
  468.         // franceculture ou culturebox
  469.         if (!empty($query['special']['type_podcast'])) {
  470.             if (is_array($query['special']['type_podcast'])) {
  471.                 $first true;
  472.                 foreach ($query['special']['type_podcast'] as $item) {
  473.                     $opt 'OR';
  474.                     if ($first) {
  475.                         $opt 'AND (';
  476.                         $first false;
  477.                     }
  478.                     $query['where'][] = ' ' $opt ' `podcasts`.`code_' $item '` IS NOT NULL';
  479.                 }
  480.                 $query['where'][] = ')';
  481.             } else {
  482.                 if ($query['special']['type_podcast'] == 'franceculture') {
  483.                     $this->addSQLParams('where'$query, array(
  484.                         array('podcasts''code_franceinter''ISNOTNULL'),
  485.                     ));
  486.                 }
  487.                 if ($query['special']['type_podcast'] == 'soundcloud') {
  488.                     $this->addSQLParams('where'$query, array(
  489.                         array('podcasts''code_soundcloud''ISNOTNULL'),
  490.                     ));
  491.                 }
  492.                 if ($query['special']['type_podcast'] == 'spotify') {
  493.                     $this->addSQLParams('where'$query, array(
  494.                         array('podcasts''code_spotify''ISNOTNULL'),
  495.                     ));
  496.                 }
  497.                 if ($query['special']['type_podcast'] == 'arte') {
  498.                     $this->addSQLParams('where'$query, array(
  499.                         array('podcasts''code_arte''ISNOTNULL'),
  500.                     ));
  501.                 }
  502.                 if ($query['special']['type_podcast'] == 'culturebox') {
  503.                     $this->addSQLParams('where'$query, array(
  504.                         array('podcasts''code_ft''ISNOTNULL'),
  505.                     ));
  506.                     // uniquement les actifs
  507.                     if (!empty($query['special']['current'])) {
  508.                         $this->addSQLParams('where'$query, array(
  509.                             array('podcasts''debut_visionnage_ft'date('Y-m-d'), 'AND''<='),
  510.                             array('podcasts''fin_visionnage_ft'date('Y-m-d'), 'AND''>'),
  511.                         ));
  512.                     }
  513.                     // uniquement les actifs avec les dates de fin vide
  514.                     if (!empty($query['special']['current_start_and_end_empty'])) {
  515.                         $this->addSQLParams('where'$query, array(
  516.                             array('podcasts''debut_visionnage_ft'date('Y-m-d H:i:s'), 'AND''<=')
  517.                         ));
  518.                     }
  519.                     // uniquement les a venir
  520.                     if (!empty($query['special']['next'])) {
  521.                         $this->addSQLParams('where'$query, array(
  522.                             array('podcasts''debut_visionnage_ft'date('Y-m-d'), 'AND''>'),
  523.                         ));
  524.                     }
  525.                 }
  526.             }
  527.         }
  528.         if (!empty($query['special']['type_diffusion'])) {
  529.             $this->addSQLParams('where'$query, array(
  530.                 array('podcasts''type_diffusion'$query['special']['type_diffusion']),
  531.             ));
  532.         } else {
  533.             $query['where'][] = 'AND (`podcasts`.`type_diffusion` IS NULL OR `podcasts`.`type_diffusion` = 0)';
  534.         }
  535.         if (!empty($query['special']['emission'])) {
  536.             //franceculture
  537.             if (is_array($query['special']['emission'])) {
  538.                 $query['where'][] = 'AND `podcasts`.`name_program` IN ("' implode('","'$query['special']['emission']) . '")';
  539. //                $query['where'][] = 'AND podcasts`.`name_program` IN (une-vie-une-oeuvre)';s
  540.             } else {
  541.                 $this->addSQLParams('where'$query, array(
  542.                     array('podcasts''name_program'$this->escape($query['special']['emission'])),
  543.                 ));
  544.             }
  545.         }
  546.         if (array_key_exists('type_franceinter'$query['special'])) {
  547.             if (is_numeric($query['special']['type_franceinter']) && $query['special']['type_franceinter'] != 0) {
  548.                 $this->addSQLParams('where'$query, array(
  549.                     array('podcasts''type_franceinter', (int)$query['special']['type_franceinter']),
  550.                 ));
  551.             } else {
  552.                 $query['where'][] = 'AND (podcasts.type_franceinter is NULL OR podcasts.type_franceinter = 0)';
  553.             }
  554.         }
  555.         if (!empty($query['special']['is_integrale'])) {
  556.             $this->addSQLParams('where'$query, array(
  557.                 array('podcasts''is_integrale'1),
  558.             ));
  559.         }
  560.         if (empty($query['order'])) {
  561.             if (!empty($query['special']['lastchance'])) {
  562.                 $this->addSQLParams('order'$query, array(
  563.                     array('podcasts' => 'fin_visionnage_ft'),
  564.                 ));
  565.                 $query['direction'] = 'ASC';
  566.             } elseif (!empty($query['special']['order'])) {
  567.                 $this->addSQLParams('order'$query, array(
  568.                     $query['special']['order']
  569.                 ));
  570.             } else {
  571.                 $this->addSQLParams('order'$query, array(
  572.                     array('podcasts' => 'date_podcast'),
  573.                 ));
  574.             }
  575.         }
  576.         return $this->getSQLObject($query);
  577.     }
  578.     // }}}
  579.     //  {{{ getListEmissions()
  580.     /** Retourne des listes des émissionss
  581.      *
  582.      * Retourne des listes de émissions au format "standard""
  583.      *
  584.      * @access   public
  585.      * @param array $params_sql paramètre pour la requete SQL
  586.      * @return   array
  587.      */
  588.     public function getListEmissions($params_sql null$params_exec null)
  589.     {
  590.         // si pas de tableau
  591.         if (!isset($params_sql['special'])) {
  592.             $params_sql['special'] = array();
  593.         }
  594.         if (!isset($params_sql['params'])) {
  595.             $params_sql['params'] = array();
  596.         }
  597.         // construction de la requête avec le passage de paramètres
  598.         $sql $this->getSQLPodcasts($params_sql);
  599.         // paramètre de debug
  600.         $dbg = (empty($params_sql['dbg'])) ? array() : $dbg $params_sql['dbg'];
  601.         // executer la requete
  602.         $this->query($sql$dbg);
  603.         // debug
  604.         $start_boucle microtime(true);
  605.         // on boucle
  606.         $emissions = array();
  607.         while ($this->fetch()) {
  608.             if (!empty($this->name_program)) {
  609.                 $datas = [
  610.                     'title' => $this->title,
  611.                     'title_program' => $this->title_program,
  612.                     'name_program' => $this->name_program
  613.                 ];
  614.             }
  615.             if (!empty($this->title)) {
  616.                 $datas['count_infos_total'] = 0;
  617.                 $arrayTypes = (!empty(empty($params_exec['getRelations']))) ? $params_exec['getRelations'] : $this->array_types;
  618.                 foreach ($arrayTypes as $item) {
  619.                     $datas[$item] = $this->noPunct($this->getLinkedObject($this->getRelationsArray($item), $this->idpodcast$item'podcasts'));
  620.                     $datas['count_infos_total'] += count($datas[$item]);
  621.                 }
  622.             }
  623.             if (!empty($datas)) {
  624.                 $emissions[] = $datas;
  625.             }
  626.         }
  627.         // debug de la boucle
  628.         if ($this->isTraceMode('list_object')) {
  629.             $this->setTraceInfos(array(
  630.                 'execution_time_boucle' => microtime(true) - $start_boucle,
  631.                 'nb_occurence' => count($emissions),
  632.                 'dbg' => $dbg,
  633.             ));
  634.         }
  635.         $this->free();
  636.         return $emissions;
  637.     }
  638.     //  {{{ getListPodcasts()
  639.     /** Retourne des listes de podcasts
  640.      *
  641.      * Retourne des listes de podcast au format "standard""
  642.      *
  643.      * @access   public
  644.      * @param array $params_sql paramètre pour la requete SQL
  645.      * @param array $format_vignette de la vignette si pas standard
  646.      * @param array $params_display paramètre pour l'affichage
  647.      * @return   array
  648.      */
  649.     public function getListPodcasts($params_sql null$format_vignette = array(), $params_display = array())
  650.     {
  651.         // si pas de tableau
  652.         if (!isset($params_sql['special'])) {
  653.             $params_sql['special'] = array();
  654.         }
  655.         if (!isset($params_sql['params'])) {
  656.             $params_sql['params'] = array();
  657.         }
  658.         // construction de la requête avec le passage de paramètres
  659.         $sql $this->getSQLPodcasts($params_sql);
  660.         // paramètre de debug
  661.         $dbg = (empty($params_sql['dbg'])) ? array() : $dbg $params_sql['dbg'];
  662.         // executer la requete
  663.         $this->datas $datas $this->query($sql$dbg);
  664.         $videos = array();
  665.         // donnée entières ?
  666.         if (empty($params_display['alldata'])) {
  667.             $params_display['alldata'] = false;
  668.         }
  669.         // debug
  670.         $start_boucle microtime(true);
  671.         $podcasts = array();
  672.         // format de la vignette
  673.         if (empty($format_vignette)) {
  674.             $format_vignette = array('width' => 100'height' => 70'direction' => 'thumb');
  675.         }
  676.         $format_vignette_infosPodcast = [
  677.             'format_vignette' => $format_vignette,
  678.         ];
  679.         if (!empty($params_display['franceculture_width'])) {
  680.             $format_vignette_infosPodcast['franceculture_width'] = $params_display['franceculture_width'];
  681.         }
  682.         // on boucle
  683.         while ($this->fetch()) {
  684.             // le total
  685.             if (!empty($params_sql['count_only'])) {
  686.                 return $this->total;
  687.             }
  688.             $idpodcast $this->idpodcast;
  689.             if (!empty($params_sql['fields'])) {
  690.                 foreach ($params_sql['fields'] as $f) {
  691.                     $podcasts[$idpodcast][$f] = $this->$f;
  692.                 }
  693.             } else {
  694.                 $podcasts[$idpodcast] = $this->getInfosPodcast($idpodcast, array('all' => true), $format_vignette_infosPodcast);
  695.             }
  696.             // si il ne reste plus de jours, on supprime
  697.             if (!empty($params_sql['special']['type_podcast']) && $params_sql['special']['type_podcast'] == 'culturebox') {
  698.                 if (!empty($podcasts[$idpodcast]['fin_visionnage_ft']) && $podcasts[$idpodcast]['fin_visionnage_ft'] != '0000-00-00 00:00:00') {
  699.                     if ($podcasts[$idpodcast]['fin_visionnage_ft'] < date('Y-m-d H:i:s')) {
  700.                         unset($podcasts[$idpodcast]);
  701.                     } else {
  702.                         $podcasts[$idpodcast]['is_permanent'] = 1;
  703.                     }
  704.                 } else {
  705.                     if (empty($podcasts[$idpodcast]['is_permanent'])) {
  706.                         if (empty($podcasts[$idpodcast]['day_left']) || $podcasts[$idpodcast]['day_left'] < 1) {
  707.                             unset($podcasts[$idpodcast]);
  708.                         }
  709.                     } else {
  710.                         $podcasts[$idpodcast]['is_permanent'] = 1;
  711.                     }
  712.                 }
  713.             }
  714.         }
  715.         // debug de la boucle
  716.         if ($this->isTraceMode('list_object')) {
  717.             $this->setTraceInfos(array(
  718.                 'execution_time_boucle' => microtime(true) - $start_boucle,
  719.                 'nb_occurence' => count($podcasts),
  720.                 'dbg' => $dbg,
  721.             ));
  722.         }
  723. //        dump($podcasts);
  724.         $this->free();
  725.         return $podcasts;
  726.     }
  727.     // }}}
  728.     //  {{{ getObjectTitle()
  729.     /** Infos de l'item recherché
  730.      *
  731.      * Affichage standard du titre de l'objet
  732.      *
  733.      * @access public
  734.      * @param int $idobject Identifiant de l'item
  735.      * @param array $infos_object Informations pour construire le titre
  736.      * @param array $params Paramétres supplémentaires
  737.      * @return string
  738.      */
  739.     public function getObjectTitle($idobject null$infos_object = array(), $params = array())
  740.     {
  741.         $title '';
  742.         if (!$idobject) {
  743.             $idobject $this->idpodcast;
  744.         }
  745.         // champs
  746.         $fields = array('idpodcast''title''url_clean');
  747.         if (!empty($infos_object)) {
  748.             foreach ($fields as $k => $v) {
  749.                 if (array_key_exists($v$infos_object)) {
  750.                     $$v $infos_object[$v];
  751.                 }
  752.             }
  753.         } else {
  754.             //charger les infos que si necessaire
  755.             if (empty($this->title)) {
  756.                 $this->selectAdd();
  757.                 $this->selectAdd(implode(','$fields));
  758.                 $this->get($idobject);
  759.             }
  760.             foreach ($fields as $k => $v) {
  761.                 if (isset($this->$v) && $this->$v != '') {
  762.                     $$v trim($this->$v);
  763.                 }
  764.             }
  765.         }
  766.         return $title;
  767.     }
  768.     // }}}
  769.     //  {{{ getListSearch()
  770.     /** Liste des podcasts
  771.      *
  772.      * Pour les champs Ajax de relations et les recherches diverses
  773.      *
  774.      * @access  public
  775.      * @param string $lettres Pour la recherche alphabetique
  776.      * @param string $type Pour le type recherche (editeurs, revues...)
  777.      * @param string $keywords Recherche par mots cles
  778.      * @return  array
  779.      */
  780.     public function getListSearch($lettre$type null$keywords null)
  781.     {
  782.         $sql 'SELECT ' $this->__idtable ', title
  783.                  FROM ' $this->__table '
  784.                  WHERE 1 ';
  785.         // selection par ordre alpha
  786.         if (!empty($lettre) && $lettre != 'tous') {
  787.             $sql_where[] = array('LOWER(LEFT(LTRIM(title),1))=\'' $this->escape($lettre) . '\'');
  788.         }
  789.         // recherche avec un mot cle
  790.         $list $this->splitKeywords($keywords);
  791.         if ($list) {
  792.             if (!empty($list[$this->IDSTR])) {
  793.                 // mots clés
  794.                 foreach ($list[$this->IDSTR] as $s) {
  795.                     $sql_more_name[] = 'title LIKE \'%' $s '%\'';
  796.                 }
  797.                 $sql_where[] = array('(' join(' OR '$sql_more_name) . ')');
  798.             }
  799.             if (!empty($list[$this->IDNUM])) {
  800.                 // recherche par numéro d'id pour les mots clés numériques
  801.                 $sql_where[] = array('idpodcast IN (' implode(','$list[$this->IDNUM]) . ')''OR');
  802.             }
  803.         }
  804.         foreach ($sql_where as $k => $v) {
  805.             if (!empty($v[1])) {
  806.                 $sql .= ' ' $v[1] . ' ' $v[0];
  807.             } else {
  808.                 $sql .= ' AND ' $v[0];
  809.             }
  810.         }
  811.         $sql .= ' ORDER BY title';
  812.         $this->query($sql);
  813.         $r = array();
  814.         while ($this->fetch()) {
  815.             $r[$this->idpodcast] = $this->title;
  816.             // si trouvé par id, on l'affiche en fin de titre
  817.             if (!empty($list[$this->IDNUM]) && in_array($this->idpodcast$list[$this->IDNUM])) {
  818.                 $r[$this->idpodcast] .= ' - n°' $this->idpodcast;
  819.             }
  820.         }
  821.         $this->free();
  822.         return $r;
  823.     }
  824.     // }}}
  825.     //  {{{ countPodcasts()
  826.     /** Nombre de podcast
  827.      *
  828.      * Compter le nb de podcast
  829.      *
  830.      * @access  public
  831.      * @param string $obect Pour la recherche alphabetique
  832.      * @param integer $idobject Pour le type recherche (editeurs, revues...)
  833.      * @param string $type Type de contenu
  834.      * @return  int
  835.      */
  836.     public function countPodcasts($object null$idobject null$type null$only_object false)
  837.     {
  838.         if (!empty($object) && !empty($idobject)) {
  839.             $object substr($object0, -1);
  840.             $sql_count '
  841.                 SELECT COUNT(DISTINCT(d.`' $this->__idtable '`)) as total
  842.                 FROM ' $this->__table ' d, podcast_' $object ' do
  843.                 WHERE d.`publish`=1
  844.                 AND do.`idpodcast`= d.`idpodcast`';
  845.             if (is_array($idobject)) {
  846.                 $sql_count .= ' AND do.`id' $object '` IN(' implode(','$idobject) . ')';
  847.             } else {
  848.                 $sql_count .= ' AND do.`id' $object '`=' . (int)$idobject;
  849.             }
  850.         } else {
  851.             $sql_count '
  852.                 SELECT COUNT(DISTINCT(' $this->__idtable ')) as total
  853.                 FROM ' $this->__table ' d
  854.                 WHERE publish=1';
  855.         }
  856.         if (!is_null($type)) {
  857.             if (isset($type['type_franceinter'])) {
  858.                 $sql_count .= ' AND d.code_franceinter IS NOT NULL ';
  859.                 if ($type['type_franceinter'] == 0) {
  860.                     $sql_count .= ' AND (d.type_franceinter = 0 OR d.type_franceinter IS NULL)';
  861.                 } else {
  862.                     $sql_count .= ' AND d.type_franceinter = ' . (int)$type['type_franceinter'];
  863.                 }
  864.             } else {
  865.                 $sql_count .= ' AND d.code_' $type ' IS NOT NULL ';
  866.             }
  867.         }
  868.         $total null;
  869.         if ($only_object && empty($idobject)) {
  870.             return $total;
  871.         }
  872.         $total $this->queryOne($sql_count);
  873.         if ($total) {
  874.             return $total;
  875.         } else {
  876.             return null;
  877.         }
  878.     }
  879.     // }}}
  880.     public function countPodcastsForContact (int $idcontact): string
  881.     {
  882.         return $this->createQueryBuilder('p')
  883.             ->select('count(p.idpodcast)')
  884.             ->join('p.idcontact''pc')
  885.             ->where('pc.idcontact = :id')
  886.             ->setParameter('id'$idcontact)
  887.             ->getQuery()
  888.             ->getSingleScalarResult();
  889.     }
  890.     //  {{{ countListPodcasts()
  891.     /** Compter la liste des podcast
  892.      *
  893.      * @access   public
  894.      * @param array $params_sql paramètre pour la requete SQL
  895.      * @param bool $debug mode débugage
  896.      * @return   int
  897.      */
  898.     public function countListPodcasts($params_sql null$debug false)
  899.     {
  900.         // si pas de limite => tout
  901.         if (empty($params_sql['limit'])) {
  902.             $params_sql['limit'] = array('all');
  903.         }
  904.         $params_sql['count_only'] = true;
  905.         // construction de la requête avec le passage de paramètres
  906.         return $this->queryOne($this->getSQLPodcasts($params_sql$debug));
  907.     }
  908.     // }}}
  909.     //  {{{ getByCodeFt()
  910.     /** Récupèrer par le code FT
  911.      *
  912.      * @access  public
  913.      * @return  int
  914.      */
  915.     public function getByCodeFt($code_ft)
  916.     {
  917.         try {
  918.             $sql '
  919.             SELECT *
  920.             FROM ' $this->__table '
  921.             WHERE `code_ft`=' . (int)$code_ft;
  922.             $podcast $this->queryRow($sql);
  923.             return $podcast;
  924.         } catch (\Throwable $e) {
  925.             return null;
  926.         }
  927.     }
  928.     // }}}
  929.     //  {{{ getByCodeRadioFrance()
  930.     /** Récupèrer par le code FT
  931.      *
  932.      * @access  public
  933.      * @return  int
  934.      */
  935.     public function getByCodeRadioFrance($code_ft)
  936.     {
  937.         try {
  938.             $sql '
  939.             SELECT *
  940.             FROM ' $this->__table '
  941.             WHERE `code_franceinter`="' $code_ft '"';
  942.             $podcast $this->queryRow($sql);
  943.             return $podcast;
  944.         } catch (\Throwable $e) {
  945.             return null;
  946.         }
  947.     }
  948.     // }}}
  949.     //  {{{ getVignettePodcast()
  950.     /** Récupère la vignette d'un podcast ou la cree si besoin
  951.      *
  952.      * @access   public
  953.      * @param int idpodcast identifiant du podcast
  954.      * @param array format $format de la vignette
  955.      * @return   string
  956.      */
  957.     public function getVignettePodcast($idpodcast null$format = array(), $url_file null)
  958.     {
  959.         // id de la podcast
  960.         if (empty($idpodcast)) {
  961.             $idpodcast $this->idpodcast;
  962.         }
  963.         $idpodcast = (int)$idpodcast;
  964.         // par default : image arrondie crop 100px x 100px qualite 75
  965.         if (!empty($format)) {
  966.             $set_format $format;
  967.         } else {
  968.             $set_format = array('width' => 80'height' => 80'direction' => 'crop''default' => '../../default/podcasts-def.png');
  969.         }
  970.         if (!empty($url_file)) {
  971.             $url_file $_ENV['PATH_DIRECTORYUPLOAD'] . 'podcasts/src/' $this->images->getHashDir($url_filetrue) . $url_file;
  972.         } else {
  973.             $sql 'SELECT url_file FROM ' $this->__table ' WHERE idpodcast=' . (int)$idpodcast;
  974.             $url_file $this->queryOne($sql);
  975. //            if(empty($url_file)) {
  976. //                $url_file = null;
  977. //            } else {
  978.             $url_file $_ENV['PATH_DIRECTORYUPLOAD'] . 'podcasts/src/' $this->images->getHashDir($url_filetrue) . $url_file;
  979. //            }
  980.         }
  981.         $this->images->setVignetteFormat($set_format);
  982.         return $this->images->getVignetteObject($idpodcast'podcasts''unknow_classification'$url_file);
  983.     }
  984.     // }}}
  985.     //  {{{ delete()
  986.     /** Supprimer une podcasts et ses images
  987.      *
  988.      * @access   public
  989.      * @param int idpodcast identifiant du podcast
  990.      * @param array format $format de la vignette
  991.      * @return   string
  992.      */
  993.     public function deleteData($idpodcast null$url_file null)
  994.     {
  995.         // si on a l'URL du fichier, on peux le supprimer ainsi que ses vignettes
  996.         if (empty($url_file)) {
  997.             try {
  998.                 $sql 'SELECT url_file FROM ' $this->__table ' WHERE idpodcast=' . (int)$idpodcast;
  999.                 $url_file $this->queryOne($sql);
  1000.             } catch (\Throwable $e) {
  1001.                 $url_file null;
  1002.             }
  1003.         }
  1004.         if (!empty($url_file)) {
  1005.             // classe des images
  1006.             if (!isset($this->images)) {
  1007.                 require_once PATH_LIBS 'Images/Images.php';
  1008.                 $this->images = new Images();
  1009.             }
  1010.             $url_file_src PATH_DIRECTORYUPLOAD 'podcasts/src/' $this->images->getHashDir($url_filetrue) . $url_file;
  1011.             // supprimer les vignettes
  1012.             $files $this->getEntityManager()->getRepository(Files::class);
  1013.             $files->deleteVignettes(null'podcasts'$idpodcast, array('file' => $url_file));
  1014.             // supprimer le fichier
  1015.             if (file_exists($url_file_src)) {
  1016.                 @unlink($url_file_src);
  1017.             }
  1018.         }
  1019.         // supprimer la podcasts
  1020.         parent::deleteData($idpodcast);
  1021.         return true;
  1022.     }
  1023.     // }}}
  1024.     //  {{{ getTypeFranceInter()
  1025.     /** Récupérer la liste des différentes stations de Radio France
  1026.      *
  1027.      * @access   public
  1028.      * @return   array
  1029.      */
  1030.     public function getTypeFranceInter()
  1031.     {
  1032.         return $this->franceinter_types;
  1033.     }
  1034.     // }}}
  1035. }