| 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 | // | [email protected] so we can mail you a copy immediately. | |
|---|
| 16 | // +----------------------------------------------------------------------+ |
|---|
| 17 | // | Authors: Harry Fuecks <[email protected]> | |
|---|
| 18 | // +----------------------------------------------------------------------+ |
|---|
| 19 | // |
|---|
| 20 | // $Id: Weekdays.php,v 1.4 2005/10/22 10:28:49 quipo Exp $ |
|---|
| 21 | // |
|---|
| 22 | /** |
|---|
| 23 | * @package Calendar |
|---|
| 24 | * @version $Id: Weekdays.php,v 1.4 2005/10/22 10:28:49 quipo 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/Month/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=null) |
|---|
| 92 | { |
|---|
| 93 | Calendar_Month::Calendar_Month($y, $m, $firstDay); |
|---|
| 94 | } |
|---|
| 95 | |
|---|
| 96 | /** |
|---|
| 97 | * Builds Day objects in tabular form, to allow display of calendar month |
|---|
| 98 | * with empty cells if the first day of the week does not fall on the first |
|---|
| 99 | * day of the month. |
|---|
| 100 | * @see Calendar_Day::isEmpty() |
|---|
| 101 | * @see Calendar_Day_Base::isFirst() |
|---|
| 102 | * @see Calendar_Day_Base::isLast() |
|---|
| 103 | * @param array (optional) Calendar_Day objects representing selected dates |
|---|
| 104 | * @return boolean |
|---|
| 105 | * @access public |
|---|
| 106 | */ |
|---|
| 107 | function build($sDates=array()) |
|---|
| 108 | { |
|---|
| 109 | require_once CALENDAR_ROOT.'Table/Helper.php'; |
|---|
| 110 | $this->tableHelper = & new Calendar_Table_Helper($this, $this->firstDay); |
|---|
| 111 | Calendar_Month::build($sDates); |
|---|
| 112 | $this->buildEmptyDaysBefore(); |
|---|
| 113 | $this->shiftDays(); |
|---|
| 114 | $this->buildEmptyDaysAfter(); |
|---|
| 115 | $this->setWeekMarkers(); |
|---|
| 116 | return true; |
|---|
| 117 | } |
|---|
| 118 | |
|---|
| 119 | /** |
|---|
| 120 | * Prepends empty days before the real days in the month |
|---|
| 121 | * @return void |
|---|
| 122 | * @access private |
|---|
| 123 | */ |
|---|
| 124 | function buildEmptyDaysBefore() |
|---|
| 125 | { |
|---|
| 126 | $eBefore = $this->tableHelper->getEmptyDaysBefore(); |
|---|
| 127 | for ($i=0; $i < $eBefore; $i++) { |
|---|
| 128 | $stamp = $this->cE->dateToStamp($this->year, $this->month, -$i); |
|---|
| 129 | $Day = new Calendar_Day( |
|---|
| 130 | $this->cE->stampToYear($stamp), |
|---|
| 131 | $this->cE->stampToMonth($stamp), |
|---|
| 132 | $this->cE->stampToDay($stamp)); |
|---|
| 133 | $Day->setEmpty(); |
|---|
| 134 | $Day->adjust(); |
|---|
| 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 | $Day->adjust(); |
|---|
| 165 | array_push($this->children, $Day); |
|---|
| 166 | } |
|---|
| 167 | } |
|---|
| 168 | |
|---|
| 169 | /** |
|---|
| 170 | * Sets the "markers" for the beginning and of a of week, in the |
|---|
| 171 | * built Calendar_Day children |
|---|
| 172 | * @return void |
|---|
| 173 | * @access private |
|---|
| 174 | */ |
|---|
| 175 | function setWeekMarkers() |
|---|
| 176 | { |
|---|
| 177 | $dIW = $this->cE->getDaysInWeek( |
|---|
| 178 | $this->thisYear(), |
|---|
| 179 | $this->thisMonth(), |
|---|
| 180 | $this->thisDay() |
|---|
| 181 | ); |
|---|
| 182 | $sDOM = $this->tableHelper->getNumTableDaysInMonth(); |
|---|
| 183 | for ($i=1; $i <= $sDOM; $i+= $dIW) { |
|---|
| 184 | $this->children[$i]->setFirst(); |
|---|
| 185 | $this->children[$i+($dIW-1)]->setLast(); |
|---|
| 186 | } |
|---|
| 187 | } |
|---|
| 188 | } |
|---|
| 189 | ?> |
|---|