1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* vim: set expandtab tabstop=4 shiftwidth=4: */ |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Contains the Calendar_Minute class. |
7
|
|
|
* |
8
|
|
|
* PHP versions 4 and 5 |
9
|
|
|
* |
10
|
|
|
* LICENSE: Redistribution and use in source and binary forms, with or without |
11
|
|
|
* modification, are permitted provided that the following conditions are met: |
12
|
|
|
* 1. Redistributions of source code must retain the above copyright |
13
|
|
|
* notice, this list of conditions and the following disclaimer. |
14
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright |
15
|
|
|
* notice, this list of conditions and the following disclaimer in the |
16
|
|
|
* documentation and/or other materials provided with the distribution. |
17
|
|
|
* 3. The name of the author may not be used to endorse or promote products |
18
|
|
|
* derived from this software without specific prior written permission. |
19
|
|
|
* |
20
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED |
21
|
|
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
22
|
|
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
23
|
|
|
* IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY |
24
|
|
|
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
25
|
|
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
26
|
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
27
|
|
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
28
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
29
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
30
|
|
|
* |
31
|
|
|
* @category Date and Time |
32
|
|
|
* |
33
|
|
|
* @author Harry Fuecks <[email protected]> |
34
|
|
|
* @copyright 2003-2007 Harry Fuecks |
35
|
|
|
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause) |
36
|
|
|
* |
37
|
|
|
* @link http://pear.php.net/package/Calendar |
38
|
|
|
*/ |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Allows Calendar include path to be redefined. |
42
|
|
|
* |
43
|
|
|
* @ignore |
44
|
|
|
*/ |
45
|
|
|
if (!defined('CALENDAR_ROOT')) { |
46
|
|
|
define('CALENDAR_ROOT', 'Calendar/'); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Load Calendar base class. |
51
|
|
|
*/ |
52
|
|
|
require_once CALENDAR_ROOT . 'Calendar.php'; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Represents a Year and builds Months<br> |
56
|
|
|
* <code> |
57
|
|
|
* require_once __DIR__ . '/Calendar/Year.php'; |
58
|
|
|
* $Year = new Calendar_Year(2003, 10, 21); // 21st Oct 2003 |
59
|
|
|
* $Year->build(); // Build Calendar_Month objects |
60
|
|
|
* while (false !== ($Month = $Year->fetch())) { |
61
|
|
|
* echo $Month->thisMonth().'<br>'; |
62
|
|
|
* } |
63
|
|
|
* </code>. |
64
|
|
|
* |
65
|
|
|
* @category Date and Time |
66
|
|
|
* |
67
|
|
|
* @author Harry Fuecks <[email protected]> |
68
|
|
|
* @copyright 2003-2007 Harry Fuecks |
69
|
|
|
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause) |
70
|
|
|
* |
71
|
|
|
* @link http://pear.php.net/package/Calendar |
72
|
|
|
*/ |
73
|
|
|
class Calendar_Year extends Calendar |
74
|
|
|
{ |
75
|
|
|
/** |
76
|
|
|
* Constructs Calendar_Year. |
77
|
|
|
* |
78
|
|
|
* @param int $y year e.g. 2003 |
79
|
|
|
*/ |
80
|
|
|
public function __construct($y) |
81
|
|
|
{ |
82
|
|
|
parent::__construct($y); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Builds the Months of the Year.<br> |
87
|
|
|
* <b>Note:</b> by defining the constant CALENDAR_MONTH_STATE you can |
88
|
|
|
* control what class of Calendar_Month is built e.g.; |
89
|
|
|
* <code> |
90
|
|
|
* require_once __DIR__ . '/Calendar/Calendar_Year.php'; |
91
|
|
|
* define('CALENDAR_MONTH_STATE',CALENDAR_USE_MONTH_WEEKDAYS); // Use Calendar_Month_Weekdays |
92
|
|
|
* // define('CALENDAR_MONTH_STATE',CALENDAR_USE_MONTH_WEEKS); // Use Calendar_Month_Weeks |
93
|
|
|
* // define('CALENDAR_MONTH_STATE',CALENDAR_USE_MONTH); // Use Calendar_Month |
94
|
|
|
* </code> |
95
|
|
|
* It defaults to building Calendar_Month objects. |
96
|
|
|
* |
97
|
|
|
* @param array $sDates (optional) array of Calendar_Month objects |
98
|
|
|
* representing selected dates |
99
|
|
|
* @param int $firstDay (optional) first day of week |
100
|
|
|
* (e.g. 0 for Sunday, 2 for Tuesday etc.) |
101
|
|
|
* |
102
|
|
|
* @return bool |
103
|
|
|
*/ |
104
|
|
|
public function build($sDates = [], $firstDay = null) |
105
|
|
|
{ |
106
|
|
|
require_once CALENDAR_ROOT . 'Factory.php'; |
107
|
|
|
$this->firstDay = $this->defineFirstDayOfWeek($firstDay); |
|
|
|
|
108
|
|
|
$monthsInYear = $this->cE->getMonthsInYear($this->thisYear()); |
109
|
|
|
for ($i = 1; $i <= $monthsInYear; ++$i) { |
110
|
|
|
$this->children[$i] = Calendar_Factory::create('Month', $this->year, $i); |
111
|
|
|
} |
112
|
|
|
if (count($sDates) > 0) { |
113
|
|
|
$this->setSelection($sDates); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
return true; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Called from build(). |
121
|
|
|
* |
122
|
|
|
* @param array $sDates array of Calendar_Month objects representing selected dates |
123
|
|
|
* @return bool|void |
124
|
|
|
*/ |
125
|
|
|
public function setSelection($sDates) |
126
|
|
|
{ |
127
|
|
|
foreach ($sDates as $sDate) { |
128
|
|
|
if ($this->year == $sDate->thisYear()) { |
129
|
|
|
$key = $sDate->thisMonth(); |
130
|
|
|
if (isset($this->children[$key])) { |
131
|
|
|
$sDate->setSelected(); |
132
|
|
|
$this->children[$key] = $sDate; |
133
|
|
|
} |
134
|
|
|
} |
135
|
|
|
} |
136
|
|
|
} |
137
|
|
|
} |
138
|
|
|
|