Overview

Packages

  • Auth
  • Config
  • Controller
  • Date
  • Db
  • Feed
    • Abstract
    • Writers
  • File
    • Decorator
  • Form
    • Element
  • Image
  • Log
    • Writer
  • Net
    • Exception
  • None
  • PHP
  • PHPMailer
  • Session
  • Util
  • Validate
    • Validator
  • Zend
    • Registry

Classes

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