<?php
namespace App\Controller;
use App\ClassTheatre\aside\asidesUrlPagination;
use App\ClassTheatre\asides;
use App\ClassTheatre\TheatreController;
use App\Service\Abonnements\Abonnements;
use App\Service\Functions;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\FormType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
use TheatreCore\Entity\Bigregions;
use TheatreCore\Entity\Classifications;
use TheatreCore\Entity\Contacts;
use TheatreCore\Entity\Typesstructures;
class ContactsController extends TheatreController
{
// {{{ _construct()
/** constructeur hérité
*
*/
public function __construct(EntityManagerInterface $em, TranslatorInterface $translator, TokenStorageInterface $tokenStorage, Abonnements $abonnements)
{
// load new aside
$this->asides = new asides();
$GLOBALS['rub_courante'] = 'contacts';
$this->em = $em;
$this->serviceAbonnements = $abonnements;
// hérite du constructeur parent
parent::__construct($translator, $tokenStorage);
}
/**
* @Route("/contacts/", name="contacts_view")
*/
public function action_view(Functions $functions, Request $request)
{
$this->view->action = $this->context['action'] = 'view';
$contacts = $this->em->getRepository(Contacts::class);
$regions = $this->em->getRepository(Bigregions::class);
// type de structure
$typesstructures = $this->em->getRepository(Typesstructures::class);
$selected_types = array('TN','CDN','SN','SC');
// alphabet
$alphabet_simple = $functions->getAlphaUpper();
// recherche par lettre soit on a le parametre,
// soit une lettre au hasard
if (isset($_GET['lettre']) && strlen($_GET['lettre']) == 1) {
$alpha = strtoupper($_GET['lettre']);
} else {
$alpha = null;
}
foreach($alphabet_simple as $lettre=>$upperlettre) {
$alphabet[$lettre]['nom'] = $upperlettre;
if ($upperlettre==$alpha) {
$alphabet[$lettre]['active'] = 'active';
}
}
$this->view->alphabet = $alphabet;
$typesstructure_list = $typesstructures->getTypeStructureList(true,true);
// liste simple
foreach($selected_types as $s) {
$liste_selected_types[$s] = $typesstructure_list[$s];
}
//setDebug(print_r($liste_selected_types,true));
$this->view->liste_selected_types = $liste_selected_types;
$this->context['formAsideSearch'] = $this->get('form.factory')->createNamedBuilder('', FormType::class);
// choix du type
foreach($typesstructure_list as $k=>$v) {
$typesstructure_list_select[$k] = $v['typestructure_pluriel'];
}
$this->context['formAsideSearch']->add('idtypestructure', ChoiceType::class, [
'label' => 'Type de structure',
'placeholder' => 'Choisissez dans la liste...',
'choices' => array_flip($typesstructure_list_select),
'required' => false,
'attr' => [
'id' => 'idtypestructure'
]
]);
// formulaire de saisie recherche contact
$this->context['formAsideSearch']->add('organisation', TextType::class, [
'label' => 'Nom de la structure',
'required' => false,
'attr' => [
'size' => '35'
]
]);
$this->context['formAsideSearch']->add('city', TextType::class, [
'label' => 'Ville',
'required' => false,
'attr' => [
'size' => '35'
]
]);
$this->context['formAsideSearch']->add('zip', TextType::class, [
'label' => 'Code postal',
'required' => false,
'attr' => [
'size' => '15'
]
]);
$this->context['formAsideSearch']->add('area', ChoiceType::class, [
'label' => 'Région',
'required' => false,
'choices' => $regions->getArea(),
'attr' => [
'class' => 'select_language',
'id' => 'area'
]
]);
$this->context['formAsideSearch']->add('search_contact', SubmitType::class, [
'label' => 'Lancer la recherche',
'attr' => [
'class'=>'boutform'
]
]);
$this->getCommonSearchView($request);
// les requetes classiques
$query_normal = 'SELECT DISTINCT(c.`idcontact`), c.`organisation`, c.`country`, c.`city`, c.`url_clean` FROM contacts c';
// compte
$query_count = 'SELECT COUNT(DISTINCT(c.`idcontact`)) as total FROM contacts c';
// pas les éditeurs
$query = ' LEFT JOIN texts t
ON c.`idcontact`=t.`idcontact_publisher`
WHERE t.`idcontact_publisher` IS NULL ';
$total_contacts = $contacts->queryOne($query_count.$query);
$this->view->nb_contacts = $total_contacts;
// si recherche alphabétique
if (!empty($alpha)) {
// the lettre
$this->view->alpha = strtoupper($alpha);
// recherche alpha
if (!empty($alpha)) {
$query .= ' AND c.`organisation` REGEXP \'^'.$alpha.'\' ';
}
$query .= ' ORDER BY c.`organisation`';
//setDebug($query_normal.$query);
$contacts->query($query_normal.$query);
while($contacts->fetch()) {
$contacts_infos = array(
'organisation' => $contacts->cutSentence($contacts->organisation,40),
'city' => $contacts->city,
'country' => $contacts->getNameCountry($contacts->country,$lng),
'url_clean' => $contacts->url_clean,
);
// on sépare FR et Inter
if ($contacts->country=='FR') {
$liste_contacts_alpha_fr[$contacts->idcontact] = $contacts_infos;
} else {
$liste_contacts_alpha_int[$contacts->idcontact] = $contacts_infos;
}
// tableau avec tous
$liste_contacts_alpha[$contacts->idcontact] = $contacts_infos;
}
$contacts->free();
//setDebug(print_r($liste_contacts_alpha,true));
// liste des contacts à la vue
if (!empty($liste_contacts_alpha)) {
if (!empty($liste_contacts_alpha_fr)) $this->view->liste_contacts_fr = $liste_contacts_alpha_fr;
if (!empty($liste_contacts_alpha_int)) $this->view->liste_contacts_int = $liste_contacts_alpha_int;
} else {
$this->view->no_contact_alpha = true;
}
$this->view->alpha_search = true;
}
// moteur de recherche contacts
if ((isset($this->context['formAsideSearch']) && $this->context['formAsideSearch']->isSubmitted()) || isset($_GET['page']) || !empty($_GET['area']) || !empty($_POST['area'])) {
$this->view->liste_contacts = array();
$sql_count = 'SELECT COUNT(DISTINCT(c.`idcontact`)) as total ';
$sql_normal = 'SELECT c.`idcontact`,c.`url_clean`,c.`city`,c.`organisation`,c.`idtypestructure`,cty.`'.$GLOBALS['lng'].'`,ts.`typestructure` ';
$sql = 'FROM contacts c
LEFT JOIN countries cty ON c.`country`=cty.`id`
INNER JOIN typesstructures ts ON ts.`idtypestructure`=c.`idtypestructure`
WHERE c.`type`=1 ';
//AND c.`idcontact` IN ('.join(',',$cont).') ORDER BY c.organisation';
//echo $sql_normal.$sql;
// recherche par région
$area = null;
if (!empty($_REQUEST['area']) && (is_numeric($_REQUEST['area']) || strlen($_REQUEST['area'])<3)) {
$area = $_REQUEST['area'];
}
$this->view->area = $area;
if (!empty($area)) {
if ($regions->my_is_int($area)) {
$sql_area = ($sqlZipCode = $regions->getZipCode($area, 'c')) ? ' AND'.$sqlZipCode : '';
$this->view->region_name = $regions->getRegionName($area);
} else {
$this->view->country_name = $contacts->getNameCountry($area);
$sql_area = ' AND c.`country`=\''.$contacts->escape($area).'\' ';
}
$sql .= $sql_area;
}
// recherche par nom de structure
$organisation = null;
if (!empty($_REQUEST['organisation'])) {
$organisation = filter_var($_REQUEST['organisation'], FILTER_SANITIZE_STRING);
}
// recherche par type de structure
$idtypestructure = null;
if (!empty($_REQUEST['idtypestructure']) && array_key_exists($_REQUEST['idtypestructure'], $typesstructure_list)) {
$idtypestructure = filter_var($_REQUEST['idtypestructure'], FILTER_SANITIZE_STRING);
$sql .= ' AND c.`idtypestructure` LIKE \''.$contacts->escape($idtypestructure).'%\' ';
foreach(array('typestructure','typestructure_pluriel') as $s) {
$typesstructure_list_simple[$s] = strtolower($typesstructure_list[$idtypestructure][$s]);
}
$typesstructure_list_simple['idtypestructure'] = $idtypestructure;
$this->view->typestructure = $typesstructure_list_simple;
if ($idtypestructure=='EC') {
$this->view->view_ec = true;
}
}
$this->view->idtypestructure = $idtypestructure;
// recherche
foreach(array('organisation','city','zip') as $f) {
$value = $this->context['formAsideSearch']->get($f)->getData();
if (empty($value) && isset($_GET[$f])) {
$value = strip_tags(trim(htmlspecialchars($_GET[$f])));
}
if (!empty($value)) {
$sql .= ' AND c.`'.$f.'` LIKE \'%'.$contacts->escape($value).'%\' ';
$this->view->$f = $value;
}
}
$sql .= ' ORDER BY c.organisation';
// nb resultat par page
$pagerOptions['perPage'] = 20;
// nombre d'enregistrement
$totalItems = $contacts->queryOne($sql_count.$sql);
//setDebug($sql_count.$sql);
if (!empty($totalItems) && $totalItems>0) {
// image du pager
$pagerOptions['totalItems'] = $totalItems;
// pagination
$pagerOptions['delta'] = 2;
$this->perPage = $pagerOptions['perPage'] = 30;
$this->view->pagination = $this->getPagination($totalItems);
// ajout des criteres de tri apres avoir fait le count
if (isset($tri)) {
$sql .= $tri;
}
//limite
$limit = $contacts->dbLimit($this->perPage, $this->getLimitStart());
$contacts->query($sql_normal.$sql.$limit);
//setDebug($sql_normal.$sql.$limit);
while($contacts->fetch()) {
$idcontact = $contacts->idcontact;
$liste_contacts[$idcontact] = array(
'organisation' => $contacts->organisation,
'subtitle' => 'nom_suite',
'country' => $contacts->fr,
'url_clean' => $contacts->url_clean,
'city' => $contacts->city,
'typestructure' => $contacts->typestructure,
'idtypestructure' => $contacts->idtypestructure,
);
if (in_array($contacts->idtypestructure, $selected_types)) {
$liste_contacts[$idcontact]['selected_type'] = true;
}
}
//passer les resultats au template
if (!empty($liste_contacts)) {
$this->view->liste_contacts = $liste_contacts;
}
$urlpagination = new asidesUrlPagination(
'/contacts/generate_params',
array(
'recherche' => true,
'areac' => $this->context['view']->area,
'city' => $this->context['formAsideSearch']->get('city')->getData(),
'organisation' => $organisation,
'structure' => $this->view->idtypestructure
),
$this->context
);
$this->view->pagination['url_custom'] = $urlpagination->url_pagination();
}
$this->view->resultat = true;
}
// titre de la page
$this->title_page = 'Les lieux de diffusion et les structures théâtrales (compagnie...)';
// situation
$this->view->locate = array(0 => 'Lieux de diffusion, compagnie et structures théâtrales');
$this->rub_courante = 'contacts';
// jajascript
$this->context['view']->carte_version = 'svg';
$this->context['view']->is_carte_svg = true;
$this->context['view']->js_more['raphael-min-js'] = 'raphaeljs/raphael-min.js';
$this->context['view']->js_more['raphael-svg-import'] = 'raphaeljs/raphael-svg-import.js';
//asides_body
$asides_body = new asides();
$asides_body->load('contact_rechercher');
$this->context['view']->aside_body = $asides_body->view($this->context['view']);
//asides_top
$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']);
$recherche_dans_region = array(
'' => array(
'name' => 'Une structure',
'url' => '/contacts/generate_params',
'key_2' => 'null'
),
'TN' => array(
'name' => 'Les théâtres nationaux',
'key_url' => 'TN'
),
'CDN' => array(
'name' => 'Les centres dramatiques',
'key_url' => 'CDN'
),
'SN' => array(
'name' => 'Les scènes nationales',
'key_url' => 'SN'
),
);
//on supprime les théâtres nationaux partout sauf dans les régins 1 et 8
if (isset($this->context['view']->area) && !in_array($this->context['view']->area, [1,8])){
unset($recherche_dans_region['TN']);
}
//On affiche la publicité google
$asides_publicite = new asides();
asides::setEntityManager($this->em);
asides::loadaside('Publicite')->addGoogle($asides_publicite, $this->serviceAbonnements);
$this->context['view']->asides_publicite = $asides_publicite->view($this->context['view']);
//asides
$asides = new asides();
$asides->load(['url_lists_alone,recherche_dans_region' => array(
'php' => [
'method' => 'asidesUrlLists',
'urls' => $recherche_dans_region,
'url' => '/contacts/structures/liste/generate_params',
'params' => array(
'activate' => (isset($idtypestructure)) ? $idtypestructure : 'null',
),
'structure' => array(
'structure_classic' => array(
'area' => (isset($this->context['view']->area)) ? $this->context['view']->area : null,
'idtypestructure' => 'key_url'
)
)
],
'title' => 'Rechercher'
)]);
$asides->load(['url_lists_alone,programme_pdf' => array(
'php' => [
'method' => 'asidesUrlLists',
'urls' => ['programmes' => array(
'name' => 'Tous les programmes'
)
],
'url' => '/contacts/archives/programmes/generate_params',
'params' => array(
'key_url' => (isset($idtypestructure)) ? $idtypestructure : 'ALL',
'key_area' => (isset($this->context['view']->area)) ? $this->context['view']->area : null,
),
'structure' => array(
'area' => 'key_area',
'structure_classic' => array(
'idtypestructure' => 'key_url'
)
)
],
'title' => 'Programme en PDF'
)]);
//Chargement de la pub par région
$params_pub = array();
if (!empty($this->context['view']->area)){
$params_pub = ['region' => $this->context['view']->area];
}
asides::setEntityManager($this->em);
asides::loadaside('Publicite')->addWithRegion($asides, $params_pub); //$this->area
$asides->load(['common_carte' => array(
'php' => array(
'method' => 'asidesUrlLists',
'url' => '/contacts/generate_params',
'params' => array(
'get_id' => 'get_id',
'key_type' => (isset($idtypestructure)) ? $idtypestructure : 'ALL',
),
'structure' => array(
'structure_classic' => array(
'area' => 'get_id',
'idtypestructure' => 'key_type',
)
)
)
)]);
asides::setEntityManager($this->em);
asides::loadaside('Publicite')->addWithNational($asides);
$asides->load('contact_ajouter_structure');
$asides->load(['common_participer' => array(
'php' => array(
'method' => 'asidesUrlLists_Ajoutez',
)
)]);
$this->context['view']->aside = $asides->view($this->context['view']);
return $this->view('contacts/view.html.twig');
}
/**
* @Route("/contacts/structures/partenaires", name="contacts_partenaires")
* @Route("/contacts/structures/partenaires/classification/{classification}", name="contacts_partenaires_classification")
*/
public function action_partenaires($classification = null)
{
$this->view->action = $this->context['view']->action = 'partenaires';
$params['classification'] = $classification;
$contacts = $this->em->getRepository(Contacts::class);
$classifications_contact = $this->em->getRepository(Classifications::class)->getClassificationsInGroup(10);
if (!empty($params['classification'])) {
foreach($classifications_contact as $k=>$v) {
if ($v['classification']==$params['classification']) {
$idclassification = $v['idclassification'];
break;
}
}
}
// TN par défaut
if (empty($idclassification)) {
$idclassification = 128;
}
$params_sql_typestructure = array(
'direction' => 'ASC',
'idclassification' => array($idclassification),
'limit' => array(0,300),
'dbg' => array('structures','Contacts avec une classification précise'),
);
$structures = $contacts->getListContacts($params_sql_typestructure,array(),array('get_profile_picture' => true));
$this->context['view']->typestructure = $this->context['tr']->trans($params['classification']);
$this->context['view']->structures = $structures;
// titre de la page
$this->view->title_page = $this->context['tr']->trans($params['classification']).' partenaires';
// situation
$this->view->locate = array(
'/contacts/' => 'Structures',
0 => $this->context['tr']->trans($params['classification']).' partenaires',
);
$rub_courante = 'contacts';
// style en plus
$this->context['view']->style_more = array(
'dossier',
'rubrique',
'pageregion'
);
// asides top
$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']);
$nav_partenaires = array(
array(
'name' => 'Théâtres nationaux',
'key_sub' => 'class_home_tn'
),
array(
'name' => 'Centres dramatiques',
'key_sub' => 'class_home_cdncdr'
),
array(
'name' => 'Scènes nationales',
'key_sub' => 'class_home_sn'
),
array(
'name' => 'Autres théâtres',
'key_sub' => 'class_home_autres'
),
array(
'name' => 'Belgique',
'key_sub' => 'class_home_belgique'
),
array(
'name' => 'Suisse',
'key_sub' => 'class_home_suisse'
),
array(
'name' => 'Festivals de théâtre',
'key_sub' => 'class_home_festival'
),
);
$nav_partenaires_infos = array(
array(
'name' => 'Théâtres nationaux',
'url' => '/contacts/structures/liste?idtypestructure=TN'
),
array(
'name' => 'Centres dramatiques',
'url' => '/contacts/structures/liste?idtypestructure=CDN'
),
array(
'name' => 'Scènes nationales',
'url' => '/contacts/structures/liste?idtypestructure=SN'
),
array(
'name' => 'Belgique',
'url' => '/regions/actualites/area/BE'
),
array(
'name' => 'Suisse',
'url' => '/regions/actualites/area/CH'
),
);
$asides = new asides();
$asides->load(['url_lists_alone' => array(
'title' => 'Les partenaires',
'php' => array(
'method' => 'asidesUrlLists',
'urls' => $nav_partenaires,
'url' => '/contacts/structures/partenaires/classification/key_sub',
'params' => array(
'activate' => $this->context['view']->typestructure
)
)
)]);
$asides->load(['url_lists_alone, nav_partenaires_infos' => array(
'php' => array(
'method' => 'asidesUrlLists',
'urls' => $nav_partenaires_infos,
'params' => array(
'activate' => ''
)
),
'title' => 'Toutes les infos'
)]);
$this->context['view']->aside = $asides->view($this->context['view']);
return $this->view('contacts/partenaires.html.twig');
}
/**
* @Route("/contacts/structures/liste", name="contacts_liste")
*/
public function action_liste()
{
$this->view->action = $this->context['view']->action = 'liste';
$contacts = $this->em->getRepository(Contacts::class);
// type de structure
$typesstructures = $this->em->getRepository(Typesstructures::class);
$typesstructure_list = $typesstructures->getTypeStructureList(true,true);
//setDebug(print_r($typesstructure_list,true));
// type de structure recherchée
if (!empty($_REQUEST['idtypestructure']) && array_key_exists($_REQUEST['idtypestructure'], $typesstructure_list)) {
$idtypestructure = filter_var($_REQUEST['idtypestructure'], FILTER_SANITIZE_STRING);
} else {
$idtypestructure = 'SN';
}
if ($idtypestructure=='SN') {
$this->view->view_sn = true;
}
foreach(array('typestructure','typestructure_pluriel') as $s) {
if (!empty($typesstructure_list[$idtypestructure])){
$typesstructure_list_simple[$s] = strtolower($typesstructure_list[$idtypestructure][$s]);
}
}
$typesstructure_list_simple['idtypestructure'] = $idtypestructure;
$this->view->typestructure = $typesstructure_list_simple;
// choix du type
$typesstructure_list_select[0] = 'Choisissez dans la liste...';
foreach($typesstructure_list as $k=>$v) {
$typesstructure_list_select[$k] = $v['typestructure_pluriel'];
}
//$form->addElement('select', 'idtypestructure', 'Type de structure', $typesstructure_list_select, array('id' => 'idtypestructure'));
$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,300),
'dbg' => array('structures','Contacts avec un type précis'),
);
// pour le HETS
if ($idtypestructure=='EC') {
unset($params_sql_typestructure['where'][1]);
}
$structures = $contacts->getListContacts($params_sql_typestructure,array(),array('get_profile_picture' => true));
$this->view->nb_structures = count($structures);
$this->view->structures = $structures;
// titre de la page
$this->title_page = $typesstructure_list[$idtypestructure]['typestructure_pluriel'];
$this->rub_courante = 'contacts';
// ajouter masonery
$this->context['view']->js_more[] = 'jquery.masonry.min.js';
$this->context['view']->use_addthis = true;
$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']);
$asides = new asides();
$asides->load(['common_carte' => array(
'url' => '/contacts/?area=get_id'
)]);
if ($idtypestructure == 'CDN'){
$asides->load('contact_acdn');
}
$asides->load(['url_lists_alone,tn_cdn_sn' => array(
'php' => [
'method' => 'tn_cdn_sn',
'url' => '/key_controller/structures/liste?idtypestructure=key_structure',
'params' => array(
'activate' => $this->context['view']->typestructure['idtypestructure']
)
],
'title' => 'Voir aussi'
)]);
$this->context['view']->aside = $asides->view($this->context['view']);
// situation
$this->view->locate = array(
'/contacts/' => 'Structures',
0 => $typesstructure_list[$idtypestructure]['typestructure_pluriel'],
);
return $this->view('contacts/liste.html.twig');
}
}