[ PHPXref.com ] [ Generated: Sun Jul 20 19:05:09 2008 ] [ onPHP 0.4.6 ]
[ Index ]     [ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/main/Base/ -> CalendarMonthWeekly.class.php (source)

   1  <?php
   2  /***************************************************************************
   3   *   Copyright (C) 2006 by Anton E. Lebedevich                             *
   4   *                                                                         *
   5   *   This program is free software; you can redistribute it and/or modify  *
   6   *   it under the terms of the GNU General Public License as published by  *
   7   *   the Free Software Foundation; either version 2 of the License, or     *
   8   *   (at your option) any later version.                                   *
   9   *                                                                         *
  10   ***************************************************************************/
  11  /* $Id: CalendarMonthWeekly.class.php 1684 2006-06-10 20:58:39Z voxus $ */
  12  
  13      /**
  14       * Calendar month representation splitted by weeks.
  15       *
  16       * @ingroup Calendar
  17      **/
  18      class CalendarMonthWeekly
  19      {
  20          private $monthRange    = null;
  21          private $fullRange    = null;
  22          private $fullLength    = null;
  23          
  24          private $weeks        = array();
  25          private $days        = array();
  26          
  27  		public function __construct(
  28              Timestamp $base, $weekStart = Timestamp::WEEKDAY_MONDAY
  29          )
  30          {
  31              $firstDayOfMonth = Timestamp::create(
  32                  $base->getYear().'-'.$base->getMonth().'-01'
  33              );
  34              
  35              $lastDayOfMonth    = Timestamp::create(
  36                  $base->getYear().'-'.$base->getMonth().'-'
  37                  .date('t', $base->toStamp()));
  38              
  39              $start = $firstDayOfMonth->getFirstDayOfWeek($weekStart);
  40              
  41              $end = $lastDayOfMonth->getLastDayOfWeek($weekStart);
  42              
  43              $this->monthRange = DateRange::create()->lazySet(
  44                  $firstDayOfMonth, $lastDayOfMonth
  45              );
  46              
  47              $this->fullRange = DateRange::create()->lazySet(
  48                  $start, $end
  49              );
  50              
  51              $rawDays = $this->fullRange->split();
  52              $this->fullLength = 0;
  53              
  54              foreach ($rawDays as $rawDay) {
  55                  $day = CalendarDay::create($rawDay->toStamp());
  56                  
  57                  if ($this->monthRange->contains($day))
  58                      $day->setOutside(false);
  59                  else 
  60                      $day->setOutside(true);
  61                      
  62                  $this->days[$day->toDate()] = $day;
  63                  
  64                  $weekNumber = floor($this->fullLength/7);
  65                  
  66                  if (!isset($this->weeks[$weekNumber]))
  67                      $this->weeks[$weekNumber] = CalendarWeek::create();
  68                  
  69                  $this->weeks[$weekNumber]->addDay($day);
  70                  ++$this->fullLength;
  71              }
  72              
  73              ++$this->fullLength;
  74          }
  75          
  76  		public static function create(
  77              Timestamp $base, $weekStart = Timestamp::WEEKDAY_MONDAY
  78          )
  79          {
  80              return new CalendarMonthWeekly($base, $weekStart);
  81          }
  82          
  83  		public function getWeeks()
  84          {
  85              return $this->weeks;
  86          }
  87          
  88  		public function getDays()
  89          {
  90              return $this->days;
  91          }
  92          
  93  		public function getFullRange()
  94          {
  95              return $this->fullRange;
  96          }
  97          
  98  		public function getFullLength()
  99          {
 100              return $this->fullLength;
 101          }
 102          
 103  		public function getMonthRange()
 104          {
 105              return $this->monthRange;
 106          }
 107          
 108  		public function setSelected(Timestamp $day)
 109          {
 110              if (!isset($this->days[$day->toDate()]))
 111                  throw new WrongArgumentException($day->toDate().' not in calendar');
 112              
 113              $this->days[$day->toDate()]->setSelected(true);
 114              
 115              return $this;
 116          }
 117          
 118  		public function getNextMonthBase()
 119          {
 120              return $this->monthRange->getEnd()->spawn('+1 day');
 121          }
 122  
 123  		public function getPrevMonthBase()
 124          {
 125              return $this->monthRange->getStart()->spawn('-1 day');
 126          }
 127          
 128  		public function getBase()
 129          {
 130              return $this->monthRange->getStart();
 131          }
 132      }
 133  ?>


[ Powered by PHPXref - Served by Debian GNU/Linux ]