<?php
namespace App\Controller;
use App\ClassTheatre\asides;
use App\ClassTheatre\TheatreController;
use App\Exception\RedirectException;
use App\Service\Functions;
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\Contacts;
use TheatreCore\Entity\Contents;
use TheatreCore\Entity\Files;
use TheatreCore\Entity\Multimedias;
use TheatreCore\Entity\News;
use TheatreCore\Entity\Persons;
use TheatreCore\Entity\Playlists;
use TheatreCore\Entity\Spectacles;
use TheatreCore\Entity\Texts;
use TheatreCore\Entity\Typesstructures;
class StructuresController 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 $structures_listes = null;
private $structure = null;
private $spectacles = null;
private $function;
// {{{ _construct()
public function __construct(EntityManagerInterface $em, TranslatorInterface $translator, TokenStorageInterface $tokenStorage, Functions $function)
{
parent::__construct($translator, $tokenStorage);
$this->context['controller'] = $this->view->controller = 'structures';
$this->view->area = '';
$this->em = $em;
$this->function = $function;
$this->spectacles = $em->getRepository(Spectacles::class);
$this->asides = new asides();
}
private function InitController($structure = null, $action = null)
{
$this->view->action = $this->context['action'] = $action;
$choix_structures = array(
'SN',
'TN',
'CDN',
'SC'
);
// les types de structure
$this->structures_listes = $this->em->getRepository(Typesstructures::class)->getTypeStructureList(true,true,$choix_structures);
$this->context['view']->idstructure = $this->structure = $structure;
if(array_key_exists($this->structure, $this->structures_listes)){
$this->context['view']->structure_name = $this->structures_listes[$this->structure];
$this->context['view']->idtypestructure = $this->structure;
}
else{
throw new RedirectException($this->generateUrl('index'));
}
}
public function finalizeAction()
{
$this->getAsides();
$this->context['view']->aside = $this->asides->view($this->context['view']);
$asides_top = new asides();
$asides_top->load(['aside_top' => array(
'php' => array(
'method' => 'asidesUrlListsMenuCDN',
)
)
]);
$this->context['view']->aside_top = $asides_top->view($this->context['view']);
}
// {{{ action_actualites()
/** page d'accueil de la région
*
* @Route("/structures/actualites/{structure}", name="structures_actualites")
*
* @access public
* @return void
*/
public function action_actualites($structure = null)
{
$this->InitController($structure, 'actualites');
$route = $this->getSpectaclesAffiches(); //les spectacles à l'affiche
if ($route != null) {
return $route;
}
$this->getSpectaclesAffichesVideos(); //les spectacles à l'affiche en vidéo
$this->getEvenements(); //les évènements
$this->getDirecteursAffiches(); //textes par l'auteur
// $this->getSpectaclesJTN();
// $this->getContamporainAffiche(); //les auteurs contemporainrs à l'affiche
// $this->getCritiques(); //les critiques
// $this->getTextesByAuteurs(); //textes par l'auteur
$this->context['view']->is_actu = true;
$this->view->locate = array(
0 => 'Actualités'
);
return $this->view('structures/actualites.html.twig');
}
// }}}
// {{{ getEvenements()
public function getDirecteursAffiches(){
$params_sql = array(
'params' => array(
'limit' => array(0,4)
),
'special' => array(
'contact_person' => array(
'idoffice' => 'directeur', // Direction
'idtypestructure' => $this->structure,
'actual' => true
),
'spectacle' => array(
'type' => 'director',
'prochains' => '360D'
),
'random' => '',
),
'dbg' => array('directeur','Les directeurs de '.$this->structure)
);
// echo $this->em->getRepository(Persons::class)->countListPersons($params_sql);
$params_display['vignette_format'] = array('width'=>$_ENV['VIGN_PERSONS_WIDTH'],'height'=>$_ENV['VIGN_PERSONS_HEIGHT'],'direction'=>'crop');
$this->context['view']->directeurs_affiches = $this->em->getRepository(Persons::class)->getListPersons($params_sql,$params_display);
}
// }}}
// {{{ getEvenements()
/** Nous récupérons les informrations des évènéments
*
*
* @access public
* @return void
*/
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' => 180,
'publish_valid' => true,
'type_news' => 'news',
'is_homepage' => 1,
'idtypestructure' => $this->structure
),
'dbg' => array('news','Liste des prochains évènements')
);
$this->context['view']->next_news = $news->getListNews($news_params);
}
// }}}
// {{{ 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 = $this->regions->getZipCode($this->area);
$params_sql = array(
'special' => array(
'with_photo' => true,
'spectacle' => array(
'type' => 'author',
'prochains' => '100D',
'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);
$contacts = $this->getContactsByType($this->structure);
$where_idcontact = ' AND contacts.idcontact IN ('.join(',', $contacts['ids']).') ';
$params_videos_affiche = array(
'where' => array(
// $where_idcontact
array('spectacles','idspectaclegenre',1), // uniquement les spectacles
array('schedules','idcontact',$contacts['ids']), // uniquement dans ces structures
),
'affiche' => array('today' => 120),
'limit' => array(0,4),
'dbg' => array('affiche','Vidéos de spectacles à l\'affiche'),
);
$this->context['view']->videos_affiche = $multimedias->getListMultimedias($params_videos_affiche,
array('width'=>$_ENV['VIGN_VIDEO_WIDTH'],'height'=>$_ENV['VIGN_VIDEO_HEIGHT'],'fleche'=>'none','ratio' => '169'),
array('get_schedule' => $contacts['ids'], 'format_vignette' => true)
);
}
//on récupère les textes par l'auteurs auteurs
public function getTextesByAuteurs(){
$spectacles = $this->em->getRepository(Multimedias::class);
$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' => '150D',
'area' => $this->area,
'plus_proche' => true,
),
'dbg' => array('spectacles_auteurs_affiche','Texte par l\'auteur à l\'affiche'),
);
$list_spectacles = $this->spectacles->getListSpectacles($params_sql_spectacles);
$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['url_clean'];
$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->db->queryOne($sql);
$pl = $playlists->getInfosPlaylist(
$x,
array(
'all' => true,
'multimedias' => true,
'format_vignette' => array('width'=>325,'height'=>162,'fleche'=>'none') //'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['url_clean'];
}
}
}
}
public function getCritiques(){
$spectacles = $this->em->getRepository(Multimedias::class);
$where_genre = ' ';
$where_zone = $sql_area = $this->regions->getZipCode($this->area);
/* -- les dernières critiques -- */
$params_sql_regions = array(
'params' => array(
'where' => $where_genre.$where_zone,
'limit' => array(0, 4),
),
'special' => array(
'prochains' => true,
'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]);
$nb_total_critiques = 0;
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'] = $this->em->getRepository(Contents::class)->countAssociateContent('spectacles',$v['idspectacle'],'class_critique',array('publish_valid' => 1));
}
}
public function getSpectaclesAffiches(){
$contacts = $this->em->getRepository(Contacts::class);
// trouver les contacts correspondants TN/CDN/Autres théare
$nb_spectacles = 2;
$groupe_contacts = array(128,129,130,131);
$partenaires = $contacts->getContactsByClassification($groupe_contacts);// idgroupclassification = 10
// grouper par type de partenaires
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 (!isset($spectacles_affiche_order[$this->structure])) {
return $this->redirectToRoute('erreur_type', ['type' => 'introuvable']);
}
$structure_selected[$this->structure] = $spectacles_affiche_order[$this->structure];
unset($spectacles_affiche_order);
foreach($structure_selected 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'];
}
}
$where_idcontact = ' AND contacts.idcontact IN ('.join(',', $v['idcontacts']).') ';
// rechercher les spectacles à l'affiche
$params_spectacles_affiche = array(
'params' => array(
'where' => $where_idcontact.' AND s.publish=1 ',
'limit' => array(0,6),
),
'special' => array(
'prochains' => 150,
'random' => '',
'publish_valid' => 1, // les critiques publiées
// 'get_schedule_ville' => $this->area
'structures_specifiques' => $this->structure
),
'dbg' => array('spectacles_'.$v['idtypestructure'], 'Spectacles à l\'affiche pour les '.$v['idtypestructure'])
);
if(!in_array($this->area, ['CH','BE','LU'])){
$params_spectacles_affiche['idcontacts'] = array('IN', $v['idcontacts']);
$params_spectacles_affiche['idcontact'] = $v['idcontacts'];
}
$params_display = array('allauthors' => 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);
if(!empty($spectacles_affiche)) {
$spectacles_affiche_reduce = array();
foreach($spectacles_affiche as $kb=>$vb) {
$vb['footer_contact'] = true;
$spectacles_affiche_reduce[$kb] = $vb;
}
$structure_selected[$k]['spectacles'] = $spectacles_affiche_reduce;
} else {
unset($structure_selected[$k]);
}
}
$filtre_cdn = ['TN','CDN','SN','THIN'];
foreach($filtre_cdn as $vc){
if(!empty($structure_selected[$vc])){
if($structure_selected[$vc]){
$spectacles_affiche_by_classification[$vc] = $structure_selected[$vc];
}
}
}
if(isset($spectacles_affiche_by_classification)){
$this->context['view']->spectacles_affiche_dans = true;
$this->context['view']->spectacles_affiche = $spectacles_affiche_by_classification;
}
}
private function getSpectaclesJTN(){
$spectacles = $this->em->getRepository(Multimedias::class);
$where_genre = ' ';
$where_zone = $this->regions->getZipCode($this->area);
$params_sql_soutien = array(
'params' => array(
'limit' => array(0,20),
'where' => $where_genre.$where_zone
),
'special' => array(
'prochains' => 180,
'random' => '',
'by_classification' => 103,
'get_schedule_ville' => $this->area
),
'dbg' => array('spectacle_soutien','Les spectacles avec un soutien à l\'affiche'),
);
$format_vignette['vignette'] = array('width'=>$_ENV['VIGN_SPECTACLE_WIDTH'],'height'=>$_ENV['VIGN_SPECTACLE_HEIGHT']);
$params_display = array('allauthors' => true);
$spectacles_soutien = $this->spectacles->getListSpectacles($params_sql_soutien, $format_vignette, 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 getAsides(){
$this->asides->load(['url_lists_alone,tn_cdn_sn' => array(
'exec' => ['color' => true,'color' => 'contacts'],
'rmv' => 'ALL',
'php' => [
'method' => 'tn_cdn_sn',
'url' => '/structures/actualites/key_structure',
'params' => array(
'activate' => $this->structure
// 'activate' => (!is_null($this->context['idtypestructure'])) ? $this->context['idtypestructure'] : 'ALL',
// 'key_action' => $this->context['view']->context['action'],
// 'key_area' => $this->context['view']->area
),
// 'structure' => array(
// 'theatre' => 'key_action',
// 'area' => 'key_area',
// 'structure_classic' => array(
// 'idtypestructure' => 'key_structure',
// 'd' => $this->context['view']->days
// )
// )
],
'title' => 'Rechercher par label'
)]);
if (isset($this->context['view']->idtypestructure)) {
if ($this->context['view']->idtypestructure == 'CDN') {
$this->asides->load('contact_acdn');
}
}
$this->asides->load(['common_carte' => array(
'url' => '/regions/actualites/area/get_id'
)]);
$this->asides->load('common_prochain_evenement');
$this->asides->load('common_facebook');
$this->asides->load('common_twitter');
// $this->asides->load('common_offre_annonce');
}
// {{{ getContactsByType()
/** Les contacts par type de structure avec bandeau
*
*/
public function getContactsByType($idtypestructure) {
// rechercher les scènes conventionnées
$params_sql_typestructure = array(
'where' => array(
array('contacts', 'idtypestructure', $idtypestructure),
array('contacts', 'country', 'FR'),
' AND contacts.idcontact NOT IN (SELECT idcontact FROM contact_classification WHERE idclassification=99) ',
),
'order' => array('contacts' => 'organisation'),
'direction' => 'ASC',
'idclassification' => array('NOT' => array(99)),
'limit' => array(0,500),
'dbg' => array('structures','Contacts avec un type précis'),
);
$structures = $this->em->getRepository(Contacts::class)->getListContacts($params_sql_typestructure);
// classe fichiers
$files = $this->em->getRepository(Files::class);
foreach($structures as $k=>$s) {
$ids_contact[] = $s['idcontact'];
// voir si la structure à une petite bannière
$structures[$k]['petit_bandeau'] = $files->getObjectFiles($s['idcontact'],'contacts',114);
}
return array(
'contacts' => $structures,
'nb_contacts' => count($structures),
'ids' => $ids_contact,
);
}
// }}}
}