Bonjour tout le monde,
J'ai une classe PHP qui me permet de générer un table qui servira de calendrier.
J'ai par exemple deux jours de la semaine utilisés :
Jeudi de 09 à 12h00
Vendredi de 08 à 11h00
Le problème est que les heures de jeudi et vendredi vont se mettre dans jeudi et vendredi :
J'ai donc :
Jeudi 09h00, 09h30... [B]12h00, 08h00, 08h30,... 11h00[/B]
idem pour vendredi (voir [URL="http://dubinfo.be/imaginatiff/reservations/CapturFiles_45.png"]l'url[/URL] <==)
Voici le code de ma classe :
Comme vous pouvez le voir, j'ai mis des print_r et des echos afin de déboger.
Le débogage me donne ceci :
[QUOTE]Array ( [1] => janvier [2] => février [3] => mars [4] => avril [5] => mai [6] => juin [7] => juillet [8] => août [9] => septembre [10] => octobre [11] => novembre [12] => décembre ) print_r de months vaut : 1
Array ( [1] => lundi [2] => mardi [3] => mercredi [4] => jeudi [5] => vendredi [6] => samedi [7] => dimanche ) print_r de days vaut : 1
$month vaut => 8
$year vaut => 2013
print_r du $date
DateTime Object ( => 2013-08-01 13:33:57 [timezone_type] => 3 => Europe/Berlin )
stdClass Object ( => 4,5 ) jours_reservables => 1
print_r($arr_jours) =>
Array ( [0] => 4 [1] => 5 )
$days_of_the_week vaut :
Array ( [0] => 4 [1] => 5 )
$date->format("n") => 8
Array ( [0] => 9:00 [1] => 12:00 [2] => 8:00 [3] => 11:00 ) $arr_heures : 1
DateTime Object ( => 2013-08-16 09:00:00 [timezone_type] => 3 => Europe/Berlin ) $start : 1
DateTime Object ( => 2013-08-16 12:00:00 [timezone_type] => 3 => Europe/Berlin ) end : 1
DateTime Object ( => 2013-08-16 09:00:00 [timezone_type] => 3 => Europe/Berlin )
DateTime Object ( => 2013-08-16 12:00:00 [timezone_type] => 3 => Europe/Berlin )
Array ( [0] => 09h00 ) hoursssss >>>>> : 1
Array ( [0] => 09h00 [1] => 09h30 ) hoursssss >>>>> : 1
Array ( [0] => 09h00 [1] => 09h30 [2] => 10h00 ) hoursssss >>>>> : 1
Array ( [0] => 09h00 [1] => 09h30 [2] => 10h00 [3] => 10h30 ) hoursssss >>>>> : 1
Array ( [0] => 09h00 [1] => 09h30 [2] => 10h00 [3] => 10h30 [4] => 11h00 ) hoursssss >>>>> : 1
Array ( [0] => 09h00 [1] => 09h30 [2] => 10h00 [3] => 10h30 [4] => 11h00 [5] => 11h30 ) hoursssss >>>>> : 1
Array ( [0] => 09h00 [1] => 09h30 [2] => 10h00 [3] => 10h30 [4] => 11h00 [5] => 11h30 [6] => 12h00 ) hoursssss >>>>> : 1
Array ( [0] => Array ( [0] => DateTime Object ( => 2013-08-01 13:33:57 [timezone_type] => 3 => Europe/Berlin ) [1] => DateTime Object ( => 2013-08-02 13:33:57 [timezone_type] => 3 => Europe/Berlin ) ) [1] => Array ( [0] => DateTime Object ( => 2013-08-08 13:33:57 [timezone_type] => 3 => Europe/Berlin ) [1] => DateTime Object ( => 2013-08-09 13:33:57 [timezone_type] => 3 => Europe/Berlin ) ) [2] => Array ( [0] => DateTime Object ( => 2013-08-15 13:33:57 [timezone_type] => 3 => Europe/Berlin ) [1] => DateTime Object ( => 2013-08-16 13:33:57 [timezone_type] => 3 => Europe/Berlin ) ) [3] => Array ( [0] => DateTime Object ( => 2013-08-22 13:33:57 [timezone_type] => 3 => Europe/Berlin ) [1] => DateTime Object ( => 2013-08-23 13:33:57 [timezone_type] => 3 => Europe/Berlin ) ) [4] => Array ( [0] => DateTime Object ( => 2013-08-29 13:33:57 [timezone_type] => 3 => Europe/Berlin ) [1] => DateTime Object ( => 2013-08-30 13:33:57 [timezone_type] => 3 [timezone] => Europe/Berlin ) ) )
[/QUOTE]
Le problème se trouve dans cette boucle :
C'est ici que le code génère jeudi et vendredi.
Il faudrait je pense générer chaque jour choisi séparément, c'est là que je bloque.
[B]L'horaire est sous ce format : 9:00#12:00#8:00#11:00[/B]
Mille mercis d'aance pour votre aide.
bee
J'ai une classe PHP qui me permet de générer un table qui servira de calendrier.
J'ai par exemple deux jours de la semaine utilisés :
Jeudi de 09 à 12h00
Vendredi de 08 à 11h00
Le problème est que les heures de jeudi et vendredi vont se mettre dans jeudi et vendredi :
J'ai donc :
Jeudi 09h00, 09h30... [B]12h00, 08h00, 08h30,... 11h00[/B]
idem pour vendredi (voir [URL="http://dubinfo.be/imaginatiff/reservations/CapturFiles_45.png"]l'url[/URL] <==)
Voici le code de ma classe :
<?php class Calendrier
{
public function generer($m = null, $y = null)
{
$months = array(
1 => 'janvier', 'février', 'mars', 'avril', 'mai', 'juin', 'juillet', 'août', 'septembre', 'octobre', 'novembre', 'décembre'
);
$days = array(
1 => 'lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi', 'dimanche'
);
echo '<br />';
echo 'print_r de months vaut : ' . print_r($months);
echo '<br />';
echo 'print_r de days vaut : ' . print_r($days);
echo '<br />';
echo '<br />';
$month = (empty($m) || ( ! isset($months[$m]))) ? (int)date('m') : (int)$m;
echo '$month vaut => '.$month;echo '<br />';
// limites des années gérées par le système : 1 <= année <= 9999
$year = (empty($y) || (intval($y) < 1) || (intval($y) > 9999)) ? (int)date('Y') : (int)$y;
echo '$year vaut => '.$year;echo '<br />';
// premier jour du mois
$date = \DateTime::createFromFormat('Y-m-d', "{$year}-{$month}-01");
echo 'print_r du $date ';echo '<br />';
print_r($date);echo '<br />';
// numéros des jours à afficher selon la norme ISO-8601 (lundi = 1, mardi = 2..., dimanche = 7)
//pour ajouter des jours
//$days_of_the_week = array(2, 3, 4, 5);
echo '<br />';
$jours_reservables = Configuration::renvoyer_Jours();
echo 'jours_reservables => '.print_r($jours_reservables);
echo '<br />';
echo '<br />';
$arr_jours = explode(',',$jours_reservables->jours);
echo 'print_r($arr_jours) => <br />';
print_r($arr_jours);
echo '<br /><br />';
echo '<br /><br />';
$days_of_the_week = $arr_jours;
echo '<br /><br /><br />';
echo '$days_of_the_week vaut : ';
echo '<br />';
print_r($days_of_the_week);
$nb = count($days_of_the_week);
$data = array();
$i = 0;
echo '<br /><br />';
echo '<br /><br />';
//$date->format('n') = Mois sans les zéros initiaux
echo '$date->format("n") => '.$date->format('n');
echo '<br /><br />';
echo '<br /><br />';
while ($date->format('n') == $month)
{
//1 (pour Lundi) à 7 (pour Dimanche)
$n = $date->format('N');
if (in_array($n, $days_of_the_week))
{
$data[$i][] = clone $date;
}
$date->modify('+1 day');
//si on est pas dans le bon mois
if ($date->format('n') != $month)
{
// on complète la ligne avec des espaces insécables si nécessaires
$nb_week_data = count($data[$i]);
if ($nb_week_data && ($nb_week_data < $nb))
{
$data[$i] = array_merge($data[$i], array_fill($nb, $nb_week_data, ' '));
}
break;
}
elseif ($n == 7)
{
++$i;
}
}
// PLANNING HORAIRE
$hours = array();
$heures = Configuration::renvoyer_heures_debut_fin();
$arr_heures = explode('#',$heures->heures_debut_fin);
echo '<br /><br />';
echo '<br /><br />';
echo '$arr_heures : '.print_r($arr_heures);
echo '<br /><br />';
echo '<br /><br />';
$start = new \DateTime($arr_heures[0].':00');
echo '$start : '.print_r($start);
echo '<br /><br />';
echo '<br /><br />';
$end = new \DateTime($arr_heures[1].':00');
echo 'end : '. print_r($end);
echo '<br /><br />';
echo '<br /><br />';
$count = count($arr_heures);
if($count == 4)
{
$start_2 = new \DateTime($arr_heures[2].':00');
$end_2 = new \DateTime($arr_heures[3].':00');
}
print_r($start);
echo '<br /><br />';
echo '<br /><br />';
print_r($end);
echo '<br /><br />';
echo '<br /><br />';
while ($start <= $end)
{
$hours[] = $start->format('H\hi');
echo 'hoursssss >>>>> : '.print_r($hours);
echo '<br /><br />';echo '<br /><br />';
$intervalle = Configuration::renvoyer_intervalle();
$start->modify('+'.$intervalle->intervale.' min');
}
print_r($hours);
if($count == 4)
{
while ($start_2 <= $end_2)
{
$hours[] = $start_2->format('H\hi');
$intervalle = Configuration::renvoyer_intervalle();
$start_2->modify('+'.$intervalle->intervale.' min');
}
}
// TABLEAU FINAL
$html =
<<<HTML
<p id="moisCourant">{$months[$month]}</p>
<p id="anneeCourante">{$year}</p>
<table>
<tbody>
HTML;
print_r($data);
foreach ($data as $v)
{
$html .= '<tr><td> </td>';
foreach ($v as $date)
{
$day = ($date instanceof \DateTime)
? ucfirst($days[$date->format('N')]).' '.$date->format('d').' '.$months[$month]
: $date;
$html .= '<td class="nomsJours center">'.$day.'</td>';
$html .= '<td></td><td></td>';
}
$html .= '</tr>';
foreach ($hours as $h)
{
$html .= '<tr>';
$html .= '<td class="periodes">'.$h.'</td>';
foreach ($v as $date)
{
$id = ($date instanceof \DateTime) ? 'id='."{$date->format('Y-m-d')}-{$h}" : '';
//si je n'utilise pas substr il envoie 'id="2013-08-06-13h00"'
$nom_client = $this->getNameClient(substr($id,3));
if(isset ($nom_client->nom))
{
$html .= '<td '.$id.' class="td_rouge" ';
if(!empty($nom_client->commentaire))
{
//permet d'afficher le commentaire si c'est un admin ou le bon client
if($_SESSION['client']->statut == 1 || $nom_client->nom == $_SESSION['client']->nom)
{
$html .= 'abbr title="'.$nom_client->commentaire.'"';
}
}
$html .='>';
//si c'est un admin ou le client peut voir ses réservations
if($_SESSION['client']->statut == 1 || $nom_client->nom == $_SESSION['client']->nom)
{
$html.= $nom_client->nom.' '.$nom_client->prenom.' '.$nom_client->telephone;
if(!empty($nom_client->commentaire))
{
$html .= ' <img src="../images/email.png"/>';
}
}
$html .='</td>';
$html .= '<td class="td_supp_res"> ';
if($_SESSION['client']->statut == 1 || $nom_client->nom == $_SESSION['client']->nom)
{
$html.= '<img src="../images/supprimer_res.png" title="Supprimer ma réservation" class="btn_supp_res"/>';
}
$html .= '</td>';
$html .= '<td class="td_mod_comment">';
if($nom_client->nom == $_SESSION['client']->nom)
{
if(!empty($nom_client->commentaire))
{
$html .= ' <img src="../images/modifier_comment.png" class="img_mod_comment" title="Modifier ou supprimer votre commentaire"/>';
}
else
{
$html .= ' <img src="../images/ajouter_commentaire.png" class="img_ajout_comment" title="Ajouter un commentaire"/>';
}
}
$html .= '</td>';
}
else
{
if(strlen($id) > 0)
{
$html .= '<td '.$id.' class="conteneurCase td_vert"></td>';
}
$html .= '<td></td><td></td>';
}
}
$html .= '</tr>';
}
}
$html .= '</tbody></table>';
return $html;
}
public function getNameClient($id)
{
$conn = DB::getInstance();
$infos_reservation = new Manager_Reservations($conn);
$retour = $infos_reservation->getReservation($id);
//print_r($retour);
return $retour;
}
}
?>
Comme vous pouvez le voir, j'ai mis des print_r et des echos afin de déboger.
Le débogage me donne ceci :
[QUOTE]Array ( [1] => janvier [2] => février [3] => mars [4] => avril [5] => mai [6] => juin [7] => juillet [8] => août [9] => septembre [10] => octobre [11] => novembre [12] => décembre ) print_r de months vaut : 1
Array ( [1] => lundi [2] => mardi [3] => mercredi [4] => jeudi [5] => vendredi [6] => samedi [7] => dimanche ) print_r de days vaut : 1
$month vaut => 8
$year vaut => 2013
print_r du $date
DateTime Object ( => 2013-08-01 13:33:57 [timezone_type] => 3 => Europe/Berlin )
stdClass Object ( => 4,5 ) jours_reservables => 1
print_r($arr_jours) =>
Array ( [0] => 4 [1] => 5 )
$days_of_the_week vaut :
Array ( [0] => 4 [1] => 5 )
$date->format("n") => 8
Array ( [0] => 9:00 [1] => 12:00 [2] => 8:00 [3] => 11:00 ) $arr_heures : 1
DateTime Object ( => 2013-08-16 09:00:00 [timezone_type] => 3 => Europe/Berlin ) $start : 1
DateTime Object ( => 2013-08-16 12:00:00 [timezone_type] => 3 => Europe/Berlin ) end : 1
DateTime Object ( => 2013-08-16 09:00:00 [timezone_type] => 3 => Europe/Berlin )
DateTime Object ( => 2013-08-16 12:00:00 [timezone_type] => 3 => Europe/Berlin )
Array ( [0] => 09h00 ) hoursssss >>>>> : 1
Array ( [0] => 09h00 [1] => 09h30 ) hoursssss >>>>> : 1
Array ( [0] => 09h00 [1] => 09h30 [2] => 10h00 ) hoursssss >>>>> : 1
Array ( [0] => 09h00 [1] => 09h30 [2] => 10h00 [3] => 10h30 ) hoursssss >>>>> : 1
Array ( [0] => 09h00 [1] => 09h30 [2] => 10h00 [3] => 10h30 [4] => 11h00 ) hoursssss >>>>> : 1
Array ( [0] => 09h00 [1] => 09h30 [2] => 10h00 [3] => 10h30 [4] => 11h00 [5] => 11h30 ) hoursssss >>>>> : 1
Array ( [0] => 09h00 [1] => 09h30 [2] => 10h00 [3] => 10h30 [4] => 11h00 [5] => 11h30 [6] => 12h00 ) hoursssss >>>>> : 1
Array ( [0] => Array ( [0] => DateTime Object ( => 2013-08-01 13:33:57 [timezone_type] => 3 => Europe/Berlin ) [1] => DateTime Object ( => 2013-08-02 13:33:57 [timezone_type] => 3 => Europe/Berlin ) ) [1] => Array ( [0] => DateTime Object ( => 2013-08-08 13:33:57 [timezone_type] => 3 => Europe/Berlin ) [1] => DateTime Object ( => 2013-08-09 13:33:57 [timezone_type] => 3 => Europe/Berlin ) ) [2] => Array ( [0] => DateTime Object ( => 2013-08-15 13:33:57 [timezone_type] => 3 => Europe/Berlin ) [1] => DateTime Object ( => 2013-08-16 13:33:57 [timezone_type] => 3 => Europe/Berlin ) ) [3] => Array ( [0] => DateTime Object ( => 2013-08-22 13:33:57 [timezone_type] => 3 => Europe/Berlin ) [1] => DateTime Object ( => 2013-08-23 13:33:57 [timezone_type] => 3 => Europe/Berlin ) ) [4] => Array ( [0] => DateTime Object ( => 2013-08-29 13:33:57 [timezone_type] => 3 => Europe/Berlin ) [1] => DateTime Object ( => 2013-08-30 13:33:57 [timezone_type] => 3 [timezone] => Europe/Berlin ) ) )
[/QUOTE]
Le problème se trouve dans cette boucle :
while ($start <= $end)
{
$hours[] = $start->format('H\hi');
echo 'hoursssss >>>>> : '.print_r($hours);
echo '<br /><br />';echo '<br /><br />';
$intervalle = Configuration::renvoyer_intervalle();
$start->modify('+'.$intervalle->intervale.' min');
}
C'est ici que le code génère jeudi et vendredi.
Il faudrait je pense générer chaque jour choisi séparément, c'est là que je bloque.
[B]L'horaire est sous ce format : 9:00#12:00#8:00#11:00[/B]
Mille mercis d'aance pour votre aide.
bee