FriendsOfPear /
Calendar
| 1 | <?php |
||
| 2 | /* vim: set expandtab tabstop=4 shiftwidth=4: */ |
||
| 3 | |||
| 4 | /** |
||
| 5 | * Contains the Calendar_Day class |
||
| 6 | * |
||
| 7 | * PHP versions 4 and 5 |
||
| 8 | * |
||
| 9 | * LICENSE: Redistribution and use in source and binary forms, with or without |
||
| 10 | * modification, are permitted provided that the following conditions are met: |
||
| 11 | * 1. Redistributions of source code must retain the above copyright |
||
| 12 | * notice, this list of conditions and the following disclaimer. |
||
| 13 | * 2. Redistributions in binary form must reproduce the above copyright |
||
| 14 | * notice, this list of conditions and the following disclaimer in the |
||
| 15 | * documentation and/or other materials provided with the distribution. |
||
| 16 | * 3. The name of the author may not be used to endorse or promote products |
||
| 17 | * derived from this software without specific prior written permission. |
||
| 18 | * |
||
| 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED |
||
| 20 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
||
| 21 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
||
| 22 | * IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY |
||
| 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
||
| 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
||
| 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
||
| 26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||
| 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
||
| 28 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
| 29 | * |
||
| 30 | * @category Date and Time |
||
| 31 | * @package Calendar |
||
| 32 | * @author Harry Fuecks <[email protected]> |
||
| 33 | * @copyright 2003-2007 Harry Fuecks |
||
| 34 | * @license http://www.debian.org/misc/bsd.license BSD License (3 Clause) |
||
| 35 | * @version CVS: $Id$ |
||
| 36 | * @link http://pear.php.net/package/Calendar |
||
| 37 | */ |
||
| 38 | namespace PEAR\Calendar; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * Allows Calendar include path to be redefined |
||
| 42 | * @ignore |
||
| 43 | */ |
||
| 44 | if (!defined('CALENDAR_ROOT')) { |
||
| 45 | define('CALENDAR_ROOT', 'Calendar'.DIRECTORY_SEPARATOR); |
||
| 46 | } |
||
| 47 | |||
| 48 | /** |
||
| 49 | * Represents a Day and builds Hours. |
||
| 50 | * <code> |
||
| 51 | * $Day = new \PEAR\Calendar\Day(2003, 10, 21); // Oct 21st 2003 |
||
| 52 | * while ($Hour = & $Day->fetch()) { |
||
| 53 | * echo $Hour->thisHour().'<br />'; |
||
| 54 | * } |
||
| 55 | * </code> |
||
| 56 | * |
||
| 57 | * @category Date and Time |
||
| 58 | * @package Calendar |
||
| 59 | * @author Harry Fuecks <[email protected]> |
||
| 60 | * @copyright 2003-2007 Harry Fuecks |
||
| 61 | * @license http://www.debian.org/misc/bsd.license BSD License (3 Clause) |
||
| 62 | * @link http://pear.php.net/package/Calendar |
||
| 63 | * @access public |
||
| 64 | */ |
||
| 65 | class Day extends Calendar |
||
| 66 | { |
||
| 67 | /** |
||
| 68 | * Marks the Day at the beginning of a week |
||
| 69 | * @access private |
||
| 70 | * @var boolean |
||
| 71 | */ |
||
| 72 | var $first = false; |
||
| 73 | |||
| 74 | /** |
||
| 75 | * Marks the Day at the end of a week |
||
| 76 | * @access private |
||
| 77 | * @var boolean |
||
| 78 | */ |
||
| 79 | var $last = false; |
||
| 80 | |||
| 81 | |||
| 82 | /** |
||
| 83 | * Used for tabular calendars |
||
| 84 | * @access private |
||
| 85 | * @var boolean |
||
| 86 | */ |
||
| 87 | var $empty = false; |
||
| 88 | |||
| 89 | /** |
||
| 90 | * Constructs Calendar_Day |
||
| 91 | * |
||
| 92 | * @param int $y year e.g. 2003 |
||
| 93 | * @param int $m month e.g. 8 |
||
| 94 | * @param int $d day e.g. 15 |
||
| 95 | * |
||
| 96 | * @access public |
||
| 97 | */ |
||
| 98 | function __construct($y, $m, $d) |
||
|
0 ignored issues
–
show
|
|||
| 99 | { |
||
| 100 | parent::__construct($y, $m, $d); |
||
| 101 | } |
||
| 102 | |||
| 103 | /** |
||
| 104 | * Builds the Hours of the Day |
||
| 105 | * |
||
| 106 | * @param array $sDates (optional) Caledar_Hour objects representing selected dates |
||
| 107 | * |
||
| 108 | * @return boolean |
||
| 109 | * @access public |
||
| 110 | */ |
||
| 111 | function build($sDates = array()) |
||
|
0 ignored issues
–
show
|
|||
| 112 | { |
||
| 113 | $hID = $this->cE->getHoursInDay($this->year, $this->month, $this->day); |
||
| 114 | for ($i=0; $i < $hID; $i++) { |
||
| 115 | $this->children[$i] = |
||
| 116 | new Hour($this->year, $this->month, $this->day, $i); |
||
| 117 | } |
||
| 118 | if (count($sDates) > 0) { |
||
| 119 | $this->setSelection($sDates); |
||
| 120 | } |
||
| 121 | return true; |
||
| 122 | } |
||
| 123 | |||
| 124 | /** |
||
| 125 | * Called from build() |
||
| 126 | * |
||
| 127 | * @param array $sDates dates to be selected |
||
| 128 | * |
||
| 129 | * @return void |
||
| 130 | * @access private |
||
| 131 | */ |
||
| 132 | function setSelection($sDates) |
||
|
0 ignored issues
–
show
|
|||
| 133 | { |
||
| 134 | foreach ($sDates as $sDate) { |
||
| 135 | if ($this->year == $sDate->thisYear() |
||
| 136 | && $this->month == $sDate->thisMonth() |
||
| 137 | && $this->day == $sDate->thisDay()) |
||
| 138 | { |
||
| 139 | $key = (int)$sDate->thisHour(); |
||
| 140 | if (isset($this->children[$key])) { |
||
| 141 | $sDate->setSelected(); |
||
| 142 | $this->children[$key] = $sDate; |
||
| 143 | } |
||
| 144 | } |
||
| 145 | } |
||
| 146 | } |
||
| 147 | |||
| 148 | /** |
||
| 149 | * Defines Day object as first in a week |
||
| 150 | * Only used by Calendar_Month_Weekdays::build() |
||
| 151 | * |
||
| 152 | * @param boolean $state set this day as first in week |
||
| 153 | * |
||
| 154 | * @return void |
||
| 155 | * @access private |
||
| 156 | */ |
||
| 157 | function setFirst($state = true) |
||
|
0 ignored issues
–
show
|
|||
| 158 | { |
||
| 159 | $this->first = $state; |
||
| 160 | } |
||
| 161 | |||
| 162 | /** |
||
| 163 | * Defines Day object as last in a week |
||
| 164 | * Used only following Calendar_Month_Weekdays::build() |
||
| 165 | * |
||
| 166 | * @param boolean $state set this day as last in week |
||
| 167 | * |
||
| 168 | * @return void |
||
| 169 | * @access private |
||
| 170 | */ |
||
| 171 | function setLast($state = true) |
||
|
0 ignored issues
–
show
|
|||
| 172 | { |
||
| 173 | $this->last = $state; |
||
| 174 | } |
||
| 175 | |||
| 176 | /** |
||
| 177 | * Returns true if Day object is first in a Week |
||
| 178 | * Only relevant when Day is created by Calendar_Month_Weekdays::build() |
||
| 179 | * |
||
| 180 | * @return boolean |
||
| 181 | * @access public |
||
| 182 | */ |
||
| 183 | function isFirst() |
||
|
0 ignored issues
–
show
|
|||
| 184 | { |
||
| 185 | return $this->first; |
||
| 186 | } |
||
| 187 | |||
| 188 | /** |
||
| 189 | * Returns true if Day object is last in a Week |
||
| 190 | * Only relevant when Day is created by Calendar_Month_Weekdays::build() |
||
| 191 | * |
||
| 192 | * @return boolean |
||
| 193 | * @access public |
||
| 194 | */ |
||
| 195 | function isLast() |
||
|
0 ignored issues
–
show
|
|||
| 196 | { |
||
| 197 | return $this->last; |
||
| 198 | } |
||
| 199 | |||
| 200 | /** |
||
| 201 | * Defines Day object as empty |
||
| 202 | * Only used by Calendar_Month_Weekdays::build() |
||
| 203 | * |
||
| 204 | * @param boolean $state set this day as empty |
||
| 205 | * |
||
| 206 | * @return void |
||
| 207 | * @access private |
||
| 208 | */ |
||
| 209 | function setEmpty ($state = true) |
||
|
0 ignored issues
–
show
|
|||
| 210 | { |
||
| 211 | $this->empty = $state; |
||
| 212 | } |
||
| 213 | |||
| 214 | /** |
||
| 215 | * Check if this day is empty |
||
| 216 | * |
||
| 217 | * @return boolean |
||
| 218 | * @access public |
||
| 219 | */ |
||
| 220 | function isEmpty() |
||
|
0 ignored issues
–
show
|
|||
| 221 | { |
||
| 222 | return $this->empty; |
||
| 223 | } |
||
| 224 | } |
||
| 225 |
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.