493 |
ddelon |
1 |
<?php
|
|
|
2 |
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
|
|
3 |
//
|
|
|
4 |
// +----------------------------------------------------------------------+
|
|
|
5 |
// | PHP Version 4 |
|
|
|
6 |
// +----------------------------------------------------------------------+
|
|
|
7 |
// | Copyright (c) 1997-2002 The PHP Group |
|
|
|
8 |
// +----------------------------------------------------------------------+
|
|
|
9 |
// | This source file is subject to version 2.02 of the PHP license, |
|
|
|
10 |
// | that is bundled with this package in the file LICENSE, and is |
|
|
|
11 |
// | available at through the world-wide-web at |
|
|
|
12 |
// | http://www.php.net/license/3_0.txt. |
|
|
|
13 |
// | If you did not receive a copy of the PHP license and are unable to |
|
|
|
14 |
// | obtain it through the world-wide-web, please send a note to |
|
|
|
15 |
// | license@php.net so we can mail you a copy immediately. |
|
|
|
16 |
// +----------------------------------------------------------------------+
|
|
|
17 |
// | Authors: Harry Fuecks <hfuecks@phppatterns.com> |
|
|
|
18 |
// +----------------------------------------------------------------------+
|
|
|
19 |
//
|
|
|
20 |
// $Id: Weekdays.php,v 1.1 2005-09-30 14:58:00 ddelon Exp $
|
|
|
21 |
//
|
|
|
22 |
/**
|
|
|
23 |
* @package Calendar
|
|
|
24 |
* @version $Id: Weekdays.php,v 1.1 2005-09-30 14:58:00 ddelon Exp $
|
|
|
25 |
*/
|
|
|
26 |
|
|
|
27 |
/**
|
|
|
28 |
* Allows Calendar include path to be redefined
|
|
|
29 |
* @ignore
|
|
|
30 |
*/
|
|
|
31 |
if (!defined('CALENDAR_ROOT')) {
|
|
|
32 |
define('CALENDAR_ROOT', 'Calendar'.DIRECTORY_SEPARATOR);
|
|
|
33 |
}
|
|
|
34 |
|
|
|
35 |
/**
|
|
|
36 |
* Load Calendar base class
|
|
|
37 |
*/
|
|
|
38 |
require_once CALENDAR_ROOT.'Calendar.php';
|
|
|
39 |
|
|
|
40 |
/**
|
|
|
41 |
* Load base month
|
|
|
42 |
*/
|
|
|
43 |
require_once CALENDAR_ROOT.'Month.php';
|
|
|
44 |
|
|
|
45 |
/**
|
|
|
46 |
* Represents a Month and builds Days in tabular form<br>
|
|
|
47 |
* <code>
|
|
|
48 |
* require_once 'Calendar'.DIRECTORY_SEPARATOR.'Month'.DIRECTORY_SEPARATOR.'Weekdays.php';
|
|
|
49 |
* $Month = & new Calendar_Month_Weekdays(2003, 10); // Oct 2003
|
|
|
50 |
* $Month->build(); // Build Calendar_Day objects
|
|
|
51 |
* while ($Day = & $Month->fetch()) {
|
|
|
52 |
* if ($Day->isFirst()) {
|
|
|
53 |
* echo '<tr>';
|
|
|
54 |
* }
|
|
|
55 |
* if ($Day->isEmpty()) {
|
|
|
56 |
* echo '<td> </td>';
|
|
|
57 |
* } else {
|
|
|
58 |
* echo '<td>'.$Day->thisDay().'</td>';
|
|
|
59 |
* }
|
|
|
60 |
* if ($Day->isLast()) {
|
|
|
61 |
* echo '</tr>';
|
|
|
62 |
* }
|
|
|
63 |
* }
|
|
|
64 |
* </code>
|
|
|
65 |
* @package Calendar
|
|
|
66 |
* @access public
|
|
|
67 |
*/
|
|
|
68 |
class Calendar_Month_Weekdays extends Calendar_Month
|
|
|
69 |
{
|
|
|
70 |
/**
|
|
|
71 |
* Instance of Calendar_Table_Helper
|
|
|
72 |
* @var Calendar_Table_Helper
|
|
|
73 |
* @access private
|
|
|
74 |
*/
|
|
|
75 |
var $tableHelper;
|
|
|
76 |
|
|
|
77 |
/**
|
|
|
78 |
* First day of the week
|
|
|
79 |
* @access private
|
|
|
80 |
* @var string
|
|
|
81 |
*/
|
|
|
82 |
var $firstDay;
|
|
|
83 |
|
|
|
84 |
/**
|
|
|
85 |
* Constructs Calendar_Month_Weekdays
|
|
|
86 |
* @param int year e.g. 2003
|
|
|
87 |
* @param int month e.g. 5
|
|
|
88 |
* @param int (optional) first day of week (e.g. 0 for Sunday, 2 for Tuesday etc.)
|
|
|
89 |
* @access public
|
|
|
90 |
*/
|
|
|
91 |
function Calendar_Month_Weekdays($y, $m, $firstDay=false)
|
|
|
92 |
{
|
|
|
93 |
Calendar_Month::Calendar_Month($y, $m);
|
|
|
94 |
$this->firstDay = $firstDay;
|
|
|
95 |
}
|
|
|
96 |
|
|
|
97 |
/**
|
|
|
98 |
* Builds Day objects in tabular form, to allow display of calendar month
|
|
|
99 |
* with empty cells if the first day of the week does not fall on the first
|
|
|
100 |
* day of the month.
|
|
|
101 |
* @see Calendar_Day::isEmpty()
|
|
|
102 |
* @see Calendar_Day_Base::isFirst()
|
|
|
103 |
* @see Calendar_Day_Base::isLast()
|
|
|
104 |
* @param array (optional) Calendar_Day objects representing selected dates
|
|
|
105 |
* @return boolean
|
|
|
106 |
* @access public
|
|
|
107 |
*/
|
|
|
108 |
function build($sDates=array())
|
|
|
109 |
{
|
|
|
110 |
require_once CALENDAR_ROOT.'Table'.DIRECTORY_SEPARATOR.'Helper.php';
|
|
|
111 |
$this->tableHelper = & new Calendar_Table_Helper($this, $this->firstDay);
|
|
|
112 |
Calendar_Month::build($sDates);
|
|
|
113 |
$this->buildEmptyDaysBefore();
|
|
|
114 |
$this->shiftDays();
|
|
|
115 |
$this->buildEmptyDaysAfter();
|
|
|
116 |
$this->setWeekMarkers();
|
|
|
117 |
return true;
|
|
|
118 |
}
|
|
|
119 |
|
|
|
120 |
/**
|
|
|
121 |
* Prepends empty days before the real days in the month
|
|
|
122 |
* @return void
|
|
|
123 |
* @access private
|
|
|
124 |
*/
|
|
|
125 |
function buildEmptyDaysBefore()
|
|
|
126 |
{
|
|
|
127 |
$eBefore = $this->tableHelper->getEmptyDaysBefore();
|
|
|
128 |
for ($i=0; $i < $eBefore; $i++) {
|
|
|
129 |
$stamp = $this->cE->dateToStamp($this->year, $this->month, -$i);
|
|
|
130 |
$Day = new Calendar_Day(
|
|
|
131 |
$this->cE->stampToYear($stamp),
|
|
|
132 |
$this->cE->stampToMonth($stamp),
|
|
|
133 |
$this->cE->stampToDay($stamp));
|
|
|
134 |
$Day->setEmpty();
|
|
|
135 |
array_unshift($this->children, $Day);
|
|
|
136 |
}
|
|
|
137 |
}
|
|
|
138 |
|
|
|
139 |
/**
|
|
|
140 |
* Shifts the array of children forward, if necessary
|
|
|
141 |
* @return void
|
|
|
142 |
* @access private
|
|
|
143 |
*/
|
|
|
144 |
function shiftDays()
|
|
|
145 |
{
|
|
|
146 |
if (isset ($this->children[0])) {
|
|
|
147 |
array_unshift($this->children, null);
|
|
|
148 |
unset($this->children[0]);
|
|
|
149 |
}
|
|
|
150 |
}
|
|
|
151 |
|
|
|
152 |
/**
|
|
|
153 |
* Appends empty days after the real days in the month
|
|
|
154 |
* @return void
|
|
|
155 |
* @access private
|
|
|
156 |
*/
|
|
|
157 |
function buildEmptyDaysAfter()
|
|
|
158 |
{
|
|
|
159 |
$eAfter = $this->tableHelper->getEmptyDaysAfter();
|
|
|
160 |
$sDOM = $this->tableHelper->getNumTableDaysInMonth();
|
|
|
161 |
for ($i = 1; $i <= $sDOM-$eAfter; $i++) {
|
|
|
162 |
$Day = new Calendar_Day($this->year, $this->month+1, $i);
|
|
|
163 |
$Day->setEmpty();
|
|
|
164 |
array_push($this->children, $Day);
|
|
|
165 |
}
|
|
|
166 |
}
|
|
|
167 |
|
|
|
168 |
/**
|
|
|
169 |
* Sets the "markers" for the beginning and of a of week, in the
|
|
|
170 |
* built Calendar_Day children
|
|
|
171 |
* @return void
|
|
|
172 |
* @access private
|
|
|
173 |
*/
|
|
|
174 |
function setWeekMarkers()
|
|
|
175 |
{
|
|
|
176 |
$dIW = $this->cE->getDaysInWeek(
|
|
|
177 |
$this->thisYear(),
|
|
|
178 |
$this->thisMonth(),
|
|
|
179 |
$this->thisDay()
|
|
|
180 |
);
|
|
|
181 |
$sDOM = $this->tableHelper->getNumTableDaysInMonth();
|
|
|
182 |
for ($i=1; $i <= $sDOM; $i+= $dIW) {
|
|
|
183 |
$this->children[$i]->setFirst();
|
|
|
184 |
$this->children[$i+($dIW-1)]->setLast();
|
|
|
185 |
}
|
|
|
186 |
}
|
|
|
187 |
}
|
|
|
188 |
?>
|