Overview

Namespaces

  • None
  • PHP
  • Pry
    • Auth
      • Interfaces
    • Config
    • Controller
    • Date
    • Db
    • Feed
      • Abstracts
      • Writers
    • File
      • Decorator
    • Form
      • Element
    • Image
    • Log
      • Writer
    • Net
      • Exception
    • Session
    • Util
    • Validate
      • Validator
    • View

Classes

  • Ferie
  • Weeks
  • Overview
  • Namespace
  • Class
  • Tree
  1: <?php
  2: 
  3: /**
  4:  * Pry Framework
  5:  *
  6:  * LICENSE
  7:  *
  8:  * This source file is subject to the new BSD license that is bundled
  9:  * with this package in the file LICENSE.txt.
 10:  * 
 11:  */
 12: 
 13: namespace Pry\Date;
 14: 
 15: use Pry\Date\Ferie;
 16: 
 17: /**
 18:  * Classe Weeks
 19:  *
 20:  * Class permettant la gestion d'un semainier
 21:  *
 22:  * @category Pry
 23:  * @package Date
 24:  * @version 1.1.1
 25:  * @author Olivier ROGER <oroger.fr>
 26:  *
 27:  */
 28: class Weeks
 29: {
 30: 
 31:     /**
 32:      * Mois dans laquelle la semaine se trouve
 33:      * @var string
 34:      */
 35:     public $mois;
 36: 
 37:     /**
 38:      * Jours de la semaine
 39:      * @var array
 40:      */
 41:     public $jours;
 42: 
 43:     /**
 44:      * Tableau des mois en français
 45:      * @var array
 46:      */
 47:     private $tabMois;
 48: 
 49:     /**
 50:      * Instance des jours fériés
 51:      * @var Date_Ferie
 52:      */
 53:     public $ferie;
 54: 
 55:     /**
 56:      * Année de la semaine
 57:      * @var int
 58:      */
 59:     private $annee;
 60: 
 61:     /**
 62:      * Numéro de semaine
 63:      * @var int
 64:      */
 65:     private $semaine;
 66: 
 67:     /**
 68:      * Timestamp des jour de la semaine
 69:      * @var array
 70:      */
 71:     private $daysOfWeek;
 72: 
 73:     /**
 74:      * Constructeur
 75:      * @param int $semaine Numéro de la semaine
 76:      * @param int $annee Années souhaité
 77:      */
 78:     public function __construct($semaine, $annee)
 79:     {
 80:         $this->jours = array('lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi', 'dimanche');
 81:         $this->tabMois = array('Janvier', 'Février', 'Mars', 'Avril', 'Mai', 'Juin', 'Juillet', 'Aout', 'Septembre', 'Octobre', 'Novembre', 'Décembre');
 82:         $this->ferie   = new Ferie($annee);
 83:         $this->semaine = intval($semaine);
 84:         $this->annee   = intval($annee);
 85:     }
 86: 
 87:     /**
 88:      * Retourne les limite Lundi et Dimanche pour une semaine donnée
 89:      *
 90:      * @return array
 91:      */
 92:     public function getBoundaries()
 93:     {
 94:         $dt = new \DateTime($this->annee . 'W' . sprintf('%02d', $this->semaine));
 95: 
 96:         $lundi    = (int) $dt->format('U');
 97:         $dt->modify('Sunday');
 98:         $dimanche = (int) $dt->format('U');
 99: 
100:         $this->daysOfWeek[0] = $lundi;
101:         $this->mois          = $this->tabMois[date("m", $this->daysOfWeek[0]) - 1];
102: 
103:         return array('lundi' => $lundi, 'dimanche' => $dimanche);
104:     }
105: 
106:     /**
107:      * Calcul les 7 jours de la semaine à partir du lundi trouvé.
108:      * getBoundaries doit avoir été appellé auparavant.
109:      *
110:      * @return array
111:      */
112:     public function computeDays()
113:     {
114:         if (empty($this->daysOfWeek))
115:             throw new \BadFunctionCallException('Use getBoundaries() first');
116:         for ($i = 1; $i < 7; $i++)
117:             $this->daysOfWeek[$i] = $this->daysOfWeek[$i - 1] + 86400;
118: 
119:         return $this->daysOfWeek;
120:     }
121: 
122:     /**
123:      * Calcul l'année et le numéro de semaine suivant/précédent
124:      *
125:      * @return array
126:      */
127:     public function computeNextPrev()
128:     {
129:         if ($this->semaine == 1)
130:         {
131:             $anneePrec   = $this->annee - 1;
132:             $semainePrec = date("W", $this->daysOfWeek[0] - 86400);
133: 
134:             $anneeSuiv   = $this->annee;
135:             $semaineSuiv = 2;
136:         }
137:         else if ($this->semaine == 52)
138:         {
139:             $anneePrec   = $this->annee;
140:             $semainePrec = 51;
141: 
142:             if (date("W", $this->daysOfWeek[6] + 86400) == 53)
143:             {
144:                 $anneeSuiv   = $this->annee;
145:                 $semaineSuiv = 53;
146:             }
147:             else
148:             {
149:                 $anneeSuiv   = $this->annee + 1;
150:                 $semaineSuiv = 1;
151:             }
152:         }
153:         elseif ($this->semaine == 53)
154:         {
155:             $anneePrec   = $this->annee;
156:             $semainePrec = 52;
157:             $anneeSuiv   = $this->annee + 1;
158:             $semaineSuiv = 1;
159:         }
160:         else
161:         {
162:             $anneePrec   = $anneeSuiv   = $this->annee;
163:             $semainePrec = $this->semaine - 1;
164:             $semaineSuiv = $this->semaine + 1;
165:         }
166: 
167:         return array('annee' => array('next' => $anneeSuiv, 'prev' => $anneePrec),
168:             'semaine' => array('next' => $semaineSuiv, 'prev' => $semainePrec));
169:     }
170: 
171:     /**
172:      * Retourne les dates des jours sous format mysql
173:      * 
174:      * @return array
175:      */
176:     public function getMysqlDays()
177:     {
178:         $total     = count($this->daysOfWeek);
179:         $mysqlDays = array();
180: 
181:         for ($i = 0; $i < $total; $i++)
182:             $mysqlDays[$i] = date("Y-m-d", $this->daysOfWeek[$i]);
183: 
184:         return $mysqlDays;
185:     }
186: 
187: }
188: 
189: ?>
Pry API documentation generated by ApiGen 2.8.0