Subversion Repositories Applications.papyrus

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
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: Day.php,v 1.1 2005-09-30 14:58:00 ddelon Exp $
21
//
22
/**
23
 * @package Calendar
24
 * @version $Id: Day.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
 * Represents a Day and builds Hours.
42
 * <code>
43
 * require_once 'Calendar'.DIRECTORY_SEPARATOR.'Day.php';
44
 * $Day = & new Calendar_Day(2003, 10, 21); // Oct 21st 2003
45
 * while ($Hour = & $Day->fetch()) {
46
 *    echo $Hour->thisHour().'<br />';
47
 * }
48
 * </code>
49
 * @package Calendar
50
 * @access public
51
 */
52
class Calendar_Day extends Calendar
53
{
54
    /**
55
     * Marks the Day at the beginning of a week
56
     * @access private
57
     * @var boolean
58
     */
59
    var $first = false;
60
 
61
    /**
62
     * Marks the Day at the end of a week
63
    * @access private
64
     * @var boolean
65
     */
66
    var $last = false;
67
 
68
 
69
    /**
70
     * Used for tabular calendars
71
     * @access private
72
     * @var boolean
73
     */
74
    var $empty = false;
75
 
76
    /**
77
     * Constructs Calendar_Day
78
     * @param int year e.g. 2003
79
     * @param int month e.g. 8
80
     * @param int day e.g. 15
81
     * @access public
82
     */
83
    function Calendar_Day($y, $m, $d)
84
    {
85
        Calendar::Calendar($y, $m, $d);
86
    }
87
 
88
    /**
89
     * Builds the Hours of the Day
90
     * @param array (optional) Caledar_Hour objects representing selected dates
91
     * @return boolean
92
     * @access public
93
     */
94
    function build($sDates = array())
95
    {
96
        require_once CALENDAR_ROOT.'Hour.php';
97
 
98
        $hID = $this->cE->getHoursInDay($this->year, $this->month, $this->day);
99
        for ($i=0; $i < $hID; $i++) {
100
            $this->children[$i]=
101
                new Calendar_Hour($this->year, $this->month, $this->day, $i);
102
        }
103
        if (count($sDates) > 0) {
104
            $this->setSelection($sDates);
105
        }
106
        return true;
107
    }
108
 
109
    /**
110
     * Called from build()
111
     * @param array
112
     * @return void
113
     * @access private
114
     */
115
    function setSelection($sDates)
116
    {
117
        foreach ($sDates as $sDate) {
118
            if ($this->year == $sDate->thisYear()
119
                && $this->month == $sDate->thisMonth()
120
                && $this->day == $sDate->thisDay())
121
            {
122
                $key = (int)$sDate->thisHour();
123
                if (isset($this->children[$key])) {
124
                    $sDate->setSelected();
125
                    $this->children[$key] = $sDate;
126
                }
127
            }
128
        }
129
    }
130
 
131
    /**
132
     * Defines Day object as first in a week
133
     * Only used by Calendar_Month_Weekdays::build()
134
     * @param boolean state
135
     * @return void
136
     * @access private
137
     */
138
    function setFirst ($state = true)
139
    {
140
        $this->first = $state;
141
    }
142
 
143
    /**
144
     * Defines Day object as last in a week
145
     * Used only following Calendar_Month_Weekdays::build()
146
     * @param boolean state
147
     * @return void
148
     * @access private
149
     */
150
    function setLast($state = true)
151
    {
152
        $this->last = $state;
153
    }
154
 
155
    /**
156
     * Returns true if Day object is first in a Week
157
     * Only relevant when Day is created by Calendar_Month_Weekdays::build()
158
     * @return boolean
159
     * @access public
160
     */
161
    function isFirst() {
162
        return $this->first;
163
    }
164
 
165
    /**
166
     * Returns true if Day object is last in a Week
167
     * Only relevant when Day is created by Calendar_Month_Weekdays::build()
168
     * @return boolean
169
     * @access public
170
     */
171
    function isLast()
172
    {
173
        return $this->last;
174
    }
175
 
176
    /**
177
     * Defines Day object as empty
178
     * Only used by Calendar_Month_Weekdays::build()
179
     * @param boolean state
180
     * @return void
181
     * @access private
182
     */
183
    function setEmpty ($state = true)
184
    {
185
        $this->empty = $state;
186
    }
187
 
188
    /**
189
     * @return boolean
190
     * @access public
191
     */
192
    function isEmpty()
193
    {
194
        return $this->empty;
195
    }
196
}
197
?>