IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

EDI, CMS, Outils, Scripts et API PHP Discussion :

[Calendrier] Créer un planning


Sujet :

EDI, CMS, Outils, Scripts et API PHP

  1. #1
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Janvier 2008
    Messages
    67
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2008
    Messages : 67
    Points : 28
    Points
    28
    Par défaut [Calendrier] Créer un planning
    Bonsoir à tous.

    j'ai lu et vu pas mal de tutoriel concernant les calendriers.
    je me suis dis que ça serait une bonne base pour la création d'un planning qui me permettrait de gérer le planning des personnes.

    j'ai donc fait ceci : ( ma page d'index )

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    <!doctype html>
    <html>
        <head>
        <meta charset="UTF-8">
        <title>planning</title>
        <link rel="stylesheet" type="text/css" href="style.css" />
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
        </head>
     
        <body>
            <?php
            require('date.php');
            $date = new Date();
            $year = date('Y');
            $dates = $date->getAll($year);  
            ?>
     
            <div class="periods">
                <div class="year"><?php echo $year; ?></div> 
                    <div class="months">
                        <ul>
                            <?php foreach ($date->months  as $id=>$m): ?>
                                <li><a href="#" id="linkMonth<?php echo $id+1; ?>"><?php echo utf8_encode(substr(utf8_decode($m),0,3));?></a></li>                
                            <?php endforeach; ?>
                        </ul>
                    </div>
                    <?php $dates = current($dates); ?>
                    <?php foreach ($dates as $m=>$days): ?>
     
                        <div class="month" id="month<?php echo $m; ?>">
                        <table>
                            <thead>
                                <tr>
                                    <?php foreach ($date->days as $d) : ?>
                                        <th><?php echo substr($d,0,3); ?></th>
                                    <?php endforeach; ?>
                                </tr>
                            </thead>
     
                            <tbody>
                                <tr>
                                    <?php foreach ($days as $d=>$w) : ?>
                                        <td><?php echo $d; ?></td>
                                    <?php endforeach; ?>
                                </tr>
                            </tbody>
                        </table>
                        </div> 
                    <?php endforeach; ?>
     
            </div>
        <pre><?php print_r($dates); ?></pre>
     
    </body>
    </html>
    ma page date.php :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    <?php
    class Date{
    	var $days = array ('Lundi','Mardi','Mercredi','Jeudi','Vendredi','Samedi','Dimanche');
    	var $months = array ('Janvier','Février','Mars','Avril','Mai','Juin','Juillet','Aout','Septembre','Octobre','Novembre','Décembre');
    	function getAll($year){
    		$r = array();
    		$date = new DateTime($year.'-01-01');
    		while ($date->format('Y') <= $year){
    		//Ce que je veux obtenir => $r[ANNEE][MOIS][JOUR] = JOUR DE LA SEMAINE
    		$y = $date->format('Y');
    		$m = $date->format('n');
    		$d = $date->format('j');
    		$w = str_replace('0','7',$date->format('w'));
    		$r[$y][$m][$d] = $w;
    		$date->add(new DateInterval('P1D'));	
    		}
    		return $r;
     
    	} 
    }
    si je continue ainsi j'arriverais à faire un ......calendrier mais comme je veux faire un planning j'ai besoin d'afficher les nom des jours sous les les numéros de jours.

    je pense que je dois faire une boucle à cette endroit de mon code :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    <thead>
                                <tr>
                                    <?php foreach ($date->days as $d) : ?>
     
                                        <th><?php echo substr($d,0,3); ?></th>
     
                                      <?php endforeach; ?>
                                </tr>
                            </thead>
    mais pour l'instant toutes les boucles que j'ai écrites boucle à l’infinie et font planter mon navigateur car je n'arrive pas à récupérer le numéro des jours ( enfin je pense que c'est ce qu'il faut faire. par exemple dire qu'il faut afficher les noms des jours tant que le mois n'est pas finis. )

    merci de votre aide.

  2. #2
    Modérateur
    Avatar de sabotage
    Homme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    29 208
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juillet 2005
    Messages : 29 208
    Points : 44 155
    Points
    44 155
    Par défaut
    Je ne sais pas comment tu fais des boucles infinies avec des foreach toi

    Grossierement, un exemple
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    <?php
    class Date{
    	var $days = array (1=>'Lundi',2=>'Mardi',3=>'Mercredi',4=>'Jeudi',5=>'Vendredi',6=>'Samedi',7=>'Dimanche');
    	var $months = array ('Janvier','Février','Mars','Avril','Mai','Juin','Juillet','Août','Septembre','Octobre','Novembre','Décembre');
    	function getAll($year){
    		$r = array();
    		$date = new DateTime($year.'-01-01');
    		while ($date->format('Y') <= $year){
    		//Ce que je veux obtenir => $r[ANNEE][MOIS][JOUR] = JOUR DE LA SEMAINE
    		$y = $date->format('Y');
    		$m = $date->format('n');
    		$d = $date->format('j');
    		$w = $date->format('N');
    		$r[$y][$m][$d] = $w;
    		$date->add(new DateInterval('P1D'));	
    		}
    		return $r;
     	}
     
    	function dayofweek($n) {
    		return substr($this->days[$n],0, 3);		
    	}
    }
     
    $objDate = new date;
     
    $fullyear = $objDate->getAll(2016);
     
    $year_line = '';
    $month_line = '';
    $day_line1 = '';
    $day_line2 = '';
    $ndays = 0;
     
    foreach ($fullyear as $year=>$months) {
    	foreach ($months as $month=>$days) {
    		$month_line .= '<td colspan="' . count($days) . '">'. $month .'</td>';
    		foreach ($days as $day=>$n) {
    			$day_line1 .= '<td>' . $n . '</td>';
    			$day_line2 .= '<td>' . $objDate->dayofweek($n) . '</td>';
    			$ndays++;
    		}
    	}
    	$year_line .= '<td colspan="' . $ndays . '">' . $year . '</td>';
    }
    ?>
    <table border="1">
    	<tr><?php echo $year_line; ?></tr>
    	<tr><?php echo $month_line; ?></tr>
    	<tr><?php echo $day_line1; ?></tr>
    	<tr><?php echo $day_line2; ?></tr>
    </table>
    Au passage, utilise 'N' pour avoir le dimanche en 7.
    N'oubliez pas de consulter les FAQ PHP et les cours et tutoriels PHP

  3. #3
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Janvier 2008
    Messages
    67
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2008
    Messages : 67
    Points : 28
    Points
    28
    Par défaut
    en gros en faisant comme j'ai fait j’obtiens un tableau du genre :

    lun mar mer jeu ven sam dim
    1 2 3 4 5 6 7
    8 9 10 11 12 13 14

    etc.....

    je cherche à obtenir ça :

    lun mar mer jeu ven sam dim lun mar mer jeu ven sam dim
    1 2 3 4 5 6 7 8 9 10 11 12 13 14

    etc.....

    pour tenté d'obtenir ce que je veux j'ai donc une boucle foreach qui parcours mon tableau

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    <thead>
                                <tr>
                                    <?php foreach ($date->days as $d) : ?>
     
                                        <th><?php echo substr($d,0,3); ?></th>
     
                                      <?php endforeach; ?>
                                </tr>
                            </thead>
    dans cette boucle foreach j'ai tenté de faire une boucle while en tentant d' afficher les noms des jours tant que le mois n'est pas finis et c'est la que la boucle infinis fait planté mon navigateur !!!!

    en tout cas merci de ton aide c'est vraiment sympa !

  4. #4
    Modérateur
    Avatar de sabotage
    Homme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    29 208
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juillet 2005
    Messages : 29 208
    Points : 44 155
    Points
    44 155
    Par défaut
    Tu aurais pu prendre un peu de temps pour voir ce que faisais precisemment mon code et comment l'adapter :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    $day_line1 .= '<td>' . $objDate->dayofweek($n) . '</td>';
    $day_line2 .= '<td>' . $ndays . '</td>';
    N'oubliez pas de consulter les FAQ PHP et les cours et tutoriels PHP

  5. #5
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Janvier 2008
    Messages
    67
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2008
    Messages : 67
    Points : 28
    Points
    28
    Par défaut
    oui oui je suis deja dessus....juste je t'expliquais mon histoire de boucle voila tout !!!!!

    je te tiens au courant demain si j'arrive à mes fins....je suis un vieux débutant donc le temps que je comprenne toutes les subtilités

    mais en tout cas merci pour ton aide !

  6. #6
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Janvier 2008
    Messages
    67
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2008
    Messages : 67
    Points : 28
    Points
    28
    Par défaut
    hello à tous.

    bon du coup j'ai fait ça :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    <?php
    setlocale(LC_ALL, 'FR_fr');
    if(empty($_GET)){
    	$firstDay = date('Y-m-d', strtotime('first day of this month'));
    	$lastDay = date('Y-m-d', strtotime('last day of this month'));
    	$nextYear = date('Y-m-d', strtotime('+ 1 year'));
    	$prevYear = date('Y-m-d', strtotime('- 1 year'));
    	$currentYear = date('Y');
    }
    else{
    	$firstDay = date('Y-m-01', strtotime($_GET['month']));
    	$lastDay = date('Y-m-t', strtotime($_GET['month']));
    	$nextYear = date('Y-m-d', strtotime($_GET['month'].' + 1 year'));
    	$prevYear = date('Y-m-d', strtotime($_GET['month'].' - 1 year'));
    	$currentYear = date('Y', strtotime($_GET['month']));
    }
     
    //la variable $nextMonth = le mois suivant au mois en court
    $nextMonth=DateTime::createFromFormat('Y-m-d',$firstDay)->add(new DateInterval('P1M'))->format('Y-m-d');
    //la variable $prevMonth = le mois precedant au mois en court
    $prevMonth=DateTime::createFromFormat('Y-m-d',$firstDay)->sub(new DateInterval('P1M'))->format('Y-m-d');
     
    //on créer un tableau qui va récupérer tout les jours du mois
    $datesMonth=array();
     
    //on definit les dates du mois en court qui seront stockées dans la variable $period On utile DatePeriod pour définir une période qui va du début du mois ($firstDay) au dernier jour du mois ($lastDay) et ce jour par jour.
    $period=new DatePeriod(
    		new DateTime($firstDay),
    		new dateInterval('P1D'),
    		(new DateTime($lastDay))->modify('+ 1 day'));
     
     
    //on recupere toute les dates dans un tableau
    foreach($period as $p){
    	array_push($datesMonth,$p->format('Y-m-d'));
    }
     
     
    //echo $firstDay.'</br>'.$lastDay.'</br>'.$nextYear.'</br>'.$prevYear.'</br>';
    //echo $nextMonth.'</br>'.$prevMonth.'</br>';
    ?>
     
     
    <!doctype html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>planning</title>
    <link rel="stylesheet" type="text/css" href="style.css" />
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
    </head>
     
    <body>
    <div id="main">
    	<div class="row">
     
        	<h3><?=strftime('%B',strtotime($firstDay)).'&nbsp;'.$currentYear;?></h3>
     
        	 <a href="index.php?month=<?=$prevYear;?>" class="btn btn-warning"> << <?php echo date('Y',strtotime($prevYear));?></a>&nbsp;
             <a href="index.php?month=<?=$prevMonth;?>" class="btn"> << <?php echo strftime('%B',strtotime($prevMonth));?></a>&nbsp;
     
             <a href="index.php?month=<?=$nextYear;?>" class="btn btn-warning">  <?php echo date('Y',strtotime($nextYear));?>>></a>&nbsp;
             <a href="index.php?month=<?=$nextMonth;?>" class="btn"><?php echo strftime('%B',strtotime($nextMonth));?>>></a>&nbsp;
     
        </div>
     
        <table class="tableau">
        	<thead>
            	<tr>
                	<?php foreach ($datesMonth as $d):?>
                    	<th><?=strftime('%a',strtotime($d));?></th>
                    <?php endforeach ?>
                </tr>           
            </thead>
            <tbody>
            	<tr>
                	<?php  foreach ($datesMonth as $d):?>
                    	<td><?=date('d',strtotime($d));?></td>
                    <?php endforeach ?>
                </tr>
            </tbody>
        </table> 	
     
    	</div> <!-- fin de main -->
     
    </body>
    </html>
    ça marche comme il faut.
    par contre au niveau de la structure du code c'est pas trop propre donc j'aurais besoin d'un coup de main pour créer des objets.(j'y connais pas grand chose !!!! )

    j'ai donc fait un test et regardé et lu tout plein de tutoriel et j'ai fait un test avec ça :

    MA CLASSE
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    <?php
    class calendrier{
    		//on creer un tableau contenant les élement de la date.
    		//$periods=array();
     
    		public $firstDay;
    		public $lastDay;
    		public $nextYear;
    		public $prevYear;
    		public $nextMonth;
    		public $prevMonth;
    		public $currentYear;
     
    		public function period(){
     
    			return"($this->firstDay
    				  $this->lastDay
    				  $this->nextMonth
    				  $this->prevMonth
    				  $this->nextYear
    				  $this->prevYear)";
     
    		}
    }
    ?>
    LA PAGE QUI RÉCUPÈRE ET AFFICHE MON OBJET
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    <?php
    require('date.php');
    $maPeriod=new calendrier();
    $maPeriod->firstDay = date('Y-m-d', strtotime('first day of this month'));
     
    print "Date du 1er jour : " .$maPeriod->period() . "\n";
    ?>
    Est-ce que je dois mettre mon contrôle ( début du code ) dans ma classe et si oui comment procéder ?
    merci de votre aide.

  7. #7
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Janvier 2008
    Messages
    67
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2008
    Messages : 67
    Points : 28
    Points
    28
    Par défaut
    bonjour je reviens vers vous cars je pense avoir avancé un peu.

    donc voici le code de ma classe Calendrier :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    <?php
    class Calendrier{
    	public $firstDay;
    	public $lastDay;
    	public $nextYear;
    	public $prevyear;
    	public $currentYear;
    	public $nextMonth;
    	public $prevMonth;
    	public $datesMonth=array();
     
     
     
     
     
    public function calendar(){
    		 $firstDay = date('Y-m-d',strtotime('first day of this month'));
    		 $lastDay = date('Y-m-d',strtotime('last day of this month'));
    		 $nextYear = date('Y-m-d',strtotime('+1 year'));
    		 $prevYear = date('Y-m-d',strtotime('-1 year'));
    		 $currentYear = date('Y');
     
    		 $nextMonth = DateTime::createFromFormat('Y-m-d',$firstDay)->add(new DateInterval('P1M'))->format('Y-m-d');
     
    		$prevMonth = DateTime::createFromFormat('Y-m-d',$firstDay)->sub(new DateInterval('P1M'))->format('Y-m-d');
     
    		$period=new DatePeriod(
    			new DateTime($firstDay),
    			new dateInterval('P1D'),
    			(new DateTime($lastDay))->modify('+ 1 day'));
     
    			foreach($period as $p){
    		array_push($datesMonth,$p->format('Y-m-d'));
    		}
    	}
     
    }
    quand je fais un print_r de mon tableau$datesMonth dans ma classe je vois bien mon tableau.

    maintenant je veux afficher le resultat de ma classe sur ma page index.php
    j'ai donc fait un require de ma page celendrier.php et j'ai ensuite implémenté ma classe en faisant ceci :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    $calendar = new Calendrier ();
    comment je peux faire apparaitre ce tableau ? j'ai tenté un
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    echo $calendrier->calendar($dateMonth);
    mais c'est pas ça.
    j'ai essayé d'afficher le tableau avec pleins d'autres essaies mais rien non plus.
    un peu d'aide serait le bienvenue.
    merci d'avance de votre aide !

  8. #8
    Modérateur
    Avatar de sabotage
    Homme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    29 208
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juillet 2005
    Messages : 29 208
    Points : 44 155
    Points
    44 155
    Par défaut
    Il manque un return sur ta fonction calendar.
    N'oubliez pas de consulter les FAQ PHP et les cours et tutoriels PHP

  9. #9
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Janvier 2008
    Messages
    67
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2008
    Messages : 67
    Points : 28
    Points
    28
    Par défaut
    Tout d'abord merci sabotage pour ton aide !

    alors je suis désolé mais j'y comprends pas grand chose.....

    je me suis aperçu qu'il fallait faire un devant toutes mes variables définis dans
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    public function calendar()
    ( je ne suis pas sur que ça soit bon car je pensais qu'il fallait simplement définir les variables et les appler dans la page d'index.php.... )
    j'ai donc fait un dans ma classe Calendrier ce qui donne ça pour ma classe :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    <?php
    class Calendrier{
    	public $firstDay;
    	public $lastDay;
    	public $nextYear;
    	public $prevyear;
    	public $currentYear;
    	public $nextMonth;
    	public $prevMonth;
    	public $datesMonth=array();
     
     
     
     
     
    public function calendar(){
    		echo $firstDay = date('Y-m-d',strtotime('first day of this month'));
    		echo $lastDay = date('Y-m-d',strtotime('last day of this month'));
    		echo $nextYear = date('Y-m-d',strtotime('+1 year'));
    		echo $prevYear = date('Y-m-d',strtotime('-1 year'));
    		echo $currentYear = date('Y');
     
    		echo $nextMonth = DateTime::createFromFormat('Y-m-d',$firstDay)->add(new DateInterval('P1M'))->format('Y-m-d');
     
    		echo $prevMonth = DateTime::createFromFormat('Y-m-d',$firstDay)->sub(new DateInterval('P1M'))->format('Y-m-d');
     
    		$period=new DatePeriod(
    			new DateTime($firstDay),
    			new dateInterval('P1D'),
    			(new DateTime($lastDay))->modify('+ 1 day'));
     
    			foreach($period as $p){
    		array_push($datesMonth,$p->format('Y-m-d'));
    		}
    		return calendar();
    	}
     
    }
    dans ma page index.php j'ai fait ça :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    <?php
    require 'class/calendrier.php';
    $calendrier = new Calendrier();
    ?>
     
     
    <!doctype html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>calendrier</title>
    <link rel="stylesheet" type="text/css" href="style.css" />
    </head>
     
    <body>
    <div id="main">
    	<div class="row">
    	<h3><?php echo $calendrier->currentYear; ?>&nbsp;</h3>	
    	</div>
    	<div class="tableau">
    		<thead>
    			<tr>
     
    					<th>
     
    					</th>
    			</tr>
    		</thead>
    	</div>
    </div>
    </body>
    </html
    alors si je fait un vardump() de ma classe je vois bien tout mes éléments.
    dans le <H3> je tente d'afficher l'année courante que j'ai définit mais rien.....et bizarrement si je tente d'afficher le mois en cours en faisant ça :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <?php echo strftime('%B',strtotime($calendrier->firstDay)); ?>
    et bien ça m'affiche bien le mois mais le mois de janvier......

    qu'est que je ne fais pas qui fonctionne en procédural mais pas avec les objets ?

  10. #10
    Modérateur
    Avatar de sabotage
    Homme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    29 208
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juillet 2005
    Messages : 29 208
    Points : 44 155
    Points
    44 155
    Par défaut
    Avant de te lancer des les classes, il faut que tu apprennes les bases des fonctions.

    Soit ta fonction produit directement un affichage :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    function afficheToto() {
       echo 'toto';
    }
    Soit elle produit des données que tu affiches ensuite :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    function getToto() {
       return 'toto';
    }
     
    echo getToto();
    Elle peut évidemment faire les deux :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    function getToto() {
       echo 'toto';
       return TRUE;
    }
     
     
    if  (getToto()) {
       echo 'la fonction a affiché toto';
    }
    N'oubliez pas de consulter les FAQ PHP et les cours et tutoriels PHP

  11. #11
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Janvier 2008
    Messages
    67
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2008
    Messages : 67
    Points : 28
    Points
    28
    Par défaut
    Merci Sabotage.

    je retourne m'instruire et je reviens dès que j'ai compris montrer le résultat. ( si ça peut servir à d'autres ! )

    merci encore !

  12. #12
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Janvier 2008
    Messages
    67
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2008
    Messages : 67
    Points : 28
    Points
    28
    Par défaut
    Hello tout le monde.
    je reviens vers vous pour vous montrer se que j'ai produit. ça fonctionne ....presque

    alors j'ai refais ma classe que voici :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    <?php
    class Calendrier{
    	private $firstDay;
    	private $lastDay;
    	private $nextYear;
    	private $prevYear;
    	private $currentYear;
    	private $nextMonth;
    	private $prevMonth;
    	private $datesMonth=array();
     
     
    public function __construct(){
    	$this->firstDay = date('Y-m-d', strtotime('first day of this month'));
    	$this->lastDay = date('Y-m-d',strtotime('last day of this month'));
    	$this->nextYear = date('Y-m-d',strtotime('+1 year'));
    	$this->prevYear = date('Y-m-d',strtotime('-1 year'));
    	$this->nextMonth =  DateTime::createFromFormat('Y-m-d',$this->firstDay)->add(new DateInterval('P1M'))->format('Y-m-d');
    	$this->prevMonth = DateTime::createFromFormat('Y-m-d',$this->firstDay)->sub(new DateInterval('P1M'))->format('Y-m-d');
    	$this->currentYear = date('Y');
    	$this->datesMonth=array();
    }			 
     
    public function afficheMois(){
    	echo strftime('%B',strtotime($this->firstDay));
    }
     
    public function afficheAnnee(){
    	echo $this->currentYear;
    }
     
    public function afficheAnneePrecedent(){
    	echo date('Y',strtotime($this->prevYear));
    }
     
    public function afficheMoisPrecedent(){
    	echo strftime('%B',strtotime($this->prevMonth));
    }
     
    public function afficheAnneeSuivant(){
    	echo date('Y',strtotime($this->nextYear));
    }
     
    public function afficheMoisSuivant(){
    	echo strftime('%B',strtotime($this->nextMonth));
    }	
     
    public function calendar(){	
     
    		$period=new DatePeriod(
    			new DateTime($this->firstDay),
    			new dateInterval('P1D'),
    			(new DateTime($this->lastDay))->modify('+ 1 day'));
     
    			foreach($period as $p){
    		array_push($this->datesMonth,$p->format('Y-m-d'));
    		}
    		return $this->datesMonth;
    	}
     
    }
    et voici ma page d'affichage index.php :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    <?php
    setlocale(LC_ALL, 'FR_fr');
    require 'class/calendrier.php';
    $calendrier = new Calendrier();
    /*
    echo '<pre>';
    print_r($calendrier->calendar());
    echo '</pre>';
    */
    ?><!doctype html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>calendrier</title>
    <link rel="stylesheet" type="text/css" href="style.css" />
    </head>
     
    <body>
    <div id="main">
    	<div class="row">
    	<h3><?= $calendrier->afficheMois();?> &nbsp;<?= $calendrier->afficheAnnee();?></h3>
     
    	<a href="index.php?month=<?=$calendrier->afficheAnneePrecedent();?>" class="btn btn-warning"> << <?php echo $calendrier->afficheAnneePrecedent();?></a>
     
    	&nbsp;
     
    	<a href="index.php?month=<?= $calendrier->afficheMoisPrecedent();?>" class="btn"> <<  <?= $calendrier->afficheMoisPrecedent();?></a>
     
    	&nbsp;&nbsp;&nbsp;&nbsp;
     
    	<a href="index.php?month=<?=$calendrier->afficheAnneeSuivant();?>" class="btn btn-warning"> >> <?php echo $calendrier->afficheAnneeSuivant();?></a>
     
    	&nbsp;
     
    	<a href="index.php?month=<?= $calendrier->afficheMoisSuivant();?>" class="btn"> >>  <?= $calendrier->afficheMoisSuivant();?></a>
     
    	</div>
    	<table class="tableau">
    		<thead>
    			<tr>
    				<?php foreach($calendrier->calendar()as $d):?>
    				<th><?=strftime('%a',strtotime($d));?></th>
    				<?php endforeach ?>
    			</tr>
    		</thead>
    		<tbody>
    			<tr>
    				<?php foreach($calendrier->calendar() as $d):?>
    				<td><?=date('d',strtotime($d));?></td>
    				<?php endforeach ?>
    			</tr>
    		</tbody>
    	</table>
     
    </div>
    </body>
    </html
    bon quand je dis ça marche presque c'est par ce que mon tableau avec les chiffres des jours se répètent sur 2 mois......mais je pense que c'est par ce que dans ma classe je fais un :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    return $this->datesMonth;
    alors que je devrais certainement faire ça :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    foreach($period as $p){
    		$mois=array_push($this->datesMonth,$p->format('Y-m-d'));
    		}
    		return $mois;

  13. #13
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Janvier 2008
    Messages
    67
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2008
    Messages : 67
    Points : 28
    Points
    28
    Par défaut
    bon et bien après avoir passé des heure à me casser les neurones (enfin ceux qui me restent.....) j'ai enfin trouvé la solution !!!!!!!
    il fallait que je créé deux variables distinctes qui sont égales à mon tableau $datesMonth.

    donc voici ma solution dites moi si ça vous parait correcte.

    Ma classe calendrier.php
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    <?php
    class Calendrier{
    	private $firstDay;
    	private $lastDay;
    	private $nextYear;
    	private $prevYear;
    	private $currentYear;
    	private $nextMonth;
    	private $prevMonth;
    	private $datesMonth;
    	private $nomJour;
    	private $numeroJour;
     
    public function __construct(){
    	$this->firstDay = date('Y-m-d', strtotime('first day of this month'));
    	$this->lastDay = date('Y-m-d',strtotime('last day of this month'));
    	$this->nextYear = date('Y-m-d',strtotime('+1 year'));
    	$this->prevYear = date('Y-m-d',strtotime('-1 year'));
    	$this->nextMonth =  DateTime::createFromFormat('Y-m-d',$this->firstDay)->add(new DateInterval('P1M'))->format('Y-m-d');
    	$this->prevMonth = DateTime::createFromFormat('Y-m-d',$this->firstDay)->sub(new DateInterval('P1M'))->format('Y-m-d');
    	$this->currentYear = date('Y');
    	$this->datesMonth=array();
    	$this->nomJour = $this->datesMonth;
    	$this->numeroJour = $this->datesMonth;
    }			 
     
    public function afficheMois(){
    	echo strftime('%B',strtotime($this->firstDay));
    }
     
    public function afficheAnnee(){
    	echo $this->currentYear;
    }
     
    public function afficheAnneePrecedent(){
    	echo date('Y',strtotime($this->prevYear));
    }
     
    public function afficheMoisPrecedent(){
    	echo strftime('%B',strtotime($this->prevMonth));
    }
     
    public function afficheAnneeSuivant(){
    	echo date('Y',strtotime($this->nextYear));
    }
     
    public function afficheMoisSuivant(){
    	echo strftime('%B',strtotime($this->nextMonth));
    }	
     
     
     
    public function afiicheNomJour(){	
     
    		$period=new DatePeriod(
    			new DateTime($this->firstDay),
    			new dateInterval('P1D'),
    			(new DateTime($this->lastDay))->modify('+ 1 day'));
     
    			foreach($period as $p){
    			array_push($this->nomJour,$p->format('Y-m-d'));
    		}
     
    			foreach ($this->nomJour as $d){
                    	echo '<th>'. strftime('%a',strtotime($d)).'</th>';
     
                    }
    	return $this->nomJour;
    	}
     
    	public function afiicheNumeroJour(){	
     
    		$period=new DatePeriod(
    			new DateTime($this->firstDay),
    			new dateInterval('P1D'),
    			(new DateTime($this->lastDay))->modify('+ 1 day'));
     
    			foreach($period as $p){
    			array_push($this->numeroJour,$p->format('Y-m-d'));
    		}
     
    			foreach ($this->numeroJour as $d){
                    	echo '<td>'.date('d',strtotime($d)).'</td>';
     
                    }
    	return $this->numeroJour;
    	}
    }
    Ma page index.php
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    <?php
    setlocale(LC_ALL, 'FR_fr');
    require 'class/calendrier.php';
    $calendrier = new Calendrier();
    /*
    echo '<pre>';
    print_r($calendrier->calendar());
    echo '</pre>';
    */
    ?><!doctype html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>calendrier</title>
    <link rel="stylesheet" type="text/css" href="style.css" />
    </head>
     
    <body>
    <div id="main">
    	<div class="row">
    	<h3><?= $calendrier->afficheMois();?> &nbsp;<?= $calendrier->afficheAnnee();?></h3>
     
    	<a href="index.php?month=<?=$calendrier->afficheAnneePrecedent();?>" class="btn btn-warning"> << <?php echo $calendrier->afficheAnneePrecedent();?></a>
     
    	&nbsp;
     
    	<a href="index.php?month=<?= $calendrier->afficheMoisPrecedent();?>" class="btn"> <<  <?= $calendrier->afficheMoisPrecedent();?></a>
     
    	&nbsp;&nbsp;&nbsp;&nbsp;
     
    	<a href="index.php?month=<?=$calendrier->afficheAnneeSuivant();?>" class="btn btn-warning"> >> <?php echo $calendrier->afficheAnneeSuivant();?></a>
     
    	&nbsp;
     
    	<a href="index.php?month=<?= $calendrier->afficheMoisSuivant();?>" class="btn"> >>  <?= $calendrier->afficheMoisSuivant();?></a>
     
    	</div>
    	<table class="tableau">
    		<thead>
    			<tr>
    				<?php $calendrier->afiicheNomJour();?> 
     
    			</tr>
    		</thead>
     
    		<tbody>	
    			<tr>
    				<?php $calendrier->afiicheNumeroJour();?>
                </tr>
    		</tbody>
    	</table>
     
    </div>
    </body>
    </html
    il ne me reste plus qu'a mettre mon teste qui "teste si ma variable globale test est vide ou non !!!! ( pour passer d'une date à l'autre !
    je laisse ce post ouvert jusqu'en 2017 pour vous laisser intervenir ( si ça ne gene pas les modos bien sur ! )

    merci encore de votre aide !

Discussions similaires

  1. Réponses: 19
    Dernier message: 28/11/2007, 00h54
  2. calendrier au second plan
    Par RdO45 dans le forum Servlets/JSP
    Réponses: 2
    Dernier message: 26/11/2007, 18h09
  3. Comment grouper et créer un plan en VBA Excel ?
    Par vacknov dans le forum Macros et VBA Excel
    Réponses: 3
    Dernier message: 24/11/2007, 08h00
  4. Créer un planning sur access...
    Par SpyesX dans le forum Access
    Réponses: 2
    Dernier message: 05/11/2005, 09h33
  5. grouper/créer un plan sous Excel
    Par EFCAugure dans le forum API, COM et SDKs
    Réponses: 6
    Dernier message: 06/10/2004, 17h46

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo