src/Controller/EditionsController.php line 53

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\ClassTheatre\asides;
  4. use App\ClassTheatre\TheatreController;
  5. use App\Service\Functions;
  6. use Doctrine\ORM\EntityManagerInterface;
  7. use Symfony\Component\Form\Extension\Core\Type\FormType;
  8. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  9. use Symfony\Component\Form\Extension\Core\Type\TextType;
  10. use Symfony\Component\HttpFoundation\Request;
  11. use Symfony\Component\Routing\Annotation\Route;
  12. use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
  13. use Symfony\Contracts\Translation\TranslatorInterface;
  14. use TheatreCore\Entity\Contacts;
  15. use TheatreCore\Entity\Spectacles;
  16. class EditionsController extends TheatreController
  17. {
  18.     // {{{ _construct()
  19.     /** constructeur hérité
  20.      *
  21.      */
  22.     public function __construct(EntityManagerInterface $emTranslatorInterface $translatorTokenStorageInterface $tokenStorageFunctions $func)
  23.     {
  24.         // surbrillance du menu principal (thnet)
  25.         $GLOBALS['rub_courante'] = 'editions';
  26.         parent::__construct($translator$tokenStorage);
  27.         $this->em $em;
  28.         $this->asides = new asides();
  29.         $this->func $func;
  30.         $this->spectacles $em->getRepository(Spectacles::class);
  31.         $this->contacts $em->getRepository(Contacts::class);
  32.         $this->perPage 1000;
  33.     }
  34.     /**
  35.      *
  36.      * @Route("/editions", name="editions")
  37.      *
  38.      */
  39.     public function action_view(Request $request)
  40.     {
  41.         // alphabet
  42.         $alphabet_simple $this->func->getAlphaUpper();
  43.         // recherche par lettre soit on a le parametre,
  44.         // soit une lettre au hasard
  45.         if(isset($_GET['lettre']) && strlen($_GET['lettre'])==1) {
  46.             $alpha strtoupper($_GET['lettre']);
  47.         } else {
  48.             $aff array_rand($alphabet_simple);
  49.             if(isset($alphabet_simple[$aff])) {
  50.                 $alpha $alphabet_simple[$aff];
  51.             } else {
  52.                 $alpha 'a';
  53.             }
  54.         }
  55.         // the lettre
  56.         $this->view->alpha strtoupper($alpha);
  57.         foreach($alphabet_simple as $lettre=>$upperlettre) {
  58.             $alphabet[$lettre]['nom'] = $upperlettre;
  59.             if($upperlettre==$alpha) {
  60.                 $alphabet[$lettre]['active'] = 'active';
  61.             }
  62.         }
  63.         $this->view->alphabet $alphabet;
  64.         // liste des éditeurs
  65.         $query_normal 'SELECT DISTINCT(c.idcontact), c.organisation, c.country, c.city, c.url_clean FROM contacts c';
  66.         $query ' WHERE 1
  67.             AND c.idcontact IN
  68.                 (SELECT DISTINCT(texts.idcontact_publisher) FROM texts WHERE texts.publish=1)';
  69.         $total_editeurs $this->contacts->queryAll($query_normal.$query);
  70.         $this->view->nb_editeurs count($total_editeurs);
  71.         // franco
  72.         $nb_editeurs_francophones 0;
  73.         foreach($total_editeurs as $k=>$v) {
  74.             if($v['country']=='FR') {
  75.                 $nb_editeurs_francophones++;
  76.             }
  77.         }
  78.         $this->view->nb_editeurs_francophones $nb_editeurs_francophones;
  79.         if(!empty($alpha)) {
  80.             $query .= ' AND c.organisation REGEXP \'^'.$alpha.'\' ';
  81.         }
  82.         $query .= ' ORDER BY c.organisation';
  83.         $this->contacts->query($query_normal.$query);
  84.         while($this->contacts->fetch()) {
  85.             // nb de texte
  86.             $nb_texts $this->contacts->countObjects('text','idcontact_publisher',$this->contacts->idcontact);
  87.             $editeur_infos = array(
  88.                 'organisation' => $this->contacts->cutSentence($this->contacts->organisation,40),
  89.                 'city' => $this->contacts->city,
  90.                 'country' => $this->contacts->getNameCountry($this->contacts->country,$this->lng),
  91.                 'url_clean' => $this->contacts->url_clean,
  92.                 'nb_texts' => $nb_texts,
  93.             );
  94.             if($nb_texts>1) {
  95.                 $editeur_infos['nb_texts_pluriel'] = 's';
  96.             }
  97.             // on sépare FR et Inter
  98.             if($this->contacts->country=='FR') {
  99.                 $liste_editeurs_alpha_fr[$this->contacts->idcontact] = $editeur_infos;
  100.             } else {
  101.                 $liste_editeurs_alpha_int[$this->contacts->idcontact] = $editeur_infos;
  102.             }
  103.             // tableau avec tous
  104.             $liste_editeurs_alpha[$this->contacts->idcontact] = $editeur_infos;
  105.         }
  106.         $this->contacts->free();
  107.         // liste des éditeurs à la vue
  108.         if(!empty($liste_editeurs_alpha)) {
  109.             if (!empty($liste_editeurs_alpha_fr)) $this->view->liste_editeurs_fr $liste_editeurs_alpha_fr;
  110.             if (!empty($liste_editeurs_alpha_int)) $this->view->liste_editeurs_int $liste_editeurs_alpha_int;
  111.         } else {
  112.             $this->view->no_editeur_alpha true;
  113.         }
  114.         // ==> moteur de recherche edition
  115.         // formulaire de saisie recherche par titre
  116.         $this->context['formAsideSearch'] = $this->get('form.factory')->createNamedBuilder(''FormType::class);
  117.         $this->context['formAsideSearch']->add('organisation'TextType::class, [
  118.             'label' => 'Mots du titre',
  119.             'attr' => [
  120.                 'size' => '35',
  121.                 'placeholder' =>'Rechercher un éditeur'
  122.             ]
  123.         ]);
  124.         $this->context['formAsideSearch']->add('search_editeur'SubmitType::class, [
  125.             'label' => 'OK',
  126.             'attr' => [
  127.                 'class'=>'boutform'
  128.             ]
  129.         ]);
  130.         if(isset($_GET['aide-recherche'])) {
  131.             $this->view->recherche_texts true;
  132.             $this->view->aide_recherche true;
  133.             $this->view->resultat true;
  134.         }
  135.         $type_recherche false;
  136.         $this->getCommonSearchView($request);
  137.         if($this->context['formAsideSearch']->isSubmitted() || isset($_GET['page'])) {
  138.             $this->view->liste_editeurs = array();
  139.             if (isset($_REQUEST['search_editeur']) || isset($_REQUEST['search'])) {
  140.                 // on recherche un éditeur
  141.                 if(isset($_REQUEST['search_editeur'])) {
  142.                     // ids éditeurs
  143.                     foreach($total_editeurs as $k=>$v) {
  144.                         $edit[] = $v['idcontact'];
  145.                     }
  146.                     $organisation $this->context['formAsideSearch']->get('organisation')->getData();
  147.                     if(empty($organisation) && isset($_GET['organisation'])) {
  148.                         $organisation $_GET['organisation'];
  149.                     }
  150.                     $sql_count 'SELECT COUNT(DISTINCT(c.idcontact)) as total ';
  151.                     $sql_normal 'SELECT c.idcontact,c.url_clean,c.organisation,cty.'.$GLOBALS['lng'].', c.country ';
  152.                     $sql 'FROM contacts c
  153.                     LEFT JOIN countries cty ON c.country=cty.id
  154.                     WHERE c.organisation LIKE "%'.$this->contacts->escape($organisation).'%"
  155.                     AND c.type=1
  156.                     AND c.idcontact IN ('.join(',',$edit).') ORDER BY c.organisation';
  157.                     //echo $sql_normal.$sql;
  158.                     $type_recherche 'recherche_editeurs';
  159.                     $this->view->organisation $organisation;
  160.                     $this->view->autre_editeur 'autre';
  161.                 }
  162.                 // nombre d'enregistrement
  163.                 $totalItems $this->contacts->queryOne($sql_count.$sql);
  164.                 if(!empty($totalItems) && $totalItems>0) {
  165.                     $pagerOptions['totalItems'] = $totalItems;
  166.                     // pagination
  167.                     $pagerOptions['delta'] = 2;
  168.                     $pagerOptions['perPage'] = 30;
  169.                     $paged_data $this->getPagination($totalItems,$this->perPage,$pagerOptions);
  170.                     // ajout des criteres de tri apres avoir fait le count
  171.                     if(isset($tri)) {
  172.                         $sql .= $tri;
  173.                     }
  174.                     //limite
  175.                     $limit ' LIMIT '.$this->getLimitStart().','.$this->perPage;
  176.                     // executer la requete et mettre en forme chaque reponse
  177.                     $this->contacts->query($sql_normal.$sql.$limit);
  178.                     $liste_editeurs_fr = [];
  179.                     $liste_editeurs_int = [];
  180.                     while($this->contacts->fetch()) {
  181.                         $idcontact $this->contacts->idcontact;
  182.                         $nb_texts $this->contacts->countObjects('text','idcontact_publisher',$idcontact);
  183.                         $editeur_infos = array(
  184.                             'organisation' => $this->contacts->organisation,
  185.                             'country' => $this->contacts->{$this->lng},
  186.                             'url_clean' => $this->contacts->url_clean,
  187.                             'nb_texts' => $nb_texts,
  188.                         );
  189.                         if($nb_texts>1) {
  190.                             $editeur_infos['nb_texts_pluriel'] = 's';
  191.                         }
  192.                         // on sépare FR et Inter
  193.                         if($this->contacts->country=='FR') {
  194.                             $liste_editeurs_fr[$idcontact] = $editeur_infos;
  195.                         } else {
  196.                             $liste_editeurs_int[$idcontact] = $editeur_infos;
  197.                         }
  198.                         // tableau avec tous
  199.                         $liste_editeurs[$idcontact] = $editeur_infos;
  200.                     }
  201.                     //passer les resultats au template
  202.                     if(!empty($liste_editeurs)) {
  203. //                        $this->view->liste_editeurs = $liste_editeurs;
  204.                         $this->view->liste_editeurs_fr $liste_editeurs_fr;
  205.                         $this->view->liste_editeurs_int $liste_editeurs_int;
  206.                         $this->view->alpha false;
  207.                     }
  208.                     // liens du pager
  209. //                    $paged_data['links'] = str_replace('editions/view/index.php?controller=editions&amp;action=view&amp;', 'editeurs?', $paged_data['links']);
  210.                 }
  211.                 $this->view->$type_recherche $type_recherche;
  212.                 $this->view->resultat true;
  213.             }
  214.         }
  215.         // titre de la page
  216.         $this->title_page 'Les maisons d\'édition de théâtre';
  217.         // situation
  218.         $this->locate = array(=> 'Maisons d\'&eacute;dition de théâtre');
  219.         $this->rub_courante 'editions';
  220.         $this->asides->load(['recherche_editeur.inc' => array(
  221.             'exec' => ['htmlstart' => true'color'=>'context'],
  222.             'action' => '/editions'
  223.         )]);
  224.         $this->asides->load(['recherche_alphabetique' => array(
  225.             'exec' => ['htmlend' => true'color' => 'alternative'],
  226.             'action' => '/editions/'
  227.         )]);
  228.         $this->asides->load('bio_editeur');
  229.         $this->context['view']->aside $this->asides->view();
  230.         return $this->view('editions/view.html.twig', [
  231.             'controller_name' => 'EditionsController',
  232.         ]);
  233.     }
  234.     private function getTextsInfoR($sql,$texts) {
  235.         $liste_texts = array();
  236.         $texts->query($sql);
  237.         $format_flou $format = array('width'=>getenv('VIGN_TEXT_WIDTH'),'height'=>getenv('VIGN_TEXT_HEIGHT'),'direction'=>'thumb');
  238.         $format_flou['blur'] = true;
  239.         while($texts->fetch()) {
  240.             $idtext $texts->idtext;
  241.             $liste_texts[$idtext] = $texts->getInfosTextRow();
  242.             $liste_texts[$idtext]['publisher_first'] = true;
  243.             $liste_texts[$idtext]['stylemore'] = array('imagep' => 'width:60px;''desctxt' => 'width:195px;');
  244.             if(count($liste_texts[$idtext]['allauthors'])>5) {
  245.                 $liste_texts[$idtext]['collectif'] = true;
  246.             }
  247.             $liste_texts[$idtext]['vignette'] = $texts->getVignetteText($idtext,$format);
  248.             $liste_texts[$idtext]['vignette_flou'] = $texts->getVignetteText($idtext,$format_flou);
  249.             $liste_texts[$idtext]['publisher']['country'] = $texts->getNameCountry($texts->publisher_country,$GLOBALS['lng']);
  250.         }
  251.         $texts->free();
  252.         return $liste_texts;
  253.     }
  254. }