<?php
namespace TheatreCore\Repository;
use Doctrine\ORM\AbstractQuery;
use TheatreCore\Classes\Images\Images;
use TheatreCore\Entity\Files;
use TheatreCore\Entity\Podcasts;
use TheatreCore\Traits\TheatreTrait;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
use DateInterval;
use DateTime;
/**
* PodcastsRepository
*
* This class was generated by the Doctrine ORM. Add your own custom
* repository methods below.
*/
class PodcastsRepository extends ServiceEntityRepository
{
use TheatreTrait {
getRelationsArray as protected getRelationsArrayTrait;
}
private $em;
public $__table;
public $__table_object;
public $__idtable;
public function __construct(ManagerRegistry $registry, Images $images)
{
parent::__construct($registry, Podcasts::class);
$this->__table = $this->getClassMetadata()->getTableName();
$this->__table_object = $this->getClassMetadata()->name;
$this->__idtable = $this->getClassMetadata()->getSingleIdentifierFieldName();
$this->images = $images;
}
// les relations
public $array_types = array('podcast_spectacle', 'podcast_contact', 'podcast_person', 'podcast_text');
public $franceinter_types = array(0 => 'franceculture', 1 => 'franceinter');
// {{{ findData()
/** Recherche des podcasts
*
* Permet de rechercher des podcasts en fonction de certains critères :
* la première lettre, un bout du nom, le type de multimedia, si il est en ligne ou pas
*
* @access public
* @see Theatre::find()
*/
public function findData($publish = null, $keywords = null, $idobject = null, $object = null, $options = null)
{
// requete perso
$query = null;
$query = $this->createQueryBuilder('e');
if ($this->getCount()) {
$query->select('COUNT(e.idpodcast)');
$this->setCount(false);
return $query;
}
if (!empty($options['type_franceinter'])) {
$query->andWhere('e.typeFranceinter = \'' . $options['type_franceinter'] . '\'');
}
if (!empty($options['group_by'])) {
$query->groupBy($options['group_by']);
}
// $this->addSQLParams('where',$query,array(
// array('podcasts','type_franceinter', (int)$query['special']['type_franceinter']),
// ));
// parametre
// if(isset($_REQUEST['idpodcast']) && !empty($_REQUEST['idpodcast'])) {
// $idpodcast = $_REQUEST['idpodcast'];
// }
//
// if(isset($_REQUEST['keywords']) && $_REQUEST['keywords']!='nom' && !empty($_REQUEST['keywords'])) {
// $keywords = $_REQUEST['keywords'];
// }
//
// if(isset($_REQUEST['publish']) && !empty($_REQUEST['publish'])) {
// $publish = $_REQUEST['publish'];
// }
//
// //recherche stricte par id
// if(!empty($idpodcast)) {
// $this->whereAdd($this->__table.'.'.$this->__idtable.'='.((int)$idpodcast));
// }
//
// // mots cles
// if (!empty($keywords)) {
// $this->whereAdd($this->__table.'.title LIKE \'%'.$this->escape($keywords).'%\'');
// }
//
// // selectionne les fiches hors ligne
// if (!empty($publish) && $publish=='no') {
// $this->whereAdd($this->__table.'.publish=0');
// }
// on lance la recherche
return $query->getQuery();
}
// }}}
// {{{ setToArray()
/** Liste des multimedias dans un tableau associatif
*
* Tableau associatif notament utilisé pour lister les informations sur les multimedias
* Utile pour générer les tableaux HTML de listes de multimedias
*
* @access public
* @return array
* @see findData()
*/
public function setToArray($spec = true)
{
if ($spec == true) {
$this->findData();
}
$values = array();
$color = null;
$nb = 0;
while ($this->fetch()) {
// valeurs de l'enregistrement
$values[$nb] = $this->getInfosPodcast();
// couleur de ligne alternative
$color = $this->colorAlternate($color);
$values[$nb]['colorline'] = $color;
$values[$nb]['id'] = $this->idpodcast;
$nb++;
}
return $values;
}
// }}}
// {{{ orderByDefaut()
/** Classement par défaut
*
* Défini le tri par défaut pour les requêtes de type SELECT
*
* @access public
* @return string
*/
public function orderByDefaut($order = null)
{
// tri par défaut
if (empty($order)) {
$order = 'idpodcast';
}
return $order;
}
// }}}
// {{{ getInfosPodcast()
/** Informations sur un podcast
*
* @access public
* @param int $idpodcast numero de la fiche podcast
* @return array les infos sous forme de tableau
*/
public function getInfosPodcast($idpodcast = null, $params_data = array(), $params_display = array())
{
$infos = array();
////////////// infos de la table
if (!isset($this->idpodcast) || empty($this->idpodcast)) {
if (!empty($idpodcast)) {
// if(!$this->get($idpodcast)) {
// return array();
// } else {
// $infos = $this->objToArray();
// }
$con = $this->getEntityManager();
$infos = $con->getRepository(Podcasts::class)
->createQueryBuilder('e')
->select('e')
->andWhere('e.idpodcast = :idpodcast')
->setParameter('idpodcast', $idpodcast)
->getQuery()
->getSingleResult(AbstractQuery::HYDRATE_ARRAY);
foreach ($infos as $key => $value) {
$this->$key = $value;
}
}
} else {
$idpodcast = $this->idpodcast;
$con = $this->getEntityManager();
$infos = $con->getRepository(Podcasts::class)
->createQueryBuilder('e')
->select('e')
->andWhere('e.idpodcast = :idpodcast')
->setParameter('idpodcast', $idpodcast)
->getQuery()
->getSingleResult(\Doctrine\ORM\Query::HYDRATE_ARRAY);
foreach ($infos as $key => $value) {
$this->$key = $value;
}
}
// retourne toutes les infos liées
if (!empty($params_data['all'])) {
// les ralations
$infos['count_infos_total'] = 0;
foreach ($this->array_types as $t) {
$infos[$t] = $this->noPunct($this->getLinkedObject($this->getRelationsArray($t), $idpodcast, $t, 'podcasts'));
$infos['count_infos_total'] += count($infos[$t]);
}
}
if (empty($params_display['format_vignette'])) {
$params_display['format_vignette'] = array();
}
$params_flou_display = $params_display['format_vignette'];
$params_flou_display['blur'] = true;
$infos['vignette'] = $this->getVignettePodcast($infos['idpodcast'], $params_display['format_vignette']);
$infos['vignette_flou'] = $this->getVignettePodcast($infos['idpodcast'], $params_display['format_vignette']);
// si code franceinter
if (!empty($infos['codeFranceinter']) && !empty($infos['integratePlayer'])) {
if (strlen($infos['codeFranceinter']) == 38) {
$infos['codeFranceinter'] = substr($infos['codeFranceinter'], 0, -2);
}
$franceculture_width = '100%';
if (!empty($params_display['format_vignette']['franceculture_width'])) {
$franceculture_width = $params_display['franceculture_width'];
}
if (!empty($infos['typeFranceinter']) && !is_null($infos['typeFranceinter']) && $this->franceinter_types[$infos['typeFranceinter']] == 'franceinter') {
$infos['player'] = '<iframe src="https://www.franceinter.fr/embed/player/aod/' . $infos['codeFranceinter'] . '" width="100%" height="64" frameborder="0" scrolling="no"></iframe>';
} else {
$infos['player'] = '<iframe src="https://www.franceculture.fr/player/export-reecouter?content=' . $infos['codeFranceinter'] . '" width="' . $franceculture_width . '" frameborder="0" scrolling="no" height="139"></iframe>';
}
}
// culturebox
if (!empty($infos['codeFt'])) {
$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>';
}
// soundcloud
if (!empty($infos['codeSoundcloud'])) {
$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>';
}
// spotify
if (!empty($infos['codeSpotify'])) {
$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>';
}
// arte
if (!empty($infos['codeArte'])) {
$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&mute=0"></iframe>';
}
// date au bon format
$infos['date_podcast_str'] = $this->getFormeDate($infos['datePodcast'], "D d F Y");
// date en FR
foreach (array('date_captation_ft', 'fin_visionnage_ft', 'debut_visionnage_ft') as $f) {
if (!empty($infos[$f]) && $infos[$f] != '0000-00-00 00:00:00') {
$infos[$f . '_str'] = $this->getFormeDate($infos[$f], '%a %d/%m/%Y', true);
}
}
if (!empty($infos['duration']) && empty($infos['isIntegrale'])) {
if (!empty($infos['datePodcast']) && !is_null($infos['datePodcast'])) {
// calcul du nombre de jour restant
$date_podcast = clone($infos['datePodcast']);
$date_podcast->add(new DateInterval('P' . $infos['duration'] . 'D'));
$date_jour = new DateTime(date('Y-m-d'));
$interval = $date_jour->diff($date_podcast);
$day_left_sign = $interval->format('%R');
if ($day_left_sign == '+') {
$infos['day_left'] = $interval->format('%a');
} else {
$infos['day_left'] = 0;
}
}
} else {
$infos['is_permanent'] = 1;
}
// pour culturebox, si fin_visionnage_ft inférieur à la date du jour, on supprime
if (!empty($infos['finVisionnageFt']) && $infos['finVisionnageFt']->format('Y-m-d h:i:m') != '0000-00-00 00:00:00') {
$fin_visionnage_ft = $infos['finVisionnageFt'];
$date_jour = new DateTime(date('Y-m-d'));
$interval = $date_jour->diff($fin_visionnage_ft);
$day_left_sign = $interval->format('%R');
if ($day_left_sign == '+') {
$infos['day_left'] = $interval->format('%a');
} else {
$infos['day_left'] = 0;
}
}
return $infos;
}
// }}}
// {{{ getItemsList()
/** Liste des items pour les champs relationnels
*
* Retourne un tableau associatif contenant la liste des items d'une relation
*
* @access public
* @param string $type Ce qu'on recherche
* @param string $idtext L'id de l'objet
* @return array
*/
public function getItemsList($idpodcast, $type)
{
if (in_array($type, $this->array_types)) {
return $this->getLinkedObject($this->getRelationsArray($type), $idpodcast, $type, 'podcasts');
} else {
return 'Aucune fonction de recherche pour le type <strong>' . $type . '</strong> dans la méthode !';
}
}
// }}}
// {{{ getRelationsArray()
/** Tableau des relations
*
* @access public
* @param string|int $type le type de champ
*/
public function getRelationsArray($type = null)
{
// récupérer les relations communes
$array_types = $this->getRelationsArrayTrait('all');
$array_types += array(
'podcast_spectacle' => array(
'type_join' => 'multiple',
'dest_table' => 'spectacles',
'fields' => array('idspectacle', 'title', 'url_clean'),
'join_table' => 'podcast_spectacle',
'hide_relation' => true,
'silent_delete_relation' => true,
'description' => 'Spectacle(s) associé(s) à ce podcast',
),
'podcast_contact' => array(
'type_join' => 'multiple',
'dest_table' => 'contacts',
'fields' => array('idcontact', 'organisation', 'url_clean'),
'join_table' => 'podcast_contact',
'hide_relation' => true,
'silent_delete_relation' => true,
'description' => 'Structure(s) associée(s) à ce podcast',
),
'podcast_person' => array(
'type_join' => 'multiple',
'dest_table' => 'persons',
'fields' => array('idperson', 'lastname', 'firstname', 'url_clean'),
'join_table' => 'podcast_person',
'hide_relation' => true,
'silent_delete_relation' => true,
'description' => 'Personne(s) associée(s) à ce podcast',
),
'podcast_text' => array(
'type_join' => 'multiple',
'dest_table' => 'texts',
'fields' => array('idtext', 'title', 'url_clean'),
'join_table' => 'podcast_text',
'hide_relation' => true,
'silent_delete_relation' => true,
'description' => 'Texte(s) associé(s) à ce podcast',
)
);
if (!empty($array_types[$type])) {
$array_types[$type]['type'] = $type;
return $array_types[$type];
} else {
return $array_types;
}
}
// }}}
// {{{ getSQLPodcasts()
/** Générer la requete standard pour des podcasts
*
* $params = array(
* 'select' => champs en plus pour le select,
* 'from' => champs en plus pour le from,
* 'where' => paramètres en plus le where,
* 'order' => classement des résultats,
* 'limit' => limiter le nb de résultats array(debut,fin), (all pour pas de limit)
* )
* $special = array(
* 'select_by_text_or_adaptation' => text et adaptation,
* 'prochains' => true = date dans le future, un entier = fait un between
* 'anciens' =>
* 'join' => jointure gauche sur contacts et schedules
* )
*
*
* @access public
* @param array $params Les paramètres pour la requete
* @param array $special Les paramètres supplémentaires
* @param bool $debug afficher la requête TODO
* @return string
*/
public function getSQLPodcasts($query = array(), $debug = false)
{
// on prepare les tableaux
foreach (array('select', 'from', 'where', 'order', 'group', 'limit') as $t) {
if (!empty($query[$t])) {
if (!is_array($query[$t])) {
$query[$t][] = $query[$t];
} else {
$query[$t] = $query[$t];
}
} else {
$query[$t] = array();
}
}
// champs par défaut
$this->addSQLParams('select', $query, array(
array('podcasts' => '*')
));
// publié ou pas
if (empty($query['publish']) && $_ENV['CHECK_IF_ONLINE']) {
$this->addSQLParams('where', $query, array(
array('podcasts', 'publish', 1)
));
} elseif (!empty($query['publish'])) {
$this->addSQLParams('where', $query, array(
array('podcasts', 'publish', $query['publish'])
));
}
// recherche par liaison via podcast_person
if (!empty($query['special']['idpersons'])) {
$this->addSQLParams('from', $query, array(
'podcast_person',
));
// jointure entre les 3 tables
$this->addSQLParams('join', $query, array(
'podcasts.`idpodcast`' => 'podcast_person.`idpodcast`',
));
$this->addSQLParams('where', $query, array(
array('podcast_person', 'idperson', $query['special']['idpersons']),
));
}
// recherche par liaison via podcast_contact
if (!empty($query['special']['idcontacts'])) {
$this->addSQLParams('from', $query, array(
'podcast_contact',
));
// jointure entre les 3 tables
$this->addSQLParams('join', $query, array(
'podcasts.`idpodcast`' => 'podcast_contact.`idpodcast`',
));
$this->addSQLParams('where', $query, array(
array('podcast_contact', 'idcontact', $query['special']['idcontacts']),
));
}
// recherche par liaison via podcast_spectacle
if (!empty($query['special']['search_spectacles'])) {
$this->addSQLParams('from', $query, array(
'podcast_spectacle',
));
// jointure entre les 3 tables
$this->addSQLParams('join', $query, array(
'podcasts.`idpodcast`' => 'podcast_spectacle.`idpodcast`',
));
// $this->addSQLParams('where',$query,array(
// array('podcast_spectacle','idspectacle',$query['special']['idspectacles']),
// 'podcasts.`idpodcast`' => 'podcast_spectacle.`idpodcast`',
// ));
}
// recherche par liaison via podcast_spectacle
if (!empty($query['special']['idspectacles'])) {
$this->addSQLParams('from', $query, array(
'podcast_spectacle',
));
// jointure entre les 3 tables
$this->addSQLParams('join', $query, array(
'podcasts.`idpodcast`' => 'podcast_spectacle.`idpodcast`',
));
$this->addSQLParams('where', $query, array(
array('podcast_spectacle', 'idspectacle', $query['special']['idspectacles']),
));
}
// recherche par liaison via podcast_text
if (!empty($query['special']['idtexts'])) {
$this->addSQLParams('from', $query, array(
'podcast_text',
));
// jointure entre les 3 tables
$this->addSQLParams('join', $query, array(
'podcasts.`idpodcast`' => 'podcast_text.`idpodcast`',
));
$this->addSQLParams('where', $query, array(
array('podcast_text', 'idtext', $query['special']['idtexts']),
));
}
// franceculture ou culturebox
if (!empty($query['special']['type_podcast'])) {
if (is_array($query['special']['type_podcast'])) {
$first = true;
foreach ($query['special']['type_podcast'] as $item) {
$opt = 'OR';
if ($first) {
$opt = 'AND (';
$first = false;
}
$query['where'][] = ' ' . $opt . ' `podcasts`.`code_' . $item . '` IS NOT NULL';
}
$query['where'][] = ')';
} else {
if ($query['special']['type_podcast'] == 'franceculture') {
$this->addSQLParams('where', $query, array(
array('podcasts', 'code_franceinter', 'ISNOTNULL'),
));
}
if ($query['special']['type_podcast'] == 'soundcloud') {
$this->addSQLParams('where', $query, array(
array('podcasts', 'code_soundcloud', 'ISNOTNULL'),
));
}
if ($query['special']['type_podcast'] == 'spotify') {
$this->addSQLParams('where', $query, array(
array('podcasts', 'code_spotify', 'ISNOTNULL'),
));
}
if ($query['special']['type_podcast'] == 'arte') {
$this->addSQLParams('where', $query, array(
array('podcasts', 'code_arte', 'ISNOTNULL'),
));
}
if ($query['special']['type_podcast'] == 'culturebox') {
$this->addSQLParams('where', $query, array(
array('podcasts', 'code_ft', 'ISNOTNULL'),
));
// uniquement les actifs
if (!empty($query['special']['current'])) {
$this->addSQLParams('where', $query, array(
array('podcasts', 'debut_visionnage_ft', date('Y-m-d'), 'AND', '<='),
array('podcasts', 'fin_visionnage_ft', date('Y-m-d'), 'AND', '>'),
));
}
// uniquement les actifs avec les dates de fin vide
if (!empty($query['special']['current_start_and_end_empty'])) {
$this->addSQLParams('where', $query, array(
array('podcasts', 'debut_visionnage_ft', date('Y-m-d H:i:s'), 'AND', '<=')
));
}
// uniquement les a venir
if (!empty($query['special']['next'])) {
$this->addSQLParams('where', $query, array(
array('podcasts', 'debut_visionnage_ft', date('Y-m-d'), 'AND', '>'),
));
}
}
}
}
if (!empty($query['special']['type_diffusion'])) {
$this->addSQLParams('where', $query, array(
array('podcasts', 'type_diffusion', $query['special']['type_diffusion']),
));
} else {
$query['where'][] = 'AND (`podcasts`.`type_diffusion` IS NULL OR `podcasts`.`type_diffusion` = 0)';
}
if (!empty($query['special']['emission'])) {
//franceculture
if (is_array($query['special']['emission'])) {
$query['where'][] = 'AND `podcasts`.`name_program` IN ("' . implode('","', $query['special']['emission']) . '")';
// $query['where'][] = 'AND podcasts`.`name_program` IN (une-vie-une-oeuvre)';s
} else {
$this->addSQLParams('where', $query, array(
array('podcasts', 'name_program', $this->escape($query['special']['emission'])),
));
}
}
if (array_key_exists('type_franceinter', $query['special'])) {
if (is_numeric($query['special']['type_franceinter']) && $query['special']['type_franceinter'] != 0) {
$this->addSQLParams('where', $query, array(
array('podcasts', 'type_franceinter', (int)$query['special']['type_franceinter']),
));
} else {
$query['where'][] = 'AND (podcasts.type_franceinter is NULL OR podcasts.type_franceinter = 0)';
}
}
if (!empty($query['special']['is_integrale'])) {
$this->addSQLParams('where', $query, array(
array('podcasts', 'is_integrale', 1),
));
}
if (empty($query['order'])) {
if (!empty($query['special']['lastchance'])) {
$this->addSQLParams('order', $query, array(
array('podcasts' => 'fin_visionnage_ft'),
));
$query['direction'] = 'ASC';
} elseif (!empty($query['special']['order'])) {
$this->addSQLParams('order', $query, array(
$query['special']['order']
));
} else {
$this->addSQLParams('order', $query, array(
array('podcasts' => 'date_podcast'),
));
}
}
return $this->getSQLObject($query);
}
// }}}
// {{{ getListEmissions()
/** Retourne des listes des émissionss
*
* Retourne des listes de émissions au format "standard""
*
* @access public
* @param array $params_sql paramètre pour la requete SQL
* @return array
*/
public function getListEmissions($params_sql = null, $params_exec = null)
{
// si pas de tableau
if (!isset($params_sql['special'])) {
$params_sql['special'] = array();
}
if (!isset($params_sql['params'])) {
$params_sql['params'] = array();
}
// construction de la requête avec le passage de paramètres
$sql = $this->getSQLPodcasts($params_sql);
// paramètre de debug
$dbg = (empty($params_sql['dbg'])) ? array() : $dbg = $params_sql['dbg'];
// executer la requete
$this->query($sql, $dbg);
// debug
$start_boucle = microtime(true);
// on boucle
$emissions = array();
while ($this->fetch()) {
if (!empty($this->name_program)) {
$datas = [
'title' => $this->title,
'title_program' => $this->title_program,
'name_program' => $this->name_program
];
}
if (!empty($this->title)) {
$datas['count_infos_total'] = 0;
$arrayTypes = (!empty(empty($params_exec['getRelations']))) ? $params_exec['getRelations'] : $this->array_types;
foreach ($arrayTypes as $item) {
$datas[$item] = $this->noPunct($this->getLinkedObject($this->getRelationsArray($item), $this->idpodcast, $item, 'podcasts'));
$datas['count_infos_total'] += count($datas[$item]);
}
}
if (!empty($datas)) {
$emissions[] = $datas;
}
}
// debug de la boucle
if ($this->isTraceMode('list_object')) {
$this->setTraceInfos(array(
'execution_time_boucle' => microtime(true) - $start_boucle,
'nb_occurence' => count($emissions),
'dbg' => $dbg,
));
}
$this->free();
return $emissions;
}
// {{{ getListPodcasts()
/** Retourne des listes de podcasts
*
* Retourne des listes de podcast au format "standard""
*
* @access public
* @param array $params_sql paramètre pour la requete SQL
* @param array $format_vignette de la vignette si pas standard
* @param array $params_display paramètre pour l'affichage
* @return array
*/
public function getListPodcasts($params_sql = null, $format_vignette = array(), $params_display = array())
{
// si pas de tableau
if (!isset($params_sql['special'])) {
$params_sql['special'] = array();
}
if (!isset($params_sql['params'])) {
$params_sql['params'] = array();
}
// construction de la requête avec le passage de paramètres
$sql = $this->getSQLPodcasts($params_sql);
// paramètre de debug
$dbg = (empty($params_sql['dbg'])) ? array() : $dbg = $params_sql['dbg'];
// executer la requete
$this->datas = $datas = $this->query($sql, $dbg);
$videos = array();
// donnée entières ?
if (empty($params_display['alldata'])) {
$params_display['alldata'] = false;
}
// debug
$start_boucle = microtime(true);
$podcasts = array();
// format de la vignette
if (empty($format_vignette)) {
$format_vignette = array('width' => 100, 'height' => 70, 'direction' => 'thumb');
}
$format_vignette_infosPodcast = [
'format_vignette' => $format_vignette,
];
if (!empty($params_display['franceculture_width'])) {
$format_vignette_infosPodcast['franceculture_width'] = $params_display['franceculture_width'];
}
// on boucle
while ($this->fetch()) {
// le total
if (!empty($params_sql['count_only'])) {
return $this->total;
}
$idpodcast = $this->idpodcast;
if (!empty($params_sql['fields'])) {
foreach ($params_sql['fields'] as $f) {
$podcasts[$idpodcast][$f] = $this->$f;
}
} else {
$podcasts[$idpodcast] = $this->getInfosPodcast($idpodcast, array('all' => true), $format_vignette_infosPodcast);
}
// si il ne reste plus de jours, on supprime
if (!empty($params_sql['special']['type_podcast']) && $params_sql['special']['type_podcast'] == 'culturebox') {
if (!empty($podcasts[$idpodcast]['fin_visionnage_ft']) && $podcasts[$idpodcast]['fin_visionnage_ft'] != '0000-00-00 00:00:00') {
if ($podcasts[$idpodcast]['fin_visionnage_ft'] < date('Y-m-d H:i:s')) {
unset($podcasts[$idpodcast]);
} else {
$podcasts[$idpodcast]['is_permanent'] = 1;
}
} else {
if (empty($podcasts[$idpodcast]['is_permanent'])) {
if (empty($podcasts[$idpodcast]['day_left']) || $podcasts[$idpodcast]['day_left'] < 1) {
unset($podcasts[$idpodcast]);
}
} else {
$podcasts[$idpodcast]['is_permanent'] = 1;
}
}
}
}
// debug de la boucle
if ($this->isTraceMode('list_object')) {
$this->setTraceInfos(array(
'execution_time_boucle' => microtime(true) - $start_boucle,
'nb_occurence' => count($podcasts),
'dbg' => $dbg,
));
}
// dump($podcasts);
$this->free();
return $podcasts;
}
// }}}
// {{{ getObjectTitle()
/** Infos de l'item recherché
*
* Affichage standard du titre de l'objet
*
* @access public
* @param int $idobject Identifiant de l'item
* @param array $infos_object Informations pour construire le titre
* @param array $params Paramétres supplémentaires
* @return string
*/
public function getObjectTitle($idobject = null, $infos_object = array(), $params = array())
{
$title = '';
if (!$idobject) {
$idobject = $this->idpodcast;
}
// champs
$fields = array('idpodcast', 'title', 'url_clean');
if (!empty($infos_object)) {
foreach ($fields as $k => $v) {
if (array_key_exists($v, $infos_object)) {
$$v = $infos_object[$v];
}
}
} else {
//charger les infos que si necessaire
if (empty($this->title)) {
$this->selectAdd();
$this->selectAdd(implode(',', $fields));
$this->get($idobject);
}
foreach ($fields as $k => $v) {
if (isset($this->$v) && $this->$v != '') {
$$v = trim($this->$v);
}
}
}
return $title;
}
// }}}
// {{{ getListSearch()
/** Liste des podcasts
*
* Pour les champs Ajax de relations et les recherches diverses
*
* @access public
* @param string $lettres Pour la recherche alphabetique
* @param string $type Pour le type recherche (editeurs, revues...)
* @param string $keywords Recherche par mots cles
* @return array
*/
public function getListSearch($lettre, $type = null, $keywords = null)
{
$sql = 'SELECT ' . $this->__idtable . ', title
FROM ' . $this->__table . '
WHERE 1 ';
// selection par ordre alpha
if (!empty($lettre) && $lettre != 'tous') {
$sql_where[] = array('LOWER(LEFT(LTRIM(title),1))=\'' . $this->escape($lettre) . '\'');
}
// recherche avec un mot cle
$list = $this->splitKeywords($keywords);
if ($list) {
if (!empty($list[$this->IDSTR])) {
// mots clés
foreach ($list[$this->IDSTR] as $s) {
$sql_more_name[] = 'title LIKE \'%' . $s . '%\'';
}
$sql_where[] = array('(' . join(' OR ', $sql_more_name) . ')');
}
if (!empty($list[$this->IDNUM])) {
// recherche par numéro d'id pour les mots clés numériques
$sql_where[] = array('idpodcast IN (' . implode(',', $list[$this->IDNUM]) . ')', 'OR');
}
}
foreach ($sql_where as $k => $v) {
if (!empty($v[1])) {
$sql .= ' ' . $v[1] . ' ' . $v[0];
} else {
$sql .= ' AND ' . $v[0];
}
}
$sql .= ' ORDER BY title';
$this->query($sql);
$r = array();
while ($this->fetch()) {
$r[$this->idpodcast] = $this->title;
// si trouvé par id, on l'affiche en fin de titre
if (!empty($list[$this->IDNUM]) && in_array($this->idpodcast, $list[$this->IDNUM])) {
$r[$this->idpodcast] .= ' - n°' . $this->idpodcast;
}
}
$this->free();
return $r;
}
// }}}
// {{{ countPodcasts()
/** Nombre de podcast
*
* Compter le nb de podcast
*
* @access public
* @param string $obect Pour la recherche alphabetique
* @param integer $idobject Pour le type recherche (editeurs, revues...)
* @param string $type Type de contenu
* @return int
*/
public function countPodcasts($object = null, $idobject = null, $type = null, $only_object = false)
{
if (!empty($object) && !empty($idobject)) {
$object = substr($object, 0, -1);
$sql_count = '
SELECT COUNT(DISTINCT(d.`' . $this->__idtable . '`)) as total
FROM ' . $this->__table . ' d, podcast_' . $object . ' do
WHERE d.`publish`=1
AND do.`idpodcast`= d.`idpodcast`';
if (is_array($idobject)) {
$sql_count .= ' AND do.`id' . $object . '` IN(' . implode(',', $idobject) . ')';
} else {
$sql_count .= ' AND do.`id' . $object . '`=' . (int)$idobject;
}
} else {
$sql_count = '
SELECT COUNT(DISTINCT(' . $this->__idtable . ')) as total
FROM ' . $this->__table . ' d
WHERE publish=1';
}
if (!is_null($type)) {
if (isset($type['type_franceinter'])) {
$sql_count .= ' AND d.code_franceinter IS NOT NULL ';
if ($type['type_franceinter'] == 0) {
$sql_count .= ' AND (d.type_franceinter = 0 OR d.type_franceinter IS NULL)';
} else {
$sql_count .= ' AND d.type_franceinter = ' . (int)$type['type_franceinter'];
}
} else {
$sql_count .= ' AND d.code_' . $type . ' IS NOT NULL ';
}
}
$total = null;
if ($only_object && empty($idobject)) {
return $total;
}
$total = $this->queryOne($sql_count);
if ($total) {
return $total;
} else {
return null;
}
}
// }}}
public function countPodcastsForContact (int $idcontact): string
{
return $this->createQueryBuilder('p')
->select('count(p.idpodcast)')
->join('p.idcontact', 'pc')
->where('pc.idcontact = :id')
->setParameter('id', $idcontact)
->getQuery()
->getSingleScalarResult();
}
// {{{ countListPodcasts()
/** Compter la liste des podcast
*
* @access public
* @param array $params_sql paramètre pour la requete SQL
* @param bool $debug mode débugage
* @return int
*/
public function countListPodcasts($params_sql = null, $debug = false)
{
// si pas de limite => tout
if (empty($params_sql['limit'])) {
$params_sql['limit'] = array('all');
}
$params_sql['count_only'] = true;
// construction de la requête avec le passage de paramètres
return $this->queryOne($this->getSQLPodcasts($params_sql, $debug));
}
// }}}
// {{{ getByCodeFt()
/** Récupèrer par le code FT
*
* @access public
* @return int
*/
public function getByCodeFt($code_ft)
{
try {
$sql = '
SELECT *
FROM ' . $this->__table . '
WHERE `code_ft`=' . (int)$code_ft;
$podcast = $this->queryRow($sql);
return $podcast;
} catch (\Throwable $e) {
return null;
}
}
// }}}
// {{{ getByCodeRadioFrance()
/** Récupèrer par le code FT
*
* @access public
* @return int
*/
public function getByCodeRadioFrance($code_ft)
{
try {
$sql = '
SELECT *
FROM ' . $this->__table . '
WHERE `code_franceinter`="' . $code_ft . '"';
$podcast = $this->queryRow($sql);
return $podcast;
} catch (\Throwable $e) {
return null;
}
}
// }}}
// {{{ getVignettePodcast()
/** Récupère la vignette d'un podcast ou la cree si besoin
*
* @access public
* @param int idpodcast identifiant du podcast
* @param array format $format de la vignette
* @return string
*/
public function getVignettePodcast($idpodcast = null, $format = array(), $url_file = null)
{
// id de la podcast
if (empty($idpodcast)) {
$idpodcast = $this->idpodcast;
}
$idpodcast = (int)$idpodcast;
// par default : image arrondie crop 100px x 100px qualite 75
if (!empty($format)) {
$set_format = $format;
} else {
$set_format = array('width' => 80, 'height' => 80, 'direction' => 'crop', 'default' => '../../default/podcasts-def.png');
}
if (!empty($url_file)) {
$url_file = $_ENV['PATH_DIRECTORYUPLOAD'] . 'podcasts/src/' . $this->images->getHashDir($url_file, true) . $url_file;
} else {
$sql = 'SELECT url_file FROM ' . $this->__table . ' WHERE idpodcast=' . (int)$idpodcast;
$url_file = $this->queryOne($sql);
// if(empty($url_file)) {
// $url_file = null;
// } else {
$url_file = $_ENV['PATH_DIRECTORYUPLOAD'] . 'podcasts/src/' . $this->images->getHashDir($url_file, true) . $url_file;
// }
}
$this->images->setVignetteFormat($set_format);
return $this->images->getVignetteObject($idpodcast, 'podcasts', 'unknow_classification', $url_file);
}
// }}}
// {{{ delete()
/** Supprimer une podcasts et ses images
*
* @access public
* @param int idpodcast identifiant du podcast
* @param array format $format de la vignette
* @return string
*/
public function deleteData($idpodcast = null, $url_file = null)
{
// si on a l'URL du fichier, on peux le supprimer ainsi que ses vignettes
if (empty($url_file)) {
try {
$sql = 'SELECT url_file FROM ' . $this->__table . ' WHERE idpodcast=' . (int)$idpodcast;
$url_file = $this->queryOne($sql);
} catch (\Throwable $e) {
$url_file = null;
}
}
if (!empty($url_file)) {
// classe des images
if (!isset($this->images)) {
require_once PATH_LIBS . 'Images/Images.php';
$this->images = new Images();
}
$url_file_src = PATH_DIRECTORYUPLOAD . 'podcasts/src/' . $this->images->getHashDir($url_file, true) . $url_file;
// supprimer les vignettes
$files = $this->getEntityManager()->getRepository(Files::class);
$files->deleteVignettes(null, 'podcasts', $idpodcast, array('file' => $url_file));
// supprimer le fichier
if (file_exists($url_file_src)) {
@unlink($url_file_src);
}
}
// supprimer la podcasts
parent::deleteData($idpodcast);
return true;
}
// }}}
// {{{ getTypeFranceInter()
/** Récupérer la liste des différentes stations de Radio France
*
* @access public
* @return array
*/
public function getTypeFranceInter()
{
return $this->franceinter_types;
}
// }}}
}