vendor/theatre/core/src/Repository/SchedulesRepository.php line 771

Open in your IDE?
  1. <?php
  2. namespace TheatreCore\Repository;
  3. use App\Service\Calendar;
  4. use TheatreCore\Entity\Bigregions;
  5. use TheatreCore\Entity\Contacts;
  6. use TheatreCore\Entity\Schedules;
  7. use TheatreCore\Traits\TheatreTrait;
  8. use TheatreCore\Entity\Spectacles;
  9. use DateTime;
  10. use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
  11. use Doctrine\Persistence\ManagerRegistry;
  12. use Doctrine\ORM\EntityManagerInterface;
  13. use Doctrine\ORM\Mapping;
  14. /**
  15.  * SchedulesRepository
  16.  *
  17.  * This class was generated by the Doctrine ORM. Add your own custom
  18.  * repository methods below.
  19.  */
  20. class SchedulesRepository extends ServiceEntityRepository
  21. {
  22.     use TheatreTrait {
  23.         getRelationsArray as protected getRelationsArrayTrait;
  24.         getLinkedObject as protected getLinkedObjectTrait;
  25.     }
  26.     private $em;
  27.     public $__table;
  28.     public $__table_object;
  29.     public $__idtable;
  30.     public function __construct(ManagerRegistry $registry)
  31.     {
  32.         parent::__construct($registrySchedules::class);
  33.         $this->__table $this->getClassMetadata()->getTableName();
  34.         $this->__table_object $this->getClassMetadata()->name;
  35.         $this->__idtable $this->getClassMetadata()->getSingleIdentifierFieldName();
  36.     }
  37.     //  {{{ getInfosSchedules()
  38.     /** Informations sur une date
  39.      *
  40.      * @access public
  41.      * @return array  les infos sous forme de tableau
  42.      * @param  int      $idschedule numero de la fiche date
  43.      */
  44.     public function getInfosSchedules($idschedule=null,$params_data=array(),$params_display=array())
  45.     {
  46.         $conn $this->getEntityManager();
  47.         $infos = array();
  48.         ////////////// infos de la table
  49.         if(!isset($this->idschedule) || empty($this->idschedule)) {
  50.             if(!empty($idschedule)) {
  51.                 $datas $this->get($idschedule);
  52.                 dump($this->get($idschedule));
  53.                 exit;
  54.                 if(!$this->get($idschedule)) {
  55.                     return array();
  56.                 } else {
  57.                     $infos $this->objToArray();
  58.                 }
  59.             }
  60.         } else {
  61.             $infos $this->datas[$this->rows-1];
  62.             $idschedule $infos['idschedule'];
  63.         }
  64.         // retourne aussi les infos sur le spectacle lié
  65.         $infos['spectacles'] = array(
  66.             'title' => $conn->getRepository(Spectacles::class)->getObjectTitle($this->idspectacle),
  67.             'idspectacle' => $this->idspectacle,
  68.         );
  69.         return $infos;
  70.     }
  71.     // }}}
  72.     //  {{{ getItemsList()
  73.     /** Liste des items pour les champs relationnels
  74.      *
  75.      * Retourne un tableau associatif contenant la liste des items
  76.      * d'une relation. Exemple : getItemsList(4,'text_author'); retourne les noms
  77.      * et prénom des auteurs du texte numéro 4
  78.      *
  79.      * @access  public
  80.      * @return  array
  81.      * @param   string $type        Ce qu'on recherche
  82.      * @param   string $idtext      L'id de l'objet
  83.      */
  84.     public function getItemsList($id,$type)
  85.     {
  86.         // on peux avoir passé juste l'idcontact ou idcontact+idspectacle
  87.         if($this->my_is_int($id)) {
  88.             $idcontact $id;
  89.         } else {
  90.             $ids unserialize($id);
  91.             $idcontact $ids['idcontact'];
  92.             $idspectacle $ids['idspectacle'];
  93.         }
  94. //        if(!in_array($type,$this->array_types)) {
  95.         if(!$this->getRelationsArray($type)) {
  96.             return 'Aucune fonction de recherche pour le type <strong>'.$type.'</strong> dans la méthode !';
  97.         }
  98.         // requête commune
  99.         $sql 'SELECT c.idcontact, sc.idcontact_festival, c.lastname, c.firstname, c.organisation as view_name 
  100.                 FROM schedules sc
  101.                 JOIN contacts c ON sc.'.$type.'=c.idcontact
  102.                 WHERE sc.idcontact='.$idcontact;
  103.         // spectacle
  104.         if(!empty($idspectacle)) {
  105.             $sql .= ' AND sc.idspectacle='.$idspectacle;
  106.         }
  107.         $sql .= ' GROUP BY c.idcontact';
  108.         $datas $this->queryAll($sql,array(),null,true);
  109.         return $datas;
  110.     }
  111.     // }}}
  112.     //  {{{ getDatesHours()
  113.     /** Dates et heures du spectacle
  114.      *
  115.      * @access  public
  116.      * @return  array
  117.      * @param   int     $idspectacle identifiant du spectacle
  118.      * @param   int     $idcontact identifiant du contact
  119.      */
  120.     public function getDatesHours($idspectacle,$idcontact,$type=null,$version='old') {
  121.         if($version=='old') {
  122.             return $this->getDatesHoursOld($idspectacle,$idcontact,$type);
  123.         } else {
  124.             return $this->getDatesHoursNew($idspectacle,$idcontact,$type);
  125.         }
  126.     }
  127.     // }}}
  128.     //  {{{ getDatesHoursOld()
  129.     /** Dates et heures du spectacles
  130.      *
  131.      * @access  public
  132.      * @return  array
  133.      * @param   int     $idspectacle identifiant du spectacle
  134.      * @param   int     $idcontact identifiant du contact
  135.      */
  136.     public function getDatesHoursOld($idspectacle,$idcontact,$type=null)
  137.     {
  138.         $query 'SELECT DISTINCT(date), note, is_cancelled, url_spectacle, url_booking, idextranetuser, publish, valid
  139.                   FROM schedules 
  140.                   WHERE idspectacle='.$idspectacle.'
  141.                   AND idcontact='.$idcontact.' ';
  142.         // pour les dates futurs, commencer au début du mois
  143.         if(!empty($type) && $type!='tous') {
  144.             if ($type == 'demain') {
  145.                 $expr '>=';
  146.                 $date_search date('Y-m-01');
  147.             } else {
  148.                 $expr '<=';
  149.                 $date_search date('Y-m-d');
  150.             }
  151.             $query .= ' AND date'.$expr.'\''.$date_search.'\' ';
  152.         }
  153.         // classement
  154.         $query .= ' ORDER BY date';
  155.         $res $this->query($query);
  156.         $nbresult $this->numRows(); //$res->numRows();
  157.         if($nbresult>1) {
  158.             $dateshours['periode'] = true;
  159.         }
  160.         $i 0;
  161.         foreach($res AS $row) { //$res->numRows()
  162.             // année mois
  163.             $y $this->getFormeDate($row['date'],"%y",true);
  164.             $m $this->getFormeDate($row['date'],"%m",true);
  165.             // format string ou classique
  166.             $date_str $this->getFormeDate($row['date'],"%a %d/%m/%y",true);
  167.             $date_orig $this->getFormeDate($row['date'],$GLOBALS['format_date'][$GLOBALS['lng']]);
  168.             $dateshours[$date_orig]['idextranetuser'] = $row['idextranetuser'];
  169.             // bidouille pour avoir à valider des heures en plus
  170.             if(!isset($dateshours[$date_orig]['valid'])) {
  171.                 $dateshours[$date_orig]['valid'] = $row['valid'];
  172.             } else {
  173.                 if($row['valid']==0) {
  174.                     $dateshours[$date_orig]['valid'] = $row['valid'];
  175.                 }
  176.             }
  177.             $dateshours[$date_orig]['publish'] = $row['publish'];
  178.             // une période
  179.             if($nbresult>1) {
  180.                 $dateshours[$date_orig]['hours'] = $this->getHours($row['date'],$idspectacle,$idcontact);
  181.                 if($type=='demain' && empty($date_debut_ok)) {
  182.                     if($row['date']>=date('Y-m-d')) {
  183.                         $dateshours[$date_orig]['datedebut'] = $date_str;
  184.                         $date_debut_ok true;
  185.                     }
  186.                 } else {
  187.                     if($i==0) { // première date = date de début
  188.                         $dateshours[$date_orig]['datedebut'] = $date_str;
  189.                     }
  190.                 }
  191.                 if($i==$nbresult-1) {
  192.                     $dateshours[$date_orig]['datefin'] = $date_str;
  193.                 }
  194.             } else { // inde date unique
  195.                 $dateshours['date'] = $date_orig;
  196.                 $dateshours['hours'] = $this->getHours($row['date'],$idspectacle,$idcontact);
  197.             }
  198.             if((empty($dateshours['is_cancelled']) || !$dateshours['is_cancelled']) && $row['is_cancelled']){
  199.                 $dateshours['is_cancelled'] = (int)$row['is_cancelled'];
  200.             }
  201.             $hour_string = array();
  202.             if(!empty($dateshours[$date_orig]['hours'])) {
  203.                 foreach($dateshours[$date_orig]['hours'] as $k=>$v) {
  204.                     if(!empty($v['hour'])) {
  205.                         $hour_string[] = $v['hour'];
  206.                     }
  207.                 }
  208.             }
  209.             // plusieurs heures ou une seule
  210.             if(!empty($hour_string)) {
  211.                 $hour_string join(' / '$hour_string);
  212.             } else {
  213.                 $hour_string null;
  214.             }
  215.             $dateshours['event'][$row['date']] = array(
  216.                 'date' => $row['date'],
  217.                 'hour' => $hour_string,
  218.                 'is_cancelled' => $row['is_cancelled'],
  219.                 'valid' => $row['valid'],
  220.                 'publish' => $row['publish'],
  221.                 'idextranetuser' => $row['idextranetuser'],
  222.             );
  223.             $dateshours['months'][$y.$m] = array('y' => $y'm' => $m);
  224.             if(!empty($row['note'])) {
  225.                 $dateshours['event'][$row['date']]['note'] = $row['note'];
  226.             }
  227.             if(!empty($row['url_spectacle'])) {
  228.                 $dateshours['event'][$row['date']]['url_spectacle'] = $row['url_spectacle'];
  229.             }
  230.             if(!empty($row['url_booking'])) {
  231.                 $dateshours['event'][$row['date']]['url_booking'] = $row['url_booking'];
  232.             }
  233.             $i++;
  234.         }
  235.         $this->free(); //$res->free()
  236.         // classement months
  237.         ksort($dateshours['months']);
  238.         ksort($dateshours['event']);
  239.         /*
  240.         print_r($dateshours);
  241.         exit;
  242.         */
  243.         return $dateshours;
  244.     }
  245.     // }}}
  246.     //  {{{ getDatesHoursNew()
  247.     /** Dates et heures du spectacle
  248.      *
  249.      * @access  public
  250.      * @return  array
  251.      * @param   int     $idspectacle identifiant du spectacle
  252.      * @param   int     $idcontact identifiant du contact
  253.      */
  254.     public function getDatesHoursNew($idspectacle,$idcontact,$type=null)
  255.     {
  256.         $query 'SELECT DISTINCT(date), note, url_spectacle, url_booking, idextranetuser, publish, valid, is_cancelled
  257.                   FROM schedules 
  258.                   WHERE idspectacle='.$idspectacle.'
  259.                   AND idcontact='.$idcontact.' ';
  260.         // pour les dates futurs, commencer au début du mois
  261.         if(!empty($type) && $type!='tous') {
  262.             if ($type == 'demain') {
  263.                 $expr '>=';
  264.                 $date_search date('Y-m-01');
  265.             } else {
  266.                 $expr '<=';
  267.                 $date_search date('Y-m-d');
  268.             }
  269.             $query .= ' AND date'.$expr.'\''.$date_search.'\' ';
  270.         }
  271.         // classement
  272.         $query .= ' ORDER BY date';
  273.         $res $this->query($query);
  274.         // combien de jours de pause pour définir une période ?
  275.         $nbperiode 15;
  276.         $periode 0// pour l'incrémentation des périodes
  277.         // grouper par période
  278.         foreach($res AS $row) {
  279.             // détection du changement de période
  280.             if(!empty($current_date)) {
  281.                 // date courante dans la boucle
  282.                 $date1 = new DateTime($current_date);
  283.                 $date2 = new DateTime($row['date']);
  284.                 $interval $date1->diff($date2);
  285.                 $diff $interval->format('%a');
  286.                 if($diff>$nbperiode) {
  287.                     $periode++;
  288.                 }
  289.             }
  290.             // format string ou classique
  291.             $date_str $this->getFormeDate($row['date'],"%a %d/%m/%y",true);
  292.             $date_orig $this->getFormeDate($row['date'],$GLOBALS['format_date'][$GLOBALS['lng']]);
  293.             $dateshours[$periode][$date_orig] = array(
  294.                 'idextranetuser' => $row['idextranetuser'],
  295.                 'valid' => $row['valid'],
  296.                 'publish' => $row['publish'],
  297.                 'date_str' => $date_str,
  298.                 'date_orig' => $date_orig,
  299.                 'is_cancelled' => $row['is_cancelled'],
  300.             );
  301.             // pour les horaires
  302.             $dateshours[$periode][$date_orig]['hours'] = $this->getHours($row['date'],$idspectacle,$idcontact);
  303.             // les passer en string
  304.             $hour_string = array();
  305.             $hours_array = array();
  306.             if(!empty($dateshours[$periode][$date_orig]['hours'])) {
  307.                 // pour les horaires en ligne (rassemblement de toutes les dates de la journée en une seule ligne)
  308.                 foreach($dateshours[$periode][$date_orig]['hours'] as $k=>$v) {
  309.                     if(!empty($v['hour'])) {
  310.                         $hour_string[] = $v['hour'];
  311.                     }
  312.                 }
  313.                 $hours_value = array();
  314.                 // pour les horaires en groupes (rassemblement de toutes les informations en tableau pour chaque date)
  315.                 foreach($dateshours[$periode][$date_orig]['hours'] as $k=>$v) {
  316.                     $key key($v);
  317.                     $hours_value[$key] = $v[$key];
  318.                     if(array_key_exists('url_booking',$v)) {
  319.                         $hours_array[] = $hours_value;
  320.                         $hours_value = array();
  321.                     }
  322.                 }
  323.             }
  324.             // plusieurs heures ou une seule
  325.             if(!empty($hour_string)) {
  326.                 $hour_string join(' / '$hour_string);
  327.             } else {
  328.                 $hour_string null;
  329.             }
  330.             // année et mois
  331.             $y $this->getFormeDate($row['date'],"%y",true);
  332.             $m $this->getFormeDate($row['date'],"%m",true);
  333.             $dateshours[$periode]['months'][$y.$m] = array(
  334.                 'y' => $y,
  335.                 'm' => $m
  336.             );
  337.             // les evenements pour Calendar
  338.             $dateshours[$periode]['event'][$row['date']] = array(
  339.                 'date' => $row['date'],
  340.                 'hour' => $hour_string//les heures de toute la journée en une seule "ligne"
  341.                 'hours' => $hours_array//Un tableau de toutes les heures qui les rassembles par "groupe"
  342.                 'valid' => $row['valid'],
  343.                 'publish' => $row['publish'],
  344.                 'idextranetuser' => $row['idextranetuser'],
  345.                 'is_cancelled' => $row['is_cancelled'],
  346.             );
  347.             if(!empty($row['note'])) {
  348.                 $dateshours[$periode]['event'][$row['date']]['note'] = $row['note'];
  349.             }
  350.             if(!empty($row['url_spectacle'])) {
  351.                 $dateshours[$periode]['event'][$row['date']]['url_spectacle'] = $row['url_spectacle'];
  352.             }
  353.             if(!empty($row['url_booking'])) {
  354.                 $dateshours[$periode]['event'][$row['date']]['url_booking'] = $row['url_booking'];
  355.             }
  356.             if(isset($row['is_cancelled'])) {
  357.                 $dateshours[$periode]['event'][$row['date']]['is_cancelled'] = $row['is_cancelled'];
  358.             }
  359.             $current_date $row['date'];
  360.         }
  361.         $this->free(); //$res->free();
  362.         foreach($dateshours as $periode=>$infos) {
  363.             // classement months et event
  364.             ksort($dateshours[$periode]['months']);
  365.             ksort($dateshours[$periode]['event']);
  366.             // est-ce une période ou une seule date ?
  367.             if(count($infos['event'])>1) {
  368.                 $dateshours[$periode]['periode'] = 1;
  369.                 // date de début de période
  370.                 if($type=='demain') {
  371.                     // parcourir les dates pour marquer la date qui fait le début de la période
  372.                     foreach($infos['event'] as $k=>$v) {
  373.                         if($v['date']>=date('Y-m-d')) {
  374.                             $date_orig $this->getFormeDate($v['date'],$GLOBALS['format_date'][$GLOBALS['lng']]);
  375.                             break;
  376.                         }
  377.                     }
  378.                 } else {
  379.                     foreach($infos['event'] as $k=>$v) {
  380.                         $date_orig $this->getFormeDate($v['date'],$GLOBALS['format_date'][$GLOBALS['lng']]);
  381.                         break;
  382.                     }
  383.                 }
  384.                 // la date début marquée
  385.                 $dateshours[$periode][$date_orig]['datedebut'] = $dateshours[$periode][$date_orig]['date_str'];
  386.                 // date de fin = dernière date
  387.                 $i 1;
  388.                 foreach($infos['event'] as $k=>$v) {
  389.                     if(!isset($dateshours[$periode]['warning']) && $v['is_cancelled']){
  390.                         $dateshours[$periode]['warning'] = true;
  391.                     }
  392.                     if($i==count($infos['event'])) {
  393.                         $date_orig $this->getFormeDate($v['date'],$GLOBALS['format_date'][$GLOBALS['lng']]);
  394.                         $dateshours[$periode][$date_orig]['datefin'] = $dateshours[$periode][$date_orig]['date_str'];
  395.                     }
  396.                     $i++;
  397.                 }
  398.                 // une seule date
  399.             } else {
  400.                 // si une seule date
  401.                 foreach($infos as $kd=>$vd) {
  402.                     if(!empty($vd['date_orig'])) {
  403.                         $dateshours[$periode]['date'] = $vd['date_orig'];
  404.                         $dateshours[$periode]['is_cancelled'] = $vd['is_cancelled'];
  405.                         $dateshours[$periode]['hours'] = $vd['hours'];
  406.                         break;
  407.                     }
  408.                 }
  409.             }
  410.         } // fin de la boucle sur les périodes
  411.         /*
  412.         print_r($dateshours);
  413.         exit;
  414.         */
  415.         return $dateshours;
  416.     }
  417.     // }}}
  418.     //  {{{ getHours()
  419.     /** heures du spectacle
  420.      *
  421.      * @access  public
  422.      * @return  array
  423.      * @param   string  $date La date du spectacle
  424.      * @param   int     $idspectacle identifiant du spectacle
  425.      * @param   int     $idcontact identifiant du contact
  426.      */
  427.     public function getHours($date,$idspectacle,$idcontact)
  428.     {
  429.         $query 'SELECT hour,note,url_spectacle,url_booking 
  430.                   FROM schedules 
  431.                   WHERE date="'.$date.'" AND idspectacle='.$idspectacle.' AND idcontact='.$idcontact;
  432.         $res $this->query($query);
  433.         foreach($res AS $row) { //TODO à revoir -> res->fetchRow()
  434.             if($row['hour']!='00:00') {
  435.                 $hour[]['hour'] = $row['hour'];
  436.             }
  437.             $hour[]['note'] = $row['note'];
  438.             $hour[]['url_spectacle'] = $row['url_spectacle'];
  439.             $hour[]['url_booking'] = $row['url_booking'];
  440.         }
  441.         $this->free(); //res->free();
  442.         return $hour;
  443.     }
  444.     // }}}
  445.     // {{{ getDateBySpectaclesCommon()
  446.     /** Code commun à getDateBySpectaclesDemain() et getDateBySpectaclesHier(),
  447.      *  Liste des dates pour une biographie
  448.      *
  449.      *
  450.      * @param  string $type demain|hier
  451.      * @param  int    $idspectacle
  452.      * @param  string $limit
  453.      * @param  string $order ASC|DESC
  454.      * @access protected
  455.      * @return array
  456.      */
  457.     public function getDateBySpectaclesCommon($type='demain',$idspectacle,$limit,$order,$version='old',$params=array())
  458.     {
  459.         $conn $this->getEntityManager();
  460.         if ($type == 'demain') {
  461.             $expr '>=';
  462.         } elseif($type == 'tous') {
  463.             $expr 'tous';
  464.         } else {
  465.             $expr '<=';
  466.         }
  467.         $query 'SELECT DISTINCT(s.idschedule),hour,date,s.note,s.url_spectacle,s.url_booking,s.idcontact_festival,s.hour,s.idspectacle,
  468.                     c.idcontact,c.organisation,c.phone1,c.phone2,c.city,c.url_clean,
  469.                     ft.idcontact as festival_idcontact,ft.organisation as festival_organisation,ft.city as festival_city,ft.url_clean as festival_url_clean
  470.                     FROM schedules s
  471.                     JOIN contacts c ON s.idcontact=c.idcontact
  472.                     LEFT JOIN contacts ft ON s.idcontact_festival=ft.idcontact
  473.                     WHERE 1';
  474.         if (empty($idspectacle)) {
  475.             return false;
  476.         }
  477.         if(is_array($idspectacle)){
  478.             $query .= ' AND s.idspectacle IN ('.implode(','$idspectacle).')';
  479.         }
  480.         else{
  481.             $query .= ' AND s.idspectacle = '.(int)$idspectacle;
  482.         }
  483.         if(!in_array($expr, ['premiere_representation''tous'])) {
  484.             $query .= ' AND s.date'.$expr.'\''.date('Y-m-d').'\'';
  485.         }
  486.         if(!empty($params['idcontact'])) {
  487.             $query .= ' AND c.idcontact = '.$params['idcontact'].' ';
  488.         }
  489.         $query .= ' ORDER BY s.date '.$order//GROUP BY c.idcontact
  490.         if(!empty($limit)) {
  491.             $query .= ' LIMIT 0,'.((int)$limit);
  492.         }
  493.         if(!empty($params['count'])){
  494.             return $this->queryOne($query);
  495.         }
  496.         //executer la requete
  497.         $this->query($query);
  498.         //tableau de retour
  499.         $r = array();
  500.         // pour le contact
  501.         $contacts $conn->getRepository(Contacts::class);
  502.         $fields_contact_select = array('idschedule''city','url_clean','idcontact','organisation','phone1','phone2','hour','date','idspectacle');
  503.         //trouver la date de fin pour chaque spectacle
  504.         while ($this->fetch()) {
  505.             $idschedule $this->idschedule;
  506.             $date $this->date;
  507.             if(empty($r[$date])){
  508.                 $r[$date]['date_str'] = $this->getFormeDate($date,"%a %d/%m/%y",true);
  509.                 $r[$date]['date_full_str'] = $this->getFormeDate($date,"%A %d %B %Y",true);
  510.                 $r[$date]['date_orig'] = $this->getFormeDate($date,$GLOBALS['format_date'][$GLOBALS['lng']]);
  511.             }
  512.             if(!empty($this->hour)){
  513.                 $r[$date]['hour'] = $this->hour;
  514.             }
  515.             foreach ($fields_contact_select as $f) {
  516.                 if (isset($this->$f)) {
  517.                     $r[$date]['datas'][$idschedule][$f] = $this->$f;
  518.                 }
  519.             }
  520.         }
  521.         if(!empty($params['premiere_representation'])) {
  522.             foreach ($r AS $idschedule => $v) {
  523.                 if (empty($r[$idschedule]['premiere_date'])) {
  524.                     if (isset($r[$idschedule]['dateshours']['event'])) {
  525.                         if (is_array($r[$idschedule]['dateshours']['event'])) {
  526.                             $premiere_date key($r[$idschedule]['dateshours']['event']);
  527.                         } else {
  528.                             $premiere_date $r[$idschedule]['dateshours']['event'];
  529.                         }
  530.                     } else {
  531.                         if (is_array($r[$idschedule]['dateshours'])) {
  532.                             //on cherche à ignorer la clé "periode" du tableau "dateshours"
  533.                             foreach ($r[$idschedule]['dateshours'] AS $kv => $vv) {
  534.                                 if ($kv != 'periode') {
  535.                                     $schedule_date $kv;
  536.                                     break;
  537.                                 }
  538.                             }
  539.                             $premiere_date $schedule_date;
  540.                         } else {
  541.                             $premiere_date $r[$idschedule]['dateshours'];
  542.                         }
  543.                     }
  544.                     $r[$idschedule]['premiere_date'] = $this->getFormeDate($premiere_date"%A %d %B %Y"true);
  545.                 }
  546.             }
  547.         }
  548.         return $r;
  549.     }
  550.     // }}}
  551.     //  {{{ getDateBySpectaclesDemain()
  552.     /** Dates pour un spectacle
  553.      *
  554.      * Liste des dates pour un spectacle
  555.      *
  556.      * @access  public
  557.      * @return  array
  558.      * @param   int     $idspectacle identifiant du spectacle
  559.      * @param   string  $limit limit de l'affichage
  560.      * @param   string  $order ASC|DESC, par défaut ASC
  561.      */
  562.     public function getDateBySpectaclesDemain($idspectacle,$limit=null,$order=null,$version='old',$params = [])
  563.     {
  564.         // ordre de tri
  565.         if (empty($order) || strtolower($order) == 'asc') {
  566.             $order 'ASC';
  567.         } else {
  568.             $order 'DESC';
  569.         }
  570.         return $this->getDateBySpectaclesCommon('demain',$idspectacle,$limit,$order,$version,$params);
  571.     }
  572.     // }}}
  573.     //  {{{ getDateBySpectaclesHier()
  574.     /** Dates pour un spectacle
  575.      *
  576.      * Liste des dates pour un spectacle
  577.      *
  578.      * @access  public
  579.      * @return  array
  580.      * @param   int     $idspectacle identifiant du spectacle
  581.      * @param   string  $limit limit de l'affichage
  582.      * @param   string  $order ASC|DESC, par défaut DESC
  583.      */
  584.     public function getDateBySpectaclesHier($idspectacle,$limit=null,$order=null,$version='old')
  585.     {
  586.         //ordre de tri
  587.         if (empty($order) || strtolower($order) == 'desc') {
  588.             $order 'DESC';
  589.         } else {
  590.             $order 'ASC';
  591.         }
  592.         return $this->getDateBySpectaclesCommon('hier',$idspectacle,$limit,$order,$version);
  593.     }
  594.     // }}}
  595.     // {{{ getDateLieuCommon()
  596.     /** Code commun à getDateLieuDemain() et getDateLieuHier(),
  597.      *  Liste des dates pour un spectacle
  598.      *
  599.      *
  600.      * @param  string $type demain|hier
  601.      * @param  int    $idspectacle
  602.      * @param  string $limit
  603.      * @param  string $order ASC|DESC
  604.      * @access protected
  605.      * @return array
  606.      */
  607.     public function getDateLieuCommon($type='demain',$idspectacle,$limit,$order,$version='old',$params=array())
  608.     {
  609.         $conn $this->getEntityManager();
  610.         if ($type == 'demain') {
  611.             $expr '>=';
  612.         } elseif($type == 'tous') {
  613.             $expr 'tous';
  614.         } else {
  615.             $expr '<=';
  616.         }
  617.         // pour débug
  618.         if(isset($_REQUEST['group_date_version'])) {
  619.             $version 'new';
  620.         }
  621.         //récupérer les informations et la date de début
  622.         $query 'SELECT DISTINCT(s.idschedule),s.note,s.url_spectacle,s.url_booking,s.idcontact_festival,s.hour,
  623.                     c.idcontact,c.organisation,c.phone1,c.phone2,c.city,c.url_clean,MIN(s.date) AS datedebut,
  624.                     ft.idcontact as festival_idcontact,ft.organisation as festival_organisation,ft.city as festival_city,ft.url_clean as festival_url_clean
  625.                     FROM schedules s
  626.                     JOIN contacts c ON s.idcontact=c.idcontact
  627.                     LEFT JOIN contacts ft ON s.idcontact_festival=ft.idcontact
  628.                     WHERE s.idspectacle='.((int)$idspectacle);
  629.         if(!in_array($expr, ['premiere_representation''tous'])) {
  630.             $query .= ' AND s.date'.$expr.'\''.date('Y-m-d').'\'';
  631.         }
  632.         $query .= ' GROUP BY c.idcontact ORDER BY s.date '.$order;
  633.         if(!empty($limit)) {
  634.             $query .= ' LIMIT 0,'.((int)$limit);
  635.         }
  636.         //setDebug($query);
  637.         //executer la requete
  638.         $datas $this->query($query);
  639.         //tableau de retour
  640.         $r = array();
  641.         // pour le contact
  642.         $contacts $conn->getRepository(Contacts::class);
  643.         $fields_contact_select = array('city','url_clean','idcontact','organisation','phone1','phone2' );
  644.         //trouver la date de fin pour chaque spectacle
  645.         foreach($datas AS $data) {
  646.             $this->loadResult($data);
  647.             $idschedule $this->idschedule;
  648.             foreach($fields_contact_select as $f) {
  649.                 if(isset($this->$f))  {
  650.                     $r[$idschedule][$f] = $this->$f;
  651.                 }
  652.             }
  653.             // booking et page du spectacle
  654.             if(!empty($this->url_booking)) {
  655.                 if(preg_match('#^https?://#'$this->url_booking)) {
  656.                     $r[$idschedule]['url_booking'] = $this->url_booking;
  657.                 } else {
  658.                     $r[$idschedule]['url_booking'] = 'http://'.$this->url_booking;
  659.                 }
  660.             }
  661.             if(!empty($this->url_spectacle)) {
  662.                 if(preg_match('#^https?://#'$this->url_booking)) {
  663.                     $r[$idschedule]['url_spectacle'] = $this->url_spectacle;
  664.                 } else {
  665.                     $r[$idschedule]['url_spectacle'] = 'http://'.$this->url_spectacle;
  666.                 }
  667.             }
  668.             // voir si le contact à un avatar
  669.             $profilepicture $contacts->getVignetteContact($this->idcontact,array('width' => 40'height' => 40),'class_pp');
  670.             if(strpos($profilepicture'normal-def')===false) {
  671.                 $r[$idschedule]['profilepicture'] = $profilepicture;
  672.             }
  673.             if(isset($this->festival_organisation) && $this->festival_organisation!='') {
  674.                 $r[$idschedule]['festival'] = array(
  675.                     'organisation' => $this->festival_organisation,
  676.                     'idcontact' => $this->festival_idcontact,
  677.                     'url_clean' => $this->festival_url_clean,
  678.                 );
  679.             }
  680.             $r[$idschedule]['dateshours'] = $this->getDatesHours($idspectacle,$this->idcontact,$type,$version);
  681.             // pour Old
  682.             if($version=='old') {
  683.                 $r[$idschedule]['event'] = $r[$idschedule]['dateshours']['event'];
  684.                 $r[$idschedule]['months'] = $r[$idschedule]['dateshours']['months'];
  685.                 // ne pas encombrer le tableau
  686.                 if(!empty($r[$idschedule]['dateshours']['months'])) {
  687.                     unset($r[$idschedule]['dateshours']['months']);
  688.                 }
  689.                 if(!empty($r[$idschedule]['dateshours']['event'])) {
  690.                     unset($r[$idschedule]['dateshours']['event']);
  691.                 }
  692.                 // générer le calendrier
  693.                 // première date
  694.                 foreach($r[$idschedule]['event'] as $k=>$v) {
  695.                     $calendar = new Calendar($v['date']);
  696.                     break;
  697.                 }
  698.                 // highlight les dates
  699.                 $i 0;
  700.                 foreach($r[$idschedule]['months'] as $k=>$v) {
  701.                     if($i>0) {
  702.                         $calendar = new Calendar($v['y'].'-'.$v['m'].'-01');
  703.                     }
  704.                     $calendar->highlighted_dates $r[$idschedule]['event'];
  705.                     $calendar->link_days 2;
  706.                     $calendar->formatted_link_to "javascript:;";
  707.                     $r[$idschedule]['calendar'][] = $calendar->output_calendar();
  708.                     $i++;
  709.                 }
  710.             } // fin test old
  711.         }
  712.         $this->free();
  713.         // pour la nouvelle présentatiopn par période
  714.         if($version=='new') {
  715.             foreach($r as $k=>$v) {
  716.                 $kp 0;
  717.                 foreach($v['dateshours'] as $kb=>$vb) {
  718.                     $key $k.'-'.$kp;
  719.                     $kp++;
  720.                     $r[$key]  = $v;
  721.                     unset($r[$k]);
  722.                     $r[$key]['dateshours'] = $vb;
  723.                     $r[$key]['event'] = $r[$key]['dateshours']['event'];
  724.                     $r[$key]['months'] = $r[$key]['dateshours']['months'];
  725.                     // ne pas encombrer le tableau
  726.                     if(!empty($r[$key]['dateshours']['months'])) {
  727.                         unset($r[$key]['dateshours']['months']);
  728.                     }
  729.                     if(!empty($r[$key]['dateshours']['event'])) {
  730.                         unset($r[$key]['dateshours']['event']);
  731.                     }
  732.                     // générer le calendrier
  733.                     // première date
  734.                     foreach($r[$key]['event'] as $kc=>$vc) {
  735.                         $calendar = new Calendar($vc['date']);
  736.                         break;
  737.                     }
  738.                     // highlight les dates
  739.                     $i 0;
  740.                     foreach($r[$key]['months'] as $kc=>$vc) {
  741.                         if($i>0) {
  742.                             $calendar = new Calendar($vc['y'].'-'.$vc['m'].'-01');
  743.                         }
  744.                         $calendar->highlighted_dates $r[$key]['event'];
  745.                         $calendar->link_days 2;
  746.                         $calendar->formatted_link_to "javascript:;";
  747.                         $r[$key]['calendar'][] = $calendar->output_calendar();
  748.                         $i++;
  749.                     }
  750.                 }
  751.             }
  752.         }
  753.         foreach($r AS $key => $data){
  754.             $r[$key]['is_cancelled'] = array_search(1array_column($r[$key]['dateshours'], 'is_cancelled'));
  755.         }
  756.         if(!empty($params['premiere_representation'])) {
  757.             foreach ($r AS $idschedule => $v) {
  758.                 if (empty($r[$idschedule]['premiere_date'])) {
  759.                     if (isset($r[$idschedule]['dateshours']['event'])) {
  760.                         if (is_array($r[$idschedule]['dateshours']['event'])) {
  761.                             $premiere_date key($r[$idschedule]['dateshours']['event']);
  762.                         } else {
  763.                             $premiere_date $r[$idschedule]['dateshours']['event'];
  764.                         }
  765.                     } else {
  766.                         if (is_array($r[$idschedule]['dateshours'])) {
  767.                             //on cherche à ignorer la clé "periode" du tableau "dateshours"
  768.                             foreach ($r[$idschedule]['dateshours'] AS $kv => $vv) {
  769.                                 if ($kv != 'periode') {
  770.                                     $schedule_date $kv;
  771.                                     break;
  772.                                 }
  773.                             }
  774.                             $premiere_date $schedule_date;
  775.                         } else {
  776.                             $premiere_date $r[$idschedule]['dateshours'];
  777.                         }
  778.                     }
  779.                     $r[$idschedule]['premiere_date'] = $this->getFormeDate($premiere_date"%A %d %B %Y"true);
  780.                 }
  781.             }
  782.         }
  783.         //retourner le tableau
  784.         return $r;
  785.     }
  786.     // }}}
  787.     //  {{{ getDateLieuDemain()
  788.     /** Dates pour un spectacle
  789.      *
  790.      * Liste des dates pour un spectacle
  791.      *
  792.      * @access  public
  793.      * @return  array
  794.      * @param   int     $idspectacle identifiant du spectacle
  795.      * @param   string  $limit limit de l'affichage
  796.      * @param   string  $order ASC|DESC, par défaut ASC
  797.      */
  798.     public function getDateLieuDemain($idspectacle,$limit=null,$order=null,$version='old')
  799.     {
  800.         // ordre de tri
  801.         if (empty($order) || strtolower($order) == 'asc') {
  802.             $order 'ASC';
  803.         } else {
  804.             $order 'DESC';
  805.         }
  806.         return $this->getDateLieuCommon('demain',$idspectacle,$limit,$order,$version);
  807.     }
  808.     // }}}
  809.     //  {{{ getDateLieuHier()
  810.     /** Dates pour un spectacle
  811.      *
  812.      * Liste des dates pour un spectacle
  813.      *
  814.      * @access  public
  815.      * @return  array
  816.      * @param   int     $idspectacle identifiant du spectacle
  817.      * @param   string  $limit limit de l'affichage
  818.      * @param   string  $order ASC|DESC, par défaut DESC
  819.      */
  820.     public function getDateLieuHier($idspectacle,$limit=null,$order=null,$version='old')
  821.     {
  822.         //ordre de tri
  823.         if (empty($order) || strtolower($order) == 'desc') {
  824.             $order 'DESC';
  825.         } else {
  826.             $order 'ASC';
  827.         }
  828.         return $this->getDateLieuCommon('hier',$idspectacle,$limit,$order,$version);
  829.     }
  830.     // }}}
  831.     // {{{ ScheduleToKeywords()
  832.     /** Génère une liste de mots clés basés sur les lieux et dates de représentation
  833.      *
  834.      *
  835.      * @param  array $schedule
  836.      * @param  int $max nb max de dates
  837.      * @access public
  838.      * @return string
  839.      */
  840.     function ScheduleToKeywords($schedule$max=20) {
  841.         return null;
  842.         require_once PATH_LIBS.'/Functions/Months.php';
  843.         // ajout des mots clés basés sur les lieux et dates de représentation
  844.         $keywords = array();
  845.         $count 0;
  846.         foreach($schedule as $item) {
  847.             $count++;
  848.             if (!empty($item['city'])) $keywords[] = trim($item['city']);
  849.             if (!empty($item['organisation'])) $keywords[] = trim($item['organisation']);
  850.             if (isset($item['dateshours']['periode'])) {
  851.                 foreach ($item['dateshours'] as $k => $v) {
  852.                     if ($k == 'periode' || $k == 'event' || $k=='months') continue;
  853.                     $date explode('/',$k);
  854.                     $keywords[] = getDay($date[1]); //mois
  855.                     $keywords[] = $date[2]; // annee
  856.                 }
  857.             } else {
  858.                 $date explode('/',$item['dateshours']['date']);
  859.                 $keywords[] = getDay($date[1]); //mois
  860.                 $keywords[] = $date[2]; //annee
  861.             }
  862.             if ($count $max) break;
  863.         }
  864.         return implode(' ',array_unique($keywords));
  865.     }
  866.     // }}}
  867.     // {{{ deleteSchedule()
  868.     /** Supprimer toutes les dates pour un spectacle et/ou un lieu
  869.      *
  870.      *
  871.      * @param  int $idspectacle Identifiant du spectacle
  872.      * @param  int    $idcontact Identifiant du contact
  873.      * @access public
  874.      * @return array
  875.      */
  876.     public function deleteSchedule($idspectacle,$idcontact=null)
  877.     {
  878.         $sql 'DELETE FROM '.$this->__table.
  879.                 WHERE idspectacle='.(int)$idspectacle;
  880.         if(!empty($idcontact)) {
  881.             $sql .= ' AND idcontact='.(int)$idcontact;
  882.         }
  883.         $this->logDeletion('[Schedules::deleteSchedule] Supprime un calendrier '.$sql);
  884.         return $this->execute($sql);
  885.     }
  886.     // }}}
  887.     // {{{ cancelledDates()
  888.     /** Annulée les dates d'un spectacle
  889.      *
  890.      *
  891.      * @param  int $idspectacle Identifiant du spectacle
  892.      * @param  int    $idcontact Identifiant du contact
  893.      * @access public
  894.      * @return array
  895.      */
  896.     public function cancelledDates($idspectacle,$idcontact=null$status true)
  897.     {
  898.         $sql 'UPDATE schedules
  899.                 SET is_cancelled = '.(int)$status.',dateupdate=\''.$this->now().'\'
  900.                 WHERE idspectacle='.(int)$idspectacle .' ';
  901.         if(!empty($idcontact)) {
  902.             $sql .= ' AND idcontact='.(int)$idcontact;
  903.         }
  904.         return $this->execute($sql);
  905.     }
  906.     // }}}
  907.     // {{{ validateSchedule()
  908.     /** Valider les dates d'un spectacle
  909.      *
  910.      *
  911.      * @param  int $idspectacle Identifiant du spectacle
  912.      * @param  int    $idcontact Identifiant du contact
  913.      * @access public
  914.      * @return array
  915.      */
  916.     public function validateSchedule($idspectacle,$idcontact=null)
  917.     {
  918.         $sql 'UPDATE schedules
  919.                 SET publish=1,valid=1,dateupdate=\''.now().'\'
  920.                 WHERE idspectacle='.(int)$idspectacle;
  921.         if(!empty($idcontact)) {
  922.             $sql .= ' AND idcontact='.(int)$idcontact;
  923.         }
  924.         return $this->execute($sql);
  925.     }
  926.     // }}}
  927.     // {{{ countDates()
  928.     /** Compter les dates pour un spectacle
  929.      *
  930.      *
  931.      * @param  int $idspectacle Identifiant du spectacle
  932.      * @access public
  933.      * @return array
  934.      */
  935.     public function countDates($idspectacle=null,$idcontact=null,$special=array())
  936.     {
  937.         $sql[] = 'SELECT COUNT(*) as nb 
  938.                   FROM '.$this->__table.' WHERE 1 ';
  939.         if(!empty($idspectacle)) {
  940.             $sql[] = ' AND idspectacle='.(int)$idspectacle;
  941.         }
  942.         if(!empty($idcontact)) {
  943.             $sql[] = ' AND idcontact='.(int)$idcontact;
  944.         }
  945.         if(array_key_exists('saison',$special)) {
  946.             $s explode('-'$special['saison']);
  947.             $sql[] = ' AND date BETWEEN \''.$s[0].'-09-01\' AND \''.$s[1].'-08-31\' ';
  948.         }
  949.         $nb $this->queryOne(join("\n"$sql));
  950.         if($nb) {
  951.             return $nb;
  952.         } else {
  953.             return null;
  954.         }
  955.     }
  956.     // }}}
  957.     //  {{{ getSQLSchedules()
  958.     /** Générer la requete standard pour des calendrier
  959.      *
  960.      * $params = array(
  961.      *  'select' => champs en plus pour le select,
  962.      *  'from' => champs en plus pour le from,
  963.      *  'where' => paramètres en plus le where,
  964.      *  'order' => classement des résultats,
  965.      *  'limit' => limiter le nb de résultats array(debut,fin), (all pour pas de limit)
  966.      * )
  967.      *
  968.      * @access   public
  969.      * @param    array  $query Les paramètres pour la requete
  970.      * @param    bool $debug afficher la requête
  971.      * @return   string
  972.      */
  973.     public function getSQLSchedules($query=array(),$debug=false)
  974.     {
  975.         // on prepare les tableaux
  976.         foreach(array('select','from','where','order','group','having','limit') as $t) {
  977.             if(!empty($query[$t])) {
  978.                 if(!is_array($query[$t])) {
  979.                     $query[$t][] = $query[$t];
  980.                 } else {
  981.                     $query[$t] = $query[$t];
  982.                 }
  983.             } else {
  984.                 $query[$t] = array();
  985.             }
  986.         }
  987.         // champs par défaut
  988.         if(empty($query['count_only'])) {
  989.             $this->addSQLParams('select',$query,array(
  990.                 array($this->__table => '*')
  991.             ));
  992.         }
  993.         else{
  994.             $this->addSQLParams('from',$query,array(
  995.                 'schedules',
  996.             ));
  997.         }
  998.         // recherche par région
  999.         if(!empty($query['special']['regions'])) {
  1000.             $this->addSQLParams('from',$query,array(
  1001.                 'contacts',
  1002.             ));
  1003.             // jointure entre les 3 tables
  1004.             $this->addSQLParams('join',$query,array(
  1005.                 'contacts.idcontact' => 'schedules.idcontact',
  1006.             ));
  1007. //            $this->addSQLParams('where',$query,array(
  1008. //                array('contacts','',$query['special']['regions'], 'AND','IN'),
  1009. //            ));
  1010.         }
  1011.         if(array_key_exists('idsschedules'$query)) {
  1012.             $query['where'][] = ' AND schedules.idschedule IN ('.implode(','$query['idsschedules']).') ';
  1013.         }
  1014.         if(array_key_exists('saison'$query)) {
  1015.             $s explode('-'$query['saison']);
  1016.             $query['where'][] = ' AND schedules.date BETWEEN \''.$s[0].'-09-01\' AND \''.$s[1].'-08-31\' ';
  1017.         }
  1018.         // publié ou pas
  1019.         if(empty($query['publish']) && $_ENV['CHECK_IF_ONLINE']) {
  1020.             $this->addSQLParams('where',$query,array(
  1021.                 array($this->__table,'publish',1)
  1022.             ));
  1023.         } elseif(!empty($query['publish'])) {
  1024.             $this->addSQLParams('where',$query,array(
  1025.                 array($this->__table,'publish',$query['publish'])
  1026.             ));
  1027.         }
  1028.         // validé ou pas
  1029.         if(isset($query['valid'])) {
  1030.             $this->addSQLParams('where',$query,array(
  1031.                 array($this->__table,'valid',$query['valid'])
  1032.             ));
  1033.         }
  1034.         return $this->getSQLObject($query);
  1035.     }
  1036.     // }}}
  1037.     //  {{{ getListSchedules()
  1038.     /** Retourne des listes de dates
  1039.      *
  1040.      * Retourne des listes de date au format "standard""
  1041.      *
  1042.      * @access   public
  1043.      * @return   array
  1044.      * @param    array $params_sql paramètre pour la requete SQL
  1045.      * @param    array $format_vignette de la vignette si pas standard
  1046.      * @param    array $params_display paramètre pour l'affichage
  1047.      */
  1048.     public function getListSchedules($params_sql=null,$format_vignette=array(),$params_display=array())
  1049.     {
  1050.         // construction de la requête avec le passage de paramètres
  1051.         $sql $this->getSQLSchedules($params_sql);
  1052.         // paramètre de debug
  1053.         $dbg = (empty($params_sql['dbg'])) ? array() : $dbg $params_sql['dbg'];
  1054.         // executer la requete
  1055.         $this->query($sql,$dbg);
  1056.         $videos = array();
  1057.         // debug
  1058.         $start_boucle microtime(true);
  1059.         $results = array();
  1060.         if(!empty($params_sql['count_only']) || !empty(!empty($params_sql['count_only']))){
  1061.             $results 0;
  1062.         }
  1063.         $color null;
  1064.         // on boucle
  1065.         while($this->fetch()) {
  1066.             // le total
  1067.             if(!empty($params_sql['count_only'])) {
  1068.                 return $this->total;
  1069.             }
  1070.             $idschedule $this->idschedule;
  1071.             $results[$idschedule] = $this->getInfosSchedules($idschedule);
  1072.             // couleur de ligne alternative
  1073.             $color $this->colorAlternate($color);
  1074.             $results[$idschedule]['colorline'] = $color;
  1075.         }
  1076.         // debug de la boucle
  1077.         if($this->isTraceMode('list_object')) {
  1078.             $this->setTraceInfos(array(
  1079.                 'execution_time_boucle' => microtime(true) - $start_boucle,
  1080.                 'nb_occurence' => count($dvds),
  1081.                 'dbg' => $dbg,
  1082.             ));
  1083.         }
  1084.         $this->free();
  1085.         return $results;
  1086.     }
  1087.     // }}}
  1088.     //  {{{ getSchedule()
  1089.     /** récupèrer le calendrier d'un spectacle
  1090.      *
  1091.      * Récupèrer simplement le calendrier d'un spectacle
  1092.      *
  1093.      * @access public
  1094.      * @return array
  1095.      * @param  int $idspectacle Identifiant du spectacle
  1096.      */
  1097.     public function getSchedule($idspectacle,$api=false)
  1098.     {
  1099.         $conn $this->getEntityManager();
  1100.         $sql "SELECT schedules.*, contacts.organisation, contacts.url_clean, contacts.city, contacts.zip, UPPER(contacts.country) AS country, departements.nom AS departement
  1101.                 FROM schedules 
  1102.                  INNER JOIN contacts ON contacts.idcontact = schedules.idcontact
  1103.                  INNER JOIN spectacles ON schedules.idspectacle = spectacles.idspectacle
  1104.                  LEFT JOIN departements ON contacts.country LIKE 'FR' AND departements.departement LIKE SUBSTRING(contacts.zip, 1, IF(SUBSTRING(contacts.zip, 1, 2) >= 97, 3, 2))
  1105.                  WHERE schedules.idspectacle = " . (int)$idspectacle "
  1106.                     AND spectacles.publish = 1 AND spectacles.valid = 1;";
  1107.         $bigregions $conn->getRepository(Bigregions::class);
  1108.         $sql .= ' WHERE schedules.idspectacle='.(int)$idspectacle;
  1109.         // uniquement les dates validées et les spectacles en ligne et validés
  1110.         $sql .= ' AND spectacles.publish=1 AND spectacles.valid=1 ';
  1111.         $dates $this->queryAll($sql);
  1112.         // parcourir => grouper les heures par dates
  1113.         foreach($dates as $k=>$v) {
  1114.             $key $v['date'].'-'.$v['url_clean'];
  1115.             // si la date existe déjà, on ajoute l'heure
  1116.             if(!empty($rows[$key])) {
  1117.                 $rows[$key]['hours'][] = array(
  1118.                     'hour' => $v['hour'],
  1119.                 );
  1120.                 if(!empty($v['comment'])) {
  1121.                     $rows[$key]['hours']['comment'] = $v['comment'];
  1122.                 }
  1123.             } else {
  1124.                 $deptCode $v['zip'] !== null
  1125.                     substr($v['zip'], 02)
  1126.                     : null;
  1127.                 $rows[$key] = array(
  1128.                     'date' => $v['date'],
  1129.                     'hours' => array(array(
  1130.                         'hour' => $v['hour'],
  1131.                     )),
  1132.                     'location' => array(
  1133.                         'name' => $v['organisation'],
  1134.                         'city' => $v['city'],
  1135.                         'area_code' => $bigregions->getIdbigregionByZip($v['zip']),
  1136.                         'department' => $v['departement'],
  1137.                         'dept_code' => $deptCode,
  1138.                         'zip_code' => $v['zip'],
  1139.                         'country' => $v['country'],
  1140.                         'object' => $v['url_clean'],
  1141.                         'permanent_url' => $_ENV['URL_THNET'].'/contacts/'.$v['url_clean'].'/',
  1142.                     )
  1143.                 );
  1144.                 if(!empty($v['comment'])) {
  1145.                     $rows[$key]['hours']['comment'] = $v['comment'];
  1146.                 }
  1147.                 if(!empty($v['url_spectacle'])) {
  1148.                     $rows[$key]['location']['url_spectacle'] = $v['url_spectacle'];
  1149.                 }
  1150.                 if(!empty($v['url_booking'])) {
  1151.                     $rows[$key]['location']['url_booking'] = $v['url_booking'];
  1152.                 }
  1153.                 /* ancienne version
  1154.                 // si la date existe déjà, on ajoute l'heure
  1155.                 if(!empty($rows[$v['date']])) {
  1156.                     $rows[$v['date']]['hours'][] = array(
  1157.                         'hour' => $v['hour'],
  1158.                     );
  1159.                     if(!empty($v['comment'])) {
  1160.                         $rows[$v['date']]['hours']['comment'] = $v['comment'];
  1161.                     }
  1162.                 } else {
  1163.                     $rows[$v['date']] = array(
  1164.                         'date' => $v['date'],
  1165.                         'hours' => array(array(
  1166.                             'hour' => $v['hour'],
  1167.                         )),
  1168.                         'location' => array(
  1169.                             'name' => $v['organisation'],
  1170.                             'city' => $v['city'],
  1171.                             'object' => $v['url_clean'],
  1172.                             'permanent_url' => $_ENV['URL_THNET'].'/contacts/'.$v['url_clean'].'/',
  1173.                         )
  1174.                     );
  1175.                     if(!empty($v['comment'])) {
  1176.                         $rows[$v['date']]['hours']['comment'] = $v['comment'];
  1177.                     }
  1178.                     if(!empty($v['url_spectacle'])) {
  1179.                         $rows[$v['date']]['location']['url_spectacle'] = $v['url_spectacle'];
  1180.                     }
  1181.                     if(!empty($v['url_booking'])) {
  1182.                         $rows[$v['date']]['location']['url_booking'] = $v['url_booking'];
  1183.                     }
  1184.                 */
  1185.                 // pour l'api
  1186.                 if($api) {
  1187.                     //$rows[$v['date']] = $this->getApiTab($rows[$v['date']]);
  1188.                 }
  1189.             }
  1190.         }
  1191.         return $rows;
  1192.     }
  1193.     // }}}
  1194.     //  {{{ getObjectTitle()
  1195.     /** Infos de l'item recherché
  1196.      *
  1197.      * Affichage standard du titre de l'objet
  1198.      *
  1199.      * @access public
  1200.      * @return string
  1201.      * @param  int $idobject Identifiant de l'item
  1202.      * @param  array $infos_object Informations pour construire le titre
  1203.      * @param array $params Paramétres supplémentaires
  1204.      */
  1205.     public function getObjectTitle($idobject=null,$infos_object=array(),$params=array())
  1206.     {
  1207.         $title '';
  1208.         if(!$idobject) {
  1209.             $idobject $this->iddvd;
  1210.         }
  1211.         // champs
  1212.         $fields = array('iddvd','title','url_clean');
  1213.         if(!empty($infos_object)) {
  1214.             foreach($fields as $k=>$v) {
  1215.                 if(array_key_exists($v$infos_object)) {
  1216.                     $$v $infos_object[$v];
  1217.                 }
  1218.             }
  1219.         } else {
  1220.             //charger les infos que si necessaire
  1221.             if(empty($this->title)) {
  1222.                 $this->selectAdd();
  1223.                 $this->selectAdd(implode(','$fields));
  1224.                 $this->get($idobject);
  1225.             }
  1226.             foreach($fields as $k=>$v) {
  1227.                 if(isset($this->$v) && $this->$v!='') {
  1228.                     $$v trim($this->$v);
  1229.                 }
  1230.             }
  1231.         }
  1232.         return $title;
  1233.     }
  1234.     // }}}
  1235.     //  {{{ getApiTab()
  1236.     /** génére la version pour la diffusion API
  1237.      *
  1238.      * @see Theatre::getApiTab
  1239.      */
  1240.     public function getApiTab($data)
  1241.     {
  1242.         // généré à partir de getApiFields
  1243.         $data_api parent::getApiTab($data,$_ENV['URL_THNET']);
  1244.         return $data_api;
  1245.     }
  1246.     // }}}
  1247.     //  {{{ getApiFields()
  1248.     /** champs à renvoyer par l'API ==> NON UTILISÉ
  1249.      *
  1250.      * @access  public
  1251.      * @param array tableau de données
  1252.      */
  1253.     protected function getApiFields()
  1254.     {
  1255.         return array(
  1256.             'date' => 'date',
  1257.             'hours' => array(
  1258.                 'hour' => 'hour',
  1259.                 'comment' => 'comment',
  1260.             ),
  1261.             'location' => array(
  1262.                 'url_clean' => 'permanent_url#(.*)#'.$_ENV['URL_THNET'].'/contacts/${1}/',
  1263.                 'organisation' => 'name'// ne garder que l'année
  1264.             ),
  1265.         );
  1266.     }
  1267.     // }}}
  1268.     //  {{{ getRelationsArray()
  1269.     /** Tableau des relations
  1270.      *
  1271.      * @access  public
  1272.      * @param string|int $type le type de champ
  1273.      */
  1274.     public function getRelationsArray($type=null)
  1275.     {
  1276.         // récupérer les relations communes
  1277.         $array_types $this->getRelationsArrayTrait('all');
  1278.         $array_types += array(
  1279.             'idcontact' => array(
  1280.                 'type_join' => 'simple',
  1281.                 'dest_table' => 'contacts',
  1282.                 'src_table_field' => 'idcontact',
  1283.                 'join_field_src' => 'idcontact',
  1284.                 'dest_table_field' => 'idcontact',
  1285.                 'fields' => array('idcontact','organisation','url_clean'),
  1286.                 'silent_delete_relation' => true,
  1287.                 'description' => 'Contact associé à ce calendrier',
  1288.             ),
  1289.             'idcontact_festival' => array(
  1290.                 'type_join' => 'simple',
  1291.                 'dest_table' => 'contacts',
  1292.                 'src_table_field' => 'idcontact',
  1293.                 'join_field_src' => 'idcontact_festival',
  1294.                 'dest_table_field' => 'idcontact',
  1295.                 'fields' => array('idcontact','organisation','url_clean'),
  1296.                 'silent_delete_relation' => true,
  1297.                 'description' => 'Festival associé à ce calendrier',
  1298.             ),
  1299.         );
  1300.         if(!empty($array_types[$type])) {
  1301.             $array_types[$type]['type'] = $type;
  1302.             return $array_types[$type];
  1303.         } else {
  1304.             return $array_types;
  1305.         }
  1306.     }
  1307.     // }}}
  1308.     // {{{ countSchedules()
  1309.     /** Compter les dates
  1310.      *
  1311.      * @access public
  1312.      * @return int
  1313.      */
  1314.     public function countSchedules($params = array())
  1315.     {
  1316.         $sql 'SELECT COUNT(*) as nb
  1317.                 FROM '.$this->__table.'
  1318.                 WHERE 1 ';
  1319.         if(!empty($params['date_start'])) {
  1320.             $sql .= ' AND date>\''.$params['date_start'].'\' ';
  1321.         }
  1322.         try {
  1323.             return $this->queryOne($sql);;
  1324.         } catch (\Throwable $e) {
  1325.             return null;
  1326.         }
  1327.     }
  1328.     // }}}
  1329.     // {{{ getContactsBySpectaclesSchedules()
  1330.     /** Récupèrer les contacts de calendrier de spectacles
  1331.      *
  1332.      * @access public
  1333.      * @param int|array $idspectacle le(s) spectacle(s)
  1334.      * @return array
  1335.      */
  1336.     public function getContactsBySpectaclesSchedules($idspectacle)
  1337.     {
  1338.         $sql 'SELECT c.* FROM
  1339.                 schedules sc
  1340.                     JOIN contacts c ON c.idcontact=sc.idcontact
  1341.                 WHERE
  1342.                 idspectacle IN ('.$this->arrayToIn($idspectacle).')';
  1343.         $contacts $this->queryAll($sql);
  1344.         if(!empty($contacts)) {
  1345.             return $contacts;
  1346.         } else {
  1347.             return array();
  1348.         }
  1349.     }
  1350.     // }}}
  1351. }