<?php
namespace App\Controller;
use App\ClassTheatre\asides;
use App\ClassTheatre\TheatreController;
use App\Exception\RedirectException;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
use TheatreCore\Entity\AnnAnnonces;
use TheatreCore\Entity\Bigregions;
use TheatreCore\Entity\Contacts;
use TheatreCore\Entity\Contents;
use TheatreCore\Entity\Multimedias;
use TheatreCore\Entity\News;
use TheatreCore\Entity\Persons;
use TheatreCore\Entity\Playlists;
use TheatreCore\Entity\Spectacles;
use TheatreCore\Entity\Texts;
class RegionsController extends TheatreController
{
// objet newsletters
public $newsletters = null;
// objet abonnés / subscribers
public $subscribers = null;
// raccourci view
public $view = null;
// raccourci form
public $form = null;
//les aides
private $asides = null;
private $menu_content = null;
private $area = null;
private $regions = null;
private $spectacles = null;
// {{{ _construct()
public function __construct(EntityManagerInterface $em, TranslatorInterface $translator, TokenStorageInterface $tokenStorage)
{
parent::__construct($translator, $tokenStorage);
$this->context['controller'] = $this->view->controller = 'regions';
$this->em = $em;
}
// }}}
// {{{
private function InitController($area = null, $action = null)
{
$this->view->action = $this->context['action'] = $action;
// regions
$this->regions = $this->em->getRepository(Bigregions::class);
$this->spectacles = $this->em->getRepository(Spectacles::class);
$this->area = $area;
//si une zone est bien sélectionné par l'utilisateur
if($this->area){
// nom de la région et code
if($this->regions->my_is_int($this->area)) {
//le nom de la région
$this->context['view']->region_name = $this->regions->getRegionName($this->area);
} else {
//le nom du pays
$this->context['view']->country_name = $this->spectacles->getNameCountry($this->area);
}
$this->context['view']->area = $this->area;
$this->asides = new asides();
}
//sinon on redirige l'utiisateur dans la bonne direction
else{
throw new RedirectException($this->generateUrl('index'));
}
}
// }}}
// {{{ finalizeAction()
/** Code exécuté après chaque action
*
*
* @access protected
* @return void
*/
protected function finalizeAction(){
$this->getAsides();
$this->context['view']->aside = $this->asides->view($this->context['view']);
$region_name = (!empty($this->context['view']->region_name)) ? $this->context['view']->region_name : $this->context['view']->country_name;
$this->context['view']->meta_description = 'Toute l\'actualité de la scène théâtrale contemporaine en '.$region_name.'. Textes théâtraux contemporains et classiques, danse, performances, opéra... Le site propose des contenus pédagogiques, des vidéos, des critiques, des sélections de textes...';
$asides_top = new asides();
$asides_top->load(['aside_top' => array(
'php' => array(
'method' => 'asidesUrlRegions',
)
)
]);
$this->context['view']->aside_top = $asides_top->view($this->context['view']);
}
// // }}}
// {{{ action_actualites()
/** page d'accueil de la région
*
* @Route("/regions/actualites/area/{area}", name="regions_actualites")
*
* @access public
* @return void
*/
public function action_actualites($area = null)
{
$this->InitController($area, 'actualites');
$ann_annonces = $this->em->getRepository(AnnAnnonces::class);
// SQL des régions
$sql_region = $this->em->getRepository(Bigregions::class)->getZipCode($this->area, 'contacts');
if ($sql_region) {
$this->context['view']->dernieres_annonces_emploi = $ann_annonces->getLastAnnonces(array(0,3),array(3),65, $this->area);
$this->context['view']->dernieres_annonces_stages = $ann_annonces->getLastAnnonces(array(0,3),array(1),65, $this->area);
} else {
return $this->redirectToRoute('erreur_type', ['type' => 'introuvable']);
}
//On récupère la liste des écoles disponibles pour la région
$idtypestructure = 'EC';
$params_sql_typestructure = array(
'where' => array(
array('contacts', 'idtypestructure', $idtypestructure),
' AND contacts.idcontact NOT IN (SELECT idcontact FROM contact_classification WHERE idclassification=99) ',
' AND '.$sql_region.' '
),
'order' => array('contacts' => 'organisation'),
'direction' => 'ASC',
'idclassification' => array('NOT' => array(99)),
'limit' => array(0,300),
'dbg' => array('ecoles','Ecoles supérieures'),
);
$this->context['view']->ecoles = $this->em->getRepository(Contacts::class)->getListContacts($params_sql_typestructure,array(),array('get_profile_picture' => true));
$this->getSpectaclesAffiches(); //les spectacles à l'affiche
$this->getSpectaclesJTN();
$this->getContamporainAffiche(); //les auteurs contemporainrs à l'affiche
$this->getSpectaclesAffichesVideos(); //les spectacles à l'affiche en vidéo
$this->getEvenements(); //les évènements
$this->getCritiques(); //les critiques
$this->getTextesByAuteurs(); //textes par l'auteur (inutilisé ?)
$this->getSpectaclesEduc(); //(inutilisé ?)
$this->getFondsInsertionProfessionnels();
return $this->view('regions/actualites.html.twig');
}
// }}}
// {{{ action_videos()
/** page d'accueil de la région
*
*
* @access public
* @return void
*/
public function action_videos(){
echo" ok";
exit;
}
// }}}
// {{{ getContamporainAffiche()
/** Nous récupérons les informrations des auteurs contemporains à l'affiche
*
*
* @access public
* @return void
*/
private function getContamporainAffiche(){
$person = $this->em->getRepository(Persons::class);
$sql_area = ' AND '.$this->regions->getZipCode($this->area);
$params_sql = array(
'special' => array(
'with_photo' => true,
'spectacle' => array(
'type' => 'author',
'prochains' => '365D',
'person_periode' => 'contemporain',
// 'text_edite' => true,
'country' => 'FR'
),
'random' => '',
),
'params' => array(
'limit' => array(0,4),
'where' => $sql_area
),
'dbg' => array('affiche_persons','Les auteurs à l\'affiche')
);
$params_display['vignette_format'] = array('width'=>$_ENV['VIGN_PERSONS_WIDTH'],'height'=>$_ENV['VIGN_PERSONS_HEIGHT'],'direction'=>'crop');
$this->context['view']->persons = $person->getListPersons($params_sql,$params_display);
}
// }}}
public function getSpectaclesAffichesVideos(){
$multimedias = $this->em->getRepository(Multimedias::class);
$sql_area = ' AND'.$this->regions->getZipCode($this->area,'contacts');
$params_videos_affiche = array(
'where' => array($sql_area),
'affiche' => array('today' => 365),
'limit' => array(0,5),
'dbg' => array('affiche','Vidéos de spectacles à l\'affiche'),
);
$video_tete_result = $multimedias->getListMultimedias($params_videos_affiche,
array('width'=>$_ENV['VIGN_VIDEO_WIDTH'],'height'=>$_ENV['VIGN_VIDEO_HEIGHT'],'fleche'=>'none','ratio' => '169'),
array('get_schedule' => true, 'get_schedule_ville' => $this->area,'format_vignette' => true));
foreach($video_tete_result as $k=>$v) {
$video_tete = $v;
unset($video_tete_result[$v['idmultimedia']]);
break;
}
if(!empty($video_tete)){
$set_format = array('width'=>$_ENV['VIGN_VIDEO_WIDTH'],'height'=>$_ENV['VIGN_VIDEO_HEIGHT'],'fleche'=>'none','ratio' => '169');
$video_tete = array_merge($video_tete, array(
'vignette' => $multimedias->getVignetteMultimedia($video_tete['idmultimedia'],$set_format),
'description_courte' => $multimedias->cutSentence($video_tete['description'],100),
'langue' => $multimedias->getNameLanguage($video_tete['language'])
));
// lien vers la video
foreach($video_tete['spectacles'] as $s) {
$video_tete['url_clean_video'] = '/spectacles/'.$s['url_clean'].'/videos/'.$video_tete['url_clean'].'?autostart';
}
$this->context['view']->video_tete = array($video_tete);
}
$this->context['view']->videos_affiche = $video_tete_result;
}
//on récupère les textes par l'auteurs auteurs
public function getTextesByAuteurs(){
$textes = $this->em->getRepository(Texts::class);
$params_sql_spectacles = array(
'params' => array(
'limit' => array(0,2),
),
'special' => array(
'playlists' => array(
'text' => true,
'idclassifications' => array(144), // par l'auteur
),
'textfictif' => 0,
'prochains' => '365',
'area' => $this->area,
'carte_version' => 'bigregions',
'get_schedule_ville' => $this->area
// 'plus_proche' => true,
),
'dbg' => array('spectacles_auteurs_affiche','Texte par l\'auteur à l\'affiche'),
);
$list_spectacles = $this->spectacles->getListSpectacles($params_sql_spectacles, null, false, ['carrer_couleurs' => true]);
$this->context['view']->textes_par_auteurs = $textes->getTextsFromSpectacles($list_spectacles);
if(isset($this->context['view']->textes_par_auteurs)) {
foreach ($this->context['view']->textes_par_auteurs as $k => $v) {
// voir s'il y a des contenus le texte par l'auteur
if ($this->em->getRepository(Playlists::class)->countPlaylists('texts', $v['idtext'], 'class_texte_parauteur') > 0) {
$playlist = $this->em->getRepository(Playlists::class)->getByClassification('texts', $v['idtext'], 'class_texte_parauteur');
$this->context['view']->textes_par_auteurs[$k]['url_clean_more'] = 'playlist/id/' . $playlist['urlClean'];
$playlists = $this->em->getRepository(Playlists::class);
$sql = 'SELECT p.idplaylist
FROM playlists p
LEFT JOIN playlist_classification pc ON p.idplaylist = pc.idplaylist
WHERE pc.idclassification = 144 AND p.idtext = '.$v['idtext'].'
GROUP BY p.idtext';
$x = $playlists->queryOne($sql);
$pl = $playlists->getInfosPlaylist(
$x,
array(
'all' => true,
'multimedias' => true,
'format_vignette' => array('width'=>$_ENV['VIGN_VIDEO_WIDTH'],'height'=>$_ENV['VIGN_VIDEO_HEIGHT'],'fleche'=>'none','ratio' => '169') //'direction'=>'crop'
),
array('format_vignette' => true)
);
$video = (array_shift($pl['multimedias']));
$this->context['view']->textes_par_auteurs[$k]['playlist']['vignette'] = $video['vignette'];
$this->context['view']->textes_par_auteurs[$k]['playlist']['vignette_flou'] = $video['vignette_flou'];
$this->context['view']->textes_par_auteurs[$k]['playlist']['thtv'] = true;
$this->context['view']->textes_par_auteurs[$k]['playlist']['thtv_permalink'] = $video['permalink'];
$this->context['view']->textes_par_auteurs[$k]['playlist']['url_clean_video'] = $playlist['urlClean'];
}
}
}
}
public function getEvenements()
{
$news = $this->em->getRepository(News::class);
// récupérer les prochains évènements
$news_params = array(
'params' => array(
'limit' => array(0,5),
),
'special' => array(
'prochains' => 365,
'publish_valid' => true,
'type_news' => 'news',
// 'is_homepage' => 1,
'idbigregion' => array($this->area)
),
'dbg' => array('news','Liste des prochains évènements')
);
$total_prochains_evements = 0;
$this->context['view']->is_news_list_news = true;
if($contents = $news->getListNews($news_params)){
$this->context['view']->news_list_news['prochains'] = $contents;
$total_prochains_evements = count($contents);
}
unset($news_params['special']['prochains']);
$news_params['params']['limit'] = array(0, 5 - $total_prochains_evements);
$news_params['special']['anciens'] = true;
if($contents = $news->getListNews($news_params)){
$this->context['view']->news_list_news['anciens'] = $contents;
}
}
public function getCritiques() {
$where_zone = ' AND'.$this->regions->getZipCode($this->area);
/* -- les dernières critiques -- */
$params_sql_regions = array(
'params' => array(
'where' => $where_zone,
'limit' => array(0, 4),
'groupby' => 'sc.date'
// 'order' => 'sc.date DESC'
),
'special' => array(
'prochains' => 365,
'publish_valid' => 1,
// 'random' => '',
'idclassification' => 101,
'get_schedule_ville' => $this->area
),
'dbg' => array('affiche_region','A l\'affiche en région')
);
$this->context['view']->critiques_spectacles = $this->spectacles->getListSpectacles($params_sql_regions,array(),false,['allauthors' => true, 'carrer_couleurs' => true]);
$nb_total_critiques = 0;
$contents = $this->em->getRepository(Contents::class);
foreach($this->context['view']->critiques_spectacles AS $k => $v){
$this->context['view']->critiques_spectacles[$k]['footer_critique'] = true;
$nb_total_critiques += $this->context['view']->critiques_spectacles[$k]['nombre_critique'] = $contents->countAssociateContent('spectacles',$v['idspectacle'],'class_critique',array('publish_valid' => 1));
}
}
public function getSpectaclesAffiches() {
$contacts = $this->em->getRepository(Contacts::class);
$where_zone = $this->regions->getZipCode($this->area);
//Spectacles à l'afafiche en régions :
$params_spectacles_affiche = array(
'params' => array(
'where' => $where_zone,
'limit' => array(0,6),
),
'special' => array(
'prochains' => 365,
//ancienne condition remplacer par structures_specifiques && idtypestructure
// 'random' => '',
'publish_valid' => 1, // les spectacles publiées
'get_schedule_ville' => $this->area
),
'dbg' => array('spectacles_affiche_region', 'Spectacles à l\'affiche pour la région ')
);
$params_display = array('allauthors' => true, 'carrer_couleurs' => true);
$format_vignette['vignette'] = array('width' => $_ENV['VIGN_SPECTACLE_HEIGHT'],'height' => $_ENV['VIGN_SPECTACLE_HEIGHT'], 'direction'=>'crop');
$spectacles_affiche = $this->spectacles->getListSpectacles($params_spectacles_affiche,$format_vignette,false,$params_display);
foreach($spectacles_affiche as $k=>$v) {
//ajout footer_contact pour region spectacles
$spectacles_affiche[$k]['footer_contact'] = true;
}
$this->view->spectacles_affiche = $spectacles_affiche;
//Spectacles à l'affiche dans les strucutres correspondants TN/CDN/Autres théare
$nb_spectacles = 2;
$groupe_contacts = array(128,129,130,131);
if(in_array($this->area, ['CH','BE','LU'])){
$nb_spectacles = 6;
$groupe_contacts = array(113); //autres théâtres partenaires
}
$partenaires = $contacts->getContactsByClassification($groupe_contacts, null, null, null, $this->area);// idgroupclassification = 10
// grouper par type de partenaires
if(in_array($this->area, ['CH','BE','LU'])){
foreach($partenaires as $k=>$v) {
$spectacles_affiche_order['THIN']['contacts'][$v['idcontact']] = $v;
$spectacles_affiche_order['THIN']['idcontacts'][$v['idcontact']] = $v['idcontact'];
$spectacles_affiche_order['THIN']['idclassification'] = $v['idclassification'];
$spectacles_affiche_order['THIN']['idtypestructure'] = 'THIN';
}
}
else{
foreach($partenaires as $k=>$v) {
$spectacles_affiche_order[$v['idtypestructure']]['contacts'][$v['idcontact']] = $v;
$spectacles_affiche_order[$v['idtypestructure']]['idcontacts'][$v['idcontact']] = $v['idcontact'];
if($v['idtypestructure']=='THIN') {
$spectacles_affiche_order[$v['idtypestructure']]['classification'] = 'Autres théâtres partenaires';
$spectacles_affiche_order[$v['idtypestructure']]['no_link'] = true;
$spectacles_affiche_order[$v['idtypestructure']]['classification_nomaj'] = strtolower($spectacles_affiche_order[$v['idtypestructure']]['classification']);
} elseif($v['idtypestructure']=='CDN') {
$spectacles_affiche_order[$v['idtypestructure']]['classification'] = 'Centres dramatiques';
$spectacles_affiche_order[$v['idtypestructure']]['classification_nomaj'] = 'centres dramatiques';
} else {
$spectacles_affiche_order[$v['idtypestructure']]['classification_nomaj'] = strtolower($this->context['tr']->trans($v['classification']));
$spectacles_affiche_order[$v['idtypestructure']]['classification'] = $this->context['tr']->trans($v['classification']);
}
$spectacles_affiche_order[$v['idtypestructure']]['idclassification'] = $v['idclassification'];
$spectacles_affiche_order[$v['idtypestructure']]['idtypestructure'] = $v['idtypestructure'];
}
}
if(!empty($spectacles_affiche_order)){
foreach($spectacles_affiche_order as $k=>$v) {
// pour les scènes nationales, rechercher dans toutes les scènes
if($v['idclassification']==130) {
$v['idcontacts'] = array();
$contacts_sn = $this->em->getRepository(Contacts::class)->getListContacts(array(
'idtypestructure' => 'SN',
'limit' => array(0,100),
'dbg' => array('liste_sn', 'liste des scènes nationales'),
));
foreach($contacts_sn as $kb=>$vb) {
$v['idcontacts'][$vb['idcontact']] = $vb['idcontact'];
}
}
// rechercher les spectacles à l'affiche
$params_spectacles_affiche = array(
'params' => array(
'where' => $where_zone,
'limit' => array(0,20),
),
'special' => array(
'prochains' => 365,
//ancienne condition remplacer par structures_specifiques && idtypestructure
'idcontacts' => array('IN', $v['idcontacts']),
'idcontact' => $v['idcontacts'],
// 'random' => '',
'publish_valid' => 1, // les critiques publiées
'get_schedule_ville' => $this->area
),
'dbg' => array('spectacles_'.$v['idtypestructure'], 'Spectacles à l\'affiche pour les '.$v['idtypestructure'])
);
$spectacles_affiche = $this->spectacles->getListSpectacles($params_spectacles_affiche,$format_vignette,false,$params_display);
if(!empty($spectacles_affiche)) {
$spectacles_affiche_reduce = array();
$i = 0;
foreach($spectacles_affiche as $kb=>$vb) {
$vb['footer_contact'] = true;
$spectacles_affiche_reduce[$kb] = $vb;
$i++;
if($i==$nb_spectacles) {
break;
}
}
$spectacles_affiche_order[$k]['spectacles'] = $spectacles_affiche_reduce;
} else {
unset($spectacles_affiche_order[$k]);
}
}
}
$filtre_cdn = ['TN','CDN','SN','THIN'];
foreach($filtre_cdn as $vc){
if(!empty($spectacles_affiche_order[$vc])){
if($spectacles_affiche_order[$vc]){
$spectacles_affiche_by_classification[$vc] = $spectacles_affiche_order[$vc];
}
}
}
if(isset($spectacles_affiche_by_classification)){
$this->context['view']->spectacles_affiche_dans = true;
$this->context['view']->spectacles_affiche_by_contact = $spectacles_affiche_by_classification;
}
}
private function getSpectaclesJTN(){
$where_zone = ' AND'.$this->regions->getZipCode($this->area);
$params_sql_soutien = array(
'params' => array(
'limit' => array(0,20),
'where' => $where_zone
),
'special' => array(
'prochains' => 365,
'random' => '',
'by_classification' => 103,
'get_schedule_ville' => $this->area
),
'dbg' => array('spectacle_soutien','Les spectacles avec un soutien à l\'affiche'),
);
$params_display = array('allauthors' => true, 'carrer_couleurs' => true);
$spectacles_soutien = $this->spectacles->getListSpectacles($params_sql_soutien, array(), false, $params_display);
$nb_spectacles = 2;
if(!empty($spectacles_soutien)) {
$i = 0;
foreach($spectacles_soutien as $k=>$v) {
$v['footer_contact'] = true;
$this->context['view']->spectacles_affiche_dans = true;
$this->context['view']->spectacles_soutien[$k] = $v;
$i++;
if($i==$nb_spectacles) {
break;
}
}
}
}
private function getFondsInsertionProfessionnels()
{
$where_zone = ' AND'.$this->regions->getZipCode($this->area);
// spectacles du JTN
$params_sql_soutien = array(
'params' => array(
'where' => $where_zone,
'limit' => array(0, 4),
),
'special' => array(
'prochains' => 180,
'random' => '',
'aide' => [
'idaidecontact' => 105
],
'spectacle_aide' => true
),
'dbg' => array('spectacle_soutien', 'Les spectacles avec un soutien à l\'affiche'),
);
$format_vignette['vignette'] = array('width' => 100, 'height' => 100, 'direction' => 'crop', 'valround' => 7);
$params_display = array('allauthors' => true);
$spectacles_soutien = $this->spectacles->getListSpectacles($params_sql_soutien, $format_vignette, false, $params_display);
if (!empty($spectacles_soutien)) {
$i = 0;
foreach ($spectacles_soutien as $k => $v) {
$v['footer_contact'] = true;
$this->context['view']->spectacles_soutien[$k] = $v;
}
}
}
private function getSpectaclesEduc(){
// trouver les spectacles qui ont des contenus éduc => 125
$sql = 'SELECT s.`idspectacle` FROM spectacles s
JOIN object_content oc ON oc.`idobject`=s.`idspectacle`
JOIN contents c ON c.`idcontent`=oc.`idcontent`
JOIN content_classification cc ON cc.`idcontent`=c.`idcontent`
WHERE c.publish=1
AND oc.object=\'spectacles\'
AND cc.idclassification=125
AND s.`publish`=1 AND s.`valid`=1';
$idspectacles_from_spectacles = $this->spectacles->queryCol($sql);
if(!empty($idspectacles_from_spectacles)) {
foreach($idspectacles_from_spectacles as $k=>$v) {
$idspectacles[$v] = $v;
}
$params_spectacles = array(
'special' => array(
'idspectacle' => $idspectacles,
'plus_proche' => true,
'prochains' => 720,
'area' => $this->area,
'carte_version' => 'bigregions',
'get_schedule_ville' => $this->area
),
'params' => array(
'limit' => 2,
),
'dbg' => array('list_spectacles_educ', 'Liste des spectacles avec un contenu educ'),
);
$this->context['view']->spectacles_educ = $this->spectacles->getListSpectacles($params_spectacles,array(),false,array('allauthors' => true, 'carrer_couleurs' => true));
foreach($this->context['view']->spectacles_educ as $k=>$v) {
$this->context['view']->spectacles_educ[$k]['footer_contact'] = true;
}
$this->context['view']->spectacles_affiche_dans = true;
}
}
private function getAsides(){
$this->asides->load(['common_carte' => array(
'url' => '/regions/actualites/area/get_id'
)]);
asides::setEntityManager($this->em);
asides::loadaside('Publicite')->addWithRegion($this->asides, ['region' => $this->area]); //$this->area
$this->asides->load(['common_carrer_informations'=> array(
'color' => 'spectacles'
)]);
$this->asides->load(['common_prochain_evenement' => array(
'url_custom' => '/evenements/view/area/'.$this->area
)]);
$this->asides->load('common_facebook');
$this->asides->load('common_twitter');
$this->asides->load(['common_participer' => array(
'php' => array(
'method' => 'asidesUrlLists_Ajoutez'
)
)]);
$this->asides->load('contact_ecoles_list');
$this->asides->load('common_offre_annonce');
}
}